hi,
I’m using a Clang C interface clang_visitChildren
to traverse the abstract syntax tree in Clang. But I get following problems :
- Get operators in the expression :
For expressions likea+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. - Get the value of constants :
For expressions likeint a =10
, for the node10
, I can get the result by usingclang_Cursor_Evaluate
interface, and then call the functionclang_EvalResult_getAsInt
to get the integer value 10. But, for expressions likeint a = 2+8
, I got2+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? - Location order of the child node in the abstract syntax tree :
If I have two statementfor (; ; a) {...}
andfor (; a; ) {...}
, I useclang_visitChildren
to traverse them, then I got two subtree:UnexposedExpr
andCompoundStmt
, How can I separate the two statements? And why did I getUnexposedExpr
, what does it means?
I don’t know how to solve these problems, I hope that someone can help.
Thank you in advance, Freya