<p style="margin:0px 0px 1em;padding:0px;border:0px;font-size:14px;vertical-align:baseline;background-color:rgb(255,255,255);clear:both;word-wrap:break-word;font-family:Arial,'Liberation Sans','DejaVu Sans',sans-serif;line-height:18px;text-align:left">
Dear Sir/Madam,</p><p style="margin:0px 0px 1em;padding:0px;border:0px;font-size:14px;vertical-align:baseline;background-color:rgb(255,255,255);clear:both;word-wrap:break-word;font-family:Arial,'Liberation Sans','DejaVu Sans',sans-serif;line-height:18px;text-align:left">
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:</p>
<pre style="margin-top:0px;margin-bottom:10px;padding:5px;border:0px;font-size:14px;vertical-align:baseline;background-color:rgb(238,238,238);font-family:Consolas,Menlo,Monaco,'Lucida Console','Liberation Mono','DejaVu Sans Mono','Bitstream Vera Sans Mono','Courier New',monospace,serif;overflow:auto;width:auto;max-height:600px;line-height:18px;text-align:left">
<code style="margin:0px;padding:0px;border:0px;vertical-align:baseline;font-family:Consolas,Menlo,Monaco,'Lucida Console','Liberation Mono','DejaVu Sans Mono','Bitstream Vera Sans Mono','Courier New',monospace,serif">    //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);
</code></pre><p style="margin:0px 0px 1em;padding:0px;border:0px;font-size:14px;vertical-align:baseline;background-color:rgb(255,255,255);clear:both;word-wrap:break-word;font-family:Arial,'Liberation Sans','DejaVu Sans',sans-serif;line-height:18px;text-align:left">
My problems is that it does not compile and I cannot understand why, since this is a standard code taken from <a href="http://wiki.ifs.hsr.ch/SemProgAnTr/files/Clang_Architecture_-_ChristopherGuntli.pdf" rel="nofollow" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(74,107,130);text-decoration:none">http://wiki.ifs.hsr.ch/SemProgAnTr/files/Clang_Architecture_-<em style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">ChristopherGuntli.pdf</em></a><em style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent"> page 10. A similar code is also here:<a href="http://clang.llvm.org/doxygen/group__CINDEX.html#ga51eb9b38c18743bf2d824c6230e61f93" rel="nofollow" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(74,107,130);text-decoration:none">http://clang.llvm.org/doxygen/group</a></em><a href="http://clang.llvm.org/doxygen/group__CINDEX.html#ga51eb9b38c18743bf2d824c6230e61f93" rel="nofollow" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(74,107,130);text-decoration:none">_CINDEX.html#ga51eb9b38c18743bf2d824c6230e61f93</a>.</p>
<p style="margin:0px 0px 1em;padding:0px;border:0px;font-size:14px;vertical-align:baseline;background-color:rgb(255,255,255);clear:both;word-wrap:break-word;font-family:Arial,'Liberation Sans','DejaVu Sans',sans-serif;line-height:18px;text-align:left">
The error I am getting is the following:</p><p style="margin:0px 0px 1em;padding:0px;border:0px;font-size:14px;vertical-align:baseline;background-color:rgb(255,255,255);clear:both;word-wrap:break-word;font-family:Arial,'Liberation Sans','DejaVu Sans',sans-serif;line-height:18px;text-align:left">
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 (<em style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">)(CXCursor, CXCursor, void</em>)}’</p>
<p style="margin:0px 0px 1em;padding:0px;border:0px;font-size:14px;vertical-align:baseline;background-color:rgb(255,255,255);clear:both;word-wrap:break-word;font-family:Arial,'Liberation Sans','DejaVu Sans',sans-serif;line-height:18px;text-align:left">
I would be greatful for your help with this.</p><p style="margin:0px 0px 1em;padding:0px;border:0px;font-size:14px;vertical-align:baseline;background-color:rgb(255,255,255);clear:both;word-wrap:break-word;font-family:Arial,'Liberation Sans','DejaVu Sans',sans-serif;line-height:18px;text-align:left">
Socrates</p>