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"
35class UsingDirectiveDecl;
183 unsigned short Depth;
187 unsigned short MSLastManglingNumber;
189 unsigned short MSCurManglingNumber;
193 unsigned short PrototypeDepth;
197 unsigned short PrototypeIndex;
202 Scope *MSLastManglingParent;
208 Scope *BreakParent, *ContinueParent;
218 Scope *TemplateParamParent;
231 DeclSetTy DeclsInScope;
239 UsingDirectivesTy UsingDirectives;
251 std::optional<VarDecl *> NRVO;
279 "not a loop or switch");
295 return MSLastManglingParent;
302 return ContinueParent;
312 Flags = (Flags & ~ConditionVarScope) |
344 return PrototypeDepth;
351 return PrototypeIndex++;
354 using decl_range = llvm::iterator_range<DeclSetTy::iterator>;
357 return decl_range(DeclsInScope.begin(), DeclsInScope.end());
363 if (
auto *VD = dyn_cast<VarDecl>(
D))
364 if (!isa<ParmVarDecl>(VD))
365 ReturnSlots.insert(VD);
367 DeclsInScope.insert(
D);
374 MSLMP->MSLastManglingNumber += 1;
375 MSCurManglingNumber += 1;
381 MSLMP->MSLastManglingNumber -= 1;
382 MSCurManglingNumber -= 1;
388 return MSLMP->MSLastManglingNumber;
393 return MSCurManglingNumber;
411 "entity associated with template param scope");
440 assert(FnS->getParent() &&
"TUScope not created?");
441 return FnS->getParent()->isClassScope();
449 for (
const Scope *S =
this; S; S = S->getParent()) {
450 if (S->isFunctionScope())
460 for (
const Scope *S =
this; S; S = S->getParent()) {
471 if (
const Scope *S =
this) {
507 for (
const Scope *S =
this; S; S = S->getParent()) {
537 "OpenMP loop directive scope is not a directive scope");
553 return P &&
P->isOpenMPLoopDirectiveScope();
576 for (
const Scope *S =
this; S; S = S->getParent()) {
577 if (S->isOpenACCComputeConstructScope())
580 if (S->getFlags() & Flags)
583 else if (S->getFlags() &
644 UsingDirectives.push_back(UDir);
648 llvm::iterator_range<UsingDirectivesTy::iterator>;
652 UsingDirectives.end());
660 void Init(
Scope *parent,
unsigned flags);
666 void dumpImpl(raw_ostream &OS)
const;
Defines the Diagnostic-related interfaces.
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.
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Decl - This represents one declaration (or definition), e.g.
RAII class that determines when any errors have occurred between the time the instance was created an...
bool hasUnrecoverableErrorOccurred() const
Determine whether any unrecoverable errors have occurred since this object instance was created.
Concrete class used by the front-end to report problems and issues.
Represents the declaration of a label.
Scope - A scope is a transient data structure that is used while parsing the program.
bool isFriendScope() const
Determine whether this scope is a friend scope.
Scope * getMSLastManglingParent()
void setEntity(DeclContext *E)
void AddFlags(unsigned Flags)
Sets up the specified scope flags and adjusts the scope state variables accordingly.
bool isClassScope() const
isClassScope - Return true if this scope is a class/struct/union scope.
bool isBlockScope() const
isBlockScope - Return true if this scope correspond to a closure.
unsigned getDepth() const
Returns the depth of this scope. The translation-unit has scope depth 0.
unsigned getNextFunctionPrototypeIndex()
Return the number of parameters declared in this function prototype, increasing it by one for the nex...
const Scope * getFnParent() const
getFnParent - Return the closest scope that is a function body.
bool isSEHExceptScope() const
Determine whether this scope is a SEH '__except' block.
llvm::iterator_range< DeclSetTy::iterator > decl_range
bool isInObjcMethodOuterScope() const
isInObjcMethodOuterScope - Return true if this scope is an Objective-C method outer most body.
bool isAtCatchScope() const
isAtCatchScope - Return true if this scope is @catch.
bool isCatchScope() const
isCatchScope - Return true if this scope is a C++ catch statement.
void setFlags(unsigned F)
void setPrecedingLabel(LabelDecl *LD)
bool isOpenACCLoopConstructScope() const
bool isInObjcMethodScope() const
isInObjcMethodScope - Return true if this scope is, or is contained in, an Objective-C method body.
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.
bool Contains(const Scope &rhs) const
Returns if rhs has a higher scope depth than this.
LabelDecl * getPrecedingLabel() const
Get the label that precedes this scope.
const Scope * getMSLastManglingParent() const
bool isOpenMPLoopDirectiveScope() const
Determine whether this scope is some OpenMP loop directive scope (for example, 'omp for',...
unsigned getFlags() const
getFlags - Return the flags for this scope.
DeclContext * getLookupEntity() const
Get the DeclContext in which to continue unqualified lookup after a lookup in this scope.
bool isSwitchScope() const
isSwitchScope - Return true if this scope is a switch scope.
bool isTypeAliasScope() const
Determine whether this scope is a type alias scope.
bool isOpenMPDirectiveScope() const
Determines whether this scope is the OpenMP directive scope.
using_directives_range using_directives()
Scope * getContinueParent()
getContinueParent - Return the closest scope that a continue statement would be affected by.
llvm::iterator_range< UsingDirectivesTy::iterator > using_directives_range
Scope(Scope *Parent, unsigned ScopeFlags, DiagnosticsEngine &Diag)
void setIsConditionVarScope(bool InConditionVarScope)
bool isDeclScope(const Decl *D) const
isDeclScope - Return true if this is the scope that the specified decl is declared in.
bool isFnTryCatchScope() const
Determine whether this scope is a function-level C++ try or catch scope.
void decrementMSManglingNumber()
bool isControlScope() const
Determine whether this scope is a controlling scope in a if/switch/while/for statement.
const Scope * getTemplateParamParent() const
void setLookupEntity(DeclContext *E)
unsigned getMSLastManglingNumber() const
DeclContext * getEntity() const
Get the entity corresponding to this scope.
unsigned getMSCurManglingNumber() const
bool isLoopScope() const
Return true if this scope is a loop.
bool isSEHTryScope() const
Determine whether this scope is a SEH '__try' block.
bool isOpenMPSimdDirectiveScope() const
Determine whether this scope is (or is nested into) some OpenMP loop simd directive scope (for exampl...
bool isTemplateParamScope() const
isTemplateParamScope - Return true if this scope is a C++ template parameter scope.
unsigned getFunctionPrototypeDepth() const
Returns the number of function prototype scopes in this scope chain.
Scope * getBreakParent()
getBreakParent - Return the closest scope that a break statement would be affected by.
bool isCompoundStmtScope() const
Determine whether this scope is a compound statement scope.
bool isInCFunctionScope() const
isInObjcMethodScope - Return true if this scope is, or is contained, in an C function body.
bool isInOpenACCComputeConstructScope(ScopeFlags Flags=NoScope) const
Determine if this scope (or its parents) are a compute construct.
bool isFunctionDeclarationScope() const
isFunctionDeclarationScope - Return true if this scope is a function prototype scope.
bool containedInPrototypeScope() const
containedInPrototypeScope - Return true if this or a parent scope is a FunctionPrototypeScope.
bool isOpenMPOrderClauseScope() const
Determine whether this scope is some OpenMP directive with order clause which specifies concurrent sc...
const Scope * getParent() const
getParent - Return the scope that this is nested in.
bool isBreakOrContinueScope() const
Determine whether this is a scope which can have 'break' or 'continue' statements embedded into it.
bool isContinueScope() const
Determine whether this scope is a while/do/for statement, which can have continue statements embedded...
bool isClassInheritanceScope() const
Determines whether this scope is between inheritance colon and the real class/struct definition.
bool isConditionVarScope() const
bool isFunctionPrototypeScope() const
isFunctionPrototypeScope - Return true if this scope is a function prototype scope.
bool isTryScope() const
Determine whether this scope is a C++ 'try' block.
void updateNRVOCandidate(VarDecl *VD)
const Scope * getBlockParent() const
bool isFunctionScope() const
isFunctionScope() - Return true if this scope is a function scope.
const Scope * getContinueParent() const
bool isOpenACCComputeConstructScope() const
Determine whether this scope is the statement associated with an OpenACC Compute construct directive.
void dumpImpl(raw_ostream &OS) const
const Scope * getDeclParent() const
bool hasUnrecoverableErrorOccurred() const
Determine whether any unrecoverable errors have occurred within this scope.
bool isOpenMPLoopScope() const
Determine whether this scope is a loop having OpenMP loop directive attached.
Scope * getTemplateParamParent()
ScopeFlags
ScopeFlags - These are bitfields that are or'd together when creating a scope, which defines the sort...
@ OpenMPDirectiveScope
This is the scope of OpenMP executable directive.
@ FunctionPrototypeScope
This is a scope that corresponds to the parameters within a function prototype.
@ OpenMPOrderClauseScope
This is a scope of some OpenMP directive with order clause which specifies concurrent.
@ LambdaScope
This is the scope for a lambda, after the lambda introducer.
@ OpenACCLoopConstructScope
This is the scope of an OpenACC Loop/Combined construct, which is used to determine whether a 'cache'...
@ BlockScope
This is a scope that corresponds to a block/closure object.
@ SEHTryScope
This scope corresponds to an SEH try.
@ FriendScope
This is a scope of friend declaration.
@ ContinueScope
This is a while, do, for, which can have continue statements embedded into it.
@ OpenACCComputeConstructScope
This is the scope of an OpenACC Compute Construct, which restricts jumping into/out of it.
@ TypeAliasScope
This is a scope of type alias declaration.
@ ControlScope
The controlling scope in a if/switch/while/for statement.
@ ClassInheritanceScope
We are between inheritance colon and the real class/struct definition scope.
@ AtCatchScope
This is a scope that corresponds to the Objective-C @catch statement.
@ TemplateParamScope
This is a scope that corresponds to the template parameters of a C++ template.
@ SEHFilterScope
We are currently in the filter expression of an SEH except block.
@ SwitchScope
This is a scope that corresponds to a switch statement.
@ BreakScope
This is a while, do, switch, for, etc that can have break statements embedded into it.
@ CatchScope
This is the scope of a C++ catch statement.
@ CompoundStmtScope
This is a compound statement scope.
@ FnTryCatchScope
This is the scope for a function-level C++ try or catch scope.
@ SEHExceptScope
This scope corresponds to an SEH except.
@ ClassScope
The scope of a struct/union/class definition.
@ TryScope
This is the scope of a C++ try statement.
@ OpenMPSimdDirectiveScope
This is the scope of some OpenMP simd directive.
@ FunctionDeclarationScope
This is a scope that corresponds to the parameters within a function prototype for a function declara...
@ ConditionVarScope
This is a scope in which a condition variable is currently being parsed.
@ FnScope
This indicates that the scope corresponds to a function, which means that labels are set here.
@ ObjCMethodScope
This scope corresponds to an Objective-C method body.
@ EnumScope
This scope corresponds to an enum.
@ OpenMPLoopDirectiveScope
This is the scope of some OpenMP loop directive.
@ DeclScope
This is a scope that can contain a declaration.
void PushUsingDirective(UsingDirectiveDecl *UDir)
Represents C++ using-directive.
Represents a variable declaration or definition.
std::variant< struct RequiresDecl, struct HeaderDecl, struct UmbrellaDirDecl, struct ModuleDecl, struct ExcludeDecl, struct ExportDecl, struct ExportAsDecl, struct ExternModuleDecl, struct UseDecl, struct LinkDecl, struct ConfigMacrosDecl, struct ConflictDecl > Decl
All declarations that can appear in a module declaration.
The JSON file list parser is used to communicate input to InstallAPI.
Diagnostic wrappers for TextAPI types for error reporting.