[cfe-dev] [PATCH]: C++ decl classes for the AST

Chris Lattner clattner at apple.com
Fri May 23 16:59:00 PDT 2008


On May 16, 2008, at 3:47 PM, Argiris Kirtzidis wrote:

> Hi,
>
> The attached patch introduces new Decl subclasses that accomodate C+ 
> + class members (there are changes only to the AST library):

Nice!

> -'CXXRecordDecl' (inherits from RecordDecl) is for C++ struct/union/ 
> classes that are not simple C structs (i.e. they contain methods,  
> nested types etc.)

Great.

> -'ClassMember' serves as a base class for members of a CXXRecord. It  
> provides the access specifier and the parent CXXRecord. Decls that  
> inherit ClassMember:
>   CXXField - for instance fields (inherits FieldDecl)
>   CXXMethod - for static and instance methods (inherits FunctionDecl)
>   NestedTypedef - for nested typedefs (inherits TypedefDecl)
>   NestedRecordDecl - for nested struct/union/classes (inherits  
> CXXRecordDecl)
>   ClassVar - for static data members (inherits VarDecl)

I'm less enthused about using multiple inheritance for this :).  Is  
there more common between members than just access specifiers?  Would  
it be horrible to just give each of those classes their own  
AccessSpecifiers member?

It doesn't seem very useful to pass around generic ClassMember*'s.  If  
we need a generic "give me the access specifiers for this member", it  
could be written as a top-level method on decl or something.

Alternatively, maybe AccessSpecifiers should be pushed up the class  
hierarchy, say to NamedDecl?  Though it would not be used by every  
subclass, it would make things simpler that way.  This would eliminate  
the need for classes like 'NestedTypedef' and 'NestedRecordDecl' which  
is strange.  A typedef shouldn't be represented with a different class  
based on where it is defined.

Some minor things: I don't think it makes sense for CXXMethod to  
derive from FunctionDecl, a CXXMethod doesn't have the "isa" property  
for FunctionDecl.

Should ClassVarDecl -> CXXClassVarDecl?  Does it make sense to  
distinguish these from CXXField in the class hierarchy?

> -I also moved the 'Decl' implementation to a separate 'DeclBase.cpp'  
> file

Ok.

> The instance fields of CXXRecord are stored in the members array of  
> RecordDecl, thus the data layout of CXXRecord is calculated through  
> the Record.
> All the other members (including the static fields), are ScopedDecls  
> with the CXXRecord as declaration context, so they can be iterated  
> through a general DeclContext member iterator (not implemented yet).
> Name lookup for class members will be efficient through the use of  
> the IdentifierResolver.

Nice!

-Chris



More information about the cfe-dev mailing list