-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsymTabBuilder.h
47 lines (39 loc) · 1.53 KB
/
symTabBuilder.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
/****************************************************************/
/* All rights reserved (it will be changed) */
/* masud.abunaser@mdh.se */
/****************************************************************/
#ifndef LLVM_CLANG_SYMTABBUILDER_H
#define LLVM_CLANG_SYMTABBUILDER_H
#include "clang/AST/RecursiveASTVisitor.h"
#include "clang/AST/ASTContext.h"
#include "clang/Frontend/CompilerInstance.h"
#include "symtab.h"
using namespace llvm;
class SymTabBuilderVisitor : public RecursiveASTVisitor<SymTabBuilderVisitor> {
private:
ASTContext *astContext; // used for getting additional AST info
FunctionDecl *current_f=NULL;
SymTab<SymBase> *symbTab=new SymTab<SymBase>();
int debugLabel;
public:
explicit SymTabBuilderVisitor(CompilerInstance *CI, int dl)
: astContext(&(CI->getASTContext())), debugLabel(dl) {}
void dumpSymTab();
inline SymTab<SymBase> *getSymTab(){return symbTab;}
bool VisitFunctionDecl(FunctionDecl *func);
bool VisitVarDecl(VarDecl *vdecl);
};
class SymTabBuilder : public ASTConsumer{
private:
SymTabBuilderVisitor *visitor; // doesn't have to be private
public:
// override the constructor in order to pass CI
explicit SymTabBuilder(CompilerInstance *CI, int dl)
: visitor(new SymTabBuilderVisitor(CI,dl)) // initialize the visitor
{}
virtual void HandleTranslationUnit(ASTContext &Context) {
visitor->TraverseDecl(Context.getTranslationUnitDecl());
visitor->dumpSymTab();
}
};
#endif