Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:42:51

0001 //===-- CompilerDeclContext.h -----------------------------------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 
0009 #ifndef LLDB_SYMBOL_COMPILERDECLCONTEXT_H
0010 #define LLDB_SYMBOL_COMPILERDECLCONTEXT_H
0011 
0012 #include <vector>
0013 
0014 #include "lldb/Symbol/Type.h"
0015 #include "lldb/Utility/ConstString.h"
0016 #include "lldb/lldb-private.h"
0017 
0018 namespace lldb_private {
0019 
0020 /// Represents a generic declaration context in a program. A declaration context
0021 /// is data structure that contains declarations (e.g. namespaces).
0022 ///
0023 /// This class serves as an abstraction for a declaration context inside one of
0024 /// the TypeSystems implemented by the language plugins. It does not have any
0025 /// actual logic in it but only stores an opaque pointer and a pointer to the
0026 /// TypeSystem that gives meaning to this opaque pointer. All methods of this
0027 /// class should call their respective method in the TypeSystem interface and
0028 /// pass the opaque pointer along.
0029 ///
0030 /// \see lldb_private::TypeSystem
0031 class CompilerDeclContext {
0032 public:
0033   /// Constructs an invalid CompilerDeclContext.
0034   CompilerDeclContext() = default;
0035 
0036   /// Constructs a CompilerDeclContext with the given opaque decl context
0037   /// and its respective TypeSystem instance.
0038   ///
0039   /// This constructor should only be called from the respective TypeSystem
0040   /// implementation.
0041   ///
0042   /// \see lldb_private::TypeSystemClang::CreateDeclContext(clang::DeclContext*)
0043   CompilerDeclContext(TypeSystem *type_system, void *decl_ctx)
0044       : m_type_system(type_system), m_opaque_decl_ctx(decl_ctx) {}
0045 
0046   // Tests
0047 
0048   explicit operator bool() const { return IsValid(); }
0049 
0050   bool operator<(const CompilerDeclContext &rhs) const {
0051     if (m_type_system == rhs.m_type_system)
0052       return m_opaque_decl_ctx < rhs.m_opaque_decl_ctx;
0053     return m_type_system < rhs.m_type_system;
0054   }
0055 
0056   bool IsValid() const {
0057     return m_type_system != nullptr && m_opaque_decl_ctx != nullptr;
0058   }
0059 
0060   /// Populate a valid compiler context from the current decl context.
0061   ///
0062   /// \returns A valid vector of CompilerContext entries that describes
0063   /// this declaration context. The first entry in the vector is the parent of
0064   /// the subsequent entry, so the topmost entry is the global namespace.
0065   std::vector<lldb_private::CompilerContext> GetCompilerContext() const;
0066 
0067   std::vector<CompilerDecl> FindDeclByName(ConstString name,
0068                                            const bool ignore_using_decls);
0069 
0070   /// Checks if this decl context represents a method of a class.
0071   ///
0072   /// \return
0073   ///     Returns true if this is a decl context that represents a method
0074   ///     in a struct, union or class.
0075   bool IsClassMethod();
0076 
0077   /// Determines the original language of the decl context.
0078   lldb::LanguageType GetLanguage();
0079 
0080   /// Check if the given other decl context is contained in the lookup
0081   /// of this decl context (for example because the other context is a nested
0082   /// inline namespace).
0083   ///
0084   /// @param[in] other
0085   ///     The other decl context for which we should check if it is contained
0086   ///     in the lookoup of this context.
0087   ///
0088   /// @return
0089   ///     Returns true iff the other decl context is contained in the lookup
0090   ///     of this decl context.
0091   bool IsContainedInLookup(CompilerDeclContext other) const;
0092 
0093   // Accessors
0094 
0095   TypeSystem *GetTypeSystem() const { return m_type_system; }
0096 
0097   void *GetOpaqueDeclContext() const { return m_opaque_decl_ctx; }
0098 
0099   void SetDeclContext(TypeSystem *type_system, void *decl_ctx) {
0100     m_type_system = type_system;
0101     m_opaque_decl_ctx = decl_ctx;
0102   }
0103 
0104   void Clear() {
0105     m_type_system = nullptr;
0106     m_opaque_decl_ctx = nullptr;
0107   }
0108 
0109   ConstString GetName() const;
0110 
0111   ConstString GetScopeQualifiedName() const;
0112 
0113 private:
0114   TypeSystem *m_type_system = nullptr;
0115   void *m_opaque_decl_ctx = nullptr;
0116 };
0117 
0118 bool operator==(const CompilerDeclContext &lhs, const CompilerDeclContext &rhs);
0119 bool operator!=(const CompilerDeclContext &lhs, const CompilerDeclContext &rhs);
0120 
0121 } // namespace lldb_private
0122 
0123 #endif // LLDB_SYMBOL_COMPILERDECLCONTEXT_H