1 //===--- ScopeInfo.h - Information about a semantic context -----*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines FunctionScopeInfo and BlockScopeInfo.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_CLANG_SEMA_SCOPE_INFO_H
15 #define LLVM_CLANG_SEMA_SCOPE_INFO_H
17 #include "clang/AST/Type.h"
18 #include "llvm/ADT/DenseMap.h"
19 #include "llvm/ADT/SmallVector.h"
32 /// \brief Retains information about a function, method, or block that is
33 /// currently being parsed.
34 class FunctionScopeInfo {
37 /// \brief Whether this scope information structure defined information for
41 /// \brief Whether this function contains a VLA, @try, try, C++
42 /// initializer, or anything else that can't be jumped past.
43 bool HasBranchProtectedScope;
45 /// \brief Whether this function contains any switches or direct gotos.
46 bool HasBranchIntoScope;
48 /// \brief Whether this function contains any indirect gotos.
51 /// \brief The number of errors that had occurred before starting this
52 /// function or block.
53 unsigned NumErrorsAtStartOfFunction;
55 /// LabelMap - This is a mapping from label identifiers to the LabelStmt for
56 /// it (which acts like the label decl in some ways). Forward referenced
57 /// labels have a LabelStmt created for them with a null location & SubStmt.
58 llvm::DenseMap<IdentifierInfo*, LabelStmt*> LabelMap;
60 /// SwitchStack - This is the current set of active switch statements in the
62 llvm::SmallVector<SwitchStmt*, 8> SwitchStack;
64 /// \brief The list of return statements that occur within the function or
65 /// block, if there is any chance of applying the named return value
67 llvm::SmallVector<ReturnStmt *, 4> Returns;
69 void setHasBranchIntoScope() {
70 HasBranchIntoScope = true;
73 void setHasBranchProtectedScope() {
74 HasBranchProtectedScope = true;
77 void setHasIndirectGoto() {
78 HasIndirectGoto = true;
81 bool NeedsScopeChecking() const {
82 return HasIndirectGoto ||
83 (HasBranchProtectedScope && HasBranchIntoScope);
86 FunctionScopeInfo(unsigned NumErrors)
88 HasBranchProtectedScope(false),
89 HasBranchIntoScope(false),
90 HasIndirectGoto(false),
91 NumErrorsAtStartOfFunction(NumErrors) { }
93 virtual ~FunctionScopeInfo();
95 /// \brief Clear out the information in this function scope, making it
96 /// suitable for reuse.
97 void Clear(unsigned NumErrors);
99 static bool classof(const FunctionScopeInfo *FSI) { return true; }
102 /// \brief Retains information about a block that is currently being parsed.
103 class BlockScopeInfo : public FunctionScopeInfo {
105 bool hasBlockDeclRefExprs;
109 /// TheScope - This is the scope for the block itself, which contains
113 /// ReturnType - The return type of the block, or null if the block
114 /// signature didn't provide an explicit return type.
117 /// BlockType - The function type of the block, if one was given.
118 /// Its return type may be BuiltinType::Dependent.
119 QualType FunctionType;
121 BlockScopeInfo(unsigned NumErrors, Scope *BlockScope, BlockDecl *Block)
122 : FunctionScopeInfo(NumErrors), hasBlockDeclRefExprs(false),
123 TheDecl(Block), TheScope(BlockScope)
128 virtual ~BlockScopeInfo();
130 static bool classof(const FunctionScopeInfo *FSI) { return FSI->IsBlockInfo; }
131 static bool classof(const BlockScopeInfo *BSI) { return true; }