1 | //===-- ClangASTMetadata.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 LLDB_SOURCE_PLUGINS_EXPRESSIONPARSER_CLANG_CLANGASTMETADATA_H |
10 | #define LLDB_SOURCE_PLUGINS_EXPRESSIONPARSER_CLANG_CLANGASTMETADATA_H |
11 | |
12 | #include "lldb/Core/dwarf.h" |
13 | #include "lldb/lldb-defines.h" |
14 | #include "lldb/lldb-enumerations.h" |
15 | #include "lldb/lldb-private-enumerations.h" |
16 | |
17 | namespace lldb_private { |
18 | |
19 | class ClangASTMetadata { |
20 | public: |
21 | ClangASTMetadata() |
22 | : m_user_id(0), m_union_is_user_id(false), m_union_is_isa_ptr(false), |
23 | m_has_object_ptr(false), m_is_self(false), |
24 | m_is_forcefully_completed(false) { |
25 | SetIsDynamicCXXType(std::nullopt); |
26 | } |
27 | |
28 | std::optional<bool> GetIsDynamicCXXType() const; |
29 | |
30 | void SetIsDynamicCXXType(std::optional<bool> b); |
31 | |
32 | void SetUserID(lldb::user_id_t user_id) { |
33 | m_user_id = user_id; |
34 | m_union_is_user_id = true; |
35 | m_union_is_isa_ptr = false; |
36 | } |
37 | |
38 | lldb::user_id_t GetUserID() const { |
39 | if (m_union_is_user_id) |
40 | return m_user_id; |
41 | else |
42 | return LLDB_INVALID_UID; |
43 | } |
44 | |
45 | void SetISAPtr(uint64_t isa_ptr) { |
46 | m_isa_ptr = isa_ptr; |
47 | m_union_is_user_id = false; |
48 | m_union_is_isa_ptr = true; |
49 | } |
50 | |
51 | uint64_t GetISAPtr() const { |
52 | if (m_union_is_isa_ptr) |
53 | return m_isa_ptr; |
54 | else |
55 | return 0; |
56 | } |
57 | |
58 | void SetObjectPtrName(const char *name) { |
59 | m_has_object_ptr = true; |
60 | if (strcmp(s1: name, s2: "self" ) == 0) |
61 | m_is_self = true; |
62 | else if (strcmp(s1: name, s2: "this" ) == 0) |
63 | m_is_self = false; |
64 | else |
65 | m_has_object_ptr = false; |
66 | } |
67 | |
68 | lldb::LanguageType GetObjectPtrLanguage() const { |
69 | if (m_has_object_ptr) { |
70 | if (m_is_self) |
71 | return lldb::eLanguageTypeObjC; |
72 | else |
73 | return lldb::eLanguageTypeC_plus_plus; |
74 | } |
75 | return lldb::eLanguageTypeUnknown; |
76 | } |
77 | |
78 | const char *GetObjectPtrName() const { |
79 | if (m_has_object_ptr) { |
80 | if (m_is_self) |
81 | return "self" ; |
82 | else |
83 | return "this" ; |
84 | } else |
85 | return nullptr; |
86 | } |
87 | |
88 | bool HasObjectPtr() const { return m_has_object_ptr; } |
89 | |
90 | /// A type is "forcefully completed" if it was declared complete to satisfy an |
91 | /// AST invariant (e.g. base classes must be complete types), but in fact we |
92 | /// were not able to find a actual definition for it. |
93 | bool IsForcefullyCompleted() const { return m_is_forcefully_completed; } |
94 | |
95 | void SetIsForcefullyCompleted(bool value = true) { |
96 | m_is_forcefully_completed = true; |
97 | } |
98 | |
99 | void Dump(Stream *s); |
100 | |
101 | private: |
102 | union { |
103 | lldb::user_id_t m_user_id; |
104 | uint64_t m_isa_ptr; |
105 | }; |
106 | |
107 | unsigned m_union_is_user_id : 1, m_union_is_isa_ptr : 1, m_has_object_ptr : 1, |
108 | m_is_self : 1, m_is_dynamic_cxx : 2, m_is_forcefully_completed : 1; |
109 | }; |
110 | |
111 | } // namespace lldb_private |
112 | |
113 | #endif // LLDB_SOURCE_PLUGINS_EXPRESSIONPARSER_CLANG_CLANGASTMETADATA_H |
114 | |