Switch labels over to using normal name lookup, instead of their
[clang.git] / include / clang / Sema / ScopeInfo.h
blobb0bb95509a91fc77271348d3c3c4eae4002285c3
1 //===--- ScopeInfo.h - Information about a semantic context -----*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
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"
20 #include "llvm/ADT/SetVector.h"
22 namespace clang {
24 class BlockDecl;
25 class IdentifierInfo;
26 class LabelDecl;
27 class ReturnStmt;
28 class Scope;
29 class SwitchStmt;
31 namespace sema {
33 /// \brief Retains information about a function, method, or block that is
34 /// currently being parsed.
35 class FunctionScopeInfo {
36 public:
38 /// \brief Whether this scope information structure defined information for
39 /// a block.
40 bool IsBlockInfo;
42 /// \brief Whether this function contains a VLA, @try, try, C++
43 /// initializer, or anything else that can't be jumped past.
44 bool HasBranchProtectedScope;
46 /// \brief Whether this function contains any switches or direct gotos.
47 bool HasBranchIntoScope;
49 /// \brief Whether this function contains any indirect gotos.
50 bool HasIndirectGoto;
52 /// \brief Used to determine if errors occurred in this function or block.
53 DiagnosticErrorTrap ErrorTrap;
55 /// SwitchStack - This is the current set of active switch statements in the
56 /// block.
57 llvm::SmallVector<SwitchStmt*, 8> SwitchStack;
59 /// \brief The list of return statements that occur within the function or
60 /// block, if there is any chance of applying the named return value
61 /// optimization.
62 llvm::SmallVector<ReturnStmt*, 4> Returns;
64 void setHasBranchIntoScope() {
65 HasBranchIntoScope = true;
68 void setHasBranchProtectedScope() {
69 HasBranchProtectedScope = true;
72 void setHasIndirectGoto() {
73 HasIndirectGoto = true;
76 bool NeedsScopeChecking() const {
77 return HasIndirectGoto ||
78 (HasBranchProtectedScope && HasBranchIntoScope);
81 FunctionScopeInfo(Diagnostic &Diag)
82 : IsBlockInfo(false),
83 HasBranchProtectedScope(false),
84 HasBranchIntoScope(false),
85 HasIndirectGoto(false),
86 ErrorTrap(Diag) { }
88 virtual ~FunctionScopeInfo();
90 /// \brief Clear out the information in this function scope, making it
91 /// suitable for reuse.
92 void Clear();
94 static bool classof(const FunctionScopeInfo *FSI) { return true; }
97 /// \brief Retains information about a block that is currently being parsed.
98 class BlockScopeInfo : public FunctionScopeInfo {
99 public:
100 BlockDecl *TheDecl;
102 /// TheScope - This is the scope for the block itself, which contains
103 /// arguments etc.
104 Scope *TheScope;
106 /// ReturnType - The return type of the block, or null if the block
107 /// signature didn't provide an explicit return type.
108 QualType ReturnType;
110 /// BlockType - The function type of the block, if one was given.
111 /// Its return type may be BuiltinType::Dependent.
112 QualType FunctionType;
114 /// CaptureMap - A map of captured variables to (index+1) into Captures.
115 llvm::DenseMap<VarDecl*, unsigned> CaptureMap;
117 /// Captures - The captured variables.
118 llvm::SmallVector<BlockDecl::Capture, 4> Captures;
120 /// CapturesCXXThis - Whether this block captures 'this'.
121 bool CapturesCXXThis;
123 BlockScopeInfo(Diagnostic &Diag, Scope *BlockScope, BlockDecl *Block)
124 : FunctionScopeInfo(Diag), TheDecl(Block), TheScope(BlockScope),
125 CapturesCXXThis(false)
127 IsBlockInfo = true;
130 virtual ~BlockScopeInfo();
132 static bool classof(const FunctionScopeInfo *FSI) { return FSI->IsBlockInfo; }
133 static bool classof(const BlockScopeInfo *BSI) { return true; }
139 #endif