[cfe-dev] get FieldDecl from FunctionDecl

Richard Trieu rtrieu at google.com
Tue Nov 5 16:39:23 PST 2013


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.


On Tue, Nov 5, 2013 at 1:23 PM, Alejandro Jimenez <whilealex at gmail.com>wrote:

> Hello!
>
> I got lost on documentation about FunctionDecl.
>
> If I have
>
> struct myStruct
> {
>    int param; <--- this is stored in a FieldDecl object
> };
> Question1?
> 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.
>
> Alejandro
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20131105/bd04e636/attachment.html>


More information about the cfe-dev mailing list