forked from rose-compiler/rose
-
Notifications
You must be signed in to change notification settings - Fork 0
/
classicObjectOrientedVisitorPatternMemoryPoolTraversal.C
47 lines (38 loc) · 1.32 KB
/
classicObjectOrientedVisitorPatternMemoryPoolTraversal.C
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include "rose.h"
// Classic Visitor Pattern in ROSE (implemented using the traversal over
// the elements stored in the memory pools so it has no cycles and visits
// ALL IR nodes (including all Sg_File_Info, SgSymbols, SgTypes, and the
// static builtin SgTypes).
class ClassicVisitor : public ROSE_VisitorPattern
{
public:
// Override virtural function defined in base class
void visit(SgGlobal* globalScope)
{
printf ("Found the SgGlobal IR node \n");
}
void visit(SgFunctionDeclaration* functionDeclaration)
{
printf ("Found a SgFunctionDeclaration IR node \n");
}
void visit(SgTypeInt* intType)
{
printf ("Found a SgTypeInt IR node \n");
}
void visit(SgTypeDouble* doubleType)
{
printf ("Found a SgTypeDouble IR node \n");
}
};
int
main ( int argc, char* argv[] )
{
// Initialize and check compatibility. See Rose::initialize
ROSE_INITIALIZE;
SgProject* project = frontend(argc,argv);
ROSE_ASSERT (project != NULL);
// Classic visitor pattern over the memory pool of IR nodes
ClassicVisitor visitor_A;
traverseMemoryPoolVisitorPattern(visitor_A);
return backend(project);
}