[cfe-dev] from source location to token?

steve naroff snaroff at apple.com
Mon Nov 24 08:44:06 PST 2008


On Nov 24, 2008, at 10:53 AM, Roberto Bagnara wrote:

> steve naroff wrote:
>> 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).
>
> Hi Steve,
>
> there are program analyses that, for instance:
>
> 1) need to reason on an exact representation of floating-point  
> literals
>   (any approximation may result into an unsound analysis);
> 2) need to reason on the textual representation that was used in the
>   program also for integer literals (for example, there are coding
>   rules that forbid the use of octal constants: the analyzer should
>   flag their use in the source program).
>

Hi Roberto,

Makes sense. We could consider adding a "LiteralName" to  
IntegerLiteral/FloatingLiteral if this becomes commonplace (it may  
help doing more precise pretty printing as well).

snaroff

> All the best,
>
>   Roberto
>
> -- 
> Prof. Roberto Bagnara
> Computer Science Group
> Department of Mathematics, University of Parma, Italy
> http://www.cs.unipr.it/~bagnara/
> mailto:bagnara at cs.unipr.it




More information about the cfe-dev mailing list