aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2007-08-15 00:03:46 +0000
committerTed Kremenek <kremenek@apple.com>2007-08-15 00:03:46 +0000
commit87ce144920a4f9c4cc8d6b021b1d759d7785317c (patch)
tree99d6cbe7e533276640c41586f867d140276315e2
parent6a2394c4eaa87580f44f49205e5ca8aba628bdd8 (diff)
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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@41092 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/clang/AST/Decl.h27
1 files changed, 27 insertions, 0 deletions
diff --git a/include/clang/AST/Decl.h b/include/clang/AST/Decl.h
index 90af50c36f..f94e126cb5 100644
--- a/include/clang/AST/Decl.h
+++ b/include/clang/AST/Decl.h
@@ -151,6 +151,33 @@ public:
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;