[cfe-commits] r164966 - in /cfe/trunk: include/clang/AST/Expr.h lib/AST/Expr.cpp lib/Sema/ScopeInfo.cpp lib/StaticAnalyzer/Checkers/IvarInvalidationChecker.cpp

Anna Zaks ganna at apple.com
Mon Oct 1 13:34:04 PDT 2012


Author: zaks
Date: Mon Oct  1 15:34:04 2012
New Revision: 164966

URL: http://llvm.org/viewvc/llvm-project?rev=164966&view=rev
Log:
Move isObjCSelf into Expr.

Modified:
    cfe/trunk/include/clang/AST/Expr.h
    cfe/trunk/lib/AST/Expr.cpp
    cfe/trunk/lib/Sema/ScopeInfo.cpp
    cfe/trunk/lib/StaticAnalyzer/Checkers/IvarInvalidationChecker.cpp

Modified: cfe/trunk/include/clang/AST/Expr.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Expr.h?rev=164966&r1=164965&r2=164966&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/trunk/include/clang/AST/Expr.h Mon Oct  1 15:34:04 2012
@@ -392,6 +392,9 @@
   /// 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;
 

Modified: cfe/trunk/lib/AST/Expr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Expr.cpp?rev=164966&r1=164965&r2=164966&view=diff
==============================================================================
--- cfe/trunk/lib/AST/Expr.cpp (original)
+++ cfe/trunk/lib/AST/Expr.cpp Mon Oct  1 15:34:04 2012
@@ -3002,6 +3002,24 @@
   return cast<ObjCPropertyRefExpr>(E);
 }
 
+bool Expr::isObjCSelfExpr() const {
+  const Expr *E = IgnoreParenImpCasts();
+
+  const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(E);
+  if (!DRE)
+    return false;
+
+  const ImplicitParamDecl *Param = dyn_cast<ImplicitParamDecl>(DRE->getDecl());
+  if (!Param)
+    return false;
+
+  const ObjCMethodDecl *M = dyn_cast<ObjCMethodDecl>(Param->getDeclContext());
+  if (!M)
+    return false;
+
+  return M->getSelfDecl() == Param;
+}
+
 FieldDecl *Expr::getBitField() {
   Expr *E = this->IgnoreParens();
 

Modified: cfe/trunk/lib/Sema/ScopeInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/ScopeInfo.cpp?rev=164966&r1=164965&r2=164966&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/ScopeInfo.cpp (original)
+++ cfe/trunk/lib/Sema/ScopeInfo.cpp Mon Oct  1 15:34:04 2012
@@ -41,24 +41,6 @@
   return PropE->getImplicitPropertyGetter();
 }
 
-static bool isSelfExpr(const Expr *E) {
-  E = E->IgnoreParenImpCasts();
-
-  const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(E);
-  if (!DRE)
-    return false;
-
-  const ImplicitParamDecl *Param = dyn_cast<ImplicitParamDecl>(DRE->getDecl());
-  if (!Param)
-    return false;
-
-  const ObjCMethodDecl *M = dyn_cast<ObjCMethodDecl>(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 @@
   case Stmt::ObjCIvarRefExprClass: {
     const ObjCIvarRefExpr *IE = cast<ObjCIvarRefExpr>(E);
     D = IE->getDecl();
-    IsExact = isSelfExpr(IE->getBase());
+    IsExact = IE->getBase()->isObjCSelfExpr();
     break;
   }
   case Stmt::PseudoObjectExprClass: {
@@ -94,7 +76,7 @@
       if (const OpaqueValueExpr *OVE = dyn_cast<OpaqueValueExpr>(DoubleBase))
         DoubleBase = OVE->getSourceExpr();
 
-      IsExact = isSelfExpr(DoubleBase);
+      IsExact = DoubleBase->isObjCSelfExpr();
     }
     break;
   }

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/IvarInvalidationChecker.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/IvarInvalidationChecker.cpp?rev=164966&r1=164965&r2=164966&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Checkers/IvarInvalidationChecker.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/IvarInvalidationChecker.cpp Mon Oct  1 15:34:04 2012
@@ -90,8 +90,6 @@
   /// Statement visitor, which walks the method body and flags the ivars
   /// referenced in it (either directly or via property).
   class MethodCrawler : public ConstStmtVisitor<MethodCrawler> {
-    const ObjCMethodDecl *EnclosingMethod;
-
     /// The set of Ivars which need to be invalidated.
     IvarSet &IVars;
 
@@ -138,15 +136,13 @@
     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 @@
 
   // 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 @@
 
   // Stop if we are calling '[self invalidate]'.
   if (Receiver && isInvalidationMethod(MD))
-    if (const DeclRefExpr *RD =
-          dyn_cast<DeclRefExpr>(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'.





More information about the cfe-commits mailing list