-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInfoCollector.h
65 lines (48 loc) · 1.48 KB
/
InfoCollector.h
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
63
64
65
class InfoCollectorRecursiveASTVisitor
: public RecursiveASTVisitor<InfoCollectorRecursiveASTVisitor>
{
public:
CallExpr *firstFunctionCall=nullptr;
InfoCollectorRecursiveASTVisitor(Rewriter &R) : Rewrite(R) { }
bool VisitCallExpr(CallExpr *E);
void InstrumentStmt(Stmt *s);
bool VisitStmt(Stmt *s);
bool VisitFunctionDecl(FunctionDecl *f);
Rewriter &Rewrite;
};
bool InfoCollectorRecursiveASTVisitor::VisitCallExpr(CallExpr *E)
{
if(firstFunctionCall==nullptr){
firstFunctionCall = E;
for(int i=0, j=E->getNumArgs(); i<j; i++)
{
argument_list.push_back(((DeclRefExpr*)E->getArg(i))->getNameInfo().getName().getAsString());
argument_type.push_back(((DeclRefExpr*)E->getArg(i))->getDecl()->getType().getAsString());
}
}
return true;
}
bool InfoCollectorRecursiveASTVisitor::VisitStmt(Stmt *s)
{
return true; // returning false aborts the traversal
}
bool InfoCollectorRecursiveASTVisitor::VisitFunctionDecl(FunctionDecl *f)
{
return true; // returning false aborts the traversal
}
class InfoCollectorConsumer : public ASTConsumer
{
public:
InfoCollectorConsumer(Rewriter &Rewrite) : rv(Rewrite) { }
virtual bool HandleTopLevelDecl(DeclGroupRef d);
InfoCollectorRecursiveASTVisitor rv;
};
bool InfoCollectorConsumer::HandleTopLevelDecl(DeclGroupRef d)
{
typedef DeclGroupRef::iterator iter;
for (iter b = d.begin(), e = d.end(); b != e; ++b)
{
rv.TraverseDecl(*b);
}
return true; // keep going
}