[cfe-dev] Retrieving the element to be casted in "ExplicitCastExpr"

Pedro Delgado Perez pedro.delgadoperez at mail.uca.es
Thu Jan 15 10:05:25 PST 2015


 
Hi,

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:

static_cast<KWriteApp *>(kapp);

what I want to print is "kapp". 

However, I have found a problem in that situation:
- kapp is defined as:
#define kapp KApplication::kApplication()

- This is the AST of that expression:

-CXXStaticCastExpr 0x4fcc118 <col:10, col:39> 'class KWriteApp *' static_cast<class KWriteApp *> <BaseToDerived (KApplication)>
|      `-CallExpr 0x4fcc0e0 </usr/include/KDE/../kapplication.h:56:14, col:41> 'class KApplication *'
|        `-ImplicitCastExpr 0x4fcc0c8 <col:14, col:28> 'class KApplication *(*)(void)' <FunctionToPointerDecay>
|          `-DeclRefExpr 0x4fcc068 <col:14, col:28> 'class KApplication *(void)' lvalue CXXMethod 0x7f4c9d3c2fe0 'kApplication' 'class KApplication *(void)'

As you can observe, "kapp" does not appear explicitly in the tree.

- When in my program I invoke "getSubExpr()" (from the object containing the "ExplicitCastExpr") to obtain "kapp", 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. 

The question is:
How could I simply obtain what is being casted as it is written in the code? I do not refer only to this specific situation, but a way to achieve my goal in general. 

Thanks in advance.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20150115/d53d89d5/attachment.html>


More information about the cfe-dev mailing list