<div dir="ltr">Note that 'a' is a VarDecl whereas 'i' is a ParamVarDecl (that derives from VarDecl). Using isa<ParamVarDecl> sounds better to me if all you're trying to do is differentiate between local variables and parameters.</div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Aug 25, 2015 at 11:49 PM, Luca Atzori via cfe-dev <span dir="ltr"><<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi all,<br>
<br>
supposing I have this code:<br>
<br>
void foo(int i){<br>
int a;<br>
a = i;<br>
}<br>
<br>
int main(){<br>
foo(0);<br>
}<br>
<br>
I would like to match all the DeclRefExpr related to the variable a,<br>
but not to the parameter i.<br>
<br>
This is the AST dump of the code<br>
<br>
|-FunctionDecl 0x6261720 <decltest.cu:1:1, line:4:1> line:1:6 used foo 'void (int)'<br>
| |-ParmVarDecl 0x6261698 <col:10, col:14> col:14 used i 'int'<br>
| `-CompoundStmt 0x62618e8 <col:16, line:4:1><br>
| |-DeclStmt 0x6261840 <line:2:2, col:7><br>
| | `-VarDecl 0x62617e0 <col:2, col:6> col:6 used a 'int'<br>
| `-BinaryOperator 0x62618c0 <line:3:2, col:6> 'int' lvalue '='<br>
| |-DeclRefExpr 0x6261858 <col:2> 'int' lvalue Var 0x62617e0 'a' 'int'<br>
| `-ImplicitCastExpr 0x62618a8 <col:6> 'int' <LValueToRValue><br>
| `-DeclRefExpr 0x6261880 <col:6> 'int' lvalue ParmVar 0x6261698 'i' 'int'<br>
`-FunctionDecl 0x6261930 <line:6:1, line:8:1> line:6:5 main 'int (void)'<br>
`-CompoundStmt 0x6261ac0 <col:11, line:8:1><br>
`-CallExpr 0x6261a90 <line:7:2, col:7> 'void'<br>
|-ImplicitCastExpr 0x6261a78 <col:2> 'void (*)(int)' <FunctionToPointerDecay><br>
| `-DeclRefExpr 0x6261a50 <col:2> 'void (int)' lvalue Function 0x6261720 'foo' 'void (int)'<br>
`-IntegerLiteral 0x6261a30 <col:6> 'int' 0<br>
<br>
It seems that I have to exploit the "address" (is it correct?) of the<br>
VarDecl, namely 0x62617e0, that guarantees me that I'm referring<br>
exactly that variable, because I'm not really sure the name will be<br>
enough for avoiding ambiguity.<br>
<br>
I'm using an ASTConsumer, and I have a Stmt* variable representing the<br>
body of the function foo (i'm not using matchers' DSL).<br>
<br>
Any idea on how can i get those addresses? (my guess is something<br>
related to VarDecl class' getASTContext method).<br>
<br>
<br>
Any help would be very much appreciated.<br>
<br>
Luca A.<br>
<br>
<br>
P.S.<br>
<br>
More, hopefully useful, details: my goal is to "vectorize" those variables, so the output must be:<br>
<br>
void foo(int i){<br>
int a[N];<br>
loop(id: 0..N-1){<br>
a[id] = i;<br>
}<br>
}<br>
_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a><br>
</blockquote></div><br></div>