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