Go to the documentation of this file.
13 #ifndef LLVM_CLANG_SEMA_SCOPE_H
14 #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"
35 class UsingDirectiveDecl;
161 unsigned short Depth;
165 unsigned short MSLastManglingNumber;
167 unsigned short MSCurManglingNumber;
171 unsigned short PrototypeDepth;
175 unsigned short PrototypeIndex;
180 Scope *MSLastManglingParent;
186 Scope *BreakParent, *ContinueParent;
196 Scope *TemplateParamParent;
205 DeclSetTy DeclsInScope;
213 UsingDirectivesTy UsingDirectives;
225 std::optional<VarDecl *> NRVO;
257 return MSLastManglingParent;
264 return ContinueParent;
303 return PrototypeDepth;
310 return PrototypeIndex++;
313 using decl_range = llvm::iterator_range<DeclSetTy::iterator>;
316 return decl_range(DeclsInScope.begin(), DeclsInScope.end());
322 if (
auto *VD = dyn_cast<VarDecl>(D))
323 if (!isa<ParmVarDecl>(VD))
324 ReturnSlots.insert(VD);
326 DeclsInScope.insert(D);
333 MSLMP->MSLastManglingNumber += 1;
334 MSCurManglingNumber += 1;
340 MSLMP->MSLastManglingNumber -= 1;
341 MSCurManglingNumber -= 1;
347 return MSLMP->MSLastManglingNumber;
352 return MSCurManglingNumber;
370 "entity associated with template param scope");
399 assert(FnS->getParent() &&
"TUScope not created?");
400 return FnS->getParent()->isClassScope();
408 for (
const Scope *S =
this; S; S = S->getParent()) {
419 if (
const Scope *S =
this) {
455 for (
const Scope *S =
this; S; S = S->getParent()) {
477 "OpenMP loop directive scope is not a directive scope");
493 return P &&
P->isOpenMPLoopDirectiveScope();
505 return getFlags() & ScopeFlags::ContinueScope;
513 return getFlags() & ScopeFlags::FnTryCatchScope;
542 UsingDirectives.push_back(UDir);
546 llvm::iterator_range<UsingDirectivesTy::iterator>;
550 UsingDirectives.end());
558 void Init(
Scope *parent,
unsigned flags);
564 void dumpImpl(raw_ostream &OS)
const;
570 #endif // LLVM_CLANG_SEMA_SCOPE_H
bool isFunctionScope() const
isFunctionScope() - Return true if this scope is a function scope.
const Scope * getFnParent() const
getFnParent - Return the closest scope that is a function body.
void setFlags(unsigned F)
YAML serialization mapping.
bool isClassScope() const
isClassScope - Return true if this scope is a class/struct/union scope.
@ FunctionPrototypeScope
This is a scope that corresponds to the parameters within a function prototype.
bool isOpenMPLoopDirectiveScope() const
Determine whether this scope is some OpenMP loop directive scope (for example, 'omp for',...
void updateNRVOCandidate(VarDecl *VD)
@ FnScope
This indicates that the scope corresponds to a function, which means that labels are set here.
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
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.
@ OpenMPLoopDirectiveScope
This is the scope of some OpenMP loop directive.
Represents C++ using-directive.
bool isFnTryCatchScope() const
Determine whether this scope is a function-level C++ try or catch scope.
@ BlockScope
This is a scope that corresponds to a block/closure object.
Concrete class used by the front-end to report problems and issues.
bool isInObjcMethodOuterScope() const
isInObjcMethodOuterScope - Return true if this scope is an Objective-C method outer most body.
unsigned getMSCurManglingNumber() const
bool isCompoundStmtScope() const
Determine whether this scope is a compound statement scope.
void setIsConditionVarScope(bool InConditionVarScope)
bool isSwitchScope() const
isSwitchScope - Return true if this scope is a switch scope.
bool hasUnrecoverableErrorOccurred() const
Determine whether any unrecoverable errors have occurred since this object instance was created.
unsigned getDepth() const
Returns the depth of this scope. The translation-unit has scope depth 0.
@ ConditionVarScope
This is a scope in which a condition variable is currently being parsed.
@ SwitchScope
This is a scope that corresponds to a switch statement.
void setLookupEntity(DeclContext *E)
RAII class that determines when any errors have occurred between the time the instance was created an...
bool containedInPrototypeScope() const
containedInPrototypeScope - Return true if this or a parent scope is a FunctionPrototypeScope.
const Scope * getParent() const
getParent - Return the scope that this is nested in.
bool isFunctionPrototypeScope() const
isFunctionPrototypeScope - Return true if this scope is a function prototype scope.
@ Decl
The l-value was an access to a declared entity or something equivalently strong, like the address of ...
@ OpenMPDirectiveScope
This is the scope of OpenMP executable directive.
@ SEHTryScope
This scope corresponds to an SEH try.
void decrementMSManglingNumber()
const Scope * getMSLastManglingParent() const
Scope * getTemplateParamParent()
Scope - A scope is a transient data structure that is used while parsing the program.
bool isOpenMPDirectiveScope() const
Determines whether this scope is the OpenMP directive scope.
bool isDeclScope(const Decl *D) const
isDeclScope - Return true if this is the scope that the specified decl is declared in.
void dumpImpl(raw_ostream &OS) const
bool isContinueScope() const
Determine whether this scope is a while/do/for statement, which can have continue statements embedded...
void Init(Scope *parent, unsigned flags)
Init - This is used by the parser to implement scope caching.
@ CompoundStmtScope
This is a compound statement scope.
@ FunctionDeclarationScope
This is a scope that corresponds to the parameters within a function prototype for a function declara...
bool hasUnrecoverableErrorOccurred() const
Determine whether any unrecoverable errors have occurred within this scope.
Scope(Scope *Parent, unsigned ScopeFlags, DiagnosticsEngine &Diag)
bool isAtCatchScope() const
isAtCatchScope - Return true if this scope is @catch.
@ ContinueScope
This is a while, do, for, which can have continue statements embedded into it.
unsigned getMSLastManglingNumber() const
Represents a variable declaration or definition.
bool isOpenMPLoopScope() const
Determine whether this scope is a loop having OpenMP loop directive attached.
bool isSEHExceptScope() const
Determine whether this scope is a SEH '__except' block.
unsigned getFunctionPrototypeDepth() const
Returns the number of function prototype scopes in this scope chain.
DeclContext * getLookupEntity() const
Get the DeclContext in which to continue unqualified lookup after a lookup in this scope.
bool isTemplateParamScope() const
isTemplateParamScope - Return true if this scope is a C++ template parameter scope.
@ ControlScope
The controlling scope in a if/switch/while/for statement.
bool isOpenMPOrderClauseScope() const
Determine whether this scope is some OpenMP directive with order clause which specifies concurrent sc...
@ EnumScope
This scope corresponds to an enum.
using_directives_range using_directives()
bool isCatchScope() const
isCatchScope - Return true if this scope is a C++ catch statement.
const Scope * getTemplateParamParent() const
void AddFlags(unsigned Flags)
Sets up the specified scope flags and adjusts the scope state variables accordingly.
void incrementMSManglingNumber()
const Scope * getBreakParent() const
bool isInCXXInlineMethodScope() const
isInCXXInlineMethodScope - Return true if this scope is a C++ inline method scope or is inside one.
@ TemplateParamScope
This is a scope that corresponds to the template parameters of a C++ template.
bool isInObjcMethodScope() const
isInObjcMethodScope - Return true if this scope is, or is contained in, an Objective-C method body.
Scope * getBreakParent()
getBreakParent - Return the closest scope that a break statement would be affected by.
@ AtCatchScope
This is a scope that corresponds to the Objective-C @catch statement.
llvm::iterator_range< DeclSetTy::iterator > decl_range
@ ClassInheritanceScope
We are between inheritance colon and the real class/struct definition scope.
@ ClassScope
The scope of a struct/union/class definition.
unsigned getFlags() const
getFlags - Return the flags for this scope.
Decl - This represents one declaration (or definition), e.g.
bool isSEHTryScope() const
Determine whether this scope is a SEH '__try' block.
@ SEHExceptScope
This scope corresponds to an SEH except.
bool isOpenMPSimdDirectiveScope() const
Determine whether this scope is (or is nested into) some OpenMP loop simd directive scope (for exampl...
void setEntity(DeclContext *E)
Scope * getContinueParent()
getContinueParent - Return the closest scope that a continue statement would be affected by.
@ OpenMPOrderClauseScope
This is a scope of some OpenMP directive with order clause which specifies concurrent.
unsigned getNextFunctionPrototypeIndex()
Return the number of parameters declared in this function prototype, increasing it by one for the nex...
@ CatchScope
This is the scope of a C++ catch statement.
ScopeFlags
ScopeFlags - These are bitfields that are or'd together when creating a scope, which defines the sort...
DeclContext * getEntity() const
Get the entity corresponding to this scope.
Scope * getMSLastManglingParent()
@ SEHFilterScope
We are currently in the filter expression of an SEH except block.
bool isControlScope() const
Determine whether this scope is a controlling scope in a if/switch/while/for statement.
const Scope * getBlockParent() const
@ ObjCMethodScope
This scope corresponds to an Objective-C method body.
bool Contains(const Scope &rhs) const
Returns if rhs has a higher scope depth than this.
bool isBlockScope() const
isBlockScope - Return true if this scope correspond to a closure.
bool isFunctionDeclarationScope() const
isFunctionDeclarationScope - Return true if this scope is a function prototype scope.
@ TryScope
This is the scope of a C++ try statement.
@ DeclScope
This is a scope that can contain a declaration.
@ FnTryCatchScope
This is the scope for a function-level C++ try or catch scope.
@ BreakScope
This is a while, do, switch, for, etc that can have break statements embedded into it.
const Scope * getContinueParent() const
@ OpenMPSimdDirectiveScope
This is the scope of some OpenMP simd directive.
bool isConditionVarScope() const
bool isTryScope() const
Determine whether this scope is a C++ 'try' block.
void PushUsingDirective(UsingDirectiveDecl *UDir)
llvm::iterator_range< UsingDirectivesTy::iterator > using_directives_range
bool isClassInheritanceScope() const
Determines whether this scope is between inheritance colon and the real class/struct definition.