Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[cdt-dev] Resolving and listing fields of a struct


I am trying to programmatically list all types used as parameters in function calls like 'AddPortInfo("myperson", this->aPersonField);'

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.

struct personStruct{
    int   age;
    float weight;
    char  name[25];

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());

My ultimate goal is to write an XML file similar to
<Port name="myperson" type="personStruct">
            <td:Struct name="personStruct">
                    <td:Field name="age" type="int" />
                    <td:Field name="weight" type="int" />
                    <td:Field name="name" type="string" />

Any help is appreciated.
Thanks and best regards.


Back to the top