[cfe-commits] r41801 - in /cfe/trunk: AST/Decl.cpp Parse/ParseObjc.cpp Sema/Sema.h Sema/SemaDecl.cpp include/clang/AST/Decl.h include/clang/Parse/Action.h include/clang/Parse/Parser.h
Chris Lattner
clattner at apple.com
Fri Sep 28 16:39:24 PDT 2007
> URL: http://llvm.org/viewvc/llvm-project?rev=41801&view=rev
> Log:
> Early patch to collect objective-c methods inserts them in
> class object.
Very nice Fariborz,
> +/// addObjcMethods - Insert instance and methods declarations into
> +/// ObjcInterfaceDecl's InsMethods and ClsMethods fields.
> +///
> +void ObjcInterfaceDecl::ObjcAddMethods(ObjcMethodDecl **insMethods,
> + unsigned numInsMembers,
Looks like some tabs got in here, I'm not sure if they were later fixed.
> ======================================================================
> ========
> --- cfe/trunk/Parse/ParseObjc.cpp (original)
> +++ cfe/trunk/Parse/ParseObjc.cpp Mon Sep 10 15:33:04 2007
> @@ -214,13 +214,14 @@
> /// @optional
> ///
> void Parser::ParseObjCInterfaceDeclList(DeclTy *interfaceDecl) {
> + llvm::SmallVector<DeclTy*, 32> allMethods;
...
> +
> + /// Insert collected methods declarations into the @interface
> object.
> + Actions.ObjcAddMethodsToClass(interfaceDecl, &allMethods[0],
> allMethods.size());
> + return;
> }
No need for an explicit return at the end.
> ======================================================================
> ========
> --- cfe/trunk/include/clang/AST/Decl.h (original)
> +++ cfe/trunk/include/clang/AST/Decl.h Mon Sep 10 15:33:04 2007
> @@ -508,13 +510,25 @@
> FieldDecl **Ivars; // Null if not defined.
> int NumIvars; // -1 if not defined.
>
> + /// instance methods
> + ObjcMethodDecl **InsMethods; // Null if not defined
> + int NumInsMethods; // -1 if not defined
> +
> + /// class methods
> + ObjcMethodDecl **ClsMethods; // Null if not defined
> + int NumClsMethods; // -1 if not defined
These comments are misleading. If the class is not defined, you know
that the 'num' fields are -1 and that the poitner is null. OTOH, the
class could be defined and not have one of these, in which case the
pointer is still null but the number is 0. Please change the
comments to "null if not defined or no methods" or something.
> +/// ObjcMethodDecl - An instance of this class is created to
> represent an instance
> +/// or class method declaration.
> +class ObjcMethodDecl : public ValueDecl {
> +public:
...
> +private:
> + /// ParamInfo - new[]'d array of pointers to VarDecls for the
> formal
> + /// parameters of this Method. This is null if there are no
> formals.
> + ParmVarDecl **ParamInfo;
> +
> + /// List of attributes for this method declaration.
> + AttributeList *MethodAttrs;
> +
> + bool IsInstance : 1;
> +};
This class has changed a bit since the initial commit. On mainline,
it inherits from Decl directly, and has these ivars:
private:
// A unigue name for this method.
Selector SelName;
// Type of this method.
QualType MethodDeclType;
/// ParamInfo - new[]'d array of pointers to VarDecls for the formal
/// parameters of this Method. This is null if there are no formals.
ParmVarDecl **ParamInfo;
int NumMethodParams; // -1 if no parameters
/// List of attributes for this method declaration.
AttributeList *MethodAttrs;
/// Loc - location of this declaration.
SourceLocation Loc;
/// instance (true) or class (false) method.
bool IsInstance : 1;
/// @required/@optional
ImplementationControl DeclImplementation : 2;
One subtle thing about Decl is that it ends with a few bitfields. As
such, if you move the bitfield ivars up, they will get merged into
Decl and shrink ObjcMethodDecl by a word. Specifically, change
ObjcMethodDecl to have this:
private:
/// instance (true) or class (false) method.
bool IsInstance : 1;
/// @required/@optional
ImplementationControl DeclImplementation : 2;
// A unigue name for this method.
Selector SelName;
// Type of this method.
QualType MethodDeclType;
/// ParamInfo - new[]'d array of pointers to VarDecls for the formal
/// parameters of this Method. This is null if there are no formals.
ParmVarDecl **ParamInfo;
int NumMethodParams; // -1 if no parameters
/// List of attributes for this method declaration.
AttributeList *MethodAttrs;
/// Loc - location of this declaration.
SourceLocation Loc;
This optimization can be applied to anything that directly inherits
from Decl or any other class that ends with bitfield members.
-Chris
More information about the cfe-commits
mailing list