[cfe-dev] from source location to token?
    steve naroff 
    snaroff at apple.com
       
    Mon Nov 24 06:53:42 PST 2008
    
    
  
Hi Paolo,
I'm not sure what you are trying to do, however here is some info...
- The AST's don't currently store Tokens (they are transient), and we  
have no mechanism for associating an AST with a list/stream of Tokens.
- The NamedDecl AST stores a DeclarationName (which is commonly an  
IdentifierInfo).
- The DeclRefExpr AST stores a NamedDecl.
You can, as you figured out, get a character stream from a  
SourceLocation (and lex/parse again).
It would be interesting to know a little bit more about what you are  
doing. In general, re-lexing/re-parsing isn't very desirable (though  
it may be appropriate if it's uncommon).
HTH,
snaroff
On Nov 24, 2008, at 5:38 AM, Paolo Bolzoni wrote:
> dear cfe list,
> I am implementing an AST visitor, and I seldom need to know the  
> exact token
> that generated the AST vertex.
>
> I can get the source location using the virtual function  
> getSourceRange(),
> the clang::SourceLocation can be used with the SourceManager, but I  
> can't
> find a natural way to get the clang::Token or the IdentifierInfo.
>
> Or I must use const char* clang::SourceManager::getCharacterData()  
> and parse
> again?
>
> Thanks for help.
> pb
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
    
    
More information about the cfe-dev
mailing list