IdentifierInfo *ClassName, SourceLocation ClassLoc,
IdentifierInfo *CategoryName, SourceLocation CategoryLoc,
IdentifierInfo **ProtoRefNames, unsigned NumProtoRefs) {
- ObjcCategoryDecl *CDecl;
- ObjcInterfaceDecl* IDecl = getObjCInterfaceDecl(ClassName);
- CDecl = new ObjcCategoryDecl(AtInterfaceLoc, NumProtoRefs);
+ ObjcInterfaceDecl *IDecl = getObjCInterfaceDecl(ClassName);
+ ObjcCategoryDecl *CDecl = new ObjcCategoryDecl(AtInterfaceLoc, NumProtoRefs,
+ CategoryName);
CDecl->setClassInterface(IDecl);
/// Check that class of this category is already completely declared.
ObjcCategoryDecl *CDeclChain;
for (CDeclChain = IDecl->getListCategories(); CDeclChain;
CDeclChain = CDeclChain->getNextClassCategory()) {
- if (CDeclChain->getCatName() == CategoryName) {
+ if (CDeclChain->getIdentifier() == CategoryName) {
Diag(CategoryLoc, diag::err_dup_category_def, ClassName->getName(),
CategoryName->getName());
break;
}
}
- if (!CDeclChain) {
- CDecl->setCatName(CategoryName);
+ if (!CDeclChain)
CDecl->insertNextClassCategory();
- }
}
/// Check then save referenced protocols
}
if (IncompleteImpl)
Diag(CatImplDecl->getLocation(), diag::warn_incomplete_impl_category,
- CatClassDecl->getCatName()->getName());
+ CatClassDecl->getName());
}
/// ActOnForwardClassDeclaration -
return true;
}
-void Sema::ActOnAddMethodsToObjcDecl(Scope* S, DeclTy *ClassDecl,
+void Sema::ActOnAddMethodsToObjcDecl(Scope* S, DeclTy *classDecl,
DeclTy **allMethods, unsigned allNum) {
+ Decl *ClassDecl = static_cast<Decl *>(classDecl);
+
// FIXME: Fix this when we can handle methods declared in protocols.
// See Parser::ParseObjCAtProtocolDeclaration
if (!ClassDecl)
llvm::DenseMap<void *, const ObjcMethodDecl*> ClsMap;
bool isClassDeclaration =
- (isa<ObjcInterfaceDecl>(static_cast<Decl *>(ClassDecl))
- || isa<ObjcCategoryDecl>(static_cast<Decl *>(ClassDecl)));
+ (isa<ObjcInterfaceDecl>(ClassDecl) || isa<ObjcCategoryDecl>(ClassDecl));
for (unsigned i = 0; i < allNum; i++ ) {
ObjcMethodDecl *Method =
clsMethods.push_back(Method);
}
}
- if (isa<ObjcInterfaceDecl>(static_cast<Decl *>(ClassDecl))) {
- ObjcInterfaceDecl *Interface = cast<ObjcInterfaceDecl>(
- static_cast<Decl*>(ClassDecl));
- Interface->ObjcAddMethods(&insMethods[0], insMethods.size(),
- &clsMethods[0], clsMethods.size());
- }
- else if (isa<ObjcProtocolDecl>(static_cast<Decl *>(ClassDecl))) {
- ObjcProtocolDecl *Protocol = cast<ObjcProtocolDecl>(
- static_cast<Decl*>(ClassDecl));
- 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 if (isa<ObjcImplementationDecl>(static_cast<Decl *>(ClassDecl))) {
- ObjcImplementationDecl* ImplClass = cast<ObjcImplementationDecl>(
- static_cast<Decl*>(ClassDecl));
- ImplClass->ObjcAddImplMethods(&insMethods[0], insMethods.size(),
- &clsMethods[0], clsMethods.size());
- ObjcInterfaceDecl* IDecl = getObjCInterfaceDecl(ImplClass->getIdentifier());
- if (IDecl)
- ImplMethodsVsClassMethods(ImplClass, IDecl);
+
+ if (ObjcInterfaceDecl *I = dyn_cast<ObjcInterfaceDecl>(ClassDecl)) {
+ I->ObjcAddMethods(&insMethods[0], insMethods.size(),
+ &clsMethods[0], clsMethods.size());
+ } else if (ObjcProtocolDecl *P = dyn_cast<ObjcProtocolDecl>(ClassDecl)) {
+ P->ObjcAddProtoMethods(&insMethods[0], insMethods.size(),
+ &clsMethods[0], clsMethods.size());
}
- else {
- ObjcCategoryImplDecl* CatImplClass = dyn_cast<ObjcCategoryImplDecl>(
- static_cast<Decl*>(ClassDecl));
- if (CatImplClass) {
- CatImplClass->ObjcAddCatImplMethods(&insMethods[0], insMethods.size(),
- &clsMethods[0], clsMethods.size());
- ObjcInterfaceDecl* IDecl = CatImplClass->getClassInterface();
- // Find category interface decl and then check that all methods declared
- // in this interface is implemented in the category @implementation.
- if (IDecl) {
- for (ObjcCategoryDecl *Categories = IDecl->getListCategories();
- Categories; Categories = Categories->getNextClassCategory()) {
- if (Categories->getCatName() == CatImplClass->getObjcCatName()) {
- ImplCategoryMethodsVsIntfMethods(CatImplClass, Categories);
- break;
- }
+ else if (ObjcCategoryDecl *C = dyn_cast<ObjcCategoryDecl>(ClassDecl)) {
+ C->ObjcAddCatMethods(&insMethods[0], insMethods.size(),
+ &clsMethods[0], clsMethods.size());
+ }
+ else if (ObjcImplementationDecl *IC =
+ dyn_cast<ObjcImplementationDecl>(ClassDecl)) {
+ IC->ObjcAddImplMethods(&insMethods[0], insMethods.size(),
+ &clsMethods[0], clsMethods.size());
+ if (ObjcInterfaceDecl* IDecl = getObjCInterfaceDecl(IC->getIdentifier()))
+ ImplMethodsVsClassMethods(IC, IDecl);
+ } else {
+ ObjcCategoryImplDecl* CatImplClass = cast<ObjcCategoryImplDecl>(ClassDecl);
+ CatImplClass->ObjcAddCatImplMethods(&insMethods[0], insMethods.size(),
+ &clsMethods[0], clsMethods.size());
+ ObjcInterfaceDecl* IDecl = CatImplClass->getClassInterface();
+ // Find category interface decl and then check that all methods declared
+ // in this interface is implemented in the category @implementation.
+ if (IDecl) {
+ for (ObjcCategoryDecl *Categories = IDecl->getListCategories();
+ Categories; Categories = Categories->getNextClassCategory()) {
+ if (Categories->getIdentifier() == CatImplClass->getObjcCatName()) {
+ ImplCategoryMethodsVsIntfMethods(CatImplClass, Categories);
+ break;
}
}
}
- else
- assert(0 && "Sema::ActOnAddMethodsToObjcDecl(): Unknown DeclTy");
}
}
static bool classof(const Decl *) { return true; }
};
-/// ScopedDecl - Represent lexically scoped names, used for all ValueDecl's
-/// and TypeDecl's.
-class ScopedDecl : public Decl {
+class NamedDecl : public Decl {
/// Identifier - The identifier for this declaration (e.g. the name for the
/// variable, the tag for a struct).
IdentifierInfo *Identifier;
+public:
+ NamedDecl(Kind DK, SourceLocation L, IdentifierInfo *Id)
+ : Decl(DK, L), Identifier(Id) {}
+
+ IdentifierInfo *getIdentifier() const { return Identifier; }
+ const char *getName() const;
+
+
+ // FIXME: classof.
+ static bool classof(const NamedDecl *D) { return true; }
+};
+
+/// ScopedDecl - Represent lexically scoped names, used for all ValueDecl's
+/// and TypeDecl's.
+class ScopedDecl : public NamedDecl {
/// NextDeclarator - If this decl was part of a multi-declarator declaration,
/// such as "int X, Y, *Z;" this indicates Decl for the next declarator.
///
ScopedDecl *Next;
protected:
- ScopedDecl(Kind DK, SourceLocation L, IdentifierInfo *Id, ScopedDecl *PrevDecl)
- : Decl(DK, L), Identifier(Id), NextDeclarator(PrevDecl), Next(0) {}
+ ScopedDecl(Kind DK, SourceLocation L, IdentifierInfo *Id,ScopedDecl *PrevDecl)
+ : NamedDecl(DK, L, Id), NextDeclarator(PrevDecl), Next(0) {}
public:
- IdentifierInfo *getIdentifier() const { return Identifier; }
- const char *getName() const;
-
ScopedDecl *getNext() const { return Next; }
void setNext(ScopedDecl *N) { Next = N; }
/// FieldDecl - An instance of this class is created by Sema::ActOnField to
/// represent a member of a struct/union/class.
-class FieldDecl : public Decl {
+class FieldDecl : public NamedDecl {
/// Identifier - The identifier for this declaration (e.g. the name for the
/// variable, the tag for a struct).
IdentifierInfo *Identifier;
QualType DeclType;
public:
FieldDecl(SourceLocation L, IdentifierInfo *Id, QualType T)
- : Decl(Field, L), Identifier(Id), DeclType(T) {}
+ : NamedDecl(Field, L, Id), DeclType(T) {}
FieldDecl(Kind DK, SourceLocation L, IdentifierInfo *Id, QualType T)
- : Decl(DK, L), Identifier(Id), DeclType(T) {}
-
- IdentifierInfo *getIdentifier() const { return Identifier; }
- const char *getName() const;
+ : NamedDecl(DK, L, Id), DeclType(T) {}
QualType getType() const { return DeclType; }
QualType getCanonicalType() const { return DeclType.getCanonicalType(); }
/// // no instance variables or methods.
/// @end
///
-/// // NSResponder inherits from NSObject and implements NSCoding (a protocol).
+/// // NSResponder inherits from NSObject & implements NSCoding (a protocol).
/// @interface NSResponder : NSObject <NSCoding>
/// { // instance variables are represented by ObjcIvarDecl.
/// id nextResponder; // nextResponder instance variable.
/// Lisp and Smalltalk. More traditional class-based languages (C++, Java)
/// don't support this level of dynamism, which is both powerful and dangerous.
///
-class ObjcCategoryDecl : public Decl {
+class ObjcCategoryDecl : public NamedDecl {
/// Interface belonging to this category
ObjcInterfaceDecl *ClassInterface;
- /// Category name
- IdentifierInfo *ObjcCatName;
-
/// referenced protocols in this category
ObjcProtocolDecl **ReferencedProtocols; // Null if none
int NumReferencedProtocols; // -1 if none
ObjcCategoryDecl *NextClassCategory;
public:
- ObjcCategoryDecl(SourceLocation L, unsigned numRefProtocol)
- : Decl(ObjcCategory, L),
- ClassInterface(0), ObjcCatName(0),
- ReferencedProtocols(0), NumReferencedProtocols(-1),
+ ObjcCategoryDecl(SourceLocation L, unsigned numRefProtocol,IdentifierInfo *Id)
+ : NamedDecl(ObjcCategory, L, Id),
+ ClassInterface(0), ReferencedProtocols(0), NumReferencedProtocols(-1),
InstanceMethods(0), NumInstanceMethods(-1),
ClassMethods(0), NumClassMethods(-1),
NextClassCategory(0) {
void ObjcAddCatMethods(ObjcMethodDecl **insMethods, unsigned numInsMembers,
ObjcMethodDecl **clsMethods, unsigned numClsMembers);
- IdentifierInfo *getCatName() const { return ObjcCatName; }
- void setCatName(IdentifierInfo *catName) { ObjcCatName = catName; }
-
ObjcCategoryDecl *getNextClassCategory() const { return NextClassCategory; }
void insertNextClassCategory() {
NextClassCategory = ClassInterface->getListCategories();