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
00033
00034
00035 const SgLocatedNode *located_node =
00036 isSgLocatedNode(graph_[v].boundary_node_);
00037
00038 AttachedPreprocessingInfoType *comments =
00039 const_cast<SgLocatedNode*>(
00040 located_node)->getAttachedPreprocessingInfo();
00041
00042 if(comments != NULL) {
00043
00044
00045
00046
00047 for(AttachedPreprocessingInfoType::iterator
00048 i = comments->begin();
00049 i != comments->end();
00050 i++) {
00051
00052 if(located_node->get_file_info()->get_line()
00053 == (*i)->getLineNumber()) {
00054
00055
00056 std::string str = (*i)->getString().substr(2,
00057 (*i)->getString().length()-2);
00058
00059
00060 str.erase(std::remove(str.begin(), str.end(), '\n'), str.end());
00061 out << " " << str;
00062 }
00063 }
00064 }
00065 } else {
00066
00067 SgNode *first_node = NULL;
00068 if(graph_[v].expressions_.size() != 0) {
00069
00070 first_node = *(graph_[v].expressions_.begin());
00071
00072 if(first_node) {
00073 SgFunctionDefinition *func_def =
00074 SageInterface::getEnclosingFunctionDefinition(first_node);
00075
00076 if(func_def) {
00077
00078 SgClassDefinition *class_def =
00079 SageInterface::getEnclosingClassDefinition(func_def);
00080
00081 if(class_def) {
00082
00083 out << " [" << SageInterface::get_name(class_def)
00084 << "::" << SageInterface::get_name(func_def) << "]";
00085 }
00086 }
00087 }
00088 }
00089
00090
00091 }
00092
00093 if(!VertexPropertyWriter::print_read_write_access) {
00094 for(Segment::Expressions::iterator
00095 expr_iter = graph_[v].expressions_.begin();
00096 expr_iter != graph_[v].expressions_.end();
00097 expr_iter++) {
00098
00099 std::string unparsed_stmt = (*expr_iter)->unparseToString();
00100
00101 replace_escape_characters(unparsed_stmt);
00102
00103 std::string temp =
00104 StringUtility::stripPathFromFileName(
00105 (*expr_iter)->get_file_info()->get_raw_filename());
00106
00107
00108
00109 out << "|" << temp << ":"
00110 << (*expr_iter)->get_file_info()->get_line() << " "
00111 << unparsed_stmt << "\\l";
00112
00113 }
00114 } else {
00115
00116
00117 for(std::set<SgVariableSymbol*>::iterator
00118 var_symbol_iter = graph_[v].write_variables_.begin();
00119 var_symbol_iter != graph_[v].write_variables_.end();
00120 var_symbol_iter++) {
00121
00122 out << "| (W) "
00123 << SageInterface::get_name(*var_symbol_iter).erase(
00124 SageInterface::get_name(*var_symbol_iter).length() - 8)
00125 << "\\l";
00126 }
00127
00128
00129 for(std::set<SgVariableSymbol*>::iterator
00130 var_symbol_iter = graph_[v].read_variables_.begin();
00131 var_symbol_iter != graph_[v].read_variables_.end();
00132 var_symbol_iter++) {
00133
00134 out << "| (R) "
00135 << SageInterface::get_name(*var_symbol_iter).erase(
00136 SageInterface::get_name(*var_symbol_iter).length() - 8)
00137 << "\\l";
00138 }
00139 }
00140
00141 out << "}\"]";
00142
00143
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
00173 void replace_escape_characters(std::string &unparsed_stmt);
00174
00175 Graph& graph_;
00176
00177 friend std::ostream& operator<< (std::ostream &out,
00178 const VertexPropertyWriter &vpw)
00179 {
00180 return out;
00181 }
00182 };
00183
00184 };
00185
00186 };
00187
00188 #endif
00189
00190