[cfe-commits] r68077 - in /cfe/trunk: include/clang/AST/DeclObjC.h lib/AST/ASTContext.cpp lib/AST/DeclObjC.cpp lib/Sema/SemaDeclObjC.cpp test/SemaObjC/property-nonfragile-abi.m test/SemaObjC/synthesized-ivar.m
Fariborz Jahanian
fjahanian at apple.com
Mon Mar 30 17:06:30 PDT 2009
Author: fjahanian
Date: Mon Mar 30 19:06:29 2009
New Revision: 68077
URL: http://llvm.org/viewvc/llvm-project?rev=68077&view=rev
Log:
fe support for objc2's nonfragile-abi synthesized ivars.
Added:
cfe/trunk/test/SemaObjC/synthesized-ivar.m
Modified:
cfe/trunk/include/clang/AST/DeclObjC.h
cfe/trunk/lib/AST/ASTContext.cpp
cfe/trunk/lib/AST/DeclObjC.cpp
cfe/trunk/lib/Sema/SemaDeclObjC.cpp
cfe/trunk/test/SemaObjC/property-nonfragile-abi.m
Modified: cfe/trunk/include/clang/AST/DeclObjC.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclObjC.h?rev=68077&r1=68076&r2=68077&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/DeclObjC.h (original)
+++ cfe/trunk/include/clang/AST/DeclObjC.h Mon Mar 30 19:06:29 2009
@@ -1009,6 +1009,7 @@
ObjCMethodDecl *GetterMethodDecl; // Declaration of getter instance method
ObjCMethodDecl *SetterMethodDecl; // Declaration of setter instance method
+ ObjCIvarDecl *PropertyIvarDecl; // Synthesize ivar for this property
ObjCPropertyDecl(DeclContext *DC, SourceLocation L, IdentifierInfo *Id,
QualType T)
@@ -1016,7 +1017,7 @@
PropertyAttributes(OBJC_PR_noattr), PropertyImplementation(None),
GetterName(Selector()),
SetterName(Selector()),
- GetterMethodDecl(0), SetterMethodDecl(0) {}
+ GetterMethodDecl(0), SetterMethodDecl(0) , PropertyIvarDecl(0) {}
public:
static ObjCPropertyDecl *Create(ASTContext &C, DeclContext *DC,
SourceLocation L,
@@ -1074,6 +1075,13 @@
return PropertyControl(PropertyImplementation);
}
+ void setPropertyIvarDecl(ObjCIvarDecl *Ivar) {
+ PropertyIvarDecl = Ivar;
+ }
+ ObjCIvarDecl *getPropertyIvarDecl() const {
+ return PropertyIvarDecl;
+ }
+
static bool classof(const Decl *D) {
return D->getKind() == ObjCProperty;
}
@@ -1091,7 +1099,6 @@
Dynamic
};
private:
- unsigned IvarKind : 1;
SourceLocation AtLoc; // location of @synthesize or @dynamic
/// Property declaration being implemented
ObjCPropertyDecl *PropertyDecl;
@@ -1103,7 +1110,7 @@
ObjCPropertyDecl *property,
Kind PK,
ObjCIvarDecl *ivarDecl)
- : Decl(ObjCPropertyImpl, DC, L), IvarKind(false), AtLoc(atLoc),
+ : Decl(ObjCPropertyImpl, DC, L), AtLoc(atLoc),
PropertyDecl(property), PropertyIvarDecl(ivarDecl) {
assert (PK == Dynamic || PropertyIvarDecl);
}
@@ -1128,16 +1135,6 @@
ObjCIvarDecl *getPropertyIvarDecl() const {
return PropertyIvarDecl;
}
- void SetPropertyIvarDecl(ObjCIvarDecl *Ivar) {
- assert(PropertyIvarDecl && "PropertyIvarDecl is already defined");
- PropertyIvarDecl = Ivar;
- }
- void SetIvarSynthesized() {
- IvarKind = true;
- }
- bool IsIvarSynthesized() const {
- return IvarKind;
- }
static bool classof(const Decl *D) {
return D->getKind() == ObjCPropertyImpl;
Modified: cfe/trunk/lib/AST/ASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=68077&r1=68076&r2=68077&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Mon Mar 30 19:06:29 2009
@@ -608,6 +608,13 @@
if (!IVDecl->isInvalidDecl())
Fields.push_back(cast<FieldDecl>(IVDecl));
}
+ // look into properties.
+ for (ObjCInterfaceDecl::prop_iterator I = OI->prop_begin(),
+ E = OI->prop_end(); I != E; ++I) {
+ ObjCPropertyDecl *PDecl = (*I);
+ if (ObjCIvarDecl *IV = PDecl->getPropertyIvarDecl())
+ Fields.push_back(cast<FieldDecl>(IV));
+ }
}
/// addRecordToClass - produces record info. for the class for its
Modified: cfe/trunk/lib/AST/DeclObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclObjC.cpp?rev=68077&r1=68076&r2=68077&view=diff
==============================================================================
--- cfe/trunk/lib/AST/DeclObjC.cpp (original)
+++ cfe/trunk/lib/AST/DeclObjC.cpp Mon Mar 30 19:06:29 2009
@@ -137,6 +137,16 @@
return *I;
}
}
+ // look into properties.
+ for (ObjCInterfaceDecl::prop_iterator I = ClassDecl->prop_begin(),
+ E = ClassDecl->prop_end(); I != E; ++I) {
+ ObjCPropertyDecl *PDecl = (*I);
+ if (ObjCIvarDecl *IV = PDecl->getPropertyIvarDecl())
+ if (IV->getIdentifier() == ID) {
+ clsDeclared = ClassDecl;
+ return IV;
+ }
+ }
ClassDecl = ClassDecl->getSuperClass();
}
return NULL;
Modified: cfe/trunk/lib/Sema/SemaDeclObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclObjC.cpp?rev=68077&r1=68076&r2=68077&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclObjC.cpp Mon Mar 30 19:06:29 2009
@@ -1765,17 +1765,22 @@
// @synthesize
if (!PropertyIvar)
PropertyIvar = PropertyId;
+ QualType PropType = Context.getCanonicalType(property->getType());
// Check that this is a previously declared 'ivar' in 'IDecl' interface
Ivar = IDecl->lookupInstanceVariable(PropertyIvar);
if (!Ivar) {
- if (getLangOptions().ObjCNonFragileABI)
- Diag(PropertyLoc, diag::error_synthesized_ivar_yet_not_supported)
- << PropertyId;
- else
+ if (getLangOptions().ObjCNonFragileABI) {
+ Ivar = ObjCIvarDecl::Create(Context, CurContext, PropertyLoc,
+ PropertyIvar, PropType,
+ ObjCIvarDecl::Private,
+ (Expr *)0);
+ property->setPropertyIvarDecl(Ivar);
+ }
+ else {
Diag(PropertyLoc, diag::error_missing_property_ivar_decl) << PropertyId;
- return DeclPtrTy();
+ return DeclPtrTy();
+ }
}
- QualType PropType = Context.getCanonicalType(property->getType());
QualType IvarType = Context.getCanonicalType(Ivar->getType());
// Check that type of property and its ivar are type compatible.
Modified: cfe/trunk/test/SemaObjC/property-nonfragile-abi.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/property-nonfragile-abi.m?rev=68077&r1=68076&r2=68077&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/property-nonfragile-abi.m (original)
+++ cfe/trunk/test/SemaObjC/property-nonfragile-abi.m Mon Mar 30 19:06:29 2009
@@ -16,7 +16,6 @@
@end
@implementation XCDeviceWillExecuteInfoBaton
- // Produce an error when compiling for -arch x86_64 (or "non-fragile" ABI)
- @synthesize sdkPath; // expected-error{{instance variable synthesis not yet supported (need to declare 'sdkPath' explicitly)}}
+ @synthesize sdkPath;
@end
Added: cfe/trunk/test/SemaObjC/synthesized-ivar.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/synthesized-ivar.m?rev=68077&view=auto
==============================================================================
--- cfe/trunk/test/SemaObjC/synthesized-ivar.m (added)
+++ cfe/trunk/test/SemaObjC/synthesized-ivar.m Mon Mar 30 19:06:29 2009
@@ -0,0 +1,13 @@
+// RUN: clang-cc -fsyntax-only -triple x86_64-apple-darwin9 -verify %s
+ at interface I
+{
+}
+ at property int IP;
+ at end
+
+ at implementation I
+ at synthesize IP;
+- (int) Meth {
+ return IP;
+}
+ at end
More information about the cfe-commits
mailing list