<html theme="default-dark" iconset="color"><head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body
 text="#000000">
Hi All,<br>
  <br>
I have  c code, below, that I'm trying to visit the AST of by using 
RecursiveASTVisitor. I'm trying to get the RecursiveASTVisitor to visit 
variable declarations (clang::VarDecl) by implementing <code>bool 
VistVarDecl(clang::VarDecl *vardecl)</code>. However, the <code>clang::VarDecl</code>
 nodes are never visited even though I've managed to visit all the other
 nodes in the AST though. Moreover, using <code>clang-query</code> on <code>test1.c</code>
 I <em>can</em> match <code>varDecl</code>.<br>

  <br>
Does anyone know the <code>clang::VarDecl</code> nodes are the only 
nodes that aren't visited by the <code>RecursiveASTVisitor</code> but 
are matched by <code>clang-query</code>?<br>
  <br>
Thanks in advaince!<br>
  <br>
```<code><span class="hljs-function"><span class="hljs-keyword"><br>
double</span> <span class="hljs-title">multiply</span><span 
class="hljs-params">(<span class="hljs-keyword">double</span> x, <span 
class="hljs-keyword">double</span> y)</span> </span>{
  </code>
  <pre class="lang-c s-code-block hljs c"><code>    <span class="hljs-keyword">return</span> x * y * y;
}

<span class="hljs-function"><span class="hljs-keyword">int</span> <span class="hljs-title">main</span><span class="hljs-params">(<span class="hljs-keyword">int</span> argc, <span class="hljs-keyword">char</span> <span class="hljs-keyword">const</span> *argv[])</span>
</span>{
    <span class="hljs-keyword">double</span> a;

    <span class="hljs-keyword">int</span> b;

    <span class="hljs-keyword">float</span> d;

    <span class="hljs-keyword">double</span> x = <span class="hljs-number">3.0</span>;
    <span class="hljs-keyword">double</span> y = <span class="hljs-number">5.0</span>;

    <span class="hljs-keyword">double</span> z = multiply(x,y);

    <span class="hljs-keyword">return</span> <span class="hljs-number">0</span>;
}
```
</code></pre>
My RecursiveASTVisitor is as follows:<br>
```<code><span class="hljs-class"><span class="hljs-keyword"><br>
struct</span> <span class="hljs-title">MyASTVisitor</span> :</span> <span
 class="hljs-keyword">public</span> 
clang::RecursiveASTVistor<MyASTVisitor> {</code><code>
  </code><code></code>
  <pre class="lang-cpp s-code-block hljs"><code>  <span class="hljs-function"><span class="hljs-keyword">bool</span> <span class="hljs-title">VistVarDecl</span><span class="hljs-params">(clang::VarDecl *vardecl)</span> </span>{
     llvm::outs() << <span class="hljs-string">"Found a VarDecl"</span>;
  };

  <span class="hljs-function"><span class="hljs-keyword">bool</span> <span class="hljs-title">VisitFunctionDecl</span><span class="hljs-params">(clang::FunctionDecl *decl)</span> </span>{
     llvm::outs() << <span class="hljs-string">"Found a FunctionDecl"</span>;
  };

  <span class="hljs-comment">// other functions implemented similarly just to see if it visits properly</span>
  <span class="hljs-function"><span class="hljs-keyword">bool</span> <span class="hljs-title">VisitParmVarmDecl</span><span class="hljs-params">(clang::ParmVarDecl *paramvardecl)</span></span>;
  <span class="hljs-function"><span class="hljs-keyword">bool</span> <span class="hljs-title">VisitCallExpr</span><span class="hljs-params">(clang::CallExpr *callexpr)</span></span>;
  <span class="hljs-function"><span class="hljs-keyword">bool</span> <span class="hljs-title">VisitImplicitCastExpr</span><span class="hljs-params">(clang::ImplicitCastExpr *castexpr)</span></span>;
  <span class="hljs-function"><span class="hljs-keyword">bool</span> <span class="hljs-title">VisitBinaryOperator</span><span class="hljs-params">(clang::BinaryOperator *bo)</span></span>;
  <span class="hljs-function"><span class="hljs-keyword">bool</span> <span class="hljs-title">VisitDeclStmt</span><span class="hljs-params">(clang::DeclStmt *declstmt)</span></span>;
  <span class="hljs-function"><span class="hljs-keyword">bool</span> <span class="hljs-title">VisitDeclRefExpr</span><span class="hljs-params">(clang::DeclRefExpr *declrefexpr)</span></span>;
  <span class="hljs-function"><span class="hljs-keyword">bool</span> <span class="hljs-title">VisitFloatingLiteral</span><span class="hljs-params">(clang::FloatingLiteral *floatliteral)</span></span>;
};

<span class="hljs-class"><span class="hljs-keyword">struct</span> <span class="hljs-title">MyASTConsumer</span> :</span> <span class="hljs-keyword">public</span> clang::ASTConsumer {

  <span class="hljs-function"><span class="hljs-keyword">bool</span> <span class="hljs-title">HandleTopLevelDecl</span><span class="hljs-params">(clang::DeclGroupRef DR)</span> <span class="hljs-keyword">override</span> </span>{
    <span class="hljs-keyword">for</span> (clang::DeclGroupRef::iterator b = DR.begin(), e = DR.end(); b != e; ++b) {
        Visitor.TraverseDecl(*b);
     }
     <span class="hljs-keyword">return</span> <span class="hljs-literal">true</span>;
  }
<span class="hljs-keyword">private</span>: 
  MyASTVisitor Visitor;
};
```
</code></pre>
  <br>
  <div class="moz-signature">-- <br>Michael.<br>

  </div>
</body>
</html>