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" 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,
136 CatchScope = 0x1000000,
150 unsigned short Depth;
154 unsigned short MSLastManglingNumber;
156 unsigned short MSCurManglingNumber;
160 unsigned short PrototypeDepth;
164 unsigned short PrototypeIndex;
169 Scope *MSLastManglingParent;
175 Scope *BreakParent, *ContinueParent;
185 Scope *TemplateParamParent;
193 using DeclSetTy = llvm::SmallPtrSet<Decl *, 32>;
194 DeclSetTy DeclsInScope;
209 llvm::PointerIntPair<VarDecl *, 1, bool> NRVO;
216 Init(Parent, ScopeFlags);
236 return MSLastManglingParent;
243 return ContinueParent;
247 return const_cast<Scope*
>(
this)->getContinueParent();
256 return const_cast<Scope*
>(
this)->getBreakParent();
271 return PrototypeDepth;
277 assert(isFunctionPrototypeScope());
278 return PrototypeIndex++;
281 using decl_range = llvm::iterator_range<DeclSetTy::iterator>;
284 return decl_range(DeclsInScope.begin(), DeclsInScope.end());
290 DeclsInScope.insert(D);
294 DeclsInScope.erase(D);
298 if (
Scope *MSLMP = getMSLastManglingParent()) {
299 MSLMP->MSLastManglingNumber += 1;
300 MSCurManglingNumber += 1;
305 if (
Scope *MSLMP = getMSLastManglingParent()) {
306 MSLMP->MSLastManglingNumber -= 1;
307 MSCurManglingNumber -= 1;
312 if (
const Scope *MSLMP = getMSLastManglingParent())
313 return MSLMP->MSLastManglingNumber;
318 return MSCurManglingNumber;
324 return DeclsInScope.count(D) != 0;
341 return (getFlags() & Scope::ClassScope);
347 if (
const Scope *FnS = getFnParent()) {
348 assert(FnS->getParent() &&
"TUScope not created?");
349 return FnS->getParent()->isClassScope();
357 for (
const Scope *S =
this; S; S = S->getParent()) {
359 if (S->getFlags() & ObjCMethodScope)
368 if (
const Scope *S =
this) {
370 if (S->getFlags() & ObjCMethodScope)
379 return getFlags() & Scope::TemplateParamScope;
385 return getFlags() & Scope::FunctionPrototypeScope;
391 return getFlags() & Scope::FunctionDeclarationScope;
396 return getFlags() & Scope::AtCatchScope;
401 for (
const Scope *S =
this; S; S = S->getParent()) {
402 if (S->getFlags() & Scope::SwitchScope)
404 else if (S->getFlags() & (Scope::FnScope | Scope::ClassScope |
405 Scope::BlockScope | Scope::TemplateParamScope |
406 Scope::FunctionPrototypeScope |
407 Scope::AtCatchScope | Scope::ObjCMethodScope))
415 return (getFlags() & Scope::OpenMPDirectiveScope);
421 if (getFlags() & Scope::OpenMPLoopDirectiveScope) {
422 assert(isOpenMPDirectiveScope() &&
423 "OpenMP loop directive scope is not a directive scope");
432 return getFlags() & Scope::OpenMPSimdDirectiveScope;
438 const Scope *
P = getParent();
443 bool isTryScope()
const {
return getFlags() & Scope::TryScope; }
453 return getFlags() & Scope::CompoundStmtScope;
464 bool containedInPrototypeScope()
const;
467 UsingDirectives.push_back(UDir);
471 llvm::iterator_range<UsingDirectivesTy::iterator>;
475 UsingDirectives.end());
481 if (NRVO.getPointer() ==
nullptr) {
485 if (NRVO.getPointer() != VD)
491 NRVO.setPointer(
nullptr);
494 void mergeNRVOIntoParent();
497 void Init(
Scope *parent,
unsigned flags);
501 void AddFlags(
unsigned Flags);
503 void dumpImpl(raw_ostream &OS)
const;
509 #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.
Specialize PointerLikeTypeTraits to allow LazyGenerationalUpdatePtr to be placed into a PointerUnion...
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)
bool isFunctionDeclarationScope() const
isFunctionDeclarationScope - Return true if this scope is a function prototype scope.
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