I am trying to programmatically list
all types used as parameters in function calls like 'AddPortInfo("myperson",
The 'aPersonField' is defined in a header
file via 'personStruct aPersonField;'
I index the project and create an AST
of the currently opened file. Via a visitor, I find all FunctionCallExpressions,
and the necessary fields. I now face the problem of finding the definition
of the Struct in the header files to list all fields of that struct.
Can someone point me in the right direction
how to search the index for the declaration, so that I can list the fields
in the struct? I am currently trying to get this information by using the
index and bindings. However, this is not working.
My ultimate goal is to write an XML
file similar to
<Port name="myperson" type="personStruct">
<td:Field name="age" type="int"
<td:Field name="weight" type="int"
<td:Field name="name" type="string"
> Can someone point me in the right direction how to search the
> index for the declaration, so that I can list the fields in the struct? I
> am currently trying to get this information by using the index and
> bindings. However, this is not working.
> IASTName sourceName = fieldReference.getFieldName();
> IBinding myBinding = index.findBinding(sourceName);
> IBinding resovledBinding = sourceName.resolveBinding();
> IBinding owner = resovledBinding.getOwner();
> System.out.println("Owner: " + owner.getName());
Apart from the call to index.findBinding(), which you don't need and whose result you're not using anyways, this looks fine. 'resolvedBinding' should be the binding representing the field, and 'owner' the binding representing the structure that contains the field.
If that's not what you're seeing, could you be more specific about what you are seeing? Is something null?