[cfe-dev] Best way to get SourceLocation of a Declarator?

Nico Weber nicolasweber at gmx.de
Fri Aug 29 03:23:34 PDT 2008


Hi,

what's the best way to get a SourceLocation of a Declarator? I want to  
skip all Declarators from system headers, so my ActOnDeclarator looks  
like this:

   Action::DeclTy *
   ActOnDeclarator(Scope *S, Declarator &D, DeclTy *LastInGroup) {
     SourceLocation loc =  // loc of D
     SourceManager& sm = pp.getSourceManager();
     if (!sm.isInSystemHeader(loc)) {
       // do stuff
     }
     return MinimalAction::ActOnDeclarator(S, D, LastInGroup);
   }

However, what's the best way to get a SourceLocation of a Declarator?  
I can use D.getIdentifierLoc(), but not all Declarators have an  
identifier (e.g. `struct s{};`). Likewise, I could use one of the  
TypeSpecLocs of the DeclSpec, but each of the typespecs is optional,  
too (e.g. `int a;` only has a TypeSpecType, `long a;` does not have a  
TypeSpecType location).

So, is there a general way to get the SourceLocation of a Declarator?

Thanks,
Nico



More information about the cfe-dev mailing list