xref: /freebsd/contrib/llvm-project/clang/include/clang/Sema/Scope.h (revision 700637cbb5e582861067a11aaca4d053546871d2)
1 //===- Scope.h - Scope interface --------------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 //  This file defines the Scope interface.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef LLVM_CLANG_SEMA_SCOPE_H
14 #define LLVM_CLANG_SEMA_SCOPE_H
15 
16 #include "clang/AST/Decl.h"
17 #include "clang/Basic/Diagnostic.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"
22 #include <cassert>
23 #include <optional>
24 
25 namespace llvm {
26 
27 class raw_ostream;
28 
29 } // namespace llvm
30 
31 namespace clang {
32 
33 class Decl;
34 class DeclContext;
35 class UsingDirectiveDecl;
36 class VarDecl;
37 
38 /// Scope - A scope is a transient data structure that is used while parsing the
39 /// program.  It assists with resolving identifiers to the appropriate
40 /// declaration.
41 class Scope {
42 public:
43   /// ScopeFlags - These are bitfields that are or'd together when creating a
44   /// scope, which defines the sorts of things the scope contains.
45   enum ScopeFlags {
46     // A bitfield value representing no scopes.
47     NoScope = 0,
48 
49     /// This indicates that the scope corresponds to a function, which
50     /// means that labels are set here.
51     FnScope = 0x01,
52 
53     /// This is a while, do, switch, for, etc that can have break
54     /// statements embedded into it.
55     BreakScope = 0x02,
56 
57     /// This is a while, do, for, which can have continue statements
58     /// embedded into it.
59     ContinueScope = 0x04,
60 
61     /// This is a scope that can contain a declaration.  Some scopes
62     /// just contain loop constructs but don't contain decls.
63     DeclScope = 0x08,
64 
65     /// The controlling scope in a if/switch/while/for statement.
66     ControlScope = 0x10,
67 
68     /// The scope of a struct/union/class definition.
69     ClassScope = 0x20,
70 
71     /// This is a scope that corresponds to a block/closure object.
72     /// Blocks serve as top-level scopes for some objects like labels, they
73     /// also prevent things like break and continue.  BlockScopes always have
74     /// the FnScope and DeclScope flags set as well.
75     BlockScope = 0x40,
76 
77     /// This is a scope that corresponds to the
78     /// template parameters of a C++ template. Template parameter
79     /// scope starts at the 'template' keyword and ends when the
80     /// template declaration ends.
81     TemplateParamScope = 0x80,
82 
83     /// This is a scope that corresponds to the
84     /// parameters within a function prototype.
85     FunctionPrototypeScope = 0x100,
86 
87     /// This is a scope that corresponds to the parameters within
88     /// a function prototype for a function declaration (as opposed to any
89     /// other kind of function declarator). Always has FunctionPrototypeScope
90     /// set as well.
91     FunctionDeclarationScope = 0x200,
92 
93     /// This is a scope that corresponds to the Objective-C
94     /// \@catch statement.
95     AtCatchScope = 0x400,
96 
97     /// This scope corresponds to an Objective-C method body.
98     /// It always has FnScope and DeclScope set as well.
99     ObjCMethodScope = 0x800,
100 
101     /// This is a scope that corresponds to a switch statement.
102     SwitchScope = 0x1000,
103 
104     /// This is the scope of a C++ try statement.
105     TryScope = 0x2000,
106 
107     /// This is the scope for a function-level C++ try or catch scope.
108     FnTryCatchScope = 0x4000,
109 
110     /// This is the scope of OpenMP executable directive.
111     OpenMPDirectiveScope = 0x8000,
112 
113     /// This is the scope of some OpenMP loop directive.
114     OpenMPLoopDirectiveScope = 0x10000,
115 
116     /// This is the scope of some OpenMP simd directive.
117     /// For example, it is used for 'omp simd', 'omp for simd'.
118     /// This flag is propagated to children scopes.
119     OpenMPSimdDirectiveScope = 0x20000,
120 
121     /// This scope corresponds to an enum.
122     EnumScope = 0x40000,
123 
124     /// This scope corresponds to an SEH try.
125     SEHTryScope = 0x80000,
126 
127     /// This scope corresponds to an SEH except.
128     SEHExceptScope = 0x100000,
129 
130     /// We are currently in the filter expression of an SEH except block.
131     SEHFilterScope = 0x200000,
132 
133     /// This is a compound statement scope.
134     CompoundStmtScope = 0x400000,
135 
136     /// We are between inheritance colon and the real class/struct definition
137     /// scope.
138     ClassInheritanceScope = 0x800000,
139 
140     /// This is the scope of a C++ catch statement.
141     CatchScope = 0x1000000,
142 
143     /// This is a scope in which a condition variable is currently being
144     /// parsed. If such a scope is a ContinueScope, it's invalid to jump to the
145     /// continue block from here.
146     ConditionVarScope = 0x2000000,
147 
148     /// This is a scope of some OpenMP directive with
149     /// order clause which specifies concurrent
150     OpenMPOrderClauseScope = 0x4000000,
151     /// This is the scope for a lambda, after the lambda introducer.
152     /// Lambdas need two FunctionPrototypeScope scopes (because there is a
153     /// template scope in between), the outer scope does not increase the
154     /// depth of recursion.
155     LambdaScope = 0x8000000,
156     /// This is the scope of an OpenACC Compute Construct, which restricts
157     /// jumping into/out of it. We also use this to represent 'combined'
158     /// constructs, since they have the same behavior.
159     OpenACCComputeConstructScope = 0x10000000,
160 
161     /// This is the scope of an OpenACC Loop/Combined construct, which is used
162     /// to determine whether a 'cache' construct variable reference is legal.
163     OpenACCLoopConstructScope = 0x20000000,
164 
165     /// This is a scope of type alias declaration.
166     TypeAliasScope = 0x40000000,
167 
168     /// This is a scope of friend declaration.
169     FriendScope = 0x80000000,
170   };
171 
172 private:
173   /// The parent scope for this scope.  This is null for the translation-unit
174   /// scope.
175   Scope *AnyParent;
176 
177   /// Flags - This contains a set of ScopeFlags, which indicates how the scope
178   /// interrelates with other control flow statements.
179   unsigned Flags;
180 
181   /// Depth - This is the depth of this scope.  The translation-unit scope has
182   /// depth 0.
183   unsigned short Depth;
184 
185   /// Declarations with static linkage are mangled with the number of
186   /// scopes seen as a component.
187   unsigned short MSLastManglingNumber;
188 
189   unsigned short MSCurManglingNumber;
190 
191   /// PrototypeDepth - This is the number of function prototype scopes
192   /// enclosing this scope, including this scope.
193   unsigned short PrototypeDepth;
194 
195   /// PrototypeIndex - This is the number of parameters currently
196   /// declared in this scope.
197   unsigned short PrototypeIndex;
198 
199   /// FnParent - If this scope has a parent scope that is a function body, this
200   /// pointer is non-null and points to it.  This is used for label processing.
201   Scope *FnParent;
202   Scope *MSLastManglingParent;
203 
204   /// BreakParent/ContinueParent - This is a direct link to the innermost
205   /// BreakScope/ContinueScope which contains the contents of this scope
206   /// for control flow purposes (and might be this scope itself), or null
207   /// if there is no such scope.
208   Scope *BreakParent, *ContinueParent;
209 
210   /// BlockParent - This is a direct link to the immediately containing
211   /// BlockScope if this scope is not one, or null if there is none.
212   Scope *BlockParent;
213 
214   /// TemplateParamParent - This is a direct link to the
215   /// immediately containing template parameter scope. In the
216   /// case of nested templates, template parameter scopes can have
217   /// other template parameter scopes as parents.
218   Scope *TemplateParamParent;
219 
220   /// DeclScopeParent - This is a direct link to the immediately containing
221   /// DeclScope, i.e. scope which can contain declarations.
222   Scope *DeclParent;
223 
224   /// DeclsInScope - This keeps track of all declarations in this scope.  When
225   /// the declaration is added to the scope, it is set as the current
226   /// declaration for the identifier in the IdentifierTable.  When the scope is
227   /// popped, these declarations are removed from the IdentifierTable's notion
228   /// of current declaration.  It is up to the current Action implementation to
229   /// implement these semantics.
230   using DeclSetTy = llvm::SmallPtrSet<Decl *, 32>;
231   DeclSetTy DeclsInScope;
232 
233   /// The DeclContext with which this scope is associated. For
234   /// example, the entity of a class scope is the class itself, the
235   /// entity of a function scope is a function, etc.
236   DeclContext *Entity;
237 
238   using UsingDirectivesTy = SmallVector<UsingDirectiveDecl *, 2>;
239   UsingDirectivesTy UsingDirectives;
240 
241   /// Used to determine if errors occurred in this scope.
242   DiagnosticErrorTrap ErrorTrap;
243 
244   /// A single NRVO candidate variable in this scope.
245   /// There are three possible values:
246   ///  1) pointer to VarDecl that denotes NRVO candidate itself.
247   ///  2) nullptr value means that NRVO is not allowed in this scope
248   ///     (e.g. return a function parameter).
249   ///  3) std::nullopt value means that there is no NRVO candidate in this scope
250   ///     (i.e. there are no return statements in this scope).
251   std::optional<VarDecl *> NRVO;
252 
253   /// Represents return slots for NRVO candidates in the current scope.
254   /// If a variable is present in this set, it means that a return slot is
255   /// available for this variable in the current scope.
256   llvm::SmallPtrSet<VarDecl *, 8> ReturnSlots;
257 
258   void setFlags(Scope *Parent, unsigned F);
259 
260 public:
Scope(Scope * Parent,unsigned ScopeFlags,DiagnosticsEngine & Diag)261   Scope(Scope *Parent, unsigned ScopeFlags, DiagnosticsEngine &Diag)
262       : ErrorTrap(Diag) {
263     Init(Parent, ScopeFlags);
264   }
265 
266   /// getFlags - Return the flags for this scope.
getFlags()267   unsigned getFlags() const { return Flags; }
268 
setFlags(unsigned F)269   void setFlags(unsigned F) { setFlags(getParent(), F); }
270 
271   /// isBlockScope - Return true if this scope correspond to a closure.
isBlockScope()272   bool isBlockScope() const { return Flags & BlockScope; }
273 
274   /// getParent - Return the scope that this is nested in.
getParent()275   const Scope *getParent() const { return AnyParent; }
getParent()276   Scope *getParent() { return AnyParent; }
277 
278   /// getFnParent - Return the closest scope that is a function body.
getFnParent()279   const Scope *getFnParent() const { return FnParent; }
getFnParent()280   Scope *getFnParent() { return FnParent; }
281 
getMSLastManglingParent()282   const Scope *getMSLastManglingParent() const {
283     return MSLastManglingParent;
284   }
getMSLastManglingParent()285   Scope *getMSLastManglingParent() { return MSLastManglingParent; }
286 
287   /// getContinueParent - Return the closest scope that a continue statement
288   /// would be affected by.
getContinueParent()289   Scope *getContinueParent() {
290     return ContinueParent;
291   }
292 
getContinueParent()293   const Scope *getContinueParent() const {
294     return const_cast<Scope*>(this)->getContinueParent();
295   }
296 
297   // Set whether we're in the scope of a condition variable, where 'continue'
298   // is disallowed despite being a continue scope.
setIsConditionVarScope(bool InConditionVarScope)299   void setIsConditionVarScope(bool InConditionVarScope) {
300     Flags = (Flags & ~ConditionVarScope) |
301             (InConditionVarScope ? ConditionVarScope : NoScope);
302   }
303 
isConditionVarScope()304   bool isConditionVarScope() const {
305     return Flags & ConditionVarScope;
306   }
307 
308   /// getBreakParent - Return the closest scope that a break statement
309   /// would be affected by.
getBreakParent()310   Scope *getBreakParent() {
311     return BreakParent;
312   }
getBreakParent()313   const Scope *getBreakParent() const {
314     return const_cast<Scope*>(this)->getBreakParent();
315   }
316 
getBlockParent()317   Scope *getBlockParent() { return BlockParent; }
getBlockParent()318   const Scope *getBlockParent() const { return BlockParent; }
319 
getTemplateParamParent()320   Scope *getTemplateParamParent() { return TemplateParamParent; }
getTemplateParamParent()321   const Scope *getTemplateParamParent() const { return TemplateParamParent; }
322 
getDeclParent()323   Scope *getDeclParent() { return DeclParent; }
getDeclParent()324   const Scope *getDeclParent() const { return DeclParent; }
325 
326   /// Returns the depth of this scope. The translation-unit has scope depth 0.
getDepth()327   unsigned getDepth() const { return Depth; }
328 
329   /// Returns the number of function prototype scopes in this scope
330   /// chain.
getFunctionPrototypeDepth()331   unsigned getFunctionPrototypeDepth() const {
332     return PrototypeDepth;
333   }
334 
335   /// Return the number of parameters declared in this function
336   /// prototype, increasing it by one for the next call.
getNextFunctionPrototypeIndex()337   unsigned getNextFunctionPrototypeIndex() {
338     assert(isFunctionPrototypeScope());
339     return PrototypeIndex++;
340   }
341 
342   using decl_range = llvm::iterator_range<DeclSetTy::iterator>;
343 
decls()344   decl_range decls() const {
345     return decl_range(DeclsInScope.begin(), DeclsInScope.end());
346   }
347 
decl_empty()348   bool decl_empty() const { return DeclsInScope.empty(); }
349 
AddDecl(Decl * D)350   void AddDecl(Decl *D) {
351     if (auto *VD = dyn_cast<VarDecl>(D))
352       if (!isa<ParmVarDecl>(VD))
353         ReturnSlots.insert(VD);
354 
355     DeclsInScope.insert(D);
356   }
357 
RemoveDecl(Decl * D)358   void RemoveDecl(Decl *D) { DeclsInScope.erase(D); }
359 
incrementMSManglingNumber()360   void incrementMSManglingNumber() {
361     if (Scope *MSLMP = getMSLastManglingParent()) {
362       MSLMP->MSLastManglingNumber += 1;
363       MSCurManglingNumber += 1;
364     }
365   }
366 
decrementMSManglingNumber()367   void decrementMSManglingNumber() {
368     if (Scope *MSLMP = getMSLastManglingParent()) {
369       MSLMP->MSLastManglingNumber -= 1;
370       MSCurManglingNumber -= 1;
371     }
372   }
373 
getMSLastManglingNumber()374   unsigned getMSLastManglingNumber() const {
375     if (const Scope *MSLMP = getMSLastManglingParent())
376       return MSLMP->MSLastManglingNumber;
377     return 1;
378   }
379 
getMSCurManglingNumber()380   unsigned getMSCurManglingNumber() const {
381     return MSCurManglingNumber;
382   }
383 
384   /// isDeclScope - Return true if this is the scope that the specified decl is
385   /// declared in.
isDeclScope(const Decl * D)386   bool isDeclScope(const Decl *D) const { return DeclsInScope.contains(D); }
387 
388   /// Get the entity corresponding to this scope.
getEntity()389   DeclContext *getEntity() const {
390     return isTemplateParamScope() ? nullptr : Entity;
391   }
392 
393   /// Get the DeclContext in which to continue unqualified lookup after a
394   /// lookup in this scope.
getLookupEntity()395   DeclContext *getLookupEntity() const { return Entity; }
396 
setEntity(DeclContext * E)397   void setEntity(DeclContext *E) {
398     assert(!isTemplateParamScope() &&
399            "entity associated with template param scope");
400     Entity = E;
401   }
setLookupEntity(DeclContext * E)402   void setLookupEntity(DeclContext *E) { Entity = E; }
403 
404   /// Determine whether any unrecoverable errors have occurred within this
405   /// scope. Note that this may return false even if the scope contains invalid
406   /// declarations or statements, if the errors for those invalid constructs
407   /// were suppressed because some prior invalid construct was referenced.
hasUnrecoverableErrorOccurred()408   bool hasUnrecoverableErrorOccurred() const {
409     return ErrorTrap.hasUnrecoverableErrorOccurred();
410   }
411 
412   /// isFunctionScope() - Return true if this scope is a function scope.
isFunctionScope()413   bool isFunctionScope() const { return getFlags() & Scope::FnScope; }
414 
415   /// isClassScope - Return true if this scope is a class/struct/union scope.
isClassScope()416   bool isClassScope() const { return getFlags() & Scope::ClassScope; }
417 
418   /// Determines whether this scope is between inheritance colon and the real
419   /// class/struct definition.
isClassInheritanceScope()420   bool isClassInheritanceScope() const {
421     return getFlags() & Scope::ClassInheritanceScope;
422   }
423 
424   /// isInCXXInlineMethodScope - Return true if this scope is a C++ inline
425   /// method scope or is inside one.
isInCXXInlineMethodScope()426   bool isInCXXInlineMethodScope() const {
427     if (const Scope *FnS = getFnParent()) {
428       assert(FnS->getParent() && "TUScope not created?");
429       return FnS->getParent()->isClassScope();
430     }
431     return false;
432   }
433 
434   /// isInObjcMethodScope - Return true if this scope is, or is contained, in an
435   /// C function body.
isInCFunctionScope()436   bool isInCFunctionScope() const {
437     for (const Scope *S = this; S; S = S->getParent()) {
438       if (S->isFunctionScope())
439         return true;
440     }
441 
442     return false;
443   }
444 
445   /// isInObjcMethodScope - Return true if this scope is, or is contained in, an
446   /// Objective-C method body.  Note that this method is not constant time.
isInObjcMethodScope()447   bool isInObjcMethodScope() const {
448     for (const Scope *S = this; S; S = S->getParent()) {
449       // If this scope is an objc method scope, then we succeed.
450       if (S->getFlags() & ObjCMethodScope)
451         return true;
452     }
453     return false;
454   }
455 
456   /// isInObjcMethodOuterScope - Return true if this scope is an
457   /// Objective-C method outer most body.
isInObjcMethodOuterScope()458   bool isInObjcMethodOuterScope() const {
459     if (const Scope *S = this) {
460       // If this scope is an objc method scope, then we succeed.
461       if (S->getFlags() & ObjCMethodScope)
462         return true;
463     }
464     return false;
465   }
466 
467   /// isTemplateParamScope - Return true if this scope is a C++
468   /// template parameter scope.
isTemplateParamScope()469   bool isTemplateParamScope() const {
470     return getFlags() & Scope::TemplateParamScope;
471   }
472 
473   /// isFunctionPrototypeScope - Return true if this scope is a
474   /// function prototype scope.
isFunctionPrototypeScope()475   bool isFunctionPrototypeScope() const {
476     return getFlags() & Scope::FunctionPrototypeScope;
477   }
478 
479   /// isFunctionDeclarationScope - Return true if this scope is a
480   /// function prototype scope.
isFunctionDeclarationScope()481   bool isFunctionDeclarationScope() const {
482     return getFlags() & Scope::FunctionDeclarationScope;
483   }
484 
485   /// isAtCatchScope - Return true if this scope is \@catch.
isAtCatchScope()486   bool isAtCatchScope() const {
487     return getFlags() & Scope::AtCatchScope;
488   }
489 
490   /// isCatchScope - Return true if this scope is a C++ catch statement.
isCatchScope()491   bool isCatchScope() const { return getFlags() & Scope::CatchScope; }
492 
493   /// isSwitchScope - Return true if this scope is a switch scope.
isSwitchScope()494   bool isSwitchScope() const {
495     for (const Scope *S = this; S; S = S->getParent()) {
496       if (S->getFlags() & Scope::SwitchScope)
497         return true;
498       else if (S->getFlags() & (Scope::FnScope | Scope::ClassScope |
499                                 Scope::BlockScope | Scope::TemplateParamScope |
500                                 Scope::FunctionPrototypeScope |
501                                 Scope::AtCatchScope | Scope::ObjCMethodScope))
502         return false;
503     }
504     return false;
505   }
506 
507   /// Return true if this scope is a loop.
isLoopScope()508   bool isLoopScope() const {
509     // 'switch' is the only loop that is not a 'break' scope as well, so we can
510     // just check BreakScope and not SwitchScope.
511     return (getFlags() & Scope::BreakScope) &&
512            !(getFlags() & Scope::SwitchScope);
513   }
514 
515   /// Determines whether this scope is the OpenMP directive scope
isOpenMPDirectiveScope()516   bool isOpenMPDirectiveScope() const {
517     return (getFlags() & Scope::OpenMPDirectiveScope);
518   }
519 
520   /// Determine whether this scope is some OpenMP loop directive scope
521   /// (for example, 'omp for', 'omp simd').
isOpenMPLoopDirectiveScope()522   bool isOpenMPLoopDirectiveScope() const {
523     if (getFlags() & Scope::OpenMPLoopDirectiveScope) {
524       assert(isOpenMPDirectiveScope() &&
525              "OpenMP loop directive scope is not a directive scope");
526       return true;
527     }
528     return false;
529   }
530 
531   /// Determine whether this scope is (or is nested into) some OpenMP
532   /// loop simd directive scope (for example, 'omp simd', 'omp for simd').
isOpenMPSimdDirectiveScope()533   bool isOpenMPSimdDirectiveScope() const {
534     return getFlags() & Scope::OpenMPSimdDirectiveScope;
535   }
536 
537   /// Determine whether this scope is a loop having OpenMP loop
538   /// directive attached.
isOpenMPLoopScope()539   bool isOpenMPLoopScope() const {
540     const Scope *P = getParent();
541     return P && P->isOpenMPLoopDirectiveScope();
542   }
543 
544   /// Determine whether this scope is some OpenMP directive with
545   /// order clause which specifies concurrent scope.
isOpenMPOrderClauseScope()546   bool isOpenMPOrderClauseScope() const {
547     return getFlags() & Scope::OpenMPOrderClauseScope;
548   }
549 
550   /// Determine whether this scope is the statement associated with an OpenACC
551   /// Compute construct directive.
isOpenACCComputeConstructScope()552   bool isOpenACCComputeConstructScope() const {
553     return getFlags() & Scope::OpenACCComputeConstructScope;
554   }
555 
isOpenACCLoopConstructScope()556   bool isOpenACCLoopConstructScope() const {
557     return getFlags() & Scope::OpenACCLoopConstructScope;
558   }
559 
560   /// Determine if this scope (or its parents) are a compute construct. If the
561   /// argument is provided, the search will stop at any of the specified scopes.
562   /// Otherwise, it will stop only at the normal 'no longer search' scopes.
563   bool isInOpenACCComputeConstructScope(ScopeFlags Flags = NoScope) const {
564     for (const Scope *S = this; S; S = S->getParent()) {
565       if (S->isOpenACCComputeConstructScope())
566         return true;
567 
568       if (S->getFlags() & Flags)
569         return false;
570 
571       else if (S->getFlags() &
572                (Scope::FnScope | Scope::ClassScope | Scope::BlockScope |
573                 Scope::TemplateParamScope | Scope::FunctionPrototypeScope |
574                 Scope::AtCatchScope | Scope::ObjCMethodScope))
575         return false;
576     }
577     return false;
578   }
579 
580   /// Determine whether this scope is a while/do/for statement, which can have
581   /// continue statements embedded into it.
isContinueScope()582   bool isContinueScope() const {
583     return getFlags() & ScopeFlags::ContinueScope;
584   }
585 
586   /// Determine whether this scope is a C++ 'try' block.
isTryScope()587   bool isTryScope() const { return getFlags() & Scope::TryScope; }
588 
589   /// Determine whether this scope is a function-level C++ try or catch scope.
isFnTryCatchScope()590   bool isFnTryCatchScope() const {
591     return getFlags() & ScopeFlags::FnTryCatchScope;
592   }
593 
594   /// Determine whether this scope is a SEH '__try' block.
isSEHTryScope()595   bool isSEHTryScope() const { return getFlags() & Scope::SEHTryScope; }
596 
597   /// Determine whether this scope is a SEH '__except' block.
isSEHExceptScope()598   bool isSEHExceptScope() const { return getFlags() & Scope::SEHExceptScope; }
599 
600   /// Determine whether this scope is a compound statement scope.
isCompoundStmtScope()601   bool isCompoundStmtScope() const {
602     return getFlags() & Scope::CompoundStmtScope;
603   }
604 
605   /// Determine whether this scope is a controlling scope in a
606   /// if/switch/while/for statement.
isControlScope()607   bool isControlScope() const { return getFlags() & Scope::ControlScope; }
608 
609   /// Determine whether this scope is a type alias scope.
isTypeAliasScope()610   bool isTypeAliasScope() const { return getFlags() & Scope::TypeAliasScope; }
611 
612   /// Determine whether this scope is a friend scope.
isFriendScope()613   bool isFriendScope() const { return getFlags() & Scope::FriendScope; }
614 
615   /// Returns if rhs has a higher scope depth than this.
616   ///
617   /// The caller is responsible for calling this only if one of the two scopes
618   /// is an ancestor of the other.
Contains(const Scope & rhs)619   bool Contains(const Scope& rhs) const { return Depth < rhs.Depth; }
620 
621   /// containedInPrototypeScope - Return true if this or a parent scope
622   /// is a FunctionPrototypeScope.
623   bool containedInPrototypeScope() const;
624 
PushUsingDirective(UsingDirectiveDecl * UDir)625   void PushUsingDirective(UsingDirectiveDecl *UDir) {
626     UsingDirectives.push_back(UDir);
627   }
628 
629   using using_directives_range =
630       llvm::iterator_range<UsingDirectivesTy::iterator>;
631 
using_directives()632   using_directives_range using_directives() {
633     return using_directives_range(UsingDirectives.begin(),
634                                   UsingDirectives.end());
635   }
636 
637   void updateNRVOCandidate(VarDecl *VD);
638 
639   void applyNRVO();
640 
641   /// Init - This is used by the parser to implement scope caching.
642   void Init(Scope *parent, unsigned flags);
643 
644   /// Sets up the specified scope flags and adjusts the scope state
645   /// variables accordingly.
646   void AddFlags(unsigned Flags);
647 
648   void dumpImpl(raw_ostream &OS) const;
649   void dump() const;
650 };
651 
652 } // namespace clang
653 
654 #endif // LLVM_CLANG_SEMA_SCOPE_H
655