16#include "llvm/Support/raw_ostream.h"
20void Scope::setFlags(
Scope *parent,
unsigned flags) {
24 if (parent && !(flags &
FnScope)) {
25 BreakParent = parent->BreakParent;
26 ContinueParent = parent->ContinueParent;
30 BreakParent = ContinueParent =
nullptr;
34 Depth = parent->Depth + 1;
35 PrototypeDepth = parent->PrototypeDepth;
37 FnParent = parent->FnParent;
38 BlockParent = parent->BlockParent;
39 TemplateParamParent = parent->TemplateParamParent;
40 MSLastManglingParent = parent->MSLastManglingParent;
53 MSLastManglingParent = FnParent = BlockParent =
nullptr;
54 TemplateParamParent =
nullptr;
55 MSLastManglingNumber = 1;
56 MSCurManglingNumber = 1;
60 if (flags &
FnScope) FnParent =
this;
65 MSLastManglingParent =
this;
66 MSCurManglingNumber = 1;
93 setFlags(parent, flags);
96 UsingDirectives.clear();
103 const Scope *S =
this;
105 if (S->isFunctionPrototypeScope())
114 "Unsupported scope flags");
116 assert((Flags &
BreakScope) == 0 &&
"Already set");
121 ContinueParent =
this;
134 auto UpdateReturnSlotsInScopeForVD = [VD](
Scope *S) ->
bool {
135 bool IsReturnSlotFound = S->ReturnSlots.contains(VD);
140 S->ReturnSlots.clear();
142 if (IsReturnSlotFound)
143 S->ReturnSlots.insert(VD);
145 return IsReturnSlotFound;
148 bool CanBePutInReturnSlot =
false;
150 for (
auto *S =
this; S; S = S->getParent()) {
151 CanBePutInReturnSlot |= UpdateReturnSlotsInScopeForVD(S);
159 NRVO = CanBePutInReturnSlot ? VD :
nullptr;
164 if (!NRVO.has_value())
168 (*NRVO)->setNRVOVariable(
true);
197 bool HasFlags = Flags != 0;
202 std::pair<unsigned, const char *> FlagInfo[] = {
230 for (
auto Info : FlagInfo) {
231 if (Flags & Info.first) {
233 Flags &= ~Info.first;
239 assert(Flags == 0 &&
"Unknown scope flags");
245 OS <<
"Parent: (clang::Scope*)" <<
Parent <<
'\n';
247 OS <<
"Depth: " << Depth <<
'\n';
251 OS <<
"Entity : (clang::DeclContext*)" << DC <<
'\n';
254 OS <<
"there is no NRVO candidate\n";
256 OS <<
"NRVO candidate : (clang::VarDecl*)" << *NRVO <<
'\n';
258 OS <<
"NRVO is not allowed\n";
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
void reset()
Set to initial state of "no errors occurred".
Scope - A scope is a transient data structure that is used while parsing the program.
void Init(Scope *parent, unsigned flags)
Init - This is used by the parser to implement scope caching.
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.
void incrementMSManglingNumber()
unsigned getFlags() const
getFlags - Return the flags for this scope.
bool isDeclScope(const Decl *D) const
isDeclScope - Return true if this is the scope that the specified decl is declared in.
unsigned getMSLastManglingNumber() const
DeclContext * getEntity() const
Get the entity corresponding to this scope.
unsigned getMSCurManglingNumber() const
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.
void updateNRVOCandidate(VarDecl *VD)
void dumpImpl(raw_ostream &OS) const
@ 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.
@ BlockScope
This is a scope that corresponds to a block/closure object.
@ SEHTryScope
This scope corresponds to an SEH try.
@ ContinueScope
This is a while, do, for, which can have continue statements embedded into it.
@ 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...
@ 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.
Represents a variable declaration or definition.