[cfe-commits] r138913 - in /cfe/trunk: include/clang/Sema/Sema.h lib/Driver/Tools.cpp lib/Parse/ParseObjc.cpp lib/Sema/SemaCodeComplete.cpp lib/Sema/SemaDecl.cpp lib/Sema/SemaDeclObjC.cpp lib/Sema/SemaExpr.cpp lib/Sema/SemaLookup.cpp lib/Sema/SemaObjCProperty.cpp test/SemaObjC/default-synthesize-1.m test/SemaObjC/direct-synthesized-ivar-access.m
Fariborz Jahanian
fjahanian at apple.com
Wed Aug 31 15:24:07 PDT 2011
Author: fjahanian
Date: Wed Aug 31 17:24:06 2011
New Revision: 138913
URL: http://llvm.org/viewvc/llvm-project?rev=138913&view=rev
Log:
objective-c: this patch (re)introduces objective-c's default property
synthesis. This new feature is currently placed under
-fobjc-default-synthesize-properties option
and is off by default pending further testing.
It will become the default feature soon.
// rdar://8843851
Modified:
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/lib/Driver/Tools.cpp
cfe/trunk/lib/Parse/ParseObjc.cpp
cfe/trunk/lib/Sema/SemaCodeComplete.cpp
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/lib/Sema/SemaDeclObjC.cpp
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/lib/Sema/SemaLookup.cpp
cfe/trunk/lib/Sema/SemaObjCProperty.cpp
cfe/trunk/test/SemaObjC/default-synthesize-1.m
cfe/trunk/test/SemaObjC/direct-synthesized-ivar-access.m
Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=138913&r1=138912&r2=138913&view=diff
==============================================================================
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Wed Aug 31 17:24:06 2011
@@ -1829,14 +1829,6 @@
ObjCIvarDecl **Fields, unsigned nIvars,
SourceLocation Loc);
- /// \brief Determine whether we can synthesize a provisional ivar for the
- /// given name.
- ObjCPropertyDecl *canSynthesizeProvisionalIvar(IdentifierInfo *II);
-
- /// \brief Determine whether we can synthesize a provisional ivar for the
- /// given property.
- bool canSynthesizeProvisionalIvar(ObjCPropertyDecl *Property);
-
/// ImplMethodsVsClassMethods - This is main routine to warn if any method
/// remains unimplemented in the class or category @implementation.
void ImplMethodsVsClassMethods(Scope *S, ObjCImplDecl* IMPDecl,
@@ -1853,6 +1845,7 @@
/// properties which must be synthesized in class's @implementation.
void DefaultSynthesizeProperties (Scope *S, ObjCImplDecl* IMPDecl,
ObjCInterfaceDecl *IDecl);
+ void DefaultSynthesizeProperties(Scope *S, Decl *D);
/// CollectImmediateProperties - This routine collects all properties in
/// the class and its conforming protocols; but not those it its super class.
@@ -2245,10 +2238,6 @@
// Primary Expressions.
SourceRange getExprRange(Expr *E) const;
-
- ObjCIvarDecl *SynthesizeProvisionalIvar(LookupResult &Lookup,
- IdentifierInfo *II,
- SourceLocation NameLoc);
ExprResult ActOnIdExpression(Scope *S, CXXScopeSpec &SS, UnqualifiedId &Name,
bool HasTrailingLParen, bool IsAddressOfOperand);
Modified: cfe/trunk/lib/Driver/Tools.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=138913&r1=138912&r2=138913&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/Tools.cpp (original)
+++ cfe/trunk/lib/Driver/Tools.cpp Wed Aug 31 17:24:06 2011
@@ -1880,18 +1880,12 @@
}
}
- // FIXME: Don't expose -fobjc-default-synthesize-properties as a top-level
- // driver flag yet. This feature is still under active development
- // and shouldn't be exposed as a user visible feature (which may change).
- // Clang still supports this as a -cc1 option for development and testing.
-#if 0
// -fobjc-default-synthesize-properties=0 is default.
if (Args.hasFlag(options::OPT_fobjc_default_synthesize_properties,
options::OPT_fno_objc_default_synthesize_properties,
getToolChain().IsObjCDefaultSynthPropertiesDefault())) {
CmdArgs.push_back("-fobjc-default-synthesize-properties");
}
-#endif
}
// Allow -fno-objc-arr to trump -fobjc-arr/-fobjc-arc.
Modified: cfe/trunk/lib/Parse/ParseObjc.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseObjc.cpp?rev=138913&r1=138912&r2=138913&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseObjc.cpp (original)
+++ cfe/trunk/lib/Parse/ParseObjc.cpp Wed Aug 31 17:24:06 2011
@@ -1401,22 +1401,23 @@
"ParseObjCAtEndDeclaration(): Expected @end");
ConsumeToken(); // the "end" identifier
SmallVector<Decl *, 8> DeclsInGroup;
-
+ Actions.DefaultSynthesizeProperties(getCurScope(), ObjCImpDecl);
for (size_t i = 0; i < LateParsedObjCMethods.size(); ++i) {
Decl *D = ParseLexedObjCMethodDefs(*LateParsedObjCMethods[i]);
DeclsInGroup.push_back(D);
}
- LateParsedObjCMethods.clear();
DeclsInGroup.push_back(ObjCImpDecl);
+
if (ObjCImpDecl) {
Actions.ActOnAtEnd(getCurScope(), atEnd);
- ObjCImpDecl = 0;
PendingObjCImpDecl.pop_back();
}
- else {
+ else
// missing @implementation
Diag(atEnd.getBegin(), diag::err_expected_implementation);
- }
+
+ LateParsedObjCMethods.clear();
+ ObjCImpDecl = 0;
return Actions.BuildDeclaratorGroup(
DeclsInGroup.data(), DeclsInGroup.size(), false);
}
Modified: cfe/trunk/lib/Sema/SemaCodeComplete.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCodeComplete.cpp?rev=138913&r1=138912&r2=138913&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaCodeComplete.cpp (original)
+++ cfe/trunk/lib/Sema/SemaCodeComplete.cpp Wed Aug 31 17:24:06 2011
@@ -990,9 +990,6 @@
else if (SemaRef.getLangOptions().ObjC1) {
if (isa<ObjCIvarDecl>(ND))
return true;
- if (isa<ObjCPropertyDecl>(ND) &&
- SemaRef.canSynthesizeProvisionalIvar(cast<ObjCPropertyDecl>(ND)))
- return true;
}
return ND->getIdentifierNamespace() & IDNS;
@@ -1011,9 +1008,6 @@
else if (SemaRef.getLangOptions().ObjC1) {
if (isa<ObjCIvarDecl>(ND))
return true;
- if (isa<ObjCPropertyDecl>(ND) &&
- SemaRef.canSynthesizeProvisionalIvar(cast<ObjCPropertyDecl>(ND)))
- return true;
}
return ND->getIdentifierNamespace() & IDNS;
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=138913&r1=138912&r2=138913&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Wed Aug 31 17:24:06 2011
@@ -420,24 +420,6 @@
ExprResult E = LookupInObjCMethod(Result, S, Name, true);
if (E.get() || E.isInvalid())
return E;
-
- // Synthesize ivars lazily.
- if (getLangOptions().ObjCDefaultSynthProperties &&
- getLangOptions().ObjCNonFragileABI2) {
- if (SynthesizeProvisionalIvar(Result, Name, NameLoc)) {
- if (const ObjCPropertyDecl *Property =
- canSynthesizeProvisionalIvar(Name)) {
- Diag(NameLoc, diag::warn_synthesized_ivar_access) << Name;
- Diag(Property->getLocation(), diag::note_property_declare);
- }
-
- // FIXME: This is strange. Shouldn't we just take the ivar returned
- // from SynthesizeProvisionalIvar and continue with that?
- E = LookupInObjCMethod(Result, S, Name, true);
- if (E.get() || E.isInvalid())
- return E;
- }
- }
}
bool SecondTry = false;
Modified: cfe/trunk/lib/Sema/SemaDeclObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclObjC.cpp?rev=138913&r1=138912&r2=138913&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclObjC.cpp Wed Aug 31 17:24:06 2011
@@ -2201,10 +2201,6 @@
}
}
}
-
- if (LangOpts.ObjCDefaultSynthProperties &&
- LangOpts.ObjCNonFragileABI2)
- DefaultSynthesizeProperties(S, IC, IDecl);
ImplMethodsVsClassMethods(S, IC, IDecl);
AtomicPropertySetterGetterRules(IC, IDecl);
DiagnoseOwningPropertyGetterSynthesis(IC);
Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=138913&r1=138912&r2=138913&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Wed Aug 31 17:24:06 2011
@@ -1553,90 +1553,6 @@
return true;
}
-ObjCPropertyDecl *Sema::canSynthesizeProvisionalIvar(IdentifierInfo *II) {
- ObjCMethodDecl *CurMeth = getCurMethodDecl();
- ObjCInterfaceDecl *IDecl = CurMeth->getClassInterface();
- if (!IDecl)
- return 0;
- ObjCImplementationDecl *ClassImpDecl = IDecl->getImplementation();
- if (!ClassImpDecl)
- return 0;
- ObjCPropertyDecl *property = LookupPropertyDecl(IDecl, II);
- if (!property)
- return 0;
- if (ObjCPropertyImplDecl *PIDecl = ClassImpDecl->FindPropertyImplDecl(II))
- if (PIDecl->getPropertyImplementation() == ObjCPropertyImplDecl::Dynamic ||
- PIDecl->getPropertyIvarDecl())
- return 0;
- return property;
-}
-
-bool Sema::canSynthesizeProvisionalIvar(ObjCPropertyDecl *Property) {
- ObjCMethodDecl *CurMeth = getCurMethodDecl();
- ObjCInterfaceDecl *IDecl = CurMeth->getClassInterface();
- if (!IDecl)
- return false;
- ObjCImplementationDecl *ClassImpDecl = IDecl->getImplementation();
- if (!ClassImpDecl)
- return false;
- if (ObjCPropertyImplDecl *PIDecl
- = ClassImpDecl->FindPropertyImplDecl(Property->getIdentifier()))
- if (PIDecl->getPropertyImplementation() == ObjCPropertyImplDecl::Dynamic ||
- PIDecl->getPropertyIvarDecl())
- return false;
-
- return true;
-}
-
-ObjCIvarDecl *Sema::SynthesizeProvisionalIvar(LookupResult &Lookup,
- IdentifierInfo *II,
- SourceLocation NameLoc) {
- ObjCMethodDecl *CurMeth = getCurMethodDecl();
- bool LookForIvars;
- if (Lookup.empty())
- LookForIvars = true;
- else if (CurMeth->isClassMethod())
- LookForIvars = false;
- else
- LookForIvars = (Lookup.isSingleResult() &&
- Lookup.getFoundDecl()->isDefinedOutsideFunctionOrMethod() &&
- (Lookup.getAsSingle<VarDecl>() != 0));
- if (!LookForIvars)
- return 0;
-
- ObjCInterfaceDecl *IDecl = CurMeth->getClassInterface();
- if (!IDecl)
- return 0;
- ObjCImplementationDecl *ClassImpDecl = IDecl->getImplementation();
- if (!ClassImpDecl)
- return 0;
- bool DynamicImplSeen = false;
- ObjCPropertyDecl *property = LookupPropertyDecl(IDecl, II);
- if (!property)
- return 0;
- if (ObjCPropertyImplDecl *PIDecl = ClassImpDecl->FindPropertyImplDecl(II)) {
- DynamicImplSeen =
- (PIDecl->getPropertyImplementation() == ObjCPropertyImplDecl::Dynamic);
- // property implementation has a designated ivar. No need to assume a new
- // one.
- if (!DynamicImplSeen && PIDecl->getPropertyIvarDecl())
- return 0;
- }
- if (!DynamicImplSeen) {
- QualType PropType = Context.getCanonicalType(property->getType());
- ObjCIvarDecl *Ivar = ObjCIvarDecl::Create(Context, ClassImpDecl,
- NameLoc, NameLoc,
- II, PropType, /*Dinfo=*/0,
- ObjCIvarDecl::Private,
- (Expr *)0, true);
- ClassImpDecl->addDecl(Ivar);
- IDecl->makeDeclVisibleInContext(Ivar, false);
- property->setPropertyIvarDecl(Ivar);
- return Ivar;
- }
- return 0;
-}
-
ExprResult Sema::ActOnIdExpression(Scope *S,
CXXScopeSpec &SS,
UnqualifiedId &Id,
@@ -1726,19 +1642,6 @@
if (Expr *Ex = E.takeAs<Expr>())
return Owned(Ex);
- // Synthesize ivars lazily.
- if (getLangOptions().ObjCDefaultSynthProperties &&
- getLangOptions().ObjCNonFragileABI2) {
- if (SynthesizeProvisionalIvar(R, II, NameLoc)) {
- if (const ObjCPropertyDecl *Property =
- canSynthesizeProvisionalIvar(II)) {
- Diag(NameLoc, diag::warn_synthesized_ivar_access) << II;
- Diag(Property->getLocation(), diag::note_property_declare);
- }
- return ActOnIdExpression(S, SS, Id, HasTrailingLParen,
- isAddressOfOperand);
- }
- }
// for further use, this must be set to false if in class method.
IvarLookupFollowUp = getCurMethodDecl()->isInstanceMethod();
}
Modified: cfe/trunk/lib/Sema/SemaLookup.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaLookup.cpp?rev=138913&r1=138912&r2=138913&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaLookup.cpp (original)
+++ cfe/trunk/lib/Sema/SemaLookup.cpp Wed Aug 31 17:24:06 2011
@@ -2885,24 +2885,7 @@
Result.getNameLoc(), Sema::LookupMemberName);
if (ObjCInterfaceDecl *IFace = Method->getClassInterface()) {
LookupVisibleDecls(IFace, IvarResult, /*QualifiedNameLookup=*/false,
- /*InBaseClass=*/false, Consumer, Visited);
-
- // Look for properties from which we can synthesize ivars, if
- // permitted.
- if (Result.getSema().getLangOptions().ObjCNonFragileABI2 &&
- IFace->getImplementation() &&
- Result.getLookupKind() == Sema::LookupOrdinaryName) {
- for (ObjCInterfaceDecl::prop_iterator
- P = IFace->prop_begin(),
- PEnd = IFace->prop_end();
- P != PEnd; ++P) {
- if (Result.getSema().canSynthesizeProvisionalIvar(*P) &&
- !IFace->lookupInstanceVariable((*P)->getIdentifier())) {
- Consumer.FoundDecl(*P, Visited.checkHidden(*P), false);
- Visited.add(*P);
- }
- }
- }
+ /*InBaseClass=*/false, Consumer, Visited);
}
}
Modified: cfe/trunk/lib/Sema/SemaObjCProperty.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaObjCProperty.cpp?rev=138913&r1=138912&r2=138913&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaObjCProperty.cpp (original)
+++ cfe/trunk/lib/Sema/SemaObjCProperty.cpp Wed Aug 31 17:24:06 2011
@@ -1289,6 +1289,16 @@
}
}
+void Sema::DefaultSynthesizeProperties(Scope *S, Decl *D) {
+ if (!LangOpts.ObjCDefaultSynthProperties || !LangOpts.ObjCNonFragileABI2)
+ return;
+ ObjCImplementationDecl *IC=dyn_cast_or_null<ObjCImplementationDecl>(D);
+ if (!IC)
+ return;
+ if (ObjCInterfaceDecl* IDecl = IC->getClassInterface())
+ DefaultSynthesizeProperties(S, IC, IDecl);
+}
+
void Sema::DiagnoseUnimplementedProperties(Scope *S, ObjCImplDecl* IMPDecl,
ObjCContainerDecl *CDecl,
const llvm::DenseSet<Selector>& InsMap) {
Modified: cfe/trunk/test/SemaObjC/default-synthesize-1.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/default-synthesize-1.m?rev=138913&r1=138912&r2=138913&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/default-synthesize-1.m (original)
+++ cfe/trunk/test/SemaObjC/default-synthesize-1.m Wed Aug 31 17:24:06 2011
@@ -68,19 +68,19 @@
//@synthesize howMany, what; // REM: Redundant anyway
- (int) howMany {
- return howMany;
+ return howMany; // expected-error {{use of undeclared identifier 'howMany'}}
}
- (void) setHowMany: (int) value {
- howMany = value;
+ howMany = value; // expected-error {{use of undeclared identifier 'howMany'}}
}
- (NSString*) what {
- return what;
+ return what; // expected-error {{use of undeclared identifier 'what'}}
}
- (void) setWhat: (NSString*) value {
- if (what != value) {
- [what release];
- what = [value retain];
+ if (what != value) { // expected-error {{use of undeclared identifier 'what'}}
+ [what release]; // expected-error {{use of undeclared identifier 'what'}}
+ what = [value retain]; // expected-error {{use of undeclared identifier 'what'}}
}
}
@end
Modified: cfe/trunk/test/SemaObjC/direct-synthesized-ivar-access.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/direct-synthesized-ivar-access.m?rev=138913&r1=138912&r2=138913&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/direct-synthesized-ivar-access.m (original)
+++ cfe/trunk/test/SemaObjC/direct-synthesized-ivar-access.m Wed Aug 31 17:24:06 2011
@@ -1,14 +1,15 @@
// RUN: %clang_cc1 -Wnonfragile-abi2 -fsyntax-only -fobjc-nonfragile-abi -fobjc-default-synthesize-properties -verify %s
// rdar://8673791
+// rdar://9943851
@interface I {
}
- at property int IVAR; // expected-note {{property declared here}}
+ at property int IVAR;
- (int) OK;
@end
@implementation I
-- (int) Meth { return IVAR; } // expected-warning {{direct access of synthesized ivar by using property access 'IVAR'}}
+- (int) Meth { return IVAR; }
- (int) OK { return self.IVAR; }
@end
More information about the cfe-commits
mailing list