diff options
| author | John McCall <rjmccall@apple.com> | 2010-12-02 01:19:52 +0000 |
|---|---|---|
| committer | John McCall <rjmccall@apple.com> | 2010-12-02 01:19:52 +0000 |
| commit | b7bd14fa08d68da7936b97b03912026ec06cb830 (patch) | |
| tree | 6149f8b6a48e6786e2aeb09ec66fce52828226bc /clang/lib/Sema | |
| parent | 13e3b00e7619688a9e69eec0e0a49f74f2aed365 (diff) | |
| download | bcm5719-llvm-b7bd14fa08d68da7936b97b03912026ec06cb830.tar.gz bcm5719-llvm-b7bd14fa08d68da7936b97b03912026ec06cb830.zip | |
Simplify the ASTs by consolidating ObjCImplicitGetterSetterExpr and ObjCPropertyRefExpr
into the latter.
llvm-svn: 120643
Diffstat (limited to 'clang/lib/Sema')
| -rw-r--r-- | clang/lib/Sema/SemaExpr.cpp | 56 | ||||
| -rw-r--r-- | clang/lib/Sema/SemaExprObjC.cpp | 19 | ||||
| -rw-r--r-- | clang/lib/Sema/SemaStmt.cpp | 12 | ||||
| -rw-r--r-- | clang/lib/Sema/TreeTransform.h | 99 |
4 files changed, 67 insertions, 119 deletions
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index ac764ab8003..c99c4916743 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -3538,9 +3538,9 @@ Sema::LookupMemberExpr(LookupResult &R, Expr *&BaseExpr, ExprObjectKind OK = (VK == VK_RValue ? OK_Ordinary : OK_ObjCProperty); // FIXME: we must check that the setter has property type. - return Owned(new (Context) ObjCImplicitSetterGetterRefExpr(Getter, - PType, VK, OK, - Setter, MemberLoc, BaseExpr)); + return Owned(new (Context) ObjCPropertyRefExpr(Getter, Setter, + PType, VK, OK, + MemberLoc, BaseExpr)); } return ExprError(Diag(MemberLoc, diag::err_property_not_found) << MemberName << BaseType); @@ -3726,10 +3726,8 @@ Sema::LookupMemberExpr(LookupResult &R, Expr *&BaseExpr, VK = VK_RValue; ExprObjectKind OK = (VK == VK_RValue ? OK_Ordinary : OK_ObjCProperty); - return Owned(new (Context) ObjCImplicitSetterGetterRefExpr(OMD, PType, - VK, OK, SMD, - MemberLoc, - BaseExpr)); + return Owned(new (Context) ObjCPropertyRefExpr(OMD, SMD, PType, VK, OK, + MemberLoc, BaseExpr)); } } @@ -6683,17 +6681,18 @@ inline QualType Sema::CheckLogicalOperands( // C99 6.5.[13,14] static bool IsReadonlyProperty(Expr *E, Sema &S) { if (E->getStmtClass() == Expr::ObjCPropertyRefExprClass) { const ObjCPropertyRefExpr* PropExpr = cast<ObjCPropertyRefExpr>(E); - if (ObjCPropertyDecl *PDecl = PropExpr->getProperty()) { - QualType BaseType = PropExpr->isSuperReceiver() ? - PropExpr->getSuperType() : + if (PropExpr->isImplicitProperty()) return false; + + ObjCPropertyDecl *PDecl = PropExpr->getExplicitProperty(); + QualType BaseType = PropExpr->isSuperReceiver() ? + PropExpr->getSuperReceiverType() : PropExpr->getBase()->getType(); - if (const ObjCObjectPointerType *OPT = - BaseType->getAsObjCInterfacePointerType()) - if (ObjCInterfaceDecl *IFace = OPT->getInterfaceDecl()) - if (S.isPropertyReadonly(PDecl, IFace)) - return true; - } + if (const ObjCObjectPointerType *OPT = + BaseType->getAsObjCInterfacePointerType()) + if (ObjCInterfaceDecl *IFace = OPT->getInterfaceDecl()) + if (S.isPropertyReadonly(PDecl, IFace)) + return true; } return false; } @@ -6970,20 +6969,18 @@ static QualType CheckIncrementDecrementOperand(Sema &S, Expr *Op, void Sema::ConvertPropertyAssignment(Expr *LHS, Expr *&RHS, QualType& LHSTy) { bool copyInit = false; - if (const ObjCImplicitSetterGetterRefExpr *OISGE = - dyn_cast<ObjCImplicitSetterGetterRefExpr>(LHS)) { - // If using property-dot syntax notation for assignment, and there is a - // setter, RHS expression is being passed to the setter argument. So, - // type conversion (and comparison) is RHS to setter's argument type. - if (const ObjCMethodDecl *SetterMD = OISGE->getSetterMethod()) { - ObjCMethodDecl::param_iterator P = SetterMD->param_begin(); - LHSTy = (*P)->getType(); + if (const ObjCPropertyRefExpr *PRE = dyn_cast<ObjCPropertyRefExpr>(LHS)) { + if (PRE->isImplicitProperty()) { + // If using property-dot syntax notation for assignment, and there is a + // setter, RHS expression is being passed to the setter argument. So, + // type conversion (and comparison) is RHS to setter's argument type. + if (const ObjCMethodDecl *SetterMD = PRE->getImplicitPropertySetter()) { + ObjCMethodDecl::param_iterator P = SetterMD->param_begin(); + LHSTy = (*P)->getType(); + } } copyInit = (getLangOptions().CPlusPlus && LHSTy->isRecordType()); } - else - copyInit = (getLangOptions().CPlusPlus && isa<ObjCPropertyRefExpr>(LHS) && - LHSTy->isRecordType()); if (copyInit) { InitializedEntity Entity = InitializedEntity::InitializeParameter(Context, LHSTy); @@ -7614,9 +7611,8 @@ ExprResult Sema::BuildBinOp(Scope *S, SourceLocation OpLoc, BinaryOperatorKind Opc, Expr *lhs, Expr *rhs) { if (getLangOptions().CPlusPlus && - ((!isa<ObjCImplicitSetterGetterRefExpr>(lhs) && - !isa<ObjCPropertyRefExpr>(lhs)) - || rhs->isTypeDependent() || Opc != BO_Assign) && + (!isa<ObjCPropertyRefExpr>(lhs) + || rhs->isTypeDependent() || Opc != BO_Assign) && (lhs->getType()->isOverloadableType() || rhs->getType()->isOverloadableType())) { // Find all of the overloaded operators visible from this diff --git a/clang/lib/Sema/SemaExprObjC.cpp b/clang/lib/Sema/SemaExprObjC.cpp index 047236b1bde..46a834a4874 100644 --- a/clang/lib/Sema/SemaExprObjC.cpp +++ b/clang/lib/Sema/SemaExprObjC.cpp @@ -439,12 +439,14 @@ HandleExprPropertyRefExpr(const ObjCObjectPointerType *OPT, VK = VK_RValue, OK = OK_Ordinary; if (Super) - return Owned(new (Context) ObjCImplicitSetterGetterRefExpr(Getter, PType, - VK, OK, Setter, MemberLoc, - SuperLoc, SuperType)); + return Owned(new (Context) ObjCPropertyRefExpr(Getter, Setter, + PType, VK, OK, + MemberLoc, + SuperLoc, SuperType)); else - return Owned(new (Context) ObjCImplicitSetterGetterRefExpr(Getter, PType, - VK, OK, Setter, MemberLoc, BaseExpr)); + return Owned(new (Context) ObjCPropertyRefExpr(Getter, Setter, + PType, VK, OK, + MemberLoc, BaseExpr)); } @@ -566,9 +568,10 @@ ActOnClassPropertyRefExpr(IdentifierInfo &receiverName, ExprObjectKind OK = (VK == VK_RValue ? OK_Ordinary : OK_ObjCProperty); - return Owned(new (Context) ObjCImplicitSetterGetterRefExpr( - Getter, PType, VK, OK, Setter, - propertyNameLoc, IFace, receiverNameLoc)); + return Owned(new (Context) ObjCPropertyRefExpr(Getter, Setter, + PType, VK, OK, + propertyNameLoc, + receiverNameLoc, IFace)); } return ExprError(Diag(propertyNameLoc, diag::err_property_not_found) << &propertyName << Context.getObjCInterfaceType(IFace)); diff --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp index 48d2b47c8a6..7fa555e4f90 100644 --- a/clang/lib/Sema/SemaStmt.cpp +++ b/clang/lib/Sema/SemaStmt.cpp @@ -89,13 +89,10 @@ void Sema::DiagnoseUnusedExprResult(const Stmt *S) { // we might want to make a more specific diagnostic. Check for one of these // cases now. unsigned DiagID = diag::warn_unused_expr; - E = E->IgnoreParens(); - if (isa<ObjCImplicitSetterGetterRefExpr>(E)) - DiagID = diag::warn_unused_property_expr; - if (const CXXExprWithTemporaries *Temps = dyn_cast<CXXExprWithTemporaries>(E)) E = Temps->getSubExpr(); - + + E = E->IgnoreParens(); if (const CallExpr *CE = dyn_cast<CallExpr>(E)) { if (E->getType()->isVoidType()) return; @@ -116,13 +113,14 @@ void Sema::DiagnoseUnusedExprResult(const Stmt *S) { return; } } - } - else if (const ObjCMessageExpr *ME = dyn_cast<ObjCMessageExpr>(E)) { + } else if (const ObjCMessageExpr *ME = dyn_cast<ObjCMessageExpr>(E)) { const ObjCMethodDecl *MD = ME->getMethodDecl(); if (MD && MD->getAttr<WarnUnusedResultAttr>()) { Diag(Loc, diag::warn_unused_call) << R1 << R2 << "warn_unused_result"; return; } + } else if (isa<ObjCPropertyRefExpr>(E)) { + DiagID = diag::warn_unused_property_expr; } else if (const CXXFunctionalCastExpr *FC = dyn_cast<CXXFunctionalCastExpr>(E)) { if (isa<CXXConstructExpr>(FC->getSubExpr()) || diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h index 5aea3f029d5..e0111f1e96d 100644 --- a/clang/lib/Sema/TreeTransform.h +++ b/clang/lib/Sema/TreeTransform.h @@ -1891,39 +1891,20 @@ public: /*TemplateArgs=*/0); } - /// \brief Build a new Objective-C implicit setter/getter reference - /// expression. + /// \brief Build a new Objective-C property reference expression. /// /// By default, performs semantic analysis to build the new expression. - /// Subclasses may override this routine to provide different behavior. - ExprResult RebuildObjCImplicitSetterGetterRefExpr( - ObjCMethodDecl *Getter, - QualType T, - ObjCMethodDecl *Setter, - SourceLocation NameLoc, - Expr *Base, - SourceLocation SuperLoc, - QualType SuperTy, - bool Super) { - // Since these expressions can only be value-dependent, we do not need to - // perform semantic analysis again. - if (Super) - return Owned( - new (getSema().Context) ObjCImplicitSetterGetterRefExpr(Getter, T, - VK_LValue, - OK_Ordinary, - Setter, - NameLoc, - SuperLoc, - SuperTy)); - else - return Owned( - new (getSema().Context) ObjCImplicitSetterGetterRefExpr(Getter, T, - VK_LValue, - OK_Ordinary, - Setter, - NameLoc, - Base)); + /// Subclasses may override this routine to provide different behavior. + ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T, + ObjCMethodDecl *Getter, + ObjCMethodDecl *Setter, + SourceLocation PropertyLoc) { + // Since these expressions can only be value-dependent, we do not + // need to perform semantic analysis again. + return Owned( + new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T, + VK_LValue, OK_ObjCProperty, + PropertyLoc, Base)); } /// \brief Build a new Objective-C "isa" expression. @@ -6222,9 +6203,9 @@ TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) { template<typename Derived> ExprResult TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) { - // 'super' never changes. Property never changes. Just retain the existing - // expression. - if (E->isSuperReceiver()) + // 'super' and types never change. Property never changes. Just + // retain the existing expression. + if (!E->isObjectReceiver()) return SemaRef.Owned(E); // Transform the base expression. @@ -6238,47 +6219,17 @@ TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) { if (!getDerived().AlwaysRebuild() && Base.get() == E->getBase()) return SemaRef.Owned(E); - - return getDerived().RebuildObjCPropertyRefExpr(Base.get(), E->getProperty(), - E->getLocation()); -} -template<typename Derived> -ExprResult -TreeTransform<Derived>::TransformObjCImplicitSetterGetterRefExpr( - ObjCImplicitSetterGetterRefExpr *E) { - // If this implicit setter/getter refers to super, it cannot have any - // dependent parts. Just retain the existing declaration. - if (E->isSuperReceiver()) - return SemaRef.Owned(E); - - // If this implicit setter/getter refers to class methods, it cannot have any - // dependent parts. Just retain the existing declaration. - if (E->getInterfaceDecl()) - return SemaRef.Owned(E); - - // Transform the base expression. - ExprResult Base = getDerived().TransformExpr(E->getBase()); - if (Base.isInvalid()) - return ExprError(); - - // We don't need to transform the getters/setters; they will never change. - - // If nothing changed, just retain the existing expression. - if (!getDerived().AlwaysRebuild() && - Base.get() == E->getBase()) - return SemaRef.Owned(E); - - return getDerived().RebuildObjCImplicitSetterGetterRefExpr( - E->getGetterMethod(), - E->getType(), - E->getSetterMethod(), - E->getLocation(), - Base.get(), - E->getSuperLocation(), - E->getSuperType(), - E->isSuperReceiver()); - + if (E->isExplicitProperty()) + return getDerived().RebuildObjCPropertyRefExpr(Base.get(), + E->getExplicitProperty(), + E->getLocation()); + + return getDerived().RebuildObjCPropertyRefExpr(Base.get(), + E->getType(), + E->getImplicitPropertyGetter(), + E->getImplicitPropertySetter(), + E->getLocation()); } template<typename Derived> |

