Andrew Walbran | 3d2c197 | 2020-04-07 12:24:26 +0100 | [diff] [blame] | 1 | //===-- CompilerDeclContext.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_CompilerDeclContext_h_ |
| 10 | #define liblldb_CompilerDeclContext_h_ |
| 11 | |
| 12 | #include <vector> |
| 13 | |
| 14 | #include "lldb/Utility/ConstString.h" |
| 15 | #include "lldb/lldb-private.h" |
| 16 | |
| 17 | namespace lldb_private { |
| 18 | |
| 19 | class CompilerDeclContext { |
| 20 | public: |
| 21 | // Constructors and Destructors |
| 22 | CompilerDeclContext() : m_type_system(nullptr), m_opaque_decl_ctx(nullptr) {} |
| 23 | |
| 24 | CompilerDeclContext(TypeSystem *type_system, void *decl_ctx) |
| 25 | : m_type_system(type_system), m_opaque_decl_ctx(decl_ctx) {} |
| 26 | |
| 27 | ~CompilerDeclContext() {} |
| 28 | |
| 29 | // Tests |
| 30 | |
| 31 | explicit operator bool() const { return IsValid(); } |
| 32 | |
| 33 | bool operator<(const CompilerDeclContext &rhs) const { |
| 34 | if (m_type_system == rhs.m_type_system) |
| 35 | return m_opaque_decl_ctx < rhs.m_opaque_decl_ctx; |
| 36 | return m_type_system < rhs.m_type_system; |
| 37 | } |
| 38 | |
| 39 | bool IsValid() const { |
| 40 | return m_type_system != nullptr && m_opaque_decl_ctx != nullptr; |
| 41 | } |
| 42 | |
| 43 | bool IsClang() const; |
| 44 | |
| 45 | std::vector<CompilerDecl> FindDeclByName(ConstString name, |
| 46 | const bool ignore_using_decls); |
| 47 | |
| 48 | /// Checks if this decl context represents a method of a class. |
| 49 | /// |
| 50 | /// \param[out] language_ptr |
| 51 | /// If non NULL and \b true is returned from this function, |
| 52 | /// this will indicate if the language that respresents the method. |
| 53 | /// |
| 54 | /// \param[out] is_instance_method_ptr |
| 55 | /// If non NULL and \b true is returned from this function, |
| 56 | /// this will indicate if the method is an instance function (true) |
| 57 | /// or a class method (false indicating the function is static, or |
| 58 | /// doesn't require an instance of the class to be called). |
| 59 | /// |
| 60 | /// \param[out] language_object_name_ptr |
| 61 | /// If non NULL and \b true is returned from this function, |
| 62 | /// this will indicate if implicit object name for the language |
| 63 | /// like "this" for C++, and "self" for Objective C. |
| 64 | /// |
| 65 | /// \return |
| 66 | /// Returns true if this is a decl context that represents a method |
| 67 | /// in a struct, union or class. |
| 68 | bool IsClassMethod(lldb::LanguageType *language_ptr, |
| 69 | bool *is_instance_method_ptr, |
| 70 | ConstString *language_object_name_ptr); |
| 71 | |
| 72 | /// Check if the given other decl context is contained in the lookup |
| 73 | /// of this decl context (for example because the other context is a nested |
| 74 | /// inline namespace). |
| 75 | /// |
| 76 | /// @param[in] other |
| 77 | /// The other decl context for which we should check if it is contained |
| 78 | /// in the lookoup of this context. |
| 79 | /// |
| 80 | /// @return |
| 81 | /// Returns true iff the other decl context is contained in the lookup |
| 82 | /// of this decl context. |
| 83 | bool IsContainedInLookup(CompilerDeclContext other) const; |
| 84 | |
| 85 | // Accessors |
| 86 | |
| 87 | TypeSystem *GetTypeSystem() const { return m_type_system; } |
| 88 | |
| 89 | void *GetOpaqueDeclContext() const { return m_opaque_decl_ctx; } |
| 90 | |
| 91 | void SetDeclContext(TypeSystem *type_system, void *decl_ctx) { |
| 92 | m_type_system = type_system; |
| 93 | m_opaque_decl_ctx = decl_ctx; |
| 94 | } |
| 95 | |
| 96 | void Clear() { |
| 97 | m_type_system = nullptr; |
| 98 | m_opaque_decl_ctx = nullptr; |
| 99 | } |
| 100 | |
| 101 | ConstString GetName() const; |
| 102 | |
| 103 | ConstString GetScopeQualifiedName() const; |
| 104 | |
| 105 | bool IsStructUnionOrClass() const; |
| 106 | |
| 107 | private: |
| 108 | TypeSystem *m_type_system; |
| 109 | void *m_opaque_decl_ctx; |
| 110 | }; |
| 111 | |
| 112 | bool operator==(const CompilerDeclContext &lhs, const CompilerDeclContext &rhs); |
| 113 | bool operator!=(const CompilerDeclContext &lhs, const CompilerDeclContext &rhs); |
| 114 | |
| 115 | } // namespace lldb_private |
| 116 | |
| 117 | #endif // #ifndef liblldb_CompilerDeclContext_h_ |