[cfe-dev] Clang C interface `clang_visitChildren` problems

freya zhou via cfe-dev cfe-dev at lists.llvm.org
Tue Mar 14 20:24:11 PDT 2017


hi,

I’m using a Clang C interface clang_visitChildren to traverse the abstract
syntax tree in Clang. But I get following problems :

   1. Get operators in the expression :
   For expressions like a+b, I can get the current cursor information
   (name, kind, type) and its child node info, but I don’t know how can I get
   the operator ‘+’ ? Should I use token to get the operators in expression?
   If so, please tell me how can I use token to get operators.
   2. Get the value of constants :
   For expressions like int a =10, for the node 10, I can get the result by
   using clang_Cursor_Evaluate interface, and then call the function
   clang_EvalResult_getAsInt to get the integer value 10. But, for
   expressions like int a = 2+8, I got 2+8 and keep traverse down, using
   the same approach, then I got two 0. Did get the value by a wrong
   way?What’s the correct way to get the value?
   3. Location order of the child node in the abstract syntax tree :
   If I have two statement for (; ; a) {...} and for (; a; ) {...}, I use
   clang_visitChildren to traverse them, then I got two subtree:
   UnexposedExpr and CompoundStmt, How can I separate the two statements?
   And why did I get UnexposedExpr, what does it means?

I don't know how to solve these problems, I hope that someone can help.
Thank you in advance, Freya
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20170315/9a2fca77/attachment.html>


More information about the cfe-dev mailing list