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