@@ -45,35 +45,33 @@ namespace {
4545class TypeDefCallback : public MatchFinder ::MatchCallback {
4646 public:
4747
48-
49- // This routine will get called for each thing that the matchers find.
50- virtual void run (const MatchFinder::MatchResult &Result) {
51-
52- const TypedefType *typeType = Result.Nodes .getNodeAs <TypedefType>(" typeDef" );
53- if (typeType)
54- {
55- builder.registerTypeDef (typeType);
48+ virtual void run (const MatchFinder::MatchResult &Result) {
49+
50+ const TypedefType *T = Result.Nodes .getNodeAs <TypedefType>(" typeDef" );
51+
52+ if (T) {
53+ builder.registerTypeDef (T);
54+ }
5655 }
57- }
5856};
5957
60- class ToolTemplateCallback : public MatchFinder ::MatchCallback {
61- public:
62- // This routine will get called for each thing that the matchers find.
63- virtual void run (const MatchFinder::MatchResult &Result) {
58+ class TypeDeclCallback : public MatchFinder ::MatchCallback {
59+ public:
60+
61+ virtual void run (const MatchFinder::MatchResult &Result) {
62+
63+ const TypeDecl *D = Result.Nodes .getNodeAs <TypeDecl>(" typeDecl" );
64+
65+ if (D) {
6466
65- const TypeDecl *decl = Result.Nodes .getNodeAs <TypeDecl>(" match" );
67+ builder.registerNamedDecl (D);
68+ }
6669
67- if (decl)
68- {
69- builder.registerNamedDecl (decl);
70+ const CXXRecordDecl *DD = Result.Nodes .getNodeAs <CXXRecordDecl>(" typeDecl" );
71+ if (DD) {
72+ builder.registerNamedDecl (DD);
73+ }
7074 }
71-
72- const CXXRecordDecl *D = Result.Nodes .getNodeAs <CXXRecordDecl>(" match" );
73- if (D) {
74- builder.registerNamedDecl (D);
75- }
76- }
7775
7876};
7977} // end anonymous namespace
@@ -88,26 +86,13 @@ int main(int argc, const char **argv) {
8886 // }}}
8987
9088 ast_matchers::MatchFinder Finder;
91- ToolTemplateCallback Callback;
92- TypeDefCallback tdCallback;
93-
94- // AST matching ftw...
95- //
96- // the big table: http://clang.llvm.org/docs/LibASTMatchersReference.html
9789
98- // the "bind" will make the match referencable by the given string in the "run()" mathod of the
99- // callback
100-
101- // the "isDefinition()" is needed to reject "Class Name Injection" and forward
102- // declarations. see https://stackoverflow.com/questions/24761684 and
103- // http://www.open-std.org/jtc1/sc22/wg21/docs/papers/1994/N0444.pdf
90+ TypeDeclCallback typeDeclCallback;
10491 internal::VariadicDynCastAllOfMatcher<Decl, TypeDecl> typeDecl;
105-
106- DeclarationMatcher matcher = typeDecl ().bind (" match" );
107-
108- Finder.addMatcher (matcher, &Callback);
92+ Finder.addMatcher (typeDecl ().bind (" typeDecl" ), &typeDeclCallback);
10993
110- Finder.addMatcher (typedefType ().bind (" typeDef" ), &tdCallback);
94+ TypeDefCallback typeDefCallback;
95+ Finder.addMatcher (typedefType ().bind (" typeDef" ), &typeDefCallback);
11196
11297 if (int retval = Tool.run (newFrontendActionFactory (&Finder)) != 0 ) {
11398 std::cerr << " whoops\n " ;
0 commit comments