diff options
Diffstat (limited to 'include/clang')
-rw-r--r-- | include/clang/AST/Decl.h | 80 | ||||
-rw-r--r-- | include/clang/AST/DeclBase.h | 9 | ||||
-rw-r--r-- | include/clang/Analysis/Analyses/UninitializedValues.h | 2 | ||||
-rw-r--r-- | include/clang/Analysis/Visitors/CFGRecStmtDeclVisitor.h | 5 |
4 files changed, 35 insertions, 61 deletions
diff --git a/include/clang/AST/Decl.h b/include/clang/AST/Decl.h index 8ce0be561f..890eb88d65 100644 --- a/include/clang/AST/Decl.h +++ b/include/clang/AST/Decl.h @@ -146,6 +146,10 @@ protected: StorageClass SC, ScopedDecl *PrevDecl) : ValueDecl(DK, CD, L, Id, T, PrevDecl), Init(0) { SClass = SC; } public: + static VarDecl *Create(ASTContext &C, DeclContext *CD, + SourceLocation L, IdentifierInfo *Id, + QualType T, StorageClass S, ScopedDecl *PrevDecl); + StorageClass getStorageClass() const { return (StorageClass)SClass; } const Expr *getInit() const { return Init; } @@ -156,7 +160,7 @@ public: /// is a non-static local variable. bool hasLocalStorage() const { if (getStorageClass() == None) - return getKind() != FileVar; + return !isFileVarDecl(); // Return true for: Auto, Register. // Return false for: Extern, Static, PrivateExtern. @@ -168,6 +172,29 @@ public: /// have local storage. This includs all global variables as well /// as static variables declared within a function. bool hasGlobalStorage() const { return !hasLocalStorage(); } + + /// isBlockVarDecl - Returns true for local variable declarations. Note that + /// this includes static variables inside of functions. + /// + /// void foo() { int x; static int y; extern int z; } + /// + bool isBlockVarDecl() const { + if (getKind() != Decl::Var) + return false; + if (DeclContext *DC = getDeclContext()) + return DC->isFunctionOrMethod(); + return false; + } + + /// isFileVarDecl - Returns true for file scoped variable declaration. + bool isFileVarDecl() const { + if (getKind() != Decl::Var) + return false; + // FIXME: change when TranlationUnitDecl is added as a declaration context. + if (!getDeclContext()) + return true; + return false; + } // Implement isa/cast/dyncast/etc. static bool classof(const Decl *D) { @@ -187,56 +214,9 @@ protected: /// ReadImpl - Deserialize this VarDecl. Called by subclasses. virtual void ReadImpl(llvm::Deserializer& D, ASTContext& C); -}; - -/// BlockVarDecl - Represent a local variable declaration. Note that this -/// includes static variables inside of functions. -/// -/// void foo() { int x; static int y; extern int z; } -/// -class BlockVarDecl : public VarDecl { - BlockVarDecl(DeclContext *CD, SourceLocation L, - IdentifierInfo *Id, QualType T, StorageClass S, - ScopedDecl *PrevDecl) - : VarDecl(BlockVar, CD, L, Id, T, S, PrevDecl) {} -public: - static BlockVarDecl *Create(ASTContext &C, DeclContext *CD, SourceLocation L, - IdentifierInfo *Id, QualType T, StorageClass S, - ScopedDecl *PrevDecl); - // Implement isa/cast/dyncast/etc. - static bool classof(const Decl *D) { return D->getKind() == BlockVar; } - static bool classof(const BlockVarDecl *D) { return true; } - -protected: - /// CreateImpl - Deserialize a BlockVarDecl. Called by Decl::Create. - static BlockVarDecl* CreateImpl(llvm::Deserializer& D, ASTContext& C); - - friend Decl* Decl::Create(llvm::Deserializer& D, ASTContext& C); -}; - -/// FileVarDecl - Represent a file scoped variable declaration. This -/// will allow us to reason about external variable declarations and tentative -/// definitions (C99 6.9.2p2) using our type system (without storing a -/// pointer to the decl's scope, which is transient). -class FileVarDecl : public VarDecl { - FileVarDecl(DeclContext *CD, SourceLocation L, - IdentifierInfo *Id, QualType T, StorageClass S, - ScopedDecl *PrevDecl) - : VarDecl(FileVar, CD, L, Id, T, S, PrevDecl) {} -public: - static FileVarDecl *Create(ASTContext &C, DeclContext *CD, - SourceLocation L, IdentifierInfo *Id, - QualType T, StorageClass S, ScopedDecl *PrevDecl); - // Implement isa/cast/dyncast/etc. - static bool classof(const Decl *D) { return D->getKind() == FileVar; } - static bool classof(const FileVarDecl *D) { return true; } - -protected: - /// CreateImpl - Deserialize a FileVarDecl. Called by Decl::Create. - static FileVarDecl* CreateImpl(llvm::Deserializer& D, ASTContext& C); - - friend Decl* Decl::Create(llvm::Deserializer& D, ASTContext& C); + /// CreateImpl - Deserialize a VarDecl. Called by Decl::Create. + static VarDecl* CreateImpl(llvm::Deserializer& D, ASTContext& C); }; /// ParmVarDecl - Represent a parameter to a function. diff --git a/include/clang/AST/DeclBase.h b/include/clang/AST/DeclBase.h index a5c1cb29ec..3575faaaf5 100644 --- a/include/clang/AST/DeclBase.h +++ b/include/clang/AST/DeclBase.h @@ -55,9 +55,7 @@ public: // ValueDecl EnumConstant, Function, - // VarDecl - BlockVar, - FileVar, + Var, ParmVar, ObjCInterface, ObjCCompatibleAlias, @@ -76,7 +74,7 @@ public: TagFirst = Enum , TagLast = Class, RecordFirst = Struct , RecordLast = Class, ValueFirst = EnumConstant , ValueLast = ParmVar, - VarFirst = BlockVar , VarLast = ParmVar + VarFirst = Var , VarLast = ParmVar }; /// IdentifierNamespace - According to C99 6.2.3, there are four namespaces, @@ -151,8 +149,7 @@ public: default: assert(0 && "Unknown decl kind!"); case Typedef: case Function: - case BlockVar: - case FileVar: + case Var: case ParmVar: case EnumConstant: case ObjCInterface: diff --git a/include/clang/Analysis/Analyses/UninitializedValues.h b/include/clang/Analysis/Analyses/UninitializedValues.h index b2e2dd052c..ea7bd14779 100644 --- a/include/clang/Analysis/Analyses/UninitializedValues.h +++ b/include/clang/Analysis/Analyses/UninitializedValues.h @@ -51,7 +51,7 @@ public: struct ObserverTy { virtual ~ObserverTy(); virtual void ObserveDeclRefExpr(ValTy& Val, AnalysisDataTy& AD, - DeclRefExpr* DR, BlockVarDecl* VD) = 0; + DeclRefExpr* DR, VarDecl* VD) = 0; }; }; diff --git a/include/clang/Analysis/Visitors/CFGRecStmtDeclVisitor.h b/include/clang/Analysis/Visitors/CFGRecStmtDeclVisitor.h index 1ff9a9392b..fab14c38da 100644 --- a/include/clang/Analysis/Visitors/CFGRecStmtDeclVisitor.h +++ b/include/clang/Analysis/Visitors/CFGRecStmtDeclVisitor.h @@ -54,8 +54,7 @@ public: void VisitScopedDecl(ScopedDecl* D) { switch (D->getKind()) { DISPATCH_CASE(Function,FunctionDecl) - DISPATCH_CASE(BlockVar,BlockVarDecl) // FIXME:Refine. VisitVarDecl? - DISPATCH_CASE(FileVar,FileVarDecl) // FIXME: (same) + DISPATCH_CASE(Var,VarDecl) DISPATCH_CASE(ParmVar,ParmVarDecl) // FIXME: (same) DISPATCH_CASE(EnumConstant,EnumConstantDecl) DISPATCH_CASE(Typedef,TypedefDecl) @@ -70,8 +69,6 @@ public: DEFAULT_DISPATCH(VarDecl) DEFAULT_DISPATCH(FunctionDecl) - DEFAULT_DISPATCH_VARDECL(BlockVarDecl) - DEFAULT_DISPATCH_VARDECL(FileVarDecl) DEFAULT_DISPATCH_VARDECL(ParmVarDecl) DEFAULT_DISPATCH(EnumConstantDecl) DEFAULT_DISPATCH(TypedefDecl) |