[cfe-commits] r42168 - in /cfe/trunk: Sema/SemaDecl.cpp include/clang/AST/ASTContext.h include/clang/Basic/DiagnosticKinds.def test/Sema/undef-superclass-1.m
Fariborz Jahanian
fjahanian at apple.com
Thu Sep 20 10:54:08 PDT 2007
Author: fjahanian
Date: Thu Sep 20 12:54:07 2007
New Revision: 42168
URL: http://llvm.org/viewvc/llvm-project?rev=42168&view=rev
Log:
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.
Added:
cfe/trunk/test/Sema/undef-superclass-1.m
Modified:
cfe/trunk/Sema/SemaDecl.cpp
cfe/trunk/include/clang/AST/ASTContext.h
cfe/trunk/include/clang/Basic/DiagnosticKinds.def
Modified: cfe/trunk/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/SemaDecl.cpp?rev=42168&r1=42167&r2=42168&view=diff
==============================================================================
--- cfe/trunk/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/Sema/SemaDecl.cpp Thu Sep 20 12:54:07 2007
@@ -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;
}
Modified: cfe/trunk/include/clang/AST/ASTContext.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTContext.h?rev=42168&r1=42167&r2=42168&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/ASTContext.h (original)
+++ cfe/trunk/include/clang/AST/ASTContext.h Thu Sep 20 12:54:07 2007
@@ -37,8 +37,10 @@
llvm::FoldingSet<FunctionTypeNoProto> FunctionTypeNoProtos;
llvm::FoldingSet<FunctionTypeProto> FunctionTypeProtos;
llvm::DenseMap<const RecordDecl*, const RecordLayout*> RecordLayoutInfo;
+ llvm::DenseMap<const IdentifierInfo*, const ObjcInterfaceDecl*> ClassNameInfo;
RecordDecl *CFConstantStringTypeDecl;
public:
+
SourceManager &SourceMgr;
TargetInfo &Target;
IdentifierTable &Idents;
@@ -157,6 +159,12 @@
/// position information.
const RecordLayout &getRecordLayout(const RecordDecl *D, SourceLocation L);
+ const ObjcInterfaceDecl* getObjCInterfaceDecl(const IdentifierInfo* ClassName)
+ { return ClassNameInfo[ClassName]; }
+ void setObjCInterfaceDecl(const IdentifierInfo* ClassName,
+ const ObjcInterfaceDecl* InterfaceDecl)
+ { ClassNameInfo[ClassName] = InterfaceDecl; }
+
//===--------------------------------------------------------------------===//
// Type Operators
//===--------------------------------------------------------------------===//
Modified: cfe/trunk/include/clang/Basic/DiagnosticKinds.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticKinds.def?rev=42168&r1=42167&r2=42168&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticKinds.def (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticKinds.def Thu Sep 20 12:54:07 2007
@@ -408,6 +408,11 @@
"@optional may be specified in protocols only")
DIAG(err_missing_catch_finally, ERROR,
"@try statment without a @catch and @finally clause")
+DIAG(err_undef_superclass, ERROR,
+ "cannot find interface declaration for '%0', superclass of '%1'")
+DIAG(err_duplicate_class_def, ERROR,
+ "duplicate interface declaration for class '%0'")
+
//===----------------------------------------------------------------------===//
// Semantic Analysis
Added: cfe/trunk/test/Sema/undef-superclass-1.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/undef-superclass-1.m?rev=42168&view=auto
==============================================================================
--- cfe/trunk/test/Sema/undef-superclass-1.m (added)
+++ cfe/trunk/test/Sema/undef-superclass-1.m Thu Sep 20 12:54:07 2007
@@ -0,0 +1,18 @@
+ at class SUPER, Y;
+
+ at interface INTF :SUPER // expected-error {{cannot find interface declaration for 'SUPER', superclass of 'INTF'}}
+ at end
+
+ at interface SUPER @end
+
+ at interface INTF1 : SUPER
+ at end
+
+ at interface INTF2 : INTF1
+ at end
+
+ at interface INTF3 : Y // expected-error {{cannot find interface declaration for 'Y', superclass of 'INTF3'}}
+ at end
+
+ at interface INTF1 // expected-error {{duplicate interface declaration for class 'INTF1'}}
+ at end
More information about the cfe-commits
mailing list