[cfe-commits] r96696 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaDeclObjC.cpp test/SemaObjC/ivar-in-implementations.m
Fariborz Jahanian
fjahanian at apple.com
Fri Feb 19 12:58:55 PST 2010
Author: fjahanian
Date: Fri Feb 19 14:58:54 2010
New Revision: 96696
URL: http://llvm.org/viewvc/llvm-project?rev=96696&view=rev
Log:
Start supporting declaration of ivars in @implementation
blocks. WIP.
Added:
cfe/trunk/test/SemaObjC/ivar-in-implementations.m
Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/SemaDeclObjC.cpp
Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=96696&r1=96695&r2=96696&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Fri Feb 19 14:58:54 2010
@@ -253,6 +253,12 @@
"reimplementation of category %1 for class %0">;
def err_conflicting_ivar_type : Error<
"instance variable %0 has conflicting type: %1 vs %2">;
+def err_duplicate_ivar_declaration : Error<
+ "instance variable is already declared">;
+def warn_on_superclass_use : Warning<
+ "class implementation may not have super class">;
+def err_non_private_ivar_declaration : Error<
+ "only private ivars may be declared in implementation">;
def err_conflicting_ivar_bitwidth : Error<
"instance variable %0 has conflicting bit-field width">;
def err_conflicting_ivar_name : Error<
Modified: cfe/trunk/lib/Sema/SemaDeclObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclObjC.cpp?rev=96696&r1=96695&r2=96696&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclObjC.cpp Fri Feb 19 14:58:54 2010
@@ -836,7 +836,26 @@
return;
assert(ivars && "missing @implementation ivars");
-
+ if (LangOpts.ObjCNonFragileABI2) {
+ if (ImpDecl->getSuperClass())
+ Diag(ImpDecl->getLocation(), diag::warn_on_superclass_use);
+ for (unsigned i = 0; i < numIvars; i++) {
+ ObjCIvarDecl* ImplIvar = ivars[i];
+ if (const ObjCIvarDecl *ClsIvar =
+ IDecl->getIvarDecl(ImplIvar->getIdentifier())) {
+ Diag(ImplIvar->getLocation(), diag::err_duplicate_ivar_declaration);
+ Diag(ClsIvar->getLocation(), diag::note_previous_definition);
+ continue;
+ }
+ if (ImplIvar->getAccessControl() != ObjCIvarDecl::Private)
+ Diag(ImplIvar->getLocation(), diag::err_non_private_ivar_declaration);
+ // Instance ivar to Implementation's DeclContext.
+ ImplIvar->setLexicalDeclContext(ImpDecl);
+ IDecl->makeDeclVisibleInContext(ImplIvar, false);
+ ImpDecl->addDecl(ImplIvar);
+ }
+ return;
+ }
// Check interface's Ivar list against those in the implementation.
// names and types must match.
//
Added: cfe/trunk/test/SemaObjC/ivar-in-implementations.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/ivar-in-implementations.m?rev=96696&view=auto
==============================================================================
--- cfe/trunk/test/SemaObjC/ivar-in-implementations.m (added)
+++ cfe/trunk/test/SemaObjC/ivar-in-implementations.m Fri Feb 19 14:58:54 2010
@@ -0,0 +1,22 @@
+// RUN: %clang_cc1 -fsyntax-only -fobjc-nonfragile-abi2 -verify %s
+
+ at interface Super @end
+
+ at interface INTFSTANDALONE : Super
+{
+ id IVAR; // expected-note {{previous definition is here}}
+}
+
+ at end
+
+ at implementation INTFSTANDALONE : Super // expected-warning {{class implementation may not have super class}}
+{
+ at private
+ id IVAR1;
+ at protected
+ id IVAR2; // expected-error {{only private ivars may be declared in implementation}}
+ at private
+ id IVAR3;
+ int IVAR; // expected-error {{instance variable is already declared}}
+}
+ at end
More information about the cfe-commits
mailing list