Match to do some semantic analysis on objective-c class decl.
1. Detect used of undeclared/forward declared super class.
2. Detect duplicate definition of a class.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@42168 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/Sema/SemaDecl.cpp b/Sema/SemaDecl.cpp
index 42024b1..ca39e6e 100644
--- a/Sema/SemaDecl.cpp
+++ b/Sema/SemaDecl.cpp
@@ -868,13 +868,30 @@
IdentifierInfo **ProtocolNames, unsigned NumProtocols,
AttributeList *AttrList) {
assert(ClassName && "Missing class identifier");
- ObjcInterfaceDecl *IDecl;
-
+
+ ObjcInterfaceDecl* IDecl;
+
+ if (Context.getObjCInterfaceDecl(ClassName))
+ Diag(AtInterfaceLoc, diag::err_duplicate_class_def, ClassName->getName());
+
IDecl = new ObjcInterfaceDecl(AtInterfaceLoc, ClassName);
// 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) {
+ Diag(AtInterfaceLoc, diag::err_undef_superclass, SuperName->getName(),
+ ClassName->getName());
+ }
+ }
+
+ Context.setObjCInterfaceDecl(ClassName, IDecl);
+
return IDecl;
}