Skip to content

Commit aab3e41

Browse files
committed
Split FunctionScopeInfo and BlockScopeInfo into their own header.
llvm-svn: 112038
1 parent cfe41db commit aab3e41

File tree

11 files changed

+217
-188
lines changed

11 files changed

+217
-188
lines changed

clang/include/clang/Sema/ScopeInfo.h

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
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.
11+
//
12+
//===----------------------------------------------------------------------===//
13+
14+
#ifndef LLVM_CLANG_SEMA_SCOPE_INFO_H
15+
#define LLVM_CLANG_SEMA_SCOPE_INFO_H
16+
17+
#include "clang/AST/Type.h"
18+
#include "llvm/ADT/DenseMap.h"
19+
#include "llvm/ADT/SmallVector.h"
20+
21+
namespace clang {
22+
23+
class BlockDecl;
24+
class IdentifierInfo;
25+
class LabelStmt;
26+
class ReturnStmt;
27+
class Scope;
28+
class SwitchStmt;
29+
30+
namespace sema {
31+
32+
/// \brief Retains information about a function, method, or block that is
33+
/// currently being parsed.
34+
class FunctionScopeInfo {
35+
public:
36+
37+
/// \brief Whether this scope information structure defined information for
38+
/// a block.
39+
bool IsBlockInfo;
40+
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;
44+
45+
/// \brief Whether this function contains any switches or direct gotos.
46+
bool HasBranchIntoScope;
47+
48+
/// \brief Whether this function contains any indirect gotos.
49+
bool HasIndirectGoto;
50+
51+
/// \brief The number of errors that had occurred before starting this
52+
/// function or block.
53+
unsigned NumErrorsAtStartOfFunction;
54+
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;
59+
60+
/// SwitchStack - This is the current set of active switch statements in the
61+
/// block.
62+
llvm::SmallVector<SwitchStmt*, 8> SwitchStack;
63+
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
66+
/// optimization.
67+
llvm::SmallVector<ReturnStmt *, 4> Returns;
68+
69+
void setHasBranchIntoScope() {
70+
HasBranchIntoScope = true;
71+
}
72+
73+
void setHasBranchProtectedScope() {
74+
HasBranchProtectedScope = true;
75+
}
76+
77+
void setHasIndirectGoto() {
78+
HasIndirectGoto = true;
79+
}
80+
81+
bool NeedsScopeChecking() const {
82+
return HasIndirectGoto ||
83+
(HasBranchProtectedScope && HasBranchIntoScope);
84+
}
85+
86+
FunctionScopeInfo(unsigned NumErrors)
87+
: IsBlockInfo(false),
88+
HasBranchProtectedScope(false),
89+
HasBranchIntoScope(false),
90+
HasIndirectGoto(false),
91+
NumErrorsAtStartOfFunction(NumErrors) { }
92+
93+
virtual ~FunctionScopeInfo();
94+
95+
/// \brief Clear out the information in this function scope, making it
96+
/// suitable for reuse.
97+
void Clear(unsigned NumErrors);
98+
99+
static bool classof(const FunctionScopeInfo *FSI) { return true; }
100+
};
101+
102+
/// \brief Retains information about a block that is currently being parsed.
103+
class BlockScopeInfo : public FunctionScopeInfo {
104+
public:
105+
bool hasBlockDeclRefExprs;
106+
107+
BlockDecl *TheDecl;
108+
109+
/// TheScope - This is the scope for the block itself, which contains
110+
/// arguments etc.
111+
Scope *TheScope;
112+
113+
/// ReturnType - The return type of the block, or null if the block
114+
/// signature didn't provide an explicit return type.
115+
QualType ReturnType;
116+
117+
/// BlockType - The function type of the block, if one was given.
118+
/// Its return type may be BuiltinType::Dependent.
119+
QualType FunctionType;
120+
121+
BlockScopeInfo(unsigned NumErrors, Scope *BlockScope, BlockDecl *Block)
122+
: FunctionScopeInfo(NumErrors), hasBlockDeclRefExprs(false),
123+
TheDecl(Block), TheScope(BlockScope)
124+
{
125+
IsBlockInfo = true;
126+
}
127+
128+
virtual ~BlockScopeInfo();
129+
130+
static bool classof(const FunctionScopeInfo *FSI) { return FSI->IsBlockInfo; }
131+
static bool classof(const BlockScopeInfo *BSI) { return true; }
132+
};
133+
134+
}
135+
}
136+
137+
#endif

clang/include/clang/Sema/Sema.h

Lines changed: 9 additions & 138 deletions
Original file line numberDiff line numberDiff line change
@@ -121,97 +121,11 @@ namespace clang {
121121

122122
namespace sema {
123123
class AccessedEntity;
124+
class BlockScopeInfo;
125+
class FunctionScopeInfo;
124126
class TemplateDeductionInfo;
125127
}
126128

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-
215129
/// \brief Holds a QualType and a TypeSourceInfo* that came out of a declarator
216130
/// parsing.
217131
///
@@ -303,16 +217,11 @@ class Sema : public Action {
303217
/// VisContext - Manages the stack for #pragma GCC visibility.
304218
void *VisContext; // Really a "PragmaVisStack*"
305219

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.
312222
///
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;
316225

317226
/// ExprTemporaries - This is the stack of temporaries that are created by
318227
/// the current full expression.
@@ -727,52 +636,14 @@ class Sema : public Action {
727636
void PushBlockScope(Scope *BlockScope, BlockDecl *Block);
728637
void PopFunctionOrBlockScope();
729638

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();
746641
}
747642

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-
772643
bool hasAnyErrorsInThisFunction() const;
773644

774645
/// \brief Retrieve the current block, if any.
775-
BlockScopeInfo *getCurBlock();
646+
sema::BlockScopeInfo *getCurBlock();
776647

777648
/// WeakTopLevelDeclDecls - access to #pragma weak-generated Decls
778649
llvm::SmallVector<Decl*,2> &WeakTopLevelDecls() { return WeakTopLevelDecl; }

0 commit comments

Comments
 (0)