forked from rose-compiler/rose
-
Notifications
You must be signed in to change notification settings - Fork 0
/
abstractHandle1.cpp
62 lines (49 loc) · 1.61 KB
/
abstractHandle1.cpp
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/*
Example code to generate abstract handles for language constructs
by Liao, 10/6/2008
*/
#include "rose.h"
#include <iostream>
#include "abstract_handle.h"
#include "roseAdapter.h"
#include <string.h>
using namespace std;
using namespace AbstractHandle;
// a global handle for the current file
static abstract_handle* file_handle = NULL;
class visitorTraversal : public AstSimpleProcessing
{
protected:
virtual void visit(SgNode* n);
};
void visitorTraversal::visit(SgNode* n)
{
SgForStatement* forloop = isSgForStatement(n);
if (forloop)
{
cout<<"Creating handles for a loop construct..."<<endl;
//Create an abstract node
abstract_node* anode= buildroseNode(forloop);
//Create an abstract handle from the abstract node
//Using source position specifiers by default
abstract_handle * ahandle = new abstract_handle(anode);
cout<<ahandle->toString()<<endl;
// Create handles based on numbering specifiers within the file
abstract_handle * bhandle = new abstract_handle(anode,e_numbering,file_handle);
cout<<bhandle->toString()<<endl<<endl;
}
}
int main(int argc, char * argv[])
{
// Initialize and check compatibility. See Rose::initialize
ROSE_INITIALIZE;
SgProject *project = frontend (argc, argv);
//Generate a file handle
abstract_node * file_node = buildroseNode((project->get_fileList())[0]);
file_handle = new abstract_handle(file_node);
//Generate handles for language constructs
visitorTraversal myvisitor;
myvisitor.traverseInputFiles(project,preorder);
// Generate source code from AST and call the vendor's compiler
return backend(project);
}