ASTs from multiple sources

Dear Sir/Madam,

I am using clang to get the AST of a source file and then traverse it. However, if you compile more than one files with clang invokes the compiler multiple times and so the ASTs of the files cannot be shared. I have found a solution to the web using indexes and *.pch files. The code is the following:

    //visit AST
  CXChildVisitResult TranslationUnitVisitor(CXCursor cursor, CXCursor parent, CXClientData data)
  {
return CXChildVisit_Recurse; // visit complete AST recursivly
  }

    // excludeDeclsFromPCH = 1, displayDiagnostics=1
    CXIndex cx_idx = clang_createIndex(1, 1);

  // test.pch was produced with the following command:
  // "clang -x c test.h -emit-ast -o test.pch"
  CXTranslationUnit TU = clang_createTranslationUnit(cx_idx, "test.pch");

  // This will load all the symbols from 'test.pch'
  clang_visitChildren(clang_getTranslationUnitCursor(TU), TranslationUnitVisitor, 0);
  clang_disposeTranslationUnit(TU);

  // This will load all the symbols from 'test.c', excluding symbols
  // from 'test.pch'.
  char *args[] = { "-Xclang", "-include-pch=test.pch" };
  TU = clang_createTranslationUnitFromSourceFile(cx_idx, "test.c", 2, args, 0, 0);

  //clang_visitChildren(clang_getTranslationUnitCursor(TU), TranslationUnitVisitor,0);
  clang_disposeTranslationUnit(TU);

My problems is that it does not compile and I cannot understand why, since this is a standard code taken from http://wiki.ifs.hsr.ch/SemProgAnTr/files/Clang_Architecture_-ChristopherGuntli.pdf page 10. A similar code is also here:http://clang.llvm.org/doxygen/group_CINDEX.html#ga51eb9b38c18743bf2d824c6230e61f93.

The error I am getting is the following:

Checker.cpp:211:85: error: argument of type ‘CXChildVisitResult ({anonymous}::TypeCheckingConsumer::)(CXCursor, CXCursor, CXClientData) {aka CXChildVisitResult ({anonymous}::TypeCheckingConsumer::)(CXCursor, CXCursor, void*)}’ does not match ‘CXCursorVisitor {aka CXChildVisitResult ()(CXCursor, CXCursor, void)}’

I would be greatful for your help with this.

Socrates

That error message is terrible, but you're trying to pass a member
function as a function pointer, which isn't allowed in C++.

-Eli