[cfe-dev] Source information for types

Argyrios Kyrtzidis kyrtzidis at apple.com
Wed Jul 8 13:28:50 PDT 2009


Hi clang community,

I'd like to make a proposal for keeping source location information  
for types in the AST, to allow functionality like "find the source  
locations where this typedef is used".
Type source info will be provided using a flag so the memory overhead  
involved will be only for clients that need that information.
Using a flag will also make it easy to find out what exactly the  
overhead is when type source info is enabled.

Ideally, since this is a feature useful only for specific clients, we  
don't want to impose any overhead on the non-type-source-info ASTs.
Here's the plan:

SourceType:
There will be a new, non canonical, not uniqued, type 'SourceType',  
whose purpose will be to store source location information for a type- 
specifier.
It will also contain the 'base' QualType of the type-specifier.
The exact amount of source info that it will keep is not important at  
this point, it can be discussed/debated after SourceType is introduced.
The owner of SourceType objects will be ASTContext.

TypeSpecifier:
TypeSpecifier will be a very thin wrapper over a QualType. It will  
have a getType() method that checks whether QualType is a SourceType,
and if it is, it will return the 'base' QualType of SourceType,  
otherwise it will return the original QualType that it wraps.
It will also have isSourceType() and getSourceType() methods.

TypeSpecifier will replace the QualType fields in the Decls. For  
example, ValueDecl will contain a TypeSpecifier instead of a plain  
QualType.
"QualType ValueDecl::getType()" will delegate to TypeSpecifier::getType 
() (ValueDecl::getType() will still return a QualType).
TypeSpecifier will also be contained in Exprs that deal with type- 
specifiers, like SizeOfAlignOfExpr.

Since getType() of Decls/Exprs will never return a QualType that is  
actually a SourceType, SourceType won't enter the semantic type  
checking code paths.
You would have to specifically ask for the TypeSpecifier through  
ValueDecl::getTypeSpec() to get at the SourceType.

The end result is that for the normal non-type-source-info case there  
will be no memory overhead at all.


Do you find the above reasonable ?
Any questions/comments/suggestions will be greatly appreciated.

-Argiris



More information about the cfe-dev mailing list