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