@@ -121,97 +121,11 @@ namespace clang {
121
121
122
122
namespace sema {
123
123
class AccessedEntity ;
124
+ class BlockScopeInfo ;
125
+ class FunctionScopeInfo ;
124
126
class TemplateDeductionInfo ;
125
127
}
126
128
127
- // / \brief Retains information about a function, method, or block that is
128
- // / currently being parsed.
129
- struct FunctionScopeInfo {
130
- // / \brief Whether this scope information structure defined information for
131
- // / a block.
132
- bool IsBlockInfo;
133
-
134
- // / \brief Whether this function contains a VLA, @try, try, C++
135
- // / initializer, or anything else that can't be jumped past.
136
- bool HasBranchProtectedScope;
137
-
138
- // / \brief Whether this function contains any switches or direct gotos.
139
- bool HasBranchIntoScope;
140
-
141
- // / \brief Whether this function contains any indirect gotos.
142
- bool HasIndirectGoto;
143
-
144
- // / \brief The number of errors that had occurred before starting this
145
- // / function or block.
146
- unsigned NumErrorsAtStartOfFunction;
147
-
148
- // / LabelMap - This is a mapping from label identifiers to the LabelStmt for
149
- // / it (which acts like the label decl in some ways). Forward referenced
150
- // / labels have a LabelStmt created for them with a null location & SubStmt.
151
- llvm::DenseMap<IdentifierInfo*, LabelStmt*> LabelMap;
152
-
153
- // / SwitchStack - This is the current set of active switch statements in the
154
- // / block.
155
- llvm::SmallVector<SwitchStmt*, 8 > SwitchStack;
156
-
157
- // / \brief The list of return statements that occur within the function or
158
- // / block, if there is any chance of applying the named return value
159
- // / optimization.
160
- llvm::SmallVector<ReturnStmt *, 4 > Returns;
161
-
162
- bool NeedsScopeChecking () const {
163
- return HasIndirectGoto ||
164
- (HasBranchProtectedScope && HasBranchIntoScope);
165
- }
166
-
167
- FunctionScopeInfo (unsigned NumErrors)
168
- : IsBlockInfo(false ),
169
- HasBranchProtectedScope (false ),
170
- HasBranchIntoScope(false ),
171
- HasIndirectGoto(false ),
172
- NumErrorsAtStartOfFunction(NumErrors) { }
173
-
174
- virtual ~FunctionScopeInfo ();
175
-
176
- // / \brief Clear out the information in this function scope, making it
177
- // / suitable for reuse.
178
- void Clear (unsigned NumErrors);
179
-
180
- static bool classof (const FunctionScopeInfo *FSI) { return true ; }
181
- };
182
-
183
-
184
- // / \brief Retains information about a block that is currently being parsed.
185
- struct BlockScopeInfo : FunctionScopeInfo {
186
- bool hasBlockDeclRefExprs;
187
-
188
- BlockDecl *TheDecl;
189
-
190
- // / TheScope - This is the scope for the block itself, which contains
191
- // / arguments etc.
192
- Scope *TheScope;
193
-
194
- // / ReturnType - The return type of the block, or null if the block
195
- // / signature didn't provide an explicit return type.
196
- QualType ReturnType;
197
-
198
- // / BlockType - The function type of the block, if one was given.
199
- // / Its return type may be BuiltinType::Dependent.
200
- QualType FunctionType;
201
-
202
- BlockScopeInfo (unsigned NumErrors, Scope *BlockScope, BlockDecl *Block)
203
- : FunctionScopeInfo(NumErrors), hasBlockDeclRefExprs(false ),
204
- TheDecl (Block), TheScope(BlockScope)
205
- {
206
- IsBlockInfo = true ;
207
- }
208
-
209
- virtual ~BlockScopeInfo ();
210
-
211
- static bool classof (const FunctionScopeInfo *FSI) { return FSI->IsBlockInfo ; }
212
- static bool classof (const BlockScopeInfo *BSI) { return true ; }
213
- };
214
-
215
129
// / \brief Holds a QualType and a TypeSourceInfo* that came out of a declarator
216
130
// / parsing.
217
131
// /
@@ -303,16 +217,11 @@ class Sema : public Action {
303
217
// / VisContext - Manages the stack for #pragma GCC visibility.
304
218
void *VisContext; // Really a "PragmaVisStack*"
305
219
306
- // / \brief Stack containing information about each of the nested function,
307
- // / block, and method scopes that are currently active.
308
- llvm::SmallVector<FunctionScopeInfo *, 4 > FunctionScopes;
309
-
310
- // / \brief Cached function scope object used for the top function scope
311
- // / and when there is no function scope (in error cases).
220
+ // / \brief Stack containing information about each of the nested
221
+ // / function, block, and method scopes that are currently active.
312
222
// /
313
- // / This should never be accessed directly; rather, its address will
314
- // / be pushed into \c FunctionScopes when we want to re-use it.
315
- FunctionScopeInfo TopFunctionScope;
223
+ // / This array is never empty, but the first element is meaningless.
224
+ llvm::SmallVector<sema::FunctionScopeInfo *, 4 > FunctionScopes;
316
225
317
226
// / ExprTemporaries - This is the stack of temporaries that are created by
318
227
// / the current full expression.
@@ -727,52 +636,14 @@ class Sema : public Action {
727
636
void PushBlockScope (Scope *BlockScope, BlockDecl *Block);
728
637
void PopFunctionOrBlockScope ();
729
638
730
- // / getLabelMap() - Return the current label map. If we're in a block, we
731
- // / return it.
732
- llvm::DenseMap<IdentifierInfo*, LabelStmt*> &getLabelMap () {
733
- if (FunctionScopes.empty ())
734
- return TopFunctionScope.LabelMap ;
735
-
736
- return FunctionScopes.back ()->LabelMap ;
737
- }
738
-
739
- // / getSwitchStack - This is returns the switch stack for the current block or
740
- // / function.
741
- llvm::SmallVector<SwitchStmt*,8 > &getSwitchStack () {
742
- if (FunctionScopes.empty ())
743
- return TopFunctionScope.SwitchStack ;
744
-
745
- return FunctionScopes.back ()->SwitchStack ;
639
+ sema::FunctionScopeInfo *getCurFunction () const {
640
+ return FunctionScopes.back ();
746
641
}
747
642
748
- // / \brief Determine whether the current function or block needs scope
749
- // / checking.
750
- bool FunctionNeedsScopeChecking () {
751
- if (!FunctionScopes.empty ())
752
- return FunctionScopes.back ()->NeedsScopeChecking ();
753
- return false ;
754
- }
755
-
756
- void setFunctionHasBranchIntoScope () {
757
- if (!FunctionScopes.empty ())
758
- FunctionScopes.back ()->HasBranchIntoScope = true ;
759
- }
760
-
761
- void setFunctionHasBranchProtectedScope () {
762
- if (!FunctionScopes.empty ())
763
- FunctionScopes.back ()->HasBranchProtectedScope = true ;
764
- }
765
-
766
- void setFunctionHasIndirectGoto () {
767
- if (!FunctionScopes.empty ())
768
- FunctionScopes.back ()->HasIndirectGoto = true ;
769
- }
770
-
771
-
772
643
bool hasAnyErrorsInThisFunction () const ;
773
644
774
645
// / \brief Retrieve the current block, if any.
775
- BlockScopeInfo *getCurBlock ();
646
+ sema:: BlockScopeInfo *getCurBlock ();
776
647
777
648
// / WeakTopLevelDeclDecls - access to #pragma weak-generated Decls
778
649
llvm::SmallVector<Decl*,2 > &WeakTopLevelDecls () { return WeakTopLevelDecl; }
0 commit comments