diff options
Diffstat (limited to 'include/clang/Sema/Scope.h')
-rw-r--r-- | include/clang/Sema/Scope.h | 100 |
1 files changed, 51 insertions, 49 deletions
diff --git a/include/clang/Sema/Scope.h b/include/clang/Sema/Scope.h index cd58a9910f98..a3379ff34f12 100644 --- a/include/clang/Sema/Scope.h +++ b/include/clang/Sema/Scope.h @@ -1,4 +1,4 @@ -//===--- Scope.h - Scope interface ------------------------------*- C++ -*-===// +//===- Scope.h - Scope interface --------------------------------*- C++ -*-===// // // The LLVM Compiler Infrastructure // @@ -14,101 +14,102 @@ #ifndef LLVM_CLANG_SEMA_SCOPE_H #define LLVM_CLANG_SEMA_SCOPE_H -#include "clang/AST/Decl.h" #include "clang/Basic/Diagnostic.h" #include "llvm/ADT/PointerIntPair.h" #include "llvm/ADT/SmallPtrSet.h" #include "llvm/ADT/SmallVector.h" +#include "llvm/ADT/iterator_range.h" +#include <cassert> namespace llvm { class raw_ostream; -} +} // namespace llvm namespace clang { class Decl; +class DeclContext; class UsingDirectiveDecl; class VarDecl; /// Scope - A scope is a transient data structure that is used while parsing the /// program. It assists with resolving identifiers to the appropriate /// declaration. -/// class Scope { public: /// ScopeFlags - These are bitfields that are or'd together when creating a /// scope, which defines the sorts of things the scope contains. enum ScopeFlags { - /// \brief This indicates that the scope corresponds to a function, which + /// This indicates that the scope corresponds to a function, which /// means that labels are set here. FnScope = 0x01, - /// \brief This is a while, do, switch, for, etc that can have break + /// This is a while, do, switch, for, etc that can have break /// statements embedded into it. BreakScope = 0x02, - /// \brief This is a while, do, for, which can have continue statements + /// This is a while, do, for, which can have continue statements /// embedded into it. ContinueScope = 0x04, - /// \brief This is a scope that can contain a declaration. Some scopes + /// This is a scope that can contain a declaration. Some scopes /// just contain loop constructs but don't contain decls. DeclScope = 0x08, - /// \brief The controlling scope in a if/switch/while/for statement. + /// The controlling scope in a if/switch/while/for statement. ControlScope = 0x10, - /// \brief The scope of a struct/union/class definition. + /// The scope of a struct/union/class definition. ClassScope = 0x20, - /// \brief This is a scope that corresponds to a block/closure object. + /// This is a scope that corresponds to a block/closure object. /// Blocks serve as top-level scopes for some objects like labels, they /// also prevent things like break and continue. BlockScopes always have /// the FnScope and DeclScope flags set as well. BlockScope = 0x40, - /// \brief This is a scope that corresponds to the + /// This is a scope that corresponds to the /// template parameters of a C++ template. Template parameter /// scope starts at the 'template' keyword and ends when the /// template declaration ends. TemplateParamScope = 0x80, - /// \brief This is a scope that corresponds to the + /// This is a scope that corresponds to the /// parameters within a function prototype. FunctionPrototypeScope = 0x100, - /// \brief This is a scope that corresponds to the parameters within + /// This is a scope that corresponds to the parameters within /// a function prototype for a function declaration (as opposed to any /// other kind of function declarator). Always has FunctionPrototypeScope /// set as well. FunctionDeclarationScope = 0x200, - /// \brief This is a scope that corresponds to the Objective-C + /// This is a scope that corresponds to the Objective-C /// \@catch statement. AtCatchScope = 0x400, - /// \brief This scope corresponds to an Objective-C method body. + /// This scope corresponds to an Objective-C method body. /// It always has FnScope and DeclScope set as well. ObjCMethodScope = 0x800, - /// \brief This is a scope that corresponds to a switch statement. + /// This is a scope that corresponds to a switch statement. SwitchScope = 0x1000, - /// \brief This is the scope of a C++ try statement. + /// This is the scope of a C++ try statement. TryScope = 0x2000, - /// \brief This is the scope for a function-level C++ try or catch scope. + /// This is the scope for a function-level C++ try or catch scope. FnTryCatchScope = 0x4000, - /// \brief This is the scope of OpenMP executable directive. + /// This is the scope of OpenMP executable directive. OpenMPDirectiveScope = 0x8000, - /// \brief This is the scope of some OpenMP loop directive. + /// This is the scope of some OpenMP loop directive. OpenMPLoopDirectiveScope = 0x10000, - /// \brief This is the scope of some OpenMP simd directive. + /// This is the scope of some OpenMP simd directive. /// For example, it is used for 'omp simd', 'omp for simd'. /// This flag is propagated to children scopes. OpenMPSimdDirectiveScope = 0x20000, @@ -131,6 +132,7 @@ public: /// We are between inheritance colon and the real class/struct definition scope. ClassInheritanceScope = 0x800000, }; + private: /// The parent scope for this scope. This is null for the translation-unit /// scope. @@ -144,7 +146,7 @@ private: /// depth 0. unsigned short Depth; - /// \brief Declarations with static linkage are mangled with the number of + /// Declarations with static linkage are mangled with the number of /// scopes seen as a component. unsigned short MSLastManglingNumber; @@ -185,7 +187,7 @@ private: /// popped, these declarations are removed from the IdentifierTable's notion /// of current declaration. It is up to the current Action implementation to /// implement these semantics. - typedef llvm::SmallPtrSet<Decl *, 32> DeclSetTy; + using DeclSetTy = llvm::SmallPtrSet<Decl *, 32>; DeclSetTy DeclsInScope; /// The DeclContext with which this scope is associated. For @@ -193,10 +195,10 @@ private: /// entity of a function scope is a function, etc. DeclContext *Entity; - typedef SmallVector<UsingDirectiveDecl *, 2> UsingDirectivesTy; + using UsingDirectivesTy = SmallVector<UsingDirectiveDecl *, 2>; UsingDirectivesTy UsingDirectives; - /// \brief Used to determine if errors occurred in this scope. + /// Used to determine if errors occurred in this scope. DiagnosticErrorTrap ErrorTrap; /// A lattice consisting of undefined, a single NRVO candidate variable in @@ -207,25 +209,23 @@ private: public: Scope(Scope *Parent, unsigned ScopeFlags, DiagnosticsEngine &Diag) - : ErrorTrap(Diag) { + : ErrorTrap(Diag) { Init(Parent, ScopeFlags); } /// getFlags - Return the flags for this scope. - /// unsigned getFlags() const { return Flags; } + void setFlags(unsigned F) { setFlags(getParent(), F); } /// isBlockScope - Return true if this scope correspond to a closure. bool isBlockScope() const { return Flags & BlockScope; } /// getParent - Return the scope that this is nested in. - /// const Scope *getParent() const { return AnyParent; } Scope *getParent() { return AnyParent; } /// getFnParent - Return the closest scope that is a function body. - /// const Scope *getFnParent() const { return FnParent; } Scope *getFnParent() { return FnParent; } @@ -259,6 +259,9 @@ public: Scope *getTemplateParamParent() { return TemplateParamParent; } const Scope *getTemplateParamParent() const { return TemplateParamParent; } + /// Returns the depth of this scope. The translation-unit has scope depth 0. + unsigned getDepth() const { return Depth; } + /// Returns the number of function prototype scopes in this scope /// chain. unsigned getFunctionPrototypeDepth() const { @@ -272,10 +275,12 @@ public: return PrototypeIndex++; } - typedef llvm::iterator_range<DeclSetTy::iterator> decl_range; + using decl_range = llvm::iterator_range<DeclSetTy::iterator>; + decl_range decls() const { return decl_range(DeclsInScope.begin(), DeclsInScope.end()); } + bool decl_empty() const { return DeclsInScope.empty(); } void AddDecl(Decl *D) { @@ -365,7 +370,6 @@ public: return false; } - /// isTemplateParamScope - Return true if this scope is a C++ /// template parameter scope. bool isTemplateParamScope() const { @@ -397,12 +401,12 @@ public: return false; } - /// \brief Determines whether this scope is the OpenMP directive scope + /// Determines whether this scope is the OpenMP directive scope bool isOpenMPDirectiveScope() const { return (getFlags() & Scope::OpenMPDirectiveScope); } - /// \brief Determine whether this scope is some OpenMP loop directive scope + /// Determine whether this scope is some OpenMP loop directive scope /// (for example, 'omp for', 'omp simd'). bool isOpenMPLoopDirectiveScope() const { if (getFlags() & Scope::OpenMPLoopDirectiveScope) { @@ -413,34 +417,34 @@ public: return false; } - /// \brief Determine whether this scope is (or is nested into) some OpenMP + /// Determine whether this scope is (or is nested into) some OpenMP /// loop simd directive scope (for example, 'omp simd', 'omp for simd'). bool isOpenMPSimdDirectiveScope() const { return getFlags() & Scope::OpenMPSimdDirectiveScope; } - /// \brief Determine whether this scope is a loop having OpenMP loop + /// Determine whether this scope is a loop having OpenMP loop /// directive attached. bool isOpenMPLoopScope() const { const Scope *P = getParent(); return P && P->isOpenMPLoopDirectiveScope(); } - /// \brief Determine whether this scope is a C++ 'try' block. + /// Determine whether this scope is a C++ 'try' block. bool isTryScope() const { return getFlags() & Scope::TryScope; } - /// \brief Determine whether this scope is a SEH '__try' block. + /// Determine whether this scope is a SEH '__try' block. bool isSEHTryScope() const { return getFlags() & Scope::SEHTryScope; } - /// \brief Determine whether this scope is a SEH '__except' block. + /// Determine whether this scope is a SEH '__except' block. bool isSEHExceptScope() const { return getFlags() & Scope::SEHExceptScope; } - /// \brief Determine whether this scope is a compound statement scope. + /// Determine whether this scope is a compound statement scope. bool isCompoundStmtScope() const { return getFlags() & Scope::CompoundStmtScope; } - /// \brief Returns if rhs has a higher scope depth than this. + /// Returns if rhs has a higher scope depth than this. /// /// The caller is responsible for calling this only if one of the two scopes /// is an ancestor of the other. @@ -454,8 +458,8 @@ public: UsingDirectives.push_back(UDir); } - typedef llvm::iterator_range<UsingDirectivesTy::iterator> - using_directives_range; + using using_directives_range = + llvm::iterator_range<UsingDirectivesTy::iterator>; using_directives_range using_directives() { return using_directives_range(UsingDirectives.begin(), @@ -474,25 +478,23 @@ public: } void setNoNRVO() { - NRVO.setInt(1); + NRVO.setInt(true); NRVO.setPointer(nullptr); } void mergeNRVOIntoParent(); /// Init - This is used by the parser to implement scope caching. - /// void Init(Scope *parent, unsigned flags); - /// \brief Sets up the specified scope flags and adjusts the scope state + /// Sets up the specified scope flags and adjusts the scope state /// variables accordingly. - /// void AddFlags(unsigned Flags); void dumpImpl(raw_ostream &OS) const; void dump() const; }; -} // end namespace clang +} // namespace clang -#endif +#endif // LLVM_CLANG_SEMA_SCOPE_H |