ROSE  0.9.9.139
AstDOTGeneration.h
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 
12 class ROSE_DLL_API AstDOTGeneration : public DOTGeneration<SgNode*>
13  {
14  public:
15  //traverse full AST , nodes which represent code from include files . name postfix does not need an ending "."
16  void generate(SgProject* node, traversalType tt=TOPDOWNBOTTOMUP, std::string filenamePostfix="");
17  void generate(SgNode* node, std::string filename, traversalType tt = TOPDOWNBOTTOMUP,std::string filenamePostfix = "");
18  // traverse the subtree of AST which represents the files specified on the command line
19  void generateInputFiles(SgProject* node, traversalType tt=TOPDOWNBOTTOMUP, std::string filenamePostfix="");
20  // only the nodes which represent code of the same file as the start node
21  void generateWithinFile(SgFile* node, traversalType tt=TOPDOWNBOTTOMUP, std::string filenamePostfix="");
22 
23  void writeIncidenceGraphToDOTFile(SgIncidenceDirectedGraph* graph, const std::string& filename);
24  void addAdditionalNodesAndEdges(SgNode* node);
25 
26  protected:
27  virtual DOTInheritedAttribute evaluateInheritedAttribute(SgNode* node, DOTInheritedAttribute ia);
28  virtual DOTSynthesizedAttribute evaluateSynthesizedAttribute(SgNode* node, DOTInheritedAttribute ia, SubTreeSynthesizedAttributes l);
29 
30  std::string additionalNodeInfo(SgNode* node);
31 
32  // DQ (11/1/2003) added mechanism to add node options (to add color, etc.)
33  std::string additionalNodeOptions(SgNode* node);
34 
35  // DQ (3/5/2007) added mechanism to add edge options (to add color, etc.)
36  std::string additionalEdgeInfo(SgNode* from, SgNode* to, std::string label);
37 
38  // DQ (3/5/2007) added mechanism to add edge options (to add color, etc.)
39  std::string additionalEdgeOptions(SgNode* from, SgNode* to, std::string label);
40 
41  // DQ (7/27/2008): Added support to eliminate IR nodes in DOT graphs
42  // (to tailor the presentation of information about ASTs).
43  bool commentOutNodeInGraph(SgNode* node);
44  };
45 
46 
48  {
49  struct ROSE_DLL_API NamedExtraNodeInfo
50  {
51 #if 1
52  // DQ (6/25/2011): Put the function definition into the source file (avoid function definitions in header files).
53  std::string operator()(SgNode* node);
54 #else
55  // std::string AstDOTGenerationExtended_Defaults::NamedExtraNodeInfo::operator()(SgNode* node)
56  std::string operator()(SgNode* node)
57  {
58  std::ostringstream ss;
59 
60  // add namespace name
61  if (SgNamespaceDeclarationStatement* n = isSgNamespaceDeclarationStatement(node))
62  {
63  ss << n->get_qualified_name().str() << "\\n";
64  }
65  // add class name
66  if (SgClassDeclaration* n = isSgClassDeclaration(node))
67  {
68  ss << n->get_qualified_name().str() << "\\n";
69  }
70  // add function name
71  if (SgFunctionDeclaration* n = isSgFunctionDeclaration(node))
72  {
73  ss << n->get_qualified_name().str() << "\\n";
74  }
75  if (SgFunctionRefExp* n = isSgFunctionRefExp(node))
76  {
77  SgFunctionDeclaration* decl = n->getAssociatedFunctionDeclaration();
78  if (decl) // it's null if through a function pointer
79  {
80  ss << decl->get_qualified_name().str() << "\\n";
81  }
82  }
83  // add variable name
84  if (SgInitializedName* n = isSgInitializedName(node))
85  {
86  ss << n->get_qualified_name().str() << "\\n";
87  }
88  if (SgVarRefExp* n = isSgVarRefExp(node))
89  {
90  SgVariableSymbol* sym = n->get_symbol();
91  ss << sym->get_name().getString() << "\\n";
92  }
93  // add variable name
94  if (SgVariableSymbol* n = isSgVariableSymbol(node))
95  {
96  ss << n->get_name().str() << "\\n";
97  }
98 
99  return ss.str();
100  }
101 #endif
102  };
103 
105  {
106  std::string operator()(SgNode* node)
107  {
108  std::ostringstream ss;
109 
110  ss << node << "\\n";
111 
112  return ss.str();
113  }
114  };
115 
117  {
118  std::string operator()(SgNode* node)
119  {
120  std::ostringstream ss;
121  // print number of max successors (= container size)
122  AstSuccessorsSelectors::SuccessorsContainer c;
123  AstSuccessorsSelectors::selectDefaultSuccessors(node,c);
124  ss << c.size() << "\\n";
125 
126  return ss.str();
127  }
128  };
129 
130  struct ROSE_DLL_API LValueExtraNodeInfo
131  {
132 #if 1
133  // DQ (6/25/2011): Put the function definition into the source file (avoid function definitions in header files).
134  std::string operator()(SgNode* node);
135 #else
136  // std::string AstDOTGenerationExtended_Defaults::LValueExtraNodeInfo::operator()(SgNode* node)
137  std::string operator()(SgNode* node)
138  {
139  std::ostringstream ss;
140 
141  // adds whether or not it is an l-value
142  if (SgExpression* n = isSgExpression(node))
143  {
144  ss << (n->isLValue() ? "L-Value" : "!L-Value") << "\\n";
145  }
146 
147  return ss.str();
148  }
149 #endif
150  };
151 
152  struct ROSE_DLL_API TypeExtraNodeInfo
153  {
154 #if 1
155  // DQ (6/25/2011): Put the function definition into the source file (avoid function definitions in header files).
156  std::string operator()(SgNode* node);
157 #else
158  // std::string AstDOTGenerationExtended_Defaults::TypeExtraNodeInfo::operator()(SgNode* node)
159  std::string operator()(SgNode* node)
160  {
161  std::ostringstream ss;
162 
163  if (SgExpression* n = isSgExpression(node))
164  {
165  ss << n->get_type()->unparseToString() << "\\n";
166  }
167 
168  return ss.str();
169  }
170 #endif
171  };
172 
174  {
175  std::string operator()(SgNode* node)
176  {
178  NamedExtraNodeInfo name;
180  return std::string("\\n") + cs(node) + name(node) + add(node);
181  }
182  };
183 
184 
186  {
187  std::string operator()(SgNode* node)
188  {
189  return std::string();
190  }
191  };
192 
194  {
195  std::string operator()(SgNode* from, SgNode* to, std::string label)
196  {
197  return std::string();
198  }
199  };
200 
202  {
203  std::string operator()(SgNode* node, SgNode* to, std::string label)
204  {
205  return std::string();
206  }
207  };
208 }
209 
210 // King84 (14/7/2010) added mechanism to customize node options on demand
211 // Note: aditionalEdgeInfo andadditionalEdgeOptions are inherited.
212 // Note: EdgeInfo and EdgeOptions are not used because they come into play
213 // for functions in the base class which are not virtual.
214 template <typename ExtraNodeInfo_t = AstDOTGenerationExtended_Defaults::DefaultExtraNodeInfo,
215  typename ExtraNodeOptions_t = AstDOTGenerationExtended_Defaults::DefaultExtraNodeOptions,
219  {
220  protected:
221  ExtraNodeInfo_t eni;
222  ExtraNodeOptions_t eno;
223  ExtraEdgeInfo_t eei;
224  ExtraEdgeOptions_t eeo;
225  public:
226  AstDOTGenerationExtended(ExtraNodeInfo_t eni_ = ExtraNodeInfo_t(), ExtraNodeOptions_t eno_ = ExtraNodeOptions_t(), ExtraEdgeInfo_t eei_ = ExtraEdgeInfo_t(), ExtraEdgeOptions_t eeo_ = ExtraEdgeOptions_t())
227  : eni(eni_), eno(eno_), eei(eei_), eeo(eeo_)
228  { }
229  // virtual DOTInheritedAttribute evaluateInheritedAttribute(SgNode* node, DOTInheritedAttribute ia);
230  virtual DOTSynthesizedAttribute evaluateSynthesizedAttribute(SgNode* node, DOTInheritedAttribute ia, SubTreeSynthesizedAttributes l);
231  };
232 
233 #endif
234 
This class represents the concept of a class declaration statement. It includes the concept of an ins...
This class defines the DOT output (graphical representation) of the AST.
This class represents a source file for a project (which may contian many source files and or directo...
This class represents the notion of a declared variable.
This class represents the concept of a function declaration statement.
This class represents the notion of an expression. Expressions are derived from SgLocatedNodes, since similar to statement, expressions have a concrete location within the user's source code.
This class represents the base class for all IR nodes within Sage III.
Definition: Cxx_Grammar.h:8322
This class represents the concept of a variable name within the compiler (a shared container for the ...
This class represents the concept of a C++ namespace declaration.
SgName get_name() const ROSE_OVERRIDE
Access function for getting name from declarations or types internally.
This class represents the variable refernece in expressions.
This class defines the DOT output (graphical representation) of the AST.
This class represents the function being called and must be assembled in the SgFunctionCall with the ...
This class represents a source project, with a list of SgFile objects and global information about th...
This class defines the DOT output (graphical representation) of the AST.