ROSE  0.9.6a
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AstDOTGeneration.h
Go to the documentation of this file.
1 // Author: Markus Schordan
2 // $Id: AstDOTGeneration.h,v 1.4 2008/01/08 02:56:38 dquinlan Exp $
3 
4 #ifndef ASTDOTGENERATION_H
5 #define ASTDOTGENERATION_H
6 
7 #include <set>
8 #include "DOTGeneration.h"
9 #include "roseInternal.h"
10 //#include "sage3.h"
11 
13  {
14  public:
15  void generate(SgProject* node, traversalType tt=TOPDOWNBOTTOMUP, std::string filenamePostfix="");
16  void generate(SgNode* node, std::string filename, traversalType tt = TOPDOWNBOTTOMUP,std::string filenamePostfix = "");
17  void generateInputFiles(SgProject* node, traversalType tt=TOPDOWNBOTTOMUP, std::string filenamePostfix="");
18  void generateWithinFile(SgFile* node, traversalType tt=TOPDOWNBOTTOMUP, std::string filenamePostfix="");
19 
20  void writeIncidenceGraphToDOTFile(SgIncidenceDirectedGraph* graph, const std::string& filename);
21  void addAdditionalNodesAndEdges(SgNode* node);
22 
23  protected:
24  virtual DOTInheritedAttribute evaluateInheritedAttribute(SgNode* node, DOTInheritedAttribute ia);
25  virtual DOTSynthesizedAttribute evaluateSynthesizedAttribute(SgNode* node, DOTInheritedAttribute ia, SubTreeSynthesizedAttributes l);
26 
27  std::string additionalNodeInfo(SgNode* node);
28 
29  // DQ (11/1/2003) added mechanism to add node options (to add color, etc.)
30  std::string additionalNodeOptions(SgNode* node);
31 
32  // DQ (3/5/2007) added mechanism to add edge options (to add color, etc.)
33  std::string additionalEdgeInfo(SgNode* from, SgNode* to, std::string label);
34 
35  // DQ (3/5/2007) added mechanism to add edge options (to add color, etc.)
36  std::string additionalEdgeOptions(SgNode* from, SgNode* to, std::string label);
37 
38  // DQ (7/27/2008): Added support to eliminate IR nodes in DOT graphs
39  // (to tailor the presentation of information about ASTs).
40  bool commentOutNodeInGraph(SgNode* node);
41  };
42 
43 
44 namespace AstDOTGenerationExtended_Defaults
45  {
47  {
48 #if 1
49  // DQ (6/25/2011): Put the function definition into the source file (avoid function definitions in header files).
50  std::string operator()(SgNode* node);
51 #else
52  // std::string AstDOTGenerationExtended_Defaults::NamedExtraNodeInfo::operator()(SgNode* node)
53  std::string operator()(SgNode* node)
54  {
55  std::ostringstream ss;
56 
57  // add namespace name
59  {
60  ss << n->get_qualified_name().str() << "\\n";
61  }
62  // add class name
64  {
65  ss << n->get_qualified_name().str() << "\\n";
66  }
67  // add function name
69  {
70  ss << n->get_qualified_name().str() << "\\n";
71  }
72  if (SgFunctionRefExp* n = isSgFunctionRefExp(node))
73  {
74  SgFunctionDeclaration* decl = n->getAssociatedFunctionDeclaration();
75  if (decl) // it's null if through a function pointer
76  {
77  ss << decl->get_qualified_name().str() << "\\n";
78  }
79  }
80  // add variable name
82  {
83  ss << n->get_qualified_name().str() << "\\n";
84  }
85  if (SgVarRefExp* n = isSgVarRefExp(node))
86  {
87  SgVariableSymbol* sym = n->get_symbol();
88  ss << sym->get_name().getString() << "\\n";
89  }
90  // add variable name
91  if (SgVariableSymbol* n = isSgVariableSymbol(node))
92  {
93  ss << n->get_name().str() << "\\n";
94  }
95 
96  return ss.str();
97  }
98 #endif
99  };
100 
102  {
103  std::string operator()(SgNode* node)
104  {
105  std::ostringstream ss;
106 
107  ss << node << "\\n";
108 
109  return ss.str();
110  }
111  };
112 
114  {
115  std::string operator()(SgNode* node)
116  {
117  std::ostringstream ss;
118  // print number of max successors (= container size)
121  ss << c.size() << "\\n";
122 
123  return ss.str();
124  }
125  };
126 
128  {
129 #if 1
130  // DQ (6/25/2011): Put the function definition into the source file (avoid function definitions in header files).
131  std::string operator()(SgNode* node);
132 #else
133  // std::string AstDOTGenerationExtended_Defaults::LValueExtraNodeInfo::operator()(SgNode* node)
134  std::string operator()(SgNode* node)
135  {
136  std::ostringstream ss;
137 
138  // adds whether or not it is an l-value
139  if (SgExpression* n = isSgExpression(node))
140  {
141  ss << (n->isLValue() ? "L-Value" : "!L-Value") << "\\n";
142  }
143 
144  return ss.str();
145  }
146 #endif
147  };
148 
150  {
151 #if 1
152  // DQ (6/25/2011): Put the function definition into the source file (avoid function definitions in header files).
153  std::string operator()(SgNode* node);
154 #else
155  // std::string AstDOTGenerationExtended_Defaults::TypeExtraNodeInfo::operator()(SgNode* node)
156  std::string operator()(SgNode* node)
157  {
158  std::ostringstream ss;
159 
160  if (SgExpression* n = isSgExpression(node))
161  {
162  ss << n->get_type()->unparseToString() << "\\n";
163  }
164 
165  return ss.str();
166  }
167 #endif
168  };
169 
171  {
172  std::string operator()(SgNode* node)
173  {
177  return std::string("\\n") + cs(node) + name(node) + add(node);
178  }
179  };
180 
181 
183  {
184  std::string operator()(SgNode* node)
185  {
186  return std::string();
187  }
188  };
189 
191  {
192  std::string operator()(SgNode* from, SgNode* to, std::string label)
193  {
194  return std::string();
195  }
196  };
197 
199  {
200  std::string operator()(SgNode* node, SgNode* to, std::string label)
201  {
202  return std::string();
203  }
204  };
205 }
206 
207 // King84 (14/7/2010) added mechanism to customize node options on demand
208 // Note: aditionalEdgeInfo andadditionalEdgeOptions are inherited.
209 // Note: EdgeInfo and EdgeOptions are not used because they come into play
210 // for functions in the base class which are not virtual.
211 template <typename ExtraNodeInfo_t = AstDOTGenerationExtended_Defaults::DefaultExtraNodeInfo,
212  typename ExtraNodeOptions_t = AstDOTGenerationExtended_Defaults::DefaultExtraNodeOptions,
216  {
217  protected:
218  ExtraNodeInfo_t eni;
219  ExtraNodeOptions_t eno;
220  ExtraEdgeInfo_t eei;
221  ExtraEdgeOptions_t eeo;
222  public:
223  AstDOTGenerationExtended(ExtraNodeInfo_t eni_ = ExtraNodeInfo_t(), ExtraNodeOptions_t eno_ = ExtraNodeOptions_t(), ExtraEdgeInfo_t eei_ = ExtraEdgeInfo_t(), ExtraEdgeOptions_t eeo_ = ExtraEdgeOptions_t())
224  : eni(eni_), eno(eno_), eei(eei_), eeo(eeo_)
225  { }
226  // virtual DOTInheritedAttribute evaluateInheritedAttribute(SgNode* node, DOTInheritedAttribute ia);
227  virtual DOTSynthesizedAttribute evaluateSynthesizedAttribute(SgNode* node, DOTInheritedAttribute ia, SubTreeSynthesizedAttributes l);
228  };
229 
230 #endif
231