I got lost on documentation about FunctionDecl.
If I have
int param; <— this is stored in a FieldDecl object
in which Decl Object this structure is stored?
Now when I have
int foo(myStruct X) <— this is stored in FunctionDecl
My problem is that I want to validate the FieldDecl object on a function signature, so I want to iterate over this FieldDecl objects if possible when reading a FunctionDecl class. Any ideas or examples how this FieldDecl can be accessed from a FunctionDecl object.
You want to go FunctionDecl to ParmVarDecl to Type to RecordType to RecordDecl to FieldDecl.
FunctionDecl has param_begin() and param_end() methods to iterate over the function parameters.
With a ParmVarDecl, call getType() to get the Type. (Actually a QualType, but when used as a pointer, it forwards calls to Type).
Call getAsStructureType() on the Type. If the RecordType returned is not null, then you’ve found your struct.
Use getDecl() on the RecordType to get the RecordDecl.
In RecordDecl, there is field_begin() and field_end() for iterating over the FieldDecl’s.
Hope that helps.
Oh yes, thank you that is exactly what I was looking for J