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 "clang/Basic/PartialDiagnostic.h"
19 #include "llvm/ADT/DenseMap.h"
20 #include "llvm/ADT/SmallVector.h"
21 #include "llvm/ADT/SetVector.h"
34 class PossiblyUnreachableDiag {
40 PossiblyUnreachableDiag(const PartialDiagnostic &PD, SourceLocation Loc,
42 : PD(PD), Loc(Loc), stmt(stmt) {}
45 /// \brief Retains information about a function, method, or block that is
46 /// currently being parsed.
47 class FunctionScopeInfo {
50 /// \brief Whether this scope information structure defined information for
54 /// \brief Whether this function contains a VLA, @try, try, C++
55 /// initializer, or anything else that can't be jumped past.
56 bool HasBranchProtectedScope;
58 /// \brief Whether this function contains any switches or direct gotos.
59 bool HasBranchIntoScope;
61 /// \brief Whether this function contains any indirect gotos.
64 /// \brief Used to determine if errors occurred in this function or block.
65 DiagnosticErrorTrap ErrorTrap;
67 /// SwitchStack - This is the current set of active switch statements in the
69 SmallVector<SwitchStmt*, 8> SwitchStack;
71 /// \brief The list of return statements that occur within the function or
72 /// block, if there is any chance of applying the named return value
74 SmallVector<ReturnStmt*, 4> Returns;
76 /// \brief A list of PartialDiagnostics created but delayed within the
77 /// current function scope. These diagnostics are vetted for reachability
78 /// prior to being emitted.
79 SmallVector<PossiblyUnreachableDiag, 4> PossiblyUnreachableDiags;
81 void setHasBranchIntoScope() {
82 HasBranchIntoScope = true;
85 void setHasBranchProtectedScope() {
86 HasBranchProtectedScope = true;
89 void setHasIndirectGoto() {
90 HasIndirectGoto = true;
93 bool NeedsScopeChecking() const {
94 return HasIndirectGoto ||
95 (HasBranchProtectedScope && HasBranchIntoScope);
98 FunctionScopeInfo(DiagnosticsEngine &Diag)
100 HasBranchProtectedScope(false),
101 HasBranchIntoScope(false),
102 HasIndirectGoto(false),
105 virtual ~FunctionScopeInfo();
107 /// \brief Clear out the information in this function scope, making it
108 /// suitable for reuse.
111 static bool classof(const FunctionScopeInfo *FSI) { return true; }
114 /// \brief Retains information about a block that is currently being parsed.
115 class BlockScopeInfo : public FunctionScopeInfo {
119 /// TheScope - This is the scope for the block itself, which contains
123 /// ReturnType - The return type of the block, or null if the block
124 /// signature didn't provide an explicit return type.
127 /// BlockType - The function type of the block, if one was given.
128 /// Its return type may be BuiltinType::Dependent.
129 QualType FunctionType;
131 /// CaptureMap - A map of captured variables to (index+1) into Captures.
132 llvm::DenseMap<VarDecl*, unsigned> CaptureMap;
134 /// Captures - The captured variables.
135 SmallVector<BlockDecl::Capture, 4> Captures;
137 /// CapturesCXXThis - Whether this block captures 'this'.
138 bool CapturesCXXThis;
140 BlockScopeInfo(DiagnosticsEngine &Diag, Scope *BlockScope, BlockDecl *Block)
141 : FunctionScopeInfo(Diag), TheDecl(Block), TheScope(BlockScope),
142 CapturesCXXThis(false)
147 virtual ~BlockScopeInfo();
149 static bool classof(const FunctionScopeInfo *FSI) { return FSI->IsBlockInfo; }
150 static bool classof(const BlockScopeInfo *BSI) { return true; }