rewriting types of function declarations

Hi,

is it possible to rewrite types in function declarations or better in
named declarations? It seems there is no location information available
for types.

Thank you very much in advance,
Stephan

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.

-Chris

Hi Chris!

Hi Chris!

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 uncommon).
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.

snaroff