diff options
author | Fariborz Jahanian <fjahanian@apple.com> | 2011-08-31 22:24:06 +0000 |
---|---|---|
committer | Fariborz Jahanian <fjahanian@apple.com> | 2011-08-31 22:24:06 +0000 |
commit | 8697d308c1bdd50e5c45757ac11be701c26e9e97 (patch) | |
tree | 59afd9cf6f5b60347b1c2886b66bd4d0e1d28162 /lib/Sema | |
parent | e082af17d4b425a49f7f8bccc2a99810f0072828 (diff) |
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
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@138913 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema')
-rw-r--r-- | lib/Sema/SemaCodeComplete.cpp | 6 | ||||
-rw-r--r-- | lib/Sema/SemaDecl.cpp | 18 | ||||
-rw-r--r-- | lib/Sema/SemaDeclObjC.cpp | 4 | ||||
-rw-r--r-- | lib/Sema/SemaExpr.cpp | 97 | ||||
-rw-r--r-- | lib/Sema/SemaLookup.cpp | 19 | ||||
-rw-r--r-- | lib/Sema/SemaObjCProperty.cpp | 10 |
6 files changed, 11 insertions, 143 deletions
diff --git a/lib/Sema/SemaCodeComplete.cpp b/lib/Sema/SemaCodeComplete.cpp index 5e19148c38..21ba3f9be5 100644 --- a/lib/Sema/SemaCodeComplete.cpp +++ b/lib/Sema/SemaCodeComplete.cpp @@ -990,9 +990,6 @@ bool ResultBuilder::IsOrdinaryName(NamedDecl *ND) const { 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 @@ bool ResultBuilder::IsOrdinaryNonTypeName(NamedDecl *ND) const { 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; diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index e09896a60c..85352c2e5a 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -420,24 +420,6 @@ Sema::NameClassification Sema::ClassifyName(Scope *S, 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; diff --git a/lib/Sema/SemaDeclObjC.cpp b/lib/Sema/SemaDeclObjC.cpp index 0bc9412c65..3e657c70e6 100644 --- a/lib/Sema/SemaDeclObjC.cpp +++ b/lib/Sema/SemaDeclObjC.cpp @@ -2201,10 +2201,6 @@ void Sema::ActOnAtEnd(Scope *S, SourceRange AtEnd, } } } - - if (LangOpts.ObjCDefaultSynthProperties && - LangOpts.ObjCNonFragileABI2) - DefaultSynthesizeProperties(S, IC, IDecl); ImplMethodsVsClassMethods(S, IC, IDecl); AtomicPropertySetterGetterRules(IC, IDecl); DiagnoseOwningPropertyGetterSynthesis(IC); diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index 928b11bd0b..b8f35639e3 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -1553,90 +1553,6 @@ bool Sema::DiagnoseEmptyLookup(Scope *S, CXXScopeSpec &SS, LookupResult &R, 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 @@ ExprResult Sema::ActOnIdExpression(Scope *S, 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(); } diff --git a/lib/Sema/SemaLookup.cpp b/lib/Sema/SemaLookup.cpp index 5dbadf7dea..c5dc144695 100644 --- a/lib/Sema/SemaLookup.cpp +++ b/lib/Sema/SemaLookup.cpp @@ -2885,24 +2885,7 @@ static void LookupVisibleDecls(Scope *S, LookupResult &Result, 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); } } diff --git a/lib/Sema/SemaObjCProperty.cpp b/lib/Sema/SemaObjCProperty.cpp index f4743acec5..84052fd9d8 100644 --- a/lib/Sema/SemaObjCProperty.cpp +++ b/lib/Sema/SemaObjCProperty.cpp @@ -1289,6 +1289,16 @@ void Sema::DefaultSynthesizeProperties (Scope *S, ObjCImplDecl* IMPDecl, } } +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) { |