[cfe-dev] Better type-specifier representation

Argiris Kirtzidis akyrtzi at gmail.com
Fri Sep 12 16:17:17 PDT 2008

To both Ted and Daniel:

Ted Kremenek wrote:
> My feeling is that type-specifiers are different than types.  They 
> aren't synonymous; one is a syntactic construct, the other a semantic 
> concept, and they shouldn't be treated as being the same in the ASTs.  
> I think that type-specifiers could possibly be encoded as a smart 
> pointer or a similar class (similar to QualType) to make the overhead 
> negligible.

Daniel Dunbar wrote:
> I don't see any clear reason why, if we want this, we should embed it into
> the type (which is fundamentally incorrect, a type specifier is not a type, many
> things have different type specifiers but the same type).

These are good points, I agree. Putting type-spec info in the type is 
the wrong way to go.

Daniel Dunbar wrote:
> If we want to explicitly represent the type specifier, what is wrong with
> actually making this a separate node (not a Type and not a Decl). We can
> probably present the abstraction that the AST has TypeSpecifier nodes
> without actually creating them (by encoding in DeclGroup or other tricks).
> This also gives a clear place to attach source range, makes clear what the
> representation of sizeof(type) is (a SizeofAlignOfTypeExpr which points to
> a TypeSpecifier which in turn points to the type), and should make ownership
> clear.

This is a great idea!

How about using something like this:

-In the AST, Decls do not have Types, they have TypeSpecifiers. Exprs 
have Types.
-TypeSpecifiers can own RecordDecls
-DeclGroups are used for declaration lists:
      int x,y,z; -> DeclGroup
  but not for parameters. If the ParmVarDecl has a TypeSpecifier, we 
don't have to use a DeclGroup in its place.

Let me know what you think.


More information about the cfe-dev mailing list