[cfe-commits] r47681 - in /cfe/trunk: AST/Expr.cpp include/clang/AST/Decl.h include/clang/AST/Expr.h

Ted Kremenek kremenek at apple.com
Wed Feb 27 10:39:48 PST 2008


Author: kremenek
Date: Wed Feb 27 12:39:48 2008
New Revision: 47681

URL: http://llvm.org/viewvc/llvm-project?rev=47681&view=rev
Log:
Removed VarDecl::hasStaticStorage() (redundant with hasGlobalStorage())
Removed VarDecl::hasAutoStorage() (only used by hasLocalStorage())

Merged logic from VarDecl::hasAutoStorage() into VarDecl::hasLocalStorage(),
and expanded (fixed) the logic of hasLocalStorage() to handle Extern and PrivateExtern.

Renamed Expr::hasStaticStorage() to Expr::hasGlobalStorage().

Modified:
    cfe/trunk/AST/Expr.cpp
    cfe/trunk/include/clang/AST/Decl.h
    cfe/trunk/include/clang/AST/Expr.h

Modified: cfe/trunk/AST/Expr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/AST/Expr.cpp?rev=47681&r1=47680&r2=47681&view=diff

==============================================================================
--- cfe/trunk/AST/Expr.cpp (original)
+++ cfe/trunk/AST/Expr.cpp Wed Feb 27 12:39:48 2008
@@ -436,31 +436,31 @@
   return MLV_Valid;    
 }
 
-/// hasStaticStorage - Return true if this expression has static storage
+/// hasGlobalStorage - Return true if this expression has static storage
 /// duration.  This means that the address of this expression is a link-time
 /// constant.
-bool Expr::hasStaticStorage() const {
+bool Expr::hasGlobalStorage() const {
   switch (getStmtClass()) {
   default:
     return false;
   case ParenExprClass:
-    return cast<ParenExpr>(this)->getSubExpr()->hasStaticStorage();
+    return cast<ParenExpr>(this)->getSubExpr()->hasGlobalStorage();
   case ImplicitCastExprClass:
-    return cast<ImplicitCastExpr>(this)->getSubExpr()->hasStaticStorage();
+    return cast<ImplicitCastExpr>(this)->getSubExpr()->hasGlobalStorage();
   case CompoundLiteralExprClass:
     return cast<CompoundLiteralExpr>(this)->isFileScope();
   case DeclRefExprClass: {
     const Decl *D = cast<DeclRefExpr>(this)->getDecl();
     if (const VarDecl *VD = dyn_cast<VarDecl>(D))
-      return VD->hasStaticStorage();
+      return VD->hasGlobalStorage();
     return false;
   }
   case MemberExprClass: {
     const MemberExpr *M = cast<MemberExpr>(this);
-    return !M->isArrow() && M->getBase()->hasStaticStorage();
+    return !M->isArrow() && M->getBase()->hasGlobalStorage();
   }
   case ArraySubscriptExprClass:
-    return cast<ArraySubscriptExpr>(this)->getBase()->hasStaticStorage();
+    return cast<ArraySubscriptExpr>(this)->getBase()->hasGlobalStorage();
   case PreDefinedExprClass:
     return true;
   }
@@ -539,7 +539,7 @@
     
     // C99 6.6p9
     if (Exp->getOpcode() == UnaryOperator::AddrOf) {
-      if (!Exp->getSubExpr()->hasStaticStorage()) {
+      if (!Exp->getSubExpr()->hasGlobalStorage()) {
         if (Loc) *Loc = getLocStart();
         return false;
       }

Modified: cfe/trunk/include/clang/AST/Decl.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Decl.h?rev=47681&r1=47680&r2=47681&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/Decl.h (original)
+++ cfe/trunk/include/clang/AST/Decl.h Wed Feb 27 12:39:48 2008
@@ -292,38 +292,24 @@
 class VarDecl : public ValueDecl {
 public:
   enum StorageClass {
-    None, Extern, Static, Auto, Register, PrivateExtern
+    None, Auto, Register, Extern, Static, PrivateExtern
   };
   StorageClass getStorageClass() const { return (StorageClass)SClass; }
 
   const Expr *getInit() const { return Init; }
   Expr *getInit() { return Init; }
   void setInit(Expr *I) { Init = I; }
-  
-  /// hasAutoStorage - Returns true if either the implicit or explicit
-  ///  storage class of a variable is "auto."  In particular, variables
-  ///  declared within a function that lack a storage keyword are
-  ///  implicitly "auto", but are represented internally with a storage
-  ///  class of None.
-  bool hasAutoStorage() const {
-    return getStorageClass() == Auto ||
-          (getStorageClass() == None && getKind() != FileVar);
-  }
-
-  /// hasStaticStorage - Returns true if either the implicit or
-  ///  explicit storage class of a variable is "static."  In
-  ///  particular, variables declared within a file (outside of a
-  ///  function) that lack a storage keyword are implicitly "static,"
-  ///  but are represented internally with a storage class of "None".
-  bool hasStaticStorage() const {
-    if (getStorageClass() == Static) return true;
-    return getKind() == FileVar;
-  }
       
   /// hasLocalStorage - Returns true if a variable with function scope
   ///  is a non-static local variable.
   bool hasLocalStorage() const {
-    return hasAutoStorage() || getStorageClass() == Register;
+    if (getStorageClass() == None)
+      return getKind() != FileVar;
+    
+    // Return true for:  Auto, Register.
+    // Return false for: Extern, Static, PrivateExtern.
+    
+    return getStorageClass() <= Register;
   }
 
   /// hasGlobalStorage - Returns true for all variables that do not

Modified: cfe/trunk/include/clang/AST/Expr.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Expr.h?rev=47681&r1=47680&r2=47681&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/trunk/include/clang/AST/Expr.h Wed Feb 27 12:39:48 2008
@@ -106,10 +106,10 @@
   /// isConstantExpr - Return true if this expression is a valid constant expr.
   bool isConstantExpr(ASTContext &Ctx, SourceLocation *Loc) const;
   
-  /// hasStaticStorage - Return true if this expression has static storage
+  /// hasGlobalStorage - Return true if this expression has static storage
   /// duration.  This means that the address of this expression is a link-time
   /// constant.
-  bool hasStaticStorage() const;  
+  bool hasGlobalStorage() const;  
   
   /// IgnoreParens - Ignore parentheses.  If this Expr is a ParenExpr, return
   ///  its subexpression.  If that subexpression is also a ParenExpr, 





More information about the cfe-commits mailing list