[cfe-dev] rewriting types of function declarations

Steve Naroff snaroff at apple.com
Fri Jun 6 07:01:08 PDT 2008

On Jun 6, 2008, at 6:41 AM, Stephan Creutz wrote:

> Hi Chris!
> On Mon, Jun 02, 2008 at 10:50:30PM -0700, Chris Lattner wrote:
>> On Jun 2, 2008, at 6:14 AM, Stephan Creutz wrote:
>>> is it possible to rewrite types in function declarations or better  
>>> in
>>> named declarations? It seems there is no location information  
>>> available
>>> for types.
>> Hi Stephan,
>> You're right that types don't have location information.  Since  
>> they are
>> unique'd, there is a many to one mapping between type instances and  
>> the
>> underlying type.  It would be possible to capture this information,  
>> but
>> would be extremely expensive.
>> For most uses, a fuzzy scanning technique can be used to find the  
>> locations
>> you need in the original source.  Given a source location for the
>> paramdecl, for example, you can get a "const char*" into the original
>> source code and scan from there with strchr etc.  This is what the  
>> objc
>> rewriter does in many cases.
> Thank you for that hint. I think that approach is sufficient for me  
> (for
> now).
> But at which point the location information is thrown away?

In some cases, the parser doesn't pass all SourceLocations (fairly  
In other cases, Sema decides to exclude the SourceLocation when  
building the AST (to save space).
Lastly, Types don't have SourceLocation info by design (since they are  
unique'd to save space).

Since types typically appear in the context of a Decl, we can likely  
improve the situation by adding more SourceLocation info to Decls.

> Would it
> help to subclass Action or or better Sema to get this kind of
> information (just for the case I get further problems)?

I think we should enhance Decl's (both the AST and action->sema API)  
on a case-by-case basis. When I was doing the ObjCRewriter, I did some  
of this.


> Stephan
> _______________________________________________
> 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