<div dir="ltr">I'm pretty sure you need to get the actual DeclRefExpr node and obtain the ValueDecl from it.</div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Jan 27, 2015 at 10:52 PM, Pedro Delgado Perez <span dir="ltr"><<a href="mailto:pedro.delgadoperez@mail.uca.es" target="_blank">pedro.delgadoperez@mail.uca.es</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

<div>
<p>Hi, I've been trying lots of things to solve this problem, but I have not found the solution yet.<br>
<span lang="en"><span>Nobody</span> <span>has</span> <span>encountered this problem</span> <span>before?</span></span></p>
<p>------------------------------------------------------------------------------------------<br>
In the program I am developing, I search for "ExplicitCastExpr" because I need to print the elements which are being casted. If the program retrieves this expression:</p>
<p style="padding-left:30px">static_cast<KWriteApp *>(kapp);</p>
<p>what I want to print is "kapp".</p>
<p>However, I have found a problem in that situation:<br>- kapp is defined as:<br>#define kapp KApplication::kApplication()</p>
<p>- This is the AST of that expression:</p>
<p style="padding-left:30px"><span style="font-size:8pt">-CXXStaticCastExpr 0x4fcc118 <col:10, col:39> 'class KWriteApp *' static_cast<class KWriteApp *> <BaseToDerived (KApplication)></span><br><span style="font-size:8pt">|       `-CallExpr 0x4fcc0e0 </usr/include/KDE/../kapplication.h:56:14, col:41> 'class KApplication *'</span><br><span style="font-size:8pt">|         `-ImplicitCastExpr 0x4fcc0c8 <col:14, col:28> 'class KApplication *(*)(void)' <FunctionToPointerDecay></span><br><span style="font-size:8pt">|           `-DeclRefExpr 0x4fcc068 <col:14, col:28> 'class KApplication *(void)' lvalue CXXMethod 0x7f4c9d3c2fe0 'kApplication' 'class KApplication *(void)'</span></p>
<p>As you can observe, "kapp" does not appear explicitly in the tree.<br>
When in my program I invoke "getSubExpr()" (from the object containing the "ExplicitCastExpr") to obtain and print "kapp":</p>
<p><span style="font-size:8pt">      SourceRange r = SourceRange(</span><br><span style="font-size:8pt">                                        FS2->getSubExpr()->getSourceRange().getBegin(),</span><br><span style="font-size:8pt">                                        FS2->getSubExpr()->getSourceRange().getEnd()</span><br><span style="font-size:8pt">                                );</span><br>
<span style="font-size:8pt">      string element_casted = Rewrite.getRewrittenText(r);</span></p>
<p>However, the range of the expression is empty. I have also tried with "getSubExprAsWritten()" but it makes no difference. This is the first time I have found a problem with the solution that I had implemented.</p>
<p>The question is:<br>How could I simply obtain what is being casted as it is written in the code? I do not refer only to this specific case, but a way to achieve my goal in general because I cannot understand this situation.</p>
<p>Thanks in advance.</p>
</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><br></div>