CompilerDecl.h revision 360660
1//===-- CompilerDecl.h ------------------------------------------*- 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#ifndef liblldb_CompilerDecl_h_ 10#define liblldb_CompilerDecl_h_ 11 12#include "lldb/Symbol/CompilerType.h" 13#include "lldb/Utility/ConstString.h" 14#include "lldb/lldb-private.h" 15 16namespace lldb_private { 17 18class CompilerDecl { 19public: 20 // Constructors and Destructors 21 CompilerDecl() : m_type_system(nullptr), m_opaque_decl(nullptr) {} 22 23 CompilerDecl(TypeSystem *type_system, void *decl) 24 : m_type_system(type_system), m_opaque_decl(decl) {} 25 26 ~CompilerDecl() {} 27 28 // Tests 29 30 explicit operator bool() const { return IsValid(); } 31 32 bool operator<(const CompilerDecl &rhs) const { 33 if (m_type_system == rhs.m_type_system) 34 return m_opaque_decl < rhs.m_opaque_decl; 35 return m_type_system < rhs.m_type_system; 36 } 37 38 bool IsValid() const { 39 return m_type_system != nullptr && m_opaque_decl != nullptr; 40 } 41 42 bool IsClang() const; 43 44 // Accessors 45 46 TypeSystem *GetTypeSystem() const { return m_type_system; } 47 48 void *GetOpaqueDecl() const { return m_opaque_decl; } 49 50 void SetDecl(TypeSystem *type_system, void *decl) { 51 m_type_system = type_system; 52 m_opaque_decl = decl; 53 } 54 55 void Clear() { 56 m_type_system = nullptr; 57 m_opaque_decl = nullptr; 58 } 59 60 ConstString GetName() const; 61 62 ConstString GetMangledName() const; 63 64 CompilerDeclContext GetDeclContext() const; 65 66 // If this decl represents a function, return the return type 67 CompilerType GetFunctionReturnType() const; 68 69 // If this decl represents a function, return the number of arguments for the 70 // function 71 size_t GetNumFunctionArguments() const; 72 73 // If this decl represents a function, return the argument type given a zero 74 // based argument index 75 CompilerType GetFunctionArgumentType(size_t arg_idx) const; 76 77private: 78 TypeSystem *m_type_system; 79 void *m_opaque_decl; 80}; 81 82bool operator==(const CompilerDecl &lhs, const CompilerDecl &rhs); 83bool operator!=(const CompilerDecl &lhs, const CompilerDecl &rhs); 84 85} // namespace lldb_private 86 87#endif // #ifndef liblldb_CompilerDecl_h_ 88