get predefined typedefs and vars

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

get predefined typedefs and vars

Maximilian Odendahl-2
Hi,

I'm using a decl_iterator to loop over Decl::Vars and Decl::Typedefs and
printing them to a file.

Is there a way to find out if this Var or Typedef was already predefined
or actually coming from my parsed source file?

So I do not want to dump stuff such as

extern char* __tzname[2] or

typedef unsigned long __u_quad_t


Thanks for your help,
Max
_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: get predefined typedefs and vars

Chris Lattner

On Jun 9, 2010, at 3:47 AM, Maximilian Odendahl wrote:

> Hi,
>
> I'm using a decl_iterator to loop over Decl::Vars and Decl::Typedefs and
> printing them to a file.
>
> Is there a way to find out if this Var or Typedef was already predefined
> or actually coming from my parsed source file?

The best way to do this is to use the SourceManager::isFromMainFile method, which tells you if a source location is in the main file.  Note that you'll probably want to pass in an instantiation location to handle things with macros.

-Chris

>
> So I do not want to dump stuff such as
>
> extern char* __tzname[2] or
>
> typedef unsigned long __u_quad_t
>
>
> Thanks for your help,
> Max
> _______________________________________________
> cfe-dev mailing list
> [hidden email]
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev


_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: get predefined typedefs and vars

Maximilian Odendahl-2
Hi,

thanks for the quick reply.

>> Is there a way to find out if this Var or Typedef was already predefined
>> or actually coming from my parsed source file?
>
> The best way to do this is to use the SourceManager::isFromMainFile method

I tried using

...
case Decl::Typedef:

if (s.getSourceManager().isFromMainFile(it->getSourceRange().getBegin())
        it->dump();
...


But then I get an assertion:

clang-cc: clang/lib/Basic/SourceManager.cpp:429: clang::FileID
clang::SourceManager::getFileIDSlow(unsigned int) const: Assertion
`SLocOffset && "Invalid FileID"' failed.

The first typedef to hit this line is __int128_t...

Am I doing sth. wrong here?

Thanks,
Max


_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: get predefined typedefs and vars

Chris Lattner

On Jun 9, 2010, at 9:50 AM, Maximilian Odendahl wrote:

> Hi,
>
> thanks for the quick reply.
>
>>> Is there a way to find out if this Var or Typedef was already predefined
>>> or actually coming from my parsed source file?
>>
>> The best way to do this is to use the SourceManager::isFromMainFile method
>
> I tried using
>
> ...
> case Decl::Typedef:
>
> if (s.getSourceManager().isFromMainFile(it->getSourceRange().getBegin())
> it->dump();
> ...
>
>
> But then I get an assertion:
>
> clang-cc: clang/lib/Basic/SourceManager.cpp:429: clang::FileID
> clang::SourceManager::getFileIDSlow(unsigned int) const: Assertion
> `SLocOffset && "Invalid FileID"' failed.
>
> The first typedef to hit this line is __int128_t...

I'm not sure what "it" is here, but try Decl::getLocation() instead.  You should check to make sure it isn't an invalid source location though with SourceLocation::isValid()

-Chris

>
> Am I doing sth. wrong here?
>
> Thanks,
> Max
>
>
> _______________________________________________
> cfe-dev mailing list
> [hidden email]
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev


_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: get predefined typedefs and vars

Maximilian Odendahl-2
Hi,

 >I'm not sure what "it" is here, but try Decl::getLocation() instead.
 >You should check to make sure it isn't an invalid source location
 >though with SourceLocation::isValid()

works perfectly, thanks!

Best,
Max
_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev