15 #ifndef ROOT__RSCANNER_H__
16 #define ROOT__RSCANNER_H__
20 #include "clang/AST/AST.h"
21 #include "clang/AST/ASTContext.h"
22 #include "clang/AST/DeclGroup.h"
23 #include "clang/AST/DeclFriend.h"
24 #include "clang/AST/Type.h"
25 #include "clang/AST/RecursiveASTVisitor.h"
27 #include "llvm/IR/Module.h"
29 #include "TClingUtils.h"
32 class ClassTemplatePartialSpecializationDecl;
33 class ClassTemplateDecl;
43 class BaseSelectionRule;
44 class ClassSelectionRule;
46 class RScanner:
public clang::RecursiveASTVisitor<RScanner>
49 bool shouldVisitDecl(clang::NamedDecl *D);
52 class AnnotatedNamespaceDecl {
54 AnnotatedNamespaceDecl(clang::NamespaceDecl *decl,
long index,
bool rRequestOnlyTClass) :
55 fDecl(decl), fRuleIndex(index), fRequestOnlyTClass(rRequestOnlyTClass){}
56 AnnotatedNamespaceDecl() { }
57 bool RequestOnlyTClass()
const {
return fRequestOnlyTClass; }
58 const clang::NamespaceDecl* GetNamespaceDecl()
const {
return fDecl; }
59 operator clang::NamespaceDecl
const *()
const {
return fDecl; }
60 bool operator<(
const AnnotatedNamespaceDecl& right) {
return fRuleIndex < right.fRuleIndex; }
62 const clang::NamespaceDecl *fDecl;
64 bool fRequestOnlyTClass;
67 typedef std::vector<AnnotatedNamespaceDecl> NamespaceColl_t;
68 typedef std::vector<ROOT::TMetaUtils::AnnotatedRecordDecl> ClassColl_t;
69 typedef std::vector<const clang::TypedefNameDecl*> TypedefColl_t;
70 typedef std::vector<const clang::FunctionDecl*> FunctionColl_t;
71 typedef std::vector<const clang::VarDecl*> VariableColl_t;
72 typedef std::vector<const clang::EnumDecl*> EnumColl_t;
73 typedef void (*DeclCallback)(
const clang::RecordDecl*);
74 typedef std::map<const clang::Decl*,const BaseSelectionRule*> DeclsSelRulesMap_t;
76 enum class EScanType : char {kNormal, kTwoPasses, kOnePCM};
78 RScanner (SelectionRules &rules,
80 const cling::Interpreter &interpret,
81 ROOT::TMetaUtils::TNormalizedCtxt &normCtxt,
82 unsigned int verbose = 0);
85 bool shouldVisitTemplateInstantiations()
const {
return true; }
88 bool TraverseStmt(clang::Stmt*) {
return true; }
91 bool TraverseClassTemplatePartialSpecializationDecl(clang::ClassTemplatePartialSpecializationDecl*) {
return true; }
93 bool VisitEnumDecl(clang::EnumDecl* D);
94 bool VisitFieldDecl(clang::FieldDecl* D);
95 bool VisitFunctionDecl(clang::FunctionDecl* D);
96 bool VisitNamespaceDecl(clang::NamespaceDecl* D);
97 bool VisitRecordDecl(clang::RecordDecl* D);
98 bool VisitTypedefNameDecl(clang::TypedefNameDecl* D);
99 bool VisitVarDecl(clang::VarDecl* D);
101 bool TreatRecordDeclOrTypedefNameDecl(clang::TypeDecl* typeDecl);
102 void AddDelayedAnnotatedRecordDecls();
104 bool TraverseDeclContextHelper(clang::DeclContext *DC);
108 DeclCallback SetRecordDeclCallback(DeclCallback callback);
111 void Scan(
const clang::ASTContext &C);
114 bool GetDeclName(clang::Decl* D, std::string& name)
const;
115 static bool GetDeclQualName(
const clang::Decl* D, std::string& qual_name);
116 bool GetFunctionPrototype(clang::Decl* D, std::string& prototype)
const;
118 static const char* fgClangDeclKey;
119 static const char* fgClangFuncKey;
121 const DeclsSelRulesMap_t& GetDeclsSelRulesMap()
const {
return fDeclSelRuleMap;};
124 ClassColl_t fSelectedClasses;
125 NamespaceColl_t fSelectedNamespaces;
126 TypedefColl_t fSelectedTypedefs;
127 FunctionColl_t fSelectedFunctions;
128 VariableColl_t fSelectedVariables;
129 EnumColl_t fSelectedEnums;
131 struct DelayedAnnotatedRecordDeclInfo {
132 const ClassSelectionRule *fSelected;
133 const clang::ClassTemplateSpecializationDecl *fDecl;
134 const clang::TypedefNameDecl* fTypedefNameDecl;
136 std::vector<DelayedAnnotatedRecordDeclInfo> fDelayedAnnotatedRecordDecls;
138 virtual ~RScanner ();
144 int AddAnnotatedRecordDecl(
const ClassSelectionRule*,
146 const clang::RecordDecl*,
148 const clang::TypedefNameDecl*,
149 unsigned int indexOffset=0);
150 std::string ConvTemplateArguments(
const clang::TemplateArgumentList& list)
const;
151 std::string ConvTemplateName(clang::TemplateName& N)
const;
152 std::string ConvTemplateParameterList(clang::TemplateParameterList* list)
const;
153 std::string ConvTemplateParams(clang::TemplateDecl* D)
const;
154 void DeclInfo(clang::Decl* D)
const;
155 std::string ExprToStr(clang::Expr* expr)
const;
156 std::string FuncParameterList(clang::FunctionDecl* D)
const;
157 std::string FuncParameters(clang::FunctionDecl* D)
const;
158 std::string GetEnumName(clang::EnumDecl* D)
const;
159 std::string GetLocation(clang::Decl* D)
const;
160 std::string GetName(clang::Decl* D)
const;
161 std::string GetSrcLocation(clang::SourceLocation L)
const;
162 unsigned int FuncModifiers(clang::FunctionDecl* D)
const;
163 unsigned int fVerboseLevel;
164 unsigned int VarModifiers(clang::VarDecl* D)
const;
165 unsigned int Visibility(clang::Decl* D)
const;
166 unsigned int VisibilityModifiers(clang::AccessSpecifier access)
const;
167 void ShowError(
const std::string &msg,
const std::string &location =
"")
const;
168 void ShowInfo(
const std::string &msg,
const std::string &location =
"")
const;
169 void ShowTemplateInfo(
const std::string &msg,
const std::string &location =
"")
const;
170 void ShowWarning(
const std::string &msg,
const std::string &location =
"")
const;
171 static std::map <clang::Decl*, std::string> fgAnonymousClassMap;
172 static std::map <clang::Decl*, std::string> fgAnonymousEnumMap;
173 void UnexpectedDecl(clang::Decl* D,
const std::string &txt =
"")
const;
174 void UnimplementedDecl(clang::Decl* D,
const std::string &txt =
"");
175 void UnimportantDecl(clang::Decl* D,
const std::string &txt =
"")
const;
176 void UnknownDecl(clang::Decl* D,
const std::string &txt =
"")
const;
177 void UnknownType(clang::QualType qual_type)
const;
178 void UnsupportedDecl(clang::Decl* D,
const std::string &txt =
"")
const;
179 void UnsupportedType(clang::QualType qual_type)
const;
181 const clang::SourceManager* fSourceManager;
182 const cling::Interpreter &fInterpreter;
183 static const int fgDeclLast = clang::Decl::Var;
184 static const int fgTypeLast = clang::Type::TemplateTypeParm;
185 bool fDeclTable [ fgDeclLast+1 ];
186 clang::Decl * fLastDecl;
187 DeclCallback fRecordDeclCallback;
188 bool fTypeTable [ fgTypeLast+1 ];
189 static int fgAnonymousClassCounter;
190 static int fgAnonymousEnumCounter;
191 static int fgBadClassCounter;
192 ROOT::TMetaUtils::TNormalizedCtxt &fNormCtxt;
193 SelectionRules &fSelectionRules;
194 std::set<clang::RecordDecl*> fselectedRecordDecls;
197 DeclsSelRulesMap_t fDeclSelRuleMap;