[cfe-commits] r41092 - /cfe/trunk/include/clang/AST/Decl.h
Ted Kremenek
kremenek at apple.com
Tue Aug 14 17:03:46 PDT 2007
Author: kremenek
Date: Tue Aug 14 19:03:46 2007
New Revision: 41092
URL: http://llvm.org/viewvc/llvm-project?rev=41092&view=rev
Log:
Added the following utility methods to VarDecl that provide
canonicalized queries of a variable's storage:
hasAutoStorage - Does a variable have (implicit) auto storage?
hasStaticStorage - Does a variable have (implicit) static storage?
hasLocalStorage - Is the variable a non-static local variable?
hasGlobalStorage - Is the variable a global variable or a static
local variable?
Additional comments documenting these functions are included in the
source.
Modified:
cfe/trunk/include/clang/AST/Decl.h
Modified: cfe/trunk/include/clang/AST/Decl.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Decl.h?rev=41092&r1=41091&r2=41092&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Decl.h (original)
+++ cfe/trunk/include/clang/AST/Decl.h Tue Aug 14 19:03:46 2007
@@ -151,6 +151,33 @@
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() {
+ return (SClass == Auto || (SClass == None && getKind() == BlockVariable));
+ }
+
+ // 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() {
+ return (SClass == Static || (SClass == None && getKind() == FileVariable));
+ }
+
+ // hasLocalStorage - Returns true if a variable with function scope
+ // is a non-static local variable.
+ bool hasLocalStorage() { return (hasAutoStorage() || SClass == Register); }
+
+ // hasGlobalStorage - Returns true for all variables that do not
+ // have local storage. This includs all global variables as well
+ // as static variables declared within a function.
+ bool hasGlobalStorage() { return !hasAutoStorage(); }
+
// Implement isa/cast/dyncast/etc.
static bool classof(const Decl *D) {
return D->getKind() >= BlockVariable && D->getKind() <= ParmVariable;
More information about the cfe-commits
mailing list