Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [cdt-dev] Getting node declaration

> Having an expression node, is it possible to get the IASTNode of some
> variable of this expression?
>
> E.g:
>
> void main() {
> int c;
> c = 10;
> }
>
> I have the IASTNode "c = 10;". How can I get the IASTNode where the
> variable "c" is declared (int c;)?

  - Walk the AST to find the IASTName representing the name
    "c" in the expresion "c=  10".
  - Call IASTName.resolveBinding() on it to obtain an IBinding
     representing the variable "c".
  - Call IASTTranslationUnit.getDeclarationsInAST(IBinding) to
     get a list of AST nodes representing declarations of the
     variable. The IASTTranslationUnit can be obtained from any
     IASTNode via IASTNode.getTranslationUnit().

Hope that helps,
Nate
 		 	   		  

Back to the top