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