14 #ifndef LLVM_CLANG_SEMA_SCOPE_H 15 #define LLVM_CLANG_SEMA_SCOPE_H 18 #include "llvm/ADT/PointerIntPair.h" 19 #include "llvm/ADT/SmallPtrSet.h" 20 #include "llvm/ADT/SmallVector.h" 21 #include "llvm/ADT/iterator_range.h" 34 class UsingDirectiveDecl;
77 TemplateParamScope = 0x80,
81 FunctionPrototypeScope = 0x100,
87 FunctionDeclarationScope = 0x200,
95 ObjCMethodScope = 0x800,
104 FnTryCatchScope = 0x4000,
107 OpenMPDirectiveScope = 0x8000,
110 OpenMPLoopDirectiveScope = 0x10000,
115 OpenMPSimdDirectiveScope = 0x20000,
121 SEHTryScope = 0x80000,
124 SEHExceptScope = 0x100000,
127 SEHFilterScope = 0x200000,
130 CompoundStmtScope = 0x400000,
133 ClassInheritanceScope = 0x800000,
147 unsigned short Depth;
151 unsigned short MSLastManglingNumber;
153 unsigned short MSCurManglingNumber;
157 unsigned short PrototypeDepth;
161 unsigned short PrototypeIndex;
166 Scope *MSLastManglingParent;
172 Scope *BreakParent, *ContinueParent;
182 Scope *TemplateParamParent;
190 using DeclSetTy = llvm::SmallPtrSet<Decl *, 32>;
191 DeclSetTy DeclsInScope;
206 llvm::PointerIntPair<VarDecl *, 1, bool> NRVO;
213 Init(Parent, ScopeFlags);
233 return MSLastManglingParent;
240 return ContinueParent;
244 return const_cast<Scope*
>(
this)->getContinueParent();
253 return const_cast<Scope*
>(
this)->getBreakParent();
268 return PrototypeDepth;
274 assert(isFunctionPrototypeScope());
275 return PrototypeIndex++;
278 using decl_range = llvm::iterator_range<DeclSetTy::iterator>;
281 return decl_range(DeclsInScope.begin(), DeclsInScope.end());
287 DeclsInScope.insert(D);
291 DeclsInScope.erase(D);
295 if (
Scope *MSLMP = getMSLastManglingParent()) {
296 MSLMP->MSLastManglingNumber += 1;
297 MSCurManglingNumber += 1;
302 if (
Scope *MSLMP = getMSLastManglingParent()) {
303 MSLMP->MSLastManglingNumber -= 1;
304 MSCurManglingNumber -= 1;
309 if (
const Scope *MSLMP = getMSLastManglingParent())
310 return MSLMP->MSLastManglingNumber;
315 return MSCurManglingNumber;
321 return DeclsInScope.count(D) != 0;
338 return (getFlags() & Scope::ClassScope);
344 if (
const Scope *FnS = getFnParent()) {
345 assert(FnS->getParent() &&
"TUScope not created?");
346 return FnS->getParent()->isClassScope();
354 for (
const Scope *S =
this; S; S = S->getParent()) {
356 if (S->getFlags() & ObjCMethodScope)
365 if (
const Scope *S =
this) {
367 if (S->getFlags() & ObjCMethodScope)
376 return getFlags() & Scope::TemplateParamScope;
382 return getFlags() & Scope::FunctionPrototypeScope;
387 return getFlags() & Scope::AtCatchScope;
392 for (
const Scope *S =
this; S; S = S->getParent()) {
393 if (S->getFlags() & Scope::SwitchScope)
395 else if (S->getFlags() & (Scope::FnScope | Scope::ClassScope |
396 Scope::BlockScope | Scope::TemplateParamScope |
397 Scope::FunctionPrototypeScope |
398 Scope::AtCatchScope | Scope::ObjCMethodScope))
406 return (getFlags() & Scope::OpenMPDirectiveScope);
412 if (getFlags() & Scope::OpenMPLoopDirectiveScope) {
413 assert(isOpenMPDirectiveScope() &&
414 "OpenMP loop directive scope is not a directive scope");
423 return getFlags() & Scope::OpenMPSimdDirectiveScope;
429 const Scope *
P = getParent();
434 bool isTryScope()
const {
return getFlags() & Scope::TryScope; }
444 return getFlags() & Scope::CompoundStmtScope;
455 bool containedInPrototypeScope()
const;
458 UsingDirectives.push_back(UDir);
462 llvm::iterator_range<UsingDirectivesTy::iterator>;
466 UsingDirectives.end());
472 if (NRVO.getPointer() ==
nullptr) {
476 if (NRVO.getPointer() != VD)
482 NRVO.setPointer(
nullptr);
485 void mergeNRVOIntoParent();
488 void Init(
Scope *parent,
unsigned flags);
492 void AddFlags(
unsigned Flags);
494 void dumpImpl(raw_ostream &OS)
const;
500 #endif // LLVM_CLANG_SEMA_SCOPE_H
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.
llvm::iterator_range< DeclSetTy::iterator > decl_range
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...
unsigned getDepth() const
Returns the depth of this scope. The translation-unit has scope depth 0.
Represents 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.
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...
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
llvm::iterator_range< UsingDirectivesTy::iterator > using_directives_range