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;
91 setFlags(parent, flags);
94 UsingDirectives.clear();
101 const Scope *S =
this;
103 if (S->isFunctionPrototypeScope())
112 "Unsupported scope flags");
114 assert((Flags &
BreakScope) == 0 &&
"Already set");
119 ContinueParent =
this;
132 auto UpdateReturnSlotsInScopeForVD = [VD](
Scope *S) ->
bool {
133 bool IsReturnSlotFound = S->ReturnSlots.contains(VD);
138 S->ReturnSlots.clear();
140 if (IsReturnSlotFound)
141 S->ReturnSlots.insert(VD);
143 return IsReturnSlotFound;
146 bool CanBePutInReturnSlot =
false;
148 for (
auto *S =
this; S; S = S->getParent()) {
149 CanBePutInReturnSlot |= UpdateReturnSlotsInScopeForVD(S);
157 NRVO = CanBePutInReturnSlot ? VD :
nullptr;
162 if (!NRVO.has_value())
166 (*NRVO)->setNRVOVariable(
true);
195 bool HasFlags = Flags != 0;
200 std::pair<unsigned, const char *> FlagInfo[] = {
228 for (
auto Info : FlagInfo) {
229 if (Flags & Info.first) {
231 Flags &= ~Info.first;
237 assert(Flags == 0 &&
"Unknown scope flags");
243 OS <<
"Parent: (clang::Scope*)" <<
Parent <<
'\n';
245 OS <<
"Depth: " << Depth <<
'\n';
249 OS <<
"Entity : (clang::DeclContext*)" << DC <<
'\n';
252 OS <<
"there is no NRVO candidate\n";
254 OS <<
"NRVO candidate : (clang::VarDecl*)" << *NRVO <<
'\n';
256 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.
@ 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.