<p dir="ltr">The most awesomest way would be to send a patch for the docs :D otherwise this is the right venue. Thanks for reporting! </p>
<div class="gmail_quote">On Jul 22, 2014 2:08 AM, "Anwar Ludin" <<a href="mailto:anwar.ludin@gmail.com">anwar.ludin@gmail.com</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div style="word-wrap:break-word">OK finally managed to compile the code in the tutorial.<div><br></div><div>The errors are probably due to Clang API changes. Is there a way to notify the clang guys so that they update the tutorial in order to reflect the latest API?</div>
<div><br></div><div>-  needed to add the include: <span style="font-family:Menlo;font-size:11px">#include "clang/AST/ASTContext.h"</span></div><div><br></div><div>- Changed FindNamedClassAction::CreateASTConsumer() to return a std::unique_ptr<ASTConsumer> instead of a raw pointer ASTConsumer*.</div>
<div><br></div><div>- Here is the updated code:</div><div><br></div><div><div style="margin:0px;font-size:11px;font-family:Menlo;color:rgb(209,47,27)"><span style="color:#78492a">#include </span>"clang/AST/ASTContext.h"</div>
<div style="margin:0px;font-size:11px;font-family:Menlo;color:rgb(209,47,27)"><span style="color:#78492a">#include </span>"clang/AST/ASTConsumer.h"</div><div style="margin:0px;font-size:11px;font-family:Menlo;color:rgb(209,47,27)">
<span style="color:#78492a">#include </span>"clang/AST/RecursiveASTVisitor.h"</div><div style="margin:0px;font-size:11px;font-family:Menlo;color:rgb(209,47,27)"><span style="color:#78492a">#include </span>"clang/Frontend/CompilerInstance.h"</div>
<div style="margin:0px;font-size:11px;font-family:Menlo;color:rgb(209,47,27)"><span style="color:#78492a">#include </span>"clang/Frontend/FrontendAction.h"</div><div style="margin:0px;font-size:11px;font-family:Menlo;color:rgb(209,47,27)">
<span style="color:#78492a">#include </span>"clang/Tooling/Tooling.h"</div><div style="margin:0px;font-size:11px;font-family:Menlo;min-height:13px"><br></div><div style="margin:0px;font-size:11px;font-family:Menlo;color:rgb(187,44,162)">
using<span style="color:#000000"> </span>namespace<span style="color:#000000"> clang;</span></div><div style="margin:0px;font-size:11px;font-family:Menlo;min-height:13px"><br></div><div style="margin:0px;font-size:11px;font-family:Menlo">
<span style="color:#bb2ca2">class</span> FindNamedClassVisitor</div><div style="margin:0px;font-size:11px;font-family:Menlo">  : <span style="color:#bb2ca2">public</span> RecursiveASTVisitor<FindNamedClassVisitor> {</div>
<div style="margin:0px;font-size:11px;font-family:Menlo;color:rgb(187,44,162)">public<span style="color:#000000">:</span></div><div style="margin:0px;font-size:11px;font-family:Menlo">  <span style="color:#bb2ca2">explicit</span> FindNamedClassVisitor(ASTContext *Context)</div>
<div style="margin:0px;font-size:11px;font-family:Menlo">    : Context(Context) {}</div><div style="margin:0px;font-size:11px;font-family:Menlo;min-height:13px"><br></div><div style="margin:0px;font-size:11px;font-family:Menlo">
  <span style="color:#bb2ca2">bool</span> VisitCXXRecordDecl(CXXRecordDecl *Declaration) {</div><div style="margin:0px;font-size:11px;font-family:Menlo">    <span style="color:#bb2ca2">if</span> (Declaration->getQualifiedNameAsString() == <span style="color:#d12f1b">"n::m::C"</span>) {</div>
<div style="margin:0px;font-size:11px;font-family:Menlo">      FullSourceLoc FullLocation = Context->getFullLoc(Declaration->getLocStart());</div><div style="margin:0px;font-size:11px;font-family:Menlo">      <span style="color:#bb2ca2">if</span> (FullLocation.isValid())</div>
<div style="margin:0px;font-size:11px;font-family:Menlo">        llvm::outs() << <span style="color:#d12f1b">"Found declaration at "</span></div><div style="margin:0px;font-size:11px;font-family:Menlo">                     << FullLocation.getSpellingLineNumber() << <span style="color:#d12f1b">":"</span></div>
<div style="margin:0px;font-size:11px;font-family:Menlo">                     << FullLocation.getSpellingColumnNumber() << <span style="color:#d12f1b">"\n"</span>;</div><div style="margin:0px;font-size:11px;font-family:Menlo">
    }</div><div style="margin:0px;font-size:11px;font-family:Menlo;color:rgb(187,44,162)"><span style="color:#000000">    </span>return<span style="color:#000000"> </span>true<span style="color:#000000">;</span></div><div style="margin:0px;font-size:11px;font-family:Menlo">
  }</div><div style="margin:0px;font-size:11px;font-family:Menlo;min-height:13px"><br></div><div style="margin:0px;font-size:11px;font-family:Menlo;color:rgb(187,44,162)">private<span style="color:#000000">:</span></div><div style="margin:0px;font-size:11px;font-family:Menlo">
  ASTContext *Context;</div><div style="margin:0px;font-size:11px;font-family:Menlo">};</div><div style="margin:0px;font-size:11px;font-family:Menlo;min-height:13px"><br></div><div style="margin:0px;font-size:11px;font-family:Menlo">
<span style="color:#bb2ca2">class</span> FindNamedClassConsumer : <span style="color:#bb2ca2">public</span> clang::ASTConsumer {</div><div style="margin:0px;font-size:11px;font-family:Menlo;color:rgb(187,44,162)">public<span style="color:#000000">:</span></div>
<div style="margin:0px;font-size:11px;font-family:Menlo">  <span style="color:#bb2ca2">explicit</span> FindNamedClassConsumer(ASTContext *Context)</div><div style="margin:0px;font-size:11px;font-family:Menlo">    : Visitor(Context) {}</div>
<div style="margin:0px;font-size:11px;font-family:Menlo;min-height:13px"><br></div><div style="margin:0px;font-size:11px;font-family:Menlo">  <span style="color:#bb2ca2">virtual</span> <span style="color:#bb2ca2">void</span> HandleTranslationUnit(clang::ASTContext &Context) {</div>
<div style="margin:0px;font-size:11px;font-family:Menlo">    Visitor.TraverseDecl(Context.getTranslationUnitDecl());</div><div style="margin:0px;font-size:11px;font-family:Menlo">  }</div><div style="margin:0px;font-size:11px;font-family:Menlo;color:rgb(187,44,162)">
private<span style="color:#000000">:</span></div><div style="margin:0px;font-size:11px;font-family:Menlo">  FindNamedClassVisitor Visitor;</div><div style="margin:0px;font-size:11px;font-family:Menlo">};</div><div style="margin:0px;font-size:11px;font-family:Menlo;min-height:13px">
<br></div><div style="margin:0px;font-size:11px;font-family:Menlo"><span style="color:#bb2ca2">class</span> FindNamedClassAction : <span style="color:#bb2ca2">public</span> clang::ASTFrontendAction {</div><div style="margin:0px;font-size:11px;font-family:Menlo;color:rgb(187,44,162)">
public<span style="color:#000000">:</span></div><div style="margin:0px;font-size:11px;font-family:Menlo">  <span style="color:#bb2ca2">virtual</span> std::unique_ptr<ASTConsumer> CreateASTConsumer(</div><div style="margin:0px;font-size:11px;font-family:Menlo">
    clang::CompilerInstance &Compiler, llvm::StringRef InFile) {</div><div style="margin:0px;font-size:11px;font-family:Menlo">    <span style="color:#bb2ca2">return</span> std::unique_ptr<ASTConsumer>(<span style="color:#bb2ca2">new</span> FindNamedClassConsumer(&Compiler.getASTContext()));</div>
<div style="margin:0px;font-size:11px;font-family:Menlo">  }</div><div style="margin:0px;font-size:11px;font-family:Menlo">};</div><div style="margin:0px;font-size:11px;font-family:Menlo;min-height:13px"><br></div><div style="margin:0px;font-size:11px;font-family:Menlo">
<span style="color:#bb2ca2">int</span> main(<span style="color:#bb2ca2">int</span> argc, <span style="color:#bb2ca2">char</span> **argv) {</div><div style="margin:0px;font-size:11px;font-family:Menlo">  <span style="color:#bb2ca2">if</span> (argc > <span style="color:#272ad8">1</span>) {</div>
<div style="margin:0px;font-size:11px;font-family:Menlo">    clang::tooling::runToolOnCode(<span style="color:#bb2ca2">new</span> FindNamedClassAction, argv[<span style="color:#272ad8">1</span>]);</div><div style="margin:0px;font-size:11px;font-family:Menlo">
  }</div><div style="margin:0px;font-size:11px;font-family:Menlo">}</div></div><div><br></div><div>Corresponding CMakeLists.txt:</div><div><br></div><div><div>set(LLVM_LINK_COMPONENTS support)</div><div>set(LLVM_USED_LIBS clangTooling clangBasic clangAST)</div>
<div><br></div><div>add_clang_executable(find-class-decls FindClassDecls.cpp)</div><div><br></div><div>target_link_libraries(find-class-decls</div><div>  clangTooling</div><div>  clangBasic</div><div>  clangASTMatchers</div>
<div>)</div></div><div><br></div><div><br></div><div><br></div><div><br><div><div>On 21 Jul 2014, at 12:08, Nikola Smiljanic <<a href="mailto:popizdeh@gmail.com" target="_blank">popizdeh@gmail.com</a>> wrote:</div><br>
<blockquote type="cite"><div dir="ltr">Have you read this <a href="http://clang.llvm.org/docs/LibASTMatchersTutorial.html#step-1-create-a-clangtool" target="_blank">http://clang.llvm.org/docs/LibASTMatchersTutorial.html#step-1-create-a-clangtool</a></div>
<div class="gmail_extra">

<br><br><div class="gmail_quote">On Mon, Jul 21, 2014 at 7:12 PM, Anwar Ludin <span dir="ltr"><<a href="mailto:anwar.ludin@gmail.com" target="_blank">anwar.ludin@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">


Hello,<br>
<br>
Sorry if this question has already been asked. I am trying to compile the "How to write RecursiveASTVisitor based ASTFrontedActions" tutorial located here <a href="http://clang.llvm.org/docs/RAVFrontendAction.html" target="_blank">http://clang.llvm.org/docs/RAVFrontendAction.html</a> by using CMake.<br>



<br>
In order to do this, I created a new "mytool" directory in the clang source tree containing the source code provided in the tutorial:<br>
<br>
~/llvm/tools/clang/tools/mytool<br>
<br>
The directory contains the CMakeLists.txt and FindClassDecls.cpp provided in the tutorial.<br>
<br>
I have also updated the CMakeLists.txt file located at ~/llvm/tools/clang/tools/ so that the mytool directory is included in the CMake build process.<br>
<br>
However when I try to build the tool, I get the following errors (I suspect the clangTooling library is not found).<br>
<br>
[ 98%] Building CXX object tools/clang/tools/mytool/CMakeFiles/find-class-decls.dir/FindClassDecls.cpp.o<br>
/Users/aludin/clang-llvm/llvm/tools/clang/tools/mytool/FindClassDecls.cpp:17:43: error: member access into incomplete type<br>
      'clang::ASTContext'<br>
      FullSourceLoc FullLocation = Context->getFullLoc(Declaration->getLocStart());<br>
                                          ^<br>
/Users/aludin/clang-llvm/llvm/tools/clang/include/clang/AST/ASTConsumer.h:20:9: note: forward declaration of<br>
      'clang::ASTContext'<br>
  class ASTContext;<br>
        ^<br>
/Users/aludin/clang-llvm/llvm/tools/clang/tools/mytool/FindClassDecls.cpp:36:33: error: member access into incomplete type<br>
      'clang::ASTContext'<br>
    Visitor.TraverseDecl(Context.getTranslationUnitDecl());<br>
                                ^<br>
/Users/aludin/clang-llvm/llvm/tools/clang/include/clang/AST/ASTConsumer.h:20:9: note: forward declaration of<br>
      'clang::ASTContext'<br>
  class ASTContext;<br>
        ^<br>
/Users/aludin/clang-llvm/llvm/tools/clang/tools/mytool/FindClassDecls.cpp:44:31: error: virtual function 'CreateASTConsumer'<br>
      has a different return type ('clang::ASTConsumer *') than the function it overrides (which has return type<br>
      'std::unique_ptr<ASTConsumer>')<br>
  virtual clang::ASTConsumer *CreateASTConsumer(<br>
                              ^<br>
/Users/aludin/clang-llvm/llvm/tools/clang/include/clang/Frontend/FrontendAction.h:64:40: note: overridden virtual function is<br>
      here<br>
  virtual std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,<br>
                                       ^<br>
3 errors generated.<br>
make[2]: *** [tools/clang/tools/mytool/CMakeFiles/find-class-decls.dir/FindClassDecls.cpp.o] Error 1<br>
make[1]: *** [tools/clang/tools/mytool/CMakeFiles/find-class-decls.dir/all] Error 2<br>
make: *** [all] Error 2<br>
<br>
Any help on how to build this would be greatly appreciated.<br>
<br>
Thanks!<br>
<br>
Anwar<br>
<br>
<br>
<br>
<br>
<br>
<br>
_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@cs.uiuc.edu" target="_blank">cfe-dev@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev</a><br>
</blockquote></div><br></div>
</blockquote></div><br></div></div><br>_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@cs.uiuc.edu">cfe-dev@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev</a><br>
<br></blockquote></div>