Back to home page

EIC code displayed by LXR

 
 

    


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

0001 //===-- CompilerDecl.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_COMPILERDECL_H
0010 #define LLDB_SYMBOL_COMPILERDECL_H
0011 
0012 #include "lldb/Symbol/CompilerType.h"
0013 #include "lldb/Utility/ConstString.h"
0014 #include "lldb/lldb-private.h"
0015 
0016 namespace lldb_private {
0017 
0018 /// Represents a generic declaration such as a function declaration.
0019 ///
0020 /// This class serves as an abstraction for a declaration inside one of the
0021 /// TypeSystems implemented by the language plugins. It does not have any actual
0022 /// logic in it but only stores an opaque pointer and a pointer to the
0023 /// TypeSystem that gives meaning to this opaque pointer. All methods of this
0024 /// class should call their respective method in the TypeSystem interface and
0025 /// pass the opaque pointer along.
0026 ///
0027 /// \see lldb_private::TypeSystem
0028 class CompilerDecl {
0029 public:
0030   // Constructors and Destructors
0031   CompilerDecl() = default;
0032 
0033   /// Creates a CompilerDecl with the given TypeSystem and opaque pointer.
0034   ///
0035   /// This constructor should only be called from the respective TypeSystem
0036   /// implementation.
0037   CompilerDecl(TypeSystem *type_system, void *decl)
0038       : m_type_system(type_system), m_opaque_decl(decl) {}
0039 
0040   // Tests
0041 
0042   explicit operator bool() const { return IsValid(); }
0043 
0044   bool operator<(const CompilerDecl &rhs) const {
0045     if (m_type_system == rhs.m_type_system)
0046       return m_opaque_decl < rhs.m_opaque_decl;
0047     return m_type_system < rhs.m_type_system;
0048   }
0049 
0050   bool IsValid() const {
0051     return m_type_system != nullptr && m_opaque_decl != nullptr;
0052   }
0053 
0054   // Accessors
0055 
0056   TypeSystem *GetTypeSystem() const { return m_type_system; }
0057 
0058   void *GetOpaqueDecl() const { return m_opaque_decl; }
0059 
0060   void SetDecl(TypeSystem *type_system, void *decl) {
0061     m_type_system = type_system;
0062     m_opaque_decl = decl;
0063   }
0064 
0065   void Clear() {
0066     m_type_system = nullptr;
0067     m_opaque_decl = nullptr;
0068   }
0069 
0070   ConstString GetName() const;
0071 
0072   ConstString GetMangledName() const;
0073 
0074   CompilerDeclContext GetDeclContext() const;
0075 
0076   // If this decl has a type, return it.
0077   CompilerType GetType() const;
0078 
0079   // If this decl represents a function, return the return type
0080   CompilerType GetFunctionReturnType() const;
0081 
0082   // If this decl represents a function, return the number of arguments for the
0083   // function
0084   size_t GetNumFunctionArguments() const;
0085 
0086   // If this decl represents a function, return the argument type given a zero
0087   // based argument index
0088   CompilerType GetFunctionArgumentType(size_t arg_idx) const;
0089 
0090   /// Populate a valid compiler context from the current declaration.
0091   ///
0092   /// \returns A valid vector of CompilerContext entries that describes
0093   /// this declaration. The first entry in the vector is the parent of
0094   /// the subsequent entry, so the topmost entry is the global namespace.
0095   std::vector<lldb_private::CompilerContext> GetCompilerContext() const;
0096 
0097   // If decl represents a constant value, return it. Otherwise, return an
0098   // invalid/empty Scalar.
0099   Scalar GetConstantValue() const;
0100 
0101 private:
0102   TypeSystem *m_type_system = nullptr;
0103   void *m_opaque_decl = nullptr;
0104 };
0105 
0106 bool operator==(const CompilerDecl &lhs, const CompilerDecl &rhs);
0107 bool operator!=(const CompilerDecl &lhs, const CompilerDecl &rhs);
0108 
0109 } // namespace lldb_private
0110 
0111 #endif // LLDB_SYMBOL_COMPILERDECL_H