00001 #ifndef VERTEX_PROPERTY_WRITER_H_INCLUDED_
00002 #define VERTEX_PROPERTY_WRITER_H_INCLUDED_
00003
00004 #include "segment_graph.h"
00005
00006 namespace risc {
00007
00008 namespace sg {
00009
00010 struct VertexPropertyWriter {
00011
00012 static bool print_read_write_access;
00013
00014 VertexPropertyWriter(Graph& graph);
00015
00016 template <class Vertex>
00017 void operator() (std::ostream &out, Vertex v)
00018 {
00019 out << "[shape=record,label=\"{ Segment ID: " << graph_[v].id_;
00020
00021 if(graph_[v].boundary_node_) {
00022 std::string unparsed_stmt = graph_[v].boundary_node_->unparseToString();
00023
00024 replace_escape_characters(unparsed_stmt);
00025
00026 std::string temp =
00027 StringUtility::stripPathFromFileName(
00028 graph_[v].boundary_node_->get_file_info()->get_raw_filename());
00029
00030 out << " (" << temp << ":"
00031 << graph_[v].boundary_node_->get_file_info()->get_line() << ")";
00032 } else {
00033
00034 SgNode *first_node = NULL;
00035 if(graph_[v].expressions_.size() != 0) {
00036
00037 first_node = *(graph_[v].expressions_.begin());
00038
00039 if(first_node) {
00040 SgFunctionDefinition *func_def =
00041 SageInterface::getEnclosingFunctionDefinition(first_node);
00042
00043 if(func_def) {
00044
00045 SgClassDefinition *class_def =
00046 SageInterface::getEnclosingClassDefinition(func_def);
00047
00048 if(class_def) {
00049
00050 out << " [" << SageInterface::get_name(class_def)
00051 << "::" << SageInterface::get_name(func_def) << "]";
00052 }
00053 }
00054 }
00055 }
00056 }
00057
00058 if(!VertexPropertyWriter::print_read_write_access) {
00059 for(Segment::Expressions::iterator
00060 expr_iter = graph_[v].expressions_.begin();
00061 expr_iter != graph_[v].expressions_.end();
00062 expr_iter++) {
00063
00064 std::string unparsed_stmt = (*expr_iter)->unparseToString();
00065
00066 replace_escape_characters(unparsed_stmt);
00067
00068 std::string temp =
00069 StringUtility::stripPathFromFileName(
00070 (*expr_iter)->get_file_info()->get_raw_filename());
00071
00072 out << "|" << temp << ":"
00073 << (*expr_iter)->get_file_info()->get_line() << " "
00074 << unparsed_stmt << "\\l";
00075 }
00076 } else {
00077
00078
00079 for(std::set<SgVariableSymbol*>::iterator
00080 var_symbol_iter = graph_[v].write_variables_.begin();
00081 var_symbol_iter != graph_[v].write_variables_.end();
00082 var_symbol_iter++) {
00083
00084 out << "| (W) "
00085 << SageInterface::get_name(*var_symbol_iter).erase(
00086 SageInterface::get_name(*var_symbol_iter).length() - 8)
00087 << "\\l";
00088 }
00089
00090
00091 for(std::set<SgVariableSymbol*>::iterator
00092 var_symbol_iter = graph_[v].read_variables_.begin();
00093 var_symbol_iter != graph_[v].read_variables_.end();
00094 var_symbol_iter++) {
00095
00096 out << "| (R) "
00097 << SageInterface::get_name(*var_symbol_iter).erase(
00098 SageInterface::get_name(*var_symbol_iter).length() - 8)
00099 << "\\l";
00100 }
00101 }
00102
00103 out << "}\"]";
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129 }
00130
00135 void replace_escape_characters(std::string &unparsed_stmt);
00136
00137 Graph& graph_;
00138
00139 friend std::ostream& operator<< (std::ostream &out,
00140 const VertexPropertyWriter &vpw)
00141 {
00142 return out;
00143 }
00144 };
00145
00146 };
00147
00148 };
00149
00150 #endif
00151
00152