v8toolkit  0.0.1
Utility library for embedding V8 Javascript engine in a c++ program
ast_consumer.cpp
Go to the documentation of this file.
1 
2 #include "ast_consumer.h"
3 
4 using namespace clang::ast_matchers;
5 
6 
7 MyASTConsumer::MyASTConsumer(CompilerInstance & ci) :
8  HandlerForClass(ci), ci(ci) {
9 
10 #ifdef TEMPLATE_INFO_ONLY
11 
12 Matcher.addMatcher(decl(anyOf(
13  classTemplateSpecializationDecl().bind("class"),
14  cxxMethodDecl().bind("method")
15  )),
16  &HandlerForClass);
17 
18 #else
19  Matcher.addMatcher(cxxRecordDecl(
20  allOf(
21  // skip classes from v8toolkit::JSWrapper
22  unless(isDerivedFrom("::v8toolkit::JSWrapper")), // JS-Classes will be completely regenerated
23 
24  // must be a struct or class
25  anyOf(isStruct(), isClass()),
26  anyOf( // order of these matters. If a class matches more than one it will only be returned as the first
27 
28 
29  allOf(isDefinition(),
30  cxxRecordDecl(isDerivedFrom("::v8toolkit::WrappedClassBase")).bind("class derived from WrappedClassBase")),
31 
32  // mark a type you control with the wrapped class attribute
33  allOf(isDefinition(),
34  unless(matchesName("^::std::")),
35  cxxRecordDecl(/*hasAttr(attr::Annotate)*/).bind("not std:: class")),
36 
37  // used for marking types not under your control with the wrapped class attribute
38  allOf(unless(isDefinition()),
39  unless(matchesName("^::std::")),
40  cxxRecordDecl(hasAttr(attr::Annotate)).bind("forward declaration with annotation"))
41  )
42  )), &HandlerForClass);
43 
44  Matcher.addMatcher(
45  namedDecl(
46  allOf(
47  hasAttr(attr::Annotate), // must have V8TOOLKIT_NAME_ALIAS set
48  unless(matchesName("^::std::")),
49  unless(matchesName("^::__")
50  )
51  )
52  ).bind("named decl"), &HandlerForClass);
53 #endif
54 
55 }
MyASTConsumer(CompilerInstance &CI)
Definition: ast_consumer.cpp:7
func::function< R(Args...)> bind(CLASS &object, R(METHOD_CLASS::*method)(Args...))
Definition: v8toolkit.h:855