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" 22 #include "llvm/ADT/iterator_range.h" 35 class UsingDirectiveDecl;
78 TemplateParamScope = 0x80,
82 FunctionPrototypeScope = 0x100,
88 FunctionDeclarationScope = 0x200,
96 ObjCMethodScope = 0x800,
105 FnTryCatchScope = 0x4000,
108 OpenMPDirectiveScope = 0x8000,
111 OpenMPLoopDirectiveScope = 0x10000,
116 OpenMPSimdDirectiveScope = 0x20000,
122 SEHTryScope = 0x80000,
125 SEHExceptScope = 0x100000,
128 SEHFilterScope = 0x200000,
131 CompoundStmtScope = 0x400000,
134 ClassInheritanceScope = 0x800000,
148 unsigned short Depth;
152 unsigned short MSLastManglingNumber;
154 unsigned short MSCurManglingNumber;
158 unsigned short PrototypeDepth;
162 unsigned short PrototypeIndex;
167 Scope *MSLastManglingParent;
173 Scope *BreakParent, *ContinueParent;
183 Scope *TemplateParamParent;
191 using DeclSetTy = llvm::SmallPtrSet<Decl *, 32>;
192 DeclSetTy DeclsInScope;
207 llvm::PointerIntPair<VarDecl *, 1, bool> NRVO;
214 Init(Parent, ScopeFlags);
234 return MSLastManglingParent;
241 return ContinueParent;
245 return const_cast<Scope*
>(
this)->getContinueParent();
254 return const_cast<Scope*
>(
this)->getBreakParent();
269 return PrototypeDepth;
275 assert(isFunctionPrototypeScope());
276 return PrototypeIndex++;
279 using decl_range = llvm::iterator_range<DeclSetTy::iterator>;
282 return decl_range(DeclsInScope.begin(), DeclsInScope.end());
288 DeclsInScope.insert(D);
292 DeclsInScope.erase(D);
296 if (
Scope *MSLMP = getMSLastManglingParent()) {
297 MSLMP->MSLastManglingNumber += 1;
298 MSCurManglingNumber += 1;
303 if (
Scope *MSLMP = getMSLastManglingParent()) {
304 MSLMP->MSLastManglingNumber -= 1;
305 MSCurManglingNumber -= 1;
310 if (
const Scope *MSLMP = getMSLastManglingParent())
311 return MSLMP->MSLastManglingNumber;
316 return MSCurManglingNumber;
322 return DeclsInScope.count(D) != 0;
339 return (getFlags() & Scope::ClassScope);
345 if (
const Scope *FnS = getFnParent()) {
346 assert(FnS->getParent() &&
"TUScope not created?");
347 return FnS->getParent()->isClassScope();
355 for (
const Scope *S =
this; S; S = S->getParent()) {
357 if (S->getFlags() & ObjCMethodScope)
366 if (
const Scope *S =
this) {
368 if (S->getFlags() & ObjCMethodScope)
377 return getFlags() & Scope::TemplateParamScope;
383 return getFlags() & Scope::FunctionPrototypeScope;
388 return getFlags() & Scope::AtCatchScope;
393 for (
const Scope *S =
this; S; S = S->getParent()) {
394 if (S->getFlags() & Scope::SwitchScope)
396 else if (S->getFlags() & (Scope::FnScope | Scope::ClassScope |
397 Scope::BlockScope | Scope::TemplateParamScope |
398 Scope::FunctionPrototypeScope |
399 Scope::AtCatchScope | Scope::ObjCMethodScope))
407 return (getFlags() & Scope::OpenMPDirectiveScope);
413 if (getFlags() & Scope::OpenMPLoopDirectiveScope) {
414 assert(isOpenMPDirectiveScope() &&
415 "OpenMP loop directive scope is not a directive scope");
424 return getFlags() & Scope::OpenMPSimdDirectiveScope;
430 const Scope *
P = getParent();
435 bool isTryScope()
const {
return getFlags() & Scope::TryScope; }
445 return getFlags() & Scope::CompoundStmtScope;
456 bool containedInPrototypeScope()
const;
459 UsingDirectives.push_back(UDir);
463 llvm::iterator_range<UsingDirectivesTy::iterator>;
467 UsingDirectives.end());
473 if (NRVO.getPointer() ==
nullptr) {
477 if (NRVO.getPointer() != VD)
483 NRVO.setPointer(
nullptr);
486 void mergeNRVOIntoParent();
489 void Init(
Scope *parent,
unsigned flags);
493 void AddFlags(
unsigned Flags);
495 void dumpImpl(raw_ostream &OS)
const;
501 #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