From: Anna Zaks Date: Mon, 1 Oct 2012 20:34:04 +0000 (+0000) Subject: Move isObjCSelf into Expr. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=bbff82f302a1dd67589f65912351978905f0c5a7;p=clang Move isObjCSelf into Expr. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@164966 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/AST/Expr.h b/include/clang/AST/Expr.h index d97c37aa59..6629e3e60c 100644 --- a/include/clang/AST/Expr.h +++ b/include/clang/AST/Expr.h @@ -392,6 +392,9 @@ public: /// property, find the underlying property reference expression. const ObjCPropertyRefExpr *getObjCProperty() const; + /// \brief Check if this expression is the ObjC 'self' implicit parameter. + bool isObjCSelfExpr() const; + /// \brief Returns whether this expression refers to a vector element. bool refersToVectorElement() const; diff --git a/lib/AST/Expr.cpp b/lib/AST/Expr.cpp index 30342585c8..e1198b85c5 100644 --- a/lib/AST/Expr.cpp +++ b/lib/AST/Expr.cpp @@ -3002,6 +3002,24 @@ const ObjCPropertyRefExpr *Expr::getObjCProperty() const { return cast(E); } +bool Expr::isObjCSelfExpr() const { + const Expr *E = IgnoreParenImpCasts(); + + const DeclRefExpr *DRE = dyn_cast(E); + if (!DRE) + return false; + + const ImplicitParamDecl *Param = dyn_cast(DRE->getDecl()); + if (!Param) + return false; + + const ObjCMethodDecl *M = dyn_cast(Param->getDeclContext()); + if (!M) + return false; + + return M->getSelfDecl() == Param; +} + FieldDecl *Expr::getBitField() { Expr *E = this->IgnoreParens(); diff --git a/lib/Sema/ScopeInfo.cpp b/lib/Sema/ScopeInfo.cpp index bb9420d1e7..7a9d917a02 100644 --- a/lib/Sema/ScopeInfo.cpp +++ b/lib/Sema/ScopeInfo.cpp @@ -41,24 +41,6 @@ static const NamedDecl *getBestPropertyDecl(const ObjCPropertyRefExpr *PropE) { return PropE->getImplicitPropertyGetter(); } -static bool isSelfExpr(const Expr *E) { - E = E->IgnoreParenImpCasts(); - - const DeclRefExpr *DRE = dyn_cast(E); - if (!DRE) - return false; - - const ImplicitParamDecl *Param = dyn_cast(DRE->getDecl()); - if (!Param) - return false; - - const ObjCMethodDecl *M = dyn_cast(Param->getDeclContext()); - if (!M) - return false; - - return M->getSelfDecl() == Param; -} - FunctionScopeInfo::WeakObjectProfileTy::BaseInfoTy FunctionScopeInfo::WeakObjectProfileTy::getBaseInfo(const Expr *E) { E = E->IgnoreParenCasts(); @@ -80,7 +62,7 @@ FunctionScopeInfo::WeakObjectProfileTy::getBaseInfo(const Expr *E) { case Stmt::ObjCIvarRefExprClass: { const ObjCIvarRefExpr *IE = cast(E); D = IE->getDecl(); - IsExact = isSelfExpr(IE->getBase()); + IsExact = IE->getBase()->isObjCSelfExpr(); break; } case Stmt::PseudoObjectExprClass: { @@ -94,7 +76,7 @@ FunctionScopeInfo::WeakObjectProfileTy::getBaseInfo(const Expr *E) { if (const OpaqueValueExpr *OVE = dyn_cast(DoubleBase)) DoubleBase = OVE->getSourceExpr(); - IsExact = isSelfExpr(DoubleBase); + IsExact = DoubleBase->isObjCSelfExpr(); } break; } diff --git a/lib/StaticAnalyzer/Checkers/IvarInvalidationChecker.cpp b/lib/StaticAnalyzer/Checkers/IvarInvalidationChecker.cpp index 5f94403824..a88b6368e8 100644 --- a/lib/StaticAnalyzer/Checkers/IvarInvalidationChecker.cpp +++ b/lib/StaticAnalyzer/Checkers/IvarInvalidationChecker.cpp @@ -90,8 +90,6 @@ class IvarInvalidationChecker : /// Statement visitor, which walks the method body and flags the ivars /// referenced in it (either directly or via property). class MethodCrawler : public ConstStmtVisitor { - const ObjCMethodDecl *EnclosingMethod; - /// The set of Ivars which need to be invalidated. IvarSet &IVars; @@ -138,15 +136,13 @@ class IvarInvalidationChecker : void check(const Expr *E); public: - MethodCrawler(const ObjCMethodDecl *InMeth, - IvarSet &InIVars, + MethodCrawler(IvarSet &InIVars, bool &InCalledAnotherInvalidationMethod, const MethToIvarMapTy &InPropertySetterToIvarMap, const MethToIvarMapTy &InPropertyGetterToIvarMap, const PropToIvarMapTy &InPropertyToIvarMap, ASTContext &InCtx) - : EnclosingMethod(InMeth), - IVars(InIVars), + : IVars(InIVars), CalledAnotherInvalidationMethod(InCalledAnotherInvalidationMethod), PropertySetterToIvarMap(InPropertySetterToIvarMap), PropertyGetterToIvarMap(InPropertyGetterToIvarMap), @@ -363,7 +359,7 @@ void IvarInvalidationChecker::checkASTDecl(const ObjCMethodDecl *D, // Check which ivars have been invalidated in the method body. bool CalledAnotherInvalidationMethod = false; - MethodCrawler(D, Ivars, + MethodCrawler(Ivars, CalledAnotherInvalidationMethod, PropSetterToIvarMap, PropGetterToIvarMap, @@ -518,12 +514,9 @@ void IvarInvalidationChecker::MethodCrawler::VisitObjCMessageExpr( // Stop if we are calling '[self invalidate]'. if (Receiver && isInvalidationMethod(MD)) - if (const DeclRefExpr *RD = - dyn_cast(Receiver->IgnoreParenCasts())) { - if (RD->getDecl() == EnclosingMethod->getSelfDecl()) { - CalledAnotherInvalidationMethod = true; - return; - } + if (Receiver->isObjCSelfExpr()) { + CalledAnotherInvalidationMethod = true; + return; } // Check if we call a setter and set the property to 'nil'.