how to check if a FieldDecl is static or not?

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

how to check if a FieldDecl is static or not?

Manas via cfe-dev
Hi, I checked all the API in FieldDecl and didn't find how to check if it is a static member, and I tried this also:

auto FieldType = TheField->getType();

and I cannot find any static checking in QualType either.

So how can I check if the field is static or not?

_______________________________________________
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: how to check if a FieldDecl is static or not?

Manas via cfe-dev
Hi Yafei,

Static members aren't FieldDecls, they are VarDecls.

Take this example
---
class Foo {
    static int Bar;
};
---

AST output is (with some boilerplate removed)
---
`-CXXRecordDecl class Foo definition
  |-CXXRecordDecl implicit class Foo
  `-VarDecl col:16 Bar 'int' static
---

Once you have a VarDecl you should be able to use
VarDecl::isStaticDataMember() to determine if its a static member of a
class.

~Nathan

On Tue, 2020-10-20 at 17:55 +0800, Yafei Liu via cfe-dev wrote:

> Hi, I checked all the API in FieldDecl and didn't find how to check
> if it is a static member, and I tried this also:
>
> auto FieldType = TheField->getType();
>
> and I cannot find any static checking in QualType either.
>
> So how can I check if the field is static or not?
> _______________________________________________
> 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: how to check if a FieldDecl is static or not?

Manas via cfe-dev
Hi Nathan, thanks a lot, I think your answer teaches me a way of how to figure problems out by myself, I rarely print a class to AST for investigation before.

On Tue, Oct 20, 2020 at 6:05 PM Nathan James <[hidden email]> wrote:
Hi Yafei,

Static members aren't FieldDecls, they are VarDecls.

Take this example
---
class Foo {
    static int Bar;
};
---

AST output is (with some boilerplate removed)
---
`-CXXRecordDecl class Foo definition
  |-CXXRecordDecl implicit class Foo
  `-VarDecl col:16 Bar 'int' static
---

Once you have a VarDecl you should be able to use
VarDecl::isStaticDataMember() to determine if its a static member of a
class.

~Nathan

On Tue, 2020-10-20 at 17:55 +0800, Yafei Liu via cfe-dev wrote:
> Hi, I checked all the API in FieldDecl and didn't find how to check
> if it is a static member, and I tried this also:
>
> auto FieldType = TheField->getType();
>
> and I cannot find any static checking in QualType either.
>
> So how can I check if the field is static or not?
> _______________________________________________
> 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