RecursiveASTVisitor: How to traverse all FieldDecl in a CXXRecordDecl?

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

RecursiveASTVisitor: How to traverse all FieldDecl in a CXXRecordDecl?

shirley breuer via cfe-dev
Hi,

I have  simple RecursiveASTVisitor, which should handle definition of
structs and their fields.


How can I traverse over all FieldDecl in a given CXXRecordDecl?

Because of the sequence the AST is traversed, I don't know in a
VisitFieldDecl approach to which CXXRecordDecl it belongs to.

I hope I have stated my problem understandable..-


Thanks

Marcel
_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: RecursiveASTVisitor: How to traverse all FieldDecl in a CXXRecordDecl?

shirley breuer via cfe-dev


> -----Original Message-----
> From: cfe-dev <[hidden email]> On Behalf Of Marcel
> Schaible via cfe-dev
> Sent: Monday, November 30, 2020 11:49 AM
> To: [hidden email]
> Subject: [cfe-dev] RecursiveASTVisitor: How to traverse all FieldDecl in a
> CXXRecordDecl?
>
> Hi,
>
> I have  simple RecursiveASTVisitor, which should handle definition of
> structs and their fields.
>
>
> How can I traverse over all FieldDecl in a given CXXRecordDecl?
>
> Because of the sequence the AST is traversed, I don't know in a
> VisitFieldDecl approach to which CXXRecordDecl it belongs to.

I don't know anything about RecursiveASTVisitor so there might be
a way to do what you want there.  If you need to traverse the AST
"manually" there's code in clang/lib/CodeGen/CGDebugInfo.cpp (look
for CGDebugInfo::CollectRecordFields) that could be instructive.
Note that a VarDecl describes a static data member, while a
FieldDecl describes a normal data member.

--paulr

>
> I hope I have stated my problem understandable..-
>
>
> Thanks
>
> Marcel
> _______________________________________________
> cfe-dev mailing list
> [hidden email]
> https://urldefense.com/v3/__https://lists.llvm.org/cgi-
> bin/mailman/listinfo/cfe-dev__;!!JmoZiZGBv3RvKRSx!sAghJD5ak8TBfwxlN3-
> clB7IHmStNEf-qYGycEskAWJCHsfocgsXmtBh2CP25GHZAA$
_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: RecursiveASTVisitor: How to traverse all FieldDecl in a CXXRecordDecl?

shirley breuer via cfe-dev
Depending on the context of your program you can either try to 1) traverse the fields within VisitCXXRecordDecl() or 2) use the FieldDecl::getParent() method within VisitFieldDecl() to figure out which CXXRecordDecl the FieldDecl belongs to (if any).

-Adam

On Mon, Nov 30, 2020 at 5:18 PM Robinson, Paul via cfe-dev <[hidden email]> wrote:


> -----Original Message-----
> From: cfe-dev <[hidden email]> On Behalf Of Marcel
> Schaible via cfe-dev
> Sent: Monday, November 30, 2020 11:49 AM
> To: [hidden email]
> Subject: [cfe-dev] RecursiveASTVisitor: How to traverse all FieldDecl in a
> CXXRecordDecl?
>
> Hi,
>
> I have  simple RecursiveASTVisitor, which should handle definition of
> structs and their fields.
>
>
> How can I traverse over all FieldDecl in a given CXXRecordDecl?
>
> Because of the sequence the AST is traversed, I don't know in a
> VisitFieldDecl approach to which CXXRecordDecl it belongs to.

I don't know anything about RecursiveASTVisitor so there might be
a way to do what you want there.  If you need to traverse the AST
"manually" there's code in clang/lib/CodeGen/CGDebugInfo.cpp (look
for CGDebugInfo::CollectRecordFields) that could be instructive.
Note that a VarDecl describes a static data member, while a
FieldDecl describes a normal data member.

--paulr

>
> I hope I have stated my problem understandable..-
>
>
> Thanks
>
> Marcel
> _______________________________________________
> cfe-dev mailing list
> [hidden email]
> https://urldefense.com/v3/__https://lists.llvm.org/cgi-
> bin/mailman/listinfo/cfe-dev__;!!JmoZiZGBv3RvKRSx!sAghJD5ak8TBfwxlN3-
> clB7IHmStNEf-qYGycEskAWJCHsfocgsXmtBh2CP25GHZAA$
_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev

_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: RecursiveASTVisitor: How to traverse all FieldDecl in a CXXRecordDecl?

shirley breuer via cfe-dev
Maybe you can try `CXXRecordDecl::fields()`?

On Tue, Dec 1, 2020 at 10:59 PM Adam McLaughlin via cfe-dev <[hidden email]> wrote:
Depending on the context of your program you can either try to 1) traverse the fields within VisitCXXRecordDecl() or 2) use the FieldDecl::getParent() method within VisitFieldDecl() to figure out which CXXRecordDecl the FieldDecl belongs to (if any).

-Adam

On Mon, Nov 30, 2020 at 5:18 PM Robinson, Paul via cfe-dev <[hidden email]> wrote:


> -----Original Message-----
> From: cfe-dev <[hidden email]> On Behalf Of Marcel
> Schaible via cfe-dev
> Sent: Monday, November 30, 2020 11:49 AM
> To: [hidden email]
> Subject: [cfe-dev] RecursiveASTVisitor: How to traverse all FieldDecl in a
> CXXRecordDecl?
>
> Hi,
>
> I have  simple RecursiveASTVisitor, which should handle definition of
> structs and their fields.
>
>
> How can I traverse over all FieldDecl in a given CXXRecordDecl?
>
> Because of the sequence the AST is traversed, I don't know in a
> VisitFieldDecl approach to which CXXRecordDecl it belongs to.

I don't know anything about RecursiveASTVisitor so there might be
a way to do what you want there.  If you need to traverse the AST
"manually" there's code in clang/lib/CodeGen/CGDebugInfo.cpp (look
for CGDebugInfo::CollectRecordFields) that could be instructive.
Note that a VarDecl describes a static data member, while a
FieldDecl describes a normal data member.

--paulr

>
> I hope I have stated my problem understandable..-
>
>
> Thanks
>
> Marcel
> _______________________________________________
> cfe-dev mailing list
> [hidden email]
> https://urldefense.com/v3/__https://lists.llvm.org/cgi-
> bin/mailman/listinfo/cfe-dev__;!!JmoZiZGBv3RvKRSx!sAghJD5ak8TBfwxlN3-
> clB7IHmStNEf-qYGycEskAWJCHsfocgsXmtBh2CP25GHZAA$
_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev

_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev