[cfe-commits] r42104 - 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
Fariborz Jahanian
fjahanian at apple.com
Tue Sep 18 13:26:58 PDT 2007
Author: fjahanian
Date: Tue Sep 18 15:26:58 2007
New Revision: 42104
URL: http://llvm.org/viewvc/llvm-project?rev=42104&view=rev
Log:
Patch for object creation and handling of category declarations.
Modified:
cfe/trunk/AST/Decl.cpp
cfe/trunk/Parse/ParseObjc.cpp
cfe/trunk/Sema/Sema.h
cfe/trunk/Sema/SemaDecl.cpp
cfe/trunk/include/clang/AST/Decl.h
cfe/trunk/include/clang/Parse/Action.h
Modified: cfe/trunk/AST/Decl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/AST/Decl.cpp?rev=42104&r1=42103&r2=42104&view=diff
==============================================================================
--- cfe/trunk/AST/Decl.cpp (original)
+++ cfe/trunk/AST/Decl.cpp Tue Sep 18 15:26:58 2007
@@ -29,6 +29,7 @@
static unsigned nClassDecls = 0;
static unsigned nMethodDecls = 0;
static unsigned nProtocolDecls = 0;
+static unsigned nCategoryDecls = 0;
static unsigned nIvarDecls = 0;
static bool StatSwitch = false;
@@ -79,7 +80,7 @@
fprintf(stderr, " %d decls total.\n",
int(nFuncs+nBlockVars+nFileVars+nParmVars+nFieldDecls+nSUC+
nEnumDecls+nEnumConst+nTypedef+nInterfaceDecls+nClassDecls+
- nMethodDecls+nProtocolDecls+nIvarDecls));
+ nMethodDecls+nProtocolDecls+nCategoryDecls+nIvarDecls));
fprintf(stderr, " %d function decls, %d each (%d bytes)\n",
nFuncs, (int)sizeof(FunctionDecl), int(nFuncs*sizeof(FunctionDecl)));
fprintf(stderr, " %d block variable decls, %d each (%d bytes)\n",
@@ -121,6 +122,9 @@
fprintf(stderr, " %d protocol decls, %d each (%d bytes)\n",
nProtocolDecls, (int)sizeof(ObjcProtocolDecl),
int(nProtocolDecls*sizeof(ObjcProtocolDecl)));
+ fprintf(stderr, " %d category decls, %d each (%d bytes)\n",
+ nCategoryDecls, (int)sizeof(ObjcCategoryDecl),
+ int(nCategoryDecls*sizeof(ObjcCategoryDecl)));
fprintf(stderr, "Total bytes = %d\n",
int(nFuncs*sizeof(FunctionDecl)+nBlockVars*sizeof(BlockVarDecl)+
@@ -174,6 +178,9 @@
case ObjcProtocol:
nProtocolDecls++;
break;
+ case ObjcCategory:
+ nCategoryDecls++;
+ break;
case ObjcIvar:
nIvarDecls++;
break;
@@ -308,4 +315,23 @@
}
}
+/// ObjcAddCat - Insert instance and methods declarations into
+/// ObjcProtocolDecl's CatInsMethods and CatClsMethods fields.
+///
+void ObjcCategoryDecl::ObjcAddCatMethods(ObjcMethodDecl **insMethods,
+ unsigned numInsMembers,
+ ObjcMethodDecl **clsMethods,
+ unsigned numClsMembers) {
+ NumCatInsMethods = numInsMembers;
+ if (numInsMembers) {
+ CatInsMethods = new ObjcMethodDecl*[numInsMembers];
+ memcpy(CatInsMethods, insMethods, numInsMembers*sizeof(ObjcMethodDecl*));
+ }
+ NumCatClsMethods = numClsMembers;
+ if (numClsMembers) {
+ CatClsMethods = new ObjcMethodDecl*[numClsMembers];
+ memcpy(CatClsMethods, clsMethods, numClsMembers*sizeof(ObjcMethodDecl*));
+ }
+}
+
Modified: cfe/trunk/Parse/ParseObjc.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Parse/ParseObjc.cpp?rev=42104&r1=42103&r2=42104&view=diff
==============================================================================
--- cfe/trunk/Parse/ParseObjc.cpp (original)
+++ cfe/trunk/Parse/ParseObjc.cpp Tue Sep 18 15:26:58 2007
@@ -130,6 +130,7 @@
SourceLocation lparenLoc = ConsumeParen();
SourceLocation categoryLoc, rparenLoc;
IdentifierInfo *categoryId = 0;
+ llvm::SmallVector<IdentifierInfo *, 8> ProtocolRefs;
// For ObjC2, the category name is optional (not an error).
if (Tok.getKind() == tok::identifier) {
@@ -147,14 +148,19 @@
rparenLoc = ConsumeParen();
// Next, we need to check for any protocol references.
if (Tok.getKind() == tok::less) {
- llvm::SmallVector<IdentifierInfo *, 8> ProtocolRefs;
if (ParseObjCProtocolReferences(ProtocolRefs))
return 0;
}
if (attrList) // categories don't support attributes.
Diag(Tok, diag::err_objc_no_attributes_on_category);
- ParseObjCInterfaceDeclList(0, tok::objc_not_keyword/*FIXME*/);
+ DeclTy *CategoryType = Actions.ObjcStartCatInterface(atLoc,
+ nameId, nameLoc,
+ categoryId, categoryLoc,
+ &ProtocolRefs[0],
+ ProtocolRefs.size());
+
+ ParseObjCInterfaceDeclList(CategoryType, tok::objc_not_keyword);
// The @ sign was already consumed by ParseObjCInterfaceDeclList().
if (Tok.isObjCAtKeyword(tok::objc_end)) {
Modified: cfe/trunk/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/Sema.h?rev=42104&r1=42103&r2=42104&view=diff
==============================================================================
--- cfe/trunk/Sema/Sema.h (original)
+++ cfe/trunk/Sema/Sema.h Tue Sep 18 15:26:58 2007
@@ -362,6 +362,11 @@
IdentifierInfo *ProtocolName, SourceLocation ProtocolLoc,
IdentifierInfo **ProtoRefNames, unsigned NumProtoRefs);
+ virtual DeclTy *ObjcStartCatInterface(SourceLocation AtInterfaceLoc,
+ IdentifierInfo *ClassName, SourceLocation ClassLoc,
+ IdentifierInfo *CategoryName, SourceLocation CategoryLoc,
+ IdentifierInfo **ProtoRefNames, unsigned NumProtoRefs);
+
virtual DeclTy *ObjcClassDeclaration(Scope *S, SourceLocation AtClassLoc,
IdentifierInfo **IdentList,
unsigned NumElts);
Modified: cfe/trunk/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/SemaDecl.cpp?rev=42104&r1=42103&r2=42104&view=diff
==============================================================================
--- cfe/trunk/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/Sema/SemaDecl.cpp Tue Sep 18 15:26:58 2007
@@ -32,8 +32,7 @@
Sema::DeclTy *Sema::isTypeName(const IdentifierInfo &II, Scope *S) const {
Decl *IIDecl = II.getFETokenInfo<Decl>();
if (dyn_cast_or_null<TypedefDecl>(IIDecl) ||
- dyn_cast_or_null<ObjcInterfaceDecl>(IIDecl) ||
- dyn_cast_or_null<ObjcProtocolDecl>(IIDecl))
+ dyn_cast_or_null<ObjcInterfaceDecl>(IIDecl))
return IIDecl;
return 0;
}
@@ -896,6 +895,22 @@
return PDecl;
}
+Sema::DeclTy *Sema::ObjcStartCatInterface(SourceLocation AtInterfaceLoc,
+ IdentifierInfo *ClassName, SourceLocation ClassLoc,
+ IdentifierInfo *CategoryName, SourceLocation CategoryLoc,
+ IdentifierInfo **ProtoRefNames, unsigned NumProtoRefs) {
+ ObjcCategoryDecl *CDecl;
+ CDecl = new ObjcCategoryDecl(AtInterfaceLoc, ClassName);
+ assert (ClassName->getFETokenInfo<ScopedDecl>() && "Missing @interface decl");
+ Decl *D = static_cast<Decl *>(ClassName->getFETokenInfo<ScopedDecl>());
+ assert(isa<ObjcInterfaceDecl>(D) && "Missing @interface decl");
+
+ // Chain & install the category decl into the identifier.
+ // Note that head of the chain is the @interface class type and follow up
+ // nodes in the chain are the protocol decl nodes.
+ cast<ObjcInterfaceDecl>(D)->setNext(CDecl);
+ return CDecl;
+}
/// ObjcClassDeclaration -
/// Scope will always be top level file scope.
Action::DeclTy *
@@ -1263,6 +1278,12 @@
Protocol->ObjcAddProtoMethods(&insMethods[0], insMethods.size(),
&clsMethods[0], clsMethods.size());
}
+ else if (isa<ObjcCategoryDecl>(static_cast<Decl *>(ClassDecl))) {
+ ObjcCategoryDecl *Category = cast<ObjcCategoryDecl>(
+ static_cast<Decl*>(ClassDecl));
+ Category->ObjcAddCatMethods(&insMethods[0], insMethods.size(),
+ &clsMethods[0], clsMethods.size());
+ }
else
assert(0 && "Sema::ObjcAddMethodsToClass(): Unknown DeclTy");
return;
Modified: cfe/trunk/include/clang/AST/Decl.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Decl.h?rev=42104&r1=42103&r2=42104&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Decl.h (original)
+++ cfe/trunk/include/clang/AST/Decl.h Tue Sep 18 15:26:58 2007
@@ -39,7 +39,7 @@
Function, BlockVariable, FileVariable, ParmVariable, EnumConstant,
// Concrete sub-classes of TypeDecl
Typedef, Struct, Union, Class, Enum, ObjcInterface, ObjcClass, ObjcMethod,
- ObjcProtoMethod, ObjcProtocol,
+ ObjcProtoMethod, ObjcProtocol, ObjcCategory,
// Concrete sub-class of Decl
Field, ObjcIvar
};
@@ -703,5 +703,36 @@
static bool classof(const ObjcProtocolDecl *D) { return true; }
};
+class ObjcCategoryDecl : public ScopedDecl {
+ /// category instance methods
+ ObjcMethodDecl **CatInsMethods; // Null if not defined
+ int NumCatInsMethods; // -1 if not defined
+
+ /// category class methods
+ ObjcMethodDecl **CatClsMethods; // Null if not defined
+ int NumCatClsMethods; // -1 if not defined
+
+ /// Category name
+ IdentifierInfo *ObjcCatName;
+
+public:
+ ObjcCategoryDecl(SourceLocation L, IdentifierInfo *Id)
+ : ScopedDecl(ObjcCategory, L, Id, 0),
+ CatInsMethods(0), NumCatInsMethods(-1),
+ CatClsMethods(0), NumCatClsMethods(-1),
+ ObjcCatName(0) {}
+
+ void ObjcAddCatMethods(ObjcMethodDecl **insMethods, unsigned numInsMembers,
+ ObjcMethodDecl **clsMethods, unsigned numClsMembers);
+
+ IdentifierInfo *getCatName() const { return ObjcCatName; }
+ void setCatName(IdentifierInfo *catName) { ObjcCatName = catName; }
+
+ static bool classof(const Decl *D) {
+ return D->getKind() == ObjcCategory;
+ }
+ static bool classof(const ObjcCategoryDecl *D) { return true; }
+};
+
} // end namespace clang
#endif
Modified: cfe/trunk/include/clang/Parse/Action.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Action.h?rev=42104&r1=42103&r2=42104&view=diff
==============================================================================
--- cfe/trunk/include/clang/Parse/Action.h (original)
+++ cfe/trunk/include/clang/Parse/Action.h Tue Sep 18 15:26:58 2007
@@ -453,6 +453,12 @@
IdentifierInfo **ProtoRefNames, unsigned NumProtoRefs) {
return 0;
}
+ virtual DeclTy *ObjcStartCatInterface(SourceLocation AtInterfaceLoc,
+ IdentifierInfo *ClassName, SourceLocation ClassLoc,
+ IdentifierInfo *CategoryName, SourceLocation CategoryLoc,
+ IdentifierInfo **ProtoRefNames, unsigned NumProtoRefs) {
+ return 0;
+ }
virtual DeclTy *ObjcBuildMethodDeclaration(SourceLocation MethodLoc,
tok::TokenKind MethodType, TypeTy *ReturnType,
ObjcKeywordDecl *Keywords, unsigned NumKeywords,
@@ -544,7 +550,6 @@
virtual DeclTy *ObjcStartProtoInterface(SourceLocation AtProtoInterfaceLoc,
IdentifierInfo *ProtocolName, SourceLocation ProtocolLoc,
IdentifierInfo **ProtoRefNames, unsigned NumProtoRefs);
-
};
} // end namespace clang
More information about the cfe-commits
mailing list