14 #ifndef LLVM_CLANG_SEMA_SCOPE_H 15 #define LLVM_CLANG_SEMA_SCOPE_H 19 #include "llvm/ADT/PointerIntPair.h" 20 #include "llvm/ADT/SmallPtrSet.h" 21 #include "llvm/ADT/SmallVector.h" 32 class UsingDirectiveDecl;
76 TemplateParamScope = 0x80,
80 FunctionPrototypeScope = 0x100,
86 FunctionDeclarationScope = 0x200,
94 ObjCMethodScope = 0x800,
103 FnTryCatchScope = 0x4000,
106 OpenMPDirectiveScope = 0x8000,
109 OpenMPLoopDirectiveScope = 0x10000,
114 OpenMPSimdDirectiveScope = 0x20000,
120 SEHTryScope = 0x80000,
123 SEHExceptScope = 0x100000,
126 SEHFilterScope = 0x200000,
129 CompoundStmtScope = 0x400000,
132 ClassInheritanceScope = 0x800000,
145 unsigned short Depth;
149 unsigned short MSLastManglingNumber;
151 unsigned short MSCurManglingNumber;
155 unsigned short PrototypeDepth;
159 unsigned short PrototypeIndex;
164 Scope *MSLastManglingParent;
170 Scope *BreakParent, *ContinueParent;
180 Scope *TemplateParamParent;
188 typedef llvm::SmallPtrSet<Decl *, 32> DeclSetTy;
189 DeclSetTy DeclsInScope;
197 UsingDirectivesTy UsingDirectives;
204 llvm::PointerIntPair<VarDecl *, 1, bool> NRVO;
211 Init(Parent, ScopeFlags);
233 return MSLastManglingParent;
240 return ContinueParent;
244 return const_cast<Scope*
>(
this)->getContinueParent();
253 return const_cast<Scope*
>(
this)->getBreakParent();
265 return PrototypeDepth;
271 assert(isFunctionPrototypeScope());
272 return PrototypeIndex++;
275 typedef llvm::iterator_range<DeclSetTy::iterator>
decl_range;
277 return decl_range(DeclsInScope.begin(), DeclsInScope.end());
282 DeclsInScope.insert(D);
286 DeclsInScope.erase(D);
290 if (
Scope *MSLMP = getMSLastManglingParent()) {
291 MSLMP->MSLastManglingNumber += 1;
292 MSCurManglingNumber += 1;
297 if (
Scope *MSLMP = getMSLastManglingParent()) {
298 MSLMP->MSLastManglingNumber -= 1;
299 MSCurManglingNumber -= 1;
304 if (
const Scope *MSLMP = getMSLastManglingParent())
305 return MSLMP->MSLastManglingNumber;
310 return MSCurManglingNumber;
316 return DeclsInScope.count(D) != 0;
333 return (getFlags() & Scope::ClassScope);
339 if (
const Scope *FnS = getFnParent()) {
340 assert(FnS->getParent() &&
"TUScope not created?");
341 return FnS->getParent()->isClassScope();
349 for (
const Scope *S =
this; S; S = S->getParent()) {
351 if (S->getFlags() & ObjCMethodScope)
360 if (
const Scope *S =
this) {
362 if (S->getFlags() & ObjCMethodScope)
372 return getFlags() & Scope::TemplateParamScope;
378 return getFlags() & Scope::FunctionPrototypeScope;
383 return getFlags() & Scope::AtCatchScope;
388 for (
const Scope *S =
this; S; S = S->getParent()) {
389 if (S->getFlags() & Scope::SwitchScope)
391 else if (S->getFlags() & (Scope::FnScope | Scope::ClassScope |
392 Scope::BlockScope | Scope::TemplateParamScope |
393 Scope::FunctionPrototypeScope |
394 Scope::AtCatchScope | Scope::ObjCMethodScope))
402 return (getFlags() & Scope::OpenMPDirectiveScope);
408 if (getFlags() & Scope::OpenMPLoopDirectiveScope) {
409 assert(isOpenMPDirectiveScope() &&
410 "OpenMP loop directive scope is not a directive scope");
419 return getFlags() & Scope::OpenMPSimdDirectiveScope;
425 const Scope *
P = getParent();
430 bool isTryScope()
const {
return getFlags() & Scope::TryScope; }
440 return getFlags() & Scope::CompoundStmtScope;
451 bool containedInPrototypeScope()
const;
454 UsingDirectives.push_back(UDir);
457 typedef llvm::iterator_range<UsingDirectivesTy::iterator>
462 UsingDirectives.end());
468 if (NRVO.getPointer() ==
nullptr) {
472 if (NRVO.getPointer() != VD)
478 NRVO.setPointer(
nullptr);
481 void mergeNRVOIntoParent();
485 void Init(
Scope *parent,
unsigned flags);
490 void AddFlags(
unsigned Flags);
492 void dumpImpl(raw_ostream &OS)
const;
static DiagnosticBuilder Diag(DiagnosticsEngine *Diags, const LangOptions &Features, FullSourceLoc TokLoc, const char *TokBegin, const char *TokRangeBegin, const char *TokRangeEnd, unsigned DiagID)
Produce a diagnostic highlighting some portion of a literal.
DominatorTree GraphTraits specialization so the DominatorTree can be iterable by generic graph iterat...
const Scope * getTemplateParamParent() const
bool isBlockScope() const
isBlockScope - Return true if this scope correspond to a closure.
Decl - This represents one declaration (or definition), e.g.
void setFlags(unsigned F)
bool isTemplateParamScope() const
isTemplateParamScope - Return true if this scope is a C++ template parameter scope.
The l-value was an access to a declared entity or something equivalently strong, like the address of ...
Scope * getContinueParent()
getContinueParent - Return the closest scope that a continue statement would be affected by...
VarDecl - An instance of this class is created to represent a variable declaration or definition...
ScopeFlags
ScopeFlags - These are bitfields that are or'd together when creating a scope, which defines the sort...
bool isInObjcMethodScope() const
isInObjcMethodScope - Return true if this scope is, or is contained in, an Objective-C method body...
RAII class that determines when any errors have occurred between the time the instance was created an...
Scope(Scope *Parent, unsigned ScopeFlags, DiagnosticsEngine &Diag)
Scope * getTemplateParamParent()
bool isAtCatchScope() const
isAtCatchScope - Return true if this scope is @catch.
unsigned getFunctionPrototypeDepth() const
Returns the number of function prototype scopes in this scope chain.
void decrementMSManglingNumber()
Scope * getBreakParent()
getBreakParent - Return the closest scope that a break statement would be affected by...
bool isFunctionPrototypeScope() const
isFunctionPrototypeScope - Return true if this scope is a function prototype scope.
static void dump(llvm::raw_ostream &OS, StringRef FunctionName, ArrayRef< CounterExpression > Expressions, ArrayRef< CounterMappingRegion > Regions)
Concrete class used by the front-end to report problems and issues.
bool isFunctionScope() const
isFunctionScope() - Return true if this scope is a function scope.
unsigned getMSLastManglingNumber() const
Defines the Diagnostic-related interfaces.
Scope - A scope is a transient data structure that is used while parsing the program.
using_directives_range using_directives()
void incrementMSManglingNumber()
unsigned getFlags() const
getFlags - Return the flags for this scope.
llvm::iterator_range< DeclSetTy::iterator > decl_range
bool isInCXXInlineMethodScope() const
isInCXXInlineMethodScope - Return true if this scope is a C++ inline method scope or is inside one...
bool isInObjcMethodOuterScope() const
isInObjcMethodOuterScope - Return true if this scope is an Objective-C method outer most body...
bool isDeclScope(Decl *D)
isDeclScope - Return true if this is the scope that the specified decl is declared in...
DeclContext * getEntity() const
Scope * getMSLastManglingParent()
bool isSEHTryScope() const
Determine whether this scope is a SEH '__try' block.
bool isClassScope() const
isClassScope - Return true if this scope is a class/struct/union scope.
bool hasErrorOccurred() const
bool isCompoundStmtScope() const
Determine whether this scope is a compound statement scope.
bool Contains(const Scope &rhs) const
Returns if rhs has a higher scope depth than this.
unsigned getMSCurManglingNumber() const
bool isOpenMPLoopScope() const
Determine whether this scope is a loop having OpenMP loop directive attached.
const Scope * getBreakParent() const
bool hasErrorOccurred() const
Determine whether any errors have occurred since this object instance was created.
void setEntity(DeclContext *E)
const Scope * getContinueParent() const
bool isOpenMPDirectiveScope() const
Determines whether this scope is the OpenMP directive scope.
Dataflow Directional Tag Classes.
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
const Scope * getParent() const
getParent - Return the scope that this is nested in.
bool isSEHExceptScope() const
Determine whether this scope is a SEH '__except' block.
void addNRVOCandidate(VarDecl *VD)
unsigned getNextFunctionPrototypeIndex()
Return the number of parameters declared in this function prototype, increasing it by one for the nex...
bool hasUnrecoverableErrorOccurred() const
Determine whether any unrecoverable errors have occurred since this object instance was created...
llvm::iterator_range< UsingDirectivesTy::iterator > using_directives_range
void PushUsingDirective(UsingDirectiveDecl *UDir)
bool isOpenMPLoopDirectiveScope() const
Determine whether this scope is some OpenMP loop directive scope (for example, 'omp for'...
const Scope * getMSLastManglingParent() const
bool isOpenMPSimdDirectiveScope() const
Determine whether this scope is (or is nested into) some OpenMP loop simd directive scope (for exampl...
bool isSwitchScope() const
isSwitchScope - Return true if this scope is a switch scope.
const Scope * getFnParent() const
getFnParent - Return the closest scope that is a function body.
bool isTryScope() const
Determine whether this scope is a C++ 'try' block.
bool hasUnrecoverableErrorOccurred() const
Represents C++ using-directive.
const Scope * getBlockParent() const