AttributeList *AttrList) {
assert(ClassName && "Missing class identifier");
- ObjcInterfaceDecl* IDecl;
+ ObjcInterfaceDecl* IDecl = Context.getObjCInterfaceDecl(ClassName);
- if (Context.getObjCInterfaceDecl(ClassName))
- Diag(AtInterfaceLoc, diag::err_duplicate_class_def, ClassName->getName());
-
- IDecl = new ObjcInterfaceDecl(AtInterfaceLoc, ClassName);
+ if (IDecl) {
+ // Class already seen. Is it a forward declaration?
+ if (!IDecl->getIsForwardDecl())
+ Diag(AtInterfaceLoc, diag::err_duplicate_class_def, ClassName->getName());
+ else
+ IDecl->setIsForwardDecl(false);
+ }
+ else {
+ IDecl = new ObjcInterfaceDecl(AtInterfaceLoc, ClassName);
- // Chain & install the interface decl into the identifier.
- IDecl->setNext(ClassName->getFETokenInfo<ScopedDecl>());
- ClassName->setFETokenInfo(IDecl);
+ // Chain & install the interface decl into the identifier.
+ IDecl->setNext(ClassName->getFETokenInfo<ScopedDecl>());
+ ClassName->setFETokenInfo(IDecl);
+ }
if (SuperName) {
const ObjcInterfaceDecl* SuperClassEntry =
Context.getObjCInterfaceDecl(SuperName);
- if (!SuperClassEntry) {
+ if (!SuperClassEntry || SuperClassEntry->getIsForwardDecl()) {
Diag(AtInterfaceLoc, diag::err_undef_superclass, SuperName->getName(),
ClassName->getName());
}
cast<ObjcInterfaceDecl>(D)->setNext(CDecl);
return CDecl;
}
+
/// ObjcClassDeclaration -
/// Scope will always be top level file scope.
Action::DeclTy *
for (unsigned i = 0; i != NumElts; ++i) {
ObjcInterfaceDecl *IDecl;
-
- // FIXME: before we create one, look up the interface decl in a hash table.
- IDecl = new ObjcInterfaceDecl(SourceLocation(), IdentList[i], true);
- // Chain & install the interface decl into the identifier.
- IDecl->setNext(IdentList[i]->getFETokenInfo<ScopedDecl>());
- IdentList[i]->setFETokenInfo(IDecl);
-
+ IDecl = Context.getObjCInterfaceDecl(IdentList[i]);
+ if (!IDecl) {// Already seen?
+ IDecl = new ObjcInterfaceDecl(SourceLocation(), IdentList[i], true);
+ // Chain & install the interface decl into the identifier.
+ IDecl->setNext(IdentList[i]->getFETokenInfo<ScopedDecl>());
+ IdentList[i]->setFETokenInfo(IDecl);
+ Context.setObjCInterfaceDecl(IdentList[i], IDecl);
+ }
// Remember that this needs to be removed when the scope is popped.
S->AddDecl(IdentList[i]);
llvm::FoldingSet<FunctionTypeNoProto> FunctionTypeNoProtos;
llvm::FoldingSet<FunctionTypeProto> FunctionTypeProtos;
llvm::DenseMap<const RecordDecl*, const RecordLayout*> RecordLayoutInfo;
- llvm::DenseMap<const IdentifierInfo*, const ObjcInterfaceDecl*> ClassNameInfo;
+ llvm::DenseMap<const IdentifierInfo*, ObjcInterfaceDecl*> ClassNameInfo;
RecordDecl *CFConstantStringTypeDecl;
public:
/// position information.
const RecordLayout &getRecordLayout(const RecordDecl *D, SourceLocation L);
- const ObjcInterfaceDecl* getObjCInterfaceDecl(const IdentifierInfo* ClassName)
- { return ClassNameInfo[ClassName]; }
+ ObjcInterfaceDecl* getObjCInterfaceDecl(const IdentifierInfo* ClassName)
+ { return ClassNameInfo[ClassName]; }
void setObjCInterfaceDecl(const IdentifierInfo* ClassName,
- const ObjcInterfaceDecl* InterfaceDecl)
+ ObjcInterfaceDecl* InterfaceDecl)
{ ClassNameInfo[ClassName] = InterfaceDecl; }
//===--------------------------------------------------------------------===//