summaryrefslogtreecommitdiff
path: root/source/Symbol
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2015-12-30 11:55:28 +0000
committerDimitry Andric <dim@FreeBSD.org>2015-12-30 11:55:28 +0000
commite81d9d49145e432d917eea3a70d2ae74dcad1d89 (patch)
tree9ed5e1a91f242e2cb5911577356e487a55c01b78 /source/Symbol
parent85d8ef8f1f0e0e063a8571944302be2d2026f823 (diff)
Notes
Diffstat (limited to 'source/Symbol')
-rw-r--r--source/Symbol/ArmUnwindInfo.cpp445
-rw-r--r--source/Symbol/Block.cpp33
-rw-r--r--source/Symbol/ClangASTContext.cpp8450
-rw-r--r--source/Symbol/ClangASTImporter.cpp130
-rw-r--r--source/Symbol/ClangASTType.cpp7057
-rw-r--r--source/Symbol/ClangExternalASTSourceCallbacks.cpp14
-rw-r--r--source/Symbol/ClangNamespaceDecl.cpp25
-rw-r--r--source/Symbol/CompactUnwindInfo.cpp10
-rw-r--r--source/Symbol/CompileUnit.cpp55
-rw-r--r--source/Symbol/CompilerDecl.cpp76
-rw-r--r--source/Symbol/CompilerDeclContext.cpp75
-rw-r--r--source/Symbol/CompilerType.cpp1320
-rw-r--r--source/Symbol/DWARFCallFrameInfo.cpp6
-rw-r--r--source/Symbol/DebugMacros.cpp65
-rw-r--r--source/Symbol/FuncUnwinders.cpp43
-rw-r--r--source/Symbol/Function.cpp78
-rw-r--r--source/Symbol/GoASTContext.cpp1519
-rw-r--r--source/Symbol/LineEntry.cpp39
-rw-r--r--source/Symbol/LineTable.cpp14
-rw-r--r--source/Symbol/ObjectFile.cpp50
-rw-r--r--source/Symbol/SymbolContext.cpp175
-rw-r--r--source/Symbol/SymbolFile.cpp69
-rw-r--r--source/Symbol/SymbolVendor.cpp51
-rw-r--r--source/Symbol/Symtab.cpp10
-rw-r--r--source/Symbol/Type.cpp370
-rw-r--r--source/Symbol/TypeList.cpp73
-rw-r--r--source/Symbol/TypeMap.cpp322
-rw-r--r--source/Symbol/TypeSystem.cpp255
-rw-r--r--source/Symbol/UnwindTable.cpp36
-rw-r--r--source/Symbol/Variable.cpp106
-rw-r--r--source/Symbol/VariableList.cpp18
31 files changed, 13189 insertions, 7800 deletions
diff --git a/source/Symbol/ArmUnwindInfo.cpp b/source/Symbol/ArmUnwindInfo.cpp
new file mode 100644
index 0000000000000..0d3e974bebbe4
--- /dev/null
+++ b/source/Symbol/ArmUnwindInfo.cpp
@@ -0,0 +1,445 @@
+//===-- ArmUnwindInfo.cpp ---------------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include <vector>
+
+#include "lldb/Core/Module.h"
+#include "lldb/Core/Section.h"
+#include "lldb/Host/Endian.h"
+#include "lldb/Symbol/ArmUnwindInfo.h"
+#include "lldb/Symbol/SymbolVendor.h"
+#include "lldb/Symbol/UnwindPlan.h"
+#include "Utility/ARM_DWARF_Registers.h"
+
+/*
+ * Unwind information reader and parser for the ARM exception handling ABI
+ *
+ * Implemented based on:
+ * Exception Handling ABI for the ARM Architecture
+ * Document number: ARM IHI 0038A (current through ABI r2.09)
+ * Date of Issue: 25th January 2007, reissued 30th November 2012
+ * http://infocenter.arm.com/help/topic/com.arm.doc.ihi0038a/IHI0038A_ehabi.pdf
+ */
+
+using namespace lldb;
+using namespace lldb_private;
+
+// Converts a prel31 avlue to lldb::addr_t with sign extension
+static addr_t
+Prel31ToAddr(uint32_t prel31)
+{
+ addr_t res = prel31;
+ if (prel31 & (1<<30))
+ res |= 0xffffffff80000000ULL;
+ return res;
+}
+
+ArmUnwindInfo::ArmExidxEntry::ArmExidxEntry(uint32_t f, lldb::addr_t a, uint32_t d) :
+ file_address(f), address(a), data(d)
+{
+}
+
+bool
+ArmUnwindInfo::ArmExidxEntry::operator<(const ArmExidxEntry& other) const
+{
+ return address < other.address;
+}
+
+ArmUnwindInfo::ArmUnwindInfo(const ObjectFile& objfile,
+ SectionSP& arm_exidx,
+ SectionSP& arm_extab) :
+ m_byte_order(objfile.GetByteOrder()),
+ m_arm_exidx_sp(arm_exidx),
+ m_arm_extab_sp(arm_extab)
+{
+ objfile.ReadSectionData(arm_exidx.get(), m_arm_exidx_data);
+ objfile.ReadSectionData(arm_extab.get(), m_arm_extab_data);
+
+ addr_t exidx_base_addr = m_arm_exidx_sp->GetFileAddress();
+
+ offset_t offset = 0;
+ while (m_arm_exidx_data.ValidOffset(offset))
+ {
+ lldb::addr_t file_addr = exidx_base_addr + offset;
+ lldb::addr_t addr = exidx_base_addr +
+ (addr_t)offset +
+ Prel31ToAddr(m_arm_exidx_data.GetU32(&offset));
+ uint32_t data = m_arm_exidx_data.GetU32(&offset);
+ m_exidx_entries.emplace_back(file_addr, addr, data);
+ }
+
+ // Sort the entries in the exidx section. The entries should be sorted inside the section but
+ // some old compiler isn't sorted them.
+ std::sort(m_exidx_entries.begin(), m_exidx_entries.end());
+}
+
+ArmUnwindInfo::~ArmUnwindInfo()
+{
+}
+
+// Read a byte from the unwind instruction stream with the given offset.
+// Custom function is required because have to red in order of significance within their containing
+// word (most significant byte first) and in increasing word address order.
+uint8_t
+ArmUnwindInfo::GetByteAtOffset(const uint32_t* data, uint16_t offset) const
+{
+ uint32_t value = data[offset / 4];
+ if (m_byte_order != endian::InlHostByteOrder())
+ value = llvm::ByteSwap_32(value);
+ return (value >> ((3 - (offset % 4)) * 8)) & 0xff;
+}
+
+uint64_t
+ArmUnwindInfo::GetULEB128(const uint32_t* data, uint16_t& offset, uint16_t max_offset) const
+{
+ uint64_t result = 0;
+ uint8_t shift = 0;
+ while (offset < max_offset)
+ {
+ uint8_t byte = GetByteAtOffset(data, offset++);
+ result |= (byte & 0x7f) << shift;
+ if ((byte & 0x80) == 0)
+ break;
+ shift += 7;
+ }
+ return result;
+}
+
+bool
+ArmUnwindInfo::GetUnwindPlan(Target &target, const Address& addr, UnwindPlan& unwind_plan)
+{
+ const uint32_t* data = (const uint32_t*)GetExceptionHandlingTableEntry(addr);
+ if (data == nullptr)
+ return false; // No unwind information for the function
+
+ if (data[0] == 0x1)
+ return false; // EXIDX_CANTUNWIND
+
+ uint16_t byte_count = 0;
+ uint16_t byte_offset = 0;
+ if (data[0] & 0x80000000)
+ {
+ switch ((data[0] >> 24) & 0x0f)
+ {
+ case 0:
+ byte_count = 4;
+ byte_offset = 1;
+ break;
+ case 1:
+ case 2:
+ byte_count = 4 * ((data[0] >> 16) & 0xff) + 4;
+ byte_offset = 2;
+ break;
+ default:
+ // Unhandled personality routine index
+ return false;
+ }
+ }
+ else
+ {
+ byte_count = 4 * ((data[1] >> 24) & 0xff) + 8;
+ byte_offset = 5;
+ }
+
+ uint8_t vsp_reg = dwarf_sp;
+ int32_t vsp = 0;
+ std::vector<std::pair<uint32_t, int32_t>> register_offsets; // register -> (offset from vsp_reg)
+
+ while (byte_offset < byte_count)
+ {
+ uint8_t byte1 = GetByteAtOffset(data, byte_offset++);
+ if ((byte1&0xc0) == 0x00)
+ {
+ // 00xxxxxx
+ // vsp = vsp + (xxxxxx << 2) + 4. Covers range 0x04-0x100 inclusive
+ vsp += ((byte1 & 0x3f) << 2) + 4;
+ }
+ else if ((byte1&0xc0) == 0x40)
+ {
+ // 01xxxxxx
+ // vsp = vsp – (xxxxxx << 2) - 4. Covers range 0x04-0x100 inclusive
+ vsp -= ((byte1 & 0x3f) << 2) + 4;
+ }
+ else if ((byte1&0xf0) == 0x80)
+ {
+ if (byte_offset >= byte_count)
+ return false;
+
+ uint8_t byte2 = GetByteAtOffset(data, byte_offset++);
+ if (byte1 == 0x80 && byte2 == 0)
+ {
+ // 10000000 00000000
+ // Refuse to unwind (for example, out of a cleanup) (see remark a)
+ return false;
+ }
+ else
+ {
+ // 1000iiii iiiiiiii (i not all 0)
+ // Pop up to 12 integer registers under masks {r15-r12}, {r11-r4} (see remark b)
+ uint16_t regs = ((byte1&0x0f) << 8) | byte2;
+ for (uint8_t i = 0; i < 12; ++i)
+ {
+ if (regs & (1<<i))
+ {
+ register_offsets.emplace_back(dwarf_r4 + i, vsp);
+ vsp += 4;
+ }
+ }
+ }
+ }
+ else if ((byte1&0xff) == 0x9d)
+ {
+ // 10011101
+ // Reserved as prefix for ARM register to register moves
+ return false;
+ }
+ else if ((byte1&0xff) == 0x9f)
+ {
+ // 10011111
+ // Reserved as prefix for Intel Wireless MMX register to register moves
+ return false;
+ }
+ else if ((byte1&0xf0) == 0x90)
+ {
+ // 1001nnnn (nnnn != 13,15)
+ // Set vsp = r[nnnn]
+ vsp_reg = dwarf_r0 + (byte1&0x0f);
+ }
+ else if ((byte1&0xf8) == 0xa0)
+ {
+ // 10100nnn
+ // Pop r4-r[4+nnn]
+ uint8_t n = byte1&0x7;
+ for (uint8_t i = 0; i <= n; ++i)
+ {
+ register_offsets.emplace_back(dwarf_r4 + i, vsp);
+ vsp += 4;
+ }
+ }
+ else if ((byte1&0xf8) == 0xa8)
+ {
+ // 10101nnn
+ // Pop r4-r[4+nnn], r14
+ uint8_t n = byte1&0x7;
+ for (uint8_t i = 0; i <= n; ++i)
+ {
+ register_offsets.emplace_back(dwarf_r4 + i, vsp);
+ vsp += 4;
+ }
+
+ register_offsets.emplace_back(dwarf_lr, vsp);
+ vsp += 4;
+ }
+ else if ((byte1&0xff) == 0xb0)
+ {
+ // 10110000
+ // Finish (see remark c)
+ break;
+ }
+ else if ((byte1&0xff) == 0xb1)
+ {
+ if (byte_offset >= byte_count)
+ return false;
+
+ uint8_t byte2 = GetByteAtOffset(data, byte_offset++);
+ if ((byte2&0xff) == 0x00)
+ {
+ // 10110001 00000000
+ // Spare (see remark f)
+ return false;
+ }
+ else if ((byte2&0xf0) == 0x00)
+ {
+ // 10110001 0000iiii (i not all 0)
+ // Pop integer registers under mask {r3, r2, r1, r0}
+ for (uint8_t i = 0; i < 4; ++i)
+ {
+ if (byte2 & (1<<i))
+ {
+ register_offsets.emplace_back(dwarf_r0 + i, vsp);
+ vsp += 4;
+ }
+ }
+ }
+ else
+ {
+ // 10110001 xxxxyyyy
+ // Spare (xxxx != 0000)
+ return false;
+ }
+ }
+ else if ((byte1&0xff) == 0xb2)
+ {
+ // 10110010 uleb128
+ // vsp = vsp + 0x204+ (uleb128 << 2)
+ uint64_t uleb128 = GetULEB128(data, byte_offset, byte_count);
+ vsp += 0x204 + (uleb128 << 2);
+ }
+ else if ((byte1&0xff) == 0xb3)
+ {
+ // 10110011 sssscccc
+ // Pop VFP double-precision registers D[ssss]-D[ssss+cccc] saved (as if) by FSTMFDX (see remark d)
+ if (byte_offset >= byte_count)
+ return false;
+
+ uint8_t byte2 = GetByteAtOffset(data, byte_offset++);
+ uint8_t s = (byte2&0xf0) >> 4;
+ uint8_t c = (byte2&0x0f) >> 0;
+ for (uint8_t i = 0; i <= c; ++i)
+ {
+ register_offsets.emplace_back(dwarf_d0 + s + i, vsp);
+ vsp += 8;
+ }
+ vsp += 4;
+ }
+ else if ((byte1&0xfc) == 0xb4)
+ {
+ // 101101nn
+ // Spare (was Pop FPA)
+ return false;
+ }
+ else if ((byte1&0xf8) == 0xb8)
+ {
+ // 10111nnn
+ // Pop VFP double-precision registers D[8]-D[8+nnn] saved (as if) by FSTMFDX (see remark d)
+ uint8_t n = byte1&0x07;
+ for (uint8_t i = 0; i <= n; ++i)
+ {
+ register_offsets.emplace_back(dwarf_d8 + i, vsp);
+ vsp += 8;
+ }
+ vsp += 4;
+ }
+ else if ((byte1&0xf8) == 0xc0)
+ {
+ // 11000nnn (nnn != 6,7)
+ // Intel Wireless MMX pop wR[10]-wR[10+nnn]
+
+ // 11000110 sssscccc
+ // Intel Wireless MMX pop wR[ssss]-wR[ssss+cccc] (see remark e)
+
+ // 11000111 00000000
+ // Spare
+
+ // 11000111 0000iiii
+ // Intel Wireless MMX pop wCGR registers under mask {wCGR3,2,1,0}
+
+ // 11000111 xxxxyyyy
+ // Spare (xxxx != 0000)
+
+ return false;
+ }
+ else if ((byte1&0xff) == 0xc8)
+ {
+ // 11001000 sssscccc
+ // Pop VFP double precision registers D[16+ssss]-D[16+ssss+cccc] saved (as if) by FSTMFDD (see remarks d,e)
+ if (byte_offset >= byte_count)
+ return false;
+
+ uint8_t byte2 = GetByteAtOffset(data, byte_offset++);
+ uint8_t s = (byte2&0xf0) >> 4;
+ uint8_t c = (byte2&0x0f) >> 0;
+ for (uint8_t i = 0; i <= c; ++i)
+ {
+ register_offsets.emplace_back(dwarf_d16 + s + i, vsp);
+ vsp += 8;
+ }
+ }
+ else if ((byte1&0xff) == 0xc9)
+ {
+ // 11001001 sssscccc
+ // Pop VFP double precision registers D[ssss]-D[ssss+cccc] saved (as if) by FSTMFDD (see remark d)
+ if (byte_offset >= byte_count)
+ return false;
+
+ uint8_t byte2 = GetByteAtOffset(data, byte_offset++);
+ uint8_t s = (byte2&0xf0) >> 4;
+ uint8_t c = (byte2&0x0f) >> 0;
+ for (uint8_t i = 0; i <= c; ++i)
+ {
+ register_offsets.emplace_back(dwarf_d0 + s + i, vsp);
+ vsp += 8;
+ }
+ }
+ else if ((byte1&0xf8) == 0xc8)
+ {
+ // 11001yyy
+ // Spare (yyy != 000, 001)
+ return false;
+ }
+ else if ((byte1&0xf8) == 0xc0)
+ {
+ // 11010nnn
+ // Pop VFP double-precision registers D[8]-D[8+nnn] saved (as if) by FSTMFDD (see remark d)
+ uint8_t n = byte1&0x07;
+ for (uint8_t i = 0; i <= n; ++i)
+ {
+ register_offsets.emplace_back(dwarf_d8 + i, vsp);
+ vsp += 8;
+ }
+ }
+ else if ((byte1&0xc0) == 0xc0)
+ {
+ // 11xxxyyy Spare (xxx != 000, 001, 010)
+ return false;
+ }
+ else
+ {
+ return false;
+ }
+ }
+
+ UnwindPlan::RowSP row = std::make_shared<UnwindPlan::Row>();
+ row->SetOffset(0);
+ row->GetCFAValue().SetIsRegisterPlusOffset(vsp_reg, vsp);
+
+ bool have_location_for_pc = false;
+ for (const auto& offset : register_offsets)
+ {
+ have_location_for_pc |= offset.first == dwarf_pc;
+ row->SetRegisterLocationToAtCFAPlusOffset(offset.first, offset.second - vsp, true);
+ }
+
+ if (!have_location_for_pc)
+ {
+ UnwindPlan::Row::RegisterLocation lr_location;
+ if (row->GetRegisterInfo(dwarf_lr, lr_location))
+ row->SetRegisterInfo(dwarf_pc, lr_location);
+ else
+ row->SetRegisterLocationToRegister(dwarf_pc, dwarf_lr, false);
+ }
+
+ unwind_plan.AppendRow(row);
+ unwind_plan.SetSourceName ("ARM.exidx unwind info");
+ unwind_plan.SetSourcedFromCompiler (eLazyBoolYes);
+ unwind_plan.SetUnwindPlanValidAtAllInstructions (eLazyBoolNo);
+ unwind_plan.SetRegisterKind (eRegisterKindDWARF);
+
+ return true;
+}
+
+const uint8_t*
+ArmUnwindInfo::GetExceptionHandlingTableEntry(const Address& addr)
+{
+ auto it = std::upper_bound(m_exidx_entries.begin(),
+ m_exidx_entries.end(),
+ ArmExidxEntry{0, addr.GetFileAddress(), 0});
+ if (it == m_exidx_entries.begin())
+ return nullptr;
+ --it;
+
+ if (it->data == 0x1)
+ return nullptr; // EXIDX_CANTUNWIND
+
+ if (it->data & 0x80000000)
+ return (const uint8_t*)&it->data;
+
+ addr_t data_file_addr = it->file_address + 4 + Prel31ToAddr(it->data);
+ return m_arm_extab_data.GetDataStart() + (data_file_addr - m_arm_extab_sp->GetFileAddress());
+}
diff --git a/source/Symbol/Block.cpp b/source/Symbol/Block.cpp
index 94fa166bb2651..dfe9217362bd1 100644
--- a/source/Symbol/Block.cpp
+++ b/source/Symbol/Block.cpp
@@ -546,27 +546,24 @@ Block::AppendVariables
return num_variables_added;
}
-clang::DeclContext *
-Block::GetClangDeclContext()
+CompilerDeclContext
+Block::GetDeclContext()
{
- SymbolContext sc;
-
- CalculateSymbolContext (&sc);
-
- if (!sc.module_sp)
- return nullptr;
-
- SymbolVendor *sym_vendor = sc.module_sp->GetSymbolVendor();
-
- if (!sym_vendor)
- return nullptr;
-
- SymbolFile *sym_file = sym_vendor->GetSymbolFile();
+ ModuleSP module_sp = CalculateSymbolContextModule ();
+
+ if (module_sp)
+ {
+ SymbolVendor *sym_vendor = module_sp->GetSymbolVendor();
- if (!sym_file)
- return nullptr;
+ if (sym_vendor)
+ {
+ SymbolFile *sym_file = sym_vendor->GetSymbolFile();
- return sym_file->GetClangDeclContextForTypeUID (sc, m_uid);
+ if (sym_file)
+ return sym_file->GetDeclContextForUID (GetID());
+ }
+ }
+ return CompilerDeclContext();
}
void
diff --git a/source/Symbol/ClangASTContext.cpp b/source/Symbol/ClangASTContext.cpp
index 68bcde8a47c1f..8b11c239aabfe 100644
--- a/source/Symbol/ClangASTContext.cpp
+++ b/source/Symbol/ClangASTContext.cpp
@@ -13,6 +13,7 @@
// C++ Includes
#include <mutex> // std::once
#include <string>
+#include <vector>
// Other libraries and framework includes
@@ -39,8 +40,10 @@
#include "clang/AST/CXXInheritance.h"
#include "clang/AST/DeclObjC.h"
#include "clang/AST/DeclTemplate.h"
+#include "clang/AST/Mangle.h"
#include "clang/AST/RecordLayout.h"
#include "clang/AST/Type.h"
+#include "clang/AST/VTableBuilder.h"
#include "clang/Basic/Builtins.h"
#include "clang/Basic/Diagnostic.h"
#include "clang/Basic/FileManager.h"
@@ -58,19 +61,33 @@
#include <assert.h>
#endif
+#include "llvm/Support/Signals.h"
+
#include "lldb/Core/ArchSpec.h"
-#include "lldb/Core/dwarf.h"
#include "lldb/Core/Flags.h"
#include "lldb/Core/Log.h"
+#include "lldb/Core/Module.h"
+#include "lldb/Core/PluginManager.h"
#include "lldb/Core/RegularExpression.h"
+#include "lldb/Core/StreamFile.h"
#include "lldb/Core/ThreadSafeDenseMap.h"
#include "lldb/Core/UniqueCStringMap.h"
-#include "lldb/Expression/ASTDumper.h"
+#include "Plugins/ExpressionParser/Clang/ClangUserExpression.h"
+#include "Plugins/ExpressionParser/Clang/ClangFunctionCaller.h"
+#include "Plugins/ExpressionParser/Clang/ClangUtilityFunction.h"
+#include "lldb/Symbol/ClangASTContext.h"
+#include "lldb/Symbol/ClangExternalASTSourceCallbacks.h"
#include "lldb/Symbol/ClangExternalASTSourceCommon.h"
+#include "lldb/Symbol/ObjectFile.h"
+#include "lldb/Symbol/SymbolFile.h"
#include "lldb/Symbol/VerifyDecl.h"
#include "lldb/Target/ExecutionContext.h"
-#include "lldb/Target/Process.h"
+#include "lldb/Target/Language.h"
#include "lldb/Target/ObjCLanguageRuntime.h"
+#include "lldb/Target/Process.h"
+#include "lldb/Target/Target.h"
+
+#include "Plugins/SymbolFile/DWARF/DWARFASTParserClang.h"
#include <stdio.h>
@@ -81,6 +98,17 @@ using namespace lldb_private;
using namespace llvm;
using namespace clang;
+namespace
+{
+ static inline bool ClangASTContextSupportsLanguage (lldb::LanguageType language)
+ {
+ return language == eLanguageTypeUnknown || // Clang is the default type system
+ Language::LanguageIsC (language) ||
+ Language::LanguageIsCPlusPlus (language) ||
+ Language::LanguageIsObjC (language);
+ }
+}
+
typedef lldb_private::ThreadSafeDenseMap<clang::ASTContext *, ClangASTContext*> ClangASTMap;
static ClangASTMap &
@@ -277,22 +305,23 @@ ParseLangArgs (LangOptions &Opts, InputKind IK, const char* triple)
}
-ClangASTContext::ClangASTContext (const char *target_triple) :
- m_target_triple(),
- m_ast_ap(),
- m_language_options_ap(),
- m_source_manager_ap(),
- m_diagnostics_engine_ap(),
- m_target_options_rp(),
- m_target_info_ap(),
- m_identifier_table_ap(),
- m_selector_table_ap(),
- m_builtins_ap(),
+ClangASTContext::ClangASTContext (const char *target_triple) :
+ TypeSystem (TypeSystem::eKindClang),
+ m_target_triple (),
+ m_ast_ap (),
+ m_language_options_ap (),
+ m_source_manager_ap (),
+ m_diagnostics_engine_ap (),
+ m_target_options_rp (),
+ m_target_info_ap (),
+ m_identifier_table_ap (),
+ m_selector_table_ap (),
+ m_builtins_ap (),
m_callback_tag_decl (nullptr),
m_callback_objc_decl (nullptr),
m_callback_baton (nullptr),
- m_pointer_byte_size (0)
-
+ m_pointer_byte_size (0),
+ m_ast_owned (false)
{
if (target_triple && target_triple[0])
SetTargetTriple (target_triple);
@@ -306,6 +335,8 @@ ClangASTContext::~ClangASTContext()
if (m_ast_ap.get())
{
GetASTMap().Erase(m_ast_ap.get());
+ if (!m_ast_owned)
+ m_ast_ap.release();
}
m_builtins_ap.reset();
@@ -319,6 +350,127 @@ ClangASTContext::~ClangASTContext()
m_ast_ap.reset();
}
+ConstString
+ClangASTContext::GetPluginNameStatic()
+{
+ return ConstString("clang");
+}
+
+ConstString
+ClangASTContext::GetPluginName()
+{
+ return ClangASTContext::GetPluginNameStatic();
+}
+
+uint32_t
+ClangASTContext::GetPluginVersion()
+{
+ return 1;
+}
+
+lldb::TypeSystemSP
+ClangASTContext::CreateInstance (lldb::LanguageType language,
+ lldb_private::Module *module,
+ Target *target)
+{
+ if (ClangASTContextSupportsLanguage(language))
+ {
+ ArchSpec arch;
+ if (module)
+ arch = module->GetArchitecture();
+ else if (target)
+ arch = target->GetArchitecture();
+
+ if (arch.IsValid())
+ {
+ ArchSpec fixed_arch = arch;
+ // LLVM wants this to be set to iOS or MacOSX; if we're working on
+ // a bare-boards type image, change the triple for llvm's benefit.
+ if (fixed_arch.GetTriple().getVendor() == llvm::Triple::Apple &&
+ fixed_arch.GetTriple().getOS() == llvm::Triple::UnknownOS)
+ {
+ if (fixed_arch.GetTriple().getArch() == llvm::Triple::arm ||
+ fixed_arch.GetTriple().getArch() == llvm::Triple::aarch64 ||
+ fixed_arch.GetTriple().getArch() == llvm::Triple::thumb)
+ {
+ fixed_arch.GetTriple().setOS(llvm::Triple::IOS);
+ }
+ else
+ {
+ fixed_arch.GetTriple().setOS(llvm::Triple::MacOSX);
+ }
+ }
+
+ if (module)
+ {
+ std::shared_ptr<ClangASTContext> ast_sp(new ClangASTContext);
+ if (ast_sp)
+ {
+ ast_sp->SetArchitecture (fixed_arch);
+ }
+ return ast_sp;
+ }
+ else if (target && target->IsValid())
+ {
+ std::shared_ptr<ClangASTContextForExpressions> ast_sp(new ClangASTContextForExpressions(*target));
+ if (ast_sp)
+ {
+ ast_sp->SetArchitecture(fixed_arch);
+ ast_sp->m_scratch_ast_source_ap.reset (new ClangASTSource(target->shared_from_this()));
+ ast_sp->m_scratch_ast_source_ap->InstallASTContext(ast_sp->getASTContext());
+ llvm::IntrusiveRefCntPtr<clang::ExternalASTSource> proxy_ast_source(ast_sp->m_scratch_ast_source_ap->CreateProxy());
+ ast_sp->SetExternalSource(proxy_ast_source);
+ return ast_sp;
+ }
+ }
+ }
+ }
+ return lldb::TypeSystemSP();
+}
+
+void
+ClangASTContext::EnumerateSupportedLanguages(std::set<lldb::LanguageType> &languages_for_types, std::set<lldb::LanguageType> &languages_for_expressions)
+{
+ static std::vector<lldb::LanguageType> s_supported_languages_for_types({
+ lldb::eLanguageTypeC89,
+ lldb::eLanguageTypeC,
+ lldb::eLanguageTypeC11,
+ lldb::eLanguageTypeC_plus_plus,
+ lldb::eLanguageTypeC99,
+ lldb::eLanguageTypeObjC,
+ lldb::eLanguageTypeObjC_plus_plus,
+ lldb::eLanguageTypeC_plus_plus_03,
+ lldb::eLanguageTypeC_plus_plus_11,
+ lldb::eLanguageTypeC11,
+ lldb::eLanguageTypeC_plus_plus_14});
+
+ static std::vector<lldb::LanguageType> s_supported_languages_for_expressions({
+ lldb::eLanguageTypeC_plus_plus,
+ lldb::eLanguageTypeObjC_plus_plus,
+ lldb::eLanguageTypeC_plus_plus_03,
+ lldb::eLanguageTypeC_plus_plus_11,
+ lldb::eLanguageTypeC_plus_plus_14});
+
+ languages_for_types.insert(s_supported_languages_for_types.begin(), s_supported_languages_for_types.end());
+ languages_for_expressions.insert(s_supported_languages_for_expressions.begin(), s_supported_languages_for_expressions.end());
+}
+
+
+void
+ClangASTContext::Initialize()
+{
+ PluginManager::RegisterPlugin (GetPluginNameStatic(),
+ "clang base AST context plug-in",
+ CreateInstance,
+ EnumerateSupportedLanguages);
+}
+
+void
+ClangASTContext::Terminate()
+{
+ PluginManager::UnregisterPlugin (CreateInstance);
+}
+
void
ClangASTContext::Clear()
@@ -389,13 +541,23 @@ ClangASTContext::RemoveExternalSource ()
}
}
-
+void
+ClangASTContext::setASTContext(clang::ASTContext *ast_ctx)
+{
+ if (!m_ast_owned) {
+ m_ast_ap.release();
+ }
+ m_ast_owned = false;
+ m_ast_ap.reset(ast_ctx);
+ GetASTMap().Insert(ast_ctx, this);
+}
ASTContext *
ClangASTContext::getASTContext()
{
if (m_ast_ap.get() == nullptr)
{
+ m_ast_owned = true;
m_ast_ap.reset(new ASTContext (*getLanguageOptions(),
*getSourceManager(),
*getIdentifierTable(),
@@ -417,6 +579,13 @@ ClangASTContext::getASTContext()
}
GetASTMap().Insert(m_ast_ap.get(), this);
+
+ llvm::IntrusiveRefCntPtr<clang::ExternalASTSource> ast_source_ap (new ClangExternalASTSourceCallbacks (ClangASTContext::CompleteTagDecl,
+ ClangASTContext::CompleteObjCInterfaceDecl,
+ nullptr,
+ ClangASTContext::LayoutRecordType,
+ this));
+ SetExternalSource (ast_source_ap);
}
return m_ast_ap.get();
}
@@ -494,6 +663,14 @@ ClangASTContext::getDiagnosticsEngine()
return m_diagnostics_engine_ap.get();
}
+clang::MangleContext *
+ClangASTContext::getMangleContext()
+{
+ if (m_mangle_ctx_ap.get() == nullptr)
+ m_mangle_ctx_ap.reset (getASTContext()->createMangleContext());
+ return m_mangle_ctx_ap.get();
+}
+
class NullDiagnosticConsumer : public DiagnosticConsumer
{
public:
@@ -561,72 +738,74 @@ QualTypeMatchesBitSize(const uint64_t bit_size, ASTContext *ast, QualType qual_t
return true;
return false;
}
-ClangASTType
-ClangASTContext::GetBuiltinTypeForEncodingAndBitSize (Encoding encoding, uint32_t bit_size)
+
+CompilerType
+ClangASTContext::GetBuiltinTypeForEncodingAndBitSize (Encoding encoding, size_t bit_size)
{
return ClangASTContext::GetBuiltinTypeForEncodingAndBitSize (getASTContext(), encoding, bit_size);
}
-ClangASTType
+CompilerType
ClangASTContext::GetBuiltinTypeForEncodingAndBitSize (ASTContext *ast, Encoding encoding, uint32_t bit_size)
{
if (!ast)
- return ClangASTType();
-
+ return CompilerType();
switch (encoding)
{
case eEncodingInvalid:
if (QualTypeMatchesBitSize (bit_size, ast, ast->VoidPtrTy))
- return ClangASTType (ast, ast->VoidPtrTy.getAsOpaquePtr());
+ return CompilerType (ast, ast->VoidPtrTy);
break;
case eEncodingUint:
if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedCharTy))
- return ClangASTType (ast, ast->UnsignedCharTy.getAsOpaquePtr());
+ return CompilerType (ast, ast->UnsignedCharTy);
if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedShortTy))
- return ClangASTType (ast, ast->UnsignedShortTy.getAsOpaquePtr());
+ return CompilerType (ast, ast->UnsignedShortTy);
if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedIntTy))
- return ClangASTType (ast, ast->UnsignedIntTy.getAsOpaquePtr());
+ return CompilerType (ast, ast->UnsignedIntTy);
if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedLongTy))
- return ClangASTType (ast, ast->UnsignedLongTy.getAsOpaquePtr());
+ return CompilerType (ast, ast->UnsignedLongTy);
if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedLongLongTy))
- return ClangASTType (ast, ast->UnsignedLongLongTy.getAsOpaquePtr());
+ return CompilerType (ast, ast->UnsignedLongLongTy);
if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedInt128Ty))
- return ClangASTType (ast, ast->UnsignedInt128Ty.getAsOpaquePtr());
+ return CompilerType (ast, ast->UnsignedInt128Ty);
break;
case eEncodingSint:
if (QualTypeMatchesBitSize (bit_size, ast, ast->CharTy))
- return ClangASTType (ast, ast->CharTy.getAsOpaquePtr());
+ return CompilerType (ast, ast->CharTy);
if (QualTypeMatchesBitSize (bit_size, ast, ast->ShortTy))
- return ClangASTType (ast, ast->ShortTy.getAsOpaquePtr());
+ return CompilerType (ast, ast->ShortTy);
if (QualTypeMatchesBitSize (bit_size, ast, ast->IntTy))
- return ClangASTType (ast, ast->IntTy.getAsOpaquePtr());
+ return CompilerType (ast, ast->IntTy);
if (QualTypeMatchesBitSize (bit_size, ast, ast->LongTy))
- return ClangASTType (ast, ast->LongTy.getAsOpaquePtr());
+ return CompilerType (ast, ast->LongTy);
if (QualTypeMatchesBitSize (bit_size, ast, ast->LongLongTy))
- return ClangASTType (ast, ast->LongLongTy.getAsOpaquePtr());
+ return CompilerType (ast, ast->LongLongTy);
if (QualTypeMatchesBitSize (bit_size, ast, ast->Int128Ty))
- return ClangASTType (ast, ast->Int128Ty.getAsOpaquePtr());
+ return CompilerType (ast, ast->Int128Ty);
break;
case eEncodingIEEE754:
if (QualTypeMatchesBitSize (bit_size, ast, ast->FloatTy))
- return ClangASTType (ast, ast->FloatTy.getAsOpaquePtr());
+ return CompilerType (ast, ast->FloatTy);
if (QualTypeMatchesBitSize (bit_size, ast, ast->DoubleTy))
- return ClangASTType (ast, ast->DoubleTy.getAsOpaquePtr());
+ return CompilerType (ast, ast->DoubleTy);
if (QualTypeMatchesBitSize (bit_size, ast, ast->LongDoubleTy))
- return ClangASTType (ast, ast->LongDoubleTy.getAsOpaquePtr());
+ return CompilerType (ast, ast->LongDoubleTy);
+ if (QualTypeMatchesBitSize (bit_size, ast, ast->HalfTy))
+ return CompilerType (ast, ast->HalfTy);
break;
case eEncodingVector:
// Sanity check that bit_size is a multiple of 8's.
if (bit_size && !(bit_size & 0x7u))
- return ClangASTType (ast, ast->getExtVectorType (ast->UnsignedCharTy, bit_size/8).getAsOpaquePtr());
+ return CompilerType (ast, ast->getExtVectorType (ast->UnsignedCharTy, bit_size/8));
break;
}
- return ClangASTType();
+ return CompilerType();
}
@@ -694,7 +873,7 @@ ClangASTContext::GetBasicTypeEnumeration (const ConstString &name)
return eBasicTypeInvalid;
}
-ClangASTType
+CompilerType
ClangASTContext::GetBasicType (ASTContext *ast, const ConstString &name)
{
if (ast)
@@ -702,7 +881,7 @@ ClangASTContext::GetBasicType (ASTContext *ast, const ConstString &name)
lldb::BasicType basic_type = ClangASTContext::GetBasicTypeEnumeration (name);
return ClangASTContext::GetBasicType (ast, basic_type);
}
- return ClangASTType();
+ return CompilerType();
}
uint32_t
@@ -713,18 +892,18 @@ ClangASTContext::GetPointerByteSize ()
return m_pointer_byte_size;
}
-ClangASTType
+CompilerType
ClangASTContext::GetBasicType (lldb::BasicType basic_type)
{
return GetBasicType (getASTContext(), basic_type);
}
-ClangASTType
+CompilerType
ClangASTContext::GetBasicType (ASTContext *ast, lldb::BasicType basic_type)
{
if (ast)
{
- clang_type_t clang_type = nullptr;
+ lldb::opaque_compiler_type_t clang_type = nullptr;
switch (basic_type)
{
@@ -827,13 +1006,13 @@ ClangASTContext::GetBasicType (ASTContext *ast, lldb::BasicType basic_type)
}
if (clang_type)
- return ClangASTType (ast, clang_type);
+ return CompilerType (GetASTContext(ast), clang_type);
}
- return ClangASTType();
+ return CompilerType();
}
-ClangASTType
+CompilerType
ClangASTContext::GetBuiltinTypeForDWARFEncodingAndBitSize (const char *type_name, uint32_t dw_ate, uint32_t bit_size)
{
ASTContext *ast = getASTContext();
@@ -849,18 +1028,18 @@ ClangASTContext::GetBuiltinTypeForDWARFEncodingAndBitSize (const char *type_name
case DW_ATE_address:
if (QualTypeMatchesBitSize (bit_size, ast, ast->VoidPtrTy))
- return ClangASTType (ast, ast->VoidPtrTy.getAsOpaquePtr());
+ return CompilerType (ast, ast->VoidPtrTy);
break;
case DW_ATE_boolean:
if (QualTypeMatchesBitSize (bit_size, ast, ast->BoolTy))
- return ClangASTType (ast, ast->BoolTy.getAsOpaquePtr());
+ return CompilerType (ast, ast->BoolTy);
if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedCharTy))
- return ClangASTType (ast, ast->UnsignedCharTy.getAsOpaquePtr());
+ return CompilerType (ast, ast->UnsignedCharTy);
if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedShortTy))
- return ClangASTType (ast, ast->UnsignedShortTy.getAsOpaquePtr());
+ return CompilerType (ast, ast->UnsignedShortTy);
if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedIntTy))
- return ClangASTType (ast, ast->UnsignedIntTy.getAsOpaquePtr());
+ return CompilerType (ast, ast->UnsignedIntTy);
break;
case DW_ATE_lo_user:
@@ -869,40 +1048,42 @@ ClangASTContext::GetBuiltinTypeForDWARFEncodingAndBitSize (const char *type_name
{
if (::strstr(type_name, "complex"))
{
- ClangASTType complex_int_clang_type = GetBuiltinTypeForDWARFEncodingAndBitSize ("int", DW_ATE_signed, bit_size/2);
- return ClangASTType (ast, ast->getComplexType (complex_int_clang_type.GetQualType()).getAsOpaquePtr());
+ CompilerType complex_int_clang_type = GetBuiltinTypeForDWARFEncodingAndBitSize ("int", DW_ATE_signed, bit_size/2);
+ return CompilerType (ast, ast->getComplexType (GetQualType(complex_int_clang_type)));
}
}
break;
case DW_ATE_complex_float:
if (QualTypeMatchesBitSize (bit_size, ast, ast->FloatComplexTy))
- return ClangASTType (ast, ast->FloatComplexTy.getAsOpaquePtr());
+ return CompilerType (ast, ast->FloatComplexTy);
else if (QualTypeMatchesBitSize (bit_size, ast, ast->DoubleComplexTy))
- return ClangASTType (ast, ast->DoubleComplexTy.getAsOpaquePtr());
+ return CompilerType (ast, ast->DoubleComplexTy);
else if (QualTypeMatchesBitSize (bit_size, ast, ast->LongDoubleComplexTy))
- return ClangASTType (ast, ast->LongDoubleComplexTy.getAsOpaquePtr());
+ return CompilerType (ast, ast->LongDoubleComplexTy);
else
{
- ClangASTType complex_float_clang_type = GetBuiltinTypeForDWARFEncodingAndBitSize ("float", DW_ATE_float, bit_size/2);
- return ClangASTType (ast, ast->getComplexType (complex_float_clang_type.GetQualType()).getAsOpaquePtr());
+ CompilerType complex_float_clang_type = GetBuiltinTypeForDWARFEncodingAndBitSize ("float", DW_ATE_float, bit_size/2);
+ return CompilerType (ast, ast->getComplexType (GetQualType(complex_float_clang_type)));
}
break;
case DW_ATE_float:
if (streq(type_name, "float") && QualTypeMatchesBitSize (bit_size, ast, ast->FloatTy))
- return ClangASTType (ast, ast->FloatTy.getAsOpaquePtr());
+ return CompilerType (ast, ast->FloatTy);
if (streq(type_name, "double") && QualTypeMatchesBitSize (bit_size, ast, ast->DoubleTy))
- return ClangASTType (ast, ast->DoubleTy.getAsOpaquePtr());
+ return CompilerType (ast, ast->DoubleTy);
if (streq(type_name, "long double") && QualTypeMatchesBitSize (bit_size, ast, ast->LongDoubleTy))
- return ClangASTType (ast, ast->LongDoubleTy.getAsOpaquePtr());
- // Fall back to not requring a name match
+ return CompilerType (ast, ast->LongDoubleTy);
+ // Fall back to not requiring a name match
if (QualTypeMatchesBitSize (bit_size, ast, ast->FloatTy))
- return ClangASTType (ast, ast->FloatTy.getAsOpaquePtr());
+ return CompilerType (ast, ast->FloatTy);
if (QualTypeMatchesBitSize (bit_size, ast, ast->DoubleTy))
- return ClangASTType (ast, ast->DoubleTy.getAsOpaquePtr());
+ return CompilerType (ast, ast->DoubleTy);
if (QualTypeMatchesBitSize (bit_size, ast, ast->LongDoubleTy))
- return ClangASTType (ast, ast->LongDoubleTy.getAsOpaquePtr());
+ return CompilerType (ast, ast->LongDoubleTy);
+ if (QualTypeMatchesBitSize (bit_size, ast, ast->HalfTy))
+ return CompilerType (ast, ast->HalfTy);
break;
case DW_ATE_signed:
@@ -911,57 +1092,57 @@ ClangASTContext::GetBuiltinTypeForDWARFEncodingAndBitSize (const char *type_name
if (streq(type_name, "wchar_t") &&
QualTypeMatchesBitSize (bit_size, ast, ast->WCharTy) &&
(getTargetInfo() && TargetInfo::isTypeSigned (getTargetInfo()->getWCharType())))
- return ClangASTType (ast, ast->WCharTy.getAsOpaquePtr());
+ return CompilerType (ast, ast->WCharTy);
if (streq(type_name, "void") &&
QualTypeMatchesBitSize (bit_size, ast, ast->VoidTy))
- return ClangASTType (ast, ast->VoidTy.getAsOpaquePtr());
+ return CompilerType (ast, ast->VoidTy);
if (strstr(type_name, "long long") &&
QualTypeMatchesBitSize (bit_size, ast, ast->LongLongTy))
- return ClangASTType (ast, ast->LongLongTy.getAsOpaquePtr());
+ return CompilerType (ast, ast->LongLongTy);
if (strstr(type_name, "long") &&
QualTypeMatchesBitSize (bit_size, ast, ast->LongTy))
- return ClangASTType (ast, ast->LongTy.getAsOpaquePtr());
+ return CompilerType (ast, ast->LongTy);
if (strstr(type_name, "short") &&
QualTypeMatchesBitSize (bit_size, ast, ast->ShortTy))
- return ClangASTType (ast, ast->ShortTy.getAsOpaquePtr());
+ return CompilerType (ast, ast->ShortTy);
if (strstr(type_name, "char"))
{
if (QualTypeMatchesBitSize (bit_size, ast, ast->CharTy))
- return ClangASTType (ast, ast->CharTy.getAsOpaquePtr());
+ return CompilerType (ast, ast->CharTy);
if (QualTypeMatchesBitSize (bit_size, ast, ast->SignedCharTy))
- return ClangASTType (ast, ast->SignedCharTy.getAsOpaquePtr());
+ return CompilerType (ast, ast->SignedCharTy);
}
if (strstr(type_name, "int"))
{
if (QualTypeMatchesBitSize (bit_size, ast, ast->IntTy))
- return ClangASTType (ast, ast->IntTy.getAsOpaquePtr());
+ return CompilerType (ast, ast->IntTy);
if (QualTypeMatchesBitSize (bit_size, ast, ast->Int128Ty))
- return ClangASTType (ast, ast->Int128Ty.getAsOpaquePtr());
+ return CompilerType (ast, ast->Int128Ty);
}
}
// We weren't able to match up a type name, just search by size
if (QualTypeMatchesBitSize (bit_size, ast, ast->CharTy))
- return ClangASTType (ast, ast->CharTy.getAsOpaquePtr());
+ return CompilerType (ast, ast->CharTy);
if (QualTypeMatchesBitSize (bit_size, ast, ast->ShortTy))
- return ClangASTType (ast, ast->ShortTy.getAsOpaquePtr());
+ return CompilerType (ast, ast->ShortTy);
if (QualTypeMatchesBitSize (bit_size, ast, ast->IntTy))
- return ClangASTType (ast, ast->IntTy.getAsOpaquePtr());
+ return CompilerType (ast, ast->IntTy);
if (QualTypeMatchesBitSize (bit_size, ast, ast->LongTy))
- return ClangASTType (ast, ast->LongTy.getAsOpaquePtr());
+ return CompilerType (ast, ast->LongTy);
if (QualTypeMatchesBitSize (bit_size, ast, ast->LongLongTy))
- return ClangASTType (ast, ast->LongLongTy.getAsOpaquePtr());
+ return CompilerType (ast, ast->LongLongTy);
if (QualTypeMatchesBitSize (bit_size, ast, ast->Int128Ty))
- return ClangASTType (ast, ast->Int128Ty.getAsOpaquePtr());
+ return CompilerType (ast, ast->Int128Ty);
break;
case DW_ATE_signed_char:
if (ast->getLangOpts().CharIsSigned && type_name && streq(type_name, "char"))
{
if (QualTypeMatchesBitSize (bit_size, ast, ast->CharTy))
- return ClangASTType (ast, ast->CharTy.getAsOpaquePtr());
+ return CompilerType (ast, ast->CharTy);
}
if (QualTypeMatchesBitSize (bit_size, ast, ast->SignedCharTy))
- return ClangASTType (ast, ast->SignedCharTy.getAsOpaquePtr());
+ return CompilerType (ast, ast->SignedCharTy);
break;
case DW_ATE_unsigned:
@@ -972,62 +1153,62 @@ ClangASTContext::GetBuiltinTypeForDWARFEncodingAndBitSize (const char *type_name
if (QualTypeMatchesBitSize (bit_size, ast, ast->WCharTy))
{
if (!(getTargetInfo() && TargetInfo::isTypeSigned (getTargetInfo()->getWCharType())))
- return ClangASTType (ast, ast->WCharTy.getAsOpaquePtr());
+ return CompilerType (ast, ast->WCharTy);
}
}
if (strstr(type_name, "long long"))
{
if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedLongLongTy))
- return ClangASTType (ast, ast->UnsignedLongLongTy.getAsOpaquePtr());
+ return CompilerType (ast, ast->UnsignedLongLongTy);
}
else if (strstr(type_name, "long"))
{
if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedLongTy))
- return ClangASTType (ast, ast->UnsignedLongTy.getAsOpaquePtr());
+ return CompilerType (ast, ast->UnsignedLongTy);
}
else if (strstr(type_name, "short"))
{
if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedShortTy))
- return ClangASTType (ast, ast->UnsignedShortTy.getAsOpaquePtr());
+ return CompilerType (ast, ast->UnsignedShortTy);
}
else if (strstr(type_name, "char"))
{
if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedCharTy))
- return ClangASTType (ast, ast->UnsignedCharTy.getAsOpaquePtr());
+ return CompilerType (ast, ast->UnsignedCharTy);
}
else if (strstr(type_name, "int"))
{
if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedIntTy))
- return ClangASTType (ast, ast->UnsignedIntTy.getAsOpaquePtr());
+ return CompilerType (ast, ast->UnsignedIntTy);
if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedInt128Ty))
- return ClangASTType (ast, ast->UnsignedInt128Ty.getAsOpaquePtr());
+ return CompilerType (ast, ast->UnsignedInt128Ty);
}
}
// We weren't able to match up a type name, just search by size
if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedCharTy))
- return ClangASTType (ast, ast->UnsignedCharTy.getAsOpaquePtr());
+ return CompilerType (ast, ast->UnsignedCharTy);
if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedShortTy))
- return ClangASTType (ast, ast->UnsignedShortTy.getAsOpaquePtr());
+ return CompilerType (ast, ast->UnsignedShortTy);
if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedIntTy))
- return ClangASTType (ast, ast->UnsignedIntTy.getAsOpaquePtr());
+ return CompilerType (ast, ast->UnsignedIntTy);
if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedLongTy))
- return ClangASTType (ast, ast->UnsignedLongTy.getAsOpaquePtr());
+ return CompilerType (ast, ast->UnsignedLongTy);
if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedLongLongTy))
- return ClangASTType (ast, ast->UnsignedLongLongTy.getAsOpaquePtr());
+ return CompilerType (ast, ast->UnsignedLongLongTy);
if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedInt128Ty))
- return ClangASTType (ast, ast->UnsignedInt128Ty.getAsOpaquePtr());
+ return CompilerType (ast, ast->UnsignedInt128Ty);
break;
case DW_ATE_unsigned_char:
if (!ast->getLangOpts().CharIsSigned && type_name && streq(type_name, "char"))
{
if (QualTypeMatchesBitSize (bit_size, ast, ast->CharTy))
- return ClangASTType (ast, ast->CharTy.getAsOpaquePtr());
+ return CompilerType (ast, ast->CharTy);
}
if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedCharTy))
- return ClangASTType (ast, ast->UnsignedCharTy.getAsOpaquePtr());
+ return CompilerType (ast, ast->UnsignedCharTy);
if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedShortTy))
- return ClangASTType (ast, ast->UnsignedShortTy.getAsOpaquePtr());
+ return CompilerType (ast, ast->UnsignedShortTy);
break;
case DW_ATE_imaginary_float:
@@ -1038,11 +1219,11 @@ ClangASTContext::GetBuiltinTypeForDWARFEncodingAndBitSize (const char *type_name
{
if (streq(type_name, "char16_t"))
{
- return ClangASTType (ast, ast->Char16Ty.getAsOpaquePtr());
+ return CompilerType (ast, ast->Char16Ty);
}
else if (streq(type_name, "char32_t"))
{
- return ClangASTType (ast, ast->Char32Ty.getAsOpaquePtr());
+ return CompilerType (ast, ast->Char32Ty);
}
}
break;
@@ -1058,18 +1239,18 @@ ClangASTContext::GetBuiltinTypeForDWARFEncodingAndBitSize (const char *type_name
{
Host::SystemLog (Host::eSystemLogError, "error: need to add support for DW_TAG_base_type encoded with DW_ATE = 0x%x, bit_size = %u\n", dw_ate, bit_size);
}
- return ClangASTType ();
+ return CompilerType ();
}
-ClangASTType
+CompilerType
ClangASTContext::GetUnknownAnyType(clang::ASTContext *ast)
{
if (ast)
- return ClangASTType (ast, ast->UnknownAnyTy.getAsOpaquePtr());
- return ClangASTType();
+ return CompilerType (ast, ast->UnknownAnyTy);
+ return CompilerType();
}
-ClangASTType
+CompilerType
ClangASTContext::GetCStringType (bool is_const)
{
ASTContext *ast = getASTContext();
@@ -1078,7 +1259,7 @@ ClangASTContext::GetCStringType (bool is_const)
if (is_const)
char_type.addConst();
- return ClangASTType (ast, ast->getPointerType(char_type).getAsOpaquePtr());
+ return CompilerType (ast, ast->getPointerType(char_type));
}
clang::DeclContext *
@@ -1087,23 +1268,6 @@ ClangASTContext::GetTranslationUnitDecl (clang::ASTContext *ast)
return ast->getTranslationUnitDecl();
}
-ClangASTType
-ClangASTContext::CopyType (ASTContext *dst_ast,
- ClangASTType src)
-{
- FileSystemOptions file_system_options;
- ASTContext *src_ast = src.GetASTContext();
- FileManager file_manager (file_system_options);
- ASTImporter importer(*dst_ast, file_manager,
- *src_ast, file_manager,
- false);
-
- QualType dst (importer.Import(src.GetQualType()));
-
- return ClangASTType (dst_ast, dst.getAsOpaquePtr());
-}
-
-
clang::Decl *
ClangASTContext::CopyDecl (ASTContext *dst_ast,
ASTContext *src_ast,
@@ -1119,19 +1283,19 @@ ClangASTContext::CopyDecl (ASTContext *dst_ast,
}
bool
-ClangASTContext::AreTypesSame (ClangASTType type1,
- ClangASTType type2,
+ClangASTContext::AreTypesSame (CompilerType type1,
+ CompilerType type2,
bool ignore_qualifiers)
{
- ASTContext *ast = type1.GetASTContext();
- if (ast != type2.GetASTContext())
+ ClangASTContext *ast = llvm::dyn_cast_or_null<ClangASTContext>(type1.GetTypeSystem());
+ if (!ast || ast != type2.GetTypeSystem())
return false;
if (type1.GetOpaqueQualType() == type2.GetOpaqueQualType())
return true;
- QualType type1_qual = type1.GetQualType();
- QualType type2_qual = type2.GetQualType();
+ QualType type1_qual = GetQualType(type1);
+ QualType type2_qual = GetQualType(type2);
if (ignore_qualifiers)
{
@@ -1139,21 +1303,21 @@ ClangASTContext::AreTypesSame (ClangASTType type1,
type2_qual = type2_qual.getUnqualifiedType();
}
- return ast->hasSameType (type1_qual, type2_qual);
+ return ast->getASTContext()->hasSameType (type1_qual, type2_qual);
}
-ClangASTType
+CompilerType
ClangASTContext::GetTypeForDecl (clang::NamedDecl *decl)
{
if (clang::ObjCInterfaceDecl *interface_decl = llvm::dyn_cast<clang::ObjCInterfaceDecl>(decl))
return GetTypeForDecl(interface_decl);
if (clang::TagDecl *tag_decl = llvm::dyn_cast<clang::TagDecl>(decl))
return GetTypeForDecl(tag_decl);
- return ClangASTType();
+ return CompilerType();
}
-ClangASTType
+CompilerType
ClangASTContext::GetTypeForDecl (TagDecl *decl)
{
// No need to call the getASTContext() accessor (which can create the AST
@@ -1161,11 +1325,11 @@ ClangASTContext::GetTypeForDecl (TagDecl *decl)
// AST if our AST didn't already exist...
ASTContext *ast = &decl->getASTContext();
if (ast)
- return ClangASTType (ast, ast->getTagDeclType(decl).getAsOpaquePtr());
- return ClangASTType();
+ return CompilerType (ast, ast->getTagDeclType(decl));
+ return CompilerType();
}
-ClangASTType
+CompilerType
ClangASTContext::GetTypeForDecl (ObjCInterfaceDecl *decl)
{
// No need to call the getASTContext() accessor (which can create the AST
@@ -1173,13 +1337,13 @@ ClangASTContext::GetTypeForDecl (ObjCInterfaceDecl *decl)
// AST if our AST didn't already exist...
ASTContext *ast = &decl->getASTContext();
if (ast)
- return ClangASTType (ast, ast->getObjCInterfaceType(decl).getAsOpaquePtr());
- return ClangASTType();
+ return CompilerType (ast, ast->getObjCInterfaceType(decl));
+ return CompilerType();
}
#pragma mark Structure, Unions, Classes
-ClangASTType
+CompilerType
ClangASTContext::CreateRecordType (DeclContext *decl_ctx,
AccessType access_type,
const char *name,
@@ -1230,9 +1394,9 @@ ClangASTContext::CreateRecordType (DeclContext *decl_ctx,
if (decl_ctx)
decl_ctx->addDecl (decl);
- return ClangASTType(ast, ast->getTagDeclType(decl).getAsOpaquePtr());
+ return CompilerType(ast, ast->getTagDeclType(decl));
}
- return ClangASTType();
+ return CompilerType();
}
static TemplateParameterList *
@@ -1282,8 +1446,7 @@ CreateTemplateParameterList (ASTContext *ast,
TemplateParameterList *template_param_list = TemplateParameterList::Create (*ast,
SourceLocation(),
SourceLocation(),
- &template_param_decls.front(),
- template_param_decls.size(),
+ template_param_decls,
SourceLocation());
return template_param_list;
}
@@ -1434,16 +1597,16 @@ ClangASTContext::CreateClassTemplateSpecializationDecl (DeclContext *decl_ctx,
return class_template_specialization_decl;
}
-ClangASTType
+CompilerType
ClangASTContext::CreateClassTemplateSpecializationType (ClassTemplateSpecializationDecl *class_template_specialization_decl)
{
if (class_template_specialization_decl)
{
ASTContext *ast = getASTContext();
if (ast)
- return ClangASTType(ast, ast->getTagDeclType(class_template_specialization_decl).getAsOpaquePtr());
+ return CompilerType(ast, ast->getTagDeclType(class_template_specialization_decl));
}
- return ClangASTType();
+ return CompilerType();
}
static inline bool
@@ -1571,7 +1734,7 @@ ClangASTContext::RecordHasFields (const RecordDecl *record_decl)
#pragma mark Objective C Classes
-ClangASTType
+CompilerType
ClangASTContext::CreateObjCClass
(
const char *name,
@@ -1600,7 +1763,7 @@ ClangASTContext::CreateObjCClass
if (decl && metadata)
SetMetadata(ast, decl, *metadata);
- return ClangASTType (ast, ast->getObjCInterfaceType(decl));
+ return CompilerType (ast, ast->getObjCInterfaceType(decl));
}
static inline bool
@@ -1714,24 +1877,6 @@ ClangASTContext::GetUniqueNamespaceDeclaration (const char *name, DeclContext *d
// BAD!!!
}
}
-
-
- if (namespace_decl)
- {
- // If we make it here, we are creating the anonymous namespace decl
- // for the first time, so we need to do the using directive magic
- // like SEMA does
- UsingDirectiveDecl* using_directive_decl = UsingDirectiveDecl::Create (*ast,
- decl_ctx,
- SourceLocation(),
- SourceLocation(),
- NestedNameSpecifierLoc(),
- SourceLocation(),
- namespace_decl,
- decl_ctx);
- using_directive_decl->setImplicit();
- decl_ctx->addDecl(using_directive_decl);
- }
}
#ifdef LLDB_CONFIGURATION_DEBUG
VerifyDecl(namespace_decl);
@@ -1740,12 +1885,104 @@ ClangASTContext::GetUniqueNamespaceDeclaration (const char *name, DeclContext *d
}
+clang::BlockDecl *
+ClangASTContext::CreateBlockDeclaration (clang::DeclContext *ctx)
+{
+ if (ctx != nullptr)
+ {
+ clang::BlockDecl *decl = clang::BlockDecl::Create(*getASTContext(), ctx, clang::SourceLocation());
+ ctx->addDecl(decl);
+ return decl;
+ }
+ return nullptr;
+}
+
+clang::DeclContext *
+FindLCABetweenDecls(clang::DeclContext *left, clang::DeclContext *right, clang::DeclContext *root)
+{
+ if (root == nullptr)
+ return nullptr;
+
+ std::set<clang::DeclContext *> path_left;
+ for (clang::DeclContext *d = left; d != nullptr; d = d->getParent())
+ path_left.insert(d);
+
+ for (clang::DeclContext *d = right; d != nullptr; d = d->getParent())
+ if (path_left.find(d) != path_left.end())
+ return d;
+
+ return nullptr;
+}
+
+clang::UsingDirectiveDecl *
+ClangASTContext::CreateUsingDirectiveDeclaration (clang::DeclContext *decl_ctx, clang::NamespaceDecl *ns_decl)
+{
+ if (decl_ctx != nullptr && ns_decl != nullptr)
+ {
+ clang::TranslationUnitDecl *translation_unit = (clang::TranslationUnitDecl *)GetTranslationUnitDecl(getASTContext());
+ clang::UsingDirectiveDecl *using_decl = clang::UsingDirectiveDecl::Create(*getASTContext(),
+ decl_ctx,
+ clang::SourceLocation(),
+ clang::SourceLocation(),
+ clang::NestedNameSpecifierLoc(),
+ clang::SourceLocation(),
+ ns_decl,
+ FindLCABetweenDecls(decl_ctx, ns_decl, translation_unit));
+ decl_ctx->addDecl(using_decl);
+ return using_decl;
+ }
+ return nullptr;
+}
+
+clang::UsingDecl *
+ClangASTContext::CreateUsingDeclaration (clang::DeclContext *current_decl_ctx, clang::NamedDecl *target)
+{
+ if (current_decl_ctx != nullptr && target != nullptr)
+ {
+ clang::UsingDecl *using_decl = clang::UsingDecl::Create(*getASTContext(),
+ current_decl_ctx,
+ clang::SourceLocation(),
+ clang::NestedNameSpecifierLoc(),
+ clang::DeclarationNameInfo(),
+ false);
+ clang::UsingShadowDecl *shadow_decl = clang::UsingShadowDecl::Create(*getASTContext(),
+ current_decl_ctx,
+ clang::SourceLocation(),
+ using_decl,
+ target);
+ using_decl->addShadowDecl(shadow_decl);
+ current_decl_ctx->addDecl(using_decl);
+ return using_decl;
+ }
+ return nullptr;
+}
+
+clang::VarDecl *
+ClangASTContext::CreateVariableDeclaration (clang::DeclContext *decl_context, const char *name, clang::QualType type)
+{
+ if (decl_context != nullptr)
+ {
+ clang::VarDecl *var_decl = clang::VarDecl::Create(*getASTContext(),
+ decl_context,
+ clang::SourceLocation(),
+ clang::SourceLocation(),
+ name && name[0] ? &getASTContext()->Idents.getOwn(name) : nullptr,
+ type,
+ nullptr,
+ clang::SC_None);
+ var_decl->setAccess(clang::AS_public);
+ decl_context->addDecl(var_decl);
+ return var_decl;
+ }
+ return nullptr;
+}
+
#pragma mark Function Types
FunctionDecl *
ClangASTContext::CreateFunctionDeclaration (DeclContext *decl_ctx,
const char *name,
- const ClangASTType &function_clang_type,
+ const CompilerType &function_clang_type,
int storage,
bool is_inline)
{
@@ -1765,7 +2002,7 @@ ClangASTContext::CreateFunctionDeclaration (DeclContext *decl_ctx,
SourceLocation(),
SourceLocation(),
DeclarationName (&ast->Idents.get(name)),
- function_clang_type.GetQualType(),
+ GetQualType(function_clang_type),
nullptr,
(clang::StorageClass)storage,
is_inline,
@@ -1779,7 +2016,7 @@ ClangASTContext::CreateFunctionDeclaration (DeclContext *decl_ctx,
SourceLocation(),
SourceLocation(),
DeclarationName (),
- function_clang_type.GetQualType(),
+ GetQualType(function_clang_type),
nullptr,
(clang::StorageClass)storage,
is_inline,
@@ -1796,10 +2033,10 @@ ClangASTContext::CreateFunctionDeclaration (DeclContext *decl_ctx,
return func_decl;
}
-ClangASTType
+CompilerType
ClangASTContext::CreateFunctionType (ASTContext *ast,
- const ClangASTType& result_type,
- const ClangASTType *args,
+ const CompilerType& result_type,
+ const CompilerType *args,
unsigned num_args,
bool is_variadic,
unsigned type_quals)
@@ -1807,7 +2044,7 @@ ClangASTContext::CreateFunctionType (ASTContext *ast,
assert (ast != nullptr);
std::vector<QualType> qual_type_args;
for (unsigned i=0; i<num_args; ++i)
- qual_type_args.push_back (args[i].GetQualType());
+ qual_type_args.push_back (GetQualType(args[i]));
// TODO: Detect calling convention in DWARF?
FunctionProtoType::ExtProtoInfo proto_info;
@@ -1816,13 +2053,13 @@ ClangASTContext::CreateFunctionType (ASTContext *ast,
proto_info.TypeQuals = type_quals;
proto_info.RefQualifier = RQ_None;
- return ClangASTType (ast, ast->getFunctionType (result_type.GetQualType(),
+ return CompilerType (ast, ast->getFunctionType (GetQualType(result_type),
qual_type_args,
- proto_info).getAsOpaquePtr());
+ proto_info));
}
ParmVarDecl *
-ClangASTContext::CreateParameterDeclaration (const char *name, const ClangASTType &param_type, int storage)
+ClangASTContext::CreateParameterDeclaration (const char *name, const CompilerType &param_type, int storage)
{
ASTContext *ast = getASTContext();
assert (ast != nullptr);
@@ -1831,7 +2068,7 @@ ClangASTContext::CreateParameterDeclaration (const char *name, const ClangASTTyp
SourceLocation(),
SourceLocation(),
name && name[0] ? &ast->Idents.get(name) : nullptr,
- param_type.GetQualType(),
+ GetQualType(param_type),
nullptr,
(clang::StorageClass)storage,
nullptr);
@@ -1847,8 +2084,8 @@ ClangASTContext::SetFunctionParameters (FunctionDecl *function_decl, ParmVarDecl
#pragma mark Array Types
-ClangASTType
-ClangASTContext::CreateArrayType (const ClangASTType &element_type,
+CompilerType
+ClangASTContext::CreateArrayType (const CompilerType &element_type,
size_t element_count,
bool is_vector)
{
@@ -1859,7 +2096,7 @@ ClangASTContext::CreateArrayType (const ClangASTType &element_type,
if (is_vector)
{
- return ClangASTType (ast, ast->getExtVectorType(element_type.GetQualType(), element_count).getAsOpaquePtr());
+ return CompilerType (ast, ast->getExtVectorType(GetQualType(element_type), element_count));
}
else
{
@@ -1867,59 +2104,59 @@ ClangASTContext::CreateArrayType (const ClangASTType &element_type,
llvm::APInt ap_element_count (64, element_count);
if (element_count == 0)
{
- return ClangASTType (ast, ast->getIncompleteArrayType (element_type.GetQualType(),
+ return CompilerType (ast, ast->getIncompleteArrayType (GetQualType(element_type),
ArrayType::Normal,
- 0).getAsOpaquePtr());
+ 0));
}
else
{
- return ClangASTType (ast, ast->getConstantArrayType (element_type.GetQualType(),
+ return CompilerType (ast, ast->getConstantArrayType (GetQualType(element_type),
ap_element_count,
ArrayType::Normal,
- 0).getAsOpaquePtr());
+ 0));
}
}
}
- return ClangASTType();
+ return CompilerType();
}
-ClangASTType
+CompilerType
ClangASTContext::GetOrCreateStructForIdentifier (const ConstString &type_name,
- const std::initializer_list< std::pair < const char *, ClangASTType > >& type_fields,
+ const std::initializer_list< std::pair < const char *, CompilerType > >& type_fields,
bool packed)
{
- ClangASTType type;
+ CompilerType type;
if ((type = GetTypeForIdentifier<clang::CXXRecordDecl>(type_name)).IsValid())
return type;
type = CreateRecordType(nullptr, lldb::eAccessPublic, type_name.GetCString(), clang::TTK_Struct, lldb::eLanguageTypeC);
- type.StartTagDeclarationDefinition();
+ StartTagDeclarationDefinition(type);
for (const auto& field : type_fields)
- type.AddFieldToRecordType(field.first, field.second, lldb::eAccessPublic, 0);
+ AddFieldToRecordType(type, field.first, field.second, lldb::eAccessPublic, 0);
if (packed)
- type.SetIsPacked();
- type.CompleteTagDeclarationDefinition();
+ SetIsPacked(type);
+ CompleteTagDeclarationDefinition(type);
return type;
}
#pragma mark Enumeration Types
-ClangASTType
-ClangASTContext::CreateEnumerationType
+CompilerType
+ClangASTContext::CreateEnumerationType
(
- const char *name,
- DeclContext *decl_ctx,
- const Declaration &decl,
- const ClangASTType &integer_clang_type
-)
+ const char *name,
+ DeclContext *decl_ctx,
+ const Declaration &decl,
+ const CompilerType &integer_clang_type
+ )
{
// TODO: Do something intelligent with the Declaration object passed in
// like maybe filling in the SourceLocation with it...
ASTContext *ast = getASTContext();
-
+
// TODO: ask about these...
-// const bool IsScoped = false;
-// const bool IsFixed = false;
-
+ // const bool IsScoped = false;
+ // const bool IsFixed = false;
+
EnumDecl *enum_decl = EnumDecl::Create (*ast,
decl_ctx,
SourceLocation(),
@@ -1934,13 +2171,13 @@ ClangASTContext::CreateEnumerationType
if (enum_decl)
{
// TODO: check if we should be setting the promotion type too?
- enum_decl->setIntegerType(integer_clang_type.GetQualType());
+ enum_decl->setIntegerType(GetQualType(integer_clang_type));
enum_decl->setAccess(AS_public); // TODO respect what's in the debug info
- return ClangASTType (ast, ast->getTagDeclType(enum_decl).getAsOpaquePtr());
+ return CompilerType (ast, ast->getTagDeclType(enum_decl));
}
- return ClangASTType();
+ return CompilerType();
}
// Disable this for now since I can't seem to get a nicely formatted float
@@ -1950,7 +2187,7 @@ ClangASTContext::CreateEnumerationType
// so we can support remote targets. The code below also requires a patch to
// llvm::APInt.
//bool
-//ClangASTContext::ConvertFloatValueToString (ASTContext *ast, clang_type_t clang_type, const uint8_t* bytes, size_t byte_size, int apint_byte_order, std::string &float_str)
+//ClangASTContext::ConvertFloatValueToString (ASTContext *ast, lldb::opaque_compiler_type_t clang_type, const uint8_t* bytes, size_t byte_size, int apint_byte_order, std::string &float_str)
//{
// uint32_t count = 0;
// bool is_complex = false;
@@ -1984,7 +2221,7 @@ ClangASTContext::CreateEnumerationType
// return false;
//}
-ClangASTType
+CompilerType
ClangASTContext::GetIntTypeFromBitSize (clang::ASTContext *ast,
size_t bit_size, bool is_signed)
{
@@ -1993,74 +2230,207 @@ ClangASTContext::GetIntTypeFromBitSize (clang::ASTContext *ast,
if (is_signed)
{
if (bit_size == ast->getTypeSize(ast->SignedCharTy))
- return ClangASTType(ast, ast->SignedCharTy.getAsOpaquePtr());
+ return CompilerType(ast, ast->SignedCharTy);
if (bit_size == ast->getTypeSize(ast->ShortTy))
- return ClangASTType(ast, ast->ShortTy.getAsOpaquePtr());
+ return CompilerType(ast, ast->ShortTy);
if (bit_size == ast->getTypeSize(ast->IntTy))
- return ClangASTType(ast, ast->IntTy.getAsOpaquePtr());
+ return CompilerType(ast, ast->IntTy);
if (bit_size == ast->getTypeSize(ast->LongTy))
- return ClangASTType(ast, ast->LongTy.getAsOpaquePtr());
+ return CompilerType(ast, ast->LongTy);
if (bit_size == ast->getTypeSize(ast->LongLongTy))
- return ClangASTType(ast, ast->LongLongTy.getAsOpaquePtr());
+ return CompilerType(ast, ast->LongLongTy);
if (bit_size == ast->getTypeSize(ast->Int128Ty))
- return ClangASTType(ast, ast->Int128Ty.getAsOpaquePtr());
+ return CompilerType(ast, ast->Int128Ty);
}
else
{
if (bit_size == ast->getTypeSize(ast->UnsignedCharTy))
- return ClangASTType(ast, ast->UnsignedCharTy.getAsOpaquePtr());
+ return CompilerType(ast, ast->UnsignedCharTy);
if (bit_size == ast->getTypeSize(ast->UnsignedShortTy))
- return ClangASTType(ast, ast->UnsignedShortTy.getAsOpaquePtr());
+ return CompilerType(ast, ast->UnsignedShortTy);
if (bit_size == ast->getTypeSize(ast->UnsignedIntTy))
- return ClangASTType(ast, ast->UnsignedIntTy.getAsOpaquePtr());
+ return CompilerType(ast, ast->UnsignedIntTy);
if (bit_size == ast->getTypeSize(ast->UnsignedLongTy))
- return ClangASTType(ast, ast->UnsignedLongTy.getAsOpaquePtr());
+ return CompilerType(ast, ast->UnsignedLongTy);
if (bit_size == ast->getTypeSize(ast->UnsignedLongLongTy))
- return ClangASTType(ast, ast->UnsignedLongLongTy.getAsOpaquePtr());
+ return CompilerType(ast, ast->UnsignedLongLongTy);
if (bit_size == ast->getTypeSize(ast->UnsignedInt128Ty))
- return ClangASTType(ast, ast->UnsignedInt128Ty.getAsOpaquePtr());
+ return CompilerType(ast, ast->UnsignedInt128Ty);
}
}
- return ClangASTType();
+ return CompilerType();
}
-ClangASTType
+CompilerType
ClangASTContext::GetPointerSizedIntType (clang::ASTContext *ast, bool is_signed)
{
if (ast)
return GetIntTypeFromBitSize(ast, ast->getTypeSize(ast->VoidPtrTy), is_signed);
- return ClangASTType();
+ return CompilerType();
}
-ClangASTType
-ClangASTContext::GetFloatTypeFromBitSize (clang::ASTContext *ast,
- size_t bit_size)
+void
+ClangASTContext::DumpDeclContextHiearchy (clang::DeclContext *decl_ctx)
{
- if (ast)
+ if (decl_ctx)
+ {
+ DumpDeclContextHiearchy (decl_ctx->getParent());
+
+ clang::NamedDecl *named_decl = llvm::dyn_cast<clang::NamedDecl>(decl_ctx);
+ if (named_decl)
+ {
+ printf ("%20s: %s\n", decl_ctx->getDeclKindName(), named_decl->getDeclName().getAsString().c_str());
+ }
+ else
+ {
+ printf ("%20s\n", decl_ctx->getDeclKindName());
+ }
+ }
+}
+
+void
+ClangASTContext::DumpDeclHiearchy (clang::Decl *decl)
+{
+ if (decl == nullptr)
+ return;
+ DumpDeclContextHiearchy(decl->getDeclContext());
+
+ clang::RecordDecl *record_decl = llvm::dyn_cast<clang::RecordDecl>(decl);
+ if (record_decl)
{
- if (bit_size == ast->getTypeSize(ast->FloatTy))
- return ClangASTType(ast, ast->FloatTy.getAsOpaquePtr());
- else if (bit_size == ast->getTypeSize(ast->DoubleTy))
- return ClangASTType(ast, ast->DoubleTy.getAsOpaquePtr());
- else if (bit_size == ast->getTypeSize(ast->LongDoubleTy))
- return ClangASTType(ast, ast->LongDoubleTy.getAsOpaquePtr());
- else if (bit_size == ast->getTypeSize(ast->HalfTy))
- return ClangASTType(ast, ast->HalfTy.getAsOpaquePtr());
+ printf ("%20s: %s%s\n", decl->getDeclKindName(), record_decl->getDeclName().getAsString().c_str(), record_decl->isInjectedClassName() ? " (injected class name)" : "");
+
+ }
+ else
+ {
+ clang::NamedDecl *named_decl = llvm::dyn_cast<clang::NamedDecl>(decl);
+ if (named_decl)
+ {
+ printf ("%20s: %s\n", decl->getDeclKindName(), named_decl->getDeclName().getAsString().c_str());
+ }
+ else
+ {
+ printf ("%20s\n", decl->getDeclKindName());
+ }
}
- return ClangASTType();
}
bool
+ClangASTContext::DeclsAreEquivalent (clang::Decl *lhs_decl, clang::Decl *rhs_decl)
+{
+ if (lhs_decl && rhs_decl)
+ {
+ //----------------------------------------------------------------------
+ // Make sure the decl kinds match first
+ //----------------------------------------------------------------------
+ const clang::Decl::Kind lhs_decl_kind = lhs_decl->getKind();
+ const clang::Decl::Kind rhs_decl_kind = rhs_decl->getKind();
+
+ if (lhs_decl_kind == rhs_decl_kind)
+ {
+ //------------------------------------------------------------------
+ // Now check that the decl contexts kinds are all equivalent
+ // before we have to check any names of the decl contexts...
+ //------------------------------------------------------------------
+ clang::DeclContext *lhs_decl_ctx = lhs_decl->getDeclContext();
+ clang::DeclContext *rhs_decl_ctx = rhs_decl->getDeclContext();
+ if (lhs_decl_ctx && rhs_decl_ctx)
+ {
+ while (1)
+ {
+ if (lhs_decl_ctx && rhs_decl_ctx)
+ {
+ const clang::Decl::Kind lhs_decl_ctx_kind = lhs_decl_ctx->getDeclKind();
+ const clang::Decl::Kind rhs_decl_ctx_kind = rhs_decl_ctx->getDeclKind();
+ if (lhs_decl_ctx_kind == rhs_decl_ctx_kind)
+ {
+ lhs_decl_ctx = lhs_decl_ctx->getParent();
+ rhs_decl_ctx = rhs_decl_ctx->getParent();
+
+ if (lhs_decl_ctx == nullptr && rhs_decl_ctx == nullptr)
+ break;
+ }
+ else
+ return false;
+ }
+ else
+ return false;
+ }
+
+ //--------------------------------------------------------------
+ // Now make sure the name of the decls match
+ //--------------------------------------------------------------
+ clang::NamedDecl *lhs_named_decl = llvm::dyn_cast<clang::NamedDecl>(lhs_decl);
+ clang::NamedDecl *rhs_named_decl = llvm::dyn_cast<clang::NamedDecl>(rhs_decl);
+ if (lhs_named_decl && rhs_named_decl)
+ {
+ clang::DeclarationName lhs_decl_name = lhs_named_decl->getDeclName();
+ clang::DeclarationName rhs_decl_name = rhs_named_decl->getDeclName();
+ if (lhs_decl_name.getNameKind() == rhs_decl_name.getNameKind())
+ {
+ if (lhs_decl_name.getAsString() != rhs_decl_name.getAsString())
+ return false;
+ }
+ else
+ return false;
+ }
+ else
+ return false;
+
+ //--------------------------------------------------------------
+ // We know that the decl context kinds all match, so now we need
+ // to make sure the names match as well
+ //--------------------------------------------------------------
+ lhs_decl_ctx = lhs_decl->getDeclContext();
+ rhs_decl_ctx = rhs_decl->getDeclContext();
+ while (1)
+ {
+ switch (lhs_decl_ctx->getDeclKind())
+ {
+ case clang::Decl::TranslationUnit:
+ // We don't care about the translation unit names
+ return true;
+ default:
+ {
+ clang::NamedDecl *lhs_named_decl = llvm::dyn_cast<clang::NamedDecl>(lhs_decl_ctx);
+ clang::NamedDecl *rhs_named_decl = llvm::dyn_cast<clang::NamedDecl>(rhs_decl_ctx);
+ if (lhs_named_decl && rhs_named_decl)
+ {
+ clang::DeclarationName lhs_decl_name = lhs_named_decl->getDeclName();
+ clang::DeclarationName rhs_decl_name = rhs_named_decl->getDeclName();
+ if (lhs_decl_name.getNameKind() == rhs_decl_name.getNameKind())
+ {
+ if (lhs_decl_name.getAsString() != rhs_decl_name.getAsString())
+ return false;
+ }
+ else
+ return false;
+ }
+ else
+ return false;
+ }
+ break;
+
+ }
+ lhs_decl_ctx = lhs_decl_ctx->getParent();
+ rhs_decl_ctx = rhs_decl_ctx->getParent();
+ }
+ }
+ }
+ }
+ return false;
+}
+bool
ClangASTContext::GetCompleteDecl (clang::ASTContext *ast,
clang::Decl *decl)
{
@@ -2148,46 +2518,7484 @@ ClangASTContext::GetAsDeclContext (clang::ObjCMethodDecl *objc_method_decl)
return llvm::dyn_cast<clang::DeclContext>(objc_method_decl);
}
+bool
+ClangASTContext::SetTagTypeKind (clang::QualType tag_qual_type, int kind) const
+{
+ const clang::Type *clang_type = tag_qual_type.getTypePtr();
+ if (clang_type)
+ {
+ const clang::TagType *tag_type = llvm::dyn_cast<clang::TagType>(clang_type);
+ if (tag_type)
+ {
+ clang::TagDecl *tag_decl = llvm::dyn_cast<clang::TagDecl>(tag_type->getDecl());
+ if (tag_decl)
+ {
+ tag_decl->setTagKind ((clang::TagDecl::TagKind)kind);
+ return true;
+ }
+ }
+ }
+ return false;
+}
+
bool
-ClangASTContext::GetClassMethodInfoForDeclContext (clang::DeclContext *decl_ctx,
- lldb::LanguageType &language,
- bool &is_instance_method,
- ConstString &language_object_name)
+ClangASTContext::SetDefaultAccessForRecordFields (clang::RecordDecl* record_decl,
+ int default_accessibility,
+ int *assigned_accessibilities,
+ size_t num_assigned_accessibilities)
{
- language_object_name.Clear();
- language = eLanguageTypeUnknown;
- is_instance_method = false;
+ if (record_decl)
+ {
+ uint32_t field_idx;
+ clang::RecordDecl::field_iterator field, field_end;
+ for (field = record_decl->field_begin(), field_end = record_decl->field_end(), field_idx = 0;
+ field != field_end;
+ ++field, ++field_idx)
+ {
+ // If no accessibility was assigned, assign the correct one
+ if (field_idx < num_assigned_accessibilities && assigned_accessibilities[field_idx] == clang::AS_none)
+ field->setAccess ((clang::AccessSpecifier)default_accessibility);
+ }
+ return true;
+ }
+ return false;
+}
- if (decl_ctx)
+clang::DeclContext *
+ClangASTContext::GetDeclContextForType (const CompilerType& type)
+{
+ return GetDeclContextForType(GetQualType(type));
+}
+
+clang::DeclContext *
+ClangASTContext::GetDeclContextForType (clang::QualType type)
+{
+ if (type.isNull())
+ return nullptr;
+
+ clang::QualType qual_type = type.getCanonicalType();
+ const clang::Type::TypeClass type_class = qual_type->getTypeClass();
+ switch (type_class)
+ {
+ case clang::Type::ObjCInterface: return llvm::cast<clang::ObjCObjectType>(qual_type.getTypePtr())->getInterface();
+ case clang::Type::ObjCObjectPointer: return GetDeclContextForType (llvm::cast<clang::ObjCObjectPointerType>(qual_type.getTypePtr())->getPointeeType());
+ case clang::Type::Record: return llvm::cast<clang::RecordType>(qual_type)->getDecl();
+ case clang::Type::Enum: return llvm::cast<clang::EnumType>(qual_type)->getDecl();
+ case clang::Type::Typedef: return GetDeclContextForType (llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType());
+ case clang::Type::Auto: return GetDeclContextForType (llvm::cast<clang::AutoType>(qual_type)->getDeducedType());
+ case clang::Type::Elaborated: return GetDeclContextForType (llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType());
+ case clang::Type::Paren: return GetDeclContextForType (llvm::cast<clang::ParenType>(qual_type)->desugar());
+ default:
+ break;
+ }
+ // No DeclContext in this type...
+ return nullptr;
+}
+
+static bool
+GetCompleteQualType (clang::ASTContext *ast, clang::QualType qual_type, bool allow_completion = true)
+{
+ const clang::Type::TypeClass type_class = qual_type->getTypeClass();
+ switch (type_class)
+ {
+ case clang::Type::ConstantArray:
+ case clang::Type::IncompleteArray:
+ case clang::Type::VariableArray:
+ {
+ const clang::ArrayType *array_type = llvm::dyn_cast<clang::ArrayType>(qual_type.getTypePtr());
+
+ if (array_type)
+ return GetCompleteQualType (ast, array_type->getElementType(), allow_completion);
+ }
+ break;
+ case clang::Type::Record:
+ {
+ clang::CXXRecordDecl *cxx_record_decl = qual_type->getAsCXXRecordDecl();
+ if (cxx_record_decl)
+ {
+ if (cxx_record_decl->hasExternalLexicalStorage())
+ {
+ const bool is_complete = cxx_record_decl->isCompleteDefinition();
+ const bool fields_loaded = cxx_record_decl->hasLoadedFieldsFromExternalStorage();
+ if (is_complete && fields_loaded)
+ return true;
+
+ if (!allow_completion)
+ return false;
+
+ // Call the field_begin() accessor to for it to use the external source
+ // to load the fields...
+ clang::ExternalASTSource *external_ast_source = ast->getExternalSource();
+ if (external_ast_source)
+ {
+ external_ast_source->CompleteType(cxx_record_decl);
+ if (cxx_record_decl->isCompleteDefinition())
+ {
+ cxx_record_decl->setHasLoadedFieldsFromExternalStorage (true);
+ cxx_record_decl->field_begin();
+ }
+ }
+ }
+ }
+ const clang::TagType *tag_type = llvm::cast<clang::TagType>(qual_type.getTypePtr());
+ return !tag_type->isIncompleteType();
+ }
+ break;
+
+ case clang::Type::Enum:
+ {
+ const clang::TagType *tag_type = llvm::dyn_cast<clang::TagType>(qual_type.getTypePtr());
+ if (tag_type)
+ {
+ clang::TagDecl *tag_decl = tag_type->getDecl();
+ if (tag_decl)
+ {
+ if (tag_decl->getDefinition())
+ return true;
+
+ if (!allow_completion)
+ return false;
+
+ if (tag_decl->hasExternalLexicalStorage())
+ {
+ if (ast)
+ {
+ clang::ExternalASTSource *external_ast_source = ast->getExternalSource();
+ if (external_ast_source)
+ {
+ external_ast_source->CompleteType(tag_decl);
+ return !tag_type->isIncompleteType();
+ }
+ }
+ }
+ return false;
+ }
+ }
+
+ }
+ break;
+ case clang::Type::ObjCObject:
+ case clang::Type::ObjCInterface:
+ {
+ const clang::ObjCObjectType *objc_class_type = llvm::dyn_cast<clang::ObjCObjectType>(qual_type);
+ if (objc_class_type)
+ {
+ clang::ObjCInterfaceDecl *class_interface_decl = objc_class_type->getInterface();
+ // We currently can't complete objective C types through the newly added ASTContext
+ // because it only supports TagDecl objects right now...
+ if (class_interface_decl)
+ {
+ if (class_interface_decl->getDefinition())
+ return true;
+
+ if (!allow_completion)
+ return false;
+
+ if (class_interface_decl->hasExternalLexicalStorage())
+ {
+ if (ast)
+ {
+ clang::ExternalASTSource *external_ast_source = ast->getExternalSource();
+ if (external_ast_source)
+ {
+ external_ast_source->CompleteType (class_interface_decl);
+ return !objc_class_type->isIncompleteType();
+ }
+ }
+ }
+ return false;
+ }
+ }
+ }
+ break;
+
+ case clang::Type::Typedef:
+ return GetCompleteQualType (ast, llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType(), allow_completion);
+
+ case clang::Type::Auto:
+ return GetCompleteQualType (ast, llvm::cast<clang::AutoType>(qual_type)->getDeducedType(), allow_completion);
+
+ case clang::Type::Elaborated:
+ return GetCompleteQualType (ast, llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType(), allow_completion);
+
+ case clang::Type::Paren:
+ return GetCompleteQualType (ast, llvm::cast<clang::ParenType>(qual_type)->desugar(), allow_completion);
+
+ case clang::Type::Attributed:
+ return GetCompleteQualType (ast, llvm::cast<clang::AttributedType>(qual_type)->getModifiedType(), allow_completion);
+
+ default:
+ break;
+ }
+
+ return true;
+}
+
+static clang::ObjCIvarDecl::AccessControl
+ConvertAccessTypeToObjCIvarAccessControl (AccessType access)
+{
+ switch (access)
+ {
+ case eAccessNone: return clang::ObjCIvarDecl::None;
+ case eAccessPublic: return clang::ObjCIvarDecl::Public;
+ case eAccessPrivate: return clang::ObjCIvarDecl::Private;
+ case eAccessProtected: return clang::ObjCIvarDecl::Protected;
+ case eAccessPackage: return clang::ObjCIvarDecl::Package;
+ }
+ return clang::ObjCIvarDecl::None;
+}
+
+
+//----------------------------------------------------------------------
+// Tests
+//----------------------------------------------------------------------
+
+bool
+ClangASTContext::IsAggregateType (lldb::opaque_compiler_type_t type)
+{
+ clang::QualType qual_type (GetCanonicalQualType(type));
+
+ const clang::Type::TypeClass type_class = qual_type->getTypeClass();
+ switch (type_class)
+ {
+ case clang::Type::IncompleteArray:
+ case clang::Type::VariableArray:
+ case clang::Type::ConstantArray:
+ case clang::Type::ExtVector:
+ case clang::Type::Vector:
+ case clang::Type::Record:
+ case clang::Type::ObjCObject:
+ case clang::Type::ObjCInterface:
+ return true;
+ case clang::Type::Auto:
+ return IsAggregateType(llvm::cast<clang::AutoType>(qual_type)->getDeducedType().getAsOpaquePtr());
+ case clang::Type::Elaborated:
+ return IsAggregateType(llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType().getAsOpaquePtr());
+ case clang::Type::Typedef:
+ return IsAggregateType(llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType().getAsOpaquePtr());
+ case clang::Type::Paren:
+ return IsAggregateType(llvm::cast<clang::ParenType>(qual_type)->desugar().getAsOpaquePtr());
+ default:
+ break;
+ }
+ // The clang type does have a value
+ return false;
+}
+
+bool
+ClangASTContext::IsAnonymousType (lldb::opaque_compiler_type_t type)
+{
+ clang::QualType qual_type (GetCanonicalQualType(type));
+
+ const clang::Type::TypeClass type_class = qual_type->getTypeClass();
+ switch (type_class)
+ {
+ case clang::Type::Record:
+ {
+ if (const clang::RecordType *record_type = llvm::dyn_cast_or_null<clang::RecordType>(qual_type.getTypePtrOrNull()))
+ {
+ if (const clang::RecordDecl *record_decl = record_type->getDecl())
+ {
+ return record_decl->isAnonymousStructOrUnion();
+ }
+ }
+ break;
+ }
+ case clang::Type::Auto:
+ return IsAnonymousType(llvm::cast<clang::AutoType>(qual_type)->getDeducedType().getAsOpaquePtr());
+ case clang::Type::Elaborated:
+ return IsAnonymousType(llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType().getAsOpaquePtr());
+ case clang::Type::Typedef:
+ return IsAnonymousType(llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType().getAsOpaquePtr());
+ case clang::Type::Paren:
+ return IsAnonymousType(llvm::cast<clang::ParenType>(qual_type)->desugar().getAsOpaquePtr());
+ default:
+ break;
+ }
+ // The clang type does have a value
+ return false;
+}
+
+bool
+ClangASTContext::IsArrayType (lldb::opaque_compiler_type_t type,
+ CompilerType *element_type_ptr,
+ uint64_t *size,
+ bool *is_incomplete)
+{
+ clang::QualType qual_type (GetCanonicalQualType(type));
+
+ const clang::Type::TypeClass type_class = qual_type->getTypeClass();
+ switch (type_class)
+ {
+ default:
+ break;
+
+ case clang::Type::ConstantArray:
+ if (element_type_ptr)
+ element_type_ptr->SetCompilerType (getASTContext(), llvm::cast<clang::ConstantArrayType>(qual_type)->getElementType());
+ if (size)
+ *size = llvm::cast<clang::ConstantArrayType>(qual_type)->getSize().getLimitedValue(ULLONG_MAX);
+ if (is_incomplete)
+ *is_incomplete = false;
+ return true;
+
+ case clang::Type::IncompleteArray:
+ if (element_type_ptr)
+ element_type_ptr->SetCompilerType (getASTContext(), llvm::cast<clang::IncompleteArrayType>(qual_type)->getElementType());
+ if (size)
+ *size = 0;
+ if (is_incomplete)
+ *is_incomplete = true;
+ return true;
+
+ case clang::Type::VariableArray:
+ if (element_type_ptr)
+ element_type_ptr->SetCompilerType (getASTContext(), llvm::cast<clang::VariableArrayType>(qual_type)->getElementType());
+ if (size)
+ *size = 0;
+ if (is_incomplete)
+ *is_incomplete = false;
+ return true;
+
+ case clang::Type::DependentSizedArray:
+ if (element_type_ptr)
+ element_type_ptr->SetCompilerType (getASTContext(), llvm::cast<clang::DependentSizedArrayType>(qual_type)->getElementType());
+ if (size)
+ *size = 0;
+ if (is_incomplete)
+ *is_incomplete = false;
+ return true;
+
+ case clang::Type::Typedef:
+ return IsArrayType(llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType().getAsOpaquePtr(),
+ element_type_ptr,
+ size,
+ is_incomplete);
+ case clang::Type::Auto:
+ return IsArrayType(llvm::cast<clang::AutoType>(qual_type)->getDeducedType().getAsOpaquePtr(),
+ element_type_ptr,
+ size,
+ is_incomplete);
+ case clang::Type::Elaborated:
+ return IsArrayType(llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType().getAsOpaquePtr(),
+ element_type_ptr,
+ size,
+ is_incomplete);
+ case clang::Type::Paren:
+ return IsArrayType(llvm::cast<clang::ParenType>(qual_type)->desugar().getAsOpaquePtr(),
+ element_type_ptr,
+ size,
+ is_incomplete);
+ }
+ if (element_type_ptr)
+ element_type_ptr->Clear();
+ if (size)
+ *size = 0;
+ if (is_incomplete)
+ *is_incomplete = false;
+ return false;
+}
+
+bool
+ClangASTContext::IsVectorType (lldb::opaque_compiler_type_t type,
+ CompilerType *element_type,
+ uint64_t *size)
+{
+ clang::QualType qual_type (GetCanonicalQualType(type));
+
+ const clang::Type::TypeClass type_class = qual_type->getTypeClass();
+ switch (type_class)
+ {
+ case clang::Type::Vector:
+ {
+ const clang::VectorType *vector_type = qual_type->getAs<clang::VectorType>();
+ if (vector_type)
+ {
+ if (size)
+ *size = vector_type->getNumElements();
+ if (element_type)
+ *element_type = CompilerType(getASTContext(), vector_type->getElementType());
+ }
+ return true;
+ }
+ break;
+ case clang::Type::ExtVector:
+ {
+ const clang::ExtVectorType *ext_vector_type = qual_type->getAs<clang::ExtVectorType>();
+ if (ext_vector_type)
+ {
+ if (size)
+ *size = ext_vector_type->getNumElements();
+ if (element_type)
+ *element_type = CompilerType(getASTContext(), ext_vector_type->getElementType());
+ }
+ return true;
+ }
+ default:
+ break;
+ }
+ return false;
+}
+
+bool
+ClangASTContext::IsRuntimeGeneratedType (lldb::opaque_compiler_type_t type)
+{
+ clang::DeclContext* decl_ctx = ClangASTContext::GetASTContext(getASTContext())->GetDeclContextForType(GetQualType(type));
+ if (!decl_ctx)
+ return false;
+
+ if (!llvm::isa<clang::ObjCInterfaceDecl>(decl_ctx))
+ return false;
+
+ clang::ObjCInterfaceDecl *result_iface_decl = llvm::dyn_cast<clang::ObjCInterfaceDecl>(decl_ctx);
+
+ ClangASTMetadata* ast_metadata = ClangASTContext::GetMetadata(getASTContext(), result_iface_decl);
+ if (!ast_metadata)
+ return false;
+ return (ast_metadata->GetISAPtr() != 0);
+}
+
+bool
+ClangASTContext::IsCharType (lldb::opaque_compiler_type_t type)
+{
+ return GetQualType(type).getUnqualifiedType()->isCharType();
+}
+
+
+bool
+ClangASTContext::IsCompleteType (lldb::opaque_compiler_type_t type)
+{
+ const bool allow_completion = false;
+ return GetCompleteQualType (getASTContext(), GetQualType(type), allow_completion);
+}
+
+bool
+ClangASTContext::IsConst(lldb::opaque_compiler_type_t type)
+{
+ return GetQualType(type).isConstQualified();
+}
+
+bool
+ClangASTContext::IsCStringType (lldb::opaque_compiler_type_t type, uint32_t &length)
+{
+ CompilerType pointee_or_element_clang_type;
+ length = 0;
+ Flags type_flags (GetTypeInfo (type, &pointee_or_element_clang_type));
+
+ if (!pointee_or_element_clang_type.IsValid())
+ return false;
+
+ if (type_flags.AnySet (eTypeIsArray | eTypeIsPointer))
+ {
+ if (pointee_or_element_clang_type.IsCharType())
+ {
+ if (type_flags.Test (eTypeIsArray))
+ {
+ // We know the size of the array and it could be a C string
+ // since it is an array of characters
+ length = llvm::cast<clang::ConstantArrayType>(GetCanonicalQualType(type).getTypePtr())->getSize().getLimitedValue();
+ }
+ return true;
+
+ }
+ }
+ return false;
+}
+
+bool
+ClangASTContext::IsFunctionType (lldb::opaque_compiler_type_t type, bool *is_variadic_ptr)
+{
+ if (type)
+ {
+ clang::QualType qual_type (GetCanonicalQualType(type));
+
+ if (qual_type->isFunctionType())
+ {
+ if (is_variadic_ptr)
+ {
+ const clang::FunctionProtoType *function_proto_type = llvm::dyn_cast<clang::FunctionProtoType>(qual_type.getTypePtr());
+ if (function_proto_type)
+ *is_variadic_ptr = function_proto_type->isVariadic();
+ else
+ *is_variadic_ptr = false;
+ }
+ return true;
+ }
+
+ const clang::Type::TypeClass type_class = qual_type->getTypeClass();
+ switch (type_class)
+ {
+ default:
+ break;
+ case clang::Type::Typedef:
+ return IsFunctionType(llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType().getAsOpaquePtr(), nullptr);
+ case clang::Type::Auto:
+ return IsFunctionType(llvm::cast<clang::AutoType>(qual_type)->getDeducedType().getAsOpaquePtr(), nullptr);
+ case clang::Type::Elaborated:
+ return IsFunctionType(llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType().getAsOpaquePtr(), nullptr);
+ case clang::Type::Paren:
+ return IsFunctionType(llvm::cast<clang::ParenType>(qual_type)->desugar().getAsOpaquePtr(), nullptr);
+ case clang::Type::LValueReference:
+ case clang::Type::RValueReference:
+ {
+ const clang::ReferenceType *reference_type = llvm::cast<clang::ReferenceType>(qual_type.getTypePtr());
+ if (reference_type)
+ return IsFunctionType(reference_type->getPointeeType().getAsOpaquePtr(), nullptr);
+ }
+ break;
+ }
+ }
+ return false;
+}
+
+// Used to detect "Homogeneous Floating-point Aggregates"
+uint32_t
+ClangASTContext::IsHomogeneousAggregate (lldb::opaque_compiler_type_t type, CompilerType* base_type_ptr)
+{
+ if (!type)
+ return 0;
+
+ clang::QualType qual_type(GetCanonicalQualType(type));
+ const clang::Type::TypeClass type_class = qual_type->getTypeClass();
+ switch (type_class)
+ {
+ case clang::Type::Record:
+ if (GetCompleteType (type))
+ {
+ const clang::CXXRecordDecl *cxx_record_decl = qual_type->getAsCXXRecordDecl();
+ if (cxx_record_decl)
+ {
+ if (cxx_record_decl->getNumBases() ||
+ cxx_record_decl->isDynamicClass())
+ return 0;
+ }
+ const clang::RecordType *record_type = llvm::cast<clang::RecordType>(qual_type.getTypePtr());
+ if (record_type)
+ {
+ const clang::RecordDecl *record_decl = record_type->getDecl();
+ if (record_decl)
+ {
+ // We are looking for a structure that contains only floating point types
+ clang::RecordDecl::field_iterator field_pos, field_end = record_decl->field_end();
+ uint32_t num_fields = 0;
+ bool is_hva = false;
+ bool is_hfa = false;
+ clang::QualType base_qual_type;
+ for (field_pos = record_decl->field_begin(); field_pos != field_end; ++field_pos)
+ {
+ clang::QualType field_qual_type = field_pos->getType();
+ if (field_qual_type->isFloatingType())
+ {
+ if (field_qual_type->isComplexType())
+ return 0;
+ else
+ {
+ if (num_fields == 0)
+ base_qual_type = field_qual_type;
+ else
+ {
+ if (is_hva)
+ return 0;
+ is_hfa = true;
+ if (field_qual_type.getTypePtr() != base_qual_type.getTypePtr())
+ return 0;
+ }
+ }
+ }
+ else if (field_qual_type->isVectorType() || field_qual_type->isExtVectorType())
+ {
+ const clang::VectorType *array = field_qual_type.getTypePtr()->getAs<clang::VectorType>();
+ if (array && array->getNumElements() <= 4)
+ {
+ if (num_fields == 0)
+ base_qual_type = array->getElementType();
+ else
+ {
+ if (is_hfa)
+ return 0;
+ is_hva = true;
+ if (field_qual_type.getTypePtr() != base_qual_type.getTypePtr())
+ return 0;
+ }
+ }
+ else
+ return 0;
+ }
+ else
+ return 0;
+ ++num_fields;
+ }
+ if (base_type_ptr)
+ *base_type_ptr = CompilerType (getASTContext(), base_qual_type);
+ return num_fields;
+ }
+ }
+ }
+ break;
+
+ case clang::Type::Typedef:
+ return IsHomogeneousAggregate(llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType().getAsOpaquePtr(), base_type_ptr);
+
+ case clang::Type::Auto:
+ return IsHomogeneousAggregate(llvm::cast<clang::AutoType>(qual_type)->getDeducedType().getAsOpaquePtr(), base_type_ptr);
+
+ case clang::Type::Elaborated:
+ return IsHomogeneousAggregate(llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType().getAsOpaquePtr(), base_type_ptr);
+ default:
+ break;
+ }
+ return 0;
+}
+
+size_t
+ClangASTContext::GetNumberOfFunctionArguments (lldb::opaque_compiler_type_t type)
+{
+ if (type)
+ {
+ clang::QualType qual_type (GetCanonicalQualType(type));
+ const clang::FunctionProtoType* func = llvm::dyn_cast<clang::FunctionProtoType>(qual_type.getTypePtr());
+ if (func)
+ return func->getNumParams();
+ }
+ return 0;
+}
+
+CompilerType
+ClangASTContext::GetFunctionArgumentAtIndex (lldb::opaque_compiler_type_t type, const size_t index)
+{
+ if (type)
+ {
+ clang::QualType qual_type (GetCanonicalQualType(type));
+ const clang::FunctionProtoType* func = llvm::dyn_cast<clang::FunctionProtoType>(qual_type.getTypePtr());
+ if (func)
+ {
+ if (index < func->getNumParams())
+ return CompilerType(getASTContext(), func->getParamType(index));
+ }
+ }
+ return CompilerType();
+}
+
+bool
+ClangASTContext::IsFunctionPointerType (lldb::opaque_compiler_type_t type)
+{
+ if (type)
+ {
+ clang::QualType qual_type (GetCanonicalQualType(type));
+
+ if (qual_type->isFunctionPointerType())
+ return true;
+
+ const clang::Type::TypeClass type_class = qual_type->getTypeClass();
+ switch (type_class)
+ {
+ default:
+ break;
+ case clang::Type::Typedef:
+ return IsFunctionPointerType (llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType().getAsOpaquePtr());
+ case clang::Type::Auto:
+ return IsFunctionPointerType (llvm::cast<clang::AutoType>(qual_type)->getDeducedType().getAsOpaquePtr());
+ case clang::Type::Elaborated:
+ return IsFunctionPointerType (llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType().getAsOpaquePtr());
+ case clang::Type::Paren:
+ return IsFunctionPointerType (llvm::cast<clang::ParenType>(qual_type)->desugar().getAsOpaquePtr());
+
+ case clang::Type::LValueReference:
+ case clang::Type::RValueReference:
+ {
+ const clang::ReferenceType *reference_type = llvm::cast<clang::ReferenceType>(qual_type.getTypePtr());
+ if (reference_type)
+ return IsFunctionPointerType(reference_type->getPointeeType().getAsOpaquePtr());
+ }
+ break;
+ }
+ }
+ return false;
+
+}
+
+bool
+ClangASTContext::IsIntegerType (lldb::opaque_compiler_type_t type, bool &is_signed)
+{
+ if (!type)
+ return false;
+
+ clang::QualType qual_type (GetCanonicalQualType(type));
+ const clang::BuiltinType *builtin_type = llvm::dyn_cast<clang::BuiltinType>(qual_type->getCanonicalTypeInternal());
+
+ if (builtin_type)
+ {
+ if (builtin_type->isInteger())
+ {
+ is_signed = builtin_type->isSignedInteger();
+ return true;
+ }
+ }
+
+ return false;
+}
+
+bool
+ClangASTContext::IsPointerType (lldb::opaque_compiler_type_t type, CompilerType *pointee_type)
+{
+ if (type)
+ {
+ clang::QualType qual_type (GetCanonicalQualType(type));
+ const clang::Type::TypeClass type_class = qual_type->getTypeClass();
+ switch (type_class)
+ {
+ case clang::Type::Builtin:
+ switch (llvm::cast<clang::BuiltinType>(qual_type)->getKind())
+ {
+ default:
+ break;
+ case clang::BuiltinType::ObjCId:
+ case clang::BuiltinType::ObjCClass:
+ return true;
+ }
+ return false;
+ case clang::Type::ObjCObjectPointer:
+ if (pointee_type)
+ pointee_type->SetCompilerType (getASTContext(), llvm::cast<clang::ObjCObjectPointerType>(qual_type)->getPointeeType());
+ return true;
+ case clang::Type::BlockPointer:
+ if (pointee_type)
+ pointee_type->SetCompilerType (getASTContext(), llvm::cast<clang::BlockPointerType>(qual_type)->getPointeeType());
+ return true;
+ case clang::Type::Pointer:
+ if (pointee_type)
+ pointee_type->SetCompilerType (getASTContext(), llvm::cast<clang::PointerType>(qual_type)->getPointeeType());
+ return true;
+ case clang::Type::MemberPointer:
+ if (pointee_type)
+ pointee_type->SetCompilerType (getASTContext(), llvm::cast<clang::MemberPointerType>(qual_type)->getPointeeType());
+ return true;
+ case clang::Type::Typedef:
+ return IsPointerType (llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType().getAsOpaquePtr(), pointee_type);
+ case clang::Type::Auto:
+ return IsPointerType (llvm::cast<clang::AutoType>(qual_type)->getDeducedType().getAsOpaquePtr(), pointee_type);
+ case clang::Type::Elaborated:
+ return IsPointerType (llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType().getAsOpaquePtr(), pointee_type);
+ case clang::Type::Paren:
+ return IsPointerType (llvm::cast<clang::ParenType>(qual_type)->desugar().getAsOpaquePtr(), pointee_type);
+ default:
+ break;
+ }
+ }
+ if (pointee_type)
+ pointee_type->Clear();
+ return false;
+}
+
+
+bool
+ClangASTContext::IsPointerOrReferenceType (lldb::opaque_compiler_type_t type, CompilerType *pointee_type)
+{
+ if (type)
+ {
+ clang::QualType qual_type (GetCanonicalQualType(type));
+ const clang::Type::TypeClass type_class = qual_type->getTypeClass();
+ switch (type_class)
+ {
+ case clang::Type::Builtin:
+ switch (llvm::cast<clang::BuiltinType>(qual_type)->getKind())
+ {
+ default:
+ break;
+ case clang::BuiltinType::ObjCId:
+ case clang::BuiltinType::ObjCClass:
+ return true;
+ }
+ return false;
+ case clang::Type::ObjCObjectPointer:
+ if (pointee_type)
+ pointee_type->SetCompilerType(getASTContext(), llvm::cast<clang::ObjCObjectPointerType>(qual_type)->getPointeeType());
+ return true;
+ case clang::Type::BlockPointer:
+ if (pointee_type)
+ pointee_type->SetCompilerType(getASTContext(), llvm::cast<clang::BlockPointerType>(qual_type)->getPointeeType());
+ return true;
+ case clang::Type::Pointer:
+ if (pointee_type)
+ pointee_type->SetCompilerType(getASTContext(), llvm::cast<clang::PointerType>(qual_type)->getPointeeType());
+ return true;
+ case clang::Type::MemberPointer:
+ if (pointee_type)
+ pointee_type->SetCompilerType(getASTContext(), llvm::cast<clang::MemberPointerType>(qual_type)->getPointeeType());
+ return true;
+ case clang::Type::LValueReference:
+ if (pointee_type)
+ pointee_type->SetCompilerType(getASTContext(), llvm::cast<clang::LValueReferenceType>(qual_type)->desugar());
+ return true;
+ case clang::Type::RValueReference:
+ if (pointee_type)
+ pointee_type->SetCompilerType(getASTContext(), llvm::cast<clang::RValueReferenceType>(qual_type)->desugar());
+ return true;
+ case clang::Type::Typedef:
+ return IsPointerOrReferenceType(llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType().getAsOpaquePtr(), pointee_type);
+ case clang::Type::Auto:
+ return IsPointerOrReferenceType(llvm::cast<clang::AutoType>(qual_type)->getDeducedType().getAsOpaquePtr(), pointee_type);
+ case clang::Type::Elaborated:
+ return IsPointerOrReferenceType(llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType().getAsOpaquePtr(), pointee_type);
+ case clang::Type::Paren:
+ return IsPointerOrReferenceType(llvm::cast<clang::ParenType>(qual_type)->desugar().getAsOpaquePtr(), pointee_type);
+ default:
+ break;
+ }
+ }
+ if (pointee_type)
+ pointee_type->Clear();
+ return false;
+}
+
+
+bool
+ClangASTContext::IsReferenceType (lldb::opaque_compiler_type_t type, CompilerType *pointee_type, bool* is_rvalue)
+{
+ if (type)
+ {
+ clang::QualType qual_type (GetCanonicalQualType(type));
+ const clang::Type::TypeClass type_class = qual_type->getTypeClass();
+
+ switch (type_class)
+ {
+ case clang::Type::LValueReference:
+ if (pointee_type)
+ pointee_type->SetCompilerType(getASTContext(), llvm::cast<clang::LValueReferenceType>(qual_type)->desugar());
+ if (is_rvalue)
+ *is_rvalue = false;
+ return true;
+ case clang::Type::RValueReference:
+ if (pointee_type)
+ pointee_type->SetCompilerType(getASTContext(), llvm::cast<clang::RValueReferenceType>(qual_type)->desugar());
+ if (is_rvalue)
+ *is_rvalue = true;
+ return true;
+ case clang::Type::Typedef:
+ return IsReferenceType (llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType().getAsOpaquePtr(), pointee_type, is_rvalue);
+ case clang::Type::Auto:
+ return IsReferenceType (llvm::cast<clang::AutoType>(qual_type)->getDeducedType().getAsOpaquePtr(), pointee_type, is_rvalue);
+ case clang::Type::Elaborated:
+ return IsReferenceType (llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType().getAsOpaquePtr(), pointee_type, is_rvalue);
+ case clang::Type::Paren:
+ return IsReferenceType (llvm::cast<clang::ParenType>(qual_type)->desugar().getAsOpaquePtr(), pointee_type, is_rvalue);
+
+ default:
+ break;
+ }
+ }
+ if (pointee_type)
+ pointee_type->Clear();
+ return false;
+}
+
+bool
+ClangASTContext::IsFloatingPointType (lldb::opaque_compiler_type_t type, uint32_t &count, bool &is_complex)
+{
+ if (type)
+ {
+ clang::QualType qual_type (GetCanonicalQualType(type));
+
+ if (const clang::BuiltinType *BT = llvm::dyn_cast<clang::BuiltinType>(qual_type->getCanonicalTypeInternal()))
+ {
+ clang::BuiltinType::Kind kind = BT->getKind();
+ if (kind >= clang::BuiltinType::Float && kind <= clang::BuiltinType::LongDouble)
+ {
+ count = 1;
+ is_complex = false;
+ return true;
+ }
+ }
+ else if (const clang::ComplexType *CT = llvm::dyn_cast<clang::ComplexType>(qual_type->getCanonicalTypeInternal()))
+ {
+ if (IsFloatingPointType (CT->getElementType().getAsOpaquePtr(), count, is_complex))
+ {
+ count = 2;
+ is_complex = true;
+ return true;
+ }
+ }
+ else if (const clang::VectorType *VT = llvm::dyn_cast<clang::VectorType>(qual_type->getCanonicalTypeInternal()))
+ {
+ if (IsFloatingPointType (VT->getElementType().getAsOpaquePtr(), count, is_complex))
+ {
+ count = VT->getNumElements();
+ is_complex = false;
+ return true;
+ }
+ }
+ }
+ count = 0;
+ is_complex = false;
+ return false;
+}
+
+
+bool
+ClangASTContext::IsDefined(lldb::opaque_compiler_type_t type)
+{
+ if (!type)
+ return false;
+
+ clang::QualType qual_type(GetQualType(type));
+ const clang::TagType *tag_type = llvm::dyn_cast<clang::TagType>(qual_type.getTypePtr());
+ if (tag_type)
+ {
+ clang::TagDecl *tag_decl = tag_type->getDecl();
+ if (tag_decl)
+ return tag_decl->isCompleteDefinition();
+ return false;
+ }
+ else
+ {
+ const clang::ObjCObjectType *objc_class_type = llvm::dyn_cast<clang::ObjCObjectType>(qual_type);
+ if (objc_class_type)
+ {
+ clang::ObjCInterfaceDecl *class_interface_decl = objc_class_type->getInterface();
+ if (class_interface_decl)
+ return class_interface_decl->getDefinition() != nullptr;
+ return false;
+ }
+ }
+ return true;
+}
+
+bool
+ClangASTContext::IsObjCClassType (const CompilerType& type)
+{
+ if (type)
+ {
+ clang::QualType qual_type (GetCanonicalQualType(type));
+
+ const clang::ObjCObjectPointerType *obj_pointer_type = llvm::dyn_cast<clang::ObjCObjectPointerType>(qual_type);
+
+ if (obj_pointer_type)
+ return obj_pointer_type->isObjCClassType();
+ }
+ return false;
+}
+
+bool
+ClangASTContext::IsObjCObjectOrInterfaceType (const CompilerType& type)
+{
+ if (IsClangType(type))
+ return GetCanonicalQualType(type)->isObjCObjectOrInterfaceType();
+ return false;
+}
+
+bool
+ClangASTContext::IsPolymorphicClass (lldb::opaque_compiler_type_t type)
+{
+ if (type)
+ {
+ clang::QualType qual_type(GetCanonicalQualType(type));
+ const clang::Type::TypeClass type_class = qual_type->getTypeClass();
+ switch (type_class)
+ {
+ case clang::Type::Record:
+ if (GetCompleteType(type))
+ {
+ const clang::RecordType *record_type = llvm::cast<clang::RecordType>(qual_type.getTypePtr());
+ const clang::RecordDecl *record_decl = record_type->getDecl();
+ if (record_decl)
+ {
+ const clang::CXXRecordDecl *cxx_record_decl = llvm::dyn_cast<clang::CXXRecordDecl>(record_decl);
+ if (cxx_record_decl)
+ return cxx_record_decl->isPolymorphic();
+ }
+ }
+ break;
+
+ default:
+ break;
+ }
+ }
+ return false;
+}
+
+bool
+ClangASTContext::IsPossibleDynamicType (lldb::opaque_compiler_type_t type, CompilerType *dynamic_pointee_type,
+ bool check_cplusplus,
+ bool check_objc)
+{
+ clang::QualType pointee_qual_type;
+ if (type)
+ {
+ clang::QualType qual_type (GetCanonicalQualType(type));
+ bool success = false;
+ const clang::Type::TypeClass type_class = qual_type->getTypeClass();
+ switch (type_class)
+ {
+ case clang::Type::Builtin:
+ if (check_objc && llvm::cast<clang::BuiltinType>(qual_type)->getKind() == clang::BuiltinType::ObjCId)
+ {
+ if (dynamic_pointee_type)
+ dynamic_pointee_type->SetCompilerType(this, type);
+ return true;
+ }
+ break;
+
+ case clang::Type::ObjCObjectPointer:
+ if (check_objc)
+ {
+ if (dynamic_pointee_type)
+ dynamic_pointee_type->SetCompilerType(getASTContext(), llvm::cast<clang::ObjCObjectPointerType>(qual_type)->getPointeeType());
+ return true;
+ }
+ break;
+
+ case clang::Type::Pointer:
+ pointee_qual_type = llvm::cast<clang::PointerType>(qual_type)->getPointeeType();
+ success = true;
+ break;
+
+ case clang::Type::LValueReference:
+ case clang::Type::RValueReference:
+ pointee_qual_type = llvm::cast<clang::ReferenceType>(qual_type)->getPointeeType();
+ success = true;
+ break;
+
+ case clang::Type::Typedef:
+ return IsPossibleDynamicType (llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType().getAsOpaquePtr(),
+ dynamic_pointee_type,
+ check_cplusplus,
+ check_objc);
+
+ case clang::Type::Auto:
+ return IsPossibleDynamicType (llvm::cast<clang::AutoType>(qual_type)->getDeducedType().getAsOpaquePtr(),
+ dynamic_pointee_type,
+ check_cplusplus,
+ check_objc);
+
+ case clang::Type::Elaborated:
+ return IsPossibleDynamicType (llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType().getAsOpaquePtr(),
+ dynamic_pointee_type,
+ check_cplusplus,
+ check_objc);
+
+ case clang::Type::Paren:
+ return IsPossibleDynamicType (llvm::cast<clang::ParenType>(qual_type)->desugar().getAsOpaquePtr(),
+ dynamic_pointee_type,
+ check_cplusplus,
+ check_objc);
+ default:
+ break;
+ }
+
+ if (success)
+ {
+ // Check to make sure what we are pointing too is a possible dynamic C++ type
+ // We currently accept any "void *" (in case we have a class that has been
+ // watered down to an opaque pointer) and virtual C++ classes.
+ const clang::Type::TypeClass pointee_type_class = pointee_qual_type.getCanonicalType()->getTypeClass();
+ switch (pointee_type_class)
+ {
+ case clang::Type::Builtin:
+ switch (llvm::cast<clang::BuiltinType>(pointee_qual_type)->getKind())
+ {
+ case clang::BuiltinType::UnknownAny:
+ case clang::BuiltinType::Void:
+ if (dynamic_pointee_type)
+ dynamic_pointee_type->SetCompilerType(getASTContext(), pointee_qual_type);
+ return true;
+ default:
+ break;
+ }
+ break;
+
+ case clang::Type::Record:
+ if (check_cplusplus)
+ {
+ clang::CXXRecordDecl *cxx_record_decl = pointee_qual_type->getAsCXXRecordDecl();
+ if (cxx_record_decl)
+ {
+ bool is_complete = cxx_record_decl->isCompleteDefinition();
+
+ if (is_complete)
+ success = cxx_record_decl->isDynamicClass();
+ else
+ {
+ ClangASTMetadata *metadata = ClangASTContext::GetMetadata (getASTContext(), cxx_record_decl);
+ if (metadata)
+ success = metadata->GetIsDynamicCXXType();
+ else
+ {
+ is_complete = CompilerType(getASTContext(), pointee_qual_type).GetCompleteType();
+ if (is_complete)
+ success = cxx_record_decl->isDynamicClass();
+ else
+ success = false;
+ }
+ }
+
+ if (success)
+ {
+ if (dynamic_pointee_type)
+ dynamic_pointee_type->SetCompilerType(getASTContext(), pointee_qual_type);
+ return true;
+ }
+ }
+ }
+ break;
+
+ case clang::Type::ObjCObject:
+ case clang::Type::ObjCInterface:
+ if (check_objc)
+ {
+ if (dynamic_pointee_type)
+ dynamic_pointee_type->SetCompilerType(getASTContext(), pointee_qual_type);
+ return true;
+ }
+ break;
+
+ default:
+ break;
+ }
+ }
+ }
+ if (dynamic_pointee_type)
+ dynamic_pointee_type->Clear();
+ return false;
+}
+
+
+bool
+ClangASTContext::IsScalarType (lldb::opaque_compiler_type_t type)
+{
+ if (!type)
+ return false;
+
+ return (GetTypeInfo (type, nullptr) & eTypeIsScalar) != 0;
+}
+
+bool
+ClangASTContext::IsTypedefType (lldb::opaque_compiler_type_t type)
+{
+ if (!type)
+ return false;
+ return GetQualType(type)->getTypeClass() == clang::Type::Typedef;
+}
+
+bool
+ClangASTContext::IsVoidType (lldb::opaque_compiler_type_t type)
+{
+ if (!type)
+ return false;
+ return GetCanonicalQualType(type)->isVoidType();
+}
+
+bool
+ClangASTContext::SupportsLanguage (lldb::LanguageType language)
+{
+ return ClangASTContextSupportsLanguage(language);
+}
+
+bool
+ClangASTContext::GetCXXClassName (const CompilerType& type, std::string &class_name)
+{
+ if (type)
+ {
+ clang::QualType qual_type (GetCanonicalQualType(type));
+ if (!qual_type.isNull())
+ {
+ clang::CXXRecordDecl *cxx_record_decl = qual_type->getAsCXXRecordDecl();
+ if (cxx_record_decl)
+ {
+ class_name.assign(cxx_record_decl->getIdentifier()->getNameStart());
+ return true;
+ }
+ }
+ }
+ class_name.clear();
+ return false;
+}
+
+
+bool
+ClangASTContext::IsCXXClassType (const CompilerType& type)
+{
+ if (!type)
+ return false;
+
+ clang::QualType qual_type (GetCanonicalQualType(type));
+ if (!qual_type.isNull() && qual_type->getAsCXXRecordDecl() != nullptr)
+ return true;
+ return false;
+}
+
+bool
+ClangASTContext::IsBeingDefined (lldb::opaque_compiler_type_t type)
+{
+ if (!type)
+ return false;
+ clang::QualType qual_type (GetCanonicalQualType(type));
+ const clang::TagType *tag_type = llvm::dyn_cast<clang::TagType>(qual_type);
+ if (tag_type)
+ return tag_type->isBeingDefined();
+ return false;
+}
+
+bool
+ClangASTContext::IsObjCObjectPointerType (const CompilerType& type, CompilerType *class_type_ptr)
+{
+ if (!type)
+ return false;
+
+ clang::QualType qual_type (GetCanonicalQualType(type));
+
+ if (!qual_type.isNull() && qual_type->isObjCObjectPointerType())
+ {
+ if (class_type_ptr)
+ {
+ if (!qual_type->isObjCClassType() &&
+ !qual_type->isObjCIdType())
+ {
+ const clang::ObjCObjectPointerType *obj_pointer_type = llvm::dyn_cast<clang::ObjCObjectPointerType>(qual_type);
+ if (obj_pointer_type == nullptr)
+ class_type_ptr->Clear();
+ else
+ class_type_ptr->SetCompilerType (type.GetTypeSystem(), clang::QualType(obj_pointer_type->getInterfaceType(), 0).getAsOpaquePtr());
+ }
+ }
+ return true;
+ }
+ if (class_type_ptr)
+ class_type_ptr->Clear();
+ return false;
+}
+
+bool
+ClangASTContext::GetObjCClassName (const CompilerType& type, std::string &class_name)
+{
+ if (!type)
+ return false;
+
+ clang::QualType qual_type (GetCanonicalQualType(type));
+
+ const clang::ObjCObjectType *object_type = llvm::dyn_cast<clang::ObjCObjectType>(qual_type);
+ if (object_type)
+ {
+ const clang::ObjCInterfaceDecl *interface = object_type->getInterface();
+ if (interface)
+ {
+ class_name = interface->getNameAsString();
+ return true;
+ }
+ }
+ return false;
+}
+
+
+//----------------------------------------------------------------------
+// Type Completion
+//----------------------------------------------------------------------
+
+bool
+ClangASTContext::GetCompleteType (lldb::opaque_compiler_type_t type)
+{
+ if (!type)
+ return false;
+ const bool allow_completion = true;
+ return GetCompleteQualType (getASTContext(), GetQualType(type), allow_completion);
+}
+
+ConstString
+ClangASTContext::GetTypeName (lldb::opaque_compiler_type_t type)
+{
+ std::string type_name;
+ if (type)
+ {
+ clang::PrintingPolicy printing_policy (getASTContext()->getPrintingPolicy());
+ clang::QualType qual_type(GetQualType(type));
+ printing_policy.SuppressTagKeyword = true;
+ printing_policy.LangOpts.WChar = true;
+ const clang::TypedefType *typedef_type = qual_type->getAs<clang::TypedefType>();
+ if (typedef_type)
+ {
+ const clang::TypedefNameDecl *typedef_decl = typedef_type->getDecl();
+ type_name = typedef_decl->getQualifiedNameAsString();
+ }
+ else
+ {
+ type_name = qual_type.getAsString(printing_policy);
+ }
+ }
+ return ConstString(type_name);
+}
+
+uint32_t
+ClangASTContext::GetTypeInfo (lldb::opaque_compiler_type_t type, CompilerType *pointee_or_element_clang_type)
+{
+ if (!type)
+ return 0;
+
+ if (pointee_or_element_clang_type)
+ pointee_or_element_clang_type->Clear();
+
+ clang::QualType qual_type (GetQualType(type));
+
+ const clang::Type::TypeClass type_class = qual_type->getTypeClass();
+ switch (type_class)
+ {
+ case clang::Type::Builtin:
+ {
+ const clang::BuiltinType *builtin_type = llvm::dyn_cast<clang::BuiltinType>(qual_type->getCanonicalTypeInternal());
+
+ uint32_t builtin_type_flags = eTypeIsBuiltIn | eTypeHasValue;
+ switch (builtin_type->getKind())
+ {
+ case clang::BuiltinType::ObjCId:
+ case clang::BuiltinType::ObjCClass:
+ if (pointee_or_element_clang_type)
+ pointee_or_element_clang_type->SetCompilerType(getASTContext(), getASTContext()->ObjCBuiltinClassTy);
+ builtin_type_flags |= eTypeIsPointer | eTypeIsObjC;
+ break;
+
+ case clang::BuiltinType::ObjCSel:
+ if (pointee_or_element_clang_type)
+ pointee_or_element_clang_type->SetCompilerType(getASTContext(), getASTContext()->CharTy);
+ builtin_type_flags |= eTypeIsPointer | eTypeIsObjC;
+ break;
+
+ case clang::BuiltinType::Bool:
+ case clang::BuiltinType::Char_U:
+ case clang::BuiltinType::UChar:
+ case clang::BuiltinType::WChar_U:
+ case clang::BuiltinType::Char16:
+ case clang::BuiltinType::Char32:
+ case clang::BuiltinType::UShort:
+ case clang::BuiltinType::UInt:
+ case clang::BuiltinType::ULong:
+ case clang::BuiltinType::ULongLong:
+ case clang::BuiltinType::UInt128:
+ case clang::BuiltinType::Char_S:
+ case clang::BuiltinType::SChar:
+ case clang::BuiltinType::WChar_S:
+ case clang::BuiltinType::Short:
+ case clang::BuiltinType::Int:
+ case clang::BuiltinType::Long:
+ case clang::BuiltinType::LongLong:
+ case clang::BuiltinType::Int128:
+ case clang::BuiltinType::Float:
+ case clang::BuiltinType::Double:
+ case clang::BuiltinType::LongDouble:
+ builtin_type_flags |= eTypeIsScalar;
+ if (builtin_type->isInteger())
+ {
+ builtin_type_flags |= eTypeIsInteger;
+ if (builtin_type->isSignedInteger())
+ builtin_type_flags |= eTypeIsSigned;
+ }
+ else if (builtin_type->isFloatingPoint())
+ builtin_type_flags |= eTypeIsFloat;
+ break;
+ default:
+ break;
+ }
+ return builtin_type_flags;
+ }
+
+ case clang::Type::BlockPointer:
+ if (pointee_or_element_clang_type)
+ pointee_or_element_clang_type->SetCompilerType(getASTContext(), qual_type->getPointeeType());
+ return eTypeIsPointer | eTypeHasChildren | eTypeIsBlock;
+
+ case clang::Type::Complex:
+ {
+ uint32_t complex_type_flags = eTypeIsBuiltIn | eTypeHasValue | eTypeIsComplex;
+ const clang::ComplexType *complex_type = llvm::dyn_cast<clang::ComplexType>(qual_type->getCanonicalTypeInternal());
+ if (complex_type)
+ {
+ clang::QualType complex_element_type (complex_type->getElementType());
+ if (complex_element_type->isIntegerType())
+ complex_type_flags |= eTypeIsFloat;
+ else if (complex_element_type->isFloatingType())
+ complex_type_flags |= eTypeIsInteger;
+ }
+ return complex_type_flags;
+ }
+ break;
+
+ case clang::Type::ConstantArray:
+ case clang::Type::DependentSizedArray:
+ case clang::Type::IncompleteArray:
+ case clang::Type::VariableArray:
+ if (pointee_or_element_clang_type)
+ pointee_or_element_clang_type->SetCompilerType(getASTContext(), llvm::cast<clang::ArrayType>(qual_type.getTypePtr())->getElementType());
+ return eTypeHasChildren | eTypeIsArray;
+
+ case clang::Type::DependentName: return 0;
+ case clang::Type::DependentSizedExtVector: return eTypeHasChildren | eTypeIsVector;
+ case clang::Type::DependentTemplateSpecialization: return eTypeIsTemplate;
+ case clang::Type::Decltype: return 0;
+
+ case clang::Type::Enum:
+ if (pointee_or_element_clang_type)
+ pointee_or_element_clang_type->SetCompilerType(getASTContext(), llvm::cast<clang::EnumType>(qual_type)->getDecl()->getIntegerType());
+ return eTypeIsEnumeration | eTypeHasValue;
+
+ case clang::Type::Auto:
+ return CompilerType (getASTContext(), llvm::cast<clang::AutoType>(qual_type)->getDeducedType()).GetTypeInfo (pointee_or_element_clang_type);
+ case clang::Type::Elaborated:
+ return CompilerType (getASTContext(), llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType()).GetTypeInfo (pointee_or_element_clang_type);
+ case clang::Type::Paren:
+ return CompilerType (getASTContext(), llvm::cast<clang::ParenType>(qual_type)->desugar()).GetTypeInfo (pointee_or_element_clang_type);
+
+ case clang::Type::FunctionProto: return eTypeIsFuncPrototype | eTypeHasValue;
+ case clang::Type::FunctionNoProto: return eTypeIsFuncPrototype | eTypeHasValue;
+ case clang::Type::InjectedClassName: return 0;
+
+ case clang::Type::LValueReference:
+ case clang::Type::RValueReference:
+ if (pointee_or_element_clang_type)
+ pointee_or_element_clang_type->SetCompilerType(getASTContext(), llvm::cast<clang::ReferenceType>(qual_type.getTypePtr())->getPointeeType());
+ return eTypeHasChildren | eTypeIsReference | eTypeHasValue;
+
+ case clang::Type::MemberPointer: return eTypeIsPointer | eTypeIsMember | eTypeHasValue;
+
+ case clang::Type::ObjCObjectPointer:
+ if (pointee_or_element_clang_type)
+ pointee_or_element_clang_type->SetCompilerType(getASTContext(), qual_type->getPointeeType());
+ return eTypeHasChildren | eTypeIsObjC | eTypeIsClass | eTypeIsPointer | eTypeHasValue;
+
+ case clang::Type::ObjCObject: return eTypeHasChildren | eTypeIsObjC | eTypeIsClass;
+ case clang::Type::ObjCInterface: return eTypeHasChildren | eTypeIsObjC | eTypeIsClass;
+
+ case clang::Type::Pointer:
+ if (pointee_or_element_clang_type)
+ pointee_or_element_clang_type->SetCompilerType(getASTContext(), qual_type->getPointeeType());
+ return eTypeHasChildren | eTypeIsPointer | eTypeHasValue;
+
+ case clang::Type::Record:
+ if (qual_type->getAsCXXRecordDecl())
+ return eTypeHasChildren | eTypeIsClass | eTypeIsCPlusPlus;
+ else
+ return eTypeHasChildren | eTypeIsStructUnion;
+ break;
+ case clang::Type::SubstTemplateTypeParm: return eTypeIsTemplate;
+ case clang::Type::TemplateTypeParm: return eTypeIsTemplate;
+ case clang::Type::TemplateSpecialization: return eTypeIsTemplate;
+
+ case clang::Type::Typedef:
+ return eTypeIsTypedef | CompilerType (getASTContext(), llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType()).GetTypeInfo (pointee_or_element_clang_type);
+ case clang::Type::TypeOfExpr: return 0;
+ case clang::Type::TypeOf: return 0;
+ case clang::Type::UnresolvedUsing: return 0;
+
+ case clang::Type::ExtVector:
+ case clang::Type::Vector:
+ {
+ uint32_t vector_type_flags = eTypeHasChildren | eTypeIsVector;
+ const clang::VectorType *vector_type = llvm::dyn_cast<clang::VectorType>(qual_type->getCanonicalTypeInternal());
+ if (vector_type)
+ {
+ if (vector_type->isIntegerType())
+ vector_type_flags |= eTypeIsFloat;
+ else if (vector_type->isFloatingType())
+ vector_type_flags |= eTypeIsInteger;
+ }
+ return vector_type_flags;
+ }
+ default: return 0;
+ }
+ return 0;
+}
+
+
+
+lldb::LanguageType
+ClangASTContext::GetMinimumLanguage (lldb::opaque_compiler_type_t type)
+{
+ if (!type)
+ return lldb::eLanguageTypeC;
+
+ // If the type is a reference, then resolve it to what it refers to first:
+ clang::QualType qual_type (GetCanonicalQualType(type).getNonReferenceType());
+ if (qual_type->isAnyPointerType())
+ {
+ if (qual_type->isObjCObjectPointerType())
+ return lldb::eLanguageTypeObjC;
+
+ clang::QualType pointee_type (qual_type->getPointeeType());
+ if (pointee_type->getPointeeCXXRecordDecl() != nullptr)
+ return lldb::eLanguageTypeC_plus_plus;
+ if (pointee_type->isObjCObjectOrInterfaceType())
+ return lldb::eLanguageTypeObjC;
+ if (pointee_type->isObjCClassType())
+ return lldb::eLanguageTypeObjC;
+ if (pointee_type.getTypePtr() == getASTContext()->ObjCBuiltinIdTy.getTypePtr())
+ return lldb::eLanguageTypeObjC;
+ }
+ else
+ {
+ if (qual_type->isObjCObjectOrInterfaceType())
+ return lldb::eLanguageTypeObjC;
+ if (qual_type->getAsCXXRecordDecl())
+ return lldb::eLanguageTypeC_plus_plus;
+ switch (qual_type->getTypeClass())
+ {
+ default:
+ break;
+ case clang::Type::Builtin:
+ switch (llvm::cast<clang::BuiltinType>(qual_type)->getKind())
+ {
+ default:
+ case clang::BuiltinType::Void:
+ case clang::BuiltinType::Bool:
+ case clang::BuiltinType::Char_U:
+ case clang::BuiltinType::UChar:
+ case clang::BuiltinType::WChar_U:
+ case clang::BuiltinType::Char16:
+ case clang::BuiltinType::Char32:
+ case clang::BuiltinType::UShort:
+ case clang::BuiltinType::UInt:
+ case clang::BuiltinType::ULong:
+ case clang::BuiltinType::ULongLong:
+ case clang::BuiltinType::UInt128:
+ case clang::BuiltinType::Char_S:
+ case clang::BuiltinType::SChar:
+ case clang::BuiltinType::WChar_S:
+ case clang::BuiltinType::Short:
+ case clang::BuiltinType::Int:
+ case clang::BuiltinType::Long:
+ case clang::BuiltinType::LongLong:
+ case clang::BuiltinType::Int128:
+ case clang::BuiltinType::Float:
+ case clang::BuiltinType::Double:
+ case clang::BuiltinType::LongDouble:
+ break;
+
+ case clang::BuiltinType::NullPtr:
+ return eLanguageTypeC_plus_plus;
+
+ case clang::BuiltinType::ObjCId:
+ case clang::BuiltinType::ObjCClass:
+ case clang::BuiltinType::ObjCSel:
+ return eLanguageTypeObjC;
+
+ case clang::BuiltinType::Dependent:
+ case clang::BuiltinType::Overload:
+ case clang::BuiltinType::BoundMember:
+ case clang::BuiltinType::UnknownAny:
+ break;
+ }
+ break;
+ case clang::Type::Typedef:
+ return CompilerType(getASTContext(), llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType()).GetMinimumLanguage();
+ }
+ }
+ return lldb::eLanguageTypeC;
+}
+
+lldb::TypeClass
+ClangASTContext::GetTypeClass (lldb::opaque_compiler_type_t type)
+{
+ if (!type)
+ return lldb::eTypeClassInvalid;
+
+ clang::QualType qual_type(GetQualType(type));
+
+ switch (qual_type->getTypeClass())
+ {
+ case clang::Type::UnaryTransform: break;
+ case clang::Type::FunctionNoProto: return lldb::eTypeClassFunction;
+ case clang::Type::FunctionProto: return lldb::eTypeClassFunction;
+ case clang::Type::IncompleteArray: return lldb::eTypeClassArray;
+ case clang::Type::VariableArray: return lldb::eTypeClassArray;
+ case clang::Type::ConstantArray: return lldb::eTypeClassArray;
+ case clang::Type::DependentSizedArray: return lldb::eTypeClassArray;
+ case clang::Type::DependentSizedExtVector: return lldb::eTypeClassVector;
+ case clang::Type::ExtVector: return lldb::eTypeClassVector;
+ case clang::Type::Vector: return lldb::eTypeClassVector;
+ case clang::Type::Builtin: return lldb::eTypeClassBuiltin;
+ case clang::Type::ObjCObjectPointer: return lldb::eTypeClassObjCObjectPointer;
+ case clang::Type::BlockPointer: return lldb::eTypeClassBlockPointer;
+ case clang::Type::Pointer: return lldb::eTypeClassPointer;
+ case clang::Type::LValueReference: return lldb::eTypeClassReference;
+ case clang::Type::RValueReference: return lldb::eTypeClassReference;
+ case clang::Type::MemberPointer: return lldb::eTypeClassMemberPointer;
+ case clang::Type::Complex:
+ if (qual_type->isComplexType())
+ return lldb::eTypeClassComplexFloat;
+ else
+ return lldb::eTypeClassComplexInteger;
+ case clang::Type::ObjCObject: return lldb::eTypeClassObjCObject;
+ case clang::Type::ObjCInterface: return lldb::eTypeClassObjCInterface;
+ case clang::Type::Record:
+ {
+ const clang::RecordType *record_type = llvm::cast<clang::RecordType>(qual_type.getTypePtr());
+ const clang::RecordDecl *record_decl = record_type->getDecl();
+ if (record_decl->isUnion())
+ return lldb::eTypeClassUnion;
+ else if (record_decl->isStruct())
+ return lldb::eTypeClassStruct;
+ else
+ return lldb::eTypeClassClass;
+ }
+ break;
+ case clang::Type::Enum: return lldb::eTypeClassEnumeration;
+ case clang::Type::Typedef: return lldb::eTypeClassTypedef;
+ case clang::Type::UnresolvedUsing: break;
+ case clang::Type::Paren:
+ return CompilerType(getASTContext(), llvm::cast<clang::ParenType>(qual_type)->desugar()).GetTypeClass();
+ case clang::Type::Auto:
+ return CompilerType(getASTContext(), llvm::cast<clang::AutoType>(qual_type)->getDeducedType()).GetTypeClass();
+ case clang::Type::Elaborated:
+ return CompilerType(getASTContext(), llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType()).GetTypeClass();
+
+ case clang::Type::Attributed: break;
+ case clang::Type::TemplateTypeParm: break;
+ case clang::Type::SubstTemplateTypeParm: break;
+ case clang::Type::SubstTemplateTypeParmPack:break;
+ case clang::Type::InjectedClassName: break;
+ case clang::Type::DependentName: break;
+ case clang::Type::DependentTemplateSpecialization: break;
+ case clang::Type::PackExpansion: break;
+
+ case clang::Type::TypeOfExpr: break;
+ case clang::Type::TypeOf: break;
+ case clang::Type::Decltype: break;
+ case clang::Type::TemplateSpecialization: break;
+ case clang::Type::Atomic: break;
+
+ // pointer type decayed from an array or function type.
+ case clang::Type::Decayed: break;
+ case clang::Type::Adjusted: break;
+ }
+ // We don't know hot to display this type...
+ return lldb::eTypeClassOther;
+
+}
+
+unsigned
+ClangASTContext::GetTypeQualifiers(lldb::opaque_compiler_type_t type)
+{
+ if (type)
+ return GetQualType(type).getQualifiers().getCVRQualifiers();
+ return 0;
+}
+
+//----------------------------------------------------------------------
+// Creating related types
+//----------------------------------------------------------------------
+
+CompilerType
+ClangASTContext::GetArrayElementType (lldb::opaque_compiler_type_t type, uint64_t *stride)
+{
+ if (type)
+ {
+ clang::QualType qual_type(GetCanonicalQualType(type));
+
+ const clang::Type *array_eletype = qual_type.getTypePtr()->getArrayElementTypeNoTypeQual();
+
+ if (!array_eletype)
+ return CompilerType();
+
+ CompilerType element_type (getASTContext(), array_eletype->getCanonicalTypeUnqualified());
+
+ // TODO: the real stride will be >= this value.. find the real one!
+ if (stride)
+ *stride = element_type.GetByteSize(nullptr);
+
+ return element_type;
+
+ }
+ return CompilerType();
+}
+
+CompilerType
+ClangASTContext::GetCanonicalType (lldb::opaque_compiler_type_t type)
+{
+ if (type)
+ return CompilerType (getASTContext(), GetCanonicalQualType(type));
+ return CompilerType();
+}
+
+static clang::QualType
+GetFullyUnqualifiedType_Impl (clang::ASTContext *ast, clang::QualType qual_type)
+{
+ if (qual_type->isPointerType())
+ qual_type = ast->getPointerType(GetFullyUnqualifiedType_Impl(ast, qual_type->getPointeeType()));
+ else
+ qual_type = qual_type.getUnqualifiedType();
+ qual_type.removeLocalConst();
+ qual_type.removeLocalRestrict();
+ qual_type.removeLocalVolatile();
+ return qual_type;
+}
+
+CompilerType
+ClangASTContext::GetFullyUnqualifiedType (lldb::opaque_compiler_type_t type)
+{
+ if (type)
+ return CompilerType(getASTContext(), GetFullyUnqualifiedType_Impl(getASTContext(), GetQualType(type)));
+ return CompilerType();
+}
+
+
+int
+ClangASTContext::GetFunctionArgumentCount (lldb::opaque_compiler_type_t type)
+{
+ if (type)
+ {
+ const clang::FunctionProtoType* func = llvm::dyn_cast<clang::FunctionProtoType>(GetCanonicalQualType(type));
+ if (func)
+ return func->getNumParams();
+ }
+ return -1;
+}
+
+CompilerType
+ClangASTContext::GetFunctionArgumentTypeAtIndex (lldb::opaque_compiler_type_t type, size_t idx)
+{
+ if (type)
+ {
+ const clang::FunctionProtoType* func = llvm::dyn_cast<clang::FunctionProtoType>(GetQualType(type));
+ if (func)
+ {
+ const uint32_t num_args = func->getNumParams();
+ if (idx < num_args)
+ return CompilerType(getASTContext(), func->getParamType(idx));
+ }
+ }
+ return CompilerType();
+}
+
+CompilerType
+ClangASTContext::GetFunctionReturnType (lldb::opaque_compiler_type_t type)
+{
+ if (type)
+ {
+ clang::QualType qual_type(GetQualType(type));
+ const clang::FunctionProtoType* func = llvm::dyn_cast<clang::FunctionProtoType>(qual_type.getTypePtr());
+ if (func)
+ return CompilerType(getASTContext(), func->getReturnType());
+ }
+ return CompilerType();
+}
+
+size_t
+ClangASTContext::GetNumMemberFunctions (lldb::opaque_compiler_type_t type)
+{
+ size_t num_functions = 0;
+ if (type)
+ {
+ clang::QualType qual_type(GetCanonicalQualType(type));
+ switch (qual_type->getTypeClass()) {
+ case clang::Type::Record:
+ if (GetCompleteQualType (getASTContext(), qual_type))
+ {
+ const clang::RecordType *record_type = llvm::cast<clang::RecordType>(qual_type.getTypePtr());
+ const clang::RecordDecl *record_decl = record_type->getDecl();
+ assert(record_decl);
+ const clang::CXXRecordDecl *cxx_record_decl = llvm::dyn_cast<clang::CXXRecordDecl>(record_decl);
+ if (cxx_record_decl)
+ num_functions = std::distance(cxx_record_decl->method_begin(), cxx_record_decl->method_end());
+ }
+ break;
+
+ case clang::Type::ObjCObjectPointer:
+ if (GetCompleteType(type))
+ {
+ const clang::ObjCObjectPointerType *objc_class_type = qual_type->getAsObjCInterfacePointerType();
+ if (objc_class_type)
+ {
+ clang::ObjCInterfaceDecl *class_interface_decl = objc_class_type->getInterfaceDecl();
+ if (class_interface_decl)
+ num_functions = std::distance(class_interface_decl->meth_begin(), class_interface_decl->meth_end());
+ }
+ }
+ break;
+
+ case clang::Type::ObjCObject:
+ case clang::Type::ObjCInterface:
+ if (GetCompleteType(type))
+ {
+ const clang::ObjCObjectType *objc_class_type = llvm::dyn_cast<clang::ObjCObjectType>(qual_type.getTypePtr());
+ if (objc_class_type)
+ {
+ clang::ObjCInterfaceDecl *class_interface_decl = objc_class_type->getInterface();
+ if (class_interface_decl)
+ num_functions = std::distance(class_interface_decl->meth_begin(), class_interface_decl->meth_end());
+ }
+ }
+ break;
+
+
+ case clang::Type::Typedef:
+ return CompilerType (getASTContext(), llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType()).GetNumMemberFunctions();
+
+ case clang::Type::Auto:
+ return CompilerType (getASTContext(), llvm::cast<clang::AutoType>(qual_type)->getDeducedType()).GetNumMemberFunctions();
+
+ case clang::Type::Elaborated:
+ return CompilerType (getASTContext(), llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType()).GetNumMemberFunctions();
+
+ case clang::Type::Paren:
+ return CompilerType (getASTContext(), llvm::cast<clang::ParenType>(qual_type)->desugar()).GetNumMemberFunctions();
+
+ default:
+ break;
+ }
+ }
+ return num_functions;
+}
+
+TypeMemberFunctionImpl
+ClangASTContext::GetMemberFunctionAtIndex (lldb::opaque_compiler_type_t type, size_t idx)
+{
+ std::string name;
+ MemberFunctionKind kind(MemberFunctionKind::eMemberFunctionKindUnknown);
+ CompilerType clang_type;
+ CompilerDecl clang_decl;
+ if (type)
+ {
+ clang::QualType qual_type(GetCanonicalQualType(type));
+ switch (qual_type->getTypeClass()) {
+ case clang::Type::Record:
+ if (GetCompleteQualType (getASTContext(), qual_type))
+ {
+ const clang::RecordType *record_type = llvm::cast<clang::RecordType>(qual_type.getTypePtr());
+ const clang::RecordDecl *record_decl = record_type->getDecl();
+ assert(record_decl);
+ const clang::CXXRecordDecl *cxx_record_decl = llvm::dyn_cast<clang::CXXRecordDecl>(record_decl);
+ if (cxx_record_decl)
+ {
+ auto method_iter = cxx_record_decl->method_begin();
+ auto method_end = cxx_record_decl->method_end();
+ if (idx < static_cast<size_t>(std::distance(method_iter, method_end)))
+ {
+ std::advance(method_iter, idx);
+ clang::CXXMethodDecl *cxx_method_decl = method_iter->getCanonicalDecl();
+ if (cxx_method_decl)
+ {
+ name = cxx_method_decl->getDeclName().getAsString();
+ if (cxx_method_decl->isStatic())
+ kind = lldb::eMemberFunctionKindStaticMethod;
+ else if (llvm::isa<clang::CXXConstructorDecl>(cxx_method_decl))
+ kind = lldb::eMemberFunctionKindConstructor;
+ else if (llvm::isa<clang::CXXDestructorDecl>(cxx_method_decl))
+ kind = lldb::eMemberFunctionKindDestructor;
+ else
+ kind = lldb::eMemberFunctionKindInstanceMethod;
+ clang_type = CompilerType(this, cxx_method_decl->getType().getAsOpaquePtr());
+ clang_decl = CompilerDecl(this, cxx_method_decl);
+ }
+ }
+ }
+ }
+ break;
+
+ case clang::Type::ObjCObjectPointer:
+ if (GetCompleteType(type))
+ {
+ const clang::ObjCObjectPointerType *objc_class_type = qual_type->getAsObjCInterfacePointerType();
+ if (objc_class_type)
+ {
+ clang::ObjCInterfaceDecl *class_interface_decl = objc_class_type->getInterfaceDecl();
+ if (class_interface_decl)
+ {
+ auto method_iter = class_interface_decl->meth_begin();
+ auto method_end = class_interface_decl->meth_end();
+ if (idx < static_cast<size_t>(std::distance(method_iter, method_end)))
+ {
+ std::advance(method_iter, idx);
+ clang::ObjCMethodDecl *objc_method_decl = method_iter->getCanonicalDecl();
+ if (objc_method_decl)
+ {
+ clang_decl = CompilerDecl(this, objc_method_decl);
+ name = objc_method_decl->getSelector().getAsString();
+ if (objc_method_decl->isClassMethod())
+ kind = lldb::eMemberFunctionKindStaticMethod;
+ else
+ kind = lldb::eMemberFunctionKindInstanceMethod;
+ }
+ }
+ }
+ }
+ }
+ break;
+
+ case clang::Type::ObjCObject:
+ case clang::Type::ObjCInterface:
+ if (GetCompleteType(type))
+ {
+ const clang::ObjCObjectType *objc_class_type = llvm::dyn_cast<clang::ObjCObjectType>(qual_type.getTypePtr());
+ if (objc_class_type)
+ {
+ clang::ObjCInterfaceDecl *class_interface_decl = objc_class_type->getInterface();
+ if (class_interface_decl)
+ {
+ auto method_iter = class_interface_decl->meth_begin();
+ auto method_end = class_interface_decl->meth_end();
+ if (idx < static_cast<size_t>(std::distance(method_iter, method_end)))
+ {
+ std::advance(method_iter, idx);
+ clang::ObjCMethodDecl *objc_method_decl = method_iter->getCanonicalDecl();
+ if (objc_method_decl)
+ {
+ clang_decl = CompilerDecl(this, objc_method_decl);
+ name = objc_method_decl->getSelector().getAsString();
+ if (objc_method_decl->isClassMethod())
+ kind = lldb::eMemberFunctionKindStaticMethod;
+ else
+ kind = lldb::eMemberFunctionKindInstanceMethod;
+ }
+ }
+ }
+ }
+ }
+ break;
+
+ case clang::Type::Typedef:
+ return GetMemberFunctionAtIndex(llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType().getAsOpaquePtr(), idx);
+
+ case clang::Type::Auto:
+ return GetMemberFunctionAtIndex(llvm::cast<clang::AutoType>(qual_type)->getDeducedType().getAsOpaquePtr(), idx);
+
+ case clang::Type::Elaborated:
+ return GetMemberFunctionAtIndex(llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType().getAsOpaquePtr(), idx);
+
+ case clang::Type::Paren:
+ return GetMemberFunctionAtIndex(llvm::cast<clang::ParenType>(qual_type)->desugar().getAsOpaquePtr(), idx);
+
+ default:
+ break;
+ }
+ }
+
+ if (kind == eMemberFunctionKindUnknown)
+ return TypeMemberFunctionImpl();
+ else
+ return TypeMemberFunctionImpl(clang_type, clang_decl, name, kind);
+}
+
+CompilerType
+ClangASTContext::GetNonReferenceType (lldb::opaque_compiler_type_t type)
+{
+ if (type)
+ return CompilerType(getASTContext(), GetQualType(type).getNonReferenceType());
+ return CompilerType();
+}
+
+CompilerType
+ClangASTContext::CreateTypedefType (const CompilerType& type,
+ const char *typedef_name,
+ const CompilerDeclContext &compiler_decl_ctx)
+{
+ if (type && typedef_name && typedef_name[0])
+ {
+ ClangASTContext *ast = llvm::dyn_cast<ClangASTContext>(type.GetTypeSystem());
+ if (!ast)
+ return CompilerType();
+ clang::ASTContext* clang_ast = ast->getASTContext();
+ clang::QualType qual_type (GetQualType(type));
+
+ clang::DeclContext *decl_ctx = ClangASTContext::DeclContextGetAsDeclContext(compiler_decl_ctx);
+ if (decl_ctx == nullptr)
+ decl_ctx = ast->getASTContext()->getTranslationUnitDecl();
+
+ clang::TypedefDecl *decl = clang::TypedefDecl::Create (*clang_ast,
+ decl_ctx,
+ clang::SourceLocation(),
+ clang::SourceLocation(),
+ &clang_ast->Idents.get(typedef_name),
+ clang_ast->getTrivialTypeSourceInfo(qual_type));
+
+ decl->setAccess(clang::AS_public); // TODO respect proper access specifier
+
+ // Get a uniqued clang::QualType for the typedef decl type
+ return CompilerType (clang_ast, clang_ast->getTypedefType (decl));
+ }
+ return CompilerType();
+
+}
+
+CompilerType
+ClangASTContext::GetPointeeType (lldb::opaque_compiler_type_t type)
+{
+ if (type)
+ {
+ clang::QualType qual_type(GetQualType(type));
+ return CompilerType (getASTContext(), qual_type.getTypePtr()->getPointeeType());
+ }
+ return CompilerType();
+}
+
+CompilerType
+ClangASTContext::GetPointerType (lldb::opaque_compiler_type_t type)
+{
+ if (type)
+ {
+ clang::QualType qual_type (GetQualType(type));
+
+ const clang::Type::TypeClass type_class = qual_type->getTypeClass();
+ switch (type_class)
+ {
+ case clang::Type::ObjCObject:
+ case clang::Type::ObjCInterface:
+ return CompilerType(getASTContext(), getASTContext()->getObjCObjectPointerType(qual_type));
+
+ default:
+ return CompilerType(getASTContext(), getASTContext()->getPointerType(qual_type));
+ }
+ }
+ return CompilerType();
+}
+
+
+CompilerType
+ClangASTContext::GetLValueReferenceType (lldb::opaque_compiler_type_t type)
+{
+ if (type)
+ return CompilerType(this, getASTContext()->getLValueReferenceType(GetQualType(type)).getAsOpaquePtr());
+ else
+ return CompilerType();
+}
+
+CompilerType
+ClangASTContext::GetRValueReferenceType (lldb::opaque_compiler_type_t type)
+{
+ if (type)
+ return CompilerType(this, getASTContext()->getRValueReferenceType(GetQualType(type)).getAsOpaquePtr());
+ else
+ return CompilerType();
+}
+
+CompilerType
+ClangASTContext::AddConstModifier (lldb::opaque_compiler_type_t type)
+{
+ if (type)
+ {
+ clang::QualType result(GetQualType(type));
+ result.addConst();
+ return CompilerType (this, result.getAsOpaquePtr());
+ }
+ return CompilerType();
+}
+
+CompilerType
+ClangASTContext::AddVolatileModifier (lldb::opaque_compiler_type_t type)
+{
+ if (type)
+ {
+ clang::QualType result(GetQualType(type));
+ result.addVolatile();
+ return CompilerType (this, result.getAsOpaquePtr());
+ }
+ return CompilerType();
+
+}
+
+CompilerType
+ClangASTContext::AddRestrictModifier (lldb::opaque_compiler_type_t type)
+{
+ if (type)
+ {
+ clang::QualType result(GetQualType(type));
+ result.addRestrict();
+ return CompilerType (this, result.getAsOpaquePtr());
+ }
+ return CompilerType();
+
+}
+
+CompilerType
+ClangASTContext::CreateTypedef (lldb::opaque_compiler_type_t type, const char *typedef_name, const CompilerDeclContext &compiler_decl_ctx)
+{
+ if (type)
+ {
+ clang::ASTContext* clang_ast = getASTContext();
+ clang::QualType qual_type (GetQualType(type));
+
+ clang::DeclContext *decl_ctx = ClangASTContext::DeclContextGetAsDeclContext(compiler_decl_ctx);
+ if (decl_ctx == nullptr)
+ decl_ctx = getASTContext()->getTranslationUnitDecl();
+
+ clang::TypedefDecl *decl = clang::TypedefDecl::Create (*clang_ast,
+ decl_ctx,
+ clang::SourceLocation(),
+ clang::SourceLocation(),
+ &clang_ast->Idents.get(typedef_name),
+ clang_ast->getTrivialTypeSourceInfo(qual_type));
+
+ decl->setAccess(clang::AS_public); // TODO respect proper access specifier
+
+ // Get a uniqued clang::QualType for the typedef decl type
+ return CompilerType (this, clang_ast->getTypedefType (decl).getAsOpaquePtr());
+
+ }
+ return CompilerType();
+
+}
+
+CompilerType
+ClangASTContext::GetTypedefedType (lldb::opaque_compiler_type_t type)
+{
+ if (type)
+ {
+ const clang::TypedefType *typedef_type = llvm::dyn_cast<clang::TypedefType>(GetQualType(type));
+ if (typedef_type)
+ return CompilerType (getASTContext(), typedef_type->getDecl()->getUnderlyingType());
+ }
+ return CompilerType();
+}
+
+CompilerType
+ClangASTContext::RemoveFastQualifiers (const CompilerType& type)
+{
+ if (IsClangType(type))
+ {
+ clang::QualType qual_type(GetQualType(type));
+ qual_type.getQualifiers().removeFastQualifiers();
+ return CompilerType (type.GetTypeSystem(), qual_type.getAsOpaquePtr());
+ }
+ return type;
+}
+
+
+//----------------------------------------------------------------------
+// Create related types using the current type's AST
+//----------------------------------------------------------------------
+
+CompilerType
+ClangASTContext::GetBasicTypeFromAST (lldb::BasicType basic_type)
+{
+ return ClangASTContext::GetBasicType(getASTContext(), basic_type);
+}
+//----------------------------------------------------------------------
+// Exploring the type
+//----------------------------------------------------------------------
+
+uint64_t
+ClangASTContext::GetBitSize (lldb::opaque_compiler_type_t type, ExecutionContextScope *exe_scope)
+{
+ if (GetCompleteType (type))
+ {
+ clang::QualType qual_type(GetCanonicalQualType(type));
+ switch (qual_type->getTypeClass())
+ {
+ case clang::Type::ObjCInterface:
+ case clang::Type::ObjCObject:
+ {
+ ExecutionContext exe_ctx (exe_scope);
+ Process *process = exe_ctx.GetProcessPtr();
+ if (process)
+ {
+ ObjCLanguageRuntime *objc_runtime = process->GetObjCLanguageRuntime();
+ if (objc_runtime)
+ {
+ uint64_t bit_size = 0;
+ if (objc_runtime->GetTypeBitSize(CompilerType(getASTContext(), qual_type), bit_size))
+ return bit_size;
+ }
+ }
+ else
+ {
+ static bool g_printed = false;
+ if (!g_printed)
+ {
+ StreamString s;
+ DumpTypeDescription(type, &s);
+
+ llvm::outs() << "warning: trying to determine the size of type ";
+ llvm::outs() << s.GetString() << "\n";
+ llvm::outs() << "without a valid ExecutionContext. this is not reliable. please file a bug against LLDB.\n";
+ llvm::outs() << "backtrace:\n";
+ llvm::sys::PrintStackTrace(llvm::outs());
+ llvm::outs() << "\n";
+ g_printed = true;
+ }
+ }
+ }
+ // fallthrough
+ default:
+ const uint32_t bit_size = getASTContext()->getTypeSize (qual_type);
+ if (bit_size == 0)
+ {
+ if (qual_type->isIncompleteArrayType())
+ return getASTContext()->getTypeSize (qual_type->getArrayElementTypeNoTypeQual()->getCanonicalTypeUnqualified());
+ }
+ if (qual_type->isObjCObjectOrInterfaceType())
+ return bit_size + getASTContext()->getTypeSize(getASTContext()->ObjCBuiltinClassTy);
+ return bit_size;
+ }
+ }
+ return 0;
+}
+
+size_t
+ClangASTContext::GetTypeBitAlign (lldb::opaque_compiler_type_t type)
+{
+ if (GetCompleteType(type))
+ return getASTContext()->getTypeAlign(GetQualType(type));
+ return 0;
+}
+
+
+lldb::Encoding
+ClangASTContext::GetEncoding (lldb::opaque_compiler_type_t type, uint64_t &count)
+{
+ if (!type)
+ return lldb::eEncodingInvalid;
+
+ count = 1;
+ clang::QualType qual_type(GetCanonicalQualType(type));
+
+ switch (qual_type->getTypeClass())
+ {
+ case clang::Type::UnaryTransform:
+ break;
+
+ case clang::Type::FunctionNoProto:
+ case clang::Type::FunctionProto:
+ break;
+
+ case clang::Type::IncompleteArray:
+ case clang::Type::VariableArray:
+ break;
+
+ case clang::Type::ConstantArray:
+ break;
+
+ case clang::Type::ExtVector:
+ case clang::Type::Vector:
+ // TODO: Set this to more than one???
+ break;
+
+ case clang::Type::Builtin:
+ switch (llvm::cast<clang::BuiltinType>(qual_type)->getKind())
+ {
+ case clang::BuiltinType::Void:
+ break;
+
+ case clang::BuiltinType::Bool:
+ case clang::BuiltinType::Char_S:
+ case clang::BuiltinType::SChar:
+ case clang::BuiltinType::WChar_S:
+ case clang::BuiltinType::Char16:
+ case clang::BuiltinType::Char32:
+ case clang::BuiltinType::Short:
+ case clang::BuiltinType::Int:
+ case clang::BuiltinType::Long:
+ case clang::BuiltinType::LongLong:
+ case clang::BuiltinType::Int128: return lldb::eEncodingSint;
+
+ case clang::BuiltinType::Char_U:
+ case clang::BuiltinType::UChar:
+ case clang::BuiltinType::WChar_U:
+ case clang::BuiltinType::UShort:
+ case clang::BuiltinType::UInt:
+ case clang::BuiltinType::ULong:
+ case clang::BuiltinType::ULongLong:
+ case clang::BuiltinType::UInt128: return lldb::eEncodingUint;
+
+ case clang::BuiltinType::Half:
+ case clang::BuiltinType::Float:
+ case clang::BuiltinType::Double:
+ case clang::BuiltinType::LongDouble: return lldb::eEncodingIEEE754;
+
+ case clang::BuiltinType::ObjCClass:
+ case clang::BuiltinType::ObjCId:
+ case clang::BuiltinType::ObjCSel: return lldb::eEncodingUint;
+
+ case clang::BuiltinType::NullPtr: return lldb::eEncodingUint;
+
+ case clang::BuiltinType::Kind::ARCUnbridgedCast:
+ case clang::BuiltinType::Kind::BoundMember:
+ case clang::BuiltinType::Kind::BuiltinFn:
+ case clang::BuiltinType::Kind::Dependent:
+ case clang::BuiltinType::Kind::OCLClkEvent:
+ case clang::BuiltinType::Kind::OCLEvent:
+ case clang::BuiltinType::Kind::OCLImage1d:
+ case clang::BuiltinType::Kind::OCLImage1dArray:
+ case clang::BuiltinType::Kind::OCLImage1dBuffer:
+ case clang::BuiltinType::Kind::OCLImage2d:
+ case clang::BuiltinType::Kind::OCLImage2dArray:
+ case clang::BuiltinType::Kind::OCLImage2dArrayDepth:
+ case clang::BuiltinType::Kind::OCLImage2dArrayMSAA:
+ case clang::BuiltinType::Kind::OCLImage2dArrayMSAADepth:
+ case clang::BuiltinType::Kind::OCLImage2dDepth:
+ case clang::BuiltinType::Kind::OCLImage2dMSAA:
+ case clang::BuiltinType::Kind::OCLImage2dMSAADepth:
+ case clang::BuiltinType::Kind::OCLImage3d:
+ case clang::BuiltinType::Kind::OCLQueue:
+ case clang::BuiltinType::Kind::OCLNDRange:
+ case clang::BuiltinType::Kind::OCLReserveID:
+ case clang::BuiltinType::Kind::OCLSampler:
+ case clang::BuiltinType::Kind::OMPArraySection:
+ case clang::BuiltinType::Kind::Overload:
+ case clang::BuiltinType::Kind::PseudoObject:
+ case clang::BuiltinType::Kind::UnknownAny:
+ break;
+ }
+ break;
+ // All pointer types are represented as unsigned integer encodings.
+ // We may nee to add a eEncodingPointer if we ever need to know the
+ // difference
+ case clang::Type::ObjCObjectPointer:
+ case clang::Type::BlockPointer:
+ case clang::Type::Pointer:
+ case clang::Type::LValueReference:
+ case clang::Type::RValueReference:
+ case clang::Type::MemberPointer: return lldb::eEncodingUint;
+ case clang::Type::Complex:
+ {
+ lldb::Encoding encoding = lldb::eEncodingIEEE754;
+ if (qual_type->isComplexType())
+ encoding = lldb::eEncodingIEEE754;
+ else
+ {
+ const clang::ComplexType *complex_type = qual_type->getAsComplexIntegerType();
+ if (complex_type)
+ encoding = CompilerType(getASTContext(), complex_type->getElementType()).GetEncoding(count);
+ else
+ encoding = lldb::eEncodingSint;
+ }
+ count = 2;
+ return encoding;
+ }
+
+ case clang::Type::ObjCInterface: break;
+ case clang::Type::Record: break;
+ case clang::Type::Enum: return lldb::eEncodingSint;
+ case clang::Type::Typedef:
+ return CompilerType(getASTContext(), llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType()).GetEncoding(count);
+
+ case clang::Type::Auto:
+ return CompilerType(getASTContext(), llvm::cast<clang::AutoType>(qual_type)->getDeducedType()).GetEncoding(count);
+
+ case clang::Type::Elaborated:
+ return CompilerType(getASTContext(), llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType()).GetEncoding(count);
+
+ case clang::Type::Paren:
+ return CompilerType(getASTContext(), llvm::cast<clang::ParenType>(qual_type)->desugar()).GetEncoding(count);
+
+ case clang::Type::DependentSizedArray:
+ case clang::Type::DependentSizedExtVector:
+ case clang::Type::UnresolvedUsing:
+ case clang::Type::Attributed:
+ case clang::Type::TemplateTypeParm:
+ case clang::Type::SubstTemplateTypeParm:
+ case clang::Type::SubstTemplateTypeParmPack:
+ case clang::Type::InjectedClassName:
+ case clang::Type::DependentName:
+ case clang::Type::DependentTemplateSpecialization:
+ case clang::Type::PackExpansion:
+ case clang::Type::ObjCObject:
+
+ case clang::Type::TypeOfExpr:
+ case clang::Type::TypeOf:
+ case clang::Type::Decltype:
+ case clang::Type::TemplateSpecialization:
+ case clang::Type::Atomic:
+ case clang::Type::Adjusted:
+ break;
+
+ // pointer type decayed from an array or function type.
+ case clang::Type::Decayed:
+ break;
+ }
+ count = 0;
+ return lldb::eEncodingInvalid;
+}
+
+lldb::Format
+ClangASTContext::GetFormat (lldb::opaque_compiler_type_t type)
+{
+ if (!type)
+ return lldb::eFormatDefault;
+
+ clang::QualType qual_type(GetCanonicalQualType(type));
+
+ switch (qual_type->getTypeClass())
+ {
+ case clang::Type::UnaryTransform:
+ break;
+
+ case clang::Type::FunctionNoProto:
+ case clang::Type::FunctionProto:
+ break;
+
+ case clang::Type::IncompleteArray:
+ case clang::Type::VariableArray:
+ break;
+
+ case clang::Type::ConstantArray:
+ return lldb::eFormatVoid; // no value
+
+ case clang::Type::ExtVector:
+ case clang::Type::Vector:
+ break;
+
+ case clang::Type::Builtin:
+ switch (llvm::cast<clang::BuiltinType>(qual_type)->getKind())
+ {
+ //default: assert(0 && "Unknown builtin type!");
+ case clang::BuiltinType::UnknownAny:
+ case clang::BuiltinType::Void:
+ case clang::BuiltinType::BoundMember:
+ break;
+
+ case clang::BuiltinType::Bool: return lldb::eFormatBoolean;
+ case clang::BuiltinType::Char_S:
+ case clang::BuiltinType::SChar:
+ case clang::BuiltinType::WChar_S:
+ case clang::BuiltinType::Char_U:
+ case clang::BuiltinType::UChar:
+ case clang::BuiltinType::WChar_U: return lldb::eFormatChar;
+ case clang::BuiltinType::Char16: return lldb::eFormatUnicode16;
+ case clang::BuiltinType::Char32: return lldb::eFormatUnicode32;
+ case clang::BuiltinType::UShort: return lldb::eFormatUnsigned;
+ case clang::BuiltinType::Short: return lldb::eFormatDecimal;
+ case clang::BuiltinType::UInt: return lldb::eFormatUnsigned;
+ case clang::BuiltinType::Int: return lldb::eFormatDecimal;
+ case clang::BuiltinType::ULong: return lldb::eFormatUnsigned;
+ case clang::BuiltinType::Long: return lldb::eFormatDecimal;
+ case clang::BuiltinType::ULongLong: return lldb::eFormatUnsigned;
+ case clang::BuiltinType::LongLong: return lldb::eFormatDecimal;
+ case clang::BuiltinType::UInt128: return lldb::eFormatUnsigned;
+ case clang::BuiltinType::Int128: return lldb::eFormatDecimal;
+ case clang::BuiltinType::Half:
+ case clang::BuiltinType::Float:
+ case clang::BuiltinType::Double:
+ case clang::BuiltinType::LongDouble: return lldb::eFormatFloat;
+ default:
+ return lldb::eFormatHex;
+ }
+ break;
+ case clang::Type::ObjCObjectPointer: return lldb::eFormatHex;
+ case clang::Type::BlockPointer: return lldb::eFormatHex;
+ case clang::Type::Pointer: return lldb::eFormatHex;
+ case clang::Type::LValueReference:
+ case clang::Type::RValueReference: return lldb::eFormatHex;
+ case clang::Type::MemberPointer: break;
+ case clang::Type::Complex:
+ {
+ if (qual_type->isComplexType())
+ return lldb::eFormatComplex;
+ else
+ return lldb::eFormatComplexInteger;
+ }
+ case clang::Type::ObjCInterface: break;
+ case clang::Type::Record: break;
+ case clang::Type::Enum: return lldb::eFormatEnum;
+ case clang::Type::Typedef:
+ return CompilerType (getASTContext(), llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType()).GetFormat();
+ case clang::Type::Auto:
+ return CompilerType (getASTContext(), llvm::cast<clang::AutoType>(qual_type)->desugar()).GetFormat();
+ case clang::Type::Paren:
+ return CompilerType (getASTContext(), llvm::cast<clang::ParenType>(qual_type)->desugar()).GetFormat();
+ case clang::Type::Elaborated:
+ return CompilerType (getASTContext(), llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType()).GetFormat();
+ case clang::Type::DependentSizedArray:
+ case clang::Type::DependentSizedExtVector:
+ case clang::Type::UnresolvedUsing:
+ case clang::Type::Attributed:
+ case clang::Type::TemplateTypeParm:
+ case clang::Type::SubstTemplateTypeParm:
+ case clang::Type::SubstTemplateTypeParmPack:
+ case clang::Type::InjectedClassName:
+ case clang::Type::DependentName:
+ case clang::Type::DependentTemplateSpecialization:
+ case clang::Type::PackExpansion:
+ case clang::Type::ObjCObject:
+
+ case clang::Type::TypeOfExpr:
+ case clang::Type::TypeOf:
+ case clang::Type::Decltype:
+ case clang::Type::TemplateSpecialization:
+ case clang::Type::Atomic:
+ case clang::Type::Adjusted:
+ break;
+
+ // pointer type decayed from an array or function type.
+ case clang::Type::Decayed:
+ break;
+ }
+ // We don't know hot to display this type...
+ return lldb::eFormatBytes;
+}
+
+static bool
+ObjCDeclHasIVars (clang::ObjCInterfaceDecl *class_interface_decl, bool check_superclass)
+{
+ while (class_interface_decl)
+ {
+ if (class_interface_decl->ivar_size() > 0)
+ return true;
+
+ if (check_superclass)
+ class_interface_decl = class_interface_decl->getSuperClass();
+ else
+ break;
+ }
+ return false;
+}
+
+uint32_t
+ClangASTContext::GetNumChildren (lldb::opaque_compiler_type_t type, bool omit_empty_base_classes)
+{
+ if (!type)
+ return 0;
+
+ uint32_t num_children = 0;
+ clang::QualType qual_type(GetQualType(type));
+ const clang::Type::TypeClass type_class = qual_type->getTypeClass();
+ switch (type_class)
+ {
+ case clang::Type::Builtin:
+ switch (llvm::cast<clang::BuiltinType>(qual_type)->getKind())
+ {
+ case clang::BuiltinType::ObjCId: // child is Class
+ case clang::BuiltinType::ObjCClass: // child is Class
+ num_children = 1;
+ break;
+
+ default:
+ break;
+ }
+ break;
+
+ case clang::Type::Complex: return 0;
+
+ case clang::Type::Record:
+ if (GetCompleteQualType (getASTContext(), qual_type))
+ {
+ const clang::RecordType *record_type = llvm::cast<clang::RecordType>(qual_type.getTypePtr());
+ const clang::RecordDecl *record_decl = record_type->getDecl();
+ assert(record_decl);
+ const clang::CXXRecordDecl *cxx_record_decl = llvm::dyn_cast<clang::CXXRecordDecl>(record_decl);
+ if (cxx_record_decl)
+ {
+ if (omit_empty_base_classes)
+ {
+ // Check each base classes to see if it or any of its
+ // base classes contain any fields. This can help
+ // limit the noise in variable views by not having to
+ // show base classes that contain no members.
+ clang::CXXRecordDecl::base_class_const_iterator base_class, base_class_end;
+ for (base_class = cxx_record_decl->bases_begin(), base_class_end = cxx_record_decl->bases_end();
+ base_class != base_class_end;
+ ++base_class)
+ {
+ const clang::CXXRecordDecl *base_class_decl = llvm::cast<clang::CXXRecordDecl>(base_class->getType()->getAs<clang::RecordType>()->getDecl());
+
+ // Skip empty base classes
+ if (ClangASTContext::RecordHasFields(base_class_decl) == false)
+ continue;
+
+ num_children++;
+ }
+ }
+ else
+ {
+ // Include all base classes
+ num_children += cxx_record_decl->getNumBases();
+ }
+
+ }
+ clang::RecordDecl::field_iterator field, field_end;
+ for (field = record_decl->field_begin(), field_end = record_decl->field_end(); field != field_end; ++field)
+ ++num_children;
+ }
+ break;
+
+ case clang::Type::ObjCObject:
+ case clang::Type::ObjCInterface:
+ if (GetCompleteQualType (getASTContext(), qual_type))
+ {
+ const clang::ObjCObjectType *objc_class_type = llvm::dyn_cast<clang::ObjCObjectType>(qual_type.getTypePtr());
+ assert (objc_class_type);
+ if (objc_class_type)
+ {
+ clang::ObjCInterfaceDecl *class_interface_decl = objc_class_type->getInterface();
+
+ if (class_interface_decl)
+ {
+
+ clang::ObjCInterfaceDecl *superclass_interface_decl = class_interface_decl->getSuperClass();
+ if (superclass_interface_decl)
+ {
+ if (omit_empty_base_classes)
+ {
+ if (ObjCDeclHasIVars (superclass_interface_decl, true))
+ ++num_children;
+ }
+ else
+ ++num_children;
+ }
+
+ num_children += class_interface_decl->ivar_size();
+ }
+ }
+ }
+ break;
+
+ case clang::Type::ObjCObjectPointer:
+ {
+ const clang::ObjCObjectPointerType *pointer_type = llvm::cast<clang::ObjCObjectPointerType>(qual_type.getTypePtr());
+ clang::QualType pointee_type = pointer_type->getPointeeType();
+ uint32_t num_pointee_children = CompilerType (getASTContext(),pointee_type).GetNumChildren (omit_empty_base_classes);
+ // If this type points to a simple type, then it has 1 child
+ if (num_pointee_children == 0)
+ num_children = 1;
+ else
+ num_children = num_pointee_children;
+ }
+ break;
+
+ case clang::Type::Vector:
+ case clang::Type::ExtVector:
+ num_children = llvm::cast<clang::VectorType>(qual_type.getTypePtr())->getNumElements();
+ break;
+
+ case clang::Type::ConstantArray:
+ num_children = llvm::cast<clang::ConstantArrayType>(qual_type.getTypePtr())->getSize().getLimitedValue();
+ break;
+
+ case clang::Type::Pointer:
+ {
+ const clang::PointerType *pointer_type = llvm::cast<clang::PointerType>(qual_type.getTypePtr());
+ clang::QualType pointee_type (pointer_type->getPointeeType());
+ uint32_t num_pointee_children = CompilerType (getASTContext(),pointee_type).GetNumChildren (omit_empty_base_classes);
+ if (num_pointee_children == 0)
+ {
+ // We have a pointer to a pointee type that claims it has no children.
+ // We will want to look at
+ num_children = GetNumPointeeChildren (pointee_type);
+ }
+ else
+ num_children = num_pointee_children;
+ }
+ break;
+
+ case clang::Type::LValueReference:
+ case clang::Type::RValueReference:
+ {
+ const clang::ReferenceType *reference_type = llvm::cast<clang::ReferenceType>(qual_type.getTypePtr());
+ clang::QualType pointee_type = reference_type->getPointeeType();
+ uint32_t num_pointee_children = CompilerType (getASTContext(), pointee_type).GetNumChildren (omit_empty_base_classes);
+ // If this type points to a simple type, then it has 1 child
+ if (num_pointee_children == 0)
+ num_children = 1;
+ else
+ num_children = num_pointee_children;
+ }
+ break;
+
+
+ case clang::Type::Typedef:
+ num_children = CompilerType (getASTContext(), llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType()).GetNumChildren (omit_empty_base_classes);
+ break;
+
+ case clang::Type::Auto:
+ num_children = CompilerType (getASTContext(), llvm::cast<clang::AutoType>(qual_type)->getDeducedType()).GetNumChildren (omit_empty_base_classes);
+ break;
+
+ case clang::Type::Elaborated:
+ num_children = CompilerType (getASTContext(), llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType()).GetNumChildren (omit_empty_base_classes);
+ break;
+
+ case clang::Type::Paren:
+ num_children = CompilerType (getASTContext(), llvm::cast<clang::ParenType>(qual_type)->desugar()).GetNumChildren (omit_empty_base_classes);
+ break;
+ default:
+ break;
+ }
+ return num_children;
+}
+
+CompilerType
+ClangASTContext::GetBuiltinTypeByName (const ConstString &name)
+{
+ return GetBasicType (GetBasicTypeEnumeration (name));
+}
+
+lldb::BasicType
+ClangASTContext::GetBasicTypeEnumeration (lldb::opaque_compiler_type_t type)
+{
+ if (type)
+ {
+ clang::QualType qual_type(GetQualType(type));
+ const clang::Type::TypeClass type_class = qual_type->getTypeClass();
+ if (type_class == clang::Type::Builtin)
+ {
+ switch (llvm::cast<clang::BuiltinType>(qual_type)->getKind())
+ {
+ case clang::BuiltinType::Void: return eBasicTypeVoid;
+ case clang::BuiltinType::Bool: return eBasicTypeBool;
+ case clang::BuiltinType::Char_S: return eBasicTypeSignedChar;
+ case clang::BuiltinType::Char_U: return eBasicTypeUnsignedChar;
+ case clang::BuiltinType::Char16: return eBasicTypeChar16;
+ case clang::BuiltinType::Char32: return eBasicTypeChar32;
+ case clang::BuiltinType::UChar: return eBasicTypeUnsignedChar;
+ case clang::BuiltinType::SChar: return eBasicTypeSignedChar;
+ case clang::BuiltinType::WChar_S: return eBasicTypeSignedWChar;
+ case clang::BuiltinType::WChar_U: return eBasicTypeUnsignedWChar;
+ case clang::BuiltinType::Short: return eBasicTypeShort;
+ case clang::BuiltinType::UShort: return eBasicTypeUnsignedShort;
+ case clang::BuiltinType::Int: return eBasicTypeInt;
+ case clang::BuiltinType::UInt: return eBasicTypeUnsignedInt;
+ case clang::BuiltinType::Long: return eBasicTypeLong;
+ case clang::BuiltinType::ULong: return eBasicTypeUnsignedLong;
+ case clang::BuiltinType::LongLong: return eBasicTypeLongLong;
+ case clang::BuiltinType::ULongLong: return eBasicTypeUnsignedLongLong;
+ case clang::BuiltinType::Int128: return eBasicTypeInt128;
+ case clang::BuiltinType::UInt128: return eBasicTypeUnsignedInt128;
+
+ case clang::BuiltinType::Half: return eBasicTypeHalf;
+ case clang::BuiltinType::Float: return eBasicTypeFloat;
+ case clang::BuiltinType::Double: return eBasicTypeDouble;
+ case clang::BuiltinType::LongDouble:return eBasicTypeLongDouble;
+
+ case clang::BuiltinType::NullPtr: return eBasicTypeNullPtr;
+ case clang::BuiltinType::ObjCId: return eBasicTypeObjCID;
+ case clang::BuiltinType::ObjCClass: return eBasicTypeObjCClass;
+ case clang::BuiltinType::ObjCSel: return eBasicTypeObjCSel;
+ default:
+ return eBasicTypeOther;
+ }
+ }
+ }
+ return eBasicTypeInvalid;
+}
+
+void
+ClangASTContext::ForEachEnumerator (lldb::opaque_compiler_type_t type, std::function <bool (const CompilerType &integer_type, const ConstString &name, const llvm::APSInt &value)> const &callback)
+{
+ const clang::EnumType *enum_type = llvm::dyn_cast<clang::EnumType>(GetCanonicalQualType(type));
+ if (enum_type)
+ {
+ const clang::EnumDecl *enum_decl = enum_type->getDecl();
+ if (enum_decl)
+ {
+ CompilerType integer_type(this, enum_decl->getIntegerType().getAsOpaquePtr());
+
+ clang::EnumDecl::enumerator_iterator enum_pos, enum_end_pos;
+ for (enum_pos = enum_decl->enumerator_begin(), enum_end_pos = enum_decl->enumerator_end(); enum_pos != enum_end_pos; ++enum_pos)
+ {
+ ConstString name(enum_pos->getNameAsString().c_str());
+ if (!callback (integer_type, name, enum_pos->getInitVal()))
+ break;
+ }
+ }
+ }
+}
+
+
+#pragma mark Aggregate Types
+
+uint32_t
+ClangASTContext::GetNumFields (lldb::opaque_compiler_type_t type)
+{
+ if (!type)
+ return 0;
+
+ uint32_t count = 0;
+ clang::QualType qual_type(GetCanonicalQualType(type));
+ const clang::Type::TypeClass type_class = qual_type->getTypeClass();
+ switch (type_class)
+ {
+ case clang::Type::Record:
+ if (GetCompleteType(type))
+ {
+ const clang::RecordType *record_type = llvm::dyn_cast<clang::RecordType>(qual_type.getTypePtr());
+ if (record_type)
+ {
+ clang::RecordDecl *record_decl = record_type->getDecl();
+ if (record_decl)
+ {
+ uint32_t field_idx = 0;
+ clang::RecordDecl::field_iterator field, field_end;
+ for (field = record_decl->field_begin(), field_end = record_decl->field_end(); field != field_end; ++field)
+ ++field_idx;
+ count = field_idx;
+ }
+ }
+ }
+ break;
+
+ case clang::Type::Typedef:
+ count = CompilerType (getASTContext(), llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType()).GetNumFields();
+ break;
+
+ case clang::Type::Auto:
+ count = CompilerType (getASTContext(), llvm::cast<clang::AutoType>(qual_type)->getDeducedType()).GetNumFields();
+ break;
+
+ case clang::Type::Elaborated:
+ count = CompilerType (getASTContext(), llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType()).GetNumFields();
+ break;
+
+ case clang::Type::Paren:
+ count = CompilerType (getASTContext(), llvm::cast<clang::ParenType>(qual_type)->desugar()).GetNumFields();
+ break;
+
+ case clang::Type::ObjCObjectPointer:
+ if (GetCompleteType(type))
+ {
+ const clang::ObjCObjectPointerType *objc_class_type = qual_type->getAsObjCInterfacePointerType();
+ if (objc_class_type)
+ {
+ clang::ObjCInterfaceDecl *class_interface_decl = objc_class_type->getInterfaceDecl();
+
+ if (class_interface_decl)
+ count = class_interface_decl->ivar_size();
+ }
+ }
+ break;
+
+ case clang::Type::ObjCObject:
+ case clang::Type::ObjCInterface:
+ if (GetCompleteType(type))
+ {
+ const clang::ObjCObjectType *objc_class_type = llvm::dyn_cast<clang::ObjCObjectType>(qual_type.getTypePtr());
+ if (objc_class_type)
+ {
+ clang::ObjCInterfaceDecl *class_interface_decl = objc_class_type->getInterface();
+
+ if (class_interface_decl)
+ count = class_interface_decl->ivar_size();
+ }
+ }
+ break;
+
+ default:
+ break;
+ }
+ return count;
+}
+
+static lldb::opaque_compiler_type_t
+GetObjCFieldAtIndex (clang::ASTContext *ast,
+ clang::ObjCInterfaceDecl *class_interface_decl,
+ size_t idx,
+ std::string& name,
+ uint64_t *bit_offset_ptr,
+ uint32_t *bitfield_bit_size_ptr,
+ bool *is_bitfield_ptr)
+{
+ if (class_interface_decl)
+ {
+ if (idx < (class_interface_decl->ivar_size()))
+ {
+ clang::ObjCInterfaceDecl::ivar_iterator ivar_pos, ivar_end = class_interface_decl->ivar_end();
+ uint32_t ivar_idx = 0;
+
+ for (ivar_pos = class_interface_decl->ivar_begin(); ivar_pos != ivar_end; ++ivar_pos, ++ivar_idx)
+ {
+ if (ivar_idx == idx)
+ {
+ const clang::ObjCIvarDecl* ivar_decl = *ivar_pos;
+
+ clang::QualType ivar_qual_type(ivar_decl->getType());
+
+ name.assign(ivar_decl->getNameAsString());
+
+ if (bit_offset_ptr)
+ {
+ const clang::ASTRecordLayout &interface_layout = ast->getASTObjCInterfaceLayout(class_interface_decl);
+ *bit_offset_ptr = interface_layout.getFieldOffset (ivar_idx);
+ }
+
+ const bool is_bitfield = ivar_pos->isBitField();
+
+ if (bitfield_bit_size_ptr)
+ {
+ *bitfield_bit_size_ptr = 0;
+
+ if (is_bitfield && ast)
+ {
+ clang::Expr *bitfield_bit_size_expr = ivar_pos->getBitWidth();
+ llvm::APSInt bitfield_apsint;
+ if (bitfield_bit_size_expr && bitfield_bit_size_expr->EvaluateAsInt(bitfield_apsint, *ast))
+ {
+ *bitfield_bit_size_ptr = bitfield_apsint.getLimitedValue();
+ }
+ }
+ }
+ if (is_bitfield_ptr)
+ *is_bitfield_ptr = is_bitfield;
+
+ return ivar_qual_type.getAsOpaquePtr();
+ }
+ }
+ }
+ }
+ return nullptr;
+}
+
+CompilerType
+ClangASTContext::GetFieldAtIndex (lldb::opaque_compiler_type_t type, size_t idx,
+ std::string& name,
+ uint64_t *bit_offset_ptr,
+ uint32_t *bitfield_bit_size_ptr,
+ bool *is_bitfield_ptr)
+{
+ if (!type)
+ return CompilerType();
+
+ clang::QualType qual_type(GetCanonicalQualType(type));
+ const clang::Type::TypeClass type_class = qual_type->getTypeClass();
+ switch (type_class)
+ {
+ case clang::Type::Record:
+ if (GetCompleteType(type))
+ {
+ const clang::RecordType *record_type = llvm::cast<clang::RecordType>(qual_type.getTypePtr());
+ const clang::RecordDecl *record_decl = record_type->getDecl();
+ uint32_t field_idx = 0;
+ clang::RecordDecl::field_iterator field, field_end;
+ for (field = record_decl->field_begin(), field_end = record_decl->field_end(); field != field_end; ++field, ++field_idx)
+ {
+ if (idx == field_idx)
+ {
+ // Print the member type if requested
+ // Print the member name and equal sign
+ name.assign(field->getNameAsString());
+
+ // Figure out the type byte size (field_type_info.first) and
+ // alignment (field_type_info.second) from the AST context.
+ if (bit_offset_ptr)
+ {
+ const clang::ASTRecordLayout &record_layout = getASTContext()->getASTRecordLayout(record_decl);
+ *bit_offset_ptr = record_layout.getFieldOffset (field_idx);
+ }
+
+ const bool is_bitfield = field->isBitField();
+
+ if (bitfield_bit_size_ptr)
+ {
+ *bitfield_bit_size_ptr = 0;
+
+ if (is_bitfield)
+ {
+ clang::Expr *bitfield_bit_size_expr = field->getBitWidth();
+ llvm::APSInt bitfield_apsint;
+ if (bitfield_bit_size_expr && bitfield_bit_size_expr->EvaluateAsInt(bitfield_apsint, *getASTContext()))
+ {
+ *bitfield_bit_size_ptr = bitfield_apsint.getLimitedValue();
+ }
+ }
+ }
+ if (is_bitfield_ptr)
+ *is_bitfield_ptr = is_bitfield;
+
+ return CompilerType (getASTContext(), field->getType());
+ }
+ }
+ }
+ break;
+
+ case clang::Type::ObjCObjectPointer:
+ if (GetCompleteType(type))
+ {
+ const clang::ObjCObjectPointerType *objc_class_type = qual_type->getAsObjCInterfacePointerType();
+ if (objc_class_type)
+ {
+ clang::ObjCInterfaceDecl *class_interface_decl = objc_class_type->getInterfaceDecl();
+ return CompilerType (this, GetObjCFieldAtIndex(getASTContext(), class_interface_decl, idx, name, bit_offset_ptr, bitfield_bit_size_ptr, is_bitfield_ptr));
+ }
+ }
+ break;
+
+ case clang::Type::ObjCObject:
+ case clang::Type::ObjCInterface:
+ if (GetCompleteType(type))
+ {
+ const clang::ObjCObjectType *objc_class_type = llvm::dyn_cast<clang::ObjCObjectType>(qual_type.getTypePtr());
+ assert (objc_class_type);
+ if (objc_class_type)
+ {
+ clang::ObjCInterfaceDecl *class_interface_decl = objc_class_type->getInterface();
+ return CompilerType (this, GetObjCFieldAtIndex(getASTContext(), class_interface_decl, idx, name, bit_offset_ptr, bitfield_bit_size_ptr, is_bitfield_ptr));
+ }
+ }
+ break;
+
+
+ case clang::Type::Typedef:
+ return CompilerType (getASTContext(), llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType()).
+ GetFieldAtIndex (idx,
+ name,
+ bit_offset_ptr,
+ bitfield_bit_size_ptr,
+ is_bitfield_ptr);
+
+ case clang::Type::Auto:
+ return CompilerType (getASTContext(), llvm::cast<clang::AutoType>(qual_type)->getDeducedType()).
+ GetFieldAtIndex (idx,
+ name,
+ bit_offset_ptr,
+ bitfield_bit_size_ptr,
+ is_bitfield_ptr);
+
+ case clang::Type::Elaborated:
+ return CompilerType (getASTContext(), llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType()).
+ GetFieldAtIndex (idx,
+ name,
+ bit_offset_ptr,
+ bitfield_bit_size_ptr,
+ is_bitfield_ptr);
+
+ case clang::Type::Paren:
+ return CompilerType (getASTContext(), llvm::cast<clang::ParenType>(qual_type)->desugar()).
+ GetFieldAtIndex (idx,
+ name,
+ bit_offset_ptr,
+ bitfield_bit_size_ptr,
+ is_bitfield_ptr);
+
+ default:
+ break;
+ }
+ return CompilerType();
+}
+
+uint32_t
+ClangASTContext::GetNumDirectBaseClasses (lldb::opaque_compiler_type_t type)
+{
+ uint32_t count = 0;
+ clang::QualType qual_type(GetCanonicalQualType(type));
+ const clang::Type::TypeClass type_class = qual_type->getTypeClass();
+ switch (type_class)
+ {
+ case clang::Type::Record:
+ if (GetCompleteType(type))
+ {
+ const clang::CXXRecordDecl *cxx_record_decl = qual_type->getAsCXXRecordDecl();
+ if (cxx_record_decl)
+ count = cxx_record_decl->getNumBases();
+ }
+ break;
+
+ case clang::Type::ObjCObjectPointer:
+ count = GetPointeeType(type).GetNumDirectBaseClasses();
+ break;
+
+ case clang::Type::ObjCObject:
+ if (GetCompleteType(type))
+ {
+ const clang::ObjCObjectType *objc_class_type = qual_type->getAsObjCQualifiedInterfaceType();
+ if (objc_class_type)
+ {
+ clang::ObjCInterfaceDecl *class_interface_decl = objc_class_type->getInterface();
+
+ if (class_interface_decl && class_interface_decl->getSuperClass())
+ count = 1;
+ }
+ }
+ break;
+ case clang::Type::ObjCInterface:
+ if (GetCompleteType(type))
+ {
+ const clang::ObjCInterfaceType *objc_interface_type = qual_type->getAs<clang::ObjCInterfaceType>();
+ if (objc_interface_type)
+ {
+ clang::ObjCInterfaceDecl *class_interface_decl = objc_interface_type->getInterface();
+
+ if (class_interface_decl && class_interface_decl->getSuperClass())
+ count = 1;
+ }
+ }
+ break;
+
+
+ case clang::Type::Typedef:
+ count = GetNumDirectBaseClasses(llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType().getAsOpaquePtr());
+ break;
+
+ case clang::Type::Auto:
+ count = GetNumDirectBaseClasses(llvm::cast<clang::AutoType>(qual_type)->getDeducedType().getAsOpaquePtr());
+ break;
+
+ case clang::Type::Elaborated:
+ count = GetNumDirectBaseClasses(llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType().getAsOpaquePtr());
+ break;
+
+ case clang::Type::Paren:
+ return GetNumDirectBaseClasses(llvm::cast<clang::ParenType>(qual_type)->desugar().getAsOpaquePtr());
+
+ default:
+ break;
+ }
+ return count;
+
+}
+
+uint32_t
+ClangASTContext::GetNumVirtualBaseClasses (lldb::opaque_compiler_type_t type)
+{
+ uint32_t count = 0;
+ clang::QualType qual_type(GetCanonicalQualType(type));
+ const clang::Type::TypeClass type_class = qual_type->getTypeClass();
+ switch (type_class)
+ {
+ case clang::Type::Record:
+ if (GetCompleteType(type))
+ {
+ const clang::CXXRecordDecl *cxx_record_decl = qual_type->getAsCXXRecordDecl();
+ if (cxx_record_decl)
+ count = cxx_record_decl->getNumVBases();
+ }
+ break;
+
+ case clang::Type::Typedef:
+ count = GetNumVirtualBaseClasses(llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType().getAsOpaquePtr());
+ break;
+
+ case clang::Type::Auto:
+ count = GetNumVirtualBaseClasses(llvm::cast<clang::AutoType>(qual_type)->getDeducedType().getAsOpaquePtr());
+ break;
+
+ case clang::Type::Elaborated:
+ count = GetNumVirtualBaseClasses(llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType().getAsOpaquePtr());
+ break;
+
+ case clang::Type::Paren:
+ count = GetNumVirtualBaseClasses(llvm::cast<clang::ParenType>(qual_type)->desugar().getAsOpaquePtr());
+ break;
+
+ default:
+ break;
+ }
+ return count;
+
+}
+
+CompilerType
+ClangASTContext::GetDirectBaseClassAtIndex (lldb::opaque_compiler_type_t type, size_t idx, uint32_t *bit_offset_ptr)
+{
+ clang::QualType qual_type(GetCanonicalQualType(type));
+ const clang::Type::TypeClass type_class = qual_type->getTypeClass();
+ switch (type_class)
+ {
+ case clang::Type::Record:
+ if (GetCompleteType(type))
+ {
+ const clang::CXXRecordDecl *cxx_record_decl = qual_type->getAsCXXRecordDecl();
+ if (cxx_record_decl)
+ {
+ uint32_t curr_idx = 0;
+ clang::CXXRecordDecl::base_class_const_iterator base_class, base_class_end;
+ for (base_class = cxx_record_decl->bases_begin(), base_class_end = cxx_record_decl->bases_end();
+ base_class != base_class_end;
+ ++base_class, ++curr_idx)
+ {
+ if (curr_idx == idx)
+ {
+ if (bit_offset_ptr)
+ {
+ const clang::ASTRecordLayout &record_layout = getASTContext()->getASTRecordLayout(cxx_record_decl);
+ const clang::CXXRecordDecl *base_class_decl = llvm::cast<clang::CXXRecordDecl>(base_class->getType()->getAs<clang::RecordType>()->getDecl());
+ if (base_class->isVirtual())
+ *bit_offset_ptr = record_layout.getVBaseClassOffset(base_class_decl).getQuantity() * 8;
+ else
+ *bit_offset_ptr = record_layout.getBaseClassOffset(base_class_decl).getQuantity() * 8;
+ }
+ return CompilerType (this, base_class->getType().getAsOpaquePtr());
+ }
+ }
+ }
+ }
+ break;
+
+ case clang::Type::ObjCObjectPointer:
+ return GetPointeeType(type).GetDirectBaseClassAtIndex(idx, bit_offset_ptr);
+
+ case clang::Type::ObjCObject:
+ if (idx == 0 && GetCompleteType(type))
+ {
+ const clang::ObjCObjectType *objc_class_type = qual_type->getAsObjCQualifiedInterfaceType();
+ if (objc_class_type)
+ {
+ clang::ObjCInterfaceDecl *class_interface_decl = objc_class_type->getInterface();
+
+ if (class_interface_decl)
+ {
+ clang::ObjCInterfaceDecl *superclass_interface_decl = class_interface_decl->getSuperClass();
+ if (superclass_interface_decl)
+ {
+ if (bit_offset_ptr)
+ *bit_offset_ptr = 0;
+ return CompilerType (getASTContext(), getASTContext()->getObjCInterfaceType(superclass_interface_decl));
+ }
+ }
+ }
+ }
+ break;
+ case clang::Type::ObjCInterface:
+ if (idx == 0 && GetCompleteType(type))
+ {
+ const clang::ObjCObjectType *objc_interface_type = qual_type->getAs<clang::ObjCInterfaceType>();
+ if (objc_interface_type)
+ {
+ clang::ObjCInterfaceDecl *class_interface_decl = objc_interface_type->getInterface();
+
+ if (class_interface_decl)
+ {
+ clang::ObjCInterfaceDecl *superclass_interface_decl = class_interface_decl->getSuperClass();
+ if (superclass_interface_decl)
+ {
+ if (bit_offset_ptr)
+ *bit_offset_ptr = 0;
+ return CompilerType (getASTContext(), getASTContext()->getObjCInterfaceType(superclass_interface_decl));
+ }
+ }
+ }
+ }
+ break;
+
+
+ case clang::Type::Typedef:
+ return GetDirectBaseClassAtIndex (llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType().getAsOpaquePtr(), idx, bit_offset_ptr);
+
+ case clang::Type::Auto:
+ return GetDirectBaseClassAtIndex (llvm::cast<clang::AutoType>(qual_type)->getDeducedType().getAsOpaquePtr(), idx, bit_offset_ptr);
+
+ case clang::Type::Elaborated:
+ return GetDirectBaseClassAtIndex (llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType().getAsOpaquePtr(), idx, bit_offset_ptr);
+
+ case clang::Type::Paren:
+ return GetDirectBaseClassAtIndex (llvm::cast<clang::ParenType>(qual_type)->desugar().getAsOpaquePtr(), idx, bit_offset_ptr);
+
+ default:
+ break;
+ }
+ return CompilerType();
+}
+
+CompilerType
+ClangASTContext::GetVirtualBaseClassAtIndex (lldb::opaque_compiler_type_t type,
+ size_t idx,
+ uint32_t *bit_offset_ptr)
+{
+ clang::QualType qual_type(GetCanonicalQualType(type));
+ const clang::Type::TypeClass type_class = qual_type->getTypeClass();
+ switch (type_class)
{
- if (clang::CXXMethodDecl *method_decl = llvm::dyn_cast<clang::CXXMethodDecl>(decl_ctx))
+ case clang::Type::Record:
+ if (GetCompleteType(type))
+ {
+ const clang::CXXRecordDecl *cxx_record_decl = qual_type->getAsCXXRecordDecl();
+ if (cxx_record_decl)
+ {
+ uint32_t curr_idx = 0;
+ clang::CXXRecordDecl::base_class_const_iterator base_class, base_class_end;
+ for (base_class = cxx_record_decl->vbases_begin(), base_class_end = cxx_record_decl->vbases_end();
+ base_class != base_class_end;
+ ++base_class, ++curr_idx)
+ {
+ if (curr_idx == idx)
+ {
+ if (bit_offset_ptr)
+ {
+ const clang::ASTRecordLayout &record_layout = getASTContext()->getASTRecordLayout(cxx_record_decl);
+ const clang::CXXRecordDecl *base_class_decl = llvm::cast<clang::CXXRecordDecl>(base_class->getType()->getAs<clang::RecordType>()->getDecl());
+ *bit_offset_ptr = record_layout.getVBaseClassOffset(base_class_decl).getQuantity() * 8;
+
+ }
+ return CompilerType (this, base_class->getType().getAsOpaquePtr());
+ }
+ }
+ }
+ }
+ break;
+
+ case clang::Type::Typedef:
+ return GetVirtualBaseClassAtIndex (llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType().getAsOpaquePtr(), idx, bit_offset_ptr);
+
+ case clang::Type::Auto:
+ return GetVirtualBaseClassAtIndex (llvm::cast<clang::AutoType>(qual_type)->getDeducedType().getAsOpaquePtr(), idx, bit_offset_ptr);
+
+ case clang::Type::Elaborated:
+ return GetVirtualBaseClassAtIndex (llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType().getAsOpaquePtr(), idx, bit_offset_ptr);
+
+ case clang::Type::Paren:
+ return GetVirtualBaseClassAtIndex (llvm::cast<clang::ParenType>(qual_type)->desugar().getAsOpaquePtr(), idx, bit_offset_ptr);
+
+ default:
+ break;
+ }
+ return CompilerType();
+
+}
+
+// If a pointer to a pointee type (the clang_type arg) says that it has no
+// children, then we either need to trust it, or override it and return a
+// different result. For example, an "int *" has one child that is an integer,
+// but a function pointer doesn't have any children. Likewise if a Record type
+// claims it has no children, then there really is nothing to show.
+uint32_t
+ClangASTContext::GetNumPointeeChildren (clang::QualType type)
+{
+ if (type.isNull())
+ return 0;
+
+ clang::QualType qual_type(type.getCanonicalType());
+ const clang::Type::TypeClass type_class = qual_type->getTypeClass();
+ switch (type_class)
+ {
+ case clang::Type::Builtin:
+ switch (llvm::cast<clang::BuiltinType>(qual_type)->getKind())
+ {
+ case clang::BuiltinType::UnknownAny:
+ case clang::BuiltinType::Void:
+ case clang::BuiltinType::NullPtr:
+ case clang::BuiltinType::OCLEvent:
+ case clang::BuiltinType::OCLImage1d:
+ case clang::BuiltinType::OCLImage1dArray:
+ case clang::BuiltinType::OCLImage1dBuffer:
+ case clang::BuiltinType::OCLImage2d:
+ case clang::BuiltinType::OCLImage2dArray:
+ case clang::BuiltinType::OCLImage3d:
+ case clang::BuiltinType::OCLSampler:
+ return 0;
+ case clang::BuiltinType::Bool:
+ case clang::BuiltinType::Char_U:
+ case clang::BuiltinType::UChar:
+ case clang::BuiltinType::WChar_U:
+ case clang::BuiltinType::Char16:
+ case clang::BuiltinType::Char32:
+ case clang::BuiltinType::UShort:
+ case clang::BuiltinType::UInt:
+ case clang::BuiltinType::ULong:
+ case clang::BuiltinType::ULongLong:
+ case clang::BuiltinType::UInt128:
+ case clang::BuiltinType::Char_S:
+ case clang::BuiltinType::SChar:
+ case clang::BuiltinType::WChar_S:
+ case clang::BuiltinType::Short:
+ case clang::BuiltinType::Int:
+ case clang::BuiltinType::Long:
+ case clang::BuiltinType::LongLong:
+ case clang::BuiltinType::Int128:
+ case clang::BuiltinType::Float:
+ case clang::BuiltinType::Double:
+ case clang::BuiltinType::LongDouble:
+ case clang::BuiltinType::Dependent:
+ case clang::BuiltinType::Overload:
+ case clang::BuiltinType::ObjCId:
+ case clang::BuiltinType::ObjCClass:
+ case clang::BuiltinType::ObjCSel:
+ case clang::BuiltinType::BoundMember:
+ case clang::BuiltinType::Half:
+ case clang::BuiltinType::ARCUnbridgedCast:
+ case clang::BuiltinType::PseudoObject:
+ case clang::BuiltinType::BuiltinFn:
+ case clang::BuiltinType::OMPArraySection:
+ return 1;
+ default:
+ return 0;
+ }
+ break;
+
+ case clang::Type::Complex: return 1;
+ case clang::Type::Pointer: return 1;
+ case clang::Type::BlockPointer: return 0; // If block pointers don't have debug info, then no children for them
+ case clang::Type::LValueReference: return 1;
+ case clang::Type::RValueReference: return 1;
+ case clang::Type::MemberPointer: return 0;
+ case clang::Type::ConstantArray: return 0;
+ case clang::Type::IncompleteArray: return 0;
+ case clang::Type::VariableArray: return 0;
+ case clang::Type::DependentSizedArray: return 0;
+ case clang::Type::DependentSizedExtVector: return 0;
+ case clang::Type::Vector: return 0;
+ case clang::Type::ExtVector: return 0;
+ case clang::Type::FunctionProto: return 0; // When we function pointers, they have no children...
+ case clang::Type::FunctionNoProto: return 0; // When we function pointers, they have no children...
+ case clang::Type::UnresolvedUsing: return 0;
+ case clang::Type::Paren: return GetNumPointeeChildren (llvm::cast<clang::ParenType>(qual_type)->desugar());
+ case clang::Type::Typedef: return GetNumPointeeChildren (llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType());
+ case clang::Type::Auto: return GetNumPointeeChildren (llvm::cast<clang::AutoType>(qual_type)->getDeducedType());
+ case clang::Type::Elaborated: return GetNumPointeeChildren (llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType());
+ case clang::Type::TypeOfExpr: return 0;
+ case clang::Type::TypeOf: return 0;
+ case clang::Type::Decltype: return 0;
+ case clang::Type::Record: return 0;
+ case clang::Type::Enum: return 1;
+ case clang::Type::TemplateTypeParm: return 1;
+ case clang::Type::SubstTemplateTypeParm: return 1;
+ case clang::Type::TemplateSpecialization: return 1;
+ case clang::Type::InjectedClassName: return 0;
+ case clang::Type::DependentName: return 1;
+ case clang::Type::DependentTemplateSpecialization: return 1;
+ case clang::Type::ObjCObject: return 0;
+ case clang::Type::ObjCInterface: return 0;
+ case clang::Type::ObjCObjectPointer: return 1;
+ default:
+ break;
+ }
+ return 0;
+}
+
+
+CompilerType
+ClangASTContext::GetChildCompilerTypeAtIndex (lldb::opaque_compiler_type_t type,
+ ExecutionContext *exe_ctx,
+ size_t idx,
+ bool transparent_pointers,
+ bool omit_empty_base_classes,
+ bool ignore_array_bounds,
+ std::string& child_name,
+ uint32_t &child_byte_size,
+ int32_t &child_byte_offset,
+ uint32_t &child_bitfield_bit_size,
+ uint32_t &child_bitfield_bit_offset,
+ bool &child_is_base_class,
+ bool &child_is_deref_of_parent,
+ ValueObject *valobj,
+ uint64_t &language_flags)
+{
+ if (!type)
+ return CompilerType();
+
+ clang::QualType parent_qual_type(GetCanonicalQualType(type));
+ const clang::Type::TypeClass parent_type_class = parent_qual_type->getTypeClass();
+ child_bitfield_bit_size = 0;
+ child_bitfield_bit_offset = 0;
+ child_is_base_class = false;
+ language_flags = 0;
+
+ const bool idx_is_valid = idx < GetNumChildren (type, omit_empty_base_classes);
+ uint32_t bit_offset;
+ switch (parent_type_class)
+ {
+ case clang::Type::Builtin:
+ if (idx_is_valid)
+ {
+ switch (llvm::cast<clang::BuiltinType>(parent_qual_type)->getKind())
+ {
+ case clang::BuiltinType::ObjCId:
+ case clang::BuiltinType::ObjCClass:
+ child_name = "isa";
+ child_byte_size = getASTContext()->getTypeSize(getASTContext()->ObjCBuiltinClassTy) / CHAR_BIT;
+ return CompilerType (getASTContext(), getASTContext()->ObjCBuiltinClassTy);
+
+ default:
+ break;
+ }
+ }
+ break;
+
+ case clang::Type::Record:
+ if (idx_is_valid && GetCompleteType(type))
+ {
+ const clang::RecordType *record_type = llvm::cast<clang::RecordType>(parent_qual_type.getTypePtr());
+ const clang::RecordDecl *record_decl = record_type->getDecl();
+ assert(record_decl);
+ const clang::ASTRecordLayout &record_layout = getASTContext()->getASTRecordLayout(record_decl);
+ uint32_t child_idx = 0;
+
+ const clang::CXXRecordDecl *cxx_record_decl = llvm::dyn_cast<clang::CXXRecordDecl>(record_decl);
+ if (cxx_record_decl)
+ {
+ // We might have base classes to print out first
+ clang::CXXRecordDecl::base_class_const_iterator base_class, base_class_end;
+ for (base_class = cxx_record_decl->bases_begin(), base_class_end = cxx_record_decl->bases_end();
+ base_class != base_class_end;
+ ++base_class)
+ {
+ const clang::CXXRecordDecl *base_class_decl = nullptr;
+
+ // Skip empty base classes
+ if (omit_empty_base_classes)
+ {
+ base_class_decl = llvm::cast<clang::CXXRecordDecl>(base_class->getType()->getAs<clang::RecordType>()->getDecl());
+ if (ClangASTContext::RecordHasFields(base_class_decl) == false)
+ continue;
+ }
+
+ if (idx == child_idx)
+ {
+ if (base_class_decl == nullptr)
+ base_class_decl = llvm::cast<clang::CXXRecordDecl>(base_class->getType()->getAs<clang::RecordType>()->getDecl());
+
+
+ if (base_class->isVirtual())
+ {
+ bool handled = false;
+ if (valobj)
+ {
+ Error err;
+ AddressType addr_type = eAddressTypeInvalid;
+ lldb::addr_t vtable_ptr_addr = valobj->GetCPPVTableAddress(addr_type);
+
+ if (vtable_ptr_addr != LLDB_INVALID_ADDRESS && addr_type == eAddressTypeLoad)
+ {
+
+ ExecutionContext exe_ctx (valobj->GetExecutionContextRef());
+ Process *process = exe_ctx.GetProcessPtr();
+ if (process)
+ {
+ clang::VTableContextBase *vtable_ctx = getASTContext()->getVTableContext();
+ if (vtable_ctx)
+ {
+ if (vtable_ctx->isMicrosoft())
+ {
+ clang::MicrosoftVTableContext *msoft_vtable_ctx = static_cast<clang::MicrosoftVTableContext *>(vtable_ctx);
+
+ if (vtable_ptr_addr)
+ {
+ const lldb::addr_t vbtable_ptr_addr = vtable_ptr_addr + record_layout.getVBPtrOffset().getQuantity();
+
+ const lldb::addr_t vbtable_ptr = process->ReadPointerFromMemory(vbtable_ptr_addr, err);
+ if (vbtable_ptr != LLDB_INVALID_ADDRESS)
+ {
+ // Get the index into the virtual base table. The index is the index in uint32_t from vbtable_ptr
+ const unsigned vbtable_index = msoft_vtable_ctx->getVBTableIndex(cxx_record_decl, base_class_decl);
+ const lldb::addr_t base_offset_addr = vbtable_ptr + vbtable_index * 4;
+ const uint32_t base_offset = process->ReadUnsignedIntegerFromMemory(base_offset_addr, 4, UINT32_MAX, err);
+ if (base_offset != UINT32_MAX)
+ {
+ handled = true;
+ bit_offset = base_offset * 8;
+ }
+ }
+ }
+ }
+ else
+ {
+ clang::ItaniumVTableContext *itanium_vtable_ctx = static_cast<clang::ItaniumVTableContext *>(vtable_ctx);
+ if (vtable_ptr_addr)
+ {
+ const lldb::addr_t vtable_ptr = process->ReadPointerFromMemory(vtable_ptr_addr, err);
+ if (vtable_ptr != LLDB_INVALID_ADDRESS)
+ {
+ clang::CharUnits base_offset_offset = itanium_vtable_ctx->getVirtualBaseOffsetOffset(cxx_record_decl, base_class_decl);
+ const lldb::addr_t base_offset_addr = vtable_ptr + base_offset_offset.getQuantity();
+ const uint32_t base_offset = process->ReadUnsignedIntegerFromMemory(base_offset_addr, 4, UINT32_MAX, err);
+ if (base_offset != UINT32_MAX)
+ {
+ handled = true;
+ bit_offset = base_offset * 8;
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+
+ }
+ if (!handled)
+ bit_offset = record_layout.getVBaseClassOffset(base_class_decl).getQuantity() * 8;
+ }
+ else
+ bit_offset = record_layout.getBaseClassOffset(base_class_decl).getQuantity() * 8;
+
+ // Base classes should be a multiple of 8 bits in size
+ child_byte_offset = bit_offset/8;
+ CompilerType base_class_clang_type(getASTContext(), base_class->getType());
+ child_name = base_class_clang_type.GetTypeName().AsCString("");
+ uint64_t base_class_clang_type_bit_size = base_class_clang_type.GetBitSize(exe_ctx ? exe_ctx->GetBestExecutionContextScope() : NULL);
+
+ // Base classes bit sizes should be a multiple of 8 bits in size
+ assert (base_class_clang_type_bit_size % 8 == 0);
+ child_byte_size = base_class_clang_type_bit_size / 8;
+ child_is_base_class = true;
+ return base_class_clang_type;
+ }
+ // We don't increment the child index in the for loop since we might
+ // be skipping empty base classes
+ ++child_idx;
+ }
+ }
+ // Make sure index is in range...
+ uint32_t field_idx = 0;
+ clang::RecordDecl::field_iterator field, field_end;
+ for (field = record_decl->field_begin(), field_end = record_decl->field_end(); field != field_end; ++field, ++field_idx, ++child_idx)
+ {
+ if (idx == child_idx)
+ {
+ // Print the member type if requested
+ // Print the member name and equal sign
+ child_name.assign(field->getNameAsString().c_str());
+
+ // Figure out the type byte size (field_type_info.first) and
+ // alignment (field_type_info.second) from the AST context.
+ CompilerType field_clang_type (getASTContext(), field->getType());
+ assert(field_idx < record_layout.getFieldCount());
+ child_byte_size = field_clang_type.GetByteSize(exe_ctx ? exe_ctx->GetBestExecutionContextScope() : NULL);
+
+ // Figure out the field offset within the current struct/union/class type
+ bit_offset = record_layout.getFieldOffset (field_idx);
+ child_byte_offset = bit_offset / 8;
+ if (ClangASTContext::FieldIsBitfield (getASTContext(), *field, child_bitfield_bit_size))
+ child_bitfield_bit_offset = bit_offset % 8;
+
+ return field_clang_type;
+ }
+ }
+ }
+ break;
+
+ case clang::Type::ObjCObject:
+ case clang::Type::ObjCInterface:
+ if (idx_is_valid && GetCompleteType(type))
+ {
+ const clang::ObjCObjectType *objc_class_type = llvm::dyn_cast<clang::ObjCObjectType>(parent_qual_type.getTypePtr());
+ assert (objc_class_type);
+ if (objc_class_type)
+ {
+ uint32_t child_idx = 0;
+ clang::ObjCInterfaceDecl *class_interface_decl = objc_class_type->getInterface();
+
+ if (class_interface_decl)
+ {
+
+ const clang::ASTRecordLayout &interface_layout = getASTContext()->getASTObjCInterfaceLayout(class_interface_decl);
+ clang::ObjCInterfaceDecl *superclass_interface_decl = class_interface_decl->getSuperClass();
+ if (superclass_interface_decl)
+ {
+ if (omit_empty_base_classes)
+ {
+ CompilerType base_class_clang_type (getASTContext(), getASTContext()->getObjCInterfaceType(superclass_interface_decl));
+ if (base_class_clang_type.GetNumChildren(omit_empty_base_classes) > 0)
+ {
+ if (idx == 0)
+ {
+ clang::QualType ivar_qual_type(getASTContext()->getObjCInterfaceType(superclass_interface_decl));
+
+
+ child_name.assign(superclass_interface_decl->getNameAsString().c_str());
+
+ clang::TypeInfo ivar_type_info = getASTContext()->getTypeInfo(ivar_qual_type.getTypePtr());
+
+ child_byte_size = ivar_type_info.Width / 8;
+ child_byte_offset = 0;
+ child_is_base_class = true;
+
+ return CompilerType (getASTContext(), ivar_qual_type);
+ }
+
+ ++child_idx;
+ }
+ }
+ else
+ ++child_idx;
+ }
+
+ const uint32_t superclass_idx = child_idx;
+
+ if (idx < (child_idx + class_interface_decl->ivar_size()))
+ {
+ clang::ObjCInterfaceDecl::ivar_iterator ivar_pos, ivar_end = class_interface_decl->ivar_end();
+
+ for (ivar_pos = class_interface_decl->ivar_begin(); ivar_pos != ivar_end; ++ivar_pos)
+ {
+ if (child_idx == idx)
+ {
+ clang::ObjCIvarDecl* ivar_decl = *ivar_pos;
+
+ clang::QualType ivar_qual_type(ivar_decl->getType());
+
+ child_name.assign(ivar_decl->getNameAsString().c_str());
+
+ clang::TypeInfo ivar_type_info = getASTContext()->getTypeInfo(ivar_qual_type.getTypePtr());
+
+ child_byte_size = ivar_type_info.Width / 8;
+
+ // Figure out the field offset within the current struct/union/class type
+ // For ObjC objects, we can't trust the bit offset we get from the Clang AST, since
+ // that doesn't account for the space taken up by unbacked properties, or from
+ // the changing size of base classes that are newer than this class.
+ // So if we have a process around that we can ask about this object, do so.
+ child_byte_offset = LLDB_INVALID_IVAR_OFFSET;
+ Process *process = nullptr;
+ if (exe_ctx)
+ process = exe_ctx->GetProcessPtr();
+ if (process)
+ {
+ ObjCLanguageRuntime *objc_runtime = process->GetObjCLanguageRuntime();
+ if (objc_runtime != nullptr)
+ {
+ CompilerType parent_ast_type (getASTContext(), parent_qual_type);
+ child_byte_offset = objc_runtime->GetByteOffsetForIvar (parent_ast_type, ivar_decl->getNameAsString().c_str());
+ }
+ }
+
+ // Setting this to UINT32_MAX to make sure we don't compute it twice...
+ bit_offset = UINT32_MAX;
+
+ if (child_byte_offset == static_cast<int32_t>(LLDB_INVALID_IVAR_OFFSET))
+ {
+ bit_offset = interface_layout.getFieldOffset (child_idx - superclass_idx);
+ child_byte_offset = bit_offset / 8;
+ }
+
+ // Note, the ObjC Ivar Byte offset is just that, it doesn't account for the bit offset
+ // of a bitfield within its containing object. So regardless of where we get the byte
+ // offset from, we still need to get the bit offset for bitfields from the layout.
+
+ if (ClangASTContext::FieldIsBitfield (getASTContext(), ivar_decl, child_bitfield_bit_size))
+ {
+ if (bit_offset == UINT32_MAX)
+ bit_offset = interface_layout.getFieldOffset (child_idx - superclass_idx);
+
+ child_bitfield_bit_offset = bit_offset % 8;
+ }
+ return CompilerType (getASTContext(), ivar_qual_type);
+ }
+ ++child_idx;
+ }
+ }
+ }
+ }
+ }
+ break;
+
+ case clang::Type::ObjCObjectPointer:
+ if (idx_is_valid)
+ {
+ CompilerType pointee_clang_type (GetPointeeType(type));
+
+ if (transparent_pointers && pointee_clang_type.IsAggregateType())
+ {
+ child_is_deref_of_parent = false;
+ bool tmp_child_is_deref_of_parent = false;
+ return pointee_clang_type.GetChildCompilerTypeAtIndex (exe_ctx,
+ idx,
+ transparent_pointers,
+ omit_empty_base_classes,
+ ignore_array_bounds,
+ child_name,
+ child_byte_size,
+ child_byte_offset,
+ child_bitfield_bit_size,
+ child_bitfield_bit_offset,
+ child_is_base_class,
+ tmp_child_is_deref_of_parent,
+ valobj,
+ language_flags);
+ }
+ else
+ {
+ child_is_deref_of_parent = true;
+ const char *parent_name = valobj ? valobj->GetName().GetCString() : NULL;
+ if (parent_name)
+ {
+ child_name.assign(1, '*');
+ child_name += parent_name;
+ }
+
+ // We have a pointer to an simple type
+ if (idx == 0 && pointee_clang_type.GetCompleteType())
+ {
+ child_byte_size = pointee_clang_type.GetByteSize(exe_ctx ? exe_ctx->GetBestExecutionContextScope() : NULL);
+ child_byte_offset = 0;
+ return pointee_clang_type;
+ }
+ }
+ }
+ break;
+
+ case clang::Type::Vector:
+ case clang::Type::ExtVector:
+ if (idx_is_valid)
+ {
+ const clang::VectorType *array = llvm::cast<clang::VectorType>(parent_qual_type.getTypePtr());
+ if (array)
+ {
+ CompilerType element_type (getASTContext(), array->getElementType());
+ if (element_type.GetCompleteType())
+ {
+ char element_name[64];
+ ::snprintf (element_name, sizeof (element_name), "[%" PRIu64 "]", static_cast<uint64_t>(idx));
+ child_name.assign(element_name);
+ child_byte_size = element_type.GetByteSize(exe_ctx ? exe_ctx->GetBestExecutionContextScope() : NULL);
+ child_byte_offset = (int32_t)idx * (int32_t)child_byte_size;
+ return element_type;
+ }
+ }
+ }
+ break;
+
+ case clang::Type::ConstantArray:
+ case clang::Type::IncompleteArray:
+ if (ignore_array_bounds || idx_is_valid)
+ {
+ const clang::ArrayType *array = GetQualType(type)->getAsArrayTypeUnsafe();
+ if (array)
+ {
+ CompilerType element_type (getASTContext(), array->getElementType());
+ if (element_type.GetCompleteType())
+ {
+ char element_name[64];
+ ::snprintf (element_name, sizeof (element_name), "[%" PRIu64 "]", static_cast<uint64_t>(idx));
+ child_name.assign(element_name);
+ child_byte_size = element_type.GetByteSize(exe_ctx ? exe_ctx->GetBestExecutionContextScope() : NULL);
+ child_byte_offset = (int32_t)idx * (int32_t)child_byte_size;
+ return element_type;
+ }
+ }
+ }
+ break;
+
+
+ case clang::Type::Pointer:
+ if (idx_is_valid)
+ {
+ CompilerType pointee_clang_type (GetPointeeType(type));
+
+ // Don't dereference "void *" pointers
+ if (pointee_clang_type.IsVoidType())
+ return CompilerType();
+
+ if (transparent_pointers && pointee_clang_type.IsAggregateType ())
+ {
+ child_is_deref_of_parent = false;
+ bool tmp_child_is_deref_of_parent = false;
+ return pointee_clang_type.GetChildCompilerTypeAtIndex (exe_ctx,
+ idx,
+ transparent_pointers,
+ omit_empty_base_classes,
+ ignore_array_bounds,
+ child_name,
+ child_byte_size,
+ child_byte_offset,
+ child_bitfield_bit_size,
+ child_bitfield_bit_offset,
+ child_is_base_class,
+ tmp_child_is_deref_of_parent,
+ valobj,
+ language_flags);
+ }
+ else
+ {
+ child_is_deref_of_parent = true;
+
+ const char *parent_name = valobj ? valobj->GetName().GetCString() : NULL;
+ if (parent_name)
+ {
+ child_name.assign(1, '*');
+ child_name += parent_name;
+ }
+
+ // We have a pointer to an simple type
+ if (idx == 0)
+ {
+ child_byte_size = pointee_clang_type.GetByteSize(exe_ctx ? exe_ctx->GetBestExecutionContextScope() : NULL);
+ child_byte_offset = 0;
+ return pointee_clang_type;
+ }
+ }
+ }
+ break;
+
+ case clang::Type::LValueReference:
+ case clang::Type::RValueReference:
+ if (idx_is_valid)
+ {
+ const clang::ReferenceType *reference_type = llvm::cast<clang::ReferenceType>(parent_qual_type.getTypePtr());
+ CompilerType pointee_clang_type (getASTContext(), reference_type->getPointeeType());
+ if (transparent_pointers && pointee_clang_type.IsAggregateType ())
+ {
+ child_is_deref_of_parent = false;
+ bool tmp_child_is_deref_of_parent = false;
+ return pointee_clang_type.GetChildCompilerTypeAtIndex (exe_ctx,
+ idx,
+ transparent_pointers,
+ omit_empty_base_classes,
+ ignore_array_bounds,
+ child_name,
+ child_byte_size,
+ child_byte_offset,
+ child_bitfield_bit_size,
+ child_bitfield_bit_offset,
+ child_is_base_class,
+ tmp_child_is_deref_of_parent,
+ valobj,
+ language_flags);
+ }
+ else
+ {
+ const char *parent_name = valobj ? valobj->GetName().GetCString() : NULL;
+ if (parent_name)
+ {
+ child_name.assign(1, '&');
+ child_name += parent_name;
+ }
+
+ // We have a pointer to an simple type
+ if (idx == 0)
+ {
+ child_byte_size = pointee_clang_type.GetByteSize(exe_ctx ? exe_ctx->GetBestExecutionContextScope() : NULL);
+ child_byte_offset = 0;
+ return pointee_clang_type;
+ }
+ }
+ }
+ break;
+
+ case clang::Type::Typedef:
+ {
+ CompilerType typedefed_clang_type (getASTContext(), llvm::cast<clang::TypedefType>(parent_qual_type)->getDecl()->getUnderlyingType());
+ return typedefed_clang_type.GetChildCompilerTypeAtIndex (exe_ctx,
+ idx,
+ transparent_pointers,
+ omit_empty_base_classes,
+ ignore_array_bounds,
+ child_name,
+ child_byte_size,
+ child_byte_offset,
+ child_bitfield_bit_size,
+ child_bitfield_bit_offset,
+ child_is_base_class,
+ child_is_deref_of_parent,
+ valobj,
+ language_flags);
+ }
+ break;
+
+ case clang::Type::Auto:
+ {
+ CompilerType elaborated_clang_type (getASTContext(), llvm::cast<clang::AutoType>(parent_qual_type)->getDeducedType());
+ return elaborated_clang_type.GetChildCompilerTypeAtIndex (exe_ctx,
+ idx,
+ transparent_pointers,
+ omit_empty_base_classes,
+ ignore_array_bounds,
+ child_name,
+ child_byte_size,
+ child_byte_offset,
+ child_bitfield_bit_size,
+ child_bitfield_bit_offset,
+ child_is_base_class,
+ child_is_deref_of_parent,
+ valobj,
+ language_flags);
+ }
+
+ case clang::Type::Elaborated:
{
- if (method_decl->isStatic())
+ CompilerType elaborated_clang_type (getASTContext(), llvm::cast<clang::ElaboratedType>(parent_qual_type)->getNamedType());
+ return elaborated_clang_type.GetChildCompilerTypeAtIndex (exe_ctx,
+ idx,
+ transparent_pointers,
+ omit_empty_base_classes,
+ ignore_array_bounds,
+ child_name,
+ child_byte_size,
+ child_byte_offset,
+ child_bitfield_bit_size,
+ child_bitfield_bit_offset,
+ child_is_base_class,
+ child_is_deref_of_parent,
+ valobj,
+ language_flags);
+ }
+
+ case clang::Type::Paren:
+ {
+ CompilerType paren_clang_type (getASTContext(), llvm::cast<clang::ParenType>(parent_qual_type)->desugar());
+ return paren_clang_type.GetChildCompilerTypeAtIndex (exe_ctx,
+ idx,
+ transparent_pointers,
+ omit_empty_base_classes,
+ ignore_array_bounds,
+ child_name,
+ child_byte_size,
+ child_byte_offset,
+ child_bitfield_bit_size,
+ child_bitfield_bit_offset,
+ child_is_base_class,
+ child_is_deref_of_parent,
+ valobj,
+ language_flags);
+ }
+
+
+ default:
+ break;
+ }
+ return CompilerType();
+}
+
+static uint32_t
+GetIndexForRecordBase
+(
+ const clang::RecordDecl *record_decl,
+ const clang::CXXBaseSpecifier *base_spec,
+ bool omit_empty_base_classes
+ )
+{
+ uint32_t child_idx = 0;
+
+ const clang::CXXRecordDecl *cxx_record_decl = llvm::dyn_cast<clang::CXXRecordDecl>(record_decl);
+
+ // const char *super_name = record_decl->getNameAsCString();
+ // const char *base_name = base_spec->getType()->getAs<clang::RecordType>()->getDecl()->getNameAsCString();
+ // printf ("GetIndexForRecordChild (%s, %s)\n", super_name, base_name);
+ //
+ if (cxx_record_decl)
+ {
+ clang::CXXRecordDecl::base_class_const_iterator base_class, base_class_end;
+ for (base_class = cxx_record_decl->bases_begin(), base_class_end = cxx_record_decl->bases_end();
+ base_class != base_class_end;
+ ++base_class)
+ {
+ if (omit_empty_base_classes)
{
- is_instance_method = false;
+ if (BaseSpecifierIsEmpty (base_class))
+ continue;
}
+
+ // printf ("GetIndexForRecordChild (%s, %s) base[%u] = %s\n", super_name, base_name,
+ // child_idx,
+ // base_class->getType()->getAs<clang::RecordType>()->getDecl()->getNameAsCString());
+ //
+ //
+ if (base_class == base_spec)
+ return child_idx;
+ ++child_idx;
+ }
+ }
+
+ return UINT32_MAX;
+}
+
+
+static uint32_t
+GetIndexForRecordChild (const clang::RecordDecl *record_decl,
+ clang::NamedDecl *canonical_decl,
+ bool omit_empty_base_classes)
+{
+ uint32_t child_idx = ClangASTContext::GetNumBaseClasses (llvm::dyn_cast<clang::CXXRecordDecl>(record_decl),
+ omit_empty_base_classes);
+
+ clang::RecordDecl::field_iterator field, field_end;
+ for (field = record_decl->field_begin(), field_end = record_decl->field_end();
+ field != field_end;
+ ++field, ++child_idx)
+ {
+ if (field->getCanonicalDecl() == canonical_decl)
+ return child_idx;
+ }
+
+ return UINT32_MAX;
+}
+
+// Look for a child member (doesn't include base classes, but it does include
+// their members) in the type hierarchy. Returns an index path into "clang_type"
+// on how to reach the appropriate member.
+//
+// class A
+// {
+// public:
+// int m_a;
+// int m_b;
+// };
+//
+// class B
+// {
+// };
+//
+// class C :
+// public B,
+// public A
+// {
+// };
+//
+// If we have a clang type that describes "class C", and we wanted to looked
+// "m_b" in it:
+//
+// With omit_empty_base_classes == false we would get an integer array back with:
+// { 1, 1 }
+// The first index 1 is the child index for "class A" within class C
+// The second index 1 is the child index for "m_b" within class A
+//
+// With omit_empty_base_classes == true we would get an integer array back with:
+// { 0, 1 }
+// The first index 0 is the child index for "class A" within class C (since class B doesn't have any members it doesn't count)
+// The second index 1 is the child index for "m_b" within class A
+
+size_t
+ClangASTContext::GetIndexOfChildMemberWithName (lldb::opaque_compiler_type_t type, const char *name,
+ bool omit_empty_base_classes,
+ std::vector<uint32_t>& child_indexes)
+{
+ if (type && name && name[0])
+ {
+ clang::QualType qual_type(GetCanonicalQualType(type));
+ const clang::Type::TypeClass type_class = qual_type->getTypeClass();
+ switch (type_class)
+ {
+ case clang::Type::Record:
+ if (GetCompleteType(type))
+ {
+ const clang::RecordType *record_type = llvm::cast<clang::RecordType>(qual_type.getTypePtr());
+ const clang::RecordDecl *record_decl = record_type->getDecl();
+
+ assert(record_decl);
+ uint32_t child_idx = 0;
+
+ const clang::CXXRecordDecl *cxx_record_decl = llvm::dyn_cast<clang::CXXRecordDecl>(record_decl);
+
+ // Try and find a field that matches NAME
+ clang::RecordDecl::field_iterator field, field_end;
+ llvm::StringRef name_sref(name);
+ for (field = record_decl->field_begin(), field_end = record_decl->field_end();
+ field != field_end;
+ ++field, ++child_idx)
+ {
+ llvm::StringRef field_name = field->getName();
+ if (field_name.empty())
+ {
+ CompilerType field_type(getASTContext(),field->getType());
+ child_indexes.push_back(child_idx);
+ if (field_type.GetIndexOfChildMemberWithName(name, omit_empty_base_classes, child_indexes))
+ return child_indexes.size();
+ child_indexes.pop_back();
+
+ }
+ else if (field_name.equals (name_sref))
+ {
+ // We have to add on the number of base classes to this index!
+ child_indexes.push_back (child_idx + ClangASTContext::GetNumBaseClasses (cxx_record_decl, omit_empty_base_classes));
+ return child_indexes.size();
+ }
+ }
+
+ if (cxx_record_decl)
+ {
+ const clang::RecordDecl *parent_record_decl = cxx_record_decl;
+
+ //printf ("parent = %s\n", parent_record_decl->getNameAsCString());
+
+ //const Decl *root_cdecl = cxx_record_decl->getCanonicalDecl();
+ // Didn't find things easily, lets let clang do its thang...
+ clang::IdentifierInfo & ident_ref = getASTContext()->Idents.get(name_sref);
+ clang::DeclarationName decl_name(&ident_ref);
+
+ clang::CXXBasePaths paths;
+ if (cxx_record_decl->lookupInBases([decl_name](const clang::CXXBaseSpecifier *specifier, clang::CXXBasePath &path) {
+ return clang::CXXRecordDecl::FindOrdinaryMember(specifier, path, decl_name);
+ },
+ paths))
+ {
+ clang::CXXBasePaths::const_paths_iterator path, path_end = paths.end();
+ for (path = paths.begin(); path != path_end; ++path)
+ {
+ const size_t num_path_elements = path->size();
+ for (size_t e=0; e<num_path_elements; ++e)
+ {
+ clang::CXXBasePathElement elem = (*path)[e];
+
+ child_idx = GetIndexForRecordBase (parent_record_decl, elem.Base, omit_empty_base_classes);
+ if (child_idx == UINT32_MAX)
+ {
+ child_indexes.clear();
+ return 0;
+ }
+ else
+ {
+ child_indexes.push_back (child_idx);
+ parent_record_decl = llvm::cast<clang::RecordDecl>(elem.Base->getType()->getAs<clang::RecordType>()->getDecl());
+ }
+ }
+ for (clang::NamedDecl *path_decl : path->Decls)
+ {
+ child_idx = GetIndexForRecordChild (parent_record_decl, path_decl, omit_empty_base_classes);
+ if (child_idx == UINT32_MAX)
+ {
+ child_indexes.clear();
+ return 0;
+ }
+ else
+ {
+ child_indexes.push_back (child_idx);
+ }
+ }
+ }
+ return child_indexes.size();
+ }
+ }
+
+ }
+ break;
+
+ case clang::Type::ObjCObject:
+ case clang::Type::ObjCInterface:
+ if (GetCompleteType(type))
+ {
+ llvm::StringRef name_sref(name);
+ const clang::ObjCObjectType *objc_class_type = llvm::dyn_cast<clang::ObjCObjectType>(qual_type.getTypePtr());
+ assert (objc_class_type);
+ if (objc_class_type)
+ {
+ uint32_t child_idx = 0;
+ clang::ObjCInterfaceDecl *class_interface_decl = objc_class_type->getInterface();
+
+ if (class_interface_decl)
+ {
+ clang::ObjCInterfaceDecl::ivar_iterator ivar_pos, ivar_end = class_interface_decl->ivar_end();
+ clang::ObjCInterfaceDecl *superclass_interface_decl = class_interface_decl->getSuperClass();
+
+ for (ivar_pos = class_interface_decl->ivar_begin(); ivar_pos != ivar_end; ++ivar_pos, ++child_idx)
+ {
+ const clang::ObjCIvarDecl* ivar_decl = *ivar_pos;
+
+ if (ivar_decl->getName().equals (name_sref))
+ {
+ if ((!omit_empty_base_classes && superclass_interface_decl) ||
+ ( omit_empty_base_classes && ObjCDeclHasIVars (superclass_interface_decl, true)))
+ ++child_idx;
+
+ child_indexes.push_back (child_idx);
+ return child_indexes.size();
+ }
+ }
+
+ if (superclass_interface_decl)
+ {
+ // The super class index is always zero for ObjC classes,
+ // so we push it onto the child indexes in case we find
+ // an ivar in our superclass...
+ child_indexes.push_back (0);
+
+ CompilerType superclass_clang_type (getASTContext(), getASTContext()->getObjCInterfaceType(superclass_interface_decl));
+ if (superclass_clang_type.GetIndexOfChildMemberWithName (name,
+ omit_empty_base_classes,
+ child_indexes))
+ {
+ // We did find an ivar in a superclass so just
+ // return the results!
+ return child_indexes.size();
+ }
+
+ // We didn't find an ivar matching "name" in our
+ // superclass, pop the superclass zero index that
+ // we pushed on above.
+ child_indexes.pop_back();
+ }
+ }
+ }
+ }
+ break;
+
+ case clang::Type::ObjCObjectPointer:
+ {
+ CompilerType objc_object_clang_type (getASTContext(), llvm::cast<clang::ObjCObjectPointerType>(qual_type.getTypePtr())->getPointeeType());
+ return objc_object_clang_type.GetIndexOfChildMemberWithName (name,
+ omit_empty_base_classes,
+ child_indexes);
+ }
+ break;
+
+
+ case clang::Type::ConstantArray:
+ {
+ // const clang::ConstantArrayType *array = llvm::cast<clang::ConstantArrayType>(parent_qual_type.getTypePtr());
+ // const uint64_t element_count = array->getSize().getLimitedValue();
+ //
+ // if (idx < element_count)
+ // {
+ // std::pair<uint64_t, unsigned> field_type_info = ast->getTypeInfo(array->getElementType());
+ //
+ // char element_name[32];
+ // ::snprintf (element_name, sizeof (element_name), "%s[%u]", parent_name ? parent_name : "", idx);
+ //
+ // child_name.assign(element_name);
+ // assert(field_type_info.first % 8 == 0);
+ // child_byte_size = field_type_info.first / 8;
+ // child_byte_offset = idx * child_byte_size;
+ // return array->getElementType().getAsOpaquePtr();
+ // }
+ }
+ break;
+
+ // case clang::Type::MemberPointerType:
+ // {
+ // MemberPointerType *mem_ptr_type = llvm::cast<MemberPointerType>(qual_type.getTypePtr());
+ // clang::QualType pointee_type = mem_ptr_type->getPointeeType();
+ //
+ // if (ClangASTContext::IsAggregateType (pointee_type.getAsOpaquePtr()))
+ // {
+ // return GetIndexOfChildWithName (ast,
+ // mem_ptr_type->getPointeeType().getAsOpaquePtr(),
+ // name);
+ // }
+ // }
+ // break;
+ //
+ case clang::Type::LValueReference:
+ case clang::Type::RValueReference:
+ {
+ const clang::ReferenceType *reference_type = llvm::cast<clang::ReferenceType>(qual_type.getTypePtr());
+ clang::QualType pointee_type(reference_type->getPointeeType());
+ CompilerType pointee_clang_type (getASTContext(), pointee_type);
+
+ if (pointee_clang_type.IsAggregateType ())
+ {
+ return pointee_clang_type.GetIndexOfChildMemberWithName (name,
+ omit_empty_base_classes,
+ child_indexes);
+ }
+ }
+ break;
+
+ case clang::Type::Pointer:
+ {
+ CompilerType pointee_clang_type (GetPointeeType(type));
+
+ if (pointee_clang_type.IsAggregateType ())
+ {
+ return pointee_clang_type.GetIndexOfChildMemberWithName (name,
+ omit_empty_base_classes,
+ child_indexes);
+ }
+ }
+ break;
+
+ case clang::Type::Typedef:
+ return CompilerType (getASTContext(), llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType()).GetIndexOfChildMemberWithName (name,
+ omit_empty_base_classes,
+ child_indexes);
+
+ case clang::Type::Auto:
+ return CompilerType (getASTContext(), llvm::cast<clang::AutoType>(qual_type)->getDeducedType()).GetIndexOfChildMemberWithName (name,
+ omit_empty_base_classes,
+ child_indexes);
+
+ case clang::Type::Elaborated:
+ return CompilerType (getASTContext(), llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType()).GetIndexOfChildMemberWithName (name,
+ omit_empty_base_classes,
+ child_indexes);
+
+ case clang::Type::Paren:
+ return CompilerType (getASTContext(), llvm::cast<clang::ParenType>(qual_type)->desugar()).GetIndexOfChildMemberWithName (name,
+ omit_empty_base_classes,
+ child_indexes);
+
+ default:
+ break;
+ }
+ }
+ return 0;
+}
+
+
+// Get the index of the child of "clang_type" whose name matches. This function
+// doesn't descend into the children, but only looks one level deep and name
+// matches can include base class names.
+
+uint32_t
+ClangASTContext::GetIndexOfChildWithName (lldb::opaque_compiler_type_t type, const char *name, bool omit_empty_base_classes)
+{
+ if (type && name && name[0])
+ {
+ clang::QualType qual_type(GetCanonicalQualType(type));
+
+ const clang::Type::TypeClass type_class = qual_type->getTypeClass();
+
+ switch (type_class)
+ {
+ case clang::Type::Record:
+ if (GetCompleteType(type))
+ {
+ const clang::RecordType *record_type = llvm::cast<clang::RecordType>(qual_type.getTypePtr());
+ const clang::RecordDecl *record_decl = record_type->getDecl();
+
+ assert(record_decl);
+ uint32_t child_idx = 0;
+
+ const clang::CXXRecordDecl *cxx_record_decl = llvm::dyn_cast<clang::CXXRecordDecl>(record_decl);
+
+ if (cxx_record_decl)
+ {
+ clang::CXXRecordDecl::base_class_const_iterator base_class, base_class_end;
+ for (base_class = cxx_record_decl->bases_begin(), base_class_end = cxx_record_decl->bases_end();
+ base_class != base_class_end;
+ ++base_class)
+ {
+ // Skip empty base classes
+ clang::CXXRecordDecl *base_class_decl = llvm::cast<clang::CXXRecordDecl>(base_class->getType()->getAs<clang::RecordType>()->getDecl());
+ if (omit_empty_base_classes && ClangASTContext::RecordHasFields(base_class_decl) == false)
+ continue;
+
+ CompilerType base_class_clang_type (getASTContext(), base_class->getType());
+ std::string base_class_type_name (base_class_clang_type.GetTypeName().AsCString(""));
+ if (base_class_type_name.compare (name) == 0)
+ return child_idx;
+ ++child_idx;
+ }
+ }
+
+ // Try and find a field that matches NAME
+ clang::RecordDecl::field_iterator field, field_end;
+ llvm::StringRef name_sref(name);
+ for (field = record_decl->field_begin(), field_end = record_decl->field_end();
+ field != field_end;
+ ++field, ++child_idx)
+ {
+ if (field->getName().equals (name_sref))
+ return child_idx;
+ }
+
+ }
+ break;
+
+ case clang::Type::ObjCObject:
+ case clang::Type::ObjCInterface:
+ if (GetCompleteType(type))
+ {
+ llvm::StringRef name_sref(name);
+ const clang::ObjCObjectType *objc_class_type = llvm::dyn_cast<clang::ObjCObjectType>(qual_type.getTypePtr());
+ assert (objc_class_type);
+ if (objc_class_type)
+ {
+ uint32_t child_idx = 0;
+ clang::ObjCInterfaceDecl *class_interface_decl = objc_class_type->getInterface();
+
+ if (class_interface_decl)
+ {
+ clang::ObjCInterfaceDecl::ivar_iterator ivar_pos, ivar_end = class_interface_decl->ivar_end();
+ clang::ObjCInterfaceDecl *superclass_interface_decl = class_interface_decl->getSuperClass();
+
+ for (ivar_pos = class_interface_decl->ivar_begin(); ivar_pos != ivar_end; ++ivar_pos, ++child_idx)
+ {
+ const clang::ObjCIvarDecl* ivar_decl = *ivar_pos;
+
+ if (ivar_decl->getName().equals (name_sref))
+ {
+ if ((!omit_empty_base_classes && superclass_interface_decl) ||
+ ( omit_empty_base_classes && ObjCDeclHasIVars (superclass_interface_decl, true)))
+ ++child_idx;
+
+ return child_idx;
+ }
+ }
+
+ if (superclass_interface_decl)
+ {
+ if (superclass_interface_decl->getName().equals (name_sref))
+ return 0;
+ }
+ }
+ }
+ }
+ break;
+
+ case clang::Type::ObjCObjectPointer:
+ {
+ CompilerType pointee_clang_type (getASTContext(), llvm::cast<clang::ObjCObjectPointerType>(qual_type.getTypePtr())->getPointeeType());
+ return pointee_clang_type.GetIndexOfChildWithName (name, omit_empty_base_classes);
+ }
+ break;
+
+ case clang::Type::ConstantArray:
+ {
+ // const clang::ConstantArrayType *array = llvm::cast<clang::ConstantArrayType>(parent_qual_type.getTypePtr());
+ // const uint64_t element_count = array->getSize().getLimitedValue();
+ //
+ // if (idx < element_count)
+ // {
+ // std::pair<uint64_t, unsigned> field_type_info = ast->getTypeInfo(array->getElementType());
+ //
+ // char element_name[32];
+ // ::snprintf (element_name, sizeof (element_name), "%s[%u]", parent_name ? parent_name : "", idx);
+ //
+ // child_name.assign(element_name);
+ // assert(field_type_info.first % 8 == 0);
+ // child_byte_size = field_type_info.first / 8;
+ // child_byte_offset = idx * child_byte_size;
+ // return array->getElementType().getAsOpaquePtr();
+ // }
+ }
+ break;
+
+ // case clang::Type::MemberPointerType:
+ // {
+ // MemberPointerType *mem_ptr_type = llvm::cast<MemberPointerType>(qual_type.getTypePtr());
+ // clang::QualType pointee_type = mem_ptr_type->getPointeeType();
+ //
+ // if (ClangASTContext::IsAggregateType (pointee_type.getAsOpaquePtr()))
+ // {
+ // return GetIndexOfChildWithName (ast,
+ // mem_ptr_type->getPointeeType().getAsOpaquePtr(),
+ // name);
+ // }
+ // }
+ // break;
+ //
+ case clang::Type::LValueReference:
+ case clang::Type::RValueReference:
+ {
+ const clang::ReferenceType *reference_type = llvm::cast<clang::ReferenceType>(qual_type.getTypePtr());
+ CompilerType pointee_type (getASTContext(), reference_type->getPointeeType());
+
+ if (pointee_type.IsAggregateType ())
+ {
+ return pointee_type.GetIndexOfChildWithName (name, omit_empty_base_classes);
+ }
+ }
+ break;
+
+ case clang::Type::Pointer:
+ {
+ const clang::PointerType *pointer_type = llvm::cast<clang::PointerType>(qual_type.getTypePtr());
+ CompilerType pointee_type (getASTContext(), pointer_type->getPointeeType());
+
+ if (pointee_type.IsAggregateType ())
+ {
+ return pointee_type.GetIndexOfChildWithName (name, omit_empty_base_classes);
+ }
+ else
+ {
+ // if (parent_name)
+ // {
+ // child_name.assign(1, '*');
+ // child_name += parent_name;
+ // }
+ //
+ // // We have a pointer to an simple type
+ // if (idx == 0)
+ // {
+ // std::pair<uint64_t, unsigned> clang_type_info = ast->getTypeInfo(pointee_type);
+ // assert(clang_type_info.first % 8 == 0);
+ // child_byte_size = clang_type_info.first / 8;
+ // child_byte_offset = 0;
+ // return pointee_type.getAsOpaquePtr();
+ // }
+ }
+ }
+ break;
+
+ case clang::Type::Auto:
+ return CompilerType (getASTContext(), llvm::cast<clang::AutoType>(qual_type)->getDeducedType()).GetIndexOfChildWithName (name, omit_empty_base_classes);
+
+ case clang::Type::Elaborated:
+ return CompilerType (getASTContext(), llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType()).GetIndexOfChildWithName (name, omit_empty_base_classes);
+
+ case clang::Type::Paren:
+ return CompilerType (getASTContext(), llvm::cast<clang::ParenType>(qual_type)->desugar()).GetIndexOfChildWithName (name, omit_empty_base_classes);
+
+ case clang::Type::Typedef:
+ return CompilerType (getASTContext(), llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType()).GetIndexOfChildWithName (name, omit_empty_base_classes);
+
+ default:
+ break;
+ }
+ }
+ return UINT32_MAX;
+}
+
+
+size_t
+ClangASTContext::GetNumTemplateArguments (lldb::opaque_compiler_type_t type)
+{
+ if (!type)
+ return 0;
+
+ clang::QualType qual_type (GetCanonicalQualType(type));
+ const clang::Type::TypeClass type_class = qual_type->getTypeClass();
+ switch (type_class)
+ {
+ case clang::Type::Record:
+ if (GetCompleteType(type))
+ {
+ const clang::CXXRecordDecl *cxx_record_decl = qual_type->getAsCXXRecordDecl();
+ if (cxx_record_decl)
+ {
+ const clang::ClassTemplateSpecializationDecl *template_decl = llvm::dyn_cast<clang::ClassTemplateSpecializationDecl>(cxx_record_decl);
+ if (template_decl)
+ return template_decl->getTemplateArgs().size();
+ }
+ }
+ break;
+
+ case clang::Type::Typedef:
+ return (CompilerType (getASTContext(), llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType())).GetNumTemplateArguments();
+
+ case clang::Type::Auto:
+ return (CompilerType (getASTContext(), llvm::cast<clang::AutoType>(qual_type)->getDeducedType())).GetNumTemplateArguments();
+
+ case clang::Type::Elaborated:
+ return (CompilerType (getASTContext(), llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType())).GetNumTemplateArguments();
+
+ case clang::Type::Paren:
+ return (CompilerType (getASTContext(), llvm::cast<clang::ParenType>(qual_type)->desugar())).GetNumTemplateArguments();
+
+ default:
+ break;
+ }
+
+ return 0;
+}
+
+CompilerType
+ClangASTContext::GetTemplateArgument (lldb::opaque_compiler_type_t type, size_t arg_idx, lldb::TemplateArgumentKind &kind)
+{
+ if (!type)
+ return CompilerType();
+
+ clang::QualType qual_type (GetCanonicalQualType(type));
+ const clang::Type::TypeClass type_class = qual_type->getTypeClass();
+ switch (type_class)
+ {
+ case clang::Type::Record:
+ if (GetCompleteType(type))
+ {
+ const clang::CXXRecordDecl *cxx_record_decl = qual_type->getAsCXXRecordDecl();
+ if (cxx_record_decl)
+ {
+ const clang::ClassTemplateSpecializationDecl *template_decl = llvm::dyn_cast<clang::ClassTemplateSpecializationDecl>(cxx_record_decl);
+ if (template_decl && arg_idx < template_decl->getTemplateArgs().size())
+ {
+ const clang::TemplateArgument &template_arg = template_decl->getTemplateArgs()[arg_idx];
+ switch (template_arg.getKind())
+ {
+ case clang::TemplateArgument::Null:
+ kind = eTemplateArgumentKindNull;
+ return CompilerType();
+
+ case clang::TemplateArgument::Type:
+ kind = eTemplateArgumentKindType;
+ return CompilerType(getASTContext(), template_arg.getAsType());
+
+ case clang::TemplateArgument::Declaration:
+ kind = eTemplateArgumentKindDeclaration;
+ return CompilerType();
+
+ case clang::TemplateArgument::Integral:
+ kind = eTemplateArgumentKindIntegral;
+ return CompilerType(getASTContext(), template_arg.getIntegralType());
+
+ case clang::TemplateArgument::Template:
+ kind = eTemplateArgumentKindTemplate;
+ return CompilerType();
+
+ case clang::TemplateArgument::TemplateExpansion:
+ kind = eTemplateArgumentKindTemplateExpansion;
+ return CompilerType();
+
+ case clang::TemplateArgument::Expression:
+ kind = eTemplateArgumentKindExpression;
+ return CompilerType();
+
+ case clang::TemplateArgument::Pack:
+ kind = eTemplateArgumentKindPack;
+ return CompilerType();
+
+ default:
+ assert (!"Unhandled clang::TemplateArgument::ArgKind");
+ break;
+ }
+ }
+ }
+ }
+ break;
+
+ case clang::Type::Typedef:
+ return (CompilerType (getASTContext(), llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType())).GetTemplateArgument(arg_idx, kind);
+
+ case clang::Type::Auto:
+ return (CompilerType (getASTContext(), llvm::cast<clang::AutoType>(qual_type)->getDeducedType())).GetTemplateArgument(arg_idx, kind);
+
+ case clang::Type::Elaborated:
+ return (CompilerType (getASTContext(), llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType())).GetTemplateArgument(arg_idx, kind);
+
+ case clang::Type::Paren:
+ return (CompilerType (getASTContext(), llvm::cast<clang::ParenType>(qual_type)->desugar())).GetTemplateArgument(arg_idx, kind);
+
+ default:
+ break;
+ }
+ kind = eTemplateArgumentKindNull;
+ return CompilerType ();
+}
+
+CompilerType
+ClangASTContext::GetTypeForFormatters (void* type)
+{
+ if (type)
+ return RemoveFastQualifiers(CompilerType(this, type));
+ return CompilerType();
+}
+
+static bool
+IsOperator (const char *name, clang::OverloadedOperatorKind &op_kind)
+{
+ if (name == nullptr || name[0] == '\0')
+ return false;
+
+#define OPERATOR_PREFIX "operator"
+#define OPERATOR_PREFIX_LENGTH (sizeof (OPERATOR_PREFIX) - 1)
+
+ const char *post_op_name = nullptr;
+
+ bool no_space = true;
+
+ if (::strncmp(name, OPERATOR_PREFIX, OPERATOR_PREFIX_LENGTH))
+ return false;
+
+ post_op_name = name + OPERATOR_PREFIX_LENGTH;
+
+ if (post_op_name[0] == ' ')
+ {
+ post_op_name++;
+ no_space = false;
+ }
+
+#undef OPERATOR_PREFIX
+#undef OPERATOR_PREFIX_LENGTH
+
+ // This is an operator, set the overloaded operator kind to invalid
+ // in case this is a conversion operator...
+ op_kind = clang::NUM_OVERLOADED_OPERATORS;
+
+ switch (post_op_name[0])
+ {
+ default:
+ if (no_space)
+ return false;
+ break;
+ case 'n':
+ if (no_space)
+ return false;
+ if (strcmp (post_op_name, "new") == 0)
+ op_kind = clang::OO_New;
+ else if (strcmp (post_op_name, "new[]") == 0)
+ op_kind = clang::OO_Array_New;
+ break;
+
+ case 'd':
+ if (no_space)
+ return false;
+ if (strcmp (post_op_name, "delete") == 0)
+ op_kind = clang::OO_Delete;
+ else if (strcmp (post_op_name, "delete[]") == 0)
+ op_kind = clang::OO_Array_Delete;
+ break;
+
+ case '+':
+ if (post_op_name[1] == '\0')
+ op_kind = clang::OO_Plus;
+ else if (post_op_name[2] == '\0')
+ {
+ if (post_op_name[1] == '=')
+ op_kind = clang::OO_PlusEqual;
+ else if (post_op_name[1] == '+')
+ op_kind = clang::OO_PlusPlus;
+ }
+ break;
+
+ case '-':
+ if (post_op_name[1] == '\0')
+ op_kind = clang::OO_Minus;
+ else if (post_op_name[2] == '\0')
+ {
+ switch (post_op_name[1])
+ {
+ case '=': op_kind = clang::OO_MinusEqual; break;
+ case '-': op_kind = clang::OO_MinusMinus; break;
+ case '>': op_kind = clang::OO_Arrow; break;
+ }
+ }
+ else if (post_op_name[3] == '\0')
+ {
+ if (post_op_name[2] == '*')
+ op_kind = clang::OO_ArrowStar; break;
+ }
+ break;
+
+ case '*':
+ if (post_op_name[1] == '\0')
+ op_kind = clang::OO_Star;
+ else if (post_op_name[1] == '=' && post_op_name[2] == '\0')
+ op_kind = clang::OO_StarEqual;
+ break;
+
+ case '/':
+ if (post_op_name[1] == '\0')
+ op_kind = clang::OO_Slash;
+ else if (post_op_name[1] == '=' && post_op_name[2] == '\0')
+ op_kind = clang::OO_SlashEqual;
+ break;
+
+ case '%':
+ if (post_op_name[1] == '\0')
+ op_kind = clang::OO_Percent;
+ else if (post_op_name[1] == '=' && post_op_name[2] == '\0')
+ op_kind = clang::OO_PercentEqual;
+ break;
+
+
+ case '^':
+ if (post_op_name[1] == '\0')
+ op_kind = clang::OO_Caret;
+ else if (post_op_name[1] == '=' && post_op_name[2] == '\0')
+ op_kind = clang::OO_CaretEqual;
+ break;
+
+ case '&':
+ if (post_op_name[1] == '\0')
+ op_kind = clang::OO_Amp;
+ else if (post_op_name[2] == '\0')
+ {
+ switch (post_op_name[1])
+ {
+ case '=': op_kind = clang::OO_AmpEqual; break;
+ case '&': op_kind = clang::OO_AmpAmp; break;
+ }
+ }
+ break;
+
+ case '|':
+ if (post_op_name[1] == '\0')
+ op_kind = clang::OO_Pipe;
+ else if (post_op_name[2] == '\0')
+ {
+ switch (post_op_name[1])
+ {
+ case '=': op_kind = clang::OO_PipeEqual; break;
+ case '|': op_kind = clang::OO_PipePipe; break;
+ }
+ }
+ break;
+
+ case '~':
+ if (post_op_name[1] == '\0')
+ op_kind = clang::OO_Tilde;
+ break;
+
+ case '!':
+ if (post_op_name[1] == '\0')
+ op_kind = clang::OO_Exclaim;
+ else if (post_op_name[1] == '=' && post_op_name[2] == '\0')
+ op_kind = clang::OO_ExclaimEqual;
+ break;
+
+ case '=':
+ if (post_op_name[1] == '\0')
+ op_kind = clang::OO_Equal;
+ else if (post_op_name[1] == '=' && post_op_name[2] == '\0')
+ op_kind = clang::OO_EqualEqual;
+ break;
+
+ case '<':
+ if (post_op_name[1] == '\0')
+ op_kind = clang::OO_Less;
+ else if (post_op_name[2] == '\0')
+ {
+ switch (post_op_name[1])
+ {
+ case '<': op_kind = clang::OO_LessLess; break;
+ case '=': op_kind = clang::OO_LessEqual; break;
+ }
+ }
+ else if (post_op_name[3] == '\0')
+ {
+ if (post_op_name[2] == '=')
+ op_kind = clang::OO_LessLessEqual;
+ }
+ break;
+
+ case '>':
+ if (post_op_name[1] == '\0')
+ op_kind = clang::OO_Greater;
+ else if (post_op_name[2] == '\0')
+ {
+ switch (post_op_name[1])
+ {
+ case '>': op_kind = clang::OO_GreaterGreater; break;
+ case '=': op_kind = clang::OO_GreaterEqual; break;
+ }
+ }
+ else if (post_op_name[1] == '>' &&
+ post_op_name[2] == '=' &&
+ post_op_name[3] == '\0')
+ {
+ op_kind = clang::OO_GreaterGreaterEqual;
+ }
+ break;
+
+ case ',':
+ if (post_op_name[1] == '\0')
+ op_kind = clang::OO_Comma;
+ break;
+
+ case '(':
+ if (post_op_name[1] == ')' && post_op_name[2] == '\0')
+ op_kind = clang::OO_Call;
+ break;
+
+ case '[':
+ if (post_op_name[1] == ']' && post_op_name[2] == '\0')
+ op_kind = clang::OO_Subscript;
+ break;
+ }
+
+ return true;
+}
+
+clang::EnumDecl *
+ClangASTContext::GetAsEnumDecl (const CompilerType& type)
+{
+ const clang::EnumType *enutype = llvm::dyn_cast<clang::EnumType>(GetCanonicalQualType(type));
+ if (enutype)
+ return enutype->getDecl();
+ return NULL;
+}
+
+clang::RecordDecl *
+ClangASTContext::GetAsRecordDecl (const CompilerType& type)
+{
+ const clang::RecordType *record_type = llvm::dyn_cast<clang::RecordType>(GetCanonicalQualType(type));
+ if (record_type)
+ return record_type->getDecl();
+ return nullptr;
+}
+
+clang::TagDecl *
+ClangASTContext::GetAsTagDecl (const CompilerType& type)
+{
+ clang::QualType qual_type = GetCanonicalQualType(type);
+ if (qual_type.isNull())
+ return nullptr;
+ else
+ return qual_type->getAsTagDecl();
+}
+
+clang::CXXRecordDecl *
+ClangASTContext::GetAsCXXRecordDecl (lldb::opaque_compiler_type_t type)
+{
+ return GetCanonicalQualType(type)->getAsCXXRecordDecl();
+}
+
+clang::ObjCInterfaceDecl *
+ClangASTContext::GetAsObjCInterfaceDecl (const CompilerType& type)
+{
+ const clang::ObjCObjectType *objc_class_type = llvm::dyn_cast<clang::ObjCObjectType>(GetCanonicalQualType(type));
+ if (objc_class_type)
+ return objc_class_type->getInterface();
+ return nullptr;
+}
+
+clang::FieldDecl *
+ClangASTContext::AddFieldToRecordType (const CompilerType& type, const char *name,
+ const CompilerType &field_clang_type,
+ AccessType access,
+ uint32_t bitfield_bit_size)
+{
+ if (!type.IsValid() || !field_clang_type.IsValid())
+ return nullptr;
+ ClangASTContext *ast = llvm::dyn_cast_or_null<ClangASTContext>(type.GetTypeSystem());
+ if (!ast)
+ return nullptr;
+ clang::ASTContext* clang_ast = ast->getASTContext();
+
+ clang::FieldDecl *field = nullptr;
+
+ clang::Expr *bit_width = nullptr;
+ if (bitfield_bit_size != 0)
+ {
+ llvm::APInt bitfield_bit_size_apint(clang_ast->getTypeSize(clang_ast->IntTy), bitfield_bit_size);
+ bit_width = new (*clang_ast)clang::IntegerLiteral (*clang_ast, bitfield_bit_size_apint, clang_ast->IntTy, clang::SourceLocation());
+ }
+
+ clang::RecordDecl *record_decl = ast->GetAsRecordDecl (type);
+ if (record_decl)
+ {
+ field = clang::FieldDecl::Create (*clang_ast,
+ record_decl,
+ clang::SourceLocation(),
+ clang::SourceLocation(),
+ name ? &clang_ast->Idents.get(name) : nullptr, // Identifier
+ GetQualType(field_clang_type), // Field type
+ nullptr, // TInfo *
+ bit_width, // BitWidth
+ false, // Mutable
+ clang::ICIS_NoInit); // HasInit
+
+ if (!name)
+ {
+ // Determine whether this field corresponds to an anonymous
+ // struct or union.
+ if (const clang::TagType *TagT = field->getType()->getAs<clang::TagType>()) {
+ if (clang::RecordDecl *Rec = llvm::dyn_cast<clang::RecordDecl>(TagT->getDecl()))
+ if (!Rec->getDeclName()) {
+ Rec->setAnonymousStructOrUnion(true);
+ field->setImplicit();
+
+ }
+ }
+ }
+
+ if (field)
+ {
+ field->setAccess (ClangASTContext::ConvertAccessTypeToAccessSpecifier (access));
+
+ record_decl->addDecl(field);
+
+#ifdef LLDB_CONFIGURATION_DEBUG
+ VerifyDecl(field);
+#endif
+ }
+ }
+ else
+ {
+ clang::ObjCInterfaceDecl *class_interface_decl = ast->GetAsObjCInterfaceDecl (type);
+
+ if (class_interface_decl)
+ {
+ const bool is_synthesized = false;
+
+ field_clang_type.GetCompleteType();
+
+ field = clang::ObjCIvarDecl::Create (*clang_ast,
+ class_interface_decl,
+ clang::SourceLocation(),
+ clang::SourceLocation(),
+ name ? &clang_ast->Idents.get(name) : nullptr, // Identifier
+ GetQualType(field_clang_type), // Field type
+ nullptr, // TypeSourceInfo *
+ ConvertAccessTypeToObjCIvarAccessControl (access),
+ bit_width,
+ is_synthesized);
+
+ if (field)
+ {
+ class_interface_decl->addDecl(field);
+
+#ifdef LLDB_CONFIGURATION_DEBUG
+ VerifyDecl(field);
+#endif
+ }
+ }
+ }
+ return field;
+}
+
+void
+ClangASTContext::BuildIndirectFields (const CompilerType& type)
+{
+ if (!type)
+ return;
+
+ ClangASTContext *ast = llvm::dyn_cast<ClangASTContext>(type.GetTypeSystem());
+ if (!ast)
+ return;
+
+ clang::RecordDecl *record_decl = ast->GetAsRecordDecl(type);
+
+ if (!record_decl)
+ return;
+
+ typedef llvm::SmallVector <clang::IndirectFieldDecl *, 1> IndirectFieldVector;
+
+ IndirectFieldVector indirect_fields;
+ clang::RecordDecl::field_iterator field_pos;
+ clang::RecordDecl::field_iterator field_end_pos = record_decl->field_end();
+ clang::RecordDecl::field_iterator last_field_pos = field_end_pos;
+ for (field_pos = record_decl->field_begin(); field_pos != field_end_pos; last_field_pos = field_pos++)
+ {
+ if (field_pos->isAnonymousStructOrUnion())
+ {
+ clang::QualType field_qual_type = field_pos->getType();
+
+ const clang::RecordType *field_record_type = field_qual_type->getAs<clang::RecordType>();
+
+ if (!field_record_type)
+ continue;
+
+ clang::RecordDecl *field_record_decl = field_record_type->getDecl();
+
+ if (!field_record_decl)
+ continue;
+
+ for (clang::RecordDecl::decl_iterator di = field_record_decl->decls_begin(), de = field_record_decl->decls_end();
+ di != de;
+ ++di)
+ {
+ if (clang::FieldDecl *nested_field_decl = llvm::dyn_cast<clang::FieldDecl>(*di))
+ {
+ clang::NamedDecl **chain = new (*ast->getASTContext()) clang::NamedDecl*[2];
+ chain[0] = *field_pos;
+ chain[1] = nested_field_decl;
+ clang::IndirectFieldDecl *indirect_field = clang::IndirectFieldDecl::Create(*ast->getASTContext(),
+ record_decl,
+ clang::SourceLocation(),
+ nested_field_decl->getIdentifier(),
+ nested_field_decl->getType(),
+ chain,
+ 2);
+
+ indirect_field->setImplicit();
+
+ indirect_field->setAccess(ClangASTContext::UnifyAccessSpecifiers(field_pos->getAccess(),
+ nested_field_decl->getAccess()));
+
+ indirect_fields.push_back(indirect_field);
+ }
+ else if (clang::IndirectFieldDecl *nested_indirect_field_decl = llvm::dyn_cast<clang::IndirectFieldDecl>(*di))
+ {
+ int nested_chain_size = nested_indirect_field_decl->getChainingSize();
+ clang::NamedDecl **chain = new (*ast->getASTContext()) clang::NamedDecl*[nested_chain_size + 1];
+ chain[0] = *field_pos;
+
+ int chain_index = 1;
+ for (clang::IndirectFieldDecl::chain_iterator nci = nested_indirect_field_decl->chain_begin(),
+ nce = nested_indirect_field_decl->chain_end();
+ nci < nce;
+ ++nci)
+ {
+ chain[chain_index] = *nci;
+ chain_index++;
+ }
+
+ clang::IndirectFieldDecl *indirect_field = clang::IndirectFieldDecl::Create(*ast->getASTContext(),
+ record_decl,
+ clang::SourceLocation(),
+ nested_indirect_field_decl->getIdentifier(),
+ nested_indirect_field_decl->getType(),
+ chain,
+ nested_chain_size + 1);
+
+ indirect_field->setImplicit();
+
+ indirect_field->setAccess(ClangASTContext::UnifyAccessSpecifiers(field_pos->getAccess(),
+ nested_indirect_field_decl->getAccess()));
+
+ indirect_fields.push_back(indirect_field);
+ }
+ }
+ }
+ }
+
+ // Check the last field to see if it has an incomplete array type as its
+ // last member and if it does, the tell the record decl about it
+ if (last_field_pos != field_end_pos)
+ {
+ if (last_field_pos->getType()->isIncompleteArrayType())
+ record_decl->hasFlexibleArrayMember();
+ }
+
+ for (IndirectFieldVector::iterator ifi = indirect_fields.begin(), ife = indirect_fields.end();
+ ifi < ife;
+ ++ifi)
+ {
+ record_decl->addDecl(*ifi);
+ }
+}
+
+void
+ClangASTContext::SetIsPacked (const CompilerType& type)
+{
+ if (type)
+ {
+ ClangASTContext *ast = llvm::dyn_cast<ClangASTContext>(type.GetTypeSystem());
+ if (ast)
+ {
+ clang::RecordDecl *record_decl = GetAsRecordDecl(type);
+
+ if (!record_decl)
+ return;
+
+ record_decl->addAttr(clang::PackedAttr::CreateImplicit(*ast->getASTContext()));
+ }
+ }
+}
+
+clang::VarDecl *
+ClangASTContext::AddVariableToRecordType (const CompilerType& type, const char *name,
+ const CompilerType &var_type,
+ AccessType access)
+{
+ clang::VarDecl *var_decl = nullptr;
+
+ if (!type.IsValid() || !var_type.IsValid())
+ return nullptr;
+ ClangASTContext *ast = llvm::dyn_cast<ClangASTContext>(type.GetTypeSystem());
+ if (!ast)
+ return nullptr;
+
+ clang::RecordDecl *record_decl = ast->GetAsRecordDecl (type);
+ if (record_decl)
+ {
+ var_decl = clang::VarDecl::Create (*ast->getASTContext(), // ASTContext &
+ record_decl, // DeclContext *
+ clang::SourceLocation(), // clang::SourceLocation StartLoc
+ clang::SourceLocation(), // clang::SourceLocation IdLoc
+ name ? &ast->getASTContext()->Idents.get(name) : nullptr, // clang::IdentifierInfo *
+ GetQualType(var_type), // Variable clang::QualType
+ nullptr, // TypeSourceInfo *
+ clang::SC_Static); // StorageClass
+ if (var_decl)
+ {
+ var_decl->setAccess(ClangASTContext::ConvertAccessTypeToAccessSpecifier (access));
+ record_decl->addDecl(var_decl);
+
+#ifdef LLDB_CONFIGURATION_DEBUG
+ VerifyDecl(var_decl);
+#endif
+ }
+ }
+ return var_decl;
+}
+
+
+clang::CXXMethodDecl *
+ClangASTContext::AddMethodToCXXRecordType (lldb::opaque_compiler_type_t type, const char *name,
+ const CompilerType &method_clang_type,
+ lldb::AccessType access,
+ bool is_virtual,
+ bool is_static,
+ bool is_inline,
+ bool is_explicit,
+ bool is_attr_used,
+ bool is_artificial)
+{
+ if (!type || !method_clang_type.IsValid() || name == nullptr || name[0] == '\0')
+ return nullptr;
+
+ clang::QualType record_qual_type(GetCanonicalQualType(type));
+
+ clang::CXXRecordDecl *cxx_record_decl = record_qual_type->getAsCXXRecordDecl();
+
+ if (cxx_record_decl == nullptr)
+ return nullptr;
+
+ clang::QualType method_qual_type (GetQualType(method_clang_type));
+
+ clang::CXXMethodDecl *cxx_method_decl = nullptr;
+
+ clang::DeclarationName decl_name (&getASTContext()->Idents.get(name));
+
+ const clang::FunctionType *function_type = llvm::dyn_cast<clang::FunctionType>(method_qual_type.getTypePtr());
+
+ if (function_type == nullptr)
+ return nullptr;
+
+ const clang::FunctionProtoType *method_function_prototype (llvm::dyn_cast<clang::FunctionProtoType>(function_type));
+
+ if (!method_function_prototype)
+ return nullptr;
+
+ unsigned int num_params = method_function_prototype->getNumParams();
+
+ clang::CXXDestructorDecl *cxx_dtor_decl(nullptr);
+ clang::CXXConstructorDecl *cxx_ctor_decl(nullptr);
+
+ if (is_artificial)
+ return nullptr; // skip everything artificial
+
+ if (name[0] == '~')
+ {
+ cxx_dtor_decl = clang::CXXDestructorDecl::Create (*getASTContext(),
+ cxx_record_decl,
+ clang::SourceLocation(),
+ clang::DeclarationNameInfo (getASTContext()->DeclarationNames.getCXXDestructorName (getASTContext()->getCanonicalType (record_qual_type)), clang::SourceLocation()),
+ method_qual_type,
+ nullptr,
+ is_inline,
+ is_artificial);
+ cxx_method_decl = cxx_dtor_decl;
+ }
+ else if (decl_name == cxx_record_decl->getDeclName())
+ {
+ cxx_ctor_decl = clang::CXXConstructorDecl::Create (*getASTContext(),
+ cxx_record_decl,
+ clang::SourceLocation(),
+ clang::DeclarationNameInfo (getASTContext()->DeclarationNames.getCXXConstructorName (getASTContext()->getCanonicalType (record_qual_type)), clang::SourceLocation()),
+ method_qual_type,
+ nullptr, // TypeSourceInfo *
+ is_explicit,
+ is_inline,
+ is_artificial,
+ false /*is_constexpr*/);
+ cxx_method_decl = cxx_ctor_decl;
+ }
+ else
+ {
+ clang::StorageClass SC = is_static ? clang::SC_Static : clang::SC_None;
+ clang::OverloadedOperatorKind op_kind = clang::NUM_OVERLOADED_OPERATORS;
+
+ if (IsOperator (name, op_kind))
+ {
+ if (op_kind != clang::NUM_OVERLOADED_OPERATORS)
+ {
+ // Check the number of operator parameters. Sometimes we have
+ // seen bad DWARF that doesn't correctly describe operators and
+ // if we try to create a method and add it to the class, clang
+ // will assert and crash, so we need to make sure things are
+ // acceptable.
+ if (!ClangASTContext::CheckOverloadedOperatorKindParameterCount (op_kind, num_params))
+ return nullptr;
+ cxx_method_decl = clang::CXXMethodDecl::Create (*getASTContext(),
+ cxx_record_decl,
+ clang::SourceLocation(),
+ clang::DeclarationNameInfo (getASTContext()->DeclarationNames.getCXXOperatorName (op_kind), clang::SourceLocation()),
+ method_qual_type,
+ nullptr, // TypeSourceInfo *
+ SC,
+ is_inline,
+ false /*is_constexpr*/,
+ clang::SourceLocation());
+ }
+ else if (num_params == 0)
+ {
+ // Conversion operators don't take params...
+ cxx_method_decl = clang::CXXConversionDecl::Create (*getASTContext(),
+ cxx_record_decl,
+ clang::SourceLocation(),
+ clang::DeclarationNameInfo (getASTContext()->DeclarationNames.getCXXConversionFunctionName (getASTContext()->getCanonicalType (function_type->getReturnType())), clang::SourceLocation()),
+ method_qual_type,
+ nullptr, // TypeSourceInfo *
+ is_inline,
+ is_explicit,
+ false /*is_constexpr*/,
+ clang::SourceLocation());
+ }
+ }
+
+ if (cxx_method_decl == nullptr)
+ {
+ cxx_method_decl = clang::CXXMethodDecl::Create (*getASTContext(),
+ cxx_record_decl,
+ clang::SourceLocation(),
+ clang::DeclarationNameInfo (decl_name, clang::SourceLocation()),
+ method_qual_type,
+ nullptr, // TypeSourceInfo *
+ SC,
+ is_inline,
+ false /*is_constexpr*/,
+ clang::SourceLocation());
+ }
+ }
+
+ clang::AccessSpecifier access_specifier = ClangASTContext::ConvertAccessTypeToAccessSpecifier (access);
+
+ cxx_method_decl->setAccess (access_specifier);
+ cxx_method_decl->setVirtualAsWritten (is_virtual);
+
+ if (is_attr_used)
+ cxx_method_decl->addAttr(clang::UsedAttr::CreateImplicit(*getASTContext()));
+
+ // Populate the method decl with parameter decls
+
+ llvm::SmallVector<clang::ParmVarDecl *, 12> params;
+
+ for (unsigned param_index = 0;
+ param_index < num_params;
+ ++param_index)
+ {
+ params.push_back (clang::ParmVarDecl::Create (*getASTContext(),
+ cxx_method_decl,
+ clang::SourceLocation(),
+ clang::SourceLocation(),
+ nullptr, // anonymous
+ method_function_prototype->getParamType(param_index),
+ nullptr,
+ clang::SC_None,
+ nullptr));
+ }
+
+ cxx_method_decl->setParams (llvm::ArrayRef<clang::ParmVarDecl*>(params));
+
+ cxx_record_decl->addDecl (cxx_method_decl);
+
+ // Sometimes the debug info will mention a constructor (default/copy/move),
+ // destructor, or assignment operator (copy/move) but there won't be any
+ // version of this in the code. So we check if the function was artificially
+ // generated and if it is trivial and this lets the compiler/backend know
+ // that it can inline the IR for these when it needs to and we can avoid a
+ // "missing function" error when running expressions.
+
+ if (is_artificial)
+ {
+ if (cxx_ctor_decl &&
+ ((cxx_ctor_decl->isDefaultConstructor() && cxx_record_decl->hasTrivialDefaultConstructor ()) ||
+ (cxx_ctor_decl->isCopyConstructor() && cxx_record_decl->hasTrivialCopyConstructor ()) ||
+ (cxx_ctor_decl->isMoveConstructor() && cxx_record_decl->hasTrivialMoveConstructor ()) ))
+ {
+ cxx_ctor_decl->setDefaulted();
+ cxx_ctor_decl->setTrivial(true);
+ }
+ else if (cxx_dtor_decl)
+ {
+ if (cxx_record_decl->hasTrivialDestructor())
+ {
+ cxx_dtor_decl->setDefaulted();
+ cxx_dtor_decl->setTrivial(true);
+ }
+ }
+ else if ((cxx_method_decl->isCopyAssignmentOperator() && cxx_record_decl->hasTrivialCopyAssignment()) ||
+ (cxx_method_decl->isMoveAssignmentOperator() && cxx_record_decl->hasTrivialMoveAssignment()))
+ {
+ cxx_method_decl->setDefaulted();
+ cxx_method_decl->setTrivial(true);
+ }
+ }
+
+#ifdef LLDB_CONFIGURATION_DEBUG
+ VerifyDecl(cxx_method_decl);
+#endif
+
+ // printf ("decl->isPolymorphic() = %i\n", cxx_record_decl->isPolymorphic());
+ // printf ("decl->isAggregate() = %i\n", cxx_record_decl->isAggregate());
+ // printf ("decl->isPOD() = %i\n", cxx_record_decl->isPOD());
+ // printf ("decl->isEmpty() = %i\n", cxx_record_decl->isEmpty());
+ // printf ("decl->isAbstract() = %i\n", cxx_record_decl->isAbstract());
+ // printf ("decl->hasTrivialConstructor() = %i\n", cxx_record_decl->hasTrivialConstructor());
+ // printf ("decl->hasTrivialCopyConstructor() = %i\n", cxx_record_decl->hasTrivialCopyConstructor());
+ // printf ("decl->hasTrivialCopyAssignment() = %i\n", cxx_record_decl->hasTrivialCopyAssignment());
+ // printf ("decl->hasTrivialDestructor() = %i\n", cxx_record_decl->hasTrivialDestructor());
+ return cxx_method_decl;
+}
+
+
+#pragma mark C++ Base Classes
+
+clang::CXXBaseSpecifier *
+ClangASTContext::CreateBaseClassSpecifier (lldb::opaque_compiler_type_t type, AccessType access, bool is_virtual, bool base_of_class)
+{
+ if (type)
+ return new clang::CXXBaseSpecifier (clang::SourceRange(),
+ is_virtual,
+ base_of_class,
+ ClangASTContext::ConvertAccessTypeToAccessSpecifier (access),
+ getASTContext()->getTrivialTypeSourceInfo (GetQualType(type)),
+ clang::SourceLocation());
+ return nullptr;
+}
+
+void
+ClangASTContext::DeleteBaseClassSpecifiers (clang::CXXBaseSpecifier **base_classes, unsigned num_base_classes)
+{
+ for (unsigned i=0; i<num_base_classes; ++i)
+ {
+ delete base_classes[i];
+ base_classes[i] = nullptr;
+ }
+}
+
+bool
+ClangASTContext::SetBaseClassesForClassType (lldb::opaque_compiler_type_t type, clang::CXXBaseSpecifier const * const *base_classes,
+ unsigned num_base_classes)
+{
+ if (type)
+ {
+ clang::CXXRecordDecl *cxx_record_decl = GetAsCXXRecordDecl(type);
+ if (cxx_record_decl)
+ {
+ cxx_record_decl->setBases(base_classes, num_base_classes);
+ return true;
+ }
+ }
+ return false;
+}
+
+bool
+ClangASTContext::SetObjCSuperClass (const CompilerType& type, const CompilerType &superclass_clang_type)
+{
+ ClangASTContext *ast = llvm::dyn_cast_or_null<ClangASTContext>(type.GetTypeSystem());
+ if (!ast)
+ return false;
+ clang::ASTContext* clang_ast = ast->getASTContext();
+
+ if (type && superclass_clang_type.IsValid() && superclass_clang_type.GetTypeSystem() == type.GetTypeSystem())
+ {
+ clang::ObjCInterfaceDecl *class_interface_decl = GetAsObjCInterfaceDecl (type);
+ clang::ObjCInterfaceDecl *super_interface_decl = GetAsObjCInterfaceDecl (superclass_clang_type);
+ if (class_interface_decl && super_interface_decl)
+ {
+ class_interface_decl->setSuperClass(clang_ast->getTrivialTypeSourceInfo(clang_ast->getObjCInterfaceType(super_interface_decl)));
+ return true;
+ }
+ }
+ return false;
+}
+
+bool
+ClangASTContext::AddObjCClassProperty (const CompilerType& type,
+ const char *property_name,
+ const CompilerType &property_clang_type,
+ clang::ObjCIvarDecl *ivar_decl,
+ const char *property_setter_name,
+ const char *property_getter_name,
+ uint32_t property_attributes,
+ ClangASTMetadata *metadata)
+{
+ if (!type || !property_clang_type.IsValid() || property_name == nullptr || property_name[0] == '\0')
+ return false;
+ ClangASTContext *ast = llvm::dyn_cast<ClangASTContext>(type.GetTypeSystem());
+ if (!ast)
+ return false;
+ clang::ASTContext* clang_ast = ast->getASTContext();
+
+ clang::ObjCInterfaceDecl *class_interface_decl = GetAsObjCInterfaceDecl (type);
+
+ if (class_interface_decl)
+ {
+ CompilerType property_clang_type_to_access;
+
+ if (property_clang_type.IsValid())
+ property_clang_type_to_access = property_clang_type;
+ else if (ivar_decl)
+ property_clang_type_to_access = CompilerType (clang_ast, ivar_decl->getType());
+
+ if (class_interface_decl && property_clang_type_to_access.IsValid())
+ {
+ clang::TypeSourceInfo *prop_type_source;
+ if (ivar_decl)
+ prop_type_source = clang_ast->getTrivialTypeSourceInfo (ivar_decl->getType());
else
+ prop_type_source = clang_ast->getTrivialTypeSourceInfo (GetQualType(property_clang_type));
+
+ clang::ObjCPropertyDecl *property_decl = clang::ObjCPropertyDecl::Create (*clang_ast,
+ class_interface_decl,
+ clang::SourceLocation(), // Source Location
+ &clang_ast->Idents.get(property_name),
+ clang::SourceLocation(), //Source Location for AT
+ clang::SourceLocation(), //Source location for (
+ ivar_decl ? ivar_decl->getType() : ClangASTContext::GetQualType(property_clang_type),
+ prop_type_source);
+
+ if (property_decl)
{
- language_object_name.SetCString("this");
- is_instance_method = true;
+ if (metadata)
+ ClangASTContext::SetMetadata(clang_ast, property_decl, *metadata);
+
+ class_interface_decl->addDecl (property_decl);
+
+ clang::Selector setter_sel, getter_sel;
+
+ if (property_setter_name != nullptr)
+ {
+ std::string property_setter_no_colon(property_setter_name, strlen(property_setter_name) - 1);
+ clang::IdentifierInfo *setter_ident = &clang_ast->Idents.get(property_setter_no_colon.c_str());
+ setter_sel = clang_ast->Selectors.getSelector(1, &setter_ident);
+ }
+ else if (!(property_attributes & DW_APPLE_PROPERTY_readonly))
+ {
+ std::string setter_sel_string("set");
+ setter_sel_string.push_back(::toupper(property_name[0]));
+ setter_sel_string.append(&property_name[1]);
+ clang::IdentifierInfo *setter_ident = &clang_ast->Idents.get(setter_sel_string.c_str());
+ setter_sel = clang_ast->Selectors.getSelector(1, &setter_ident);
+ }
+ property_decl->setSetterName(setter_sel);
+ property_decl->setPropertyAttributes (clang::ObjCPropertyDecl::OBJC_PR_setter);
+
+ if (property_getter_name != nullptr)
+ {
+ clang::IdentifierInfo *getter_ident = &clang_ast->Idents.get(property_getter_name);
+ getter_sel = clang_ast->Selectors.getSelector(0, &getter_ident);
+ }
+ else
+ {
+ clang::IdentifierInfo *getter_ident = &clang_ast->Idents.get(property_name);
+ getter_sel = clang_ast->Selectors.getSelector(0, &getter_ident);
+ }
+ property_decl->setGetterName(getter_sel);
+ property_decl->setPropertyAttributes (clang::ObjCPropertyDecl::OBJC_PR_getter);
+
+ if (ivar_decl)
+ property_decl->setPropertyIvarDecl (ivar_decl);
+
+ if (property_attributes & DW_APPLE_PROPERTY_readonly)
+ property_decl->setPropertyAttributes (clang::ObjCPropertyDecl::OBJC_PR_readonly);
+ if (property_attributes & DW_APPLE_PROPERTY_readwrite)
+ property_decl->setPropertyAttributes (clang::ObjCPropertyDecl::OBJC_PR_readwrite);
+ if (property_attributes & DW_APPLE_PROPERTY_assign)
+ property_decl->setPropertyAttributes (clang::ObjCPropertyDecl::OBJC_PR_assign);
+ if (property_attributes & DW_APPLE_PROPERTY_retain)
+ property_decl->setPropertyAttributes (clang::ObjCPropertyDecl::OBJC_PR_retain);
+ if (property_attributes & DW_APPLE_PROPERTY_copy)
+ property_decl->setPropertyAttributes (clang::ObjCPropertyDecl::OBJC_PR_copy);
+ if (property_attributes & DW_APPLE_PROPERTY_nonatomic)
+ property_decl->setPropertyAttributes (clang::ObjCPropertyDecl::OBJC_PR_nonatomic);
+
+ if (!getter_sel.isNull() && !class_interface_decl->lookupInstanceMethod(getter_sel))
+ {
+ const bool isInstance = true;
+ const bool isVariadic = false;
+ const bool isSynthesized = false;
+ const bool isImplicitlyDeclared = true;
+ const bool isDefined = false;
+ const clang::ObjCMethodDecl::ImplementationControl impControl = clang::ObjCMethodDecl::None;
+ const bool HasRelatedResultType = false;
+
+ clang::ObjCMethodDecl *getter = clang::ObjCMethodDecl::Create (*clang_ast,
+ clang::SourceLocation(),
+ clang::SourceLocation(),
+ getter_sel,
+ GetQualType(property_clang_type_to_access),
+ nullptr,
+ class_interface_decl,
+ isInstance,
+ isVariadic,
+ isSynthesized,
+ isImplicitlyDeclared,
+ isDefined,
+ impControl,
+ HasRelatedResultType);
+
+ if (getter && metadata)
+ ClangASTContext::SetMetadata(clang_ast, getter, *metadata);
+
+ if (getter)
+ {
+ getter->setMethodParams(*clang_ast, llvm::ArrayRef<clang::ParmVarDecl*>(), llvm::ArrayRef<clang::SourceLocation>());
+
+ class_interface_decl->addDecl(getter);
+ }
+ }
+
+ if (!setter_sel.isNull() && !class_interface_decl->lookupInstanceMethod(setter_sel))
+ {
+ clang::QualType result_type = clang_ast->VoidTy;
+
+ const bool isInstance = true;
+ const bool isVariadic = false;
+ const bool isSynthesized = false;
+ const bool isImplicitlyDeclared = true;
+ const bool isDefined = false;
+ const clang::ObjCMethodDecl::ImplementationControl impControl = clang::ObjCMethodDecl::None;
+ const bool HasRelatedResultType = false;
+
+ clang::ObjCMethodDecl *setter = clang::ObjCMethodDecl::Create (*clang_ast,
+ clang::SourceLocation(),
+ clang::SourceLocation(),
+ setter_sel,
+ result_type,
+ nullptr,
+ class_interface_decl,
+ isInstance,
+ isVariadic,
+ isSynthesized,
+ isImplicitlyDeclared,
+ isDefined,
+ impControl,
+ HasRelatedResultType);
+
+ if (setter && metadata)
+ ClangASTContext::SetMetadata(clang_ast, setter, *metadata);
+
+ llvm::SmallVector<clang::ParmVarDecl *, 1> params;
+
+ params.push_back (clang::ParmVarDecl::Create (*clang_ast,
+ setter,
+ clang::SourceLocation(),
+ clang::SourceLocation(),
+ nullptr, // anonymous
+ GetQualType(property_clang_type_to_access),
+ nullptr,
+ clang::SC_Auto,
+ nullptr));
+
+ if (setter)
+ {
+ setter->setMethodParams(*clang_ast, llvm::ArrayRef<clang::ParmVarDecl*>(params), llvm::ArrayRef<clang::SourceLocation>());
+
+ class_interface_decl->addDecl(setter);
+ }
+ }
+
+ return true;
}
- language = eLanguageTypeC_plus_plus;
+ }
+ }
+ return false;
+}
+
+bool
+ClangASTContext::IsObjCClassTypeAndHasIVars (const CompilerType& type, bool check_superclass)
+{
+ clang::ObjCInterfaceDecl *class_interface_decl = GetAsObjCInterfaceDecl (type);
+ if (class_interface_decl)
+ return ObjCDeclHasIVars (class_interface_decl, check_superclass);
+ return false;
+}
+
+
+clang::ObjCMethodDecl *
+ClangASTContext::AddMethodToObjCObjectType (const CompilerType& type,
+ const char *name, // the full symbol name as seen in the symbol table (lldb::opaque_compiler_type_t type, "-[NString stringWithCString:]")
+ const CompilerType &method_clang_type,
+ lldb::AccessType access,
+ bool is_artificial)
+{
+ if (!type || !method_clang_type.IsValid())
+ return nullptr;
+
+ clang::ObjCInterfaceDecl *class_interface_decl = GetAsObjCInterfaceDecl(type);
+
+ if (class_interface_decl == nullptr)
+ return nullptr;
+ ClangASTContext *lldb_ast = llvm::dyn_cast<ClangASTContext>(type.GetTypeSystem());
+ if (lldb_ast == nullptr)
+ return nullptr;
+ clang::ASTContext *ast = lldb_ast->getASTContext();
+
+ const char *selector_start = ::strchr (name, ' ');
+ if (selector_start == nullptr)
+ return nullptr;
+
+ selector_start++;
+ llvm::SmallVector<clang::IdentifierInfo *, 12> selector_idents;
+
+ size_t len = 0;
+ const char *start;
+ //printf ("name = '%s'\n", name);
+
+ unsigned num_selectors_with_args = 0;
+ for (start = selector_start;
+ start && *start != '\0' && *start != ']';
+ start += len)
+ {
+ len = ::strcspn(start, ":]");
+ bool has_arg = (start[len] == ':');
+ if (has_arg)
+ ++num_selectors_with_args;
+ selector_idents.push_back (&ast->Idents.get (llvm::StringRef (start, len)));
+ if (has_arg)
+ len += 1;
+ }
+
+
+ if (selector_idents.size() == 0)
+ return nullptr;
+
+ clang::Selector method_selector = ast->Selectors.getSelector (num_selectors_with_args ? selector_idents.size() : 0,
+ selector_idents.data());
+
+ clang::QualType method_qual_type (GetQualType(method_clang_type));
+
+ // Populate the method decl with parameter decls
+ const clang::Type *method_type(method_qual_type.getTypePtr());
+
+ if (method_type == nullptr)
+ return nullptr;
+
+ const clang::FunctionProtoType *method_function_prototype (llvm::dyn_cast<clang::FunctionProtoType>(method_type));
+
+ if (!method_function_prototype)
+ return nullptr;
+
+
+ bool is_variadic = false;
+ bool is_synthesized = false;
+ bool is_defined = false;
+ clang::ObjCMethodDecl::ImplementationControl imp_control = clang::ObjCMethodDecl::None;
+
+ const unsigned num_args = method_function_prototype->getNumParams();
+
+ if (num_args != num_selectors_with_args)
+ return nullptr; // some debug information is corrupt. We are not going to deal with it.
+
+ clang::ObjCMethodDecl *objc_method_decl = clang::ObjCMethodDecl::Create (*ast,
+ clang::SourceLocation(), // beginLoc,
+ clang::SourceLocation(), // endLoc,
+ method_selector,
+ method_function_prototype->getReturnType(),
+ nullptr, // TypeSourceInfo *ResultTInfo,
+ ClangASTContext::GetASTContext(ast)->GetDeclContextForType(GetQualType(type)),
+ name[0] == '-',
+ is_variadic,
+ is_synthesized,
+ true, // is_implicitly_declared; we force this to true because we don't have source locations
+ is_defined,
+ imp_control,
+ false /*has_related_result_type*/);
+
+
+ if (objc_method_decl == nullptr)
+ return nullptr;
+
+ if (num_args > 0)
+ {
+ llvm::SmallVector<clang::ParmVarDecl *, 12> params;
+
+ for (unsigned param_index = 0; param_index < num_args; ++param_index)
+ {
+ params.push_back (clang::ParmVarDecl::Create (*ast,
+ objc_method_decl,
+ clang::SourceLocation(),
+ clang::SourceLocation(),
+ nullptr, // anonymous
+ method_function_prototype->getParamType(param_index),
+ nullptr,
+ clang::SC_Auto,
+ nullptr));
+ }
+
+ objc_method_decl->setMethodParams(*ast, llvm::ArrayRef<clang::ParmVarDecl*>(params), llvm::ArrayRef<clang::SourceLocation>());
+ }
+
+ class_interface_decl->addDecl (objc_method_decl);
+
+#ifdef LLDB_CONFIGURATION_DEBUG
+ VerifyDecl(objc_method_decl);
+#endif
+
+ return objc_method_decl;
+}
+
+bool
+ClangASTContext::GetHasExternalStorage (const CompilerType &type)
+{
+ if (IsClangType(type))
+ return false;
+
+ clang::QualType qual_type (GetCanonicalQualType(type));
+
+ const clang::Type::TypeClass type_class = qual_type->getTypeClass();
+ switch (type_class)
+ {
+ case clang::Type::Record:
+ {
+ clang::CXXRecordDecl *cxx_record_decl = qual_type->getAsCXXRecordDecl();
+ if (cxx_record_decl)
+ return cxx_record_decl->hasExternalLexicalStorage () || cxx_record_decl->hasExternalVisibleStorage();
+ }
+ break;
+
+ case clang::Type::Enum:
+ {
+ clang::EnumDecl *enum_decl = llvm::cast<clang::EnumType>(qual_type)->getDecl();
+ if (enum_decl)
+ return enum_decl->hasExternalLexicalStorage () || enum_decl->hasExternalVisibleStorage();
+ }
+ break;
+
+ case clang::Type::ObjCObject:
+ case clang::Type::ObjCInterface:
+ {
+ const clang::ObjCObjectType *objc_class_type = llvm::dyn_cast<clang::ObjCObjectType>(qual_type.getTypePtr());
+ assert (objc_class_type);
+ if (objc_class_type)
+ {
+ clang::ObjCInterfaceDecl *class_interface_decl = objc_class_type->getInterface();
+
+ if (class_interface_decl)
+ return class_interface_decl->hasExternalLexicalStorage () || class_interface_decl->hasExternalVisibleStorage ();
+ }
+ }
+ break;
+
+ case clang::Type::Typedef:
+ return GetHasExternalStorage (CompilerType(type.GetTypeSystem(), llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType().getAsOpaquePtr()));
+
+ case clang::Type::Auto:
+ return GetHasExternalStorage (CompilerType(type.GetTypeSystem(), llvm::cast<clang::AutoType>(qual_type)->getDeducedType().getAsOpaquePtr()));
+
+ case clang::Type::Elaborated:
+ return GetHasExternalStorage (CompilerType(type.GetTypeSystem(), llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType().getAsOpaquePtr()));
+
+ case clang::Type::Paren:
+ return GetHasExternalStorage (CompilerType(type.GetTypeSystem(), llvm::cast<clang::ParenType>(qual_type)->desugar().getAsOpaquePtr()));
+
+ default:
+ break;
+ }
+ return false;
+}
+
+
+bool
+ClangASTContext::SetHasExternalStorage (lldb::opaque_compiler_type_t type, bool has_extern)
+{
+ if (!type)
+ return false;
+
+ clang::QualType qual_type (GetCanonicalQualType(type));
+
+ const clang::Type::TypeClass type_class = qual_type->getTypeClass();
+ switch (type_class)
+ {
+ case clang::Type::Record:
+ {
+ clang::CXXRecordDecl *cxx_record_decl = qual_type->getAsCXXRecordDecl();
+ if (cxx_record_decl)
+ {
+ cxx_record_decl->setHasExternalLexicalStorage (has_extern);
+ cxx_record_decl->setHasExternalVisibleStorage (has_extern);
+ return true;
+ }
+ }
+ break;
+
+ case clang::Type::Enum:
+ {
+ clang::EnumDecl *enum_decl = llvm::cast<clang::EnumType>(qual_type)->getDecl();
+ if (enum_decl)
+ {
+ enum_decl->setHasExternalLexicalStorage (has_extern);
+ enum_decl->setHasExternalVisibleStorage (has_extern);
+ return true;
+ }
+ }
+ break;
+
+ case clang::Type::ObjCObject:
+ case clang::Type::ObjCInterface:
+ {
+ const clang::ObjCObjectType *objc_class_type = llvm::dyn_cast<clang::ObjCObjectType>(qual_type.getTypePtr());
+ assert (objc_class_type);
+ if (objc_class_type)
+ {
+ clang::ObjCInterfaceDecl *class_interface_decl = objc_class_type->getInterface();
+
+ if (class_interface_decl)
+ {
+ class_interface_decl->setHasExternalLexicalStorage (has_extern);
+ class_interface_decl->setHasExternalVisibleStorage (has_extern);
+ return true;
+ }
+ }
+ }
+ break;
+
+ case clang::Type::Typedef:
+ return SetHasExternalStorage(llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType().getAsOpaquePtr(), has_extern);
+
+ case clang::Type::Auto:
+ return SetHasExternalStorage (llvm::cast<clang::AutoType>(qual_type)->getDeducedType().getAsOpaquePtr(), has_extern);
+
+ case clang::Type::Elaborated:
+ return SetHasExternalStorage (llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType().getAsOpaquePtr(), has_extern);
+
+ case clang::Type::Paren:
+ return SetHasExternalStorage (llvm::cast<clang::ParenType>(qual_type)->desugar().getAsOpaquePtr(), has_extern);
+
+ default:
+ break;
+ }
+ return false;
+}
+
+
+bool
+ClangASTContext::CanImport (const CompilerType &type, lldb_private::ClangASTImporter &importer)
+{
+ if (IsClangType(type))
+ {
+ // TODO: remove external completion BOOL
+ // CompleteAndFetchChildren should get the Decl out and check for the
+
+ clang::QualType qual_type(GetCanonicalQualType(RemoveFastQualifiers(type)));
+
+ const clang::Type::TypeClass type_class = qual_type->getTypeClass();
+ switch (type_class)
+ {
+ case clang::Type::Record:
+ {
+ const clang::CXXRecordDecl *cxx_record_decl = qual_type->getAsCXXRecordDecl();
+ if (cxx_record_decl)
+ {
+ if (importer.ResolveDeclOrigin (cxx_record_decl, NULL, NULL))
+ return true;
+ }
+ }
+ break;
+
+ case clang::Type::Enum:
+ {
+ clang::EnumDecl *enum_decl = llvm::cast<clang::EnumType>(qual_type)->getDecl();
+ if (enum_decl)
+ {
+ if (importer.ResolveDeclOrigin (enum_decl, NULL, NULL))
+ return true;
+ }
+ }
+ break;
+
+ case clang::Type::ObjCObject:
+ case clang::Type::ObjCInterface:
+ {
+ const clang::ObjCObjectType *objc_class_type = llvm::dyn_cast<clang::ObjCObjectType>(qual_type);
+ if (objc_class_type)
+ {
+ clang::ObjCInterfaceDecl *class_interface_decl = objc_class_type->getInterface();
+ // We currently can't complete objective C types through the newly added ASTContext
+ // because it only supports TagDecl objects right now...
+ if (class_interface_decl)
+ {
+ if (importer.ResolveDeclOrigin (class_interface_decl, NULL, NULL))
+ return true;
+ }
+ }
+ }
+ break;
+
+
+ case clang::Type::Typedef:
+ return CanImport(CompilerType (type.GetTypeSystem(), llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType().getAsOpaquePtr()), importer);
+
+ case clang::Type::Auto:
+ return CanImport(CompilerType (type.GetTypeSystem(), llvm::cast<clang::AutoType>(qual_type)->getDeducedType().getAsOpaquePtr()), importer);
+
+ case clang::Type::Elaborated:
+ return CanImport(CompilerType (type.GetTypeSystem(), llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType().getAsOpaquePtr()), importer);
+
+ case clang::Type::Paren:
+ return CanImport(CompilerType (type.GetTypeSystem(), llvm::cast<clang::ParenType>(qual_type)->desugar().getAsOpaquePtr()), importer);
+
+ default:
+ break;
+ }
+ }
+ return false;
+}
+bool
+ClangASTContext::Import (const CompilerType &type, lldb_private::ClangASTImporter &importer)
+{
+ if (IsClangType(type))
+ {
+ // TODO: remove external completion BOOL
+ // CompleteAndFetchChildren should get the Decl out and check for the
+
+ clang::QualType qual_type(GetCanonicalQualType(RemoveFastQualifiers(type)));
+
+ const clang::Type::TypeClass type_class = qual_type->getTypeClass();
+ switch (type_class)
+ {
+ case clang::Type::Record:
+ {
+ const clang::CXXRecordDecl *cxx_record_decl = qual_type->getAsCXXRecordDecl();
+ if (cxx_record_decl)
+ {
+ if (importer.ResolveDeclOrigin (cxx_record_decl, NULL, NULL))
+ return importer.CompleteAndFetchChildren(qual_type);
+ }
+ }
+ break;
+
+ case clang::Type::Enum:
+ {
+ clang::EnumDecl *enum_decl = llvm::cast<clang::EnumType>(qual_type)->getDecl();
+ if (enum_decl)
+ {
+ if (importer.ResolveDeclOrigin (enum_decl, NULL, NULL))
+ return importer.CompleteAndFetchChildren(qual_type);
+ }
+ }
+ break;
+
+ case clang::Type::ObjCObject:
+ case clang::Type::ObjCInterface:
+ {
+ const clang::ObjCObjectType *objc_class_type = llvm::dyn_cast<clang::ObjCObjectType>(qual_type);
+ if (objc_class_type)
+ {
+ clang::ObjCInterfaceDecl *class_interface_decl = objc_class_type->getInterface();
+ // We currently can't complete objective C types through the newly added ASTContext
+ // because it only supports TagDecl objects right now...
+ if (class_interface_decl)
+ {
+ if (importer.ResolveDeclOrigin (class_interface_decl, NULL, NULL))
+ return importer.CompleteAndFetchChildren(qual_type);
+ }
+ }
+ }
+ break;
+
+
+ case clang::Type::Typedef:
+ return Import (CompilerType(type.GetTypeSystem(), llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType().getAsOpaquePtr()), importer);
+
+ case clang::Type::Auto:
+ return Import (CompilerType(type.GetTypeSystem(),llvm::cast<clang::AutoType>(qual_type)->getDeducedType().getAsOpaquePtr()), importer);
+
+ case clang::Type::Elaborated:
+ return Import (CompilerType(type.GetTypeSystem(),llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType().getAsOpaquePtr()), importer);
+
+ case clang::Type::Paren:
+ return Import (CompilerType(type.GetTypeSystem(),llvm::cast<clang::ParenType>(qual_type)->desugar().getAsOpaquePtr()), importer);
+
+ default:
+ break;
+ }
+ }
+ return false;
+}
+
+
+#pragma mark TagDecl
+
+bool
+ClangASTContext::StartTagDeclarationDefinition (const CompilerType &type)
+{
+ clang::QualType qual_type (ClangASTContext::GetQualType(type));
+ if (!qual_type.isNull())
+ {
+ const clang::TagType *tag_type = qual_type->getAs<clang::TagType>();
+ if (tag_type)
+ {
+ clang::TagDecl *tag_decl = tag_type->getDecl();
+ if (tag_decl)
+ {
+ tag_decl->startDefinition();
+ return true;
+ }
+ }
+
+ const clang::ObjCObjectType *object_type = qual_type->getAs<clang::ObjCObjectType>();
+ if (object_type)
+ {
+ clang::ObjCInterfaceDecl *interface_decl = object_type->getInterface();
+ if (interface_decl)
+ {
+ interface_decl->startDefinition();
+ return true;
+ }
+ }
+ }
+ return false;
+}
+
+bool
+ClangASTContext::CompleteTagDeclarationDefinition (const CompilerType& type)
+{
+ clang::QualType qual_type (ClangASTContext::GetQualType(type));
+ if (!qual_type.isNull())
+ {
+ clang::CXXRecordDecl *cxx_record_decl = qual_type->getAsCXXRecordDecl();
+
+ if (cxx_record_decl)
+ {
+ if (!cxx_record_decl->isCompleteDefinition())
+ cxx_record_decl->completeDefinition();
+ cxx_record_decl->setHasLoadedFieldsFromExternalStorage(true);
+ cxx_record_decl->setHasExternalLexicalStorage (false);
+ cxx_record_decl->setHasExternalVisibleStorage (false);
return true;
}
- else if (clang::ObjCMethodDecl *method_decl = llvm::dyn_cast<clang::ObjCMethodDecl>(decl_ctx))
+
+ const clang::EnumType *enutype = qual_type->getAs<clang::EnumType>();
+
+ if (enutype)
{
- // Both static and instance methods have a "self" object in objective C
- language_object_name.SetCString("self");
- if (method_decl->isInstanceMethod())
+ clang::EnumDecl *enum_decl = enutype->getDecl();
+
+ if (enum_decl)
{
- is_instance_method = true;
+ if (!enum_decl->isCompleteDefinition())
+ {
+ ClangASTContext *lldb_ast = llvm::dyn_cast<ClangASTContext>(type.GetTypeSystem());
+ if (lldb_ast == nullptr)
+ return false;
+ clang::ASTContext *ast = lldb_ast->getASTContext();
+
+ /// TODO This really needs to be fixed.
+
+ unsigned NumPositiveBits = 1;
+ unsigned NumNegativeBits = 0;
+
+ clang::QualType promotion_qual_type;
+ // If the enum integer type is less than an integer in bit width,
+ // then we must promote it to an integer size.
+ if (ast->getTypeSize(enum_decl->getIntegerType()) < ast->getTypeSize(ast->IntTy))
+ {
+ if (enum_decl->getIntegerType()->isSignedIntegerType())
+ promotion_qual_type = ast->IntTy;
+ else
+ promotion_qual_type = ast->UnsignedIntTy;
+ }
+ else
+ promotion_qual_type = enum_decl->getIntegerType();
+
+ enum_decl->completeDefinition(enum_decl->getIntegerType(), promotion_qual_type, NumPositiveBits, NumNegativeBits);
+ }
+ return true;
+ }
+ }
+ }
+ return false;
+}
+
+bool
+ClangASTContext::AddEnumerationValueToEnumerationType (lldb::opaque_compiler_type_t type,
+ const CompilerType &enumerator_clang_type,
+ const Declaration &decl,
+ const char *name,
+ int64_t enum_value,
+ uint32_t enum_value_bit_size)
+{
+ if (type && enumerator_clang_type.IsValid() && name && name[0])
+ {
+ clang::QualType enum_qual_type (GetCanonicalQualType(type));
+
+ bool is_signed = false;
+ enumerator_clang_type.IsIntegerType (is_signed);
+ const clang::Type *clang_type = enum_qual_type.getTypePtr();
+ if (clang_type)
+ {
+ const clang::EnumType *enutype = llvm::dyn_cast<clang::EnumType>(clang_type);
+
+ if (enutype)
+ {
+ llvm::APSInt enum_llvm_apsint(enum_value_bit_size, is_signed);
+ enum_llvm_apsint = enum_value;
+ clang::EnumConstantDecl *enumerator_decl =
+ clang::EnumConstantDecl::Create (*getASTContext(),
+ enutype->getDecl(),
+ clang::SourceLocation(),
+ name ? &getASTContext()->Idents.get(name) : nullptr, // Identifier
+ GetQualType(enumerator_clang_type),
+ nullptr,
+ enum_llvm_apsint);
+
+ if (enumerator_decl)
+ {
+ enutype->getDecl()->addDecl(enumerator_decl);
+
+#ifdef LLDB_CONFIGURATION_DEBUG
+ VerifyDecl(enumerator_decl);
+#endif
+
+ return true;
+ }
+ }
+ }
+ }
+ return false;
+}
+
+CompilerType
+ClangASTContext::GetEnumerationIntegerType (lldb::opaque_compiler_type_t type)
+{
+ clang::QualType enum_qual_type (GetCanonicalQualType(type));
+ const clang::Type *clang_type = enum_qual_type.getTypePtr();
+ if (clang_type)
+ {
+ const clang::EnumType *enutype = llvm::dyn_cast<clang::EnumType>(clang_type);
+ if (enutype)
+ {
+ clang::EnumDecl *enum_decl = enutype->getDecl();
+ if (enum_decl)
+ return CompilerType (getASTContext(), enum_decl->getIntegerType());
+ }
+ }
+ return CompilerType();
+}
+
+CompilerType
+ClangASTContext::CreateMemberPointerType (const CompilerType& type, const CompilerType &pointee_type)
+{
+ if (type && pointee_type.IsValid() && type.GetTypeSystem() == pointee_type.GetTypeSystem())
+ {
+ ClangASTContext *ast = llvm::dyn_cast<ClangASTContext>(type.GetTypeSystem());
+ if (!ast)
+ return CompilerType();
+ return CompilerType (ast->getASTContext(),
+ ast->getASTContext()->getMemberPointerType (GetQualType(pointee_type),
+ GetQualType(type).getTypePtr()));
+ }
+ return CompilerType();
+}
+
+
+size_t
+ClangASTContext::ConvertStringToFloatValue (lldb::opaque_compiler_type_t type, const char *s, uint8_t *dst, size_t dst_size)
+{
+ if (type)
+ {
+ clang::QualType qual_type (GetCanonicalQualType(type));
+ uint32_t count = 0;
+ bool is_complex = false;
+ if (IsFloatingPointType (type, count, is_complex))
+ {
+ // TODO: handle complex and vector types
+ if (count != 1)
+ return false;
+
+ llvm::StringRef s_sref(s);
+ llvm::APFloat ap_float(getASTContext()->getFloatTypeSemantics(qual_type), s_sref);
+
+ const uint64_t bit_size = getASTContext()->getTypeSize (qual_type);
+ const uint64_t byte_size = bit_size / 8;
+ if (dst_size >= byte_size)
+ {
+ if (bit_size == sizeof(float)*8)
+ {
+ float float32 = ap_float.convertToFloat();
+ ::memcpy (dst, &float32, byte_size);
+ return byte_size;
+ }
+ else if (bit_size >= 64)
+ {
+ llvm::APInt ap_int(ap_float.bitcastToAPInt());
+ ::memcpy (dst, ap_int.getRawData(), byte_size);
+ return byte_size;
+ }
+ }
+ }
+ }
+ return 0;
+}
+
+
+
+//----------------------------------------------------------------------
+// Dumping types
+//----------------------------------------------------------------------
+#define DEPTH_INCREMENT 2
+
+void
+ClangASTContext::DumpValue (lldb::opaque_compiler_type_t type, ExecutionContext *exe_ctx,
+ Stream *s,
+ lldb::Format format,
+ const lldb_private::DataExtractor &data,
+ lldb::offset_t data_byte_offset,
+ size_t data_byte_size,
+ uint32_t bitfield_bit_size,
+ uint32_t bitfield_bit_offset,
+ bool show_types,
+ bool show_summary,
+ bool verbose,
+ uint32_t depth)
+{
+ if (!type)
+ return;
+
+ clang::QualType qual_type(GetQualType(type));
+ switch (qual_type->getTypeClass())
+ {
+ case clang::Type::Record:
+ if (GetCompleteType(type))
+ {
+ const clang::RecordType *record_type = llvm::cast<clang::RecordType>(qual_type.getTypePtr());
+ const clang::RecordDecl *record_decl = record_type->getDecl();
+ assert(record_decl);
+ uint32_t field_bit_offset = 0;
+ uint32_t field_byte_offset = 0;
+ const clang::ASTRecordLayout &record_layout = getASTContext()->getASTRecordLayout(record_decl);
+ uint32_t child_idx = 0;
+
+ const clang::CXXRecordDecl *cxx_record_decl = llvm::dyn_cast<clang::CXXRecordDecl>(record_decl);
+ if (cxx_record_decl)
+ {
+ // We might have base classes to print out first
+ clang::CXXRecordDecl::base_class_const_iterator base_class, base_class_end;
+ for (base_class = cxx_record_decl->bases_begin(), base_class_end = cxx_record_decl->bases_end();
+ base_class != base_class_end;
+ ++base_class)
+ {
+ const clang::CXXRecordDecl *base_class_decl = llvm::cast<clang::CXXRecordDecl>(base_class->getType()->getAs<clang::RecordType>()->getDecl());
+
+ // Skip empty base classes
+ if (verbose == false && ClangASTContext::RecordHasFields(base_class_decl) == false)
+ continue;
+
+ if (base_class->isVirtual())
+ field_bit_offset = record_layout.getVBaseClassOffset(base_class_decl).getQuantity() * 8;
+ else
+ field_bit_offset = record_layout.getBaseClassOffset(base_class_decl).getQuantity() * 8;
+ field_byte_offset = field_bit_offset / 8;
+ assert (field_bit_offset % 8 == 0);
+ if (child_idx == 0)
+ s->PutChar('{');
+ else
+ s->PutChar(',');
+
+ clang::QualType base_class_qual_type = base_class->getType();
+ std::string base_class_type_name(base_class_qual_type.getAsString());
+
+ // Indent and print the base class type name
+ s->Printf("\n%*s%s ", depth + DEPTH_INCREMENT, "", base_class_type_name.c_str());
+
+ clang::TypeInfo base_class_type_info = getASTContext()->getTypeInfo(base_class_qual_type);
+
+ // Dump the value of the member
+ CompilerType base_clang_type(getASTContext(), base_class_qual_type);
+ base_clang_type.DumpValue (exe_ctx,
+ s, // Stream to dump to
+ base_clang_type.GetFormat(), // The format with which to display the member
+ data, // Data buffer containing all bytes for this type
+ data_byte_offset + field_byte_offset,// Offset into "data" where to grab value from
+ base_class_type_info.Width / 8, // Size of this type in bytes
+ 0, // Bitfield bit size
+ 0, // Bitfield bit offset
+ show_types, // Boolean indicating if we should show the variable types
+ show_summary, // Boolean indicating if we should show a summary for the current type
+ verbose, // Verbose output?
+ depth + DEPTH_INCREMENT); // Scope depth for any types that have children
+
+ ++child_idx;
+ }
+ }
+ uint32_t field_idx = 0;
+ clang::RecordDecl::field_iterator field, field_end;
+ for (field = record_decl->field_begin(), field_end = record_decl->field_end(); field != field_end; ++field, ++field_idx, ++child_idx)
+ {
+ // Print the starting squiggly bracket (if this is the
+ // first member) or comma (for member 2 and beyond) for
+ // the struct/union/class member.
+ if (child_idx == 0)
+ s->PutChar('{');
+ else
+ s->PutChar(',');
+
+ // Indent
+ s->Printf("\n%*s", depth + DEPTH_INCREMENT, "");
+
+ clang::QualType field_type = field->getType();
+ // Print the member type if requested
+ // Figure out the type byte size (field_type_info.first) and
+ // alignment (field_type_info.second) from the AST context.
+ clang::TypeInfo field_type_info = getASTContext()->getTypeInfo(field_type);
+ assert(field_idx < record_layout.getFieldCount());
+ // Figure out the field offset within the current struct/union/class type
+ field_bit_offset = record_layout.getFieldOffset (field_idx);
+ field_byte_offset = field_bit_offset / 8;
+ uint32_t field_bitfield_bit_size = 0;
+ uint32_t field_bitfield_bit_offset = 0;
+ if (ClangASTContext::FieldIsBitfield (getASTContext(), *field, field_bitfield_bit_size))
+ field_bitfield_bit_offset = field_bit_offset % 8;
+
+ if (show_types)
+ {
+ std::string field_type_name(field_type.getAsString());
+ if (field_bitfield_bit_size > 0)
+ s->Printf("(%s:%u) ", field_type_name.c_str(), field_bitfield_bit_size);
+ else
+ s->Printf("(%s) ", field_type_name.c_str());
+ }
+ // Print the member name and equal sign
+ s->Printf("%s = ", field->getNameAsString().c_str());
+
+
+ // Dump the value of the member
+ CompilerType field_clang_type (getASTContext(), field_type);
+ field_clang_type.DumpValue (exe_ctx,
+ s, // Stream to dump to
+ field_clang_type.GetFormat(), // The format with which to display the member
+ data, // Data buffer containing all bytes for this type
+ data_byte_offset + field_byte_offset,// Offset into "data" where to grab value from
+ field_type_info.Width / 8, // Size of this type in bytes
+ field_bitfield_bit_size, // Bitfield bit size
+ field_bitfield_bit_offset, // Bitfield bit offset
+ show_types, // Boolean indicating if we should show the variable types
+ show_summary, // Boolean indicating if we should show a summary for the current type
+ verbose, // Verbose output?
+ depth + DEPTH_INCREMENT); // Scope depth for any types that have children
+ }
+
+ // Indent the trailing squiggly bracket
+ if (child_idx > 0)
+ s->Printf("\n%*s}", depth, "");
+ }
+ return;
+
+ case clang::Type::Enum:
+ if (GetCompleteType(type))
+ {
+ const clang::EnumType *enutype = llvm::cast<clang::EnumType>(qual_type.getTypePtr());
+ const clang::EnumDecl *enum_decl = enutype->getDecl();
+ assert(enum_decl);
+ clang::EnumDecl::enumerator_iterator enum_pos, enum_end_pos;
+ lldb::offset_t offset = data_byte_offset;
+ const int64_t enum_value = data.GetMaxU64Bitfield(&offset, data_byte_size, bitfield_bit_size, bitfield_bit_offset);
+ for (enum_pos = enum_decl->enumerator_begin(), enum_end_pos = enum_decl->enumerator_end(); enum_pos != enum_end_pos; ++enum_pos)
+ {
+ if (enum_pos->getInitVal() == enum_value)
+ {
+ s->Printf("%s", enum_pos->getNameAsString().c_str());
+ return;
+ }
+ }
+ // If we have gotten here we didn't get find the enumerator in the
+ // enum decl, so just print the integer.
+ s->Printf("%" PRIi64, enum_value);
+ }
+ return;
+
+ case clang::Type::ConstantArray:
+ {
+ const clang::ConstantArrayType *array = llvm::cast<clang::ConstantArrayType>(qual_type.getTypePtr());
+ bool is_array_of_characters = false;
+ clang::QualType element_qual_type = array->getElementType();
+
+ const clang::Type *canonical_type = element_qual_type->getCanonicalTypeInternal().getTypePtr();
+ if (canonical_type)
+ is_array_of_characters = canonical_type->isCharType();
+
+ const uint64_t element_count = array->getSize().getLimitedValue();
+
+ clang::TypeInfo field_type_info = getASTContext()->getTypeInfo(element_qual_type);
+
+ uint32_t element_idx = 0;
+ uint32_t element_offset = 0;
+ uint64_t element_byte_size = field_type_info.Width / 8;
+ uint32_t element_stride = element_byte_size;
+
+ if (is_array_of_characters)
+ {
+ s->PutChar('"');
+ data.Dump(s, data_byte_offset, lldb::eFormatChar, element_byte_size, element_count, UINT32_MAX, LLDB_INVALID_ADDRESS, 0, 0);
+ s->PutChar('"');
+ return;
}
else
{
- is_instance_method = false;
+ CompilerType element_clang_type(getASTContext(), element_qual_type);
+ lldb::Format element_format = element_clang_type.GetFormat();
+
+ for (element_idx = 0; element_idx < element_count; ++element_idx)
+ {
+ // Print the starting squiggly bracket (if this is the
+ // first member) or comman (for member 2 and beyong) for
+ // the struct/union/class member.
+ if (element_idx == 0)
+ s->PutChar('{');
+ else
+ s->PutChar(',');
+
+ // Indent and print the index
+ s->Printf("\n%*s[%u] ", depth + DEPTH_INCREMENT, "", element_idx);
+
+ // Figure out the field offset within the current struct/union/class type
+ element_offset = element_idx * element_stride;
+
+ // Dump the value of the member
+ element_clang_type.DumpValue (exe_ctx,
+ s, // Stream to dump to
+ element_format, // The format with which to display the element
+ data, // Data buffer containing all bytes for this type
+ data_byte_offset + element_offset,// Offset into "data" where to grab value from
+ element_byte_size, // Size of this type in bytes
+ 0, // Bitfield bit size
+ 0, // Bitfield bit offset
+ show_types, // Boolean indicating if we should show the variable types
+ show_summary, // Boolean indicating if we should show a summary for the current type
+ verbose, // Verbose output?
+ depth + DEPTH_INCREMENT); // Scope depth for any types that have children
+ }
+
+ // Indent the trailing squiggly bracket
+ if (element_idx > 0)
+ s->Printf("\n%*s}", depth, "");
+ }
+ }
+ return;
+
+ case clang::Type::Typedef:
+ {
+ clang::QualType typedef_qual_type = llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType();
+
+ CompilerType typedef_clang_type (getASTContext(), typedef_qual_type);
+ lldb::Format typedef_format = typedef_clang_type.GetFormat();
+ clang::TypeInfo typedef_type_info = getASTContext()->getTypeInfo(typedef_qual_type);
+ uint64_t typedef_byte_size = typedef_type_info.Width / 8;
+
+ return typedef_clang_type.DumpValue (exe_ctx,
+ s, // Stream to dump to
+ typedef_format, // The format with which to display the element
+ data, // Data buffer containing all bytes for this type
+ data_byte_offset, // Offset into "data" where to grab value from
+ typedef_byte_size, // Size of this type in bytes
+ bitfield_bit_size, // Bitfield bit size
+ bitfield_bit_offset,// Bitfield bit offset
+ show_types, // Boolean indicating if we should show the variable types
+ show_summary, // Boolean indicating if we should show a summary for the current type
+ verbose, // Verbose output?
+ depth); // Scope depth for any types that have children
+ }
+ break;
+
+ case clang::Type::Auto:
+ {
+ clang::QualType elaborated_qual_type = llvm::cast<clang::AutoType>(qual_type)->getDeducedType();
+ CompilerType elaborated_clang_type (getASTContext(), elaborated_qual_type);
+ lldb::Format elaborated_format = elaborated_clang_type.GetFormat();
+ clang::TypeInfo elaborated_type_info = getASTContext()->getTypeInfo(elaborated_qual_type);
+ uint64_t elaborated_byte_size = elaborated_type_info.Width / 8;
+
+ return elaborated_clang_type.DumpValue (exe_ctx,
+ s, // Stream to dump to
+ elaborated_format, // The format with which to display the element
+ data, // Data buffer containing all bytes for this type
+ data_byte_offset, // Offset into "data" where to grab value from
+ elaborated_byte_size, // Size of this type in bytes
+ bitfield_bit_size, // Bitfield bit size
+ bitfield_bit_offset,// Bitfield bit offset
+ show_types, // Boolean indicating if we should show the variable types
+ show_summary, // Boolean indicating if we should show a summary for the current type
+ verbose, // Verbose output?
+ depth); // Scope depth for any types that have children
+ }
+ break;
+
+ case clang::Type::Elaborated:
+ {
+ clang::QualType elaborated_qual_type = llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType();
+ CompilerType elaborated_clang_type (getASTContext(), elaborated_qual_type);
+ lldb::Format elaborated_format = elaborated_clang_type.GetFormat();
+ clang::TypeInfo elaborated_type_info = getASTContext()->getTypeInfo(elaborated_qual_type);
+ uint64_t elaborated_byte_size = elaborated_type_info.Width / 8;
+
+ return elaborated_clang_type.DumpValue (exe_ctx,
+ s, // Stream to dump to
+ elaborated_format, // The format with which to display the element
+ data, // Data buffer containing all bytes for this type
+ data_byte_offset, // Offset into "data" where to grab value from
+ elaborated_byte_size, // Size of this type in bytes
+ bitfield_bit_size, // Bitfield bit size
+ bitfield_bit_offset,// Bitfield bit offset
+ show_types, // Boolean indicating if we should show the variable types
+ show_summary, // Boolean indicating if we should show a summary for the current type
+ verbose, // Verbose output?
+ depth); // Scope depth for any types that have children
+ }
+ break;
+
+ case clang::Type::Paren:
+ {
+ clang::QualType desugar_qual_type = llvm::cast<clang::ParenType>(qual_type)->desugar();
+ CompilerType desugar_clang_type (getASTContext(), desugar_qual_type);
+
+ lldb::Format desugar_format = desugar_clang_type.GetFormat();
+ clang::TypeInfo desugar_type_info = getASTContext()->getTypeInfo(desugar_qual_type);
+ uint64_t desugar_byte_size = desugar_type_info.Width / 8;
+
+ return desugar_clang_type.DumpValue (exe_ctx,
+ s, // Stream to dump to
+ desugar_format, // The format with which to display the element
+ data, // Data buffer containing all bytes for this type
+ data_byte_offset, // Offset into "data" where to grab value from
+ desugar_byte_size, // Size of this type in bytes
+ bitfield_bit_size, // Bitfield bit size
+ bitfield_bit_offset,// Bitfield bit offset
+ show_types, // Boolean indicating if we should show the variable types
+ show_summary, // Boolean indicating if we should show a summary for the current type
+ verbose, // Verbose output?
+ depth); // Scope depth for any types that have children
+ }
+ break;
+
+ default:
+ // We are down to a scalar type that we just need to display.
+ data.Dump(s,
+ data_byte_offset,
+ format,
+ data_byte_size,
+ 1,
+ UINT32_MAX,
+ LLDB_INVALID_ADDRESS,
+ bitfield_bit_size,
+ bitfield_bit_offset);
+
+ if (show_summary)
+ DumpSummary (type, exe_ctx, s, data, data_byte_offset, data_byte_size);
+ break;
+ }
+}
+
+
+
+
+bool
+ClangASTContext::DumpTypeValue (lldb::opaque_compiler_type_t type, Stream *s,
+ lldb::Format format,
+ const lldb_private::DataExtractor &data,
+ lldb::offset_t byte_offset,
+ size_t byte_size,
+ uint32_t bitfield_bit_size,
+ uint32_t bitfield_bit_offset,
+ ExecutionContextScope *exe_scope)
+{
+ if (!type)
+ return false;
+ if (IsAggregateType(type))
+ {
+ return false;
+ }
+ else
+ {
+ clang::QualType qual_type(GetQualType(type));
+
+ const clang::Type::TypeClass type_class = qual_type->getTypeClass();
+ switch (type_class)
+ {
+ case clang::Type::Typedef:
+ {
+ clang::QualType typedef_qual_type = llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType();
+ CompilerType typedef_clang_type (getASTContext(), typedef_qual_type);
+ if (format == eFormatDefault)
+ format = typedef_clang_type.GetFormat();
+ clang::TypeInfo typedef_type_info = getASTContext()->getTypeInfo(typedef_qual_type);
+ uint64_t typedef_byte_size = typedef_type_info.Width / 8;
+
+ return typedef_clang_type.DumpTypeValue (s,
+ format, // The format with which to display the element
+ data, // Data buffer containing all bytes for this type
+ byte_offset, // Offset into "data" where to grab value from
+ typedef_byte_size, // Size of this type in bytes
+ bitfield_bit_size, // Size in bits of a bitfield value, if zero don't treat as a bitfield
+ bitfield_bit_offset, // Offset in bits of a bitfield value if bitfield_bit_size != 0
+ exe_scope);
+ }
+ break;
+
+ case clang::Type::Enum:
+ // If our format is enum or default, show the enumeration value as
+ // its enumeration string value, else just display it as requested.
+ if ((format == eFormatEnum || format == eFormatDefault) && GetCompleteType(type))
+ {
+ const clang::EnumType *enutype = llvm::cast<clang::EnumType>(qual_type.getTypePtr());
+ const clang::EnumDecl *enum_decl = enutype->getDecl();
+ assert(enum_decl);
+ clang::EnumDecl::enumerator_iterator enum_pos, enum_end_pos;
+ const bool is_signed = qual_type->isSignedIntegerOrEnumerationType();
+ lldb::offset_t offset = byte_offset;
+ if (is_signed)
+ {
+ const int64_t enum_svalue = data.GetMaxS64Bitfield (&offset, byte_size, bitfield_bit_size, bitfield_bit_offset);
+ for (enum_pos = enum_decl->enumerator_begin(), enum_end_pos = enum_decl->enumerator_end(); enum_pos != enum_end_pos; ++enum_pos)
+ {
+ if (enum_pos->getInitVal().getSExtValue() == enum_svalue)
+ {
+ s->PutCString (enum_pos->getNameAsString().c_str());
+ return true;
+ }
+ }
+ // If we have gotten here we didn't get find the enumerator in the
+ // enum decl, so just print the integer.
+ s->Printf("%" PRIi64, enum_svalue);
+ }
+ else
+ {
+ const uint64_t enum_uvalue = data.GetMaxU64Bitfield (&offset, byte_size, bitfield_bit_size, bitfield_bit_offset);
+ for (enum_pos = enum_decl->enumerator_begin(), enum_end_pos = enum_decl->enumerator_end(); enum_pos != enum_end_pos; ++enum_pos)
+ {
+ if (enum_pos->getInitVal().getZExtValue() == enum_uvalue)
+ {
+ s->PutCString (enum_pos->getNameAsString().c_str());
+ return true;
+ }
+ }
+ // If we have gotten here we didn't get find the enumerator in the
+ // enum decl, so just print the integer.
+ s->Printf("%" PRIu64, enum_uvalue);
+ }
+ return true;
+ }
+ // format was not enum, just fall through and dump the value as requested....
+
+ default:
+ // We are down to a scalar type that we just need to display.
+ {
+ uint32_t item_count = 1;
+ // A few formats, we might need to modify our size and count for depending
+ // on how we are trying to display the value...
+ switch (format)
+ {
+ default:
+ case eFormatBoolean:
+ case eFormatBinary:
+ case eFormatComplex:
+ case eFormatCString: // NULL terminated C strings
+ case eFormatDecimal:
+ case eFormatEnum:
+ case eFormatHex:
+ case eFormatHexUppercase:
+ case eFormatFloat:
+ case eFormatOctal:
+ case eFormatOSType:
+ case eFormatUnsigned:
+ case eFormatPointer:
+ case eFormatVectorOfChar:
+ case eFormatVectorOfSInt8:
+ case eFormatVectorOfUInt8:
+ case eFormatVectorOfSInt16:
+ case eFormatVectorOfUInt16:
+ case eFormatVectorOfSInt32:
+ case eFormatVectorOfUInt32:
+ case eFormatVectorOfSInt64:
+ case eFormatVectorOfUInt64:
+ case eFormatVectorOfFloat32:
+ case eFormatVectorOfFloat64:
+ case eFormatVectorOfUInt128:
+ break;
+
+ case eFormatChar:
+ case eFormatCharPrintable:
+ case eFormatCharArray:
+ case eFormatBytes:
+ case eFormatBytesWithASCII:
+ item_count = byte_size;
+ byte_size = 1;
+ break;
+
+ case eFormatUnicode16:
+ item_count = byte_size / 2;
+ byte_size = 2;
+ break;
+
+ case eFormatUnicode32:
+ item_count = byte_size / 4;
+ byte_size = 4;
+ break;
+ }
+ return data.Dump (s,
+ byte_offset,
+ format,
+ byte_size,
+ item_count,
+ UINT32_MAX,
+ LLDB_INVALID_ADDRESS,
+ bitfield_bit_size,
+ bitfield_bit_offset,
+ exe_scope);
+ }
+ break;
+ }
+ }
+ return 0;
+}
+
+
+
+void
+ClangASTContext::DumpSummary (lldb::opaque_compiler_type_t type, ExecutionContext *exe_ctx,
+ Stream *s,
+ const lldb_private::DataExtractor &data,
+ lldb::offset_t data_byte_offset,
+ size_t data_byte_size)
+{
+ uint32_t length = 0;
+ if (IsCStringType (type, length))
+ {
+ if (exe_ctx)
+ {
+ Process *process = exe_ctx->GetProcessPtr();
+ if (process)
+ {
+ lldb::offset_t offset = data_byte_offset;
+ lldb::addr_t pointer_address = data.GetMaxU64(&offset, data_byte_size);
+ std::vector<uint8_t> buf;
+ if (length > 0)
+ buf.resize (length);
+ else
+ buf.resize (256);
+
+ lldb_private::DataExtractor cstr_data(&buf.front(), buf.size(), process->GetByteOrder(), 4);
+ buf.back() = '\0';
+ size_t bytes_read;
+ size_t total_cstr_len = 0;
+ Error error;
+ while ((bytes_read = process->ReadMemory (pointer_address, &buf.front(), buf.size(), error)) > 0)
+ {
+ const size_t len = strlen((const char *)&buf.front());
+ if (len == 0)
+ break;
+ if (total_cstr_len == 0)
+ s->PutCString (" \"");
+ cstr_data.Dump(s, 0, lldb::eFormatChar, 1, len, UINT32_MAX, LLDB_INVALID_ADDRESS, 0, 0);
+ total_cstr_len += len;
+ if (len < buf.size())
+ break;
+ pointer_address += total_cstr_len;
+ }
+ if (total_cstr_len > 0)
+ s->PutChar ('"');
+ }
+ }
+ }
+}
+
+void
+ClangASTContext::DumpTypeDescription (lldb::opaque_compiler_type_t type)
+{
+ StreamFile s (stdout, false);
+ DumpTypeDescription (type, &s);
+ ClangASTMetadata *metadata = ClangASTContext::GetMetadata (getASTContext(), type);
+ if (metadata)
+ {
+ metadata->Dump (&s);
+ }
+}
+
+void
+ClangASTContext::DumpTypeDescription (lldb::opaque_compiler_type_t type, Stream *s)
+{
+ if (type)
+ {
+ clang::QualType qual_type(GetQualType(type));
+
+ llvm::SmallVector<char, 1024> buf;
+ llvm::raw_svector_ostream llvm_ostrm (buf);
+
+ const clang::Type::TypeClass type_class = qual_type->getTypeClass();
+ switch (type_class)
+ {
+ case clang::Type::ObjCObject:
+ case clang::Type::ObjCInterface:
+ {
+ GetCompleteType(type);
+
+ const clang::ObjCObjectType *objc_class_type = llvm::dyn_cast<clang::ObjCObjectType>(qual_type.getTypePtr());
+ assert (objc_class_type);
+ if (objc_class_type)
+ {
+ clang::ObjCInterfaceDecl *class_interface_decl = objc_class_type->getInterface();
+ if (class_interface_decl)
+ {
+ clang::PrintingPolicy policy = getASTContext()->getPrintingPolicy();
+ class_interface_decl->print(llvm_ostrm, policy, s->GetIndentLevel());
+ }
+ }
+ }
+ break;
+
+ case clang::Type::Typedef:
+ {
+ const clang::TypedefType *typedef_type = qual_type->getAs<clang::TypedefType>();
+ if (typedef_type)
+ {
+ const clang::TypedefNameDecl *typedef_decl = typedef_type->getDecl();
+ std::string clang_typedef_name (typedef_decl->getQualifiedNameAsString());
+ if (!clang_typedef_name.empty())
+ {
+ s->PutCString ("typedef ");
+ s->PutCString (clang_typedef_name.c_str());
+ }
+ }
+ }
+ break;
+
+ case clang::Type::Auto:
+ CompilerType (getASTContext(), llvm::cast<clang::AutoType>(qual_type)->getDeducedType()).DumpTypeDescription(s);
+ return;
+
+ case clang::Type::Elaborated:
+ CompilerType (getASTContext(), llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType()).DumpTypeDescription(s);
+ return;
+
+ case clang::Type::Paren:
+ CompilerType (getASTContext(), llvm::cast<clang::ParenType>(qual_type)->desugar()).DumpTypeDescription(s);
+ return;
+
+ case clang::Type::Record:
+ {
+ GetCompleteType(type);
+
+ const clang::RecordType *record_type = llvm::cast<clang::RecordType>(qual_type.getTypePtr());
+ const clang::RecordDecl *record_decl = record_type->getDecl();
+ const clang::CXXRecordDecl *cxx_record_decl = llvm::dyn_cast<clang::CXXRecordDecl>(record_decl);
+
+ if (cxx_record_decl)
+ cxx_record_decl->print(llvm_ostrm, getASTContext()->getPrintingPolicy(), s->GetIndentLevel());
+ else
+ record_decl->print(llvm_ostrm, getASTContext()->getPrintingPolicy(), s->GetIndentLevel());
+ }
+ break;
+
+ default:
+ {
+ const clang::TagType *tag_type = llvm::dyn_cast<clang::TagType>(qual_type.getTypePtr());
+ if (tag_type)
+ {
+ clang::TagDecl *tag_decl = tag_type->getDecl();
+ if (tag_decl)
+ tag_decl->print(llvm_ostrm, 0);
+ }
+ else
+ {
+ std::string clang_type_name(qual_type.getAsString());
+ if (!clang_type_name.empty())
+ s->PutCString (clang_type_name.c_str());
+ }
+ }
+ }
+
+ if (buf.size() > 0)
+ {
+ s->Write (buf.data(), buf.size());
+ }
+ }
+}
+
+void
+ClangASTContext::DumpTypeName (const CompilerType &type)
+{
+ if (IsClangType(type))
+ {
+ clang::QualType qual_type(GetCanonicalQualType(RemoveFastQualifiers(type)));
+
+ const clang::Type::TypeClass type_class = qual_type->getTypeClass();
+ switch (type_class)
+ {
+ case clang::Type::Record:
+ {
+ const clang::CXXRecordDecl *cxx_record_decl = qual_type->getAsCXXRecordDecl();
+ if (cxx_record_decl)
+ printf("class %s", cxx_record_decl->getName().str().c_str());
+ }
+ break;
+
+ case clang::Type::Enum:
+ {
+ clang::EnumDecl *enum_decl = llvm::cast<clang::EnumType>(qual_type)->getDecl();
+ if (enum_decl)
+ {
+ printf("enum %s", enum_decl->getName().str().c_str());
+ }
+ }
+ break;
+
+ case clang::Type::ObjCObject:
+ case clang::Type::ObjCInterface:
+ {
+ const clang::ObjCObjectType *objc_class_type = llvm::dyn_cast<clang::ObjCObjectType>(qual_type);
+ if (objc_class_type)
+ {
+ clang::ObjCInterfaceDecl *class_interface_decl = objc_class_type->getInterface();
+ // We currently can't complete objective C types through the newly added ASTContext
+ // because it only supports TagDecl objects right now...
+ if (class_interface_decl)
+ printf("@class %s", class_interface_decl->getName().str().c_str());
+ }
+ }
+ break;
+
+
+ case clang::Type::Typedef:
+ printf("typedef %s", llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getName().str().c_str());
+ break;
+
+ case clang::Type::Auto:
+ printf("auto ");
+ return DumpTypeName (CompilerType (type.GetTypeSystem(), llvm::cast<clang::AutoType>(qual_type)->getDeducedType().getAsOpaquePtr()));
+
+ case clang::Type::Elaborated:
+ printf("elaborated ");
+ return DumpTypeName (CompilerType (type.GetTypeSystem(), llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType().getAsOpaquePtr()));
+
+ case clang::Type::Paren:
+ printf("paren ");
+ return DumpTypeName (CompilerType (type.GetTypeSystem(), llvm::cast<clang::ParenType>(qual_type)->desugar().getAsOpaquePtr()));
+
+ default:
+ printf("ClangASTContext::DumpTypeName() type_class = %u", type_class);
+ break;
+ }
+ }
+
+}
+
+
+
+clang::ClassTemplateDecl *
+ClangASTContext::ParseClassTemplateDecl (clang::DeclContext *decl_ctx,
+ lldb::AccessType access_type,
+ const char *parent_name,
+ int tag_decl_kind,
+ const ClangASTContext::TemplateParameterInfos &template_param_infos)
+{
+ if (template_param_infos.IsValid())
+ {
+ std::string template_basename(parent_name);
+ template_basename.erase (template_basename.find('<'));
+
+ return CreateClassTemplateDecl (decl_ctx,
+ access_type,
+ template_basename.c_str(),
+ tag_decl_kind,
+ template_param_infos);
+ }
+ return NULL;
+}
+
+void
+ClangASTContext::CompleteTagDecl (void *baton, clang::TagDecl *decl)
+{
+ ClangASTContext *ast = (ClangASTContext *)baton;
+ SymbolFile *sym_file = ast->GetSymbolFile();
+ if (sym_file)
+ {
+ CompilerType clang_type = GetTypeForDecl (decl);
+ if (clang_type)
+ sym_file->CompleteType (clang_type);
+ }
+}
+
+void
+ClangASTContext::CompleteObjCInterfaceDecl (void *baton, clang::ObjCInterfaceDecl *decl)
+{
+ ClangASTContext *ast = (ClangASTContext *)baton;
+ SymbolFile *sym_file = ast->GetSymbolFile();
+ if (sym_file)
+ {
+ CompilerType clang_type = GetTypeForDecl (decl);
+ if (clang_type)
+ sym_file->CompleteType (clang_type);
+ }
+}
+
+
+DWARFASTParser *
+ClangASTContext::GetDWARFParser ()
+{
+ if (!m_dwarf_ast_parser_ap)
+ m_dwarf_ast_parser_ap.reset(new DWARFASTParserClang(*this));
+ return m_dwarf_ast_parser_ap.get();
+}
+
+
+bool
+ClangASTContext::LayoutRecordType(void *baton,
+ const clang::RecordDecl *record_decl,
+ uint64_t &bit_size,
+ uint64_t &alignment,
+ llvm::DenseMap<const clang::FieldDecl *, uint64_t> &field_offsets,
+ llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits> &base_offsets,
+ llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits> &vbase_offsets)
+{
+ ClangASTContext *ast = (ClangASTContext *)baton;
+ DWARFASTParserClang *dwarf_ast_parser = (DWARFASTParserClang *)ast->GetDWARFParser();
+ return dwarf_ast_parser->LayoutRecordType(record_decl, bit_size, alignment, field_offsets, base_offsets, vbase_offsets);
+}
+
+//----------------------------------------------------------------------
+// CompilerDecl override functions
+//----------------------------------------------------------------------
+lldb::VariableSP
+ClangASTContext::DeclGetVariable (void *opaque_decl)
+{
+ if (llvm::dyn_cast<clang::VarDecl>((clang::Decl *)opaque_decl))
+ {
+ auto decl_search_it = m_decl_objects.find(opaque_decl);
+ if (decl_search_it != m_decl_objects.end())
+ return std::static_pointer_cast<Variable>(decl_search_it->second);
+ }
+ return VariableSP();
+}
+
+void
+ClangASTContext::DeclLinkToObject (void *opaque_decl, std::shared_ptr<void> object)
+{
+ if (m_decl_objects.find(opaque_decl) == m_decl_objects.end())
+ m_decl_objects.insert(std::make_pair(opaque_decl, object));
+}
+
+ConstString
+ClangASTContext::DeclGetName (void *opaque_decl)
+{
+ if (opaque_decl)
+ {
+ clang::NamedDecl *nd = llvm::dyn_cast<NamedDecl>((clang::Decl*)opaque_decl);
+ if (nd != nullptr)
+ return ConstString(nd->getDeclName().getAsString());
+ }
+ return ConstString();
+}
+
+ConstString
+ClangASTContext::DeclGetMangledName (void *opaque_decl)
+{
+ if (opaque_decl)
+ {
+ clang::NamedDecl *nd = llvm::dyn_cast<clang::NamedDecl>((clang::Decl*)opaque_decl);
+ if (nd != nullptr && !llvm::isa<clang::ObjCMethodDecl>(nd))
+ {
+ clang::MangleContext *mc = getMangleContext();
+ if (mc && mc->shouldMangleCXXName(nd))
+ {
+ llvm::SmallVector<char, 1024> buf;
+ llvm::raw_svector_ostream llvm_ostrm (buf);
+ if (llvm::isa<clang::CXXConstructorDecl>(nd))
+ {
+ mc->mangleCXXCtor(llvm::dyn_cast<clang::CXXConstructorDecl>(nd), Ctor_Complete, llvm_ostrm);
+ }
+ else if (llvm::isa<clang::CXXDestructorDecl>(nd))
+ {
+ mc->mangleCXXDtor(llvm::dyn_cast<clang::CXXDestructorDecl>(nd), Dtor_Complete, llvm_ostrm);
+ }
+ else
+ {
+ mc->mangleName(nd, llvm_ostrm);
+ }
+ if (buf.size() > 0)
+ return ConstString(buf.data(), buf.size());
+ }
+ }
+ }
+ return ConstString();
+}
+
+CompilerDeclContext
+ClangASTContext::DeclGetDeclContext (void *opaque_decl)
+{
+ if (opaque_decl)
+ return CompilerDeclContext(this, ((clang::Decl*)opaque_decl)->getDeclContext());
+ else
+ return CompilerDeclContext();
+}
+
+CompilerType
+ClangASTContext::DeclGetFunctionReturnType(void *opaque_decl)
+{
+ if (clang::FunctionDecl *func_decl = llvm::dyn_cast<clang::FunctionDecl>((clang::Decl*)opaque_decl))
+ return CompilerType(this, func_decl->getReturnType().getAsOpaquePtr());
+ if (clang::ObjCMethodDecl *objc_method = llvm::dyn_cast<clang::ObjCMethodDecl>((clang::Decl*)opaque_decl))
+ return CompilerType(this, objc_method->getReturnType().getAsOpaquePtr());
+ else
+ return CompilerType();
+}
+
+size_t
+ClangASTContext::DeclGetFunctionNumArguments(void *opaque_decl)
+{
+ if (clang::FunctionDecl *func_decl = llvm::dyn_cast<clang::FunctionDecl>((clang::Decl*)opaque_decl))
+ return func_decl->param_size();
+ if (clang::ObjCMethodDecl *objc_method = llvm::dyn_cast<clang::ObjCMethodDecl>((clang::Decl*)opaque_decl))
+ return objc_method->param_size();
+ else
+ return 0;
+}
+
+CompilerType
+ClangASTContext::DeclGetFunctionArgumentType (void *opaque_decl, size_t idx)
+{
+ if (clang::FunctionDecl *func_decl = llvm::dyn_cast<clang::FunctionDecl>((clang::Decl*)opaque_decl))
+ {
+ if (idx < func_decl->param_size())
+ {
+ ParmVarDecl *var_decl = func_decl->getParamDecl(idx);
+ if (var_decl)
+ return CompilerType(this, var_decl->getOriginalType().getAsOpaquePtr());
+ }
+ }
+ else if (clang::ObjCMethodDecl *objc_method = llvm::dyn_cast<clang::ObjCMethodDecl>((clang::Decl*)opaque_decl))
+ {
+ if (idx < objc_method->param_size())
+ return CompilerType(this, objc_method->parameters()[idx]->getOriginalType().getAsOpaquePtr());
+ }
+ return CompilerType();
+}
+
+//----------------------------------------------------------------------
+// CompilerDeclContext functions
+//----------------------------------------------------------------------
+
+std::vector<CompilerDecl>
+ClangASTContext::DeclContextFindDeclByName(void *opaque_decl_ctx, ConstString name)
+{
+ std::vector<CompilerDecl> found_decls;
+ if (opaque_decl_ctx)
+ {
+ DeclContext *root_decl_ctx = (DeclContext *)opaque_decl_ctx;
+ std::set<DeclContext *> searched;
+ std::multimap<DeclContext *, DeclContext *> search_queue;
+ SymbolFile *symbol_file = GetSymbolFile();
+
+ for (clang::DeclContext *decl_context = root_decl_ctx; decl_context != nullptr && found_decls.empty(); decl_context = decl_context->getParent())
+ {
+ search_queue.insert(std::make_pair(decl_context, decl_context));
+
+ for (auto it = search_queue.find(decl_context); it != search_queue.end(); it++)
+ {
+ if (!searched.insert(it->second).second)
+ continue;
+ symbol_file->ParseDeclsForContext(CompilerDeclContext(this, it->second));
+
+ for (clang::Decl *child : it->second->decls())
+ {
+ if (clang::UsingDirectiveDecl *ud = llvm::dyn_cast<clang::UsingDirectiveDecl>(child))
+ {
+ clang::DeclContext *from = ud->getCommonAncestor();
+ if (searched.find(ud->getNominatedNamespace()) == searched.end())
+ search_queue.insert(std::make_pair(from, ud->getNominatedNamespace()));
+ }
+ else if (clang::UsingDecl *ud = llvm::dyn_cast<clang::UsingDecl>(child))
+ {
+ for (clang::UsingShadowDecl *usd : ud->shadows())
+ {
+ clang::Decl *target = usd->getTargetDecl();
+ if (clang::NamedDecl *nd = llvm::dyn_cast<clang::NamedDecl>(target))
+ {
+ IdentifierInfo *ii = nd->getIdentifier();
+ if (ii != nullptr && ii->getName().equals(name.AsCString(nullptr)))
+ found_decls.push_back(CompilerDecl(this, nd));
+ }
+ }
+ }
+ else if (clang::NamedDecl *nd = llvm::dyn_cast<clang::NamedDecl>(child))
+ {
+ IdentifierInfo *ii = nd->getIdentifier();
+ if (ii != nullptr && ii->getName().equals(name.AsCString(nullptr)))
+ found_decls.push_back(CompilerDecl(this, nd));
+ }
+ }
}
- language = eLanguageTypeObjC;
+ }
+ }
+ return found_decls;
+}
+
+// Look for child_decl_ctx's lookup scope in frame_decl_ctx and its parents,
+// and return the number of levels it took to find it, or LLDB_INVALID_DECL_LEVEL
+// if not found. If the decl was imported via a using declaration, its name and/or
+// type, if set, will be used to check that the decl found in the scope is a match.
+//
+// The optional name is required by languages (like C++) to handle using declarations
+// like:
+//
+// void poo();
+// namespace ns {
+// void foo();
+// void goo();
+// }
+// void bar() {
+// using ns::foo;
+// // CountDeclLevels returns 0 for 'foo', 1 for 'poo', and
+// // LLDB_INVALID_DECL_LEVEL for 'goo'.
+// }
+//
+// The optional type is useful in the case that there's a specific overload
+// that we're looking for that might otherwise be shadowed, like:
+//
+// void foo(int);
+// namespace ns {
+// void foo();
+// }
+// void bar() {
+// using ns::foo;
+// // CountDeclLevels returns 0 for { 'foo', void() },
+// // 1 for { 'foo', void(int) }, and
+// // LLDB_INVALID_DECL_LEVEL for { 'foo', void(int, int) }.
+// }
+//
+// NOTE: Because file statics are at the TranslationUnit along with globals, a
+// function at file scope will return the same level as a function at global scope.
+// Ideally we'd like to treat the file scope as an additional scope just below the
+// global scope. More work needs to be done to recognise that, if the decl we're
+// trying to look up is static, we should compare its source file with that of the
+// current scope and return a lower number for it.
+uint32_t
+ClangASTContext::CountDeclLevels (clang::DeclContext *frame_decl_ctx,
+ clang::DeclContext *child_decl_ctx,
+ ConstString *child_name,
+ CompilerType *child_type)
+{
+ if (frame_decl_ctx)
+ {
+ std::set<DeclContext *> searched;
+ std::multimap<DeclContext *, DeclContext *> search_queue;
+ SymbolFile *symbol_file = GetSymbolFile();
+
+ // Get the lookup scope for the decl we're trying to find.
+ clang::DeclContext *parent_decl_ctx = child_decl_ctx->getParent();
+
+ // Look for it in our scope's decl context and its parents.
+ uint32_t level = 0;
+ for (clang::DeclContext *decl_ctx = frame_decl_ctx; decl_ctx != nullptr; decl_ctx = decl_ctx->getParent())
+ {
+ if (!decl_ctx->isLookupContext())
+ continue;
+ if (decl_ctx == parent_decl_ctx)
+ // Found it!
+ return level;
+ search_queue.insert(std::make_pair(decl_ctx, decl_ctx));
+ for (auto it = search_queue.find(decl_ctx); it != search_queue.end(); it++)
+ {
+ if (searched.find(it->second) != searched.end())
+ continue;
+ searched.insert(it->second);
+ symbol_file->ParseDeclsForContext(CompilerDeclContext(this, it->second));
+
+ for (clang::Decl *child : it->second->decls())
+ {
+ if (clang::UsingDirectiveDecl *ud = llvm::dyn_cast<clang::UsingDirectiveDecl>(child))
+ {
+ clang::DeclContext *ns = ud->getNominatedNamespace();
+ if (ns == parent_decl_ctx)
+ // Found it!
+ return level;
+ clang::DeclContext *from = ud->getCommonAncestor();
+ if (searched.find(ns) == searched.end())
+ search_queue.insert(std::make_pair(from, ns));
+ }
+ else if (child_name)
+ {
+ if (clang::UsingDecl *ud = llvm::dyn_cast<clang::UsingDecl>(child))
+ {
+ for (clang::UsingShadowDecl *usd : ud->shadows())
+ {
+ clang::Decl *target = usd->getTargetDecl();
+ clang::NamedDecl *nd = llvm::dyn_cast<clang::NamedDecl>(target);
+ if (!nd)
+ continue;
+ // Check names.
+ IdentifierInfo *ii = nd->getIdentifier();
+ if (ii == nullptr || !ii->getName().equals(child_name->AsCString(nullptr)))
+ continue;
+ // Check types, if one was provided.
+ if (child_type)
+ {
+ CompilerType clang_type = ClangASTContext::GetTypeForDecl(nd);
+ if (!AreTypesSame(clang_type, *child_type, /*ignore_qualifiers=*/true))
+ continue;
+ }
+ // Found it!
+ return level;
+ }
+ }
+ }
+ }
+ }
+ ++level;
+ }
+ }
+ return LLDB_INVALID_DECL_LEVEL;
+}
+
+bool
+ClangASTContext::DeclContextIsStructUnionOrClass (void *opaque_decl_ctx)
+{
+ if (opaque_decl_ctx)
+ return ((clang::DeclContext *)opaque_decl_ctx)->isRecord();
+ else
+ return false;
+}
+
+ConstString
+ClangASTContext::DeclContextGetName (void *opaque_decl_ctx)
+{
+ if (opaque_decl_ctx)
+ {
+ clang::NamedDecl *named_decl = llvm::dyn_cast<clang::NamedDecl>((clang::DeclContext *)opaque_decl_ctx);
+ if (named_decl)
+ return ConstString(named_decl->getName());
+ }
+ return ConstString();
+}
+
+bool
+ClangASTContext::DeclContextIsClassMethod (void *opaque_decl_ctx,
+ lldb::LanguageType *language_ptr,
+ bool *is_instance_method_ptr,
+ ConstString *language_object_name_ptr)
+{
+ if (opaque_decl_ctx)
+ {
+ clang::DeclContext *decl_ctx = (clang::DeclContext *)opaque_decl_ctx;
+ if (ObjCMethodDecl *objc_method = llvm::dyn_cast<clang::ObjCMethodDecl>(decl_ctx))
+ {
+ if (is_instance_method_ptr)
+ *is_instance_method_ptr = objc_method->isInstanceMethod();
+ if (language_ptr)
+ *language_ptr = eLanguageTypeObjC;
+ if (language_object_name_ptr)
+ language_object_name_ptr->SetCString("self");
+ return true;
+ }
+ else if (CXXMethodDecl *cxx_method = llvm::dyn_cast<clang::CXXMethodDecl>(decl_ctx))
+ {
+ if (is_instance_method_ptr)
+ *is_instance_method_ptr = cxx_method->isInstance();
+ if (language_ptr)
+ *language_ptr = eLanguageTypeC_plus_plus;
+ if (language_object_name_ptr)
+ language_object_name_ptr->SetCString("this");
return true;
}
else if (clang::FunctionDecl *function_decl = llvm::dyn_cast<clang::FunctionDecl>(decl_ctx))
@@ -2195,13 +10003,129 @@ ClangASTContext::GetClassMethodInfoForDeclContext (clang::DeclContext *decl_ctx,
ClangASTMetadata *metadata = GetMetadata (&decl_ctx->getParentASTContext(), function_decl);
if (metadata && metadata->HasObjectPtr())
{
- language_object_name.SetCString (metadata->GetObjectPtrName());
- language = eLanguageTypeObjC;
- is_instance_method = true;
+ if (is_instance_method_ptr)
+ *is_instance_method_ptr = true;
+ if (language_ptr)
+ *language_ptr = eLanguageTypeObjC;
+ if (language_object_name_ptr)
+ language_object_name_ptr->SetCString (metadata->GetObjectPtrName());
+ return true;
}
- return true;
}
}
return false;
}
+clang::DeclContext *
+ClangASTContext::DeclContextGetAsDeclContext (const CompilerDeclContext &dc)
+{
+ if (dc.IsClang())
+ return (clang::DeclContext *)dc.GetOpaqueDeclContext();
+ return nullptr;
+}
+
+
+ObjCMethodDecl *
+ClangASTContext::DeclContextGetAsObjCMethodDecl (const CompilerDeclContext &dc)
+{
+ if (dc.IsClang())
+ return llvm::dyn_cast<clang::ObjCMethodDecl>((clang::DeclContext *)dc.GetOpaqueDeclContext());
+ return nullptr;
+}
+
+CXXMethodDecl *
+ClangASTContext::DeclContextGetAsCXXMethodDecl (const CompilerDeclContext &dc)
+{
+ if (dc.IsClang())
+ return llvm::dyn_cast<clang::CXXMethodDecl>((clang::DeclContext *)dc.GetOpaqueDeclContext());
+ return nullptr;
+}
+
+clang::FunctionDecl *
+ClangASTContext::DeclContextGetAsFunctionDecl (const CompilerDeclContext &dc)
+{
+ if (dc.IsClang())
+ return llvm::dyn_cast<clang::FunctionDecl>((clang::DeclContext *)dc.GetOpaqueDeclContext());
+ return nullptr;
+}
+
+clang::NamespaceDecl *
+ClangASTContext::DeclContextGetAsNamespaceDecl (const CompilerDeclContext &dc)
+{
+ if (dc.IsClang())
+ return llvm::dyn_cast<clang::NamespaceDecl>((clang::DeclContext *)dc.GetOpaqueDeclContext());
+ return nullptr;
+}
+
+ClangASTMetadata *
+ClangASTContext::DeclContextGetMetaData (const CompilerDeclContext &dc, const void *object)
+{
+ clang::ASTContext *ast = DeclContextGetClangASTContext (dc);
+ if (ast)
+ return ClangASTContext::GetMetadata (ast, object);
+ return nullptr;
+}
+
+clang::ASTContext *
+ClangASTContext::DeclContextGetClangASTContext (const CompilerDeclContext &dc)
+{
+ ClangASTContext *ast = llvm::dyn_cast_or_null<ClangASTContext>(dc.GetTypeSystem());
+ if (ast)
+ return ast->getASTContext();
+ return nullptr;
+}
+
+ClangASTContextForExpressions::ClangASTContextForExpressions (Target &target) :
+ ClangASTContext (target.GetArchitecture().GetTriple().getTriple().c_str()),
+ m_target_wp(target.shared_from_this()),
+ m_persistent_variables (new ClangPersistentVariables)
+{
+}
+
+UserExpression *
+ClangASTContextForExpressions::GetUserExpression (const char *expr,
+ const char *expr_prefix,
+ lldb::LanguageType language,
+ Expression::ResultType desired_type,
+ const EvaluateExpressionOptions &options)
+{
+ TargetSP target_sp = m_target_wp.lock();
+ if (!target_sp)
+ return nullptr;
+
+ return new ClangUserExpression(*target_sp.get(), expr, expr_prefix, language, desired_type, options);
+}
+
+FunctionCaller *
+ClangASTContextForExpressions::GetFunctionCaller (const CompilerType &return_type,
+ const Address& function_address,
+ const ValueList &arg_value_list,
+ const char *name)
+{
+ TargetSP target_sp = m_target_wp.lock();
+ if (!target_sp)
+ return nullptr;
+
+ Process *process = target_sp->GetProcessSP().get();
+ if (!process)
+ return nullptr;
+
+ return new ClangFunctionCaller (*process, return_type, function_address, arg_value_list, name);
+}
+
+UtilityFunction *
+ClangASTContextForExpressions::GetUtilityFunction (const char *text,
+ const char *name)
+{
+ TargetSP target_sp = m_target_wp.lock();
+ if (!target_sp)
+ return nullptr;
+
+ return new ClangUtilityFunction(*target_sp.get(), text, name);
+}
+
+PersistentExpressionState *
+ClangASTContextForExpressions::GetPersistentExpressionState ()
+{
+ return m_persistent_variables.get();
+}
diff --git a/source/Symbol/ClangASTImporter.cpp b/source/Symbol/ClangASTImporter.cpp
index dd73b35d86a92..141937072c730 100644
--- a/source/Symbol/ClangASTImporter.cpp
+++ b/source/Symbol/ClangASTImporter.cpp
@@ -16,7 +16,6 @@
#include "lldb/Symbol/ClangASTContext.h"
#include "lldb/Symbol/ClangASTImporter.h"
#include "lldb/Symbol/ClangExternalASTSourceCommon.h"
-#include "lldb/Symbol/ClangNamespaceDecl.h"
#include "lldb/Utility/LLDBAssert.h"
using namespace lldb_private;
@@ -60,14 +59,39 @@ ClangASTImporter::CopyType (clang::ASTContext *dst_ast,
return QualType();
}
-lldb::clang_type_t
+lldb::opaque_compiler_type_t
ClangASTImporter::CopyType (clang::ASTContext *dst_ast,
clang::ASTContext *src_ast,
- lldb::clang_type_t type)
+ lldb::opaque_compiler_type_t type)
{
return CopyType (dst_ast, src_ast, QualType::getFromOpaquePtr(type)).getAsOpaquePtr();
}
+CompilerType
+ClangASTImporter::CopyType (ClangASTContext &dst_ast,
+ const CompilerType &src_type)
+{
+ clang::ASTContext *dst_clang_ast = dst_ast.getASTContext();
+ if (dst_clang_ast)
+ {
+ ClangASTContext *src_ast = llvm::dyn_cast_or_null<ClangASTContext>(src_type.GetTypeSystem());
+ if (src_ast)
+ {
+ clang::ASTContext *src_clang_ast = src_ast->getASTContext();
+ if (src_clang_ast)
+ {
+ lldb::opaque_compiler_type_t dst_clang_type = CopyType(dst_clang_ast,
+ src_clang_ast,
+ src_type.GetOpaqueQualType());
+
+ if (dst_clang_type)
+ return CompilerType(&dst_ast, dst_clang_type);
+ }
+ }
+ }
+ return CompilerType();
+}
+
clang::Decl *
ClangASTImporter::CopyDecl (clang::ASTContext *dst_ast,
clang::ASTContext *src_ast,
@@ -238,11 +262,19 @@ public:
}
};
-lldb::clang_type_t
+lldb::opaque_compiler_type_t
ClangASTImporter::DeportType (clang::ASTContext *dst_ctx,
clang::ASTContext *src_ctx,
- lldb::clang_type_t type)
-{
+ lldb::opaque_compiler_type_t type)
+{
+ Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
+
+ if (log)
+ log->Printf(" [ClangASTImporter] DeportType called on (%sType*)0x%llx from (ASTContext*)%p to (ASTContext*)%p",
+ QualType::getFromOpaquePtr(type)->getTypeClassName(), (unsigned long long)type,
+ static_cast<void*>(src_ctx),
+ static_cast<void*>(dst_ctx));
+
MinionSP minion_sp (GetMinion (dst_ctx, src_ctx));
if (!minion_sp)
@@ -261,7 +293,7 @@ ClangASTImporter::DeportType (clang::ASTContext *dst_ctx,
minion_sp->InitDeportWorkQueues(&decls_to_deport,
&decls_already_deported);
- lldb::clang_type_t result = CopyType(dst_ctx, src_ctx, type);
+ lldb::opaque_compiler_type_t result = CopyType(dst_ctx, src_ctx, type);
minion_sp->ExecuteDeportWorkQueues();
@@ -280,7 +312,7 @@ ClangASTImporter::DeportDecl (clang::ASTContext *dst_ctx,
Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
if (log)
- log->Printf(" [ClangASTImporter] DeportDecl called on (%sDecl*)%p from (ASTContext*)%p to (ASTContex*)%p",
+ log->Printf(" [ClangASTImporter] DeportDecl called on (%sDecl*)%p from (ASTContext*)%p to (ASTContext*)%p",
decl->getDeclKindName(), static_cast<void*>(decl),
static_cast<void*>(src_ctx),
static_cast<void*>(dst_ctx));
@@ -422,6 +454,68 @@ ClangASTImporter::CompleteObjCInterfaceDecl (clang::ObjCInterfaceDecl *interface
}
bool
+ClangASTImporter::CompleteAndFetchChildren (clang::QualType type)
+{
+ if (!RequireCompleteType(type))
+ return false;
+
+ if (const TagType *tag_type = type->getAs<TagType>())
+ {
+ TagDecl *tag_decl = tag_type->getDecl();
+
+ DeclOrigin decl_origin = GetDeclOrigin(tag_decl);
+
+ if (!decl_origin.Valid())
+ return false;
+
+ MinionSP minion_sp (GetMinion(&tag_decl->getASTContext(), decl_origin.ctx));
+
+ TagDecl *origin_tag_decl = llvm::dyn_cast<TagDecl>(decl_origin.decl);
+
+ for (Decl *origin_child_decl : origin_tag_decl->decls())
+ {
+ minion_sp->Import(origin_child_decl);
+ }
+
+ if (RecordDecl *record_decl = dyn_cast<RecordDecl>(origin_tag_decl))
+ {
+ record_decl->setHasLoadedFieldsFromExternalStorage(true);
+ }
+
+ return true;
+ }
+
+ if (const ObjCObjectType *objc_object_type = type->getAs<ObjCObjectType>())
+ {
+ if (ObjCInterfaceDecl *objc_interface_decl = objc_object_type->getInterface())
+ {
+ DeclOrigin decl_origin = GetDeclOrigin(objc_interface_decl);
+
+ if (!decl_origin.Valid())
+ return false;
+
+ MinionSP minion_sp (GetMinion(&objc_interface_decl->getASTContext(), decl_origin.ctx));
+
+ ObjCInterfaceDecl *origin_interface_decl = llvm::dyn_cast<ObjCInterfaceDecl>(decl_origin.decl);
+
+ for (Decl *origin_child_decl : origin_interface_decl->decls())
+ {
+ minion_sp->Import(origin_child_decl);
+ }
+
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+ }
+
+ return true;
+}
+
+
+bool
ClangASTImporter::RequireCompleteType (clang::QualType type)
{
if (type.isNull())
@@ -600,7 +694,7 @@ void
ClangASTImporter::Minion::InitDeportWorkQueues (std::set<clang::NamedDecl *> *decls_to_deport,
std::set<clang::NamedDecl *> *decls_already_deported)
{
- assert(!m_decls_to_deport); // TODO make debug only
+ assert(!m_decls_to_deport);
assert(!m_decls_already_deported);
m_decls_to_deport = decls_to_deport;
@@ -610,7 +704,7 @@ ClangASTImporter::Minion::InitDeportWorkQueues (std::set<clang::NamedDecl *> *de
void
ClangASTImporter::Minion::ExecuteDeportWorkQueues ()
{
- assert(m_decls_to_deport); // TODO make debug only
+ assert(m_decls_to_deport);
assert(m_decls_already_deported);
ASTContextMetadataSP to_context_md = m_master.GetContextMetadata(&getToContext());
@@ -623,6 +717,7 @@ ClangASTImporter::Minion::ExecuteDeportWorkQueues ()
m_decls_to_deport->erase(decl);
DeclOrigin &origin = to_context_md->m_origins[decl];
+ UNUSED_IF_ASSERT_DISABLED(origin);
assert (origin.ctx == m_source_ctx); // otherwise we should never have added this
// because it doesn't need to be deported
@@ -763,7 +858,8 @@ ClangASTImporter::Minion::Imported (clang::Decl *from, clang::Decl *to)
if (to_context_md->m_origins.find(to) == to_context_md->m_origins.end() ||
user_id != LLDB_INVALID_UID)
{
- to_context_md->m_origins[to] = origin_iter->second;
+ if (origin_iter->second.ctx != &to->getASTContext())
+ to_context_md->m_origins[to] = origin_iter->second;
}
MinionSP direct_completer = m_master.GetMinion(&to->getASTContext(), origin_iter->second.ctx);
@@ -784,10 +880,14 @@ ClangASTImporter::Minion::Imported (clang::Decl *from, clang::Decl *to)
{
if (isa<TagDecl>(to) || isa<ObjCInterfaceDecl>(to))
{
- NamedDecl *to_named_decl = dyn_cast<NamedDecl>(to);
-
- if (!m_decls_already_deported->count(to_named_decl))
- m_decls_to_deport->insert(to_named_decl);
+ RecordDecl *from_record_decl = dyn_cast<RecordDecl>(from);
+ if (from_record_decl == nullptr || from_record_decl->isInjectedClassName() == false)
+ {
+ NamedDecl *to_named_decl = dyn_cast<NamedDecl>(to);
+
+ if (!m_decls_already_deported->count(to_named_decl))
+ m_decls_to_deport->insert(to_named_decl);
+ }
}
}
diff --git a/source/Symbol/ClangASTType.cpp b/source/Symbol/ClangASTType.cpp
deleted file mode 100644
index 6f1002fbd9fc4..0000000000000
--- a/source/Symbol/ClangASTType.cpp
+++ /dev/null
@@ -1,7057 +0,0 @@
-//===-- ClangASTType.cpp ----------------------------------------*- C++ -*-===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#include "lldb/Symbol/ClangASTType.h"
-
-#include "clang/AST/ASTConsumer.h"
-#include "clang/AST/ASTContext.h"
-#include "clang/AST/Attr.h"
-#include "clang/AST/CXXInheritance.h"
-#include "clang/AST/Decl.h"
-#include "clang/AST/DeclCXX.h"
-#include "clang/AST/DeclObjC.h"
-#include "clang/AST/DeclGroup.h"
-#include "clang/AST/DeclTemplate.h"
-#include "clang/AST/RecordLayout.h"
-#include "clang/AST/Type.h"
-#include "clang/AST/VTableBuilder.h"
-
-#include "clang/Basic/Builtins.h"
-#include "clang/Basic/IdentifierTable.h"
-#include "clang/Basic/LangOptions.h"
-#include "clang/Basic/SourceManager.h"
-#include "clang/Basic/TargetInfo.h"
-
-#include "llvm/Support/Format.h"
-#include "llvm/Support/Signals.h"
-#include "llvm/Support/FormattedStream.h"
-#include "llvm/Support/raw_ostream.h"
-
-#include "lldb/Core/ConstString.h"
-#include "lldb/Core/DataBufferHeap.h"
-#include "lldb/Core/DataExtractor.h"
-#include "lldb/Core/Debugger.h"
-#include "lldb/Core/Scalar.h"
-#include "lldb/Core/Stream.h"
-#include "lldb/Core/StreamFile.h"
-#include "lldb/Core/StreamString.h"
-#include "lldb/Symbol/ClangASTContext.h"
-#include "lldb/Symbol/ClangExternalASTSourceCommon.h"
-#include "lldb/Symbol/Type.h"
-#include "lldb/Symbol/VerifyDecl.h"
-#include "lldb/Target/ExecutionContext.h"
-#include "lldb/Target/ObjCLanguageRuntime.h"
-#include "lldb/Target/Process.h"
-
-#include <iterator>
-#include <mutex>
-
-using namespace lldb;
-using namespace lldb_private;
-
-static bool
-GetCompleteQualType (clang::ASTContext *ast, clang::QualType qual_type, bool allow_completion = true)
-{
- const clang::Type::TypeClass type_class = qual_type->getTypeClass();
- switch (type_class)
- {
- case clang::Type::ConstantArray:
- case clang::Type::IncompleteArray:
- case clang::Type::VariableArray:
- {
- const clang::ArrayType *array_type = llvm::dyn_cast<clang::ArrayType>(qual_type.getTypePtr());
-
- if (array_type)
- return GetCompleteQualType (ast, array_type->getElementType(), allow_completion);
- }
- break;
-
- case clang::Type::Record:
- case clang::Type::Enum:
- {
- const clang::TagType *tag_type = llvm::dyn_cast<clang::TagType>(qual_type.getTypePtr());
- if (tag_type)
- {
- clang::TagDecl *tag_decl = tag_type->getDecl();
- if (tag_decl)
- {
- if (tag_decl->isCompleteDefinition())
- return true;
-
- if (!allow_completion)
- return false;
-
- if (tag_decl->hasExternalLexicalStorage())
- {
- if (ast)
- {
- clang::ExternalASTSource *external_ast_source = ast->getExternalSource();
- if (external_ast_source)
- {
- external_ast_source->CompleteType(tag_decl);
- return !tag_type->isIncompleteType();
- }
- }
- }
- return false;
- }
- }
-
- }
- break;
-
- case clang::Type::ObjCObject:
- case clang::Type::ObjCInterface:
- {
- const clang::ObjCObjectType *objc_class_type = llvm::dyn_cast<clang::ObjCObjectType>(qual_type);
- if (objc_class_type)
- {
- clang::ObjCInterfaceDecl *class_interface_decl = objc_class_type->getInterface();
- // We currently can't complete objective C types through the newly added ASTContext
- // because it only supports TagDecl objects right now...
- if (class_interface_decl)
- {
- if (class_interface_decl->getDefinition())
- return true;
-
- if (!allow_completion)
- return false;
-
- if (class_interface_decl->hasExternalLexicalStorage())
- {
- if (ast)
- {
- clang::ExternalASTSource *external_ast_source = ast->getExternalSource();
- if (external_ast_source)
- {
- external_ast_source->CompleteType (class_interface_decl);
- return !objc_class_type->isIncompleteType();
- }
- }
- }
- return false;
- }
- }
- }
- break;
-
- case clang::Type::Typedef:
- return GetCompleteQualType (ast, llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType(), allow_completion);
-
- case clang::Type::Elaborated:
- return GetCompleteQualType (ast, llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType(), allow_completion);
-
- case clang::Type::Paren:
- return GetCompleteQualType (ast, llvm::cast<clang::ParenType>(qual_type)->desugar(), allow_completion);
-
- default:
- break;
- }
-
- return true;
-}
-
-static clang::ObjCIvarDecl::AccessControl
-ConvertAccessTypeToObjCIvarAccessControl (AccessType access)
-{
- switch (access)
- {
- case eAccessNone: return clang::ObjCIvarDecl::None;
- case eAccessPublic: return clang::ObjCIvarDecl::Public;
- case eAccessPrivate: return clang::ObjCIvarDecl::Private;
- case eAccessProtected: return clang::ObjCIvarDecl::Protected;
- case eAccessPackage: return clang::ObjCIvarDecl::Package;
- }
- return clang::ObjCIvarDecl::None;
-}
-
-//----------------------------------------------------------------------
-// Tests
-//----------------------------------------------------------------------
-
-ClangASTType::ClangASTType (clang::ASTContext *ast,
- clang::QualType qual_type) :
- m_type (qual_type.getAsOpaquePtr()),
- m_ast (ast)
-{
-}
-
-ClangASTType::~ClangASTType()
-{
-}
-
-//----------------------------------------------------------------------
-// Tests
-//----------------------------------------------------------------------
-
-bool
-ClangASTType::IsAggregateType () const
-{
- if (!IsValid())
- return false;
-
- clang::QualType qual_type (GetCanonicalQualType());
-
- const clang::Type::TypeClass type_class = qual_type->getTypeClass();
- switch (type_class)
- {
- case clang::Type::IncompleteArray:
- case clang::Type::VariableArray:
- case clang::Type::ConstantArray:
- case clang::Type::ExtVector:
- case clang::Type::Vector:
- case clang::Type::Record:
- case clang::Type::ObjCObject:
- case clang::Type::ObjCInterface:
- return true;
- case clang::Type::Elaborated:
- return ClangASTType(m_ast, llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType()).IsAggregateType();
- case clang::Type::Typedef:
- return ClangASTType(m_ast, llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType()).IsAggregateType();
- case clang::Type::Paren:
- return ClangASTType(m_ast, llvm::cast<clang::ParenType>(qual_type)->desugar()).IsAggregateType();
- default:
- break;
- }
- // The clang type does have a value
- return false;
-}
-
-bool
-ClangASTType::IsArrayType (ClangASTType *element_type_ptr,
- uint64_t *size,
- bool *is_incomplete) const
-{
- if (IsValid())
- {
- clang::QualType qual_type (GetCanonicalQualType());
-
- const clang::Type::TypeClass type_class = qual_type->getTypeClass();
- switch (type_class)
- {
- default:
- break;
-
- case clang::Type::ConstantArray:
- if (element_type_ptr)
- element_type_ptr->SetClangType (m_ast, llvm::cast<clang::ConstantArrayType>(qual_type)->getElementType());
- if (size)
- *size = llvm::cast<clang::ConstantArrayType>(qual_type)->getSize().getLimitedValue(ULLONG_MAX);
- return true;
-
- case clang::Type::IncompleteArray:
- if (element_type_ptr)
- element_type_ptr->SetClangType (m_ast, llvm::cast<clang::IncompleteArrayType>(qual_type)->getElementType());
- if (size)
- *size = 0;
- if (is_incomplete)
- *is_incomplete = true;
- return true;
-
- case clang::Type::VariableArray:
- if (element_type_ptr)
- element_type_ptr->SetClangType (m_ast, llvm::cast<clang::VariableArrayType>(qual_type)->getElementType());
- if (size)
- *size = 0;
- return true;
-
- case clang::Type::DependentSizedArray:
- if (element_type_ptr)
- element_type_ptr->SetClangType (m_ast, llvm::cast<clang::DependentSizedArrayType>(qual_type)->getElementType());
- if (size)
- *size = 0;
- return true;
-
- case clang::Type::Typedef:
- return ClangASTType (m_ast, llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType()).IsArrayType (element_type_ptr,
- size,
- is_incomplete);
- case clang::Type::Elaborated:
- return ClangASTType (m_ast, llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType()).IsArrayType (element_type_ptr,
- size,
- is_incomplete);
- case clang::Type::Paren:
- return ClangASTType (m_ast, llvm::cast<clang::ParenType>(qual_type)->desugar()).IsArrayType (element_type_ptr,
- size,
- is_incomplete);
- }
- }
- if (element_type_ptr)
- element_type_ptr->Clear();
- if (size)
- *size = 0;
- if (is_incomplete)
- *is_incomplete = false;
- return 0;
-}
-
-bool
-ClangASTType::IsVectorType (ClangASTType *element_type,
- uint64_t *size) const
-{
- if (IsValid())
- {
- clang::QualType qual_type (GetCanonicalQualType());
-
- const clang::Type::TypeClass type_class = qual_type->getTypeClass();
- switch (type_class)
- {
- case clang::Type::Vector:
- {
- const clang::VectorType *vector_type = qual_type->getAs<clang::VectorType>();
- if (vector_type)
- {
- if (size)
- *size = vector_type->getNumElements();
- if (element_type)
- *element_type = ClangASTType(m_ast, vector_type->getElementType().getAsOpaquePtr());
- }
- return true;
- }
- break;
- case clang::Type::ExtVector:
- {
- const clang::ExtVectorType *ext_vector_type = qual_type->getAs<clang::ExtVectorType>();
- if (ext_vector_type)
- {
- if (size)
- *size = ext_vector_type->getNumElements();
- if (element_type)
- *element_type = ClangASTType(m_ast, ext_vector_type->getElementType().getAsOpaquePtr());
- }
- return true;
- }
- default:
- break;
- }
- }
- return false;
-}
-
-bool
-ClangASTType::IsRuntimeGeneratedType () const
-{
- if (!IsValid())
- return false;
-
- clang::DeclContext* decl_ctx = GetDeclContextForType();
- if (!decl_ctx)
- return false;
-
- if (!llvm::isa<clang::ObjCInterfaceDecl>(decl_ctx))
- return false;
-
- clang::ObjCInterfaceDecl *result_iface_decl = llvm::dyn_cast<clang::ObjCInterfaceDecl>(decl_ctx);
-
- ClangASTMetadata* ast_metadata = ClangASTContext::GetMetadata(m_ast, result_iface_decl);
- if (!ast_metadata)
- return false;
- return (ast_metadata->GetISAPtr() != 0);
-}
-
-bool
-ClangASTType::IsCharType () const
-{
- if (!IsValid())
- return false;
- return GetQualType().getUnqualifiedType()->isCharType();
-}
-
-
-bool
-ClangASTType::IsCompleteType () const
-{
- if (!IsValid())
- return false;
- const bool allow_completion = false;
- return GetCompleteQualType (m_ast, GetQualType(), allow_completion);
-}
-
-bool
-ClangASTType::IsConst() const
-{
- return GetQualType().isConstQualified();
-}
-
-bool
-ClangASTType::IsCStringType (uint32_t &length) const
-{
- ClangASTType pointee_or_element_clang_type;
- length = 0;
- Flags type_flags (GetTypeInfo (&pointee_or_element_clang_type));
-
- if (!pointee_or_element_clang_type.IsValid())
- return false;
-
- if (type_flags.AnySet (eTypeIsArray | eTypeIsPointer))
- {
- if (pointee_or_element_clang_type.IsCharType())
- {
- if (type_flags.Test (eTypeIsArray))
- {
- // We know the size of the array and it could be a C string
- // since it is an array of characters
- length = llvm::cast<clang::ConstantArrayType>(GetCanonicalQualType().getTypePtr())->getSize().getLimitedValue();
- }
- return true;
-
- }
- }
- return false;
-}
-
-bool
-ClangASTType::IsFunctionType (bool *is_variadic_ptr) const
-{
- if (IsValid())
- {
- clang::QualType qual_type (GetCanonicalQualType());
-
- if (qual_type->isFunctionType())
- {
- if (is_variadic_ptr)
- {
- const clang::FunctionProtoType *function_proto_type = llvm::dyn_cast<clang::FunctionProtoType>(qual_type.getTypePtr());
- if (function_proto_type)
- *is_variadic_ptr = function_proto_type->isVariadic();
- else
- *is_variadic_ptr = false;
- }
- return true;
- }
-
- const clang::Type::TypeClass type_class = qual_type->getTypeClass();
- switch (type_class)
- {
- default:
- break;
- case clang::Type::Typedef:
- return ClangASTType (m_ast, llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType()).IsFunctionType();
- case clang::Type::Elaborated:
- return ClangASTType (m_ast, llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType()).IsFunctionType();
- case clang::Type::Paren:
- return ClangASTType (m_ast, llvm::cast<clang::ParenType>(qual_type)->desugar()).IsFunctionType();
-
- case clang::Type::LValueReference:
- case clang::Type::RValueReference:
- {
- const clang::ReferenceType *reference_type = llvm::cast<clang::ReferenceType>(qual_type.getTypePtr());
- if (reference_type)
- return ClangASTType (m_ast, reference_type->getPointeeType()).IsFunctionType();
- }
- break;
- }
- }
- return false;
-}
-
-// Used to detect "Homogeneous Floating-point Aggregates"
-uint32_t
-ClangASTType::IsHomogeneousAggregate (ClangASTType* base_type_ptr) const
-{
- if (!IsValid())
- return 0;
-
- clang::QualType qual_type(GetCanonicalQualType());
- const clang::Type::TypeClass type_class = qual_type->getTypeClass();
- switch (type_class)
- {
- case clang::Type::Record:
- if (GetCompleteType ())
- {
- const clang::CXXRecordDecl *cxx_record_decl = qual_type->getAsCXXRecordDecl();
- if (cxx_record_decl)
- {
- if (cxx_record_decl->getNumBases() ||
- cxx_record_decl->isDynamicClass())
- return 0;
- }
- const clang::RecordType *record_type = llvm::cast<clang::RecordType>(qual_type.getTypePtr());
- if (record_type)
- {
- const clang::RecordDecl *record_decl = record_type->getDecl();
- if (record_decl)
- {
- // We are looking for a structure that contains only floating point types
- clang::RecordDecl::field_iterator field_pos, field_end = record_decl->field_end();
- uint32_t num_fields = 0;
- bool is_hva = false;
- bool is_hfa = false;
- clang::QualType base_qual_type;
- for (field_pos = record_decl->field_begin(); field_pos != field_end; ++field_pos)
- {
- clang::QualType field_qual_type = field_pos->getType();
- if (field_qual_type->isFloatingType())
- {
- if (field_qual_type->isComplexType())
- return 0;
- else
- {
- if (num_fields == 0)
- base_qual_type = field_qual_type;
- else
- {
- if (is_hva)
- return 0;
- is_hfa = true;
- if (field_qual_type.getTypePtr() != base_qual_type.getTypePtr())
- return 0;
- }
- }
- }
- else if (field_qual_type->isVectorType() || field_qual_type->isExtVectorType())
- {
- const clang::VectorType *array = field_qual_type.getTypePtr()->getAs<clang::VectorType>();
- if (array && array->getNumElements() <= 4)
- {
- if (num_fields == 0)
- base_qual_type = array->getElementType();
- else
- {
- if (is_hfa)
- return 0;
- is_hva = true;
- if (field_qual_type.getTypePtr() != base_qual_type.getTypePtr())
- return 0;
- }
- }
- else
- return 0;
- }
- else
- return 0;
- ++num_fields;
- }
- if (base_type_ptr)
- *base_type_ptr = ClangASTType (m_ast, base_qual_type);
- return num_fields;
- }
- }
- }
- break;
-
- case clang::Type::Typedef:
- return ClangASTType(m_ast, llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType()).IsHomogeneousAggregate (base_type_ptr);
-
- case clang::Type::Elaborated:
- return ClangASTType(m_ast, llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType()).IsHomogeneousAggregate (base_type_ptr);
- default:
- break;
- }
- return 0;
-}
-
-size_t
-ClangASTType::GetNumberOfFunctionArguments () const
-{
- if (IsValid())
- {
- clang::QualType qual_type (GetCanonicalQualType());
- const clang::FunctionProtoType* func = llvm::dyn_cast<clang::FunctionProtoType>(qual_type.getTypePtr());
- if (func)
- return func->getNumParams();
- }
- return 0;
-}
-
-ClangASTType
-ClangASTType::GetFunctionArgumentAtIndex (const size_t index) const
-{
- if (IsValid())
- {
- clang::QualType qual_type (GetCanonicalQualType());
- const clang::FunctionProtoType* func = llvm::dyn_cast<clang::FunctionProtoType>(qual_type.getTypePtr());
- if (func)
- {
- if (index < func->getNumParams())
- return ClangASTType(m_ast, func->getParamType(index).getAsOpaquePtr());
- }
- }
- return ClangASTType();
-}
-
-bool
-ClangASTType::IsFunctionPointerType () const
-{
- if (IsValid())
- {
- clang::QualType qual_type (GetCanonicalQualType());
-
- if (qual_type->isFunctionPointerType())
- return true;
-
- const clang::Type::TypeClass type_class = qual_type->getTypeClass();
- switch (type_class)
- {
- default:
- break;
- case clang::Type::Typedef:
- return ClangASTType (m_ast, llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType()).IsFunctionPointerType();
- case clang::Type::Elaborated:
- return ClangASTType (m_ast, llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType()).IsFunctionPointerType();
- case clang::Type::Paren:
- return ClangASTType (m_ast, llvm::cast<clang::ParenType>(qual_type)->desugar()).IsFunctionPointerType();
-
- case clang::Type::LValueReference:
- case clang::Type::RValueReference:
- {
- const clang::ReferenceType *reference_type = llvm::cast<clang::ReferenceType>(qual_type.getTypePtr());
- if (reference_type)
- return ClangASTType (m_ast, reference_type->getPointeeType()).IsFunctionPointerType();
- }
- break;
- }
- }
- return false;
-
-}
-
-bool
-ClangASTType::IsIntegerType (bool &is_signed) const
-{
- if (!IsValid())
- return false;
-
- clang::QualType qual_type (GetCanonicalQualType());
- const clang::BuiltinType *builtin_type = llvm::dyn_cast<clang::BuiltinType>(qual_type->getCanonicalTypeInternal());
-
- if (builtin_type)
- {
- if (builtin_type->isInteger())
- {
- is_signed = builtin_type->isSignedInteger();
- return true;
- }
- }
-
- return false;
-}
-
-bool
-ClangASTType::IsPointerType (ClangASTType *pointee_type) const
-{
- if (IsValid())
- {
- clang::QualType qual_type (GetCanonicalQualType());
- const clang::Type::TypeClass type_class = qual_type->getTypeClass();
- switch (type_class)
- {
- case clang::Type::Builtin:
- switch (llvm::cast<clang::BuiltinType>(qual_type)->getKind())
- {
- default:
- break;
- case clang::BuiltinType::ObjCId:
- case clang::BuiltinType::ObjCClass:
- return true;
- }
- return false;
- case clang::Type::ObjCObjectPointer:
- if (pointee_type)
- pointee_type->SetClangType (m_ast, llvm::cast<clang::ObjCObjectPointerType>(qual_type)->getPointeeType());
- return true;
- case clang::Type::BlockPointer:
- if (pointee_type)
- pointee_type->SetClangType (m_ast, llvm::cast<clang::BlockPointerType>(qual_type)->getPointeeType());
- return true;
- case clang::Type::Pointer:
- if (pointee_type)
- pointee_type->SetClangType (m_ast, llvm::cast<clang::PointerType>(qual_type)->getPointeeType());
- return true;
- case clang::Type::MemberPointer:
- if (pointee_type)
- pointee_type->SetClangType (m_ast, llvm::cast<clang::MemberPointerType>(qual_type)->getPointeeType());
- return true;
- case clang::Type::Typedef:
- return ClangASTType (m_ast, llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType()).IsPointerType(pointee_type);
- case clang::Type::Elaborated:
- return ClangASTType (m_ast, llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType()).IsPointerType(pointee_type);
- case clang::Type::Paren:
- return ClangASTType (m_ast, llvm::cast<clang::ParenType>(qual_type)->desugar()).IsPointerType(pointee_type);
- default:
- break;
- }
- }
- if (pointee_type)
- pointee_type->Clear();
- return false;
-}
-
-
-bool
-ClangASTType::IsPointerOrReferenceType (ClangASTType *pointee_type) const
-{
- if (IsValid())
- {
- clang::QualType qual_type (GetCanonicalQualType());
- const clang::Type::TypeClass type_class = qual_type->getTypeClass();
- switch (type_class)
- {
- case clang::Type::Builtin:
- switch (llvm::cast<clang::BuiltinType>(qual_type)->getKind())
- {
- default:
- break;
- case clang::BuiltinType::ObjCId:
- case clang::BuiltinType::ObjCClass:
- return true;
- }
- return false;
- case clang::Type::ObjCObjectPointer:
- if (pointee_type)
- pointee_type->SetClangType(m_ast, llvm::cast<clang::ObjCObjectPointerType>(qual_type)->getPointeeType());
- return true;
- case clang::Type::BlockPointer:
- if (pointee_type)
- pointee_type->SetClangType(m_ast, llvm::cast<clang::BlockPointerType>(qual_type)->getPointeeType());
- return true;
- case clang::Type::Pointer:
- if (pointee_type)
- pointee_type->SetClangType(m_ast, llvm::cast<clang::PointerType>(qual_type)->getPointeeType());
- return true;
- case clang::Type::MemberPointer:
- if (pointee_type)
- pointee_type->SetClangType(m_ast, llvm::cast<clang::MemberPointerType>(qual_type)->getPointeeType());
- return true;
- case clang::Type::LValueReference:
- if (pointee_type)
- pointee_type->SetClangType(m_ast, llvm::cast<clang::LValueReferenceType>(qual_type)->desugar());
- return true;
- case clang::Type::RValueReference:
- if (pointee_type)
- pointee_type->SetClangType(m_ast, llvm::cast<clang::RValueReferenceType>(qual_type)->desugar());
- return true;
- case clang::Type::Typedef:
- return ClangASTType (m_ast, llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType()).IsPointerOrReferenceType(pointee_type);
- case clang::Type::Elaborated:
- return ClangASTType (m_ast, llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType()).IsPointerOrReferenceType(pointee_type);
- case clang::Type::Paren:
- return ClangASTType (m_ast, llvm::cast<clang::ParenType>(qual_type)->desugar()).IsPointerOrReferenceType(pointee_type);
- default:
- break;
- }
- }
- if (pointee_type)
- pointee_type->Clear();
- return false;
-}
-
-
-bool
-ClangASTType::IsReferenceType (ClangASTType *pointee_type, bool* is_rvalue) const
-{
- if (IsValid())
- {
- clang::QualType qual_type (GetCanonicalQualType());
- const clang::Type::TypeClass type_class = qual_type->getTypeClass();
-
- switch (type_class)
- {
- case clang::Type::LValueReference:
- if (pointee_type)
- pointee_type->SetClangType(m_ast, llvm::cast<clang::LValueReferenceType>(qual_type)->desugar());
- if (is_rvalue)
- *is_rvalue = false;
- return true;
- case clang::Type::RValueReference:
- if (pointee_type)
- pointee_type->SetClangType(m_ast, llvm::cast<clang::RValueReferenceType>(qual_type)->desugar());
- if (is_rvalue)
- *is_rvalue = true;
- return true;
- case clang::Type::Typedef:
- return ClangASTType(m_ast, llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType()).IsReferenceType(pointee_type, is_rvalue);
- case clang::Type::Elaborated:
- return ClangASTType(m_ast, llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType()).IsReferenceType(pointee_type, is_rvalue);
- case clang::Type::Paren:
- return ClangASTType(m_ast, llvm::cast<clang::ParenType>(qual_type)->desugar()).IsReferenceType(pointee_type, is_rvalue);
-
- default:
- break;
- }
- }
- if (pointee_type)
- pointee_type->Clear();
- return false;
-}
-
-bool
-ClangASTType::IsFloatingPointType (uint32_t &count, bool &is_complex) const
-{
- if (IsValid())
- {
- clang::QualType qual_type (GetCanonicalQualType());
-
- if (const clang::BuiltinType *BT = llvm::dyn_cast<clang::BuiltinType>(qual_type->getCanonicalTypeInternal()))
- {
- clang::BuiltinType::Kind kind = BT->getKind();
- if (kind >= clang::BuiltinType::Float && kind <= clang::BuiltinType::LongDouble)
- {
- count = 1;
- is_complex = false;
- return true;
- }
- }
- else if (const clang::ComplexType *CT = llvm::dyn_cast<clang::ComplexType>(qual_type->getCanonicalTypeInternal()))
- {
- if (ClangASTType (m_ast, CT->getElementType()).IsFloatingPointType (count, is_complex))
- {
- count = 2;
- is_complex = true;
- return true;
- }
- }
- else if (const clang::VectorType *VT = llvm::dyn_cast<clang::VectorType>(qual_type->getCanonicalTypeInternal()))
- {
- if (ClangASTType (m_ast, VT->getElementType()).IsFloatingPointType (count, is_complex))
- {
- count = VT->getNumElements();
- is_complex = false;
- return true;
- }
- }
- }
- count = 0;
- is_complex = false;
- return false;
-}
-
-
-bool
-ClangASTType::IsDefined() const
-{
- if (!IsValid())
- return false;
-
- clang::QualType qual_type(GetQualType());
- const clang::TagType *tag_type = llvm::dyn_cast<clang::TagType>(qual_type.getTypePtr());
- if (tag_type)
- {
- clang::TagDecl *tag_decl = tag_type->getDecl();
- if (tag_decl)
- return tag_decl->isCompleteDefinition();
- return false;
- }
- else
- {
- const clang::ObjCObjectType *objc_class_type = llvm::dyn_cast<clang::ObjCObjectType>(qual_type);
- if (objc_class_type)
- {
- clang::ObjCInterfaceDecl *class_interface_decl = objc_class_type->getInterface();
- if (class_interface_decl)
- return class_interface_decl->getDefinition() != nullptr;
- return false;
- }
- }
- return true;
-}
-
-bool
-ClangASTType::IsObjCClassType () const
-{
- if (IsValid())
- {
- clang::QualType qual_type (GetCanonicalQualType());
-
- const clang::ObjCObjectPointerType *obj_pointer_type = llvm::dyn_cast<clang::ObjCObjectPointerType>(qual_type);
-
- if (obj_pointer_type)
- return obj_pointer_type->isObjCClassType();
- }
- return false;
-}
-
-bool
-ClangASTType::IsObjCObjectOrInterfaceType () const
-{
- if (IsValid())
- return GetCanonicalQualType()->isObjCObjectOrInterfaceType();
- return false;
-}
-
-bool
-ClangASTType::IsPolymorphicClass () const
-{
- if (IsValid())
- {
- clang::QualType qual_type(GetCanonicalQualType());
- const clang::Type::TypeClass type_class = qual_type->getTypeClass();
- switch (type_class)
- {
- case clang::Type::Record:
- if (GetCompleteType())
- {
- const clang::RecordType *record_type = llvm::cast<clang::RecordType>(qual_type.getTypePtr());
- const clang::RecordDecl *record_decl = record_type->getDecl();
- if (record_decl)
- {
- const clang::CXXRecordDecl *cxx_record_decl = llvm::dyn_cast<clang::CXXRecordDecl>(record_decl);
- if (cxx_record_decl)
- return cxx_record_decl->isPolymorphic();
- }
- }
- break;
-
- default:
- break;
- }
- }
- return false;
-}
-
-bool
-ClangASTType::IsPossibleDynamicType (ClangASTType *dynamic_pointee_type,
- bool check_cplusplus,
- bool check_objc) const
-{
- clang::QualType pointee_qual_type;
- if (m_type)
- {
- clang::QualType qual_type (GetCanonicalQualType());
- bool success = false;
- const clang::Type::TypeClass type_class = qual_type->getTypeClass();
- switch (type_class)
- {
- case clang::Type::Builtin:
- if (check_objc && llvm::cast<clang::BuiltinType>(qual_type)->getKind() == clang::BuiltinType::ObjCId)
- {
- if (dynamic_pointee_type)
- dynamic_pointee_type->SetClangType(m_ast, m_type);
- return true;
- }
- break;
-
- case clang::Type::ObjCObjectPointer:
- if (check_objc)
- {
- if (dynamic_pointee_type)
- dynamic_pointee_type->SetClangType(m_ast, llvm::cast<clang::ObjCObjectPointerType>(qual_type)->getPointeeType());
- return true;
- }
- break;
-
- case clang::Type::Pointer:
- pointee_qual_type = llvm::cast<clang::PointerType>(qual_type)->getPointeeType();
- success = true;
- break;
-
- case clang::Type::LValueReference:
- case clang::Type::RValueReference:
- pointee_qual_type = llvm::cast<clang::ReferenceType>(qual_type)->getPointeeType();
- success = true;
- break;
-
- case clang::Type::Typedef:
- return ClangASTType (m_ast,
- llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType()).IsPossibleDynamicType (dynamic_pointee_type,
- check_cplusplus,
- check_objc);
-
- case clang::Type::Elaborated:
- return ClangASTType (m_ast,
- llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType()).IsPossibleDynamicType (dynamic_pointee_type,
- check_cplusplus,
- check_objc);
-
- case clang::Type::Paren:
- return ClangASTType (m_ast,
- llvm::cast<clang::ParenType>(qual_type)->desugar()).IsPossibleDynamicType (dynamic_pointee_type,
- check_cplusplus,
- check_objc);
- default:
- break;
- }
-
- if (success)
- {
- // Check to make sure what we are pointing too is a possible dynamic C++ type
- // We currently accept any "void *" (in case we have a class that has been
- // watered down to an opaque pointer) and virtual C++ classes.
- const clang::Type::TypeClass pointee_type_class = pointee_qual_type.getCanonicalType()->getTypeClass();
- switch (pointee_type_class)
- {
- case clang::Type::Builtin:
- switch (llvm::cast<clang::BuiltinType>(pointee_qual_type)->getKind())
- {
- case clang::BuiltinType::UnknownAny:
- case clang::BuiltinType::Void:
- if (dynamic_pointee_type)
- dynamic_pointee_type->SetClangType(m_ast, pointee_qual_type);
- return true;
-
- case clang::BuiltinType::NullPtr:
- case clang::BuiltinType::Bool:
- case clang::BuiltinType::Char_U:
- case clang::BuiltinType::UChar:
- case clang::BuiltinType::WChar_U:
- case clang::BuiltinType::Char16:
- case clang::BuiltinType::Char32:
- case clang::BuiltinType::UShort:
- case clang::BuiltinType::UInt:
- case clang::BuiltinType::ULong:
- case clang::BuiltinType::ULongLong:
- case clang::BuiltinType::UInt128:
- case clang::BuiltinType::Char_S:
- case clang::BuiltinType::SChar:
- case clang::BuiltinType::WChar_S:
- case clang::BuiltinType::Short:
- case clang::BuiltinType::Int:
- case clang::BuiltinType::Long:
- case clang::BuiltinType::LongLong:
- case clang::BuiltinType::Int128:
- case clang::BuiltinType::Float:
- case clang::BuiltinType::Double:
- case clang::BuiltinType::LongDouble:
- case clang::BuiltinType::Dependent:
- case clang::BuiltinType::Overload:
- case clang::BuiltinType::ObjCId:
- case clang::BuiltinType::ObjCClass:
- case clang::BuiltinType::ObjCSel:
- case clang::BuiltinType::BoundMember:
- case clang::BuiltinType::Half:
- case clang::BuiltinType::ARCUnbridgedCast:
- case clang::BuiltinType::PseudoObject:
- case clang::BuiltinType::BuiltinFn:
- case clang::BuiltinType::OCLEvent:
- case clang::BuiltinType::OCLImage1d:
- case clang::BuiltinType::OCLImage1dArray:
- case clang::BuiltinType::OCLImage1dBuffer:
- case clang::BuiltinType::OCLImage2d:
- case clang::BuiltinType::OCLImage2dArray:
- case clang::BuiltinType::OCLImage3d:
- case clang::BuiltinType::OCLSampler:
- break;
- }
- break;
-
- case clang::Type::Record:
- if (check_cplusplus)
- {
- clang::CXXRecordDecl *cxx_record_decl = pointee_qual_type->getAsCXXRecordDecl();
- if (cxx_record_decl)
- {
- bool is_complete = cxx_record_decl->isCompleteDefinition();
-
- if (is_complete)
- success = cxx_record_decl->isDynamicClass();
- else
- {
- ClangASTMetadata *metadata = ClangASTContext::GetMetadata (m_ast, cxx_record_decl);
- if (metadata)
- success = metadata->GetIsDynamicCXXType();
- else
- {
- is_complete = ClangASTType(m_ast, pointee_qual_type).GetCompleteType();
- if (is_complete)
- success = cxx_record_decl->isDynamicClass();
- else
- success = false;
- }
- }
-
- if (success)
- {
- if (dynamic_pointee_type)
- dynamic_pointee_type->SetClangType(m_ast, pointee_qual_type);
- return true;
- }
- }
- }
- break;
-
- case clang::Type::ObjCObject:
- case clang::Type::ObjCInterface:
- if (check_objc)
- {
- if (dynamic_pointee_type)
- dynamic_pointee_type->SetClangType(m_ast, pointee_qual_type);
- return true;
- }
- break;
-
- default:
- break;
- }
- }
- }
- if (dynamic_pointee_type)
- dynamic_pointee_type->Clear();
- return false;
-}
-
-
-bool
-ClangASTType::IsScalarType () const
-{
- if (!IsValid())
- return false;
-
- return (GetTypeInfo (nullptr) & eTypeIsScalar) != 0;
-}
-
-bool
-ClangASTType::IsTypedefType () const
-{
- if (!IsValid())
- return false;
- return GetQualType()->getTypeClass() == clang::Type::Typedef;
-}
-
-bool
-ClangASTType::IsVoidType () const
-{
- if (!IsValid())
- return false;
- return GetCanonicalQualType()->isVoidType();
-}
-
-bool
-ClangASTType::IsPointerToScalarType () const
-{
- if (!IsValid())
- return false;
-
- return IsPointerType() && GetPointeeType().IsScalarType();
-}
-
-bool
-ClangASTType::IsArrayOfScalarType () const
-{
- ClangASTType element_type;
- if (IsArrayType(&element_type, nullptr, nullptr))
- return element_type.IsScalarType();
- return false;
-}
-
-
-bool
-ClangASTType::GetCXXClassName (std::string &class_name) const
-{
- if (IsValid())
- {
- clang::QualType qual_type (GetCanonicalQualType());
-
- clang::CXXRecordDecl *cxx_record_decl = qual_type->getAsCXXRecordDecl();
- if (cxx_record_decl)
- {
- class_name.assign (cxx_record_decl->getIdentifier()->getNameStart());
- return true;
- }
- }
- class_name.clear();
- return false;
-}
-
-
-bool
-ClangASTType::IsCXXClassType () const
-{
- if (!IsValid())
- return false;
-
- clang::QualType qual_type (GetCanonicalQualType());
- if (qual_type->getAsCXXRecordDecl() != nullptr)
- return true;
- return false;
-}
-
-bool
-ClangASTType::IsBeingDefined () const
-{
- if (!IsValid())
- return false;
- clang::QualType qual_type (GetCanonicalQualType());
- const clang::TagType *tag_type = llvm::dyn_cast<clang::TagType>(qual_type);
- if (tag_type)
- return tag_type->isBeingDefined();
- return false;
-}
-
-bool
-ClangASTType::IsObjCObjectPointerType (ClangASTType *class_type_ptr)
-{
- if (!IsValid())
- return false;
-
- clang::QualType qual_type (GetCanonicalQualType());
-
- if (qual_type->isObjCObjectPointerType())
- {
- if (class_type_ptr)
- {
- if (!qual_type->isObjCClassType() &&
- !qual_type->isObjCIdType())
- {
- const clang::ObjCObjectPointerType *obj_pointer_type = llvm::dyn_cast<clang::ObjCObjectPointerType>(qual_type);
- if (obj_pointer_type == nullptr)
- class_type_ptr->Clear();
- else
- class_type_ptr->SetClangType (m_ast, clang::QualType(obj_pointer_type->getInterfaceType(), 0));
- }
- }
- return true;
- }
- if (class_type_ptr)
- class_type_ptr->Clear();
- return false;
-}
-
-bool
-ClangASTType::GetObjCClassName (std::string &class_name)
-{
- if (!IsValid())
- return false;
-
- clang::QualType qual_type (GetCanonicalQualType());
-
- const clang::ObjCObjectType *object_type = llvm::dyn_cast<clang::ObjCObjectType>(qual_type);
- if (object_type)
- {
- const clang::ObjCInterfaceDecl *interface = object_type->getInterface();
- if (interface)
- {
- class_name = interface->getNameAsString();
- return true;
- }
- }
- return false;
-}
-
-
-//----------------------------------------------------------------------
-// Type Completion
-//----------------------------------------------------------------------
-
-bool
-ClangASTType::GetCompleteType () const
-{
- if (!IsValid())
- return false;
- const bool allow_completion = true;
- return GetCompleteQualType (m_ast, GetQualType(), allow_completion);
-}
-
-//----------------------------------------------------------------------
-// AST related queries
-//----------------------------------------------------------------------
-size_t
-ClangASTType::GetPointerByteSize () const
-{
- if (m_ast)
- return m_ast->getTypeSize(m_ast->VoidPtrTy) / 8;
- return 0;
-}
-
-ConstString
-ClangASTType::GetConstQualifiedTypeName () const
-{
- return GetConstTypeName ();
-}
-
-ConstString
-ClangASTType::GetConstTypeName () const
-{
- if (IsValid())
- {
- ConstString type_name (GetTypeName());
- if (type_name)
- return type_name;
- }
- return ConstString("<invalid>");
-}
-
-ConstString
-ClangASTType::GetTypeName () const
-{
- std::string type_name;
- if (IsValid())
- {
- clang::PrintingPolicy printing_policy (m_ast->getPrintingPolicy());
- clang::QualType qual_type(GetQualType());
- printing_policy.SuppressTagKeyword = true;
- printing_policy.LangOpts.WChar = true;
- const clang::TypedefType *typedef_type = qual_type->getAs<clang::TypedefType>();
- if (typedef_type)
- {
- const clang::TypedefNameDecl *typedef_decl = typedef_type->getDecl();
- type_name = typedef_decl->getQualifiedNameAsString();
- }
- else
- {
- type_name = qual_type.getAsString(printing_policy);
- }
- }
- return ConstString(type_name);
-}
-
-ConstString
-ClangASTType::GetDisplayTypeName () const
-{
- return GetTypeName();
-}
-
-uint32_t
-ClangASTType::GetTypeInfo (ClangASTType *pointee_or_element_clang_type) const
-{
- if (!IsValid())
- return 0;
-
- if (pointee_or_element_clang_type)
- pointee_or_element_clang_type->Clear();
-
- clang::QualType qual_type (GetQualType());
-
- const clang::Type::TypeClass type_class = qual_type->getTypeClass();
- switch (type_class)
- {
- case clang::Type::Builtin:
- {
- const clang::BuiltinType *builtin_type = llvm::dyn_cast<clang::BuiltinType>(qual_type->getCanonicalTypeInternal());
-
- uint32_t builtin_type_flags = eTypeIsBuiltIn | eTypeHasValue;
- switch (builtin_type->getKind())
- {
- case clang::BuiltinType::ObjCId:
- case clang::BuiltinType::ObjCClass:
- if (pointee_or_element_clang_type)
- pointee_or_element_clang_type->SetClangType(m_ast, m_ast->ObjCBuiltinClassTy);
- builtin_type_flags |= eTypeIsPointer | eTypeIsObjC;
- break;
-
- case clang::BuiltinType::ObjCSel:
- if (pointee_or_element_clang_type)
- pointee_or_element_clang_type->SetClangType(m_ast, m_ast->CharTy);
- builtin_type_flags |= eTypeIsPointer | eTypeIsObjC;
- break;
-
- case clang::BuiltinType::Bool:
- case clang::BuiltinType::Char_U:
- case clang::BuiltinType::UChar:
- case clang::BuiltinType::WChar_U:
- case clang::BuiltinType::Char16:
- case clang::BuiltinType::Char32:
- case clang::BuiltinType::UShort:
- case clang::BuiltinType::UInt:
- case clang::BuiltinType::ULong:
- case clang::BuiltinType::ULongLong:
- case clang::BuiltinType::UInt128:
- case clang::BuiltinType::Char_S:
- case clang::BuiltinType::SChar:
- case clang::BuiltinType::WChar_S:
- case clang::BuiltinType::Short:
- case clang::BuiltinType::Int:
- case clang::BuiltinType::Long:
- case clang::BuiltinType::LongLong:
- case clang::BuiltinType::Int128:
- case clang::BuiltinType::Float:
- case clang::BuiltinType::Double:
- case clang::BuiltinType::LongDouble:
- builtin_type_flags |= eTypeIsScalar;
- if (builtin_type->isInteger())
- {
- builtin_type_flags |= eTypeIsInteger;
- if (builtin_type->isSignedInteger())
- builtin_type_flags |= eTypeIsSigned;
- }
- else if (builtin_type->isFloatingPoint())
- builtin_type_flags |= eTypeIsFloat;
- break;
- default:
- break;
- }
- return builtin_type_flags;
- }
-
- case clang::Type::BlockPointer:
- if (pointee_or_element_clang_type)
- pointee_or_element_clang_type->SetClangType(m_ast, qual_type->getPointeeType());
- return eTypeIsPointer | eTypeHasChildren | eTypeIsBlock;
-
- case clang::Type::Complex:
- {
- uint32_t complex_type_flags = eTypeIsBuiltIn | eTypeHasValue | eTypeIsComplex;
- const clang::ComplexType *complex_type = llvm::dyn_cast<clang::ComplexType>(qual_type->getCanonicalTypeInternal());
- if (complex_type)
- {
- clang::QualType complex_element_type (complex_type->getElementType());
- if (complex_element_type->isIntegerType())
- complex_type_flags |= eTypeIsFloat;
- else if (complex_element_type->isFloatingType())
- complex_type_flags |= eTypeIsInteger;
- }
- return complex_type_flags;
- }
- break;
-
- case clang::Type::ConstantArray:
- case clang::Type::DependentSizedArray:
- case clang::Type::IncompleteArray:
- case clang::Type::VariableArray:
- if (pointee_or_element_clang_type)
- pointee_or_element_clang_type->SetClangType(m_ast, llvm::cast<clang::ArrayType>(qual_type.getTypePtr())->getElementType());
- return eTypeHasChildren | eTypeIsArray;
-
- case clang::Type::DependentName: return 0;
- case clang::Type::DependentSizedExtVector: return eTypeHasChildren | eTypeIsVector;
- case clang::Type::DependentTemplateSpecialization: return eTypeIsTemplate;
- case clang::Type::Decltype: return 0;
-
- case clang::Type::Enum:
- if (pointee_or_element_clang_type)
- pointee_or_element_clang_type->SetClangType(m_ast, llvm::cast<clang::EnumType>(qual_type)->getDecl()->getIntegerType());
- return eTypeIsEnumeration | eTypeHasValue;
-
- case clang::Type::Elaborated:
- return ClangASTType (m_ast, llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType()).GetTypeInfo (pointee_or_element_clang_type);
- case clang::Type::Paren:
- return ClangASTType (m_ast, llvm::cast<clang::ParenType>(qual_type)->desugar()).GetTypeInfo (pointee_or_element_clang_type);
-
- case clang::Type::FunctionProto: return eTypeIsFuncPrototype | eTypeHasValue;
- case clang::Type::FunctionNoProto: return eTypeIsFuncPrototype | eTypeHasValue;
- case clang::Type::InjectedClassName: return 0;
-
- case clang::Type::LValueReference:
- case clang::Type::RValueReference:
- if (pointee_or_element_clang_type)
- pointee_or_element_clang_type->SetClangType(m_ast, llvm::cast<clang::ReferenceType>(qual_type.getTypePtr())->getPointeeType());
- return eTypeHasChildren | eTypeIsReference | eTypeHasValue;
-
- case clang::Type::MemberPointer: return eTypeIsPointer | eTypeIsMember | eTypeHasValue;
-
- case clang::Type::ObjCObjectPointer:
- if (pointee_or_element_clang_type)
- pointee_or_element_clang_type->SetClangType(m_ast, qual_type->getPointeeType());
- return eTypeHasChildren | eTypeIsObjC | eTypeIsClass | eTypeIsPointer | eTypeHasValue;
-
- case clang::Type::ObjCObject: return eTypeHasChildren | eTypeIsObjC | eTypeIsClass;
- case clang::Type::ObjCInterface: return eTypeHasChildren | eTypeIsObjC | eTypeIsClass;
-
- case clang::Type::Pointer:
- if (pointee_or_element_clang_type)
- pointee_or_element_clang_type->SetClangType(m_ast, qual_type->getPointeeType());
- return eTypeHasChildren | eTypeIsPointer | eTypeHasValue;
-
- case clang::Type::Record:
- if (qual_type->getAsCXXRecordDecl())
- return eTypeHasChildren | eTypeIsClass | eTypeIsCPlusPlus;
- else
- return eTypeHasChildren | eTypeIsStructUnion;
- break;
- case clang::Type::SubstTemplateTypeParm: return eTypeIsTemplate;
- case clang::Type::TemplateTypeParm: return eTypeIsTemplate;
- case clang::Type::TemplateSpecialization: return eTypeIsTemplate;
-
- case clang::Type::Typedef:
- return eTypeIsTypedef | ClangASTType (m_ast, llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType()).GetTypeInfo (pointee_or_element_clang_type);
- case clang::Type::TypeOfExpr: return 0;
- case clang::Type::TypeOf: return 0;
- case clang::Type::UnresolvedUsing: return 0;
-
- case clang::Type::ExtVector:
- case clang::Type::Vector:
- {
- uint32_t vector_type_flags = eTypeHasChildren | eTypeIsVector;
- const clang::VectorType *vector_type = llvm::dyn_cast<clang::VectorType>(qual_type->getCanonicalTypeInternal());
- if (vector_type)
- {
- if (vector_type->isIntegerType())
- vector_type_flags |= eTypeIsFloat;
- else if (vector_type->isFloatingType())
- vector_type_flags |= eTypeIsInteger;
- }
- return vector_type_flags;
- }
- default: return 0;
- }
- return 0;
-}
-
-
-
-lldb::LanguageType
-ClangASTType::GetMinimumLanguage ()
-{
- if (!IsValid())
- return lldb::eLanguageTypeC;
-
- // If the type is a reference, then resolve it to what it refers to first:
- clang::QualType qual_type (GetCanonicalQualType().getNonReferenceType());
- if (qual_type->isAnyPointerType())
- {
- if (qual_type->isObjCObjectPointerType())
- return lldb::eLanguageTypeObjC;
-
- clang::QualType pointee_type (qual_type->getPointeeType());
- if (pointee_type->getPointeeCXXRecordDecl() != nullptr)
- return lldb::eLanguageTypeC_plus_plus;
- if (pointee_type->isObjCObjectOrInterfaceType())
- return lldb::eLanguageTypeObjC;
- if (pointee_type->isObjCClassType())
- return lldb::eLanguageTypeObjC;
- if (pointee_type.getTypePtr() == m_ast->ObjCBuiltinIdTy.getTypePtr())
- return lldb::eLanguageTypeObjC;
- }
- else
- {
- if (qual_type->isObjCObjectOrInterfaceType())
- return lldb::eLanguageTypeObjC;
- if (qual_type->getAsCXXRecordDecl())
- return lldb::eLanguageTypeC_plus_plus;
- switch (qual_type->getTypeClass())
- {
- default:
- break;
- case clang::Type::Builtin:
- switch (llvm::cast<clang::BuiltinType>(qual_type)->getKind())
- {
- default:
- case clang::BuiltinType::Void:
- case clang::BuiltinType::Bool:
- case clang::BuiltinType::Char_U:
- case clang::BuiltinType::UChar:
- case clang::BuiltinType::WChar_U:
- case clang::BuiltinType::Char16:
- case clang::BuiltinType::Char32:
- case clang::BuiltinType::UShort:
- case clang::BuiltinType::UInt:
- case clang::BuiltinType::ULong:
- case clang::BuiltinType::ULongLong:
- case clang::BuiltinType::UInt128:
- case clang::BuiltinType::Char_S:
- case clang::BuiltinType::SChar:
- case clang::BuiltinType::WChar_S:
- case clang::BuiltinType::Short:
- case clang::BuiltinType::Int:
- case clang::BuiltinType::Long:
- case clang::BuiltinType::LongLong:
- case clang::BuiltinType::Int128:
- case clang::BuiltinType::Float:
- case clang::BuiltinType::Double:
- case clang::BuiltinType::LongDouble:
- break;
-
- case clang::BuiltinType::NullPtr:
- return eLanguageTypeC_plus_plus;
-
- case clang::BuiltinType::ObjCId:
- case clang::BuiltinType::ObjCClass:
- case clang::BuiltinType::ObjCSel:
- return eLanguageTypeObjC;
-
- case clang::BuiltinType::Dependent:
- case clang::BuiltinType::Overload:
- case clang::BuiltinType::BoundMember:
- case clang::BuiltinType::UnknownAny:
- break;
- }
- break;
- case clang::Type::Typedef:
- return ClangASTType(m_ast, llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType()).GetMinimumLanguage();
- }
- }
- return lldb::eLanguageTypeC;
-}
-
-lldb::TypeClass
-ClangASTType::GetTypeClass () const
-{
- if (!IsValid())
- return lldb::eTypeClassInvalid;
-
- clang::QualType qual_type(GetQualType());
-
- switch (qual_type->getTypeClass())
- {
- case clang::Type::UnaryTransform: break;
- case clang::Type::FunctionNoProto: return lldb::eTypeClassFunction;
- case clang::Type::FunctionProto: return lldb::eTypeClassFunction;
- case clang::Type::IncompleteArray: return lldb::eTypeClassArray;
- case clang::Type::VariableArray: return lldb::eTypeClassArray;
- case clang::Type::ConstantArray: return lldb::eTypeClassArray;
- case clang::Type::DependentSizedArray: return lldb::eTypeClassArray;
- case clang::Type::DependentSizedExtVector: return lldb::eTypeClassVector;
- case clang::Type::ExtVector: return lldb::eTypeClassVector;
- case clang::Type::Vector: return lldb::eTypeClassVector;
- case clang::Type::Builtin: return lldb::eTypeClassBuiltin;
- case clang::Type::ObjCObjectPointer: return lldb::eTypeClassObjCObjectPointer;
- case clang::Type::BlockPointer: return lldb::eTypeClassBlockPointer;
- case clang::Type::Pointer: return lldb::eTypeClassPointer;
- case clang::Type::LValueReference: return lldb::eTypeClassReference;
- case clang::Type::RValueReference: return lldb::eTypeClassReference;
- case clang::Type::MemberPointer: return lldb::eTypeClassMemberPointer;
- case clang::Type::Complex:
- if (qual_type->isComplexType())
- return lldb::eTypeClassComplexFloat;
- else
- return lldb::eTypeClassComplexInteger;
- case clang::Type::ObjCObject: return lldb::eTypeClassObjCObject;
- case clang::Type::ObjCInterface: return lldb::eTypeClassObjCInterface;
- case clang::Type::Record:
- {
- const clang::RecordType *record_type = llvm::cast<clang::RecordType>(qual_type.getTypePtr());
- const clang::RecordDecl *record_decl = record_type->getDecl();
- if (record_decl->isUnion())
- return lldb::eTypeClassUnion;
- else if (record_decl->isStruct())
- return lldb::eTypeClassStruct;
- else
- return lldb::eTypeClassClass;
- }
- break;
- case clang::Type::Enum: return lldb::eTypeClassEnumeration;
- case clang::Type::Typedef: return lldb::eTypeClassTypedef;
- case clang::Type::UnresolvedUsing: break;
- case clang::Type::Paren:
- return ClangASTType(m_ast, llvm::cast<clang::ParenType>(qual_type)->desugar()).GetTypeClass();
- case clang::Type::Elaborated:
- return ClangASTType(m_ast, llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType()).GetTypeClass();
-
- case clang::Type::Attributed: break;
- case clang::Type::TemplateTypeParm: break;
- case clang::Type::SubstTemplateTypeParm: break;
- case clang::Type::SubstTemplateTypeParmPack:break;
- case clang::Type::Auto: break;
- case clang::Type::InjectedClassName: break;
- case clang::Type::DependentName: break;
- case clang::Type::DependentTemplateSpecialization: break;
- case clang::Type::PackExpansion: break;
-
- case clang::Type::TypeOfExpr: break;
- case clang::Type::TypeOf: break;
- case clang::Type::Decltype: break;
- case clang::Type::TemplateSpecialization: break;
- case clang::Type::Atomic: break;
-
- // pointer type decayed from an array or function type.
- case clang::Type::Decayed: break;
- case clang::Type::Adjusted: break;
- }
- // We don't know hot to display this type...
- return lldb::eTypeClassOther;
-
-}
-
-void
-ClangASTType::SetClangType (clang::ASTContext *ast, clang::QualType qual_type)
-{
- m_ast = ast;
- m_type = qual_type.getAsOpaquePtr();
-}
-
-unsigned
-ClangASTType::GetTypeQualifiers() const
-{
- if (IsValid())
- return GetQualType().getQualifiers().getCVRQualifiers();
- return 0;
-}
-
-//----------------------------------------------------------------------
-// Creating related types
-//----------------------------------------------------------------------
-
-ClangASTType
-ClangASTType::AddConstModifier () const
-{
- if (m_type)
- {
- clang::QualType result(GetQualType());
- result.addConst();
- return ClangASTType (m_ast, result);
- }
- return ClangASTType();
-}
-
-ClangASTType
-ClangASTType::AddRestrictModifier () const
-{
- if (m_type)
- {
- clang::QualType result(GetQualType());
- result.getQualifiers().setRestrict (true);
- return ClangASTType (m_ast, result);
- }
- return ClangASTType();
-}
-
-ClangASTType
-ClangASTType::AddVolatileModifier () const
-{
- if (m_type)
- {
- clang::QualType result(GetQualType());
- result.getQualifiers().setVolatile (true);
- return ClangASTType (m_ast, result);
- }
- return ClangASTType();
-}
-
-ClangASTType
-ClangASTType::GetArrayElementType (uint64_t *stride) const
-{
- if (IsValid())
- {
- clang::QualType qual_type(GetCanonicalQualType());
-
- const clang::Type *array_elem_type = qual_type.getTypePtr()->getArrayElementTypeNoTypeQual();
-
- if (!array_elem_type)
- return ClangASTType();
-
- ClangASTType element_type (m_ast, array_elem_type->getCanonicalTypeUnqualified());
-
- // TODO: the real stride will be >= this value.. find the real one!
- if (stride)
- *stride = element_type.GetByteSize(nullptr);
-
- return element_type;
-
- }
- return ClangASTType();
-}
-
-ClangASTType
-ClangASTType::GetCanonicalType () const
-{
- if (IsValid())
- return ClangASTType (m_ast, GetCanonicalQualType());
- return ClangASTType();
-}
-
-static clang::QualType
-GetFullyUnqualifiedType_Impl (clang::ASTContext *ast, clang::QualType qual_type)
-{
- if (qual_type->isPointerType())
- qual_type = ast->getPointerType(GetFullyUnqualifiedType_Impl(ast, qual_type->getPointeeType()));
- else
- qual_type = qual_type.getUnqualifiedType();
- qual_type.removeLocalConst();
- qual_type.removeLocalRestrict();
- qual_type.removeLocalVolatile();
- return qual_type;
-}
-
-ClangASTType
-ClangASTType::GetFullyUnqualifiedType () const
-{
- if (IsValid())
- return ClangASTType(m_ast, GetFullyUnqualifiedType_Impl(m_ast, GetQualType()));
- return ClangASTType();
-}
-
-
-int
-ClangASTType::GetFunctionArgumentCount () const
-{
- if (IsValid())
- {
- const clang::FunctionProtoType* func = llvm::dyn_cast<clang::FunctionProtoType>(GetCanonicalQualType());
- if (func)
- return func->getNumParams();
- }
- return -1;
-}
-
-ClangASTType
-ClangASTType::GetFunctionArgumentTypeAtIndex (size_t idx) const
-{
- if (IsValid())
- {
- const clang::FunctionProtoType* func = llvm::dyn_cast<clang::FunctionProtoType>(GetCanonicalQualType());
- if (func)
- {
- const uint32_t num_args = func->getNumParams();
- if (idx < num_args)
- return ClangASTType(m_ast, func->getParamType(idx));
- }
- }
- return ClangASTType();
-}
-
-ClangASTType
-ClangASTType::GetFunctionReturnType () const
-{
- if (IsValid())
- {
- clang::QualType qual_type(GetCanonicalQualType());
- const clang::FunctionProtoType* func = llvm::dyn_cast<clang::FunctionProtoType>(qual_type.getTypePtr());
- if (func)
- return ClangASTType(m_ast, func->getReturnType());
- }
- return ClangASTType();
-}
-
-size_t
-ClangASTType::GetNumMemberFunctions () const
-{
- size_t num_functions = 0;
- if (IsValid())
- {
- clang::QualType qual_type(GetCanonicalQualType());
- switch (qual_type->getTypeClass()) {
- case clang::Type::Record:
- if (GetCompleteQualType (m_ast, qual_type))
- {
- const clang::RecordType *record_type = llvm::cast<clang::RecordType>(qual_type.getTypePtr());
- const clang::RecordDecl *record_decl = record_type->getDecl();
- assert(record_decl);
- const clang::CXXRecordDecl *cxx_record_decl = llvm::dyn_cast<clang::CXXRecordDecl>(record_decl);
- if (cxx_record_decl)
- num_functions = std::distance(cxx_record_decl->method_begin(), cxx_record_decl->method_end());
- }
- break;
-
- case clang::Type::ObjCObjectPointer:
- if (GetCompleteType())
- {
- const clang::ObjCObjectPointerType *objc_class_type = qual_type->getAsObjCInterfacePointerType();
- if (objc_class_type)
- {
- clang::ObjCInterfaceDecl *class_interface_decl = objc_class_type->getInterfaceDecl();
- if (class_interface_decl)
- num_functions = std::distance(class_interface_decl->meth_begin(), class_interface_decl->meth_end());
- }
- }
- break;
-
- case clang::Type::ObjCObject:
- case clang::Type::ObjCInterface:
- if (GetCompleteType())
- {
- const clang::ObjCObjectType *objc_class_type = llvm::dyn_cast<clang::ObjCObjectType>(qual_type.getTypePtr());
- if (objc_class_type)
- {
- clang::ObjCInterfaceDecl *class_interface_decl = objc_class_type->getInterface();
- if (class_interface_decl)
- num_functions = std::distance(class_interface_decl->meth_begin(), class_interface_decl->meth_end());
- }
- }
- break;
-
-
- case clang::Type::Typedef:
- return ClangASTType (m_ast, llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType()).GetNumMemberFunctions();
-
- case clang::Type::Elaborated:
- return ClangASTType (m_ast, llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType()).GetNumMemberFunctions();
-
- case clang::Type::Paren:
- return ClangASTType (m_ast, llvm::cast<clang::ParenType>(qual_type)->desugar()).GetNumMemberFunctions();
-
- default:
- break;
- }
- }
- return num_functions;
-}
-
-TypeMemberFunctionImpl
-ClangASTType::GetMemberFunctionAtIndex (size_t idx)
-{
- std::string name("");
- MemberFunctionKind kind(MemberFunctionKind::eMemberFunctionKindUnknown);
- ClangASTType type{};
- clang::ObjCMethodDecl *method_decl(nullptr);
- if (IsValid())
- {
- clang::QualType qual_type(GetCanonicalQualType());
- switch (qual_type->getTypeClass()) {
- case clang::Type::Record:
- if (GetCompleteQualType (m_ast, qual_type))
- {
- const clang::RecordType *record_type = llvm::cast<clang::RecordType>(qual_type.getTypePtr());
- const clang::RecordDecl *record_decl = record_type->getDecl();
- assert(record_decl);
- const clang::CXXRecordDecl *cxx_record_decl = llvm::dyn_cast<clang::CXXRecordDecl>(record_decl);
- if (cxx_record_decl)
- {
- auto method_iter = cxx_record_decl->method_begin();
- auto method_end = cxx_record_decl->method_end();
- if (idx < static_cast<size_t>(std::distance(method_iter, method_end)))
- {
- std::advance(method_iter, idx);
- auto method_decl = method_iter->getCanonicalDecl();
- if (method_decl)
- {
- if (!method_decl->getName().empty())
- name.assign(method_decl->getName().data());
- else
- name.clear();
- if (method_decl->isStatic())
- kind = lldb::eMemberFunctionKindStaticMethod;
- else if (llvm::isa<clang::CXXConstructorDecl>(method_decl))
- kind = lldb::eMemberFunctionKindConstructor;
- else if (llvm::isa<clang::CXXDestructorDecl>(method_decl))
- kind = lldb::eMemberFunctionKindDestructor;
- else
- kind = lldb::eMemberFunctionKindInstanceMethod;
- type = ClangASTType(m_ast,method_decl->getType().getAsOpaquePtr());
- }
- }
- }
- }
- break;
-
- case clang::Type::ObjCObjectPointer:
- if (GetCompleteType())
- {
- const clang::ObjCObjectPointerType *objc_class_type = qual_type->getAsObjCInterfacePointerType();
- if (objc_class_type)
- {
- clang::ObjCInterfaceDecl *class_interface_decl = objc_class_type->getInterfaceDecl();
- if (class_interface_decl)
- {
- auto method_iter = class_interface_decl->meth_begin();
- auto method_end = class_interface_decl->meth_end();
- if (idx < static_cast<size_t>(std::distance(method_iter, method_end)))
- {
- std::advance(method_iter, idx);
- method_decl = method_iter->getCanonicalDecl();
- if (method_decl)
- {
- name = method_decl->getSelector().getAsString();
- if (method_decl->isClassMethod())
- kind = lldb::eMemberFunctionKindStaticMethod;
- else
- kind = lldb::eMemberFunctionKindInstanceMethod;
- }
- }
- }
- }
- }
- break;
-
- case clang::Type::ObjCObject:
- case clang::Type::ObjCInterface:
- if (GetCompleteType())
- {
- const clang::ObjCObjectType *objc_class_type = llvm::dyn_cast<clang::ObjCObjectType>(qual_type.getTypePtr());
- if (objc_class_type)
- {
- clang::ObjCInterfaceDecl *class_interface_decl = objc_class_type->getInterface();
- if (class_interface_decl)
- {
- auto method_iter = class_interface_decl->meth_begin();
- auto method_end = class_interface_decl->meth_end();
- if (idx < static_cast<size_t>(std::distance(method_iter, method_end)))
- {
- std::advance(method_iter, idx);
- method_decl = method_iter->getCanonicalDecl();
- if (method_decl)
- {
- name = method_decl->getSelector().getAsString();
- if (method_decl->isClassMethod())
- kind = lldb::eMemberFunctionKindStaticMethod;
- else
- kind = lldb::eMemberFunctionKindInstanceMethod;
- }
- }
- }
- }
- }
- break;
-
- case clang::Type::Typedef:
- return ClangASTType (m_ast, llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType()).GetMemberFunctionAtIndex(idx);
-
- case clang::Type::Elaborated:
- return ClangASTType (m_ast, llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType()).GetMemberFunctionAtIndex(idx);
-
- case clang::Type::Paren:
- return ClangASTType (m_ast, llvm::cast<clang::ParenType>(qual_type)->desugar()).GetMemberFunctionAtIndex(idx);
-
- default:
- break;
- }
- }
-
- if (kind == eMemberFunctionKindUnknown)
- return TypeMemberFunctionImpl();
- if (method_decl)
- return TypeMemberFunctionImpl(method_decl, name, kind);
- if (type)
- return TypeMemberFunctionImpl(type, name, kind);
-
- return TypeMemberFunctionImpl();
-}
-
-ClangASTType
-ClangASTType::GetLValueReferenceType () const
-{
- if (IsValid())
- {
- return ClangASTType(m_ast, m_ast->getLValueReferenceType(GetQualType()));
- }
- return ClangASTType();
-}
-
-ClangASTType
-ClangASTType::GetRValueReferenceType () const
-{
- if (IsValid())
- {
- return ClangASTType(m_ast, m_ast->getRValueReferenceType(GetQualType()));
- }
- return ClangASTType();
-}
-
-ClangASTType
-ClangASTType::GetNonReferenceType () const
-{
- if (IsValid())
- return ClangASTType(m_ast, GetQualType().getNonReferenceType());
- return ClangASTType();
-}
-
-ClangASTType
-ClangASTType::CreateTypedefType (const char *typedef_name,
- clang::DeclContext *decl_ctx) const
-{
- if (IsValid() && typedef_name && typedef_name[0])
- {
- clang::QualType qual_type (GetQualType());
- if (decl_ctx == nullptr)
- decl_ctx = m_ast->getTranslationUnitDecl();
- clang::TypedefDecl *decl = clang::TypedefDecl::Create (*m_ast,
- decl_ctx,
- clang::SourceLocation(),
- clang::SourceLocation(),
- &m_ast->Idents.get(typedef_name),
- m_ast->getTrivialTypeSourceInfo(qual_type));
-
- decl->setAccess(clang::AS_public); // TODO respect proper access specifier
-
- // Get a uniqued clang::QualType for the typedef decl type
- return ClangASTType (m_ast, m_ast->getTypedefType (decl));
- }
- return ClangASTType();
-
-}
-
-ClangASTType
-ClangASTType::GetPointeeType () const
-{
- if (m_type)
- {
- clang::QualType qual_type(GetQualType());
- return ClangASTType (m_ast, qual_type.getTypePtr()->getPointeeType());
- }
- return ClangASTType();
-}
-
-ClangASTType
-ClangASTType::GetPointerType () const
-{
- if (IsValid())
- {
- clang::QualType qual_type (GetQualType());
-
- const clang::Type::TypeClass type_class = qual_type->getTypeClass();
- switch (type_class)
- {
- case clang::Type::ObjCObject:
- case clang::Type::ObjCInterface:
- return ClangASTType(m_ast, m_ast->getObjCObjectPointerType(qual_type).getAsOpaquePtr());
-
- default:
- return ClangASTType(m_ast, m_ast->getPointerType(qual_type).getAsOpaquePtr());
- }
- }
- return ClangASTType();
-}
-
-ClangASTType
-ClangASTType::GetTypedefedType () const
-{
- if (IsValid())
- {
- const clang::TypedefType *typedef_type = llvm::dyn_cast<clang::TypedefType>(GetQualType());
- if (typedef_type)
- return ClangASTType (m_ast, typedef_type->getDecl()->getUnderlyingType());
- }
- return ClangASTType();
-}
-
-ClangASTType
-ClangASTType::RemoveFastQualifiers () const
-{
- if (m_type)
- {
- clang::QualType qual_type(GetQualType());
- qual_type.getQualifiers().removeFastQualifiers();
- return ClangASTType (m_ast, qual_type);
- }
- return ClangASTType();
-}
-
-
-//----------------------------------------------------------------------
-// Create related types using the current type's AST
-//----------------------------------------------------------------------
-
-ClangASTType
-ClangASTType::GetBasicTypeFromAST (lldb::BasicType basic_type) const
-{
- if (IsValid())
- return ClangASTContext::GetBasicType(m_ast, basic_type);
- return ClangASTType();
-}
-//----------------------------------------------------------------------
-// Exploring the type
-//----------------------------------------------------------------------
-
-uint64_t
-ClangASTType::GetBitSize (ExecutionContextScope *exe_scope) const
-{
- if (GetCompleteType ())
- {
- clang::QualType qual_type(GetCanonicalQualType());
- switch (qual_type->getTypeClass())
- {
- case clang::Type::ObjCInterface:
- case clang::Type::ObjCObject:
- {
- ExecutionContext exe_ctx (exe_scope);
- Process *process = exe_ctx.GetProcessPtr();
- if (process)
- {
- ObjCLanguageRuntime *objc_runtime = process->GetObjCLanguageRuntime();
- if (objc_runtime)
- {
- uint64_t bit_size = 0;
- if (objc_runtime->GetTypeBitSize(*this, bit_size))
- return bit_size;
- }
- }
- else
- {
- static bool g_printed = false;
- if (!g_printed)
- {
- StreamString s;
- DumpTypeDescription(&s);
-
- llvm::outs() << "warning: trying to determine the size of type ";
- llvm::outs() << s.GetString() << "\n";
- llvm::outs() << "without a valid ExecutionContext. this is not reliable. please file a bug against LLDB.\n";
- llvm::outs() << "backtrace:\n";
- llvm::sys::PrintStackTrace(llvm::outs());
- llvm::outs() << "\n";
- g_printed = true;
- }
- }
- }
- // fallthrough
- default:
- const uint32_t bit_size = m_ast->getTypeSize (qual_type);
- if (bit_size == 0)
- {
- if (qual_type->isIncompleteArrayType())
- return m_ast->getTypeSize (qual_type->getArrayElementTypeNoTypeQual()->getCanonicalTypeUnqualified());
- }
- if (qual_type->isObjCObjectOrInterfaceType())
- return bit_size + m_ast->getTypeSize(m_ast->ObjCBuiltinClassTy);
- return bit_size;
- }
- }
- return 0;
-}
-
-uint64_t
-ClangASTType::GetByteSize (ExecutionContextScope *exe_scope) const
-{
- return (GetBitSize (exe_scope) + 7) / 8;
-}
-
-
-size_t
-ClangASTType::GetTypeBitAlign () const
-{
- if (GetCompleteType ())
- return m_ast->getTypeAlign(GetQualType());
- return 0;
-}
-
-
-lldb::Encoding
-ClangASTType::GetEncoding (uint64_t &count) const
-{
- if (!IsValid())
- return lldb::eEncodingInvalid;
-
- count = 1;
- clang::QualType qual_type(GetCanonicalQualType());
-
- switch (qual_type->getTypeClass())
- {
- case clang::Type::UnaryTransform:
- break;
-
- case clang::Type::FunctionNoProto:
- case clang::Type::FunctionProto:
- break;
-
- case clang::Type::IncompleteArray:
- case clang::Type::VariableArray:
- break;
-
- case clang::Type::ConstantArray:
- break;
-
- case clang::Type::ExtVector:
- case clang::Type::Vector:
- // TODO: Set this to more than one???
- break;
-
- case clang::Type::Builtin:
- switch (llvm::cast<clang::BuiltinType>(qual_type)->getKind())
- {
- default: assert(0 && "Unknown builtin type!");
- case clang::BuiltinType::Void:
- break;
-
- case clang::BuiltinType::Bool:
- case clang::BuiltinType::Char_S:
- case clang::BuiltinType::SChar:
- case clang::BuiltinType::WChar_S:
- case clang::BuiltinType::Char16:
- case clang::BuiltinType::Char32:
- case clang::BuiltinType::Short:
- case clang::BuiltinType::Int:
- case clang::BuiltinType::Long:
- case clang::BuiltinType::LongLong:
- case clang::BuiltinType::Int128: return lldb::eEncodingSint;
-
- case clang::BuiltinType::Char_U:
- case clang::BuiltinType::UChar:
- case clang::BuiltinType::WChar_U:
- case clang::BuiltinType::UShort:
- case clang::BuiltinType::UInt:
- case clang::BuiltinType::ULong:
- case clang::BuiltinType::ULongLong:
- case clang::BuiltinType::UInt128: return lldb::eEncodingUint;
-
- case clang::BuiltinType::Float:
- case clang::BuiltinType::Double:
- case clang::BuiltinType::LongDouble: return lldb::eEncodingIEEE754;
-
- case clang::BuiltinType::ObjCClass:
- case clang::BuiltinType::ObjCId:
- case clang::BuiltinType::ObjCSel: return lldb::eEncodingUint;
-
- case clang::BuiltinType::NullPtr: return lldb::eEncodingUint;
-
- case clang::BuiltinType::Kind::ARCUnbridgedCast:
- case clang::BuiltinType::Kind::BoundMember:
- case clang::BuiltinType::Kind::BuiltinFn:
- case clang::BuiltinType::Kind::Dependent:
- case clang::BuiltinType::Kind::Half:
- case clang::BuiltinType::Kind::OCLEvent:
- case clang::BuiltinType::Kind::OCLImage1d:
- case clang::BuiltinType::Kind::OCLImage1dArray:
- case clang::BuiltinType::Kind::OCLImage1dBuffer:
- case clang::BuiltinType::Kind::OCLImage2d:
- case clang::BuiltinType::Kind::OCLImage2dArray:
- case clang::BuiltinType::Kind::OCLImage3d:
- case clang::BuiltinType::Kind::OCLSampler:
- case clang::BuiltinType::Kind::Overload:
- case clang::BuiltinType::Kind::PseudoObject:
- case clang::BuiltinType::Kind::UnknownAny:
- break;
- }
- break;
- // All pointer types are represented as unsigned integer encodings.
- // We may nee to add a eEncodingPointer if we ever need to know the
- // difference
- case clang::Type::ObjCObjectPointer:
- case clang::Type::BlockPointer:
- case clang::Type::Pointer:
- case clang::Type::LValueReference:
- case clang::Type::RValueReference:
- case clang::Type::MemberPointer: return lldb::eEncodingUint;
- case clang::Type::Complex:
- {
- lldb::Encoding encoding = lldb::eEncodingIEEE754;
- if (qual_type->isComplexType())
- encoding = lldb::eEncodingIEEE754;
- else
- {
- const clang::ComplexType *complex_type = qual_type->getAsComplexIntegerType();
- if (complex_type)
- encoding = ClangASTType(m_ast, complex_type->getElementType()).GetEncoding(count);
- else
- encoding = lldb::eEncodingSint;
- }
- count = 2;
- return encoding;
- }
-
- case clang::Type::ObjCInterface: break;
- case clang::Type::Record: break;
- case clang::Type::Enum: return lldb::eEncodingSint;
- case clang::Type::Typedef:
- return ClangASTType(m_ast, llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType()).GetEncoding(count);
-
- case clang::Type::Elaborated:
- return ClangASTType(m_ast, llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType()).GetEncoding(count);
-
- case clang::Type::Paren:
- return ClangASTType(m_ast, llvm::cast<clang::ParenType>(qual_type)->desugar()).GetEncoding(count);
-
- case clang::Type::DependentSizedArray:
- case clang::Type::DependentSizedExtVector:
- case clang::Type::UnresolvedUsing:
- case clang::Type::Attributed:
- case clang::Type::TemplateTypeParm:
- case clang::Type::SubstTemplateTypeParm:
- case clang::Type::SubstTemplateTypeParmPack:
- case clang::Type::Auto:
- case clang::Type::InjectedClassName:
- case clang::Type::DependentName:
- case clang::Type::DependentTemplateSpecialization:
- case clang::Type::PackExpansion:
- case clang::Type::ObjCObject:
-
- case clang::Type::TypeOfExpr:
- case clang::Type::TypeOf:
- case clang::Type::Decltype:
- case clang::Type::TemplateSpecialization:
- case clang::Type::Atomic:
- case clang::Type::Adjusted:
- break;
-
- // pointer type decayed from an array or function type.
- case clang::Type::Decayed:
- break;
- }
- count = 0;
- return lldb::eEncodingInvalid;
-}
-
-lldb::Format
-ClangASTType::GetFormat () const
-{
- if (!IsValid())
- return lldb::eFormatDefault;
-
- clang::QualType qual_type(GetCanonicalQualType());
-
- switch (qual_type->getTypeClass())
- {
- case clang::Type::UnaryTransform:
- break;
-
- case clang::Type::FunctionNoProto:
- case clang::Type::FunctionProto:
- break;
-
- case clang::Type::IncompleteArray:
- case clang::Type::VariableArray:
- break;
-
- case clang::Type::ConstantArray:
- return lldb::eFormatVoid; // no value
-
- case clang::Type::ExtVector:
- case clang::Type::Vector:
- break;
-
- case clang::Type::Builtin:
- switch (llvm::cast<clang::BuiltinType>(qual_type)->getKind())
- {
- //default: assert(0 && "Unknown builtin type!");
- case clang::BuiltinType::UnknownAny:
- case clang::BuiltinType::Void:
- case clang::BuiltinType::BoundMember:
- break;
-
- case clang::BuiltinType::Bool: return lldb::eFormatBoolean;
- case clang::BuiltinType::Char_S:
- case clang::BuiltinType::SChar:
- case clang::BuiltinType::WChar_S:
- case clang::BuiltinType::Char_U:
- case clang::BuiltinType::UChar:
- case clang::BuiltinType::WChar_U: return lldb::eFormatChar;
- case clang::BuiltinType::Char16: return lldb::eFormatUnicode16;
- case clang::BuiltinType::Char32: return lldb::eFormatUnicode32;
- case clang::BuiltinType::UShort: return lldb::eFormatUnsigned;
- case clang::BuiltinType::Short: return lldb::eFormatDecimal;
- case clang::BuiltinType::UInt: return lldb::eFormatUnsigned;
- case clang::BuiltinType::Int: return lldb::eFormatDecimal;
- case clang::BuiltinType::ULong: return lldb::eFormatUnsigned;
- case clang::BuiltinType::Long: return lldb::eFormatDecimal;
- case clang::BuiltinType::ULongLong: return lldb::eFormatUnsigned;
- case clang::BuiltinType::LongLong: return lldb::eFormatDecimal;
- case clang::BuiltinType::UInt128: return lldb::eFormatUnsigned;
- case clang::BuiltinType::Int128: return lldb::eFormatDecimal;
- case clang::BuiltinType::Float: return lldb::eFormatFloat;
- case clang::BuiltinType::Double: return lldb::eFormatFloat;
- case clang::BuiltinType::LongDouble: return lldb::eFormatFloat;
- case clang::BuiltinType::NullPtr:
- case clang::BuiltinType::Overload:
- case clang::BuiltinType::Dependent:
- case clang::BuiltinType::ObjCId:
- case clang::BuiltinType::ObjCClass:
- case clang::BuiltinType::ObjCSel:
- case clang::BuiltinType::Half:
- case clang::BuiltinType::ARCUnbridgedCast:
- case clang::BuiltinType::PseudoObject:
- case clang::BuiltinType::BuiltinFn:
- case clang::BuiltinType::OCLEvent:
- case clang::BuiltinType::OCLImage1d:
- case clang::BuiltinType::OCLImage1dArray:
- case clang::BuiltinType::OCLImage1dBuffer:
- case clang::BuiltinType::OCLImage2d:
- case clang::BuiltinType::OCLImage2dArray:
- case clang::BuiltinType::OCLImage3d:
- case clang::BuiltinType::OCLSampler:
- return lldb::eFormatHex;
- }
- break;
- case clang::Type::ObjCObjectPointer: return lldb::eFormatHex;
- case clang::Type::BlockPointer: return lldb::eFormatHex;
- case clang::Type::Pointer: return lldb::eFormatHex;
- case clang::Type::LValueReference:
- case clang::Type::RValueReference: return lldb::eFormatHex;
- case clang::Type::MemberPointer: break;
- case clang::Type::Complex:
- {
- if (qual_type->isComplexType())
- return lldb::eFormatComplex;
- else
- return lldb::eFormatComplexInteger;
- }
- case clang::Type::ObjCInterface: break;
- case clang::Type::Record: break;
- case clang::Type::Enum: return lldb::eFormatEnum;
- case clang::Type::Typedef:
- return ClangASTType (m_ast, llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType()).GetFormat();
- case clang::Type::Auto:
- return ClangASTType (m_ast, llvm::cast<clang::AutoType>(qual_type)->desugar()).GetFormat();
- case clang::Type::Paren:
- return ClangASTType (m_ast, llvm::cast<clang::ParenType>(qual_type)->desugar()).GetFormat();
- case clang::Type::Elaborated:
- return ClangASTType (m_ast, llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType()).GetFormat();
- case clang::Type::DependentSizedArray:
- case clang::Type::DependentSizedExtVector:
- case clang::Type::UnresolvedUsing:
- case clang::Type::Attributed:
- case clang::Type::TemplateTypeParm:
- case clang::Type::SubstTemplateTypeParm:
- case clang::Type::SubstTemplateTypeParmPack:
- case clang::Type::InjectedClassName:
- case clang::Type::DependentName:
- case clang::Type::DependentTemplateSpecialization:
- case clang::Type::PackExpansion:
- case clang::Type::ObjCObject:
-
- case clang::Type::TypeOfExpr:
- case clang::Type::TypeOf:
- case clang::Type::Decltype:
- case clang::Type::TemplateSpecialization:
- case clang::Type::Atomic:
- case clang::Type::Adjusted:
- break;
-
- // pointer type decayed from an array or function type.
- case clang::Type::Decayed:
- break;
- }
- // We don't know hot to display this type...
- return lldb::eFormatBytes;
-}
-
-static bool
-ObjCDeclHasIVars (clang::ObjCInterfaceDecl *class_interface_decl, bool check_superclass)
-{
- while (class_interface_decl)
- {
- if (class_interface_decl->ivar_size() > 0)
- return true;
-
- if (check_superclass)
- class_interface_decl = class_interface_decl->getSuperClass();
- else
- break;
- }
- return false;
-}
-
-uint32_t
-ClangASTType::GetNumChildren (bool omit_empty_base_classes) const
-{
- if (!IsValid())
- return 0;
-
- uint32_t num_children = 0;
- clang::QualType qual_type(GetQualType());
- const clang::Type::TypeClass type_class = qual_type->getTypeClass();
- switch (type_class)
- {
- case clang::Type::Builtin:
- switch (llvm::cast<clang::BuiltinType>(qual_type)->getKind())
- {
- case clang::BuiltinType::ObjCId: // child is Class
- case clang::BuiltinType::ObjCClass: // child is Class
- num_children = 1;
- break;
-
- default:
- break;
- }
- break;
-
- case clang::Type::Complex: return 0;
-
- case clang::Type::Record:
- if (GetCompleteQualType (m_ast, qual_type))
- {
- const clang::RecordType *record_type = llvm::cast<clang::RecordType>(qual_type.getTypePtr());
- const clang::RecordDecl *record_decl = record_type->getDecl();
- assert(record_decl);
- const clang::CXXRecordDecl *cxx_record_decl = llvm::dyn_cast<clang::CXXRecordDecl>(record_decl);
- if (cxx_record_decl)
- {
- if (omit_empty_base_classes)
- {
- // Check each base classes to see if it or any of its
- // base classes contain any fields. This can help
- // limit the noise in variable views by not having to
- // show base classes that contain no members.
- clang::CXXRecordDecl::base_class_const_iterator base_class, base_class_end;
- for (base_class = cxx_record_decl->bases_begin(), base_class_end = cxx_record_decl->bases_end();
- base_class != base_class_end;
- ++base_class)
- {
- const clang::CXXRecordDecl *base_class_decl = llvm::cast<clang::CXXRecordDecl>(base_class->getType()->getAs<clang::RecordType>()->getDecl());
-
- // Skip empty base classes
- if (ClangASTContext::RecordHasFields(base_class_decl) == false)
- continue;
-
- num_children++;
- }
- }
- else
- {
- // Include all base classes
- num_children += cxx_record_decl->getNumBases();
- }
-
- }
- clang::RecordDecl::field_iterator field, field_end;
- for (field = record_decl->field_begin(), field_end = record_decl->field_end(); field != field_end; ++field)
- ++num_children;
- }
- break;
-
- case clang::Type::ObjCObject:
- case clang::Type::ObjCInterface:
- if (GetCompleteQualType (m_ast, qual_type))
- {
- const clang::ObjCObjectType *objc_class_type = llvm::dyn_cast<clang::ObjCObjectType>(qual_type.getTypePtr());
- assert (objc_class_type);
- if (objc_class_type)
- {
- clang::ObjCInterfaceDecl *class_interface_decl = objc_class_type->getInterface();
-
- if (class_interface_decl)
- {
-
- clang::ObjCInterfaceDecl *superclass_interface_decl = class_interface_decl->getSuperClass();
- if (superclass_interface_decl)
- {
- if (omit_empty_base_classes)
- {
- if (ObjCDeclHasIVars (superclass_interface_decl, true))
- ++num_children;
- }
- else
- ++num_children;
- }
-
- num_children += class_interface_decl->ivar_size();
- }
- }
- }
- break;
-
- case clang::Type::ObjCObjectPointer:
- {
- const clang::ObjCObjectPointerType *pointer_type = llvm::cast<clang::ObjCObjectPointerType>(qual_type.getTypePtr());
- clang::QualType pointee_type = pointer_type->getPointeeType();
- uint32_t num_pointee_children = ClangASTType (m_ast,pointee_type).GetNumChildren (omit_empty_base_classes);
- // If this type points to a simple type, then it has 1 child
- if (num_pointee_children == 0)
- num_children = 1;
- else
- num_children = num_pointee_children;
- }
- break;
-
- case clang::Type::Vector:
- case clang::Type::ExtVector:
- num_children = llvm::cast<clang::VectorType>(qual_type.getTypePtr())->getNumElements();
- break;
-
- case clang::Type::ConstantArray:
- num_children = llvm::cast<clang::ConstantArrayType>(qual_type.getTypePtr())->getSize().getLimitedValue();
- break;
-
- case clang::Type::Pointer:
- {
- const clang::PointerType *pointer_type = llvm::cast<clang::PointerType>(qual_type.getTypePtr());
- clang::QualType pointee_type (pointer_type->getPointeeType());
- uint32_t num_pointee_children = ClangASTType (m_ast,pointee_type).GetNumChildren (omit_empty_base_classes);
- if (num_pointee_children == 0)
- {
- // We have a pointer to a pointee type that claims it has no children.
- // We will want to look at
- num_children = ClangASTType (m_ast, pointee_type).GetNumPointeeChildren();
- }
- else
- num_children = num_pointee_children;
- }
- break;
-
- case clang::Type::LValueReference:
- case clang::Type::RValueReference:
- {
- const clang::ReferenceType *reference_type = llvm::cast<clang::ReferenceType>(qual_type.getTypePtr());
- clang::QualType pointee_type = reference_type->getPointeeType();
- uint32_t num_pointee_children = ClangASTType (m_ast, pointee_type).GetNumChildren (omit_empty_base_classes);
- // If this type points to a simple type, then it has 1 child
- if (num_pointee_children == 0)
- num_children = 1;
- else
- num_children = num_pointee_children;
- }
- break;
-
-
- case clang::Type::Typedef:
- num_children = ClangASTType (m_ast, llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType()).GetNumChildren (omit_empty_base_classes);
- break;
-
- case clang::Type::Elaborated:
- num_children = ClangASTType (m_ast, llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType()).GetNumChildren (omit_empty_base_classes);
- break;
-
- case clang::Type::Paren:
- num_children = ClangASTType (m_ast, llvm::cast<clang::ParenType>(qual_type)->desugar()).GetNumChildren (omit_empty_base_classes);
- break;
- default:
- break;
- }
- return num_children;
-}
-
-lldb::BasicType
-ClangASTType::GetBasicTypeEnumeration () const
-{
- if (IsValid())
- {
- clang::QualType qual_type(GetQualType());
- const clang::Type::TypeClass type_class = qual_type->getTypeClass();
- if (type_class == clang::Type::Builtin)
- {
- switch (llvm::cast<clang::BuiltinType>(qual_type)->getKind())
- {
- case clang::BuiltinType::Void: return eBasicTypeVoid;
- case clang::BuiltinType::Bool: return eBasicTypeBool;
- case clang::BuiltinType::Char_S: return eBasicTypeSignedChar;
- case clang::BuiltinType::Char_U: return eBasicTypeUnsignedChar;
- case clang::BuiltinType::Char16: return eBasicTypeChar16;
- case clang::BuiltinType::Char32: return eBasicTypeChar32;
- case clang::BuiltinType::UChar: return eBasicTypeUnsignedChar;
- case clang::BuiltinType::SChar: return eBasicTypeSignedChar;
- case clang::BuiltinType::WChar_S: return eBasicTypeSignedWChar;
- case clang::BuiltinType::WChar_U: return eBasicTypeUnsignedWChar;
- case clang::BuiltinType::Short: return eBasicTypeShort;
- case clang::BuiltinType::UShort: return eBasicTypeUnsignedShort;
- case clang::BuiltinType::Int: return eBasicTypeInt;
- case clang::BuiltinType::UInt: return eBasicTypeUnsignedInt;
- case clang::BuiltinType::Long: return eBasicTypeLong;
- case clang::BuiltinType::ULong: return eBasicTypeUnsignedLong;
- case clang::BuiltinType::LongLong: return eBasicTypeLongLong;
- case clang::BuiltinType::ULongLong: return eBasicTypeUnsignedLongLong;
- case clang::BuiltinType::Int128: return eBasicTypeInt128;
- case clang::BuiltinType::UInt128: return eBasicTypeUnsignedInt128;
-
- case clang::BuiltinType::Half: return eBasicTypeHalf;
- case clang::BuiltinType::Float: return eBasicTypeFloat;
- case clang::BuiltinType::Double: return eBasicTypeDouble;
- case clang::BuiltinType::LongDouble:return eBasicTypeLongDouble;
-
- case clang::BuiltinType::NullPtr: return eBasicTypeNullPtr;
- case clang::BuiltinType::ObjCId: return eBasicTypeObjCID;
- case clang::BuiltinType::ObjCClass: return eBasicTypeObjCClass;
- case clang::BuiltinType::ObjCSel: return eBasicTypeObjCSel;
- case clang::BuiltinType::Dependent:
- case clang::BuiltinType::Overload:
- case clang::BuiltinType::BoundMember:
- case clang::BuiltinType::PseudoObject:
- case clang::BuiltinType::UnknownAny:
- case clang::BuiltinType::BuiltinFn:
- case clang::BuiltinType::ARCUnbridgedCast:
- case clang::BuiltinType::OCLEvent:
- case clang::BuiltinType::OCLImage1d:
- case clang::BuiltinType::OCLImage1dArray:
- case clang::BuiltinType::OCLImage1dBuffer:
- case clang::BuiltinType::OCLImage2d:
- case clang::BuiltinType::OCLImage2dArray:
- case clang::BuiltinType::OCLImage3d:
- case clang::BuiltinType::OCLSampler:
- return eBasicTypeOther;
- }
- }
- }
- return eBasicTypeInvalid;
-}
-
-
-#pragma mark Aggregate Types
-
-uint32_t
-ClangASTType::GetNumDirectBaseClasses () const
-{
- if (!IsValid())
- return 0;
-
- uint32_t count = 0;
- clang::QualType qual_type(GetCanonicalQualType());
- const clang::Type::TypeClass type_class = qual_type->getTypeClass();
- switch (type_class)
- {
- case clang::Type::Record:
- if (GetCompleteType())
- {
- const clang::CXXRecordDecl *cxx_record_decl = qual_type->getAsCXXRecordDecl();
- if (cxx_record_decl)
- count = cxx_record_decl->getNumBases();
- }
- break;
-
- case clang::Type::ObjCObjectPointer:
- count = GetPointeeType().GetNumDirectBaseClasses();
- break;
-
- case clang::Type::ObjCObject:
- if (GetCompleteType())
- {
- const clang::ObjCObjectType *objc_class_type = qual_type->getAsObjCQualifiedInterfaceType();
- if (objc_class_type)
- {
- clang::ObjCInterfaceDecl *class_interface_decl = objc_class_type->getInterface();
-
- if (class_interface_decl && class_interface_decl->getSuperClass())
- count = 1;
- }
- }
- break;
- case clang::Type::ObjCInterface:
- if (GetCompleteType())
- {
- const clang::ObjCInterfaceType *objc_interface_type = qual_type->getAs<clang::ObjCInterfaceType>();
- if (objc_interface_type)
- {
- clang::ObjCInterfaceDecl *class_interface_decl = objc_interface_type->getInterface();
-
- if (class_interface_decl && class_interface_decl->getSuperClass())
- count = 1;
- }
- }
- break;
-
-
- case clang::Type::Typedef:
- count = ClangASTType (m_ast, llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType()).GetNumDirectBaseClasses ();
- break;
-
- case clang::Type::Elaborated:
- count = ClangASTType (m_ast, llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType()).GetNumDirectBaseClasses ();
- break;
-
- case clang::Type::Paren:
- return ClangASTType (m_ast, llvm::cast<clang::ParenType>(qual_type)->desugar()).GetNumDirectBaseClasses ();
-
- default:
- break;
- }
- return count;
-}
-
-uint32_t
-ClangASTType::GetNumVirtualBaseClasses () const
-{
- if (!IsValid())
- return 0;
-
- uint32_t count = 0;
- clang::QualType qual_type(GetCanonicalQualType());
- const clang::Type::TypeClass type_class = qual_type->getTypeClass();
- switch (type_class)
- {
- case clang::Type::Record:
- if (GetCompleteType())
- {
- const clang::CXXRecordDecl *cxx_record_decl = qual_type->getAsCXXRecordDecl();
- if (cxx_record_decl)
- count = cxx_record_decl->getNumVBases();
- }
- break;
-
- case clang::Type::Typedef:
- count = ClangASTType (m_ast, llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType()).GetNumVirtualBaseClasses();
- break;
-
- case clang::Type::Elaborated:
- count = ClangASTType (m_ast, llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType()).GetNumVirtualBaseClasses();
- break;
-
- case clang::Type::Paren:
- count = ClangASTType (m_ast, llvm::cast<clang::ParenType>(qual_type)->desugar()).GetNumVirtualBaseClasses();
- break;
-
- default:
- break;
- }
- return count;
-}
-
-uint32_t
-ClangASTType::GetNumFields () const
-{
- if (!IsValid())
- return 0;
-
- uint32_t count = 0;
- clang::QualType qual_type(GetCanonicalQualType());
- const clang::Type::TypeClass type_class = qual_type->getTypeClass();
- switch (type_class)
- {
- case clang::Type::Record:
- if (GetCompleteType())
- {
- const clang::RecordType *record_type = llvm::dyn_cast<clang::RecordType>(qual_type.getTypePtr());
- if (record_type)
- {
- clang::RecordDecl *record_decl = record_type->getDecl();
- if (record_decl)
- {
- uint32_t field_idx = 0;
- clang::RecordDecl::field_iterator field, field_end;
- for (field = record_decl->field_begin(), field_end = record_decl->field_end(); field != field_end; ++field)
- ++field_idx;
- count = field_idx;
- }
- }
- }
- break;
-
- case clang::Type::Typedef:
- count = ClangASTType (m_ast, llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType()).GetNumFields();
- break;
-
- case clang::Type::Elaborated:
- count = ClangASTType (m_ast, llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType()).GetNumFields();
- break;
-
- case clang::Type::Paren:
- count = ClangASTType (m_ast, llvm::cast<clang::ParenType>(qual_type)->desugar()).GetNumFields();
- break;
-
- case clang::Type::ObjCObjectPointer:
- if (GetCompleteType())
- {
- const clang::ObjCObjectPointerType *objc_class_type = qual_type->getAsObjCInterfacePointerType();
- if (objc_class_type)
- {
- clang::ObjCInterfaceDecl *class_interface_decl = objc_class_type->getInterfaceDecl();
-
- if (class_interface_decl)
- count = class_interface_decl->ivar_size();
- }
- }
- break;
-
- case clang::Type::ObjCObject:
- case clang::Type::ObjCInterface:
- if (GetCompleteType())
- {
- const clang::ObjCObjectType *objc_class_type = llvm::dyn_cast<clang::ObjCObjectType>(qual_type.getTypePtr());
- if (objc_class_type)
- {
- clang::ObjCInterfaceDecl *class_interface_decl = objc_class_type->getInterface();
-
- if (class_interface_decl)
- count = class_interface_decl->ivar_size();
- }
- }
- break;
-
- default:
- break;
- }
- return count;
-}
-
-ClangASTType
-ClangASTType::GetDirectBaseClassAtIndex (size_t idx, uint32_t *bit_offset_ptr) const
-{
- if (!IsValid())
- return ClangASTType();
-
- clang::QualType qual_type(GetCanonicalQualType());
- const clang::Type::TypeClass type_class = qual_type->getTypeClass();
- switch (type_class)
- {
- case clang::Type::Record:
- if (GetCompleteType())
- {
- const clang::CXXRecordDecl *cxx_record_decl = qual_type->getAsCXXRecordDecl();
- if (cxx_record_decl)
- {
- uint32_t curr_idx = 0;
- clang::CXXRecordDecl::base_class_const_iterator base_class, base_class_end;
- for (base_class = cxx_record_decl->bases_begin(), base_class_end = cxx_record_decl->bases_end();
- base_class != base_class_end;
- ++base_class, ++curr_idx)
- {
- if (curr_idx == idx)
- {
- if (bit_offset_ptr)
- {
- const clang::ASTRecordLayout &record_layout = m_ast->getASTRecordLayout(cxx_record_decl);
- const clang::CXXRecordDecl *base_class_decl = llvm::cast<clang::CXXRecordDecl>(base_class->getType()->getAs<clang::RecordType>()->getDecl());
- if (base_class->isVirtual())
- *bit_offset_ptr = record_layout.getVBaseClassOffset(base_class_decl).getQuantity() * 8;
- else
- *bit_offset_ptr = record_layout.getBaseClassOffset(base_class_decl).getQuantity() * 8;
- }
- return ClangASTType (m_ast, base_class->getType());
- }
- }
- }
- }
- break;
-
- case clang::Type::ObjCObjectPointer:
- return GetPointeeType().GetDirectBaseClassAtIndex(idx,bit_offset_ptr);
-
- case clang::Type::ObjCObject:
- if (idx == 0 && GetCompleteType())
- {
- const clang::ObjCObjectType *objc_class_type = qual_type->getAsObjCQualifiedInterfaceType();
- if (objc_class_type)
- {
- clang::ObjCInterfaceDecl *class_interface_decl = objc_class_type->getInterface();
-
- if (class_interface_decl)
- {
- clang::ObjCInterfaceDecl *superclass_interface_decl = class_interface_decl->getSuperClass();
- if (superclass_interface_decl)
- {
- if (bit_offset_ptr)
- *bit_offset_ptr = 0;
- return ClangASTType (m_ast, m_ast->getObjCInterfaceType(superclass_interface_decl));
- }
- }
- }
- }
- break;
- case clang::Type::ObjCInterface:
- if (idx == 0 && GetCompleteType())
- {
- const clang::ObjCObjectType *objc_interface_type = qual_type->getAs<clang::ObjCInterfaceType>();
- if (objc_interface_type)
- {
- clang::ObjCInterfaceDecl *class_interface_decl = objc_interface_type->getInterface();
-
- if (class_interface_decl)
- {
- clang::ObjCInterfaceDecl *superclass_interface_decl = class_interface_decl->getSuperClass();
- if (superclass_interface_decl)
- {
- if (bit_offset_ptr)
- *bit_offset_ptr = 0;
- return ClangASTType (m_ast, m_ast->getObjCInterfaceType(superclass_interface_decl));
- }
- }
- }
- }
- break;
-
-
- case clang::Type::Typedef:
- return ClangASTType (m_ast, llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType()).GetDirectBaseClassAtIndex (idx, bit_offset_ptr);
-
- case clang::Type::Elaborated:
- return ClangASTType (m_ast, llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType()).GetDirectBaseClassAtIndex (idx, bit_offset_ptr);
-
- case clang::Type::Paren:
- return ClangASTType (m_ast, llvm::cast<clang::ParenType>(qual_type)->desugar()).GetDirectBaseClassAtIndex (idx, bit_offset_ptr);
-
- default:
- break;
- }
- return ClangASTType();
-}
-
-ClangASTType
-ClangASTType::GetVirtualBaseClassAtIndex (size_t idx, uint32_t *bit_offset_ptr) const
-{
- if (!IsValid())
- return ClangASTType();
-
- clang::QualType qual_type(GetCanonicalQualType());
- const clang::Type::TypeClass type_class = qual_type->getTypeClass();
- switch (type_class)
- {
- case clang::Type::Record:
- if (GetCompleteType())
- {
- const clang::CXXRecordDecl *cxx_record_decl = qual_type->getAsCXXRecordDecl();
- if (cxx_record_decl)
- {
- uint32_t curr_idx = 0;
- clang::CXXRecordDecl::base_class_const_iterator base_class, base_class_end;
- for (base_class = cxx_record_decl->vbases_begin(), base_class_end = cxx_record_decl->vbases_end();
- base_class != base_class_end;
- ++base_class, ++curr_idx)
- {
- if (curr_idx == idx)
- {
- if (bit_offset_ptr)
- {
- const clang::ASTRecordLayout &record_layout = m_ast->getASTRecordLayout(cxx_record_decl);
- const clang::CXXRecordDecl *base_class_decl = llvm::cast<clang::CXXRecordDecl>(base_class->getType()->getAs<clang::RecordType>()->getDecl());
- *bit_offset_ptr = record_layout.getVBaseClassOffset(base_class_decl).getQuantity() * 8;
-
- }
- return ClangASTType (m_ast, base_class->getType());
- }
- }
- }
- }
- break;
-
- case clang::Type::Typedef:
- return ClangASTType (m_ast, llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType()).GetVirtualBaseClassAtIndex (idx, bit_offset_ptr);
-
- case clang::Type::Elaborated:
- return ClangASTType (m_ast, llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType()).GetVirtualBaseClassAtIndex (idx, bit_offset_ptr);
-
- case clang::Type::Paren:
- return ClangASTType (m_ast, llvm::cast<clang::ParenType>(qual_type)->desugar()).GetVirtualBaseClassAtIndex (idx, bit_offset_ptr);
-
- default:
- break;
- }
- return ClangASTType();
-}
-
-static clang_type_t
-GetObjCFieldAtIndex (clang::ASTContext *ast,
- clang::ObjCInterfaceDecl *class_interface_decl,
- size_t idx,
- std::string& name,
- uint64_t *bit_offset_ptr,
- uint32_t *bitfield_bit_size_ptr,
- bool *is_bitfield_ptr)
-{
- if (class_interface_decl)
- {
- if (idx < (class_interface_decl->ivar_size()))
- {
- clang::ObjCInterfaceDecl::ivar_iterator ivar_pos, ivar_end = class_interface_decl->ivar_end();
- uint32_t ivar_idx = 0;
-
- for (ivar_pos = class_interface_decl->ivar_begin(); ivar_pos != ivar_end; ++ivar_pos, ++ivar_idx)
- {
- if (ivar_idx == idx)
- {
- const clang::ObjCIvarDecl* ivar_decl = *ivar_pos;
-
- clang::QualType ivar_qual_type(ivar_decl->getType());
-
- name.assign(ivar_decl->getNameAsString());
-
- if (bit_offset_ptr)
- {
- const clang::ASTRecordLayout &interface_layout = ast->getASTObjCInterfaceLayout(class_interface_decl);
- *bit_offset_ptr = interface_layout.getFieldOffset (ivar_idx);
- }
-
- const bool is_bitfield = ivar_pos->isBitField();
-
- if (bitfield_bit_size_ptr)
- {
- *bitfield_bit_size_ptr = 0;
-
- if (is_bitfield && ast)
- {
- clang::Expr *bitfield_bit_size_expr = ivar_pos->getBitWidth();
- llvm::APSInt bitfield_apsint;
- if (bitfield_bit_size_expr && bitfield_bit_size_expr->EvaluateAsInt(bitfield_apsint, *ast))
- {
- *bitfield_bit_size_ptr = bitfield_apsint.getLimitedValue();
- }
- }
- }
- if (is_bitfield_ptr)
- *is_bitfield_ptr = is_bitfield;
-
- return ivar_qual_type.getAsOpaquePtr();
- }
- }
- }
- }
- return nullptr;
-}
-
-ClangASTType
-ClangASTType::GetFieldAtIndex (size_t idx,
- std::string& name,
- uint64_t *bit_offset_ptr,
- uint32_t *bitfield_bit_size_ptr,
- bool *is_bitfield_ptr) const
-{
- if (!IsValid())
- return ClangASTType();
-
- clang::QualType qual_type(GetCanonicalQualType());
- const clang::Type::TypeClass type_class = qual_type->getTypeClass();
- switch (type_class)
- {
- case clang::Type::Record:
- if (GetCompleteType())
- {
- const clang::RecordType *record_type = llvm::cast<clang::RecordType>(qual_type.getTypePtr());
- const clang::RecordDecl *record_decl = record_type->getDecl();
- uint32_t field_idx = 0;
- clang::RecordDecl::field_iterator field, field_end;
- for (field = record_decl->field_begin(), field_end = record_decl->field_end(); field != field_end; ++field, ++field_idx)
- {
- if (idx == field_idx)
- {
- // Print the member type if requested
- // Print the member name and equal sign
- name.assign(field->getNameAsString());
-
- // Figure out the type byte size (field_type_info.first) and
- // alignment (field_type_info.second) from the AST context.
- if (bit_offset_ptr)
- {
- const clang::ASTRecordLayout &record_layout = m_ast->getASTRecordLayout(record_decl);
- *bit_offset_ptr = record_layout.getFieldOffset (field_idx);
- }
-
- const bool is_bitfield = field->isBitField();
-
- if (bitfield_bit_size_ptr)
- {
- *bitfield_bit_size_ptr = 0;
-
- if (is_bitfield)
- {
- clang::Expr *bitfield_bit_size_expr = field->getBitWidth();
- llvm::APSInt bitfield_apsint;
- if (bitfield_bit_size_expr && bitfield_bit_size_expr->EvaluateAsInt(bitfield_apsint, *m_ast))
- {
- *bitfield_bit_size_ptr = bitfield_apsint.getLimitedValue();
- }
- }
- }
- if (is_bitfield_ptr)
- *is_bitfield_ptr = is_bitfield;
-
- return ClangASTType (m_ast, field->getType());
- }
- }
- }
- break;
-
- case clang::Type::ObjCObjectPointer:
- if (GetCompleteType())
- {
- const clang::ObjCObjectPointerType *objc_class_type = qual_type->getAsObjCInterfacePointerType();
- if (objc_class_type)
- {
- clang::ObjCInterfaceDecl *class_interface_decl = objc_class_type->getInterfaceDecl();
- return ClangASTType (m_ast, GetObjCFieldAtIndex(m_ast, class_interface_decl, idx, name, bit_offset_ptr, bitfield_bit_size_ptr, is_bitfield_ptr));
- }
- }
- break;
-
- case clang::Type::ObjCObject:
- case clang::Type::ObjCInterface:
- if (GetCompleteType())
- {
- const clang::ObjCObjectType *objc_class_type = llvm::dyn_cast<clang::ObjCObjectType>(qual_type.getTypePtr());
- assert (objc_class_type);
- if (objc_class_type)
- {
- clang::ObjCInterfaceDecl *class_interface_decl = objc_class_type->getInterface();
- return ClangASTType (m_ast, GetObjCFieldAtIndex(m_ast, class_interface_decl, idx, name, bit_offset_ptr, bitfield_bit_size_ptr, is_bitfield_ptr));
- }
- }
- break;
-
-
- case clang::Type::Typedef:
- return ClangASTType (m_ast, llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType()).
- GetFieldAtIndex (idx,
- name,
- bit_offset_ptr,
- bitfield_bit_size_ptr,
- is_bitfield_ptr);
-
- case clang::Type::Elaborated:
- return ClangASTType (m_ast, llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType()).
- GetFieldAtIndex (idx,
- name,
- bit_offset_ptr,
- bitfield_bit_size_ptr,
- is_bitfield_ptr);
-
- case clang::Type::Paren:
- return ClangASTType (m_ast, llvm::cast<clang::ParenType>(qual_type)->desugar()).
- GetFieldAtIndex (idx,
- name,
- bit_offset_ptr,
- bitfield_bit_size_ptr,
- is_bitfield_ptr);
-
- default:
- break;
- }
- return ClangASTType();
-}
-
-uint32_t
-ClangASTType::GetIndexOfFieldWithName (const char* name,
- ClangASTType* field_clang_type_ptr,
- uint64_t *bit_offset_ptr,
- uint32_t *bitfield_bit_size_ptr,
- bool *is_bitfield_ptr) const
-{
- unsigned count = GetNumFields();
- std::string field_name;
- for (unsigned index = 0; index < count; index++)
- {
- ClangASTType field_clang_type (GetFieldAtIndex(index, field_name, bit_offset_ptr, bitfield_bit_size_ptr, is_bitfield_ptr));
- if (strcmp(field_name.c_str(), name) == 0)
- {
- if (field_clang_type_ptr)
- *field_clang_type_ptr = field_clang_type;
- return index;
- }
- }
- return UINT32_MAX;
-}
-
-// If a pointer to a pointee type (the clang_type arg) says that it has no
-// children, then we either need to trust it, or override it and return a
-// different result. For example, an "int *" has one child that is an integer,
-// but a function pointer doesn't have any children. Likewise if a Record type
-// claims it has no children, then there really is nothing to show.
-uint32_t
-ClangASTType::GetNumPointeeChildren () const
-{
- if (!IsValid())
- return 0;
-
- clang::QualType qual_type(GetCanonicalQualType());
- const clang::Type::TypeClass type_class = qual_type->getTypeClass();
- switch (type_class)
- {
- case clang::Type::Builtin:
- switch (llvm::cast<clang::BuiltinType>(qual_type)->getKind())
- {
- case clang::BuiltinType::UnknownAny:
- case clang::BuiltinType::Void:
- case clang::BuiltinType::NullPtr:
- case clang::BuiltinType::OCLEvent:
- case clang::BuiltinType::OCLImage1d:
- case clang::BuiltinType::OCLImage1dArray:
- case clang::BuiltinType::OCLImage1dBuffer:
- case clang::BuiltinType::OCLImage2d:
- case clang::BuiltinType::OCLImage2dArray:
- case clang::BuiltinType::OCLImage3d:
- case clang::BuiltinType::OCLSampler:
- return 0;
- case clang::BuiltinType::Bool:
- case clang::BuiltinType::Char_U:
- case clang::BuiltinType::UChar:
- case clang::BuiltinType::WChar_U:
- case clang::BuiltinType::Char16:
- case clang::BuiltinType::Char32:
- case clang::BuiltinType::UShort:
- case clang::BuiltinType::UInt:
- case clang::BuiltinType::ULong:
- case clang::BuiltinType::ULongLong:
- case clang::BuiltinType::UInt128:
- case clang::BuiltinType::Char_S:
- case clang::BuiltinType::SChar:
- case clang::BuiltinType::WChar_S:
- case clang::BuiltinType::Short:
- case clang::BuiltinType::Int:
- case clang::BuiltinType::Long:
- case clang::BuiltinType::LongLong:
- case clang::BuiltinType::Int128:
- case clang::BuiltinType::Float:
- case clang::BuiltinType::Double:
- case clang::BuiltinType::LongDouble:
- case clang::BuiltinType::Dependent:
- case clang::BuiltinType::Overload:
- case clang::BuiltinType::ObjCId:
- case clang::BuiltinType::ObjCClass:
- case clang::BuiltinType::ObjCSel:
- case clang::BuiltinType::BoundMember:
- case clang::BuiltinType::Half:
- case clang::BuiltinType::ARCUnbridgedCast:
- case clang::BuiltinType::PseudoObject:
- case clang::BuiltinType::BuiltinFn:
- return 1;
- }
- break;
-
- case clang::Type::Complex: return 1;
- case clang::Type::Pointer: return 1;
- case clang::Type::BlockPointer: return 0; // If block pointers don't have debug info, then no children for them
- case clang::Type::LValueReference: return 1;
- case clang::Type::RValueReference: return 1;
- case clang::Type::MemberPointer: return 0;
- case clang::Type::ConstantArray: return 0;
- case clang::Type::IncompleteArray: return 0;
- case clang::Type::VariableArray: return 0;
- case clang::Type::DependentSizedArray: return 0;
- case clang::Type::DependentSizedExtVector: return 0;
- case clang::Type::Vector: return 0;
- case clang::Type::ExtVector: return 0;
- case clang::Type::FunctionProto: return 0; // When we function pointers, they have no children...
- case clang::Type::FunctionNoProto: return 0; // When we function pointers, they have no children...
- case clang::Type::UnresolvedUsing: return 0;
- case clang::Type::Paren: return ClangASTType (m_ast, llvm::cast<clang::ParenType>(qual_type)->desugar()).GetNumPointeeChildren ();
- case clang::Type::Typedef: return ClangASTType (m_ast, llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType()).GetNumPointeeChildren ();
- case clang::Type::Elaborated: return ClangASTType (m_ast, llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType()).GetNumPointeeChildren ();
- case clang::Type::TypeOfExpr: return 0;
- case clang::Type::TypeOf: return 0;
- case clang::Type::Decltype: return 0;
- case clang::Type::Record: return 0;
- case clang::Type::Enum: return 1;
- case clang::Type::TemplateTypeParm: return 1;
- case clang::Type::SubstTemplateTypeParm: return 1;
- case clang::Type::TemplateSpecialization: return 1;
- case clang::Type::InjectedClassName: return 0;
- case clang::Type::DependentName: return 1;
- case clang::Type::DependentTemplateSpecialization: return 1;
- case clang::Type::ObjCObject: return 0;
- case clang::Type::ObjCInterface: return 0;
- case clang::Type::ObjCObjectPointer: return 1;
- default:
- break;
- }
- return 0;
-}
-
-
-ClangASTType
-ClangASTType::GetChildClangTypeAtIndex (ExecutionContext *exe_ctx,
- size_t idx,
- bool transparent_pointers,
- bool omit_empty_base_classes,
- bool ignore_array_bounds,
- std::string& child_name,
- uint32_t &child_byte_size,
- int32_t &child_byte_offset,
- uint32_t &child_bitfield_bit_size,
- uint32_t &child_bitfield_bit_offset,
- bool &child_is_base_class,
- bool &child_is_deref_of_parent,
- ValueObject *valobj) const
-{
- if (!IsValid())
- return ClangASTType();
-
- clang::QualType parent_qual_type(GetCanonicalQualType());
- const clang::Type::TypeClass parent_type_class = parent_qual_type->getTypeClass();
- child_bitfield_bit_size = 0;
- child_bitfield_bit_offset = 0;
- child_is_base_class = false;
-
- const bool idx_is_valid = idx < GetNumChildren (omit_empty_base_classes);
- uint32_t bit_offset;
- switch (parent_type_class)
- {
- case clang::Type::Builtin:
- if (idx_is_valid)
- {
- switch (llvm::cast<clang::BuiltinType>(parent_qual_type)->getKind())
- {
- case clang::BuiltinType::ObjCId:
- case clang::BuiltinType::ObjCClass:
- child_name = "isa";
- child_byte_size = m_ast->getTypeSize(m_ast->ObjCBuiltinClassTy) / CHAR_BIT;
- return ClangASTType (m_ast, m_ast->ObjCBuiltinClassTy);
-
- default:
- break;
- }
- }
- break;
-
- case clang::Type::Record:
- if (idx_is_valid && GetCompleteType())
- {
- const clang::RecordType *record_type = llvm::cast<clang::RecordType>(parent_qual_type.getTypePtr());
- const clang::RecordDecl *record_decl = record_type->getDecl();
- assert(record_decl);
- const clang::ASTRecordLayout &record_layout = m_ast->getASTRecordLayout(record_decl);
- uint32_t child_idx = 0;
-
- const clang::CXXRecordDecl *cxx_record_decl = llvm::dyn_cast<clang::CXXRecordDecl>(record_decl);
- if (cxx_record_decl)
- {
- // We might have base classes to print out first
- clang::CXXRecordDecl::base_class_const_iterator base_class, base_class_end;
- for (base_class = cxx_record_decl->bases_begin(), base_class_end = cxx_record_decl->bases_end();
- base_class != base_class_end;
- ++base_class)
- {
- const clang::CXXRecordDecl *base_class_decl = nullptr;
-
- // Skip empty base classes
- if (omit_empty_base_classes)
- {
- base_class_decl = llvm::cast<clang::CXXRecordDecl>(base_class->getType()->getAs<clang::RecordType>()->getDecl());
- if (ClangASTContext::RecordHasFields(base_class_decl) == false)
- continue;
- }
-
- if (idx == child_idx)
- {
- if (base_class_decl == nullptr)
- base_class_decl = llvm::cast<clang::CXXRecordDecl>(base_class->getType()->getAs<clang::RecordType>()->getDecl());
-
-
- if (base_class->isVirtual())
- {
- bool handled = false;
- if (valobj)
- {
- Error err;
- AddressType addr_type = eAddressTypeInvalid;
- lldb::addr_t vtable_ptr_addr = valobj->GetCPPVTableAddress(addr_type);
-
- if (vtable_ptr_addr != LLDB_INVALID_ADDRESS && addr_type == eAddressTypeLoad)
- {
-
- ExecutionContext exe_ctx (valobj->GetExecutionContextRef());
- Process *process = exe_ctx.GetProcessPtr();
- if (process)
- {
- clang::VTableContextBase *vtable_ctx = m_ast->getVTableContext();
- if (vtable_ctx)
- {
- if (vtable_ctx->isMicrosoft())
- {
- clang::MicrosoftVTableContext *msoft_vtable_ctx = static_cast<clang::MicrosoftVTableContext *>(vtable_ctx);
-
- if (vtable_ptr_addr)
- {
- const lldb::addr_t vbtable_ptr_addr = vtable_ptr_addr + record_layout.getVBPtrOffset().getQuantity();
-
- const lldb::addr_t vbtable_ptr = process->ReadPointerFromMemory(vbtable_ptr_addr, err);
- if (vbtable_ptr != LLDB_INVALID_ADDRESS)
- {
- // Get the index into the virtual base table. The index is the index in uint32_t from vbtable_ptr
- const unsigned vbtable_index = msoft_vtable_ctx->getVBTableIndex(cxx_record_decl, base_class_decl);
- const lldb::addr_t base_offset_addr = vbtable_ptr + vbtable_index * 4;
- const uint32_t base_offset = process->ReadUnsignedIntegerFromMemory(base_offset_addr, 4, UINT32_MAX, err);
- if (base_offset != UINT32_MAX)
- {
- handled = true;
- bit_offset = base_offset * 8;
- }
- }
- }
- }
- else
- {
- clang::ItaniumVTableContext *itanium_vtable_ctx = static_cast<clang::ItaniumVTableContext *>(vtable_ctx);
- if (vtable_ptr_addr)
- {
- const lldb::addr_t vtable_ptr = process->ReadPointerFromMemory(vtable_ptr_addr, err);
- if (vtable_ptr != LLDB_INVALID_ADDRESS)
- {
- clang::CharUnits base_offset_offset = itanium_vtable_ctx->getVirtualBaseOffsetOffset(cxx_record_decl, base_class_decl);
- const lldb::addr_t base_offset_addr = vtable_ptr + base_offset_offset.getQuantity();
- const uint32_t base_offset = process->ReadUnsignedIntegerFromMemory(base_offset_addr, 4, UINT32_MAX, err);
- if (base_offset != UINT32_MAX)
- {
- handled = true;
- bit_offset = base_offset * 8;
- }
- }
- }
- }
- }
- }
- }
-
- }
- if (!handled)
- bit_offset = record_layout.getVBaseClassOffset(base_class_decl).getQuantity() * 8;
- }
- else
- bit_offset = record_layout.getBaseClassOffset(base_class_decl).getQuantity() * 8;
-
- // Base classes should be a multiple of 8 bits in size
- child_byte_offset = bit_offset/8;
- ClangASTType base_class_clang_type(m_ast, base_class->getType());
- child_name = base_class_clang_type.GetTypeName().AsCString("");
- uint64_t base_class_clang_type_bit_size = base_class_clang_type.GetBitSize(exe_ctx ? exe_ctx->GetBestExecutionContextScope() : NULL);
-
- // Base classes bit sizes should be a multiple of 8 bits in size
- assert (base_class_clang_type_bit_size % 8 == 0);
- child_byte_size = base_class_clang_type_bit_size / 8;
- child_is_base_class = true;
- return base_class_clang_type;
- }
- // We don't increment the child index in the for loop since we might
- // be skipping empty base classes
- ++child_idx;
- }
- }
- // Make sure index is in range...
- uint32_t field_idx = 0;
- clang::RecordDecl::field_iterator field, field_end;
- for (field = record_decl->field_begin(), field_end = record_decl->field_end(); field != field_end; ++field, ++field_idx, ++child_idx)
- {
- if (idx == child_idx)
- {
- // Print the member type if requested
- // Print the member name and equal sign
- child_name.assign(field->getNameAsString().c_str());
-
- // Figure out the type byte size (field_type_info.first) and
- // alignment (field_type_info.second) from the AST context.
- ClangASTType field_clang_type (m_ast, field->getType());
- assert(field_idx < record_layout.getFieldCount());
- child_byte_size = field_clang_type.GetByteSize(exe_ctx ? exe_ctx->GetBestExecutionContextScope() : NULL);
-
- // Figure out the field offset within the current struct/union/class type
- bit_offset = record_layout.getFieldOffset (field_idx);
- child_byte_offset = bit_offset / 8;
- if (ClangASTContext::FieldIsBitfield (m_ast, *field, child_bitfield_bit_size))
- child_bitfield_bit_offset = bit_offset % 8;
-
- return field_clang_type;
- }
- }
- }
- break;
-
- case clang::Type::ObjCObject:
- case clang::Type::ObjCInterface:
- if (idx_is_valid && GetCompleteType())
- {
- const clang::ObjCObjectType *objc_class_type = llvm::dyn_cast<clang::ObjCObjectType>(parent_qual_type.getTypePtr());
- assert (objc_class_type);
- if (objc_class_type)
- {
- uint32_t child_idx = 0;
- clang::ObjCInterfaceDecl *class_interface_decl = objc_class_type->getInterface();
-
- if (class_interface_decl)
- {
-
- const clang::ASTRecordLayout &interface_layout = m_ast->getASTObjCInterfaceLayout(class_interface_decl);
- clang::ObjCInterfaceDecl *superclass_interface_decl = class_interface_decl->getSuperClass();
- if (superclass_interface_decl)
- {
- if (omit_empty_base_classes)
- {
- ClangASTType base_class_clang_type (m_ast, m_ast->getObjCInterfaceType(superclass_interface_decl));
- if (base_class_clang_type.GetNumChildren(omit_empty_base_classes) > 0)
- {
- if (idx == 0)
- {
- clang::QualType ivar_qual_type(m_ast->getObjCInterfaceType(superclass_interface_decl));
-
-
- child_name.assign(superclass_interface_decl->getNameAsString().c_str());
-
- clang::TypeInfo ivar_type_info = m_ast->getTypeInfo(ivar_qual_type.getTypePtr());
-
- child_byte_size = ivar_type_info.Width / 8;
- child_byte_offset = 0;
- child_is_base_class = true;
-
- return ClangASTType (m_ast, ivar_qual_type);
- }
-
- ++child_idx;
- }
- }
- else
- ++child_idx;
- }
-
- const uint32_t superclass_idx = child_idx;
-
- if (idx < (child_idx + class_interface_decl->ivar_size()))
- {
- clang::ObjCInterfaceDecl::ivar_iterator ivar_pos, ivar_end = class_interface_decl->ivar_end();
-
- for (ivar_pos = class_interface_decl->ivar_begin(); ivar_pos != ivar_end; ++ivar_pos)
- {
- if (child_idx == idx)
- {
- clang::ObjCIvarDecl* ivar_decl = *ivar_pos;
-
- clang::QualType ivar_qual_type(ivar_decl->getType());
-
- child_name.assign(ivar_decl->getNameAsString().c_str());
-
- clang::TypeInfo ivar_type_info = m_ast->getTypeInfo(ivar_qual_type.getTypePtr());
-
- child_byte_size = ivar_type_info.Width / 8;
-
- // Figure out the field offset within the current struct/union/class type
- // For ObjC objects, we can't trust the bit offset we get from the Clang AST, since
- // that doesn't account for the space taken up by unbacked properties, or from
- // the changing size of base classes that are newer than this class.
- // So if we have a process around that we can ask about this object, do so.
- child_byte_offset = LLDB_INVALID_IVAR_OFFSET;
- Process *process = nullptr;
- if (exe_ctx)
- process = exe_ctx->GetProcessPtr();
- if (process)
- {
- ObjCLanguageRuntime *objc_runtime = process->GetObjCLanguageRuntime();
- if (objc_runtime != nullptr)
- {
- ClangASTType parent_ast_type (m_ast, parent_qual_type);
- child_byte_offset = objc_runtime->GetByteOffsetForIvar (parent_ast_type, ivar_decl->getNameAsString().c_str());
- }
- }
-
- // Setting this to UINT32_MAX to make sure we don't compute it twice...
- bit_offset = UINT32_MAX;
-
- if (child_byte_offset == static_cast<int32_t>(LLDB_INVALID_IVAR_OFFSET))
- {
- bit_offset = interface_layout.getFieldOffset (child_idx - superclass_idx);
- child_byte_offset = bit_offset / 8;
- }
-
- // Note, the ObjC Ivar Byte offset is just that, it doesn't account for the bit offset
- // of a bitfield within its containing object. So regardless of where we get the byte
- // offset from, we still need to get the bit offset for bitfields from the layout.
-
- if (ClangASTContext::FieldIsBitfield (m_ast, ivar_decl, child_bitfield_bit_size))
- {
- if (bit_offset == UINT32_MAX)
- bit_offset = interface_layout.getFieldOffset (child_idx - superclass_idx);
-
- child_bitfield_bit_offset = bit_offset % 8;
- }
- return ClangASTType (m_ast, ivar_qual_type);
- }
- ++child_idx;
- }
- }
- }
- }
- }
- break;
-
- case clang::Type::ObjCObjectPointer:
- if (idx_is_valid)
- {
- ClangASTType pointee_clang_type (GetPointeeType());
-
- if (transparent_pointers && pointee_clang_type.IsAggregateType())
- {
- child_is_deref_of_parent = false;
- bool tmp_child_is_deref_of_parent = false;
- return pointee_clang_type.GetChildClangTypeAtIndex (exe_ctx,
- idx,
- transparent_pointers,
- omit_empty_base_classes,
- ignore_array_bounds,
- child_name,
- child_byte_size,
- child_byte_offset,
- child_bitfield_bit_size,
- child_bitfield_bit_offset,
- child_is_base_class,
- tmp_child_is_deref_of_parent,
- valobj);
- }
- else
- {
- child_is_deref_of_parent = true;
- const char *parent_name = valobj ? valobj->GetName().GetCString() : NULL;
- if (parent_name)
- {
- child_name.assign(1, '*');
- child_name += parent_name;
- }
-
- // We have a pointer to an simple type
- if (idx == 0 && pointee_clang_type.GetCompleteType())
- {
- child_byte_size = pointee_clang_type.GetByteSize(exe_ctx ? exe_ctx->GetBestExecutionContextScope() : NULL);
- child_byte_offset = 0;
- return pointee_clang_type;
- }
- }
- }
- break;
-
- case clang::Type::Vector:
- case clang::Type::ExtVector:
- if (idx_is_valid)
- {
- const clang::VectorType *array = llvm::cast<clang::VectorType>(parent_qual_type.getTypePtr());
- if (array)
- {
- ClangASTType element_type (m_ast, array->getElementType());
- if (element_type.GetCompleteType())
- {
- char element_name[64];
- ::snprintf(element_name, sizeof(element_name), "[%" PRIu64 "]", static_cast<uint64_t>(idx));
- child_name.assign(element_name);
- child_byte_size = element_type.GetByteSize(exe_ctx ? exe_ctx->GetBestExecutionContextScope() : NULL);
- child_byte_offset = (int32_t)idx * (int32_t)child_byte_size;
- return element_type;
- }
- }
- }
- break;
-
- case clang::Type::ConstantArray:
- case clang::Type::IncompleteArray:
- if (ignore_array_bounds || idx_is_valid)
- {
- const clang::ArrayType *array = GetQualType()->getAsArrayTypeUnsafe();
- if (array)
- {
- ClangASTType element_type (m_ast, array->getElementType());
- if (element_type.GetCompleteType())
- {
- char element_name[64];
- ::snprintf(element_name, sizeof(element_name), "[%" PRIu64 "]", static_cast<uint64_t>(idx));
- child_name.assign(element_name);
- child_byte_size = element_type.GetByteSize(exe_ctx ? exe_ctx->GetBestExecutionContextScope() : NULL);
- child_byte_offset = (int32_t)idx * (int32_t)child_byte_size;
- return element_type;
- }
- }
- }
- break;
-
-
- case clang::Type::Pointer:
- if (idx_is_valid)
- {
- ClangASTType pointee_clang_type (GetPointeeType());
-
- // Don't dereference "void *" pointers
- if (pointee_clang_type.IsVoidType())
- return ClangASTType();
-
- if (transparent_pointers && pointee_clang_type.IsAggregateType ())
- {
- child_is_deref_of_parent = false;
- bool tmp_child_is_deref_of_parent = false;
- return pointee_clang_type.GetChildClangTypeAtIndex (exe_ctx,
- idx,
- transparent_pointers,
- omit_empty_base_classes,
- ignore_array_bounds,
- child_name,
- child_byte_size,
- child_byte_offset,
- child_bitfield_bit_size,
- child_bitfield_bit_offset,
- child_is_base_class,
- tmp_child_is_deref_of_parent,
- valobj);
- }
- else
- {
- child_is_deref_of_parent = true;
-
- const char *parent_name = valobj ? valobj->GetName().GetCString() : NULL;
- if (parent_name)
- {
- child_name.assign(1, '*');
- child_name += parent_name;
- }
-
- // We have a pointer to an simple type
- if (idx == 0)
- {
- child_byte_size = pointee_clang_type.GetByteSize(exe_ctx ? exe_ctx->GetBestExecutionContextScope() : NULL);
- child_byte_offset = 0;
- return pointee_clang_type;
- }
- }
- }
- break;
-
- case clang::Type::LValueReference:
- case clang::Type::RValueReference:
- if (idx_is_valid)
- {
- const clang::ReferenceType *reference_type = llvm::cast<clang::ReferenceType>(parent_qual_type.getTypePtr());
- ClangASTType pointee_clang_type (m_ast, reference_type->getPointeeType());
- if (transparent_pointers && pointee_clang_type.IsAggregateType ())
- {
- child_is_deref_of_parent = false;
- bool tmp_child_is_deref_of_parent = false;
- return pointee_clang_type.GetChildClangTypeAtIndex (exe_ctx,
- idx,
- transparent_pointers,
- omit_empty_base_classes,
- ignore_array_bounds,
- child_name,
- child_byte_size,
- child_byte_offset,
- child_bitfield_bit_size,
- child_bitfield_bit_offset,
- child_is_base_class,
- tmp_child_is_deref_of_parent,
- valobj);
- }
- else
- {
- const char *parent_name = valobj ? valobj->GetName().GetCString() : NULL;
- if (parent_name)
- {
- child_name.assign(1, '&');
- child_name += parent_name;
- }
-
- // We have a pointer to an simple type
- if (idx == 0)
- {
- child_byte_size = pointee_clang_type.GetByteSize(exe_ctx ? exe_ctx->GetBestExecutionContextScope() : NULL);
- child_byte_offset = 0;
- return pointee_clang_type;
- }
- }
- }
- break;
-
- case clang::Type::Typedef:
- {
- ClangASTType typedefed_clang_type (m_ast, llvm::cast<clang::TypedefType>(parent_qual_type)->getDecl()->getUnderlyingType());
- return typedefed_clang_type.GetChildClangTypeAtIndex (exe_ctx,
- idx,
- transparent_pointers,
- omit_empty_base_classes,
- ignore_array_bounds,
- child_name,
- child_byte_size,
- child_byte_offset,
- child_bitfield_bit_size,
- child_bitfield_bit_offset,
- child_is_base_class,
- child_is_deref_of_parent,
- valobj);
- }
- break;
-
- case clang::Type::Elaborated:
- {
- ClangASTType elaborated_clang_type (m_ast, llvm::cast<clang::ElaboratedType>(parent_qual_type)->getNamedType());
- return elaborated_clang_type.GetChildClangTypeAtIndex (exe_ctx,
- idx,
- transparent_pointers,
- omit_empty_base_classes,
- ignore_array_bounds,
- child_name,
- child_byte_size,
- child_byte_offset,
- child_bitfield_bit_size,
- child_bitfield_bit_offset,
- child_is_base_class,
- child_is_deref_of_parent,
- valobj);
- }
-
- case clang::Type::Paren:
- {
- ClangASTType paren_clang_type (m_ast, llvm::cast<clang::ParenType>(parent_qual_type)->desugar());
- return paren_clang_type.GetChildClangTypeAtIndex (exe_ctx,
- idx,
- transparent_pointers,
- omit_empty_base_classes,
- ignore_array_bounds,
- child_name,
- child_byte_size,
- child_byte_offset,
- child_bitfield_bit_size,
- child_bitfield_bit_offset,
- child_is_base_class,
- child_is_deref_of_parent,
- valobj);
- }
-
-
- default:
- break;
- }
- return ClangASTType();
-}
-
-static inline bool
-BaseSpecifierIsEmpty (const clang::CXXBaseSpecifier *b)
-{
- return ClangASTContext::RecordHasFields(b->getType()->getAsCXXRecordDecl()) == false;
-}
-
-static uint32_t
-GetIndexForRecordBase
-(
- const clang::RecordDecl *record_decl,
- const clang::CXXBaseSpecifier *base_spec,
- bool omit_empty_base_classes
- )
-{
- uint32_t child_idx = 0;
-
- const clang::CXXRecordDecl *cxx_record_decl = llvm::dyn_cast<clang::CXXRecordDecl>(record_decl);
-
- // const char *super_name = record_decl->getNameAsCString();
- // const char *base_name = base_spec->getType()->getAs<clang::RecordType>()->getDecl()->getNameAsCString();
- // printf ("GetIndexForRecordChild (%s, %s)\n", super_name, base_name);
- //
- if (cxx_record_decl)
- {
- clang::CXXRecordDecl::base_class_const_iterator base_class, base_class_end;
- for (base_class = cxx_record_decl->bases_begin(), base_class_end = cxx_record_decl->bases_end();
- base_class != base_class_end;
- ++base_class)
- {
- if (omit_empty_base_classes)
- {
- if (BaseSpecifierIsEmpty (base_class))
- continue;
- }
-
- // printf ("GetIndexForRecordChild (%s, %s) base[%u] = %s\n", super_name, base_name,
- // child_idx,
- // base_class->getType()->getAs<clang::RecordType>()->getDecl()->getNameAsCString());
- //
- //
- if (base_class == base_spec)
- return child_idx;
- ++child_idx;
- }
- }
-
- return UINT32_MAX;
-}
-
-
-static uint32_t
-GetIndexForRecordChild (const clang::RecordDecl *record_decl,
- clang::NamedDecl *canonical_decl,
- bool omit_empty_base_classes)
-{
- uint32_t child_idx = ClangASTContext::GetNumBaseClasses (llvm::dyn_cast<clang::CXXRecordDecl>(record_decl),
- omit_empty_base_classes);
-
- clang::RecordDecl::field_iterator field, field_end;
- for (field = record_decl->field_begin(), field_end = record_decl->field_end();
- field != field_end;
- ++field, ++child_idx)
- {
- if (field->getCanonicalDecl() == canonical_decl)
- return child_idx;
- }
-
- return UINT32_MAX;
-}
-
-// Look for a child member (doesn't include base classes, but it does include
-// their members) in the type hierarchy. Returns an index path into "clang_type"
-// on how to reach the appropriate member.
-//
-// class A
-// {
-// public:
-// int m_a;
-// int m_b;
-// };
-//
-// class B
-// {
-// };
-//
-// class C :
-// public B,
-// public A
-// {
-// };
-//
-// If we have a clang type that describes "class C", and we wanted to looked
-// "m_b" in it:
-//
-// With omit_empty_base_classes == false we would get an integer array back with:
-// { 1, 1 }
-// The first index 1 is the child index for "class A" within class C
-// The second index 1 is the child index for "m_b" within class A
-//
-// With omit_empty_base_classes == true we would get an integer array back with:
-// { 0, 1 }
-// The first index 0 is the child index for "class A" within class C (since class B doesn't have any members it doesn't count)
-// The second index 1 is the child index for "m_b" within class A
-
-size_t
-ClangASTType::GetIndexOfChildMemberWithName (const char *name,
- bool omit_empty_base_classes,
- std::vector<uint32_t>& child_indexes) const
-{
- if (IsValid() && name && name[0])
- {
- clang::QualType qual_type(GetCanonicalQualType());
- const clang::Type::TypeClass type_class = qual_type->getTypeClass();
- switch (type_class)
- {
- case clang::Type::Record:
- if (GetCompleteType ())
- {
- const clang::RecordType *record_type = llvm::cast<clang::RecordType>(qual_type.getTypePtr());
- const clang::RecordDecl *record_decl = record_type->getDecl();
-
- assert(record_decl);
- uint32_t child_idx = 0;
-
- const clang::CXXRecordDecl *cxx_record_decl = llvm::dyn_cast<clang::CXXRecordDecl>(record_decl);
-
- // Try and find a field that matches NAME
- clang::RecordDecl::field_iterator field, field_end;
- llvm::StringRef name_sref(name);
- for (field = record_decl->field_begin(), field_end = record_decl->field_end();
- field != field_end;
- ++field, ++child_idx)
- {
- llvm::StringRef field_name = field->getName();
- if (field_name.empty())
- {
- ClangASTType field_type(m_ast,field->getType());
- child_indexes.push_back(child_idx);
- if (field_type.GetIndexOfChildMemberWithName(name, omit_empty_base_classes, child_indexes))
- return child_indexes.size();
- child_indexes.pop_back();
-
- }
- else if (field_name.equals (name_sref))
- {
- // We have to add on the number of base classes to this index!
- child_indexes.push_back (child_idx + ClangASTContext::GetNumBaseClasses (cxx_record_decl, omit_empty_base_classes));
- return child_indexes.size();
- }
- }
-
- if (cxx_record_decl)
- {
- const clang::RecordDecl *parent_record_decl = cxx_record_decl;
-
- //printf ("parent = %s\n", parent_record_decl->getNameAsCString());
-
- //const Decl *root_cdecl = cxx_record_decl->getCanonicalDecl();
- // Didn't find things easily, lets let clang do its thang...
- clang::IdentifierInfo & ident_ref = m_ast->Idents.get(name_sref);
- clang::DeclarationName decl_name(&ident_ref);
-
- clang::CXXBasePaths paths;
- if (cxx_record_decl->lookupInBases(clang::CXXRecordDecl::FindOrdinaryMember,
- decl_name.getAsOpaquePtr(),
- paths))
- {
- clang::CXXBasePaths::const_paths_iterator path, path_end = paths.end();
- for (path = paths.begin(); path != path_end; ++path)
- {
- const size_t num_path_elements = path->size();
- for (size_t e=0; e<num_path_elements; ++e)
- {
- clang::CXXBasePathElement elem = (*path)[e];
-
- child_idx = GetIndexForRecordBase (parent_record_decl, elem.Base, omit_empty_base_classes);
- if (child_idx == UINT32_MAX)
- {
- child_indexes.clear();
- return 0;
- }
- else
- {
- child_indexes.push_back (child_idx);
- parent_record_decl = llvm::cast<clang::RecordDecl>(elem.Base->getType()->getAs<clang::RecordType>()->getDecl());
- }
- }
- for (clang::NamedDecl *path_decl : path->Decls)
- {
- child_idx = GetIndexForRecordChild (parent_record_decl, path_decl, omit_empty_base_classes);
- if (child_idx == UINT32_MAX)
- {
- child_indexes.clear();
- return 0;
- }
- else
- {
- child_indexes.push_back (child_idx);
- }
- }
- }
- return child_indexes.size();
- }
- }
-
- }
- break;
-
- case clang::Type::ObjCObject:
- case clang::Type::ObjCInterface:
- if (GetCompleteType ())
- {
- llvm::StringRef name_sref(name);
- const clang::ObjCObjectType *objc_class_type = llvm::dyn_cast<clang::ObjCObjectType>(qual_type.getTypePtr());
- assert (objc_class_type);
- if (objc_class_type)
- {
- uint32_t child_idx = 0;
- clang::ObjCInterfaceDecl *class_interface_decl = objc_class_type->getInterface();
-
- if (class_interface_decl)
- {
- clang::ObjCInterfaceDecl::ivar_iterator ivar_pos, ivar_end = class_interface_decl->ivar_end();
- clang::ObjCInterfaceDecl *superclass_interface_decl = class_interface_decl->getSuperClass();
-
- for (ivar_pos = class_interface_decl->ivar_begin(); ivar_pos != ivar_end; ++ivar_pos, ++child_idx)
- {
- const clang::ObjCIvarDecl* ivar_decl = *ivar_pos;
-
- if (ivar_decl->getName().equals (name_sref))
- {
- if ((!omit_empty_base_classes && superclass_interface_decl) ||
- ( omit_empty_base_classes && ObjCDeclHasIVars (superclass_interface_decl, true)))
- ++child_idx;
-
- child_indexes.push_back (child_idx);
- return child_indexes.size();
- }
- }
-
- if (superclass_interface_decl)
- {
- // The super class index is always zero for ObjC classes,
- // so we push it onto the child indexes in case we find
- // an ivar in our superclass...
- child_indexes.push_back (0);
-
- ClangASTType superclass_clang_type (m_ast, m_ast->getObjCInterfaceType(superclass_interface_decl));
- if (superclass_clang_type.GetIndexOfChildMemberWithName (name,
- omit_empty_base_classes,
- child_indexes))
- {
- // We did find an ivar in a superclass so just
- // return the results!
- return child_indexes.size();
- }
-
- // We didn't find an ivar matching "name" in our
- // superclass, pop the superclass zero index that
- // we pushed on above.
- child_indexes.pop_back();
- }
- }
- }
- }
- break;
-
- case clang::Type::ObjCObjectPointer:
- {
- ClangASTType objc_object_clang_type (m_ast, llvm::cast<clang::ObjCObjectPointerType>(qual_type.getTypePtr())->getPointeeType());
- return objc_object_clang_type.GetIndexOfChildMemberWithName (name,
- omit_empty_base_classes,
- child_indexes);
- }
- break;
-
-
- case clang::Type::ConstantArray:
- {
- // const clang::ConstantArrayType *array = llvm::cast<clang::ConstantArrayType>(parent_qual_type.getTypePtr());
- // const uint64_t element_count = array->getSize().getLimitedValue();
- //
- // if (idx < element_count)
- // {
- // std::pair<uint64_t, unsigned> field_type_info = ast->getTypeInfo(array->getElementType());
- //
- // char element_name[32];
- // ::snprintf (element_name, sizeof (element_name), "%s[%u]", parent_name ? parent_name : "", idx);
- //
- // child_name.assign(element_name);
- // assert(field_type_info.first % 8 == 0);
- // child_byte_size = field_type_info.first / 8;
- // child_byte_offset = idx * child_byte_size;
- // return array->getElementType().getAsOpaquePtr();
- // }
- }
- break;
-
- // case clang::Type::MemberPointerType:
- // {
- // MemberPointerType *mem_ptr_type = llvm::cast<MemberPointerType>(qual_type.getTypePtr());
- // clang::QualType pointee_type = mem_ptr_type->getPointeeType();
- //
- // if (ClangASTContext::IsAggregateType (pointee_type.getAsOpaquePtr()))
- // {
- // return GetIndexOfChildWithName (ast,
- // mem_ptr_type->getPointeeType().getAsOpaquePtr(),
- // name);
- // }
- // }
- // break;
- //
- case clang::Type::LValueReference:
- case clang::Type::RValueReference:
- {
- const clang::ReferenceType *reference_type = llvm::cast<clang::ReferenceType>(qual_type.getTypePtr());
- clang::QualType pointee_type(reference_type->getPointeeType());
- ClangASTType pointee_clang_type (m_ast, pointee_type);
-
- if (pointee_clang_type.IsAggregateType ())
- {
- return pointee_clang_type.GetIndexOfChildMemberWithName (name,
- omit_empty_base_classes,
- child_indexes);
- }
- }
- break;
-
- case clang::Type::Pointer:
- {
- ClangASTType pointee_clang_type (GetPointeeType());
-
- if (pointee_clang_type.IsAggregateType ())
- {
- return pointee_clang_type.GetIndexOfChildMemberWithName (name,
- omit_empty_base_classes,
- child_indexes);
- }
- }
- break;
-
- case clang::Type::Typedef:
- return ClangASTType (m_ast, llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType()).GetIndexOfChildMemberWithName (name,
- omit_empty_base_classes,
- child_indexes);
-
- case clang::Type::Elaborated:
- return ClangASTType (m_ast, llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType()).GetIndexOfChildMemberWithName (name,
- omit_empty_base_classes,
- child_indexes);
-
- case clang::Type::Paren:
- return ClangASTType (m_ast, llvm::cast<clang::ParenType>(qual_type)->desugar()).GetIndexOfChildMemberWithName (name,
- omit_empty_base_classes,
- child_indexes);
-
- default:
- break;
- }
- }
- return 0;
-}
-
-
-// Get the index of the child of "clang_type" whose name matches. This function
-// doesn't descend into the children, but only looks one level deep and name
-// matches can include base class names.
-
-uint32_t
-ClangASTType::GetIndexOfChildWithName (const char *name, bool omit_empty_base_classes) const
-{
- if (IsValid() && name && name[0])
- {
- clang::QualType qual_type(GetCanonicalQualType());
-
- const clang::Type::TypeClass type_class = qual_type->getTypeClass();
-
- switch (type_class)
- {
- case clang::Type::Record:
- if (GetCompleteType ())
- {
- const clang::RecordType *record_type = llvm::cast<clang::RecordType>(qual_type.getTypePtr());
- const clang::RecordDecl *record_decl = record_type->getDecl();
-
- assert(record_decl);
- uint32_t child_idx = 0;
-
- const clang::CXXRecordDecl *cxx_record_decl = llvm::dyn_cast<clang::CXXRecordDecl>(record_decl);
-
- if (cxx_record_decl)
- {
- clang::CXXRecordDecl::base_class_const_iterator base_class, base_class_end;
- for (base_class = cxx_record_decl->bases_begin(), base_class_end = cxx_record_decl->bases_end();
- base_class != base_class_end;
- ++base_class)
- {
- // Skip empty base classes
- clang::CXXRecordDecl *base_class_decl = llvm::cast<clang::CXXRecordDecl>(base_class->getType()->getAs<clang::RecordType>()->getDecl());
- if (omit_empty_base_classes && ClangASTContext::RecordHasFields(base_class_decl) == false)
- continue;
-
- ClangASTType base_class_clang_type (m_ast, base_class->getType());
- std::string base_class_type_name (base_class_clang_type.GetTypeName().AsCString(""));
- if (base_class_type_name.compare (name) == 0)
- return child_idx;
- ++child_idx;
- }
- }
-
- // Try and find a field that matches NAME
- clang::RecordDecl::field_iterator field, field_end;
- llvm::StringRef name_sref(name);
- for (field = record_decl->field_begin(), field_end = record_decl->field_end();
- field != field_end;
- ++field, ++child_idx)
- {
- if (field->getName().equals (name_sref))
- return child_idx;
- }
-
- }
- break;
-
- case clang::Type::ObjCObject:
- case clang::Type::ObjCInterface:
- if (GetCompleteType())
- {
- llvm::StringRef name_sref(name);
- const clang::ObjCObjectType *objc_class_type = llvm::dyn_cast<clang::ObjCObjectType>(qual_type.getTypePtr());
- assert (objc_class_type);
- if (objc_class_type)
- {
- uint32_t child_idx = 0;
- clang::ObjCInterfaceDecl *class_interface_decl = objc_class_type->getInterface();
-
- if (class_interface_decl)
- {
- clang::ObjCInterfaceDecl::ivar_iterator ivar_pos, ivar_end = class_interface_decl->ivar_end();
- clang::ObjCInterfaceDecl *superclass_interface_decl = class_interface_decl->getSuperClass();
-
- for (ivar_pos = class_interface_decl->ivar_begin(); ivar_pos != ivar_end; ++ivar_pos, ++child_idx)
- {
- const clang::ObjCIvarDecl* ivar_decl = *ivar_pos;
-
- if (ivar_decl->getName().equals (name_sref))
- {
- if ((!omit_empty_base_classes && superclass_interface_decl) ||
- ( omit_empty_base_classes && ObjCDeclHasIVars (superclass_interface_decl, true)))
- ++child_idx;
-
- return child_idx;
- }
- }
-
- if (superclass_interface_decl)
- {
- if (superclass_interface_decl->getName().equals (name_sref))
- return 0;
- }
- }
- }
- }
- break;
-
- case clang::Type::ObjCObjectPointer:
- {
- ClangASTType pointee_clang_type (m_ast, llvm::cast<clang::ObjCObjectPointerType>(qual_type.getTypePtr())->getPointeeType());
- return pointee_clang_type.GetIndexOfChildWithName (name, omit_empty_base_classes);
- }
- break;
-
- case clang::Type::ConstantArray:
- {
- // const clang::ConstantArrayType *array = llvm::cast<clang::ConstantArrayType>(parent_qual_type.getTypePtr());
- // const uint64_t element_count = array->getSize().getLimitedValue();
- //
- // if (idx < element_count)
- // {
- // std::pair<uint64_t, unsigned> field_type_info = ast->getTypeInfo(array->getElementType());
- //
- // char element_name[32];
- // ::snprintf (element_name, sizeof (element_name), "%s[%u]", parent_name ? parent_name : "", idx);
- //
- // child_name.assign(element_name);
- // assert(field_type_info.first % 8 == 0);
- // child_byte_size = field_type_info.first / 8;
- // child_byte_offset = idx * child_byte_size;
- // return array->getElementType().getAsOpaquePtr();
- // }
- }
- break;
-
- // case clang::Type::MemberPointerType:
- // {
- // MemberPointerType *mem_ptr_type = llvm::cast<MemberPointerType>(qual_type.getTypePtr());
- // clang::QualType pointee_type = mem_ptr_type->getPointeeType();
- //
- // if (ClangASTContext::IsAggregateType (pointee_type.getAsOpaquePtr()))
- // {
- // return GetIndexOfChildWithName (ast,
- // mem_ptr_type->getPointeeType().getAsOpaquePtr(),
- // name);
- // }
- // }
- // break;
- //
- case clang::Type::LValueReference:
- case clang::Type::RValueReference:
- {
- const clang::ReferenceType *reference_type = llvm::cast<clang::ReferenceType>(qual_type.getTypePtr());
- ClangASTType pointee_type (m_ast, reference_type->getPointeeType());
-
- if (pointee_type.IsAggregateType ())
- {
- return pointee_type.GetIndexOfChildWithName (name, omit_empty_base_classes);
- }
- }
- break;
-
- case clang::Type::Pointer:
- {
- const clang::PointerType *pointer_type = llvm::cast<clang::PointerType>(qual_type.getTypePtr());
- ClangASTType pointee_type (m_ast, pointer_type->getPointeeType());
-
- if (pointee_type.IsAggregateType ())
- {
- return pointee_type.GetIndexOfChildWithName (name, omit_empty_base_classes);
- }
- else
- {
- // if (parent_name)
- // {
- // child_name.assign(1, '*');
- // child_name += parent_name;
- // }
- //
- // // We have a pointer to an simple type
- // if (idx == 0)
- // {
- // std::pair<uint64_t, unsigned> clang_type_info = ast->getTypeInfo(pointee_type);
- // assert(clang_type_info.first % 8 == 0);
- // child_byte_size = clang_type_info.first / 8;
- // child_byte_offset = 0;
- // return pointee_type.getAsOpaquePtr();
- // }
- }
- }
- break;
-
- case clang::Type::Elaborated:
- return ClangASTType (m_ast, llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType()).GetIndexOfChildWithName (name, omit_empty_base_classes);
-
- case clang::Type::Paren:
- return ClangASTType (m_ast, llvm::cast<clang::ParenType>(qual_type)->desugar()).GetIndexOfChildWithName (name, omit_empty_base_classes);
-
- case clang::Type::Typedef:
- return ClangASTType (m_ast, llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType()).GetIndexOfChildWithName (name, omit_empty_base_classes);
-
- default:
- break;
- }
- }
- return UINT32_MAX;
-}
-
-
-size_t
-ClangASTType::GetNumTemplateArguments () const
-{
- if (IsValid())
- {
- clang::QualType qual_type (GetCanonicalQualType());
-
- const clang::Type::TypeClass type_class = qual_type->getTypeClass();
- switch (type_class)
- {
- case clang::Type::Record:
- if (GetCompleteType ())
- {
- const clang::CXXRecordDecl *cxx_record_decl = qual_type->getAsCXXRecordDecl();
- if (cxx_record_decl)
- {
- const clang::ClassTemplateSpecializationDecl *template_decl = llvm::dyn_cast<clang::ClassTemplateSpecializationDecl>(cxx_record_decl);
- if (template_decl)
- return template_decl->getTemplateArgs().size();
- }
- }
- break;
-
- case clang::Type::Typedef:
- return ClangASTType (m_ast, llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType()).GetNumTemplateArguments();
-
- case clang::Type::Elaborated:
- return ClangASTType (m_ast, llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType()).GetNumTemplateArguments();
-
- case clang::Type::Paren:
- return ClangASTType (m_ast, llvm::cast<clang::ParenType>(qual_type)->desugar()).GetNumTemplateArguments();
-
- default:
- break;
- }
- }
- return 0;
-}
-
-ClangASTType
-ClangASTType::GetTemplateArgument (size_t arg_idx, lldb::TemplateArgumentKind &kind) const
-{
- if (IsValid())
- {
- clang::QualType qual_type (GetCanonicalQualType());
-
- const clang::Type::TypeClass type_class = qual_type->getTypeClass();
- switch (type_class)
- {
- case clang::Type::Record:
- if (GetCompleteType ())
- {
- const clang::CXXRecordDecl *cxx_record_decl = qual_type->getAsCXXRecordDecl();
- if (cxx_record_decl)
- {
- const clang::ClassTemplateSpecializationDecl *template_decl = llvm::dyn_cast<clang::ClassTemplateSpecializationDecl>(cxx_record_decl);
- if (template_decl && arg_idx < template_decl->getTemplateArgs().size())
- {
- const clang::TemplateArgument &template_arg = template_decl->getTemplateArgs()[arg_idx];
- switch (template_arg.getKind())
- {
- case clang::TemplateArgument::Null:
- kind = eTemplateArgumentKindNull;
- return ClangASTType();
-
- case clang::TemplateArgument::Type:
- kind = eTemplateArgumentKindType;
- return ClangASTType(m_ast, template_arg.getAsType());
-
- case clang::TemplateArgument::Declaration:
- kind = eTemplateArgumentKindDeclaration;
- return ClangASTType();
-
- case clang::TemplateArgument::Integral:
- kind = eTemplateArgumentKindIntegral;
- return ClangASTType(m_ast, template_arg.getIntegralType());
-
- case clang::TemplateArgument::Template:
- kind = eTemplateArgumentKindTemplate;
- return ClangASTType();
-
- case clang::TemplateArgument::TemplateExpansion:
- kind = eTemplateArgumentKindTemplateExpansion;
- return ClangASTType();
-
- case clang::TemplateArgument::Expression:
- kind = eTemplateArgumentKindExpression;
- return ClangASTType();
-
- case clang::TemplateArgument::Pack:
- kind = eTemplateArgumentKindPack;
- return ClangASTType();
-
- default:
- assert (!"Unhandled clang::TemplateArgument::ArgKind");
- break;
- }
- }
- }
- }
- break;
-
- case clang::Type::Typedef:
- return ClangASTType (m_ast, llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType()).GetTemplateArgument (arg_idx, kind);
-
- case clang::Type::Elaborated:
- return ClangASTType (m_ast, llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType()).GetTemplateArgument (arg_idx, kind);
-
- case clang::Type::Paren:
- return ClangASTType (m_ast, llvm::cast<clang::ParenType>(qual_type)->desugar()).GetTemplateArgument (arg_idx, kind);
-
- default:
- break;
- }
- }
- kind = eTemplateArgumentKindNull;
- return ClangASTType ();
-}
-
-static bool
-IsOperator (const char *name, clang::OverloadedOperatorKind &op_kind)
-{
- if (name == nullptr || name[0] == '\0')
- return false;
-
-#define OPERATOR_PREFIX "operator"
-#define OPERATOR_PREFIX_LENGTH (sizeof (OPERATOR_PREFIX) - 1)
-
- const char *post_op_name = nullptr;
-
- bool no_space = true;
-
- if (::strncmp(name, OPERATOR_PREFIX, OPERATOR_PREFIX_LENGTH))
- return false;
-
- post_op_name = name + OPERATOR_PREFIX_LENGTH;
-
- if (post_op_name[0] == ' ')
- {
- post_op_name++;
- no_space = false;
- }
-
-#undef OPERATOR_PREFIX
-#undef OPERATOR_PREFIX_LENGTH
-
- // This is an operator, set the overloaded operator kind to invalid
- // in case this is a conversion operator...
- op_kind = clang::NUM_OVERLOADED_OPERATORS;
-
- switch (post_op_name[0])
- {
- default:
- if (no_space)
- return false;
- break;
- case 'n':
- if (no_space)
- return false;
- if (strcmp (post_op_name, "new") == 0)
- op_kind = clang::OO_New;
- else if (strcmp (post_op_name, "new[]") == 0)
- op_kind = clang::OO_Array_New;
- break;
-
- case 'd':
- if (no_space)
- return false;
- if (strcmp (post_op_name, "delete") == 0)
- op_kind = clang::OO_Delete;
- else if (strcmp (post_op_name, "delete[]") == 0)
- op_kind = clang::OO_Array_Delete;
- break;
-
- case '+':
- if (post_op_name[1] == '\0')
- op_kind = clang::OO_Plus;
- else if (post_op_name[2] == '\0')
- {
- if (post_op_name[1] == '=')
- op_kind = clang::OO_PlusEqual;
- else if (post_op_name[1] == '+')
- op_kind = clang::OO_PlusPlus;
- }
- break;
-
- case '-':
- if (post_op_name[1] == '\0')
- op_kind = clang::OO_Minus;
- else if (post_op_name[2] == '\0')
- {
- switch (post_op_name[1])
- {
- case '=': op_kind = clang::OO_MinusEqual; break;
- case '-': op_kind = clang::OO_MinusMinus; break;
- case '>': op_kind = clang::OO_Arrow; break;
- }
- }
- else if (post_op_name[3] == '\0')
- {
- if (post_op_name[2] == '*')
- op_kind = clang::OO_ArrowStar; break;
- }
- break;
-
- case '*':
- if (post_op_name[1] == '\0')
- op_kind = clang::OO_Star;
- else if (post_op_name[1] == '=' && post_op_name[2] == '\0')
- op_kind = clang::OO_StarEqual;
- break;
-
- case '/':
- if (post_op_name[1] == '\0')
- op_kind = clang::OO_Slash;
- else if (post_op_name[1] == '=' && post_op_name[2] == '\0')
- op_kind = clang::OO_SlashEqual;
- break;
-
- case '%':
- if (post_op_name[1] == '\0')
- op_kind = clang::OO_Percent;
- else if (post_op_name[1] == '=' && post_op_name[2] == '\0')
- op_kind = clang::OO_PercentEqual;
- break;
-
-
- case '^':
- if (post_op_name[1] == '\0')
- op_kind = clang::OO_Caret;
- else if (post_op_name[1] == '=' && post_op_name[2] == '\0')
- op_kind = clang::OO_CaretEqual;
- break;
-
- case '&':
- if (post_op_name[1] == '\0')
- op_kind = clang::OO_Amp;
- else if (post_op_name[2] == '\0')
- {
- switch (post_op_name[1])
- {
- case '=': op_kind = clang::OO_AmpEqual; break;
- case '&': op_kind = clang::OO_AmpAmp; break;
- }
- }
- break;
-
- case '|':
- if (post_op_name[1] == '\0')
- op_kind = clang::OO_Pipe;
- else if (post_op_name[2] == '\0')
- {
- switch (post_op_name[1])
- {
- case '=': op_kind = clang::OO_PipeEqual; break;
- case '|': op_kind = clang::OO_PipePipe; break;
- }
- }
- break;
-
- case '~':
- if (post_op_name[1] == '\0')
- op_kind = clang::OO_Tilde;
- break;
-
- case '!':
- if (post_op_name[1] == '\0')
- op_kind = clang::OO_Exclaim;
- else if (post_op_name[1] == '=' && post_op_name[2] == '\0')
- op_kind = clang::OO_ExclaimEqual;
- break;
-
- case '=':
- if (post_op_name[1] == '\0')
- op_kind = clang::OO_Equal;
- else if (post_op_name[1] == '=' && post_op_name[2] == '\0')
- op_kind = clang::OO_EqualEqual;
- break;
-
- case '<':
- if (post_op_name[1] == '\0')
- op_kind = clang::OO_Less;
- else if (post_op_name[2] == '\0')
- {
- switch (post_op_name[1])
- {
- case '<': op_kind = clang::OO_LessLess; break;
- case '=': op_kind = clang::OO_LessEqual; break;
- }
- }
- else if (post_op_name[3] == '\0')
- {
- if (post_op_name[2] == '=')
- op_kind = clang::OO_LessLessEqual;
- }
- break;
-
- case '>':
- if (post_op_name[1] == '\0')
- op_kind = clang::OO_Greater;
- else if (post_op_name[2] == '\0')
- {
- switch (post_op_name[1])
- {
- case '>': op_kind = clang::OO_GreaterGreater; break;
- case '=': op_kind = clang::OO_GreaterEqual; break;
- }
- }
- else if (post_op_name[1] == '>' &&
- post_op_name[2] == '=' &&
- post_op_name[3] == '\0')
- {
- op_kind = clang::OO_GreaterGreaterEqual;
- }
- break;
-
- case ',':
- if (post_op_name[1] == '\0')
- op_kind = clang::OO_Comma;
- break;
-
- case '(':
- if (post_op_name[1] == ')' && post_op_name[2] == '\0')
- op_kind = clang::OO_Call;
- break;
-
- case '[':
- if (post_op_name[1] == ']' && post_op_name[2] == '\0')
- op_kind = clang::OO_Subscript;
- break;
- }
-
- return true;
-}
-
-clang::EnumDecl *
-ClangASTType::GetAsEnumDecl () const
-{
- const clang::EnumType *enum_type = llvm::dyn_cast<clang::EnumType>(GetCanonicalQualType());
- if (enum_type)
- return enum_type->getDecl();
- return NULL;
-}
-
-clang::RecordDecl *
-ClangASTType::GetAsRecordDecl () const
-{
- const clang::RecordType *record_type = llvm::dyn_cast<clang::RecordType>(GetCanonicalQualType());
- if (record_type)
- return record_type->getDecl();
- return nullptr;
-}
-
-clang::CXXRecordDecl *
-ClangASTType::GetAsCXXRecordDecl () const
-{
- return GetCanonicalQualType()->getAsCXXRecordDecl();
-}
-
-clang::ObjCInterfaceDecl *
-ClangASTType::GetAsObjCInterfaceDecl () const
-{
- const clang::ObjCObjectType *objc_class_type = llvm::dyn_cast<clang::ObjCObjectType>(GetCanonicalQualType());
- if (objc_class_type)
- return objc_class_type->getInterface();
- return nullptr;
-}
-
-clang::FieldDecl *
-ClangASTType::AddFieldToRecordType (const char *name,
- const ClangASTType &field_clang_type,
- AccessType access,
- uint32_t bitfield_bit_size)
-{
- if (!IsValid() || !field_clang_type.IsValid())
- return nullptr;
-
- clang::FieldDecl *field = nullptr;
-
- clang::Expr *bit_width = nullptr;
- if (bitfield_bit_size != 0)
- {
- llvm::APInt bitfield_bit_size_apint(m_ast->getTypeSize(m_ast->IntTy), bitfield_bit_size);
- bit_width = new (*m_ast)clang::IntegerLiteral (*m_ast, bitfield_bit_size_apint, m_ast->IntTy, clang::SourceLocation());
- }
-
- clang::RecordDecl *record_decl = GetAsRecordDecl ();
- if (record_decl)
- {
- field = clang::FieldDecl::Create (*m_ast,
- record_decl,
- clang::SourceLocation(),
- clang::SourceLocation(),
- name ? &m_ast->Idents.get(name) : nullptr, // Identifier
- field_clang_type.GetQualType(), // Field type
- nullptr, // TInfo *
- bit_width, // BitWidth
- false, // Mutable
- clang::ICIS_NoInit); // HasInit
-
- if (!name)
- {
- // Determine whether this field corresponds to an anonymous
- // struct or union.
- if (const clang::TagType *TagT = field->getType()->getAs<clang::TagType>()) {
- if (clang::RecordDecl *Rec = llvm::dyn_cast<clang::RecordDecl>(TagT->getDecl()))
- if (!Rec->getDeclName()) {
- Rec->setAnonymousStructOrUnion(true);
- field->setImplicit();
-
- }
- }
- }
-
- if (field)
- {
- field->setAccess (ClangASTContext::ConvertAccessTypeToAccessSpecifier (access));
-
- record_decl->addDecl(field);
-
-#ifdef LLDB_CONFIGURATION_DEBUG
- VerifyDecl(field);
-#endif
- }
- }
- else
- {
- clang::ObjCInterfaceDecl *class_interface_decl = GetAsObjCInterfaceDecl ();
-
- if (class_interface_decl)
- {
- const bool is_synthesized = false;
-
- field_clang_type.GetCompleteType();
-
- field = clang::ObjCIvarDecl::Create (*m_ast,
- class_interface_decl,
- clang::SourceLocation(),
- clang::SourceLocation(),
- name ? &m_ast->Idents.get(name) : nullptr, // Identifier
- field_clang_type.GetQualType(), // Field type
- nullptr, // TypeSourceInfo *
- ConvertAccessTypeToObjCIvarAccessControl (access),
- bit_width,
- is_synthesized);
-
- if (field)
- {
- class_interface_decl->addDecl(field);
-
-#ifdef LLDB_CONFIGURATION_DEBUG
- VerifyDecl(field);
-#endif
- }
- }
- }
- return field;
-}
-
-void
-ClangASTType::BuildIndirectFields ()
-{
- clang::RecordDecl *record_decl = GetAsRecordDecl();
-
- if (!record_decl)
- return;
-
- typedef llvm::SmallVector <clang::IndirectFieldDecl *, 1> IndirectFieldVector;
-
- IndirectFieldVector indirect_fields;
- clang::RecordDecl::field_iterator field_pos;
- clang::RecordDecl::field_iterator field_end_pos = record_decl->field_end();
- clang::RecordDecl::field_iterator last_field_pos = field_end_pos;
- for (field_pos = record_decl->field_begin(); field_pos != field_end_pos; last_field_pos = field_pos++)
- {
- if (field_pos->isAnonymousStructOrUnion())
- {
- clang::QualType field_qual_type = field_pos->getType();
-
- const clang::RecordType *field_record_type = field_qual_type->getAs<clang::RecordType>();
-
- if (!field_record_type)
- continue;
-
- clang::RecordDecl *field_record_decl = field_record_type->getDecl();
-
- if (!field_record_decl)
- continue;
-
- for (clang::RecordDecl::decl_iterator di = field_record_decl->decls_begin(), de = field_record_decl->decls_end();
- di != de;
- ++di)
- {
- if (clang::FieldDecl *nested_field_decl = llvm::dyn_cast<clang::FieldDecl>(*di))
- {
- clang::NamedDecl **chain = new (*m_ast) clang::NamedDecl*[2];
- chain[0] = *field_pos;
- chain[1] = nested_field_decl;
- clang::IndirectFieldDecl *indirect_field = clang::IndirectFieldDecl::Create(*m_ast,
- record_decl,
- clang::SourceLocation(),
- nested_field_decl->getIdentifier(),
- nested_field_decl->getType(),
- chain,
- 2);
-
- indirect_field->setImplicit();
-
- indirect_field->setAccess(ClangASTContext::UnifyAccessSpecifiers(field_pos->getAccess(),
- nested_field_decl->getAccess()));
-
- indirect_fields.push_back(indirect_field);
- }
- else if (clang::IndirectFieldDecl *nested_indirect_field_decl = llvm::dyn_cast<clang::IndirectFieldDecl>(*di))
- {
- int nested_chain_size = nested_indirect_field_decl->getChainingSize();
- clang::NamedDecl **chain = new (*m_ast) clang::NamedDecl*[nested_chain_size + 1];
- chain[0] = *field_pos;
-
- int chain_index = 1;
- for (clang::IndirectFieldDecl::chain_iterator nci = nested_indirect_field_decl->chain_begin(),
- nce = nested_indirect_field_decl->chain_end();
- nci < nce;
- ++nci)
- {
- chain[chain_index] = *nci;
- chain_index++;
- }
-
- clang::IndirectFieldDecl *indirect_field = clang::IndirectFieldDecl::Create(*m_ast,
- record_decl,
- clang::SourceLocation(),
- nested_indirect_field_decl->getIdentifier(),
- nested_indirect_field_decl->getType(),
- chain,
- nested_chain_size + 1);
-
- indirect_field->setImplicit();
-
- indirect_field->setAccess(ClangASTContext::UnifyAccessSpecifiers(field_pos->getAccess(),
- nested_indirect_field_decl->getAccess()));
-
- indirect_fields.push_back(indirect_field);
- }
- }
- }
- }
-
- // Check the last field to see if it has an incomplete array type as its
- // last member and if it does, the tell the record decl about it
- if (last_field_pos != field_end_pos)
- {
- if (last_field_pos->getType()->isIncompleteArrayType())
- record_decl->hasFlexibleArrayMember();
- }
-
- for (IndirectFieldVector::iterator ifi = indirect_fields.begin(), ife = indirect_fields.end();
- ifi < ife;
- ++ifi)
- {
- record_decl->addDecl(*ifi);
- }
-}
-
-void
-ClangASTType::SetIsPacked ()
-{
- clang::RecordDecl *record_decl = GetAsRecordDecl();
-
- if (!record_decl)
- return;
-
- record_decl->addAttr(clang::PackedAttr::CreateImplicit(*m_ast));
-}
-
-clang::VarDecl *
-ClangASTType::AddVariableToRecordType (const char *name,
- const ClangASTType &var_type,
- AccessType access)
-{
- clang::VarDecl *var_decl = nullptr;
-
- if (!IsValid() || !var_type.IsValid())
- return nullptr;
-
- clang::RecordDecl *record_decl = GetAsRecordDecl ();
- if (record_decl)
- {
- var_decl = clang::VarDecl::Create (*m_ast, // ASTContext &
- record_decl, // DeclContext *
- clang::SourceLocation(), // clang::SourceLocation StartLoc
- clang::SourceLocation(), // clang::SourceLocation IdLoc
- name ? &m_ast->Idents.get(name) : nullptr, // clang::IdentifierInfo *
- var_type.GetQualType(), // Variable clang::QualType
- nullptr, // TypeSourceInfo *
- clang::SC_Static); // StorageClass
- if (var_decl)
- {
- var_decl->setAccess(ClangASTContext::ConvertAccessTypeToAccessSpecifier (access));
- record_decl->addDecl(var_decl);
-
-#ifdef LLDB_CONFIGURATION_DEBUG
- VerifyDecl(var_decl);
-#endif
- }
- }
- return var_decl;
-}
-
-
-clang::CXXMethodDecl *
-ClangASTType::AddMethodToCXXRecordType (const char *name,
- const ClangASTType &method_clang_type,
- lldb::AccessType access,
- bool is_virtual,
- bool is_static,
- bool is_inline,
- bool is_explicit,
- bool is_attr_used,
- bool is_artificial)
-{
- if (!IsValid() || !method_clang_type.IsValid() || name == nullptr || name[0] == '\0')
- return nullptr;
-
- clang::QualType record_qual_type(GetCanonicalQualType());
-
- clang::CXXRecordDecl *cxx_record_decl = record_qual_type->getAsCXXRecordDecl();
-
- if (cxx_record_decl == nullptr)
- return nullptr;
-
- clang::QualType method_qual_type (method_clang_type.GetQualType());
-
- clang::CXXMethodDecl *cxx_method_decl = nullptr;
-
- clang::DeclarationName decl_name (&m_ast->Idents.get(name));
-
- const clang::FunctionType *function_type = llvm::dyn_cast<clang::FunctionType>(method_qual_type.getTypePtr());
-
- if (function_type == nullptr)
- return nullptr;
-
- const clang::FunctionProtoType *method_function_prototype (llvm::dyn_cast<clang::FunctionProtoType>(function_type));
-
- if (!method_function_prototype)
- return nullptr;
-
- unsigned int num_params = method_function_prototype->getNumParams();
-
- clang::CXXDestructorDecl *cxx_dtor_decl(nullptr);
- clang::CXXConstructorDecl *cxx_ctor_decl(nullptr);
-
- if (is_artificial)
- return nullptr; // skip everything artificial
-
- if (name[0] == '~')
- {
- cxx_dtor_decl = clang::CXXDestructorDecl::Create (*m_ast,
- cxx_record_decl,
- clang::SourceLocation(),
- clang::DeclarationNameInfo (m_ast->DeclarationNames.getCXXDestructorName (m_ast->getCanonicalType (record_qual_type)), clang::SourceLocation()),
- method_qual_type,
- nullptr,
- is_inline,
- is_artificial);
- cxx_method_decl = cxx_dtor_decl;
- }
- else if (decl_name == cxx_record_decl->getDeclName())
- {
- cxx_ctor_decl = clang::CXXConstructorDecl::Create (*m_ast,
- cxx_record_decl,
- clang::SourceLocation(),
- clang::DeclarationNameInfo (m_ast->DeclarationNames.getCXXConstructorName (m_ast->getCanonicalType (record_qual_type)), clang::SourceLocation()),
- method_qual_type,
- nullptr, // TypeSourceInfo *
- is_explicit,
- is_inline,
- is_artificial,
- false /*is_constexpr*/);
- cxx_method_decl = cxx_ctor_decl;
- }
- else
- {
- clang::StorageClass SC = is_static ? clang::SC_Static : clang::SC_None;
- clang::OverloadedOperatorKind op_kind = clang::NUM_OVERLOADED_OPERATORS;
-
- if (IsOperator (name, op_kind))
- {
- if (op_kind != clang::NUM_OVERLOADED_OPERATORS)
- {
- // Check the number of operator parameters. Sometimes we have
- // seen bad DWARF that doesn't correctly describe operators and
- // if we try to create a method and add it to the class, clang
- // will assert and crash, so we need to make sure things are
- // acceptable.
- if (!ClangASTContext::CheckOverloadedOperatorKindParameterCount (op_kind, num_params))
- return nullptr;
- cxx_method_decl = clang::CXXMethodDecl::Create (*m_ast,
- cxx_record_decl,
- clang::SourceLocation(),
- clang::DeclarationNameInfo (m_ast->DeclarationNames.getCXXOperatorName (op_kind), clang::SourceLocation()),
- method_qual_type,
- nullptr, // TypeSourceInfo *
- SC,
- is_inline,
- false /*is_constexpr*/,
- clang::SourceLocation());
- }
- else if (num_params == 0)
- {
- // Conversion operators don't take params...
- cxx_method_decl = clang::CXXConversionDecl::Create (*m_ast,
- cxx_record_decl,
- clang::SourceLocation(),
- clang::DeclarationNameInfo (m_ast->DeclarationNames.getCXXConversionFunctionName (m_ast->getCanonicalType (function_type->getReturnType())), clang::SourceLocation()),
- method_qual_type,
- nullptr, // TypeSourceInfo *
- is_inline,
- is_explicit,
- false /*is_constexpr*/,
- clang::SourceLocation());
- }
- }
-
- if (cxx_method_decl == nullptr)
- {
- cxx_method_decl = clang::CXXMethodDecl::Create (*m_ast,
- cxx_record_decl,
- clang::SourceLocation(),
- clang::DeclarationNameInfo (decl_name, clang::SourceLocation()),
- method_qual_type,
- nullptr, // TypeSourceInfo *
- SC,
- is_inline,
- false /*is_constexpr*/,
- clang::SourceLocation());
- }
- }
-
- clang::AccessSpecifier access_specifier = ClangASTContext::ConvertAccessTypeToAccessSpecifier (access);
-
- cxx_method_decl->setAccess (access_specifier);
- cxx_method_decl->setVirtualAsWritten (is_virtual);
-
- if (is_attr_used)
- cxx_method_decl->addAttr(clang::UsedAttr::CreateImplicit(*m_ast));
-
- // Populate the method decl with parameter decls
-
- llvm::SmallVector<clang::ParmVarDecl *, 12> params;
-
- for (unsigned param_index = 0;
- param_index < num_params;
- ++param_index)
- {
- params.push_back (clang::ParmVarDecl::Create (*m_ast,
- cxx_method_decl,
- clang::SourceLocation(),
- clang::SourceLocation(),
- nullptr, // anonymous
- method_function_prototype->getParamType(param_index),
- nullptr,
- clang::SC_None,
- nullptr));
- }
-
- cxx_method_decl->setParams (llvm::ArrayRef<clang::ParmVarDecl*>(params));
-
- cxx_record_decl->addDecl (cxx_method_decl);
-
- // Sometimes the debug info will mention a constructor (default/copy/move),
- // destructor, or assignment operator (copy/move) but there won't be any
- // version of this in the code. So we check if the function was artificially
- // generated and if it is trivial and this lets the compiler/backend know
- // that it can inline the IR for these when it needs to and we can avoid a
- // "missing function" error when running expressions.
-
- if (is_artificial)
- {
- if (cxx_ctor_decl &&
- ((cxx_ctor_decl->isDefaultConstructor() && cxx_record_decl->hasTrivialDefaultConstructor ()) ||
- (cxx_ctor_decl->isCopyConstructor() && cxx_record_decl->hasTrivialCopyConstructor ()) ||
- (cxx_ctor_decl->isMoveConstructor() && cxx_record_decl->hasTrivialMoveConstructor ()) ))
- {
- cxx_ctor_decl->setDefaulted();
- cxx_ctor_decl->setTrivial(true);
- }
- else if (cxx_dtor_decl)
- {
- if (cxx_record_decl->hasTrivialDestructor())
- {
- cxx_dtor_decl->setDefaulted();
- cxx_dtor_decl->setTrivial(true);
- }
- }
- else if ((cxx_method_decl->isCopyAssignmentOperator() && cxx_record_decl->hasTrivialCopyAssignment()) ||
- (cxx_method_decl->isMoveAssignmentOperator() && cxx_record_decl->hasTrivialMoveAssignment()))
- {
- cxx_method_decl->setDefaulted();
- cxx_method_decl->setTrivial(true);
- }
- }
-
-#ifdef LLDB_CONFIGURATION_DEBUG
- VerifyDecl(cxx_method_decl);
-#endif
-
- // printf ("decl->isPolymorphic() = %i\n", cxx_record_decl->isPolymorphic());
- // printf ("decl->isAggregate() = %i\n", cxx_record_decl->isAggregate());
- // printf ("decl->isPOD() = %i\n", cxx_record_decl->isPOD());
- // printf ("decl->isEmpty() = %i\n", cxx_record_decl->isEmpty());
- // printf ("decl->isAbstract() = %i\n", cxx_record_decl->isAbstract());
- // printf ("decl->hasTrivialConstructor() = %i\n", cxx_record_decl->hasTrivialConstructor());
- // printf ("decl->hasTrivialCopyConstructor() = %i\n", cxx_record_decl->hasTrivialCopyConstructor());
- // printf ("decl->hasTrivialCopyAssignment() = %i\n", cxx_record_decl->hasTrivialCopyAssignment());
- // printf ("decl->hasTrivialDestructor() = %i\n", cxx_record_decl->hasTrivialDestructor());
- return cxx_method_decl;
-}
-
-
-#pragma mark C++ Base Classes
-
-clang::CXXBaseSpecifier *
-ClangASTType::CreateBaseClassSpecifier (AccessType access, bool is_virtual, bool base_of_class)
-{
- if (IsValid())
- return new clang::CXXBaseSpecifier (clang::SourceRange(),
- is_virtual,
- base_of_class,
- ClangASTContext::ConvertAccessTypeToAccessSpecifier (access),
- m_ast->getTrivialTypeSourceInfo (GetQualType()),
- clang::SourceLocation());
- return nullptr;
-}
-
-void
-ClangASTType::DeleteBaseClassSpecifiers (clang::CXXBaseSpecifier **base_classes, unsigned num_base_classes)
-{
- for (unsigned i=0; i<num_base_classes; ++i)
- {
- delete base_classes[i];
- base_classes[i] = nullptr;
- }
-}
-
-bool
-ClangASTType::SetBaseClassesForClassType (clang::CXXBaseSpecifier const * const *base_classes,
- unsigned num_base_classes)
-{
- if (IsValid())
- {
- clang::CXXRecordDecl *cxx_record_decl = GetAsCXXRecordDecl();
- if (cxx_record_decl)
- {
- cxx_record_decl->setBases(base_classes, num_base_classes);
- return true;
- }
- }
- return false;
-}
-
-bool
-ClangASTType::SetObjCSuperClass (const ClangASTType &superclass_clang_type)
-{
- if (IsValid() && superclass_clang_type.IsValid())
- {
- clang::ObjCInterfaceDecl *class_interface_decl = GetAsObjCInterfaceDecl ();
- clang::ObjCInterfaceDecl *super_interface_decl = superclass_clang_type.GetAsObjCInterfaceDecl ();
- if (class_interface_decl && super_interface_decl)
- {
-
- class_interface_decl->setSuperClass(
- m_ast->getTrivialTypeSourceInfo(m_ast->getObjCInterfaceType(super_interface_decl)));
- return true;
- }
- }
- return false;
-}
-
-bool
-ClangASTType::AddObjCClassProperty (const char *property_name,
- const ClangASTType &property_clang_type,
- clang::ObjCIvarDecl *ivar_decl,
- const char *property_setter_name,
- const char *property_getter_name,
- uint32_t property_attributes,
- ClangASTMetadata *metadata)
-{
- if (!IsValid() || !property_clang_type.IsValid() || property_name == nullptr || property_name[0] == '\0')
- return false;
-
- clang::ObjCInterfaceDecl *class_interface_decl = GetAsObjCInterfaceDecl ();
-
- if (class_interface_decl)
- {
- ClangASTType property_clang_type_to_access;
-
- if (property_clang_type.IsValid())
- property_clang_type_to_access = property_clang_type;
- else if (ivar_decl)
- property_clang_type_to_access = ClangASTType (m_ast, ivar_decl->getType());
-
- if (class_interface_decl && property_clang_type_to_access.IsValid())
- {
- clang::TypeSourceInfo *prop_type_source;
- if (ivar_decl)
- prop_type_source = m_ast->getTrivialTypeSourceInfo (ivar_decl->getType());
- else
- prop_type_source = m_ast->getTrivialTypeSourceInfo (property_clang_type.GetQualType());
-
- clang::ObjCPropertyDecl *property_decl = clang::ObjCPropertyDecl::Create (*m_ast,
- class_interface_decl,
- clang::SourceLocation(), // Source Location
- &m_ast->Idents.get(property_name),
- clang::SourceLocation(), //Source Location for AT
- clang::SourceLocation(), //Source location for (
- ivar_decl ? ivar_decl->getType() : property_clang_type.GetQualType(),
- prop_type_source);
-
- if (property_decl)
- {
- if (metadata)
- ClangASTContext::SetMetadata(m_ast, property_decl, *metadata);
-
- class_interface_decl->addDecl (property_decl);
-
- clang::Selector setter_sel, getter_sel;
-
- if (property_setter_name != nullptr)
- {
- std::string property_setter_no_colon(property_setter_name, strlen(property_setter_name) - 1);
- clang::IdentifierInfo *setter_ident = &m_ast->Idents.get(property_setter_no_colon.c_str());
- setter_sel = m_ast->Selectors.getSelector(1, &setter_ident);
- }
- else if (!(property_attributes & DW_APPLE_PROPERTY_readonly))
- {
- std::string setter_sel_string("set");
- setter_sel_string.push_back(::toupper(property_name[0]));
- setter_sel_string.append(&property_name[1]);
- clang::IdentifierInfo *setter_ident = &m_ast->Idents.get(setter_sel_string.c_str());
- setter_sel = m_ast->Selectors.getSelector(1, &setter_ident);
- }
- property_decl->setSetterName(setter_sel);
- property_decl->setPropertyAttributes (clang::ObjCPropertyDecl::OBJC_PR_setter);
-
- if (property_getter_name != nullptr)
- {
- clang::IdentifierInfo *getter_ident = &m_ast->Idents.get(property_getter_name);
- getter_sel = m_ast->Selectors.getSelector(0, &getter_ident);
- }
- else
- {
- clang::IdentifierInfo *getter_ident = &m_ast->Idents.get(property_name);
- getter_sel = m_ast->Selectors.getSelector(0, &getter_ident);
- }
- property_decl->setGetterName(getter_sel);
- property_decl->setPropertyAttributes (clang::ObjCPropertyDecl::OBJC_PR_getter);
-
- if (ivar_decl)
- property_decl->setPropertyIvarDecl (ivar_decl);
-
- if (property_attributes & DW_APPLE_PROPERTY_readonly)
- property_decl->setPropertyAttributes (clang::ObjCPropertyDecl::OBJC_PR_readonly);
- if (property_attributes & DW_APPLE_PROPERTY_readwrite)
- property_decl->setPropertyAttributes (clang::ObjCPropertyDecl::OBJC_PR_readwrite);
- if (property_attributes & DW_APPLE_PROPERTY_assign)
- property_decl->setPropertyAttributes (clang::ObjCPropertyDecl::OBJC_PR_assign);
- if (property_attributes & DW_APPLE_PROPERTY_retain)
- property_decl->setPropertyAttributes (clang::ObjCPropertyDecl::OBJC_PR_retain);
- if (property_attributes & DW_APPLE_PROPERTY_copy)
- property_decl->setPropertyAttributes (clang::ObjCPropertyDecl::OBJC_PR_copy);
- if (property_attributes & DW_APPLE_PROPERTY_nonatomic)
- property_decl->setPropertyAttributes (clang::ObjCPropertyDecl::OBJC_PR_nonatomic);
-
- if (!getter_sel.isNull() && !class_interface_decl->lookupInstanceMethod(getter_sel))
- {
- const bool isInstance = true;
- const bool isVariadic = false;
- const bool isSynthesized = false;
- const bool isImplicitlyDeclared = true;
- const bool isDefined = false;
- const clang::ObjCMethodDecl::ImplementationControl impControl = clang::ObjCMethodDecl::None;
- const bool HasRelatedResultType = false;
-
- clang::ObjCMethodDecl *getter = clang::ObjCMethodDecl::Create (*m_ast,
- clang::SourceLocation(),
- clang::SourceLocation(),
- getter_sel,
- property_clang_type_to_access.GetQualType(),
- nullptr,
- class_interface_decl,
- isInstance,
- isVariadic,
- isSynthesized,
- isImplicitlyDeclared,
- isDefined,
- impControl,
- HasRelatedResultType);
-
- if (getter && metadata)
- ClangASTContext::SetMetadata(m_ast, getter, *metadata);
-
- if (getter)
- {
- getter->setMethodParams(*m_ast, llvm::ArrayRef<clang::ParmVarDecl*>(), llvm::ArrayRef<clang::SourceLocation>());
-
- class_interface_decl->addDecl(getter);
- }
- }
-
- if (!setter_sel.isNull() && !class_interface_decl->lookupInstanceMethod(setter_sel))
- {
- clang::QualType result_type = m_ast->VoidTy;
-
- const bool isInstance = true;
- const bool isVariadic = false;
- const bool isSynthesized = false;
- const bool isImplicitlyDeclared = true;
- const bool isDefined = false;
- const clang::ObjCMethodDecl::ImplementationControl impControl = clang::ObjCMethodDecl::None;
- const bool HasRelatedResultType = false;
-
- clang::ObjCMethodDecl *setter = clang::ObjCMethodDecl::Create (*m_ast,
- clang::SourceLocation(),
- clang::SourceLocation(),
- setter_sel,
- result_type,
- nullptr,
- class_interface_decl,
- isInstance,
- isVariadic,
- isSynthesized,
- isImplicitlyDeclared,
- isDefined,
- impControl,
- HasRelatedResultType);
-
- if (setter && metadata)
- ClangASTContext::SetMetadata(m_ast, setter, *metadata);
-
- llvm::SmallVector<clang::ParmVarDecl *, 1> params;
-
- params.push_back (clang::ParmVarDecl::Create (*m_ast,
- setter,
- clang::SourceLocation(),
- clang::SourceLocation(),
- nullptr, // anonymous
- property_clang_type_to_access.GetQualType(),
- nullptr,
- clang::SC_Auto,
- nullptr));
-
- if (setter)
- {
- setter->setMethodParams(*m_ast, llvm::ArrayRef<clang::ParmVarDecl*>(params), llvm::ArrayRef<clang::SourceLocation>());
-
- class_interface_decl->addDecl(setter);
- }
- }
-
- return true;
- }
- }
- }
- return false;
-}
-
-bool
-ClangASTType::IsObjCClassTypeAndHasIVars (bool check_superclass) const
-{
- clang::ObjCInterfaceDecl *class_interface_decl = GetAsObjCInterfaceDecl ();
- if (class_interface_decl)
- return ObjCDeclHasIVars (class_interface_decl, check_superclass);
- return false;
-}
-
-
-clang::ObjCMethodDecl *
-ClangASTType::AddMethodToObjCObjectType (const char *name, // the full symbol name as seen in the symbol table ("-[NString stringWithCString:]")
- const ClangASTType &method_clang_type,
- lldb::AccessType access,
- bool is_artificial)
-{
- if (!IsValid() || !method_clang_type.IsValid())
- return nullptr;
-
- clang::ObjCInterfaceDecl *class_interface_decl = GetAsObjCInterfaceDecl();
-
- if (class_interface_decl == nullptr)
- return nullptr;
-
- const char *selector_start = ::strchr (name, ' ');
- if (selector_start == nullptr)
- return nullptr;
-
- selector_start++;
- llvm::SmallVector<clang::IdentifierInfo *, 12> selector_idents;
-
- size_t len = 0;
- const char *start;
- //printf ("name = '%s'\n", name);
-
- unsigned num_selectors_with_args = 0;
- for (start = selector_start;
- start && *start != '\0' && *start != ']';
- start += len)
- {
- len = ::strcspn(start, ":]");
- bool has_arg = (start[len] == ':');
- if (has_arg)
- ++num_selectors_with_args;
- selector_idents.push_back (&m_ast->Idents.get (llvm::StringRef (start, len)));
- if (has_arg)
- len += 1;
- }
-
-
- if (selector_idents.size() == 0)
- return nullptr;
-
- clang::Selector method_selector = m_ast->Selectors.getSelector (num_selectors_with_args ? selector_idents.size() : 0,
- selector_idents.data());
-
- clang::QualType method_qual_type (method_clang_type.GetQualType());
-
- // Populate the method decl with parameter decls
- const clang::Type *method_type(method_qual_type.getTypePtr());
-
- if (method_type == nullptr)
- return nullptr;
-
- const clang::FunctionProtoType *method_function_prototype (llvm::dyn_cast<clang::FunctionProtoType>(method_type));
-
- if (!method_function_prototype)
- return nullptr;
-
-
- bool is_variadic = false;
- bool is_synthesized = false;
- bool is_defined = false;
- clang::ObjCMethodDecl::ImplementationControl imp_control = clang::ObjCMethodDecl::None;
-
- const unsigned num_args = method_function_prototype->getNumParams();
-
- if (num_args != num_selectors_with_args)
- return nullptr; // some debug information is corrupt. We are not going to deal with it.
-
- clang::ObjCMethodDecl *objc_method_decl = clang::ObjCMethodDecl::Create (*m_ast,
- clang::SourceLocation(), // beginLoc,
- clang::SourceLocation(), // endLoc,
- method_selector,
- method_function_prototype->getReturnType(),
- nullptr, // TypeSourceInfo *ResultTInfo,
- GetDeclContextForType (),
- name[0] == '-',
- is_variadic,
- is_synthesized,
- true, // is_implicitly_declared; we force this to true because we don't have source locations
- is_defined,
- imp_control,
- false /*has_related_result_type*/);
-
-
- if (objc_method_decl == nullptr)
- return nullptr;
-
- if (num_args > 0)
- {
- llvm::SmallVector<clang::ParmVarDecl *, 12> params;
-
- for (unsigned param_index = 0; param_index < num_args; ++param_index)
- {
- params.push_back (clang::ParmVarDecl::Create (*m_ast,
- objc_method_decl,
- clang::SourceLocation(),
- clang::SourceLocation(),
- nullptr, // anonymous
- method_function_prototype->getParamType(param_index),
- nullptr,
- clang::SC_Auto,
- nullptr));
- }
-
- objc_method_decl->setMethodParams(*m_ast, llvm::ArrayRef<clang::ParmVarDecl*>(params), llvm::ArrayRef<clang::SourceLocation>());
- }
-
- class_interface_decl->addDecl (objc_method_decl);
-
-#ifdef LLDB_CONFIGURATION_DEBUG
- VerifyDecl(objc_method_decl);
-#endif
-
- return objc_method_decl;
-}
-
-
-clang::DeclContext *
-ClangASTType::GetDeclContextForType () const
-{
- if (!IsValid())
- return nullptr;
-
- clang::QualType qual_type(GetCanonicalQualType());
- const clang::Type::TypeClass type_class = qual_type->getTypeClass();
- switch (type_class)
- {
- case clang::Type::UnaryTransform: break;
- case clang::Type::FunctionNoProto: break;
- case clang::Type::FunctionProto: break;
- case clang::Type::IncompleteArray: break;
- case clang::Type::VariableArray: break;
- case clang::Type::ConstantArray: break;
- case clang::Type::DependentSizedArray: break;
- case clang::Type::ExtVector: break;
- case clang::Type::DependentSizedExtVector: break;
- case clang::Type::Vector: break;
- case clang::Type::Builtin: break;
- case clang::Type::BlockPointer: break;
- case clang::Type::Pointer: break;
- case clang::Type::LValueReference: break;
- case clang::Type::RValueReference: break;
- case clang::Type::MemberPointer: break;
- case clang::Type::Complex: break;
- case clang::Type::ObjCObject: break;
- case clang::Type::ObjCInterface: return llvm::cast<clang::ObjCObjectType>(qual_type.getTypePtr())->getInterface();
- case clang::Type::ObjCObjectPointer: return ClangASTType (m_ast, llvm::cast<clang::ObjCObjectPointerType>(qual_type.getTypePtr())->getPointeeType()).GetDeclContextForType();
- case clang::Type::Record: return llvm::cast<clang::RecordType>(qual_type)->getDecl();
- case clang::Type::Enum: return llvm::cast<clang::EnumType>(qual_type)->getDecl();
- case clang::Type::Typedef: return ClangASTType (m_ast, llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType()).GetDeclContextForType();
- case clang::Type::Elaborated: return ClangASTType (m_ast, llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType()).GetDeclContextForType();
- case clang::Type::Paren: return ClangASTType (m_ast, llvm::cast<clang::ParenType>(qual_type)->desugar()).GetDeclContextForType();
- case clang::Type::TypeOfExpr: break;
- case clang::Type::TypeOf: break;
- case clang::Type::Decltype: break;
- //case clang::Type::QualifiedName: break;
- case clang::Type::TemplateSpecialization: break;
- case clang::Type::DependentTemplateSpecialization: break;
- case clang::Type::TemplateTypeParm: break;
- case clang::Type::SubstTemplateTypeParm: break;
- case clang::Type::SubstTemplateTypeParmPack:break;
- case clang::Type::PackExpansion: break;
- case clang::Type::UnresolvedUsing: break;
- case clang::Type::Attributed: break;
- case clang::Type::Auto: break;
- case clang::Type::InjectedClassName: break;
- case clang::Type::DependentName: break;
- case clang::Type::Atomic: break;
- case clang::Type::Adjusted: break;
-
- // pointer type decayed from an array or function type.
- case clang::Type::Decayed: break;
- }
- // No DeclContext in this type...
- return nullptr;
-}
-
-bool
-ClangASTType::SetDefaultAccessForRecordFields (int default_accessibility,
- int *assigned_accessibilities,
- size_t num_assigned_accessibilities)
-{
- if (IsValid())
- {
- clang::RecordDecl *record_decl = GetAsRecordDecl();
- if (record_decl)
- {
- uint32_t field_idx;
- clang::RecordDecl::field_iterator field, field_end;
- for (field = record_decl->field_begin(), field_end = record_decl->field_end(), field_idx = 0;
- field != field_end;
- ++field, ++field_idx)
- {
- // If no accessibility was assigned, assign the correct one
- if (field_idx < num_assigned_accessibilities && assigned_accessibilities[field_idx] == clang::AS_none)
- field->setAccess ((clang::AccessSpecifier)default_accessibility);
- }
- return true;
- }
- }
- return false;
-}
-
-
-bool
-ClangASTType::SetHasExternalStorage (bool has_extern)
-{
- if (!IsValid())
- return false;
-
- clang::QualType qual_type (GetCanonicalQualType());
-
- const clang::Type::TypeClass type_class = qual_type->getTypeClass();
- switch (type_class)
- {
- case clang::Type::Record:
- {
- clang::CXXRecordDecl *cxx_record_decl = qual_type->getAsCXXRecordDecl();
- if (cxx_record_decl)
- {
- cxx_record_decl->setHasExternalLexicalStorage (has_extern);
- cxx_record_decl->setHasExternalVisibleStorage (has_extern);
- return true;
- }
- }
- break;
-
- case clang::Type::Enum:
- {
- clang::EnumDecl *enum_decl = llvm::cast<clang::EnumType>(qual_type)->getDecl();
- if (enum_decl)
- {
- enum_decl->setHasExternalLexicalStorage (has_extern);
- enum_decl->setHasExternalVisibleStorage (has_extern);
- return true;
- }
- }
- break;
-
- case clang::Type::ObjCObject:
- case clang::Type::ObjCInterface:
- {
- const clang::ObjCObjectType *objc_class_type = llvm::dyn_cast<clang::ObjCObjectType>(qual_type.getTypePtr());
- assert (objc_class_type);
- if (objc_class_type)
- {
- clang::ObjCInterfaceDecl *class_interface_decl = objc_class_type->getInterface();
-
- if (class_interface_decl)
- {
- class_interface_decl->setHasExternalLexicalStorage (has_extern);
- class_interface_decl->setHasExternalVisibleStorage (has_extern);
- return true;
- }
- }
- }
- break;
-
- case clang::Type::Typedef:
- return ClangASTType (m_ast, llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType()).SetHasExternalStorage (has_extern);
-
- case clang::Type::Elaborated:
- return ClangASTType (m_ast, llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType()).SetHasExternalStorage (has_extern);
-
- case clang::Type::Paren:
- return ClangASTType (m_ast, llvm::cast<clang::ParenType>(qual_type)->desugar()).SetHasExternalStorage (has_extern);
-
- default:
- break;
- }
- return false;
-}
-
-bool
-ClangASTType::SetTagTypeKind (int kind) const
-{
- if (IsValid())
- {
- clang::QualType tag_qual_type(GetQualType());
- const clang::Type *clang_type = tag_qual_type.getTypePtr();
- if (clang_type)
- {
- const clang::TagType *tag_type = llvm::dyn_cast<clang::TagType>(clang_type);
- if (tag_type)
- {
- clang::TagDecl *tag_decl = llvm::dyn_cast<clang::TagDecl>(tag_type->getDecl());
- if (tag_decl)
- {
- tag_decl->setTagKind ((clang::TagDecl::TagKind)kind);
- return true;
- }
- }
- }
- }
- return false;
-}
-
-
-#pragma mark TagDecl
-
-bool
-ClangASTType::StartTagDeclarationDefinition ()
-{
- if (IsValid())
- {
- clang::QualType qual_type (GetQualType());
- const clang::Type *t = qual_type.getTypePtr();
- if (t)
- {
- const clang::TagType *tag_type = llvm::dyn_cast<clang::TagType>(t);
- if (tag_type)
- {
- clang::TagDecl *tag_decl = tag_type->getDecl();
- if (tag_decl)
- {
- tag_decl->startDefinition();
- return true;
- }
- }
-
- const clang::ObjCObjectType *object_type = llvm::dyn_cast<clang::ObjCObjectType>(t);
- if (object_type)
- {
- clang::ObjCInterfaceDecl *interface_decl = object_type->getInterface();
- if (interface_decl)
- {
- interface_decl->startDefinition();
- return true;
- }
- }
- }
- }
- return false;
-}
-
-bool
-ClangASTType::CompleteTagDeclarationDefinition ()
-{
- if (IsValid())
- {
- clang::QualType qual_type (GetQualType());
-
- clang::CXXRecordDecl *cxx_record_decl = qual_type->getAsCXXRecordDecl();
-
- if (cxx_record_decl)
- {
- cxx_record_decl->completeDefinition();
-
- return true;
- }
-
- const clang::EnumType *enum_type = llvm::dyn_cast<clang::EnumType>(qual_type.getTypePtr());
-
- if (enum_type)
- {
- clang::EnumDecl *enum_decl = enum_type->getDecl();
-
- if (enum_decl)
- {
- /// TODO This really needs to be fixed.
-
- unsigned NumPositiveBits = 1;
- unsigned NumNegativeBits = 0;
-
- clang::QualType promotion_qual_type;
- // If the enum integer type is less than an integer in bit width,
- // then we must promote it to an integer size.
- if (m_ast->getTypeSize(enum_decl->getIntegerType()) < m_ast->getTypeSize(m_ast->IntTy))
- {
- if (enum_decl->getIntegerType()->isSignedIntegerType())
- promotion_qual_type = m_ast->IntTy;
- else
- promotion_qual_type = m_ast->UnsignedIntTy;
- }
- else
- promotion_qual_type = enum_decl->getIntegerType();
-
- enum_decl->completeDefinition(enum_decl->getIntegerType(), promotion_qual_type, NumPositiveBits, NumNegativeBits);
- return true;
- }
- }
- }
- return false;
-}
-
-
-
-
-
-
-
-bool
-ClangASTType::AddEnumerationValueToEnumerationType (const ClangASTType &enumerator_clang_type,
- const Declaration &decl,
- const char *name,
- int64_t enum_value,
- uint32_t enum_value_bit_size)
-{
- if (IsValid() && enumerator_clang_type.IsValid() && name && name[0])
- {
- clang::QualType enum_qual_type (GetCanonicalQualType());
-
- bool is_signed = false;
- enumerator_clang_type.IsIntegerType (is_signed);
- const clang::Type *clang_type = enum_qual_type.getTypePtr();
- if (clang_type)
- {
- const clang::EnumType *enum_type = llvm::dyn_cast<clang::EnumType>(clang_type);
-
- if (enum_type)
- {
- llvm::APSInt enum_llvm_apsint(enum_value_bit_size, is_signed);
- enum_llvm_apsint = enum_value;
- clang::EnumConstantDecl *enumerator_decl =
- clang::EnumConstantDecl::Create (*m_ast,
- enum_type->getDecl(),
- clang::SourceLocation(),
- name ? &m_ast->Idents.get(name) : nullptr, // Identifier
- enumerator_clang_type.GetQualType(),
- nullptr,
- enum_llvm_apsint);
-
- if (enumerator_decl)
- {
- enum_type->getDecl()->addDecl(enumerator_decl);
-
-#ifdef LLDB_CONFIGURATION_DEBUG
- VerifyDecl(enumerator_decl);
-#endif
-
- return true;
- }
- }
- }
- }
- return false;
-}
-
-
-ClangASTType
-ClangASTType::GetEnumerationIntegerType () const
-{
- clang::QualType enum_qual_type (GetCanonicalQualType());
- const clang::Type *clang_type = enum_qual_type.getTypePtr();
- if (clang_type)
- {
- const clang::EnumType *enum_type = llvm::dyn_cast<clang::EnumType>(clang_type);
- if (enum_type)
- {
- clang::EnumDecl *enum_decl = enum_type->getDecl();
- if (enum_decl)
- return ClangASTType (m_ast, enum_decl->getIntegerType());
- }
- }
- return ClangASTType();
-}
-
-ClangASTType
-ClangASTType::CreateMemberPointerType (const ClangASTType &pointee_type) const
-{
- if (IsValid() && pointee_type.IsValid())
- {
- return ClangASTType (m_ast, m_ast->getMemberPointerType (pointee_type.GetQualType(),
- GetQualType().getTypePtr()));
- }
- return ClangASTType();
-}
-
-
-size_t
-ClangASTType::ConvertStringToFloatValue (const char *s, uint8_t *dst, size_t dst_size) const
-{
- if (IsValid())
- {
- clang::QualType qual_type (GetCanonicalQualType());
- uint32_t count = 0;
- bool is_complex = false;
- if (IsFloatingPointType (count, is_complex))
- {
- // TODO: handle complex and vector types
- if (count != 1)
- return false;
-
- llvm::StringRef s_sref(s);
- llvm::APFloat ap_float(m_ast->getFloatTypeSemantics(qual_type), s_sref);
-
- const uint64_t bit_size = m_ast->getTypeSize (qual_type);
- const uint64_t byte_size = bit_size / 8;
- if (dst_size >= byte_size)
- {
- if (bit_size == sizeof(float)*8)
- {
- float float32 = ap_float.convertToFloat();
- ::memcpy (dst, &float32, byte_size);
- return byte_size;
- }
- else if (bit_size >= 64)
- {
- llvm::APInt ap_int(ap_float.bitcastToAPInt());
- ::memcpy (dst, ap_int.getRawData(), byte_size);
- return byte_size;
- }
- }
- }
- }
- return 0;
-}
-
-
-
-//----------------------------------------------------------------------
-// Dumping types
-//----------------------------------------------------------------------
-#define DEPTH_INCREMENT 2
-
-void
-ClangASTType::DumpValue (ExecutionContext *exe_ctx,
- Stream *s,
- lldb::Format format,
- const lldb_private::DataExtractor &data,
- lldb::offset_t data_byte_offset,
- size_t data_byte_size,
- uint32_t bitfield_bit_size,
- uint32_t bitfield_bit_offset,
- bool show_types,
- bool show_summary,
- bool verbose,
- uint32_t depth)
-{
- if (!IsValid())
- return;
-
- clang::QualType qual_type(GetQualType());
- switch (qual_type->getTypeClass())
- {
- case clang::Type::Record:
- if (GetCompleteType ())
- {
- const clang::RecordType *record_type = llvm::cast<clang::RecordType>(qual_type.getTypePtr());
- const clang::RecordDecl *record_decl = record_type->getDecl();
- assert(record_decl);
- uint32_t field_bit_offset = 0;
- uint32_t field_byte_offset = 0;
- const clang::ASTRecordLayout &record_layout = m_ast->getASTRecordLayout(record_decl);
- uint32_t child_idx = 0;
-
- const clang::CXXRecordDecl *cxx_record_decl = llvm::dyn_cast<clang::CXXRecordDecl>(record_decl);
- if (cxx_record_decl)
- {
- // We might have base classes to print out first
- clang::CXXRecordDecl::base_class_const_iterator base_class, base_class_end;
- for (base_class = cxx_record_decl->bases_begin(), base_class_end = cxx_record_decl->bases_end();
- base_class != base_class_end;
- ++base_class)
- {
- const clang::CXXRecordDecl *base_class_decl = llvm::cast<clang::CXXRecordDecl>(base_class->getType()->getAs<clang::RecordType>()->getDecl());
-
- // Skip empty base classes
- if (verbose == false && ClangASTContext::RecordHasFields(base_class_decl) == false)
- continue;
-
- if (base_class->isVirtual())
- field_bit_offset = record_layout.getVBaseClassOffset(base_class_decl).getQuantity() * 8;
- else
- field_bit_offset = record_layout.getBaseClassOffset(base_class_decl).getQuantity() * 8;
- field_byte_offset = field_bit_offset / 8;
- assert (field_bit_offset % 8 == 0);
- if (child_idx == 0)
- s->PutChar('{');
- else
- s->PutChar(',');
-
- clang::QualType base_class_qual_type = base_class->getType();
- std::string base_class_type_name(base_class_qual_type.getAsString());
-
- // Indent and print the base class type name
- s->Printf("\n%*s%s ", depth + DEPTH_INCREMENT, "", base_class_type_name.c_str());
-
- clang::TypeInfo base_class_type_info = m_ast->getTypeInfo(base_class_qual_type);
-
- // Dump the value of the member
- ClangASTType base_clang_type(m_ast, base_class_qual_type);
- base_clang_type.DumpValue (exe_ctx,
- s, // Stream to dump to
- base_clang_type.GetFormat(), // The format with which to display the member
- data, // Data buffer containing all bytes for this type
- data_byte_offset + field_byte_offset,// Offset into "data" where to grab value from
- base_class_type_info.Width / 8, // Size of this type in bytes
- 0, // Bitfield bit size
- 0, // Bitfield bit offset
- show_types, // Boolean indicating if we should show the variable types
- show_summary, // Boolean indicating if we should show a summary for the current type
- verbose, // Verbose output?
- depth + DEPTH_INCREMENT); // Scope depth for any types that have children
-
- ++child_idx;
- }
- }
- uint32_t field_idx = 0;
- clang::RecordDecl::field_iterator field, field_end;
- for (field = record_decl->field_begin(), field_end = record_decl->field_end(); field != field_end; ++field, ++field_idx, ++child_idx)
- {
- // Print the starting squiggly bracket (if this is the
- // first member) or comma (for member 2 and beyond) for
- // the struct/union/class member.
- if (child_idx == 0)
- s->PutChar('{');
- else
- s->PutChar(',');
-
- // Indent
- s->Printf("\n%*s", depth + DEPTH_INCREMENT, "");
-
- clang::QualType field_type = field->getType();
- // Print the member type if requested
- // Figure out the type byte size (field_type_info.first) and
- // alignment (field_type_info.second) from the AST context.
- clang::TypeInfo field_type_info = m_ast->getTypeInfo(field_type);
- assert(field_idx < record_layout.getFieldCount());
- // Figure out the field offset within the current struct/union/class type
- field_bit_offset = record_layout.getFieldOffset (field_idx);
- field_byte_offset = field_bit_offset / 8;
- uint32_t field_bitfield_bit_size = 0;
- uint32_t field_bitfield_bit_offset = 0;
- if (ClangASTContext::FieldIsBitfield (m_ast, *field, field_bitfield_bit_size))
- field_bitfield_bit_offset = field_bit_offset % 8;
-
- if (show_types)
- {
- std::string field_type_name(field_type.getAsString());
- if (field_bitfield_bit_size > 0)
- s->Printf("(%s:%u) ", field_type_name.c_str(), field_bitfield_bit_size);
- else
- s->Printf("(%s) ", field_type_name.c_str());
- }
- // Print the member name and equal sign
- s->Printf("%s = ", field->getNameAsString().c_str());
-
-
- // Dump the value of the member
- ClangASTType field_clang_type (m_ast, field_type);
- field_clang_type.DumpValue (exe_ctx,
- s, // Stream to dump to
- field_clang_type.GetFormat(), // The format with which to display the member
- data, // Data buffer containing all bytes for this type
- data_byte_offset + field_byte_offset,// Offset into "data" where to grab value from
- field_type_info.Width / 8, // Size of this type in bytes
- field_bitfield_bit_size, // Bitfield bit size
- field_bitfield_bit_offset, // Bitfield bit offset
- show_types, // Boolean indicating if we should show the variable types
- show_summary, // Boolean indicating if we should show a summary for the current type
- verbose, // Verbose output?
- depth + DEPTH_INCREMENT); // Scope depth for any types that have children
- }
-
- // Indent the trailing squiggly bracket
- if (child_idx > 0)
- s->Printf("\n%*s}", depth, "");
- }
- return;
-
- case clang::Type::Enum:
- if (GetCompleteType ())
- {
- const clang::EnumType *enum_type = llvm::cast<clang::EnumType>(qual_type.getTypePtr());
- const clang::EnumDecl *enum_decl = enum_type->getDecl();
- assert(enum_decl);
- clang::EnumDecl::enumerator_iterator enum_pos, enum_end_pos;
- lldb::offset_t offset = data_byte_offset;
- const int64_t enum_value = data.GetMaxU64Bitfield(&offset, data_byte_size, bitfield_bit_size, bitfield_bit_offset);
- for (enum_pos = enum_decl->enumerator_begin(), enum_end_pos = enum_decl->enumerator_end(); enum_pos != enum_end_pos; ++enum_pos)
- {
- if (enum_pos->getInitVal() == enum_value)
- {
- s->Printf("%s", enum_pos->getNameAsString().c_str());
- return;
- }
- }
- // If we have gotten here we didn't get find the enumerator in the
- // enum decl, so just print the integer.
- s->Printf("%" PRIi64, enum_value);
- }
- return;
-
- case clang::Type::ConstantArray:
- {
- const clang::ConstantArrayType *array = llvm::cast<clang::ConstantArrayType>(qual_type.getTypePtr());
- bool is_array_of_characters = false;
- clang::QualType element_qual_type = array->getElementType();
-
- const clang::Type *canonical_type = element_qual_type->getCanonicalTypeInternal().getTypePtr();
- if (canonical_type)
- is_array_of_characters = canonical_type->isCharType();
-
- const uint64_t element_count = array->getSize().getLimitedValue();
-
- clang::TypeInfo field_type_info = m_ast->getTypeInfo(element_qual_type);
-
- uint32_t element_idx = 0;
- uint32_t element_offset = 0;
- uint64_t element_byte_size = field_type_info.Width / 8;
- uint32_t element_stride = element_byte_size;
-
- if (is_array_of_characters)
- {
- s->PutChar('"');
- data.Dump(s, data_byte_offset, lldb::eFormatChar, element_byte_size, element_count, UINT32_MAX, LLDB_INVALID_ADDRESS, 0, 0);
- s->PutChar('"');
- return;
- }
- else
- {
- ClangASTType element_clang_type(m_ast, element_qual_type);
- lldb::Format element_format = element_clang_type.GetFormat();
-
- for (element_idx = 0; element_idx < element_count; ++element_idx)
- {
- // Print the starting squiggly bracket (if this is the
- // first member) or comma (for member 2 and beyond) for
- // the struct/union/class member.
- if (element_idx == 0)
- s->PutChar('{');
- else
- s->PutChar(',');
-
- // Indent and print the index
- s->Printf("\n%*s[%u] ", depth + DEPTH_INCREMENT, "", element_idx);
-
- // Figure out the field offset within the current struct/union/class type
- element_offset = element_idx * element_stride;
-
- // Dump the value of the member
- element_clang_type.DumpValue (exe_ctx,
- s, // Stream to dump to
- element_format, // The format with which to display the element
- data, // Data buffer containing all bytes for this type
- data_byte_offset + element_offset,// Offset into "data" where to grab value from
- element_byte_size, // Size of this type in bytes
- 0, // Bitfield bit size
- 0, // Bitfield bit offset
- show_types, // Boolean indicating if we should show the variable types
- show_summary, // Boolean indicating if we should show a summary for the current type
- verbose, // Verbose output?
- depth + DEPTH_INCREMENT); // Scope depth for any types that have children
- }
-
- // Indent the trailing squiggly bracket
- if (element_idx > 0)
- s->Printf("\n%*s}", depth, "");
- }
- }
- return;
-
- case clang::Type::Typedef:
- {
- clang::QualType typedef_qual_type = llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType();
-
- ClangASTType typedef_clang_type (m_ast, typedef_qual_type);
- lldb::Format typedef_format = typedef_clang_type.GetFormat();
- clang::TypeInfo typedef_type_info = m_ast->getTypeInfo(typedef_qual_type);
- uint64_t typedef_byte_size = typedef_type_info.Width / 8;
-
- return typedef_clang_type.DumpValue (exe_ctx,
- s, // Stream to dump to
- typedef_format, // The format with which to display the element
- data, // Data buffer containing all bytes for this type
- data_byte_offset, // Offset into "data" where to grab value from
- typedef_byte_size, // Size of this type in bytes
- bitfield_bit_size, // Bitfield bit size
- bitfield_bit_offset,// Bitfield bit offset
- show_types, // Boolean indicating if we should show the variable types
- show_summary, // Boolean indicating if we should show a summary for the current type
- verbose, // Verbose output?
- depth); // Scope depth for any types that have children
- }
- break;
-
- case clang::Type::Elaborated:
- {
- clang::QualType elaborated_qual_type = llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType();
- ClangASTType elaborated_clang_type (m_ast, elaborated_qual_type);
- lldb::Format elaborated_format = elaborated_clang_type.GetFormat();
- clang::TypeInfo elaborated_type_info = m_ast->getTypeInfo(elaborated_qual_type);
- uint64_t elaborated_byte_size = elaborated_type_info.Width / 8;
-
- return elaborated_clang_type.DumpValue (exe_ctx,
- s, // Stream to dump to
- elaborated_format, // The format with which to display the element
- data, // Data buffer containing all bytes for this type
- data_byte_offset, // Offset into "data" where to grab value from
- elaborated_byte_size, // Size of this type in bytes
- bitfield_bit_size, // Bitfield bit size
- bitfield_bit_offset,// Bitfield bit offset
- show_types, // Boolean indicating if we should show the variable types
- show_summary, // Boolean indicating if we should show a summary for the current type
- verbose, // Verbose output?
- depth); // Scope depth for any types that have children
- }
- break;
-
- case clang::Type::Paren:
- {
- clang::QualType desugar_qual_type = llvm::cast<clang::ParenType>(qual_type)->desugar();
- ClangASTType desugar_clang_type (m_ast, desugar_qual_type);
-
- lldb::Format desugar_format = desugar_clang_type.GetFormat();
- clang::TypeInfo desugar_type_info = m_ast->getTypeInfo(desugar_qual_type);
- uint64_t desugar_byte_size = desugar_type_info.Width / 8;
-
- return desugar_clang_type.DumpValue (exe_ctx,
- s, // Stream to dump to
- desugar_format, // The format with which to display the element
- data, // Data buffer containing all bytes for this type
- data_byte_offset, // Offset into "data" where to grab value from
- desugar_byte_size, // Size of this type in bytes
- bitfield_bit_size, // Bitfield bit size
- bitfield_bit_offset,// Bitfield bit offset
- show_types, // Boolean indicating if we should show the variable types
- show_summary, // Boolean indicating if we should show a summary for the current type
- verbose, // Verbose output?
- depth); // Scope depth for any types that have children
- }
- break;
-
- default:
- // We are down to a scalar type that we just need to display.
- data.Dump(s,
- data_byte_offset,
- format,
- data_byte_size,
- 1,
- UINT32_MAX,
- LLDB_INVALID_ADDRESS,
- bitfield_bit_size,
- bitfield_bit_offset);
-
- if (show_summary)
- DumpSummary (exe_ctx, s, data, data_byte_offset, data_byte_size);
- break;
- }
-}
-
-
-
-
-bool
-ClangASTType::DumpTypeValue (Stream *s,
- lldb::Format format,
- const lldb_private::DataExtractor &data,
- lldb::offset_t byte_offset,
- size_t byte_size,
- uint32_t bitfield_bit_size,
- uint32_t bitfield_bit_offset,
- ExecutionContextScope *exe_scope)
-{
- if (!IsValid())
- return false;
- if (IsAggregateType())
- {
- return false;
- }
- else
- {
- clang::QualType qual_type(GetQualType());
-
- const clang::Type::TypeClass type_class = qual_type->getTypeClass();
- switch (type_class)
- {
- case clang::Type::Typedef:
- {
- clang::QualType typedef_qual_type = llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType();
- ClangASTType typedef_clang_type (m_ast, typedef_qual_type);
- if (format == eFormatDefault)
- format = typedef_clang_type.GetFormat();
- clang::TypeInfo typedef_type_info = m_ast->getTypeInfo(typedef_qual_type);
- uint64_t typedef_byte_size = typedef_type_info.Width / 8;
-
- return typedef_clang_type.DumpTypeValue (s,
- format, // The format with which to display the element
- data, // Data buffer containing all bytes for this type
- byte_offset, // Offset into "data" where to grab value from
- typedef_byte_size, // Size of this type in bytes
- bitfield_bit_size, // Size in bits of a bitfield value, if zero don't treat as a bitfield
- bitfield_bit_offset, // Offset in bits of a bitfield value if bitfield_bit_size != 0
- exe_scope);
- }
- break;
-
- case clang::Type::Enum:
- // If our format is enum or default, show the enumeration value as
- // its enumeration string value, else just display it as requested.
- if ((format == eFormatEnum || format == eFormatDefault) && GetCompleteType ())
- {
- const clang::EnumType *enum_type = llvm::cast<clang::EnumType>(qual_type.getTypePtr());
- const clang::EnumDecl *enum_decl = enum_type->getDecl();
- assert(enum_decl);
- clang::EnumDecl::enumerator_iterator enum_pos, enum_end_pos;
- const bool is_signed = qual_type->isSignedIntegerOrEnumerationType();
- lldb::offset_t offset = byte_offset;
- if (is_signed)
- {
- const int64_t enum_svalue = data.GetMaxS64Bitfield (&offset, byte_size, bitfield_bit_size, bitfield_bit_offset);
- for (enum_pos = enum_decl->enumerator_begin(), enum_end_pos = enum_decl->enumerator_end(); enum_pos != enum_end_pos; ++enum_pos)
- {
- if (enum_pos->getInitVal().getSExtValue() == enum_svalue)
- {
- s->PutCString (enum_pos->getNameAsString().c_str());
- return true;
- }
- }
- // If we have gotten here we didn't get find the enumerator in the
- // enum decl, so just print the integer.
- s->Printf("%" PRIi64, enum_svalue);
- }
- else
- {
- const uint64_t enum_uvalue = data.GetMaxU64Bitfield (&offset, byte_size, bitfield_bit_size, bitfield_bit_offset);
- for (enum_pos = enum_decl->enumerator_begin(), enum_end_pos = enum_decl->enumerator_end(); enum_pos != enum_end_pos; ++enum_pos)
- {
- if (enum_pos->getInitVal().getZExtValue() == enum_uvalue)
- {
- s->PutCString (enum_pos->getNameAsString().c_str());
- return true;
- }
- }
- // If we have gotten here we didn't get find the enumerator in the
- // enum decl, so just print the integer.
- s->Printf("%" PRIu64, enum_uvalue);
- }
- return true;
- }
- // format was not enum, just fall through and dump the value as requested....
-
- default:
- // We are down to a scalar type that we just need to display.
- {
- uint32_t item_count = 1;
- // A few formats, we might need to modify our size and count for depending
- // on how we are trying to display the value...
- switch (format)
- {
- default:
- case eFormatBoolean:
- case eFormatBinary:
- case eFormatComplex:
- case eFormatCString: // NULL terminated C strings
- case eFormatDecimal:
- case eFormatEnum:
- case eFormatHex:
- case eFormatHexUppercase:
- case eFormatFloat:
- case eFormatOctal:
- case eFormatOSType:
- case eFormatUnsigned:
- case eFormatPointer:
- case eFormatVectorOfChar:
- case eFormatVectorOfSInt8:
- case eFormatVectorOfUInt8:
- case eFormatVectorOfSInt16:
- case eFormatVectorOfUInt16:
- case eFormatVectorOfSInt32:
- case eFormatVectorOfUInt32:
- case eFormatVectorOfSInt64:
- case eFormatVectorOfUInt64:
- case eFormatVectorOfFloat32:
- case eFormatVectorOfFloat64:
- case eFormatVectorOfUInt128:
- break;
-
- case eFormatChar:
- case eFormatCharPrintable:
- case eFormatCharArray:
- case eFormatBytes:
- case eFormatBytesWithASCII:
- item_count = byte_size;
- byte_size = 1;
- break;
-
- case eFormatUnicode16:
- item_count = byte_size / 2;
- byte_size = 2;
- break;
-
- case eFormatUnicode32:
- item_count = byte_size / 4;
- byte_size = 4;
- break;
- }
- return data.Dump (s,
- byte_offset,
- format,
- byte_size,
- item_count,
- UINT32_MAX,
- LLDB_INVALID_ADDRESS,
- bitfield_bit_size,
- bitfield_bit_offset,
- exe_scope);
- }
- break;
- }
- }
- return 0;
-}
-
-
-
-void
-ClangASTType::DumpSummary (ExecutionContext *exe_ctx,
- Stream *s,
- const lldb_private::DataExtractor &data,
- lldb::offset_t data_byte_offset,
- size_t data_byte_size)
-{
- uint32_t length = 0;
- if (IsCStringType (length))
- {
- if (exe_ctx)
- {
- Process *process = exe_ctx->GetProcessPtr();
- if (process)
- {
- lldb::offset_t offset = data_byte_offset;
- lldb::addr_t pointer_address = data.GetMaxU64(&offset, data_byte_size);
- std::vector<uint8_t> buf;
- if (length > 0)
- buf.resize (length);
- else
- buf.resize (256);
-
- lldb_private::DataExtractor cstr_data(&buf.front(), buf.size(), process->GetByteOrder(), 4);
- buf.back() = '\0';
- size_t bytes_read;
- size_t total_cstr_len = 0;
- Error error;
- while ((bytes_read = process->ReadMemory (pointer_address, &buf.front(), buf.size(), error)) > 0)
- {
- const size_t len = strlen((const char *)&buf.front());
- if (len == 0)
- break;
- if (total_cstr_len == 0)
- s->PutCString (" \"");
- cstr_data.Dump(s, 0, lldb::eFormatChar, 1, len, UINT32_MAX, LLDB_INVALID_ADDRESS, 0, 0);
- total_cstr_len += len;
- if (len < buf.size())
- break;
- pointer_address += total_cstr_len;
- }
- if (total_cstr_len > 0)
- s->PutChar ('"');
- }
- }
- }
-}
-
-void
-ClangASTType::DumpTypeDescription () const
-{
- StreamFile s (stdout, false);
- DumpTypeDescription (&s);
- ClangASTMetadata *metadata = ClangASTContext::GetMetadata (m_ast, m_type);
- if (metadata)
- {
- metadata->Dump (&s);
- }
-}
-
-void
-ClangASTType::DumpTypeDescription (Stream *s) const
-{
- if (IsValid())
- {
- clang::QualType qual_type(GetQualType());
-
- llvm::SmallVector<char, 1024> buf;
- llvm::raw_svector_ostream llvm_ostrm (buf);
-
- const clang::Type::TypeClass type_class = qual_type->getTypeClass();
- switch (type_class)
- {
- case clang::Type::ObjCObject:
- case clang::Type::ObjCInterface:
- {
- GetCompleteType ();
-
- const clang::ObjCObjectType *objc_class_type = llvm::dyn_cast<clang::ObjCObjectType>(qual_type.getTypePtr());
- assert (objc_class_type);
- if (objc_class_type)
- {
- clang::ObjCInterfaceDecl *class_interface_decl = objc_class_type->getInterface();
- if (class_interface_decl)
- {
- clang::PrintingPolicy policy = m_ast->getPrintingPolicy();
- class_interface_decl->print(llvm_ostrm, policy, s->GetIndentLevel());
- }
- }
- }
- break;
-
- case clang::Type::Typedef:
- {
- const clang::TypedefType *typedef_type = qual_type->getAs<clang::TypedefType>();
- if (typedef_type)
- {
- const clang::TypedefNameDecl *typedef_decl = typedef_type->getDecl();
- std::string clang_typedef_name (typedef_decl->getQualifiedNameAsString());
- if (!clang_typedef_name.empty())
- {
- s->PutCString ("typedef ");
- s->PutCString (clang_typedef_name.c_str());
- }
- }
- }
- break;
-
- case clang::Type::Elaborated:
- ClangASTType (m_ast, llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType()).DumpTypeDescription(s);
- return;
-
- case clang::Type::Paren:
- ClangASTType (m_ast, llvm::cast<clang::ParenType>(qual_type)->desugar()).DumpTypeDescription(s);
- return;
-
- case clang::Type::Record:
- {
- GetCompleteType ();
-
- const clang::RecordType *record_type = llvm::cast<clang::RecordType>(qual_type.getTypePtr());
- const clang::RecordDecl *record_decl = record_type->getDecl();
- const clang::CXXRecordDecl *cxx_record_decl = llvm::dyn_cast<clang::CXXRecordDecl>(record_decl);
-
- if (cxx_record_decl)
- cxx_record_decl->print(llvm_ostrm, m_ast->getPrintingPolicy(), s->GetIndentLevel());
- else
- record_decl->print(llvm_ostrm, m_ast->getPrintingPolicy(), s->GetIndentLevel());
- }
- break;
-
- default:
- {
- const clang::TagType *tag_type = llvm::dyn_cast<clang::TagType>(qual_type.getTypePtr());
- if (tag_type)
- {
- clang::TagDecl *tag_decl = tag_type->getDecl();
- if (tag_decl)
- tag_decl->print(llvm_ostrm, 0);
- }
- else
- {
- std::string clang_type_name(qual_type.getAsString());
- if (!clang_type_name.empty())
- s->PutCString (clang_type_name.c_str());
- }
- }
- }
-
- llvm_ostrm.flush();
- if (buf.size() > 0)
- {
- s->Write (buf.data(), buf.size());
- }
- }
-}
-
-bool
-ClangASTType::GetValueAsScalar (const lldb_private::DataExtractor &data,
- lldb::offset_t data_byte_offset,
- size_t data_byte_size,
- Scalar &value) const
-{
- if (!IsValid())
- return false;
-
- if (IsAggregateType ())
- {
- return false; // Aggregate types don't have scalar values
- }
- else
- {
- uint64_t count = 0;
- lldb::Encoding encoding = GetEncoding (count);
-
- if (encoding == lldb::eEncodingInvalid || count != 1)
- return false;
-
- const uint64_t byte_size = GetByteSize(nullptr);
- lldb::offset_t offset = data_byte_offset;
- switch (encoding)
- {
- case lldb::eEncodingInvalid:
- break;
- case lldb::eEncodingVector:
- break;
- case lldb::eEncodingUint:
- if (byte_size <= sizeof(unsigned long long))
- {
- uint64_t uval64 = data.GetMaxU64 (&offset, byte_size);
- if (byte_size <= sizeof(unsigned int))
- {
- value = (unsigned int)uval64;
- return true;
- }
- else if (byte_size <= sizeof(unsigned long))
- {
- value = (unsigned long)uval64;
- return true;
- }
- else if (byte_size <= sizeof(unsigned long long))
- {
- value = (unsigned long long )uval64;
- return true;
- }
- else
- value.Clear();
- }
- break;
-
- case lldb::eEncodingSint:
- if (byte_size <= sizeof(long long))
- {
- int64_t sval64 = data.GetMaxS64 (&offset, byte_size);
- if (byte_size <= sizeof(int))
- {
- value = (int)sval64;
- return true;
- }
- else if (byte_size <= sizeof(long))
- {
- value = (long)sval64;
- return true;
- }
- else if (byte_size <= sizeof(long long))
- {
- value = (long long )sval64;
- return true;
- }
- else
- value.Clear();
- }
- break;
-
- case lldb::eEncodingIEEE754:
- if (byte_size <= sizeof(long double))
- {
- uint32_t u32;
- uint64_t u64;
- if (byte_size == sizeof(float))
- {
- if (sizeof(float) == sizeof(uint32_t))
- {
- u32 = data.GetU32(&offset);
- value = *((float *)&u32);
- return true;
- }
- else if (sizeof(float) == sizeof(uint64_t))
- {
- u64 = data.GetU64(&offset);
- value = *((float *)&u64);
- return true;
- }
- }
- else
- if (byte_size == sizeof(double))
- {
- if (sizeof(double) == sizeof(uint32_t))
- {
- u32 = data.GetU32(&offset);
- value = *((double *)&u32);
- return true;
- }
- else if (sizeof(double) == sizeof(uint64_t))
- {
- u64 = data.GetU64(&offset);
- value = *((double *)&u64);
- return true;
- }
- }
- else
- if (byte_size == sizeof(long double))
- {
- if (sizeof(long double) == sizeof(uint32_t))
- {
- u32 = data.GetU32(&offset);
- value = *((long double *)&u32);
- return true;
- }
- else if (sizeof(long double) == sizeof(uint64_t))
- {
- u64 = data.GetU64(&offset);
- value = *((long double *)&u64);
- return true;
- }
- }
- }
- break;
- }
- }
- return false;
-}
-
-bool
-ClangASTType::SetValueFromScalar (const Scalar &value, Stream &strm)
-{
- // Aggregate types don't have scalar values
- if (!IsAggregateType ())
- {
- strm.GetFlags().Set(Stream::eBinary);
- uint64_t count = 0;
- lldb::Encoding encoding = GetEncoding (count);
-
- if (encoding == lldb::eEncodingInvalid || count != 1)
- return false;
-
- const uint64_t bit_width = GetBitSize(nullptr);
- // This function doesn't currently handle non-byte aligned assignments
- if ((bit_width % 8) != 0)
- return false;
-
- const uint64_t byte_size = (bit_width + 7 ) / 8;
- switch (encoding)
- {
- case lldb::eEncodingInvalid:
- break;
- case lldb::eEncodingVector:
- break;
- case lldb::eEncodingUint:
- switch (byte_size)
- {
- case 1: strm.PutHex8(value.UInt()); return true;
- case 2: strm.PutHex16(value.UInt()); return true;
- case 4: strm.PutHex32(value.UInt()); return true;
- case 8: strm.PutHex64(value.ULongLong()); return true;
- default:
- break;
- }
- break;
-
- case lldb::eEncodingSint:
- switch (byte_size)
- {
- case 1: strm.PutHex8(value.SInt()); return true;
- case 2: strm.PutHex16(value.SInt()); return true;
- case 4: strm.PutHex32(value.SInt()); return true;
- case 8: strm.PutHex64(value.SLongLong()); return true;
- default:
- break;
- }
- break;
-
- case lldb::eEncodingIEEE754:
- if (byte_size <= sizeof(long double))
- {
- if (byte_size == sizeof(float))
- {
- strm.PutFloat(value.Float());
- return true;
- }
- else
- if (byte_size == sizeof(double))
- {
- strm.PutDouble(value.Double());
- return true;
- }
- else
- if (byte_size == sizeof(long double))
- {
- strm.PutDouble(value.LongDouble());
- return true;
- }
- }
- break;
- }
- }
- return false;
-}
-
-bool
-ClangASTType::ReadFromMemory (lldb_private::ExecutionContext *exe_ctx,
- lldb::addr_t addr,
- AddressType address_type,
- lldb_private::DataExtractor &data)
-{
- if (!IsValid())
- return false;
-
- // Can't convert a file address to anything valid without more
- // context (which Module it came from)
- if (address_type == eAddressTypeFile)
- return false;
-
- if (!GetCompleteType())
- return false;
-
- const uint64_t byte_size = GetByteSize(exe_ctx ? exe_ctx->GetBestExecutionContextScope() : NULL);
- if (data.GetByteSize() < byte_size)
- {
- lldb::DataBufferSP data_sp(new DataBufferHeap (byte_size, '\0'));
- data.SetData(data_sp);
- }
-
- uint8_t* dst = (uint8_t*)data.PeekData(0, byte_size);
- if (dst != nullptr)
- {
- if (address_type == eAddressTypeHost)
- {
- if (addr == 0)
- return false;
- // The address is an address in this process, so just copy it
- memcpy (dst, (uint8_t*)nullptr + addr, byte_size);
- return true;
- }
- else
- {
- Process *process = nullptr;
- if (exe_ctx)
- process = exe_ctx->GetProcessPtr();
- if (process)
- {
- Error error;
- return process->ReadMemory(addr, dst, byte_size, error) == byte_size;
- }
- }
- }
- return false;
-}
-
-bool
-ClangASTType::WriteToMemory (lldb_private::ExecutionContext *exe_ctx,
- lldb::addr_t addr,
- AddressType address_type,
- StreamString &new_value)
-{
- if (!IsValid())
- return false;
-
- // Can't convert a file address to anything valid without more
- // context (which Module it came from)
- if (address_type == eAddressTypeFile)
- return false;
-
- if (!GetCompleteType())
- return false;
-
- const uint64_t byte_size = GetByteSize(exe_ctx ? exe_ctx->GetBestExecutionContextScope() : NULL);
-
- if (byte_size > 0)
- {
- if (address_type == eAddressTypeHost)
- {
- // The address is an address in this process, so just copy it
- memcpy ((void *)addr, new_value.GetData(), byte_size);
- return true;
- }
- else
- {
- Process *process = nullptr;
- if (exe_ctx)
- process = exe_ctx->GetProcessPtr();
- if (process)
- {
- Error error;
- return process->WriteMemory(addr, new_value.GetData(), byte_size, error) == byte_size;
- }
- }
- }
- return false;
-}
-
-
-//clang::CXXRecordDecl *
-//ClangASTType::GetAsCXXRecordDecl (lldb::clang_type_t opaque_clang_qual_type)
-//{
-// if (opaque_clang_qual_type)
-// return clang::QualType::getFromOpaquePtr(opaque_clang_qual_type)->getAsCXXRecordDecl();
-// return NULL;
-//}
-
-bool
-lldb_private::operator == (const lldb_private::ClangASTType &lhs, const lldb_private::ClangASTType &rhs)
-{
- return lhs.GetASTContext() == rhs.GetASTContext() && lhs.GetOpaqueQualType() == rhs.GetOpaqueQualType();
-}
-
-
-bool
-lldb_private::operator != (const lldb_private::ClangASTType &lhs, const lldb_private::ClangASTType &rhs)
-{
- return lhs.GetASTContext() != rhs.GetASTContext() || lhs.GetOpaqueQualType() != rhs.GetOpaqueQualType();
-}
-
-
-
diff --git a/source/Symbol/ClangExternalASTSourceCallbacks.cpp b/source/Symbol/ClangExternalASTSourceCallbacks.cpp
index cd6972cce9720..6c804f4d969ce 100644
--- a/source/Symbol/ClangExternalASTSourceCallbacks.cpp
+++ b/source/Symbol/ClangExternalASTSourceCallbacks.cpp
@@ -41,6 +41,7 @@
#endif
#include "lldb/Core/Log.h"
+#include "clang/AST/Decl.h"
using namespace clang;
using namespace lldb_private;
@@ -160,3 +161,16 @@ ClangExternalASTSourceCallbacks::layoutRecordType(
return false;
}
+void
+ClangExternalASTSourceCallbacks::FindExternalLexicalDecls (const clang::DeclContext *decl_ctx,
+ llvm::function_ref<bool(clang::Decl::Kind)> IsKindWeWant,
+ llvm::SmallVectorImpl<clang::Decl *> &decls)
+{
+ if (m_callback_tag_decl && decl_ctx)
+ {
+ clang::TagDecl *tag_decl = llvm::dyn_cast<clang::TagDecl>(const_cast<clang::DeclContext *>(decl_ctx));
+ if (tag_decl)
+ CompleteType(tag_decl);
+ }
+}
+
diff --git a/source/Symbol/ClangNamespaceDecl.cpp b/source/Symbol/ClangNamespaceDecl.cpp
deleted file mode 100644
index 568b0263f0feb..0000000000000
--- a/source/Symbol/ClangNamespaceDecl.cpp
+++ /dev/null
@@ -1,25 +0,0 @@
-//===-- ClangNamespaceDecl.cpp ----------------------------------*- C++ -*-===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#include "lldb/Symbol/ClangNamespaceDecl.h"
-
-#include "clang/AST/Decl.h"
-
-namespace lldb_private {
-
-std::string
-ClangNamespaceDecl::GetQualifiedName () const
-{
- if (m_namespace_decl)
- return m_namespace_decl->getQualifiedNameAsString();
- return std::string();
-}
-
-
-}
diff --git a/source/Symbol/CompactUnwindInfo.cpp b/source/Symbol/CompactUnwindInfo.cpp
index afef4e480e8e0..233ca91ec8d8a 100644
--- a/source/Symbol/CompactUnwindInfo.cpp
+++ b/source/Symbol/CompactUnwindInfo.cpp
@@ -297,7 +297,7 @@ CompactUnwindInfo::ScanIndex (const ProcessSP &process_sp)
Host::SystemLog (Host::eSystemLogError,
"error: Invalid offset encountered in compact unwind info, skipping\n");
// don't trust anything from this compact_unwind section if it looks
- // blatently invalid data in the header.
+ // blatantly invalid data in the header.
m_indexes_computed = eLazyBoolNo;
return;
}
@@ -693,7 +693,7 @@ enum x86_64_eh_regnum {
};
// Convert the compact_unwind_info.h register numbering scheme
-// to eRegisterKindGCC (eh_frame) register numbering scheme.
+// to eRegisterKindEHFrame (eh_frame) register numbering scheme.
uint32_t
translate_to_eh_frame_regnum_x86_64 (uint32_t unwind_regno)
{
@@ -722,7 +722,7 @@ CompactUnwindInfo::CreateUnwindPlan_x86_64 (Target &target, FunctionInfo &functi
unwind_plan.SetSourceName ("compact unwind info");
unwind_plan.SetSourcedFromCompiler (eLazyBoolYes);
unwind_plan.SetUnwindPlanValidAtAllInstructions (eLazyBoolNo);
- unwind_plan.SetRegisterKind (eRegisterKindGCC);
+ unwind_plan.SetRegisterKind (eRegisterKindEHFrame);
unwind_plan.SetLSDAAddress (function_info.lsda_address);
unwind_plan.SetPersonalityFunctionPtr (function_info.personality_ptr_address);
@@ -976,7 +976,7 @@ enum i386_eh_regnum {
};
// Convert the compact_unwind_info.h register numbering scheme
-// to eRegisterKindGCC (eh_frame) register numbering scheme.
+// to eRegisterKindEHFrame (eh_frame) register numbering scheme.
uint32_t
translate_to_eh_frame_regnum_i386 (uint32_t unwind_regno)
{
@@ -1006,7 +1006,7 @@ CompactUnwindInfo::CreateUnwindPlan_i386 (Target &target, FunctionInfo &function
unwind_plan.SetSourceName ("compact unwind info");
unwind_plan.SetSourcedFromCompiler (eLazyBoolYes);
unwind_plan.SetUnwindPlanValidAtAllInstructions (eLazyBoolNo);
- unwind_plan.SetRegisterKind (eRegisterKindGCC);
+ unwind_plan.SetRegisterKind (eRegisterKindEHFrame);
unwind_plan.SetLSDAAddress (function_info.lsda_address);
unwind_plan.SetPersonalityFunctionPtr (function_info.personality_ptr_address);
diff --git a/source/Symbol/CompileUnit.cpp b/source/Symbol/CompileUnit.cpp
index d43ef44a13763..50eda8806375b 100644
--- a/source/Symbol/CompileUnit.cpp
+++ b/source/Symbol/CompileUnit.cpp
@@ -9,15 +9,15 @@
#include "lldb/Symbol/CompileUnit.h"
#include "lldb/Core/Module.h"
-#include "lldb/Core/Language.h"
#include "lldb/Symbol/LineTable.h"
#include "lldb/Symbol/SymbolVendor.h"
#include "lldb/Symbol/VariableList.h"
+#include "lldb/Target/Language.h"
using namespace lldb;
using namespace lldb_private;
-CompileUnit::CompileUnit (const lldb::ModuleSP &module_sp, void *user_data, const char *pathname, const lldb::user_id_t cu_sym_id, lldb::LanguageType language) :
+CompileUnit::CompileUnit (const lldb::ModuleSP &module_sp, void *user_data, const char *pathname, const lldb::user_id_t cu_sym_id, lldb::LanguageType language, bool is_optimized) :
ModuleChild(module_sp),
FileSpec (pathname, false),
UserID(cu_sym_id),
@@ -27,14 +27,15 @@ CompileUnit::CompileUnit (const lldb::ModuleSP &module_sp, void *user_data, cons
m_functions (),
m_support_files (),
m_line_table_ap (),
- m_variables()
+ m_variables(),
+ m_is_optimized (is_optimized)
{
if (language != eLanguageTypeUnknown)
m_flags.Set(flagsParsedLanguage);
assert(module_sp);
}
-CompileUnit::CompileUnit (const lldb::ModuleSP &module_sp, void *user_data, const FileSpec &fspec, const lldb::user_id_t cu_sym_id, lldb::LanguageType language) :
+CompileUnit::CompileUnit (const lldb::ModuleSP &module_sp, void *user_data, const FileSpec &fspec, const lldb::user_id_t cu_sym_id, lldb::LanguageType language, bool is_optimized) :
ModuleChild(module_sp),
FileSpec (fspec),
UserID(cu_sym_id),
@@ -44,7 +45,8 @@ CompileUnit::CompileUnit (const lldb::ModuleSP &module_sp, void *user_data, cons
m_functions (),
m_support_files (),
m_line_table_ap (),
- m_variables()
+ m_variables(),
+ m_is_optimized (is_optimized)
{
if (language != eLanguageTypeUnknown)
m_flags.Set(flagsParsedLanguage);
@@ -85,7 +87,7 @@ CompileUnit::DumpSymbolContext(Stream *s)
void
CompileUnit::GetDescription(Stream *s, lldb::DescriptionLevel level) const
{
- Language language(m_language);
+ const char* language = Language::GetNameForLanguageType(m_language);
*s << "id = " << (const UserID&)*this << ", file = \"" << (const FileSpec&)*this << "\", language = \"" << language << '"';
}
@@ -99,10 +101,12 @@ CompileUnit::GetDescription(Stream *s, lldb::DescriptionLevel level) const
void
CompileUnit::Dump(Stream *s, bool show_context) const
{
+ const char* language = Language::GetNameForLanguageType(m_language);
+
s->Printf("%p: ", static_cast<const void*>(this));
s->Indent();
*s << "CompileUnit" << static_cast<const UserID&>(*this)
- << ", language = \"" << reinterpret_cast<const Language&>(*this)
+ << ", language = \"" << language
<< "\", file = '" << static_cast<const FileSpec&>(*this) << "'\n";
// m_types.Dump(s);
@@ -264,6 +268,37 @@ CompileUnit::SetLineTable(LineTable* line_table)
m_line_table_ap.reset(line_table);
}
+DebugMacros*
+CompileUnit::GetDebugMacros()
+{
+ if (m_debug_macros_sp.get() == nullptr)
+ {
+ if (m_flags.IsClear(flagsParsedDebugMacros))
+ {
+ m_flags.Set(flagsParsedDebugMacros);
+ SymbolVendor* symbol_vendor = GetModule()->GetSymbolVendor();
+ if (symbol_vendor)
+ {
+ SymbolContext sc;
+ CalculateSymbolContext(&sc);
+ symbol_vendor->ParseCompileUnitDebugMacros(sc);
+ }
+ }
+ }
+
+ return m_debug_macros_sp.get();
+}
+
+void
+CompileUnit::SetDebugMacros(const DebugMacrosSP &debug_macros_sp)
+{
+ if (debug_macros_sp.get() == nullptr)
+ m_flags.Clear(flagsParsedDebugMacros);
+ else
+ m_flags.Set(flagsParsedDebugMacros);
+ m_debug_macros_sp = debug_macros_sp;
+}
+
VariableListSP
CompileUnit::GetVariableList(bool can_create)
{
@@ -430,6 +465,12 @@ CompileUnit::ResolveSymbolContext
return sc_list.GetSize() - prev_size;
}
+bool
+CompileUnit::GetIsOptimized ()
+{
+ return m_is_optimized;
+}
+
void
CompileUnit::SetVariableList(VariableListSP &variables)
{
diff --git a/source/Symbol/CompilerDecl.cpp b/source/Symbol/CompilerDecl.cpp
new file mode 100644
index 0000000000000..42e5fb0810711
--- /dev/null
+++ b/source/Symbol/CompilerDecl.cpp
@@ -0,0 +1,76 @@
+//===-- CompilerDecl.cpp ----------------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "lldb/Symbol/CompilerDecl.h"
+#include "lldb/Symbol/CompilerDeclContext.h"
+#include "lldb/Symbol/TypeSystem.h"
+
+using namespace lldb_private;
+
+bool
+CompilerDecl::IsClang () const
+{
+ return IsValid() && m_type_system->getKind() == TypeSystem::eKindClang;
+}
+
+ConstString
+CompilerDecl::GetName() const
+{
+ return m_type_system->DeclGetName(m_opaque_decl);
+}
+
+ConstString
+CompilerDecl::GetMangledName () const
+{
+ return m_type_system->DeclGetMangledName(m_opaque_decl);
+}
+
+lldb::VariableSP
+CompilerDecl::GetAsVariable ()
+{
+ return m_type_system->DeclGetVariable(m_opaque_decl);
+}
+
+CompilerDeclContext
+CompilerDecl::GetDeclContext() const
+{
+ return m_type_system->DeclGetDeclContext(m_opaque_decl);
+}
+
+CompilerType
+CompilerDecl::GetFunctionReturnType() const
+{
+ return m_type_system->DeclGetFunctionReturnType(m_opaque_decl);
+}
+
+size_t
+CompilerDecl::GetNumFunctionArguments() const
+{
+ return m_type_system->DeclGetFunctionNumArguments(m_opaque_decl);
+}
+
+CompilerType
+CompilerDecl::GetFunctionArgumentType (size_t arg_idx) const
+{
+ return m_type_system->DeclGetFunctionArgumentType(m_opaque_decl, arg_idx);
+}
+
+bool
+lldb_private::operator == (const lldb_private::CompilerDecl &lhs, const lldb_private::CompilerDecl &rhs)
+{
+ return lhs.GetTypeSystem() == rhs.GetTypeSystem() && lhs.GetOpaqueDecl() == rhs.GetOpaqueDecl();
+}
+
+
+bool
+lldb_private::operator != (const lldb_private::CompilerDecl &lhs, const lldb_private::CompilerDecl &rhs)
+{
+ return lhs.GetTypeSystem() != rhs.GetTypeSystem() || lhs.GetOpaqueDecl() != rhs.GetOpaqueDecl();
+}
+
diff --git a/source/Symbol/CompilerDeclContext.cpp b/source/Symbol/CompilerDeclContext.cpp
new file mode 100644
index 0000000000000..e44cee67284c0
--- /dev/null
+++ b/source/Symbol/CompilerDeclContext.cpp
@@ -0,0 +1,75 @@
+//===-- CompilerDeclContext.cpp ---------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "lldb/Symbol/CompilerDeclContext.h"
+#include "lldb/Symbol/CompilerDecl.h"
+#include "lldb/Symbol/TypeSystem.h"
+#include <vector>
+
+using namespace lldb_private;
+
+std::vector<CompilerDecl>
+CompilerDeclContext::FindDeclByName (ConstString name)
+{
+ if (IsValid())
+ return m_type_system->DeclContextFindDeclByName(m_opaque_decl_ctx, name);
+ else
+ return std::vector<CompilerDecl>();
+}
+
+bool
+CompilerDeclContext::IsClang () const
+{
+ return IsValid() && m_type_system->getKind() == TypeSystem::eKindClang;
+}
+
+ConstString
+CompilerDeclContext::GetName () const
+{
+ if (IsValid())
+ return m_type_system->DeclContextGetName(m_opaque_decl_ctx);
+ else
+ return ConstString();
+}
+
+bool
+CompilerDeclContext::IsStructUnionOrClass () const
+{
+ if (IsValid())
+ return m_type_system->DeclContextIsStructUnionOrClass(m_opaque_decl_ctx);
+ else
+ return false;
+}
+
+bool
+CompilerDeclContext::IsClassMethod (lldb::LanguageType *language_ptr,
+ bool *is_instance_method_ptr,
+ ConstString *language_object_name_ptr)
+{
+ if (IsValid())
+ return m_type_system->DeclContextIsClassMethod (m_opaque_decl_ctx,
+ language_ptr,
+ is_instance_method_ptr,
+ language_object_name_ptr);
+ else
+ return false;
+}
+
+bool
+lldb_private::operator == (const lldb_private::CompilerDeclContext &lhs, const lldb_private::CompilerDeclContext &rhs)
+{
+ return lhs.GetTypeSystem() == rhs.GetTypeSystem() && lhs.GetOpaqueDeclContext() == rhs.GetOpaqueDeclContext();
+}
+
+
+bool
+lldb_private::operator != (const lldb_private::CompilerDeclContext &lhs, const lldb_private::CompilerDeclContext &rhs)
+{
+ return lhs.GetTypeSystem() != rhs.GetTypeSystem() || lhs.GetOpaqueDeclContext() != rhs.GetOpaqueDeclContext();
+}
diff --git a/source/Symbol/CompilerType.cpp b/source/Symbol/CompilerType.cpp
new file mode 100644
index 0000000000000..000a949626c59
--- /dev/null
+++ b/source/Symbol/CompilerType.cpp
@@ -0,0 +1,1320 @@
+//===-- CompilerType.cpp ----------------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "lldb/Symbol/CompilerType.h"
+
+#include "lldb/Core/ConstString.h"
+#include "lldb/Core/DataBufferHeap.h"
+#include "lldb/Core/DataExtractor.h"
+#include "lldb/Core/Debugger.h"
+#include "lldb/Core/Scalar.h"
+#include "lldb/Core/Stream.h"
+#include "lldb/Core/StreamFile.h"
+#include "lldb/Core/StreamString.h"
+#include "lldb/Symbol/ClangASTContext.h"
+#include "lldb/Symbol/ClangExternalASTSourceCommon.h"
+#include "lldb/Symbol/Type.h"
+#include "lldb/Target/ExecutionContext.h"
+#include "lldb/Target/Process.h"
+
+#include <iterator>
+#include <mutex>
+
+using namespace lldb;
+using namespace lldb_private;
+
+CompilerType::CompilerType (TypeSystem *type_system,
+ lldb::opaque_compiler_type_t type) :
+ m_type (type),
+ m_type_system (type_system)
+{
+}
+
+CompilerType::CompilerType (clang::ASTContext *ast,
+ clang::QualType qual_type) :
+ m_type (qual_type.getAsOpaquePtr()),
+ m_type_system (ClangASTContext::GetASTContext(ast))
+{
+#ifdef LLDB_CONFIGURATION_DEBUG
+ if (m_type)
+ assert(m_type_system != nullptr);
+#endif
+}
+
+CompilerType::~CompilerType()
+{
+}
+
+//----------------------------------------------------------------------
+// Tests
+//----------------------------------------------------------------------
+
+bool
+CompilerType::IsAggregateType () const
+{
+ if (IsValid())
+ return m_type_system->IsAggregateType(m_type);
+ return false;
+}
+
+bool
+CompilerType::IsAnonymousType () const
+{
+ if (IsValid())
+ return m_type_system->IsAnonymousType(m_type);
+ return false;
+}
+
+bool
+CompilerType::IsArrayType (CompilerType *element_type_ptr,
+ uint64_t *size,
+ bool *is_incomplete) const
+{
+ if (IsValid())
+ return m_type_system->IsArrayType(m_type, element_type_ptr, size, is_incomplete);
+
+ if (element_type_ptr)
+ element_type_ptr->Clear();
+ if (size)
+ *size = 0;
+ if (is_incomplete)
+ *is_incomplete = false;
+ return false;
+}
+
+bool
+CompilerType::IsVectorType (CompilerType *element_type,
+ uint64_t *size) const
+{
+ if (IsValid())
+ return m_type_system->IsVectorType(m_type, element_type, size);
+ return false;
+}
+
+bool
+CompilerType::IsRuntimeGeneratedType () const
+{
+ if (IsValid())
+ return m_type_system->IsRuntimeGeneratedType(m_type);
+ return false;
+}
+
+bool
+CompilerType::IsCharType () const
+{
+ if (IsValid())
+ return m_type_system->IsCharType(m_type);
+ return false;
+}
+
+
+bool
+CompilerType::IsCompleteType () const
+{
+ if (IsValid())
+ return m_type_system->IsCompleteType(m_type);
+ return false;
+}
+
+bool
+CompilerType::IsConst() const
+{
+ if (IsValid())
+ return m_type_system->IsConst(m_type);
+ return false;
+}
+
+bool
+CompilerType::IsCStringType (uint32_t &length) const
+{
+ if (IsValid())
+ return m_type_system->IsCStringType(m_type, length);
+ return false;
+}
+
+bool
+CompilerType::IsFunctionType (bool *is_variadic_ptr) const
+{
+ if (IsValid())
+ return m_type_system->IsFunctionType(m_type, is_variadic_ptr);
+ return false;
+}
+
+// Used to detect "Homogeneous Floating-point Aggregates"
+uint32_t
+CompilerType::IsHomogeneousAggregate (CompilerType* base_type_ptr) const
+{
+ if (IsValid())
+ return m_type_system->IsHomogeneousAggregate(m_type, base_type_ptr);
+ return 0;
+}
+
+size_t
+CompilerType::GetNumberOfFunctionArguments () const
+{
+ if (IsValid())
+ return m_type_system->GetNumberOfFunctionArguments(m_type);
+ return 0;
+}
+
+CompilerType
+CompilerType::GetFunctionArgumentAtIndex (const size_t index) const
+{
+ if (IsValid())
+ return m_type_system->GetFunctionArgumentAtIndex(m_type, index);
+ return CompilerType();
+}
+
+bool
+CompilerType::IsFunctionPointerType () const
+{
+ if (IsValid())
+ return m_type_system->IsFunctionPointerType(m_type);
+ return false;
+
+}
+
+bool
+CompilerType::IsIntegerType (bool &is_signed) const
+{
+ if (IsValid())
+ return m_type_system->IsIntegerType(m_type, is_signed);
+ return false;
+}
+
+bool
+CompilerType::IsPointerType (CompilerType *pointee_type) const
+{
+ if (IsValid())
+ {
+ return m_type_system->IsPointerType(m_type, pointee_type);
+ }
+ if (pointee_type)
+ pointee_type->Clear();
+ return false;
+}
+
+
+bool
+CompilerType::IsPointerOrReferenceType (CompilerType *pointee_type) const
+{
+ if (IsValid())
+ {
+ return m_type_system->IsPointerOrReferenceType(m_type, pointee_type);
+ }
+ if (pointee_type)
+ pointee_type->Clear();
+ return false;
+}
+
+
+bool
+CompilerType::IsReferenceType (CompilerType *pointee_type, bool* is_rvalue) const
+{
+ if (IsValid())
+ {
+ return m_type_system->IsReferenceType(m_type, pointee_type, is_rvalue);
+ }
+ if (pointee_type)
+ pointee_type->Clear();
+ return false;
+}
+
+bool
+CompilerType::ShouldTreatScalarValueAsAddress () const
+{
+ if (IsValid())
+ return m_type_system->ShouldTreatScalarValueAsAddress(m_type);
+ return false;
+}
+
+bool
+CompilerType::IsFloatingPointType (uint32_t &count, bool &is_complex) const
+{
+ if (IsValid())
+ {
+ return m_type_system->IsFloatingPointType(m_type, count, is_complex);
+ }
+ count = 0;
+ is_complex = false;
+ return false;
+}
+
+
+bool
+CompilerType::IsDefined() const
+{
+ if (IsValid())
+ return m_type_system->IsDefined(m_type);
+ return true;
+}
+
+bool
+CompilerType::IsPolymorphicClass () const
+{
+ if (IsValid())
+ {
+ return m_type_system->IsPolymorphicClass(m_type);
+ }
+ return false;
+}
+
+bool
+CompilerType::IsPossibleDynamicType (CompilerType *dynamic_pointee_type,
+ bool check_cplusplus,
+ bool check_objc) const
+{
+ if (IsValid())
+ return m_type_system->IsPossibleDynamicType(m_type, dynamic_pointee_type, check_cplusplus, check_objc);
+ return false;
+}
+
+
+bool
+CompilerType::IsScalarType () const
+{
+ if (!IsValid())
+ return false;
+
+ return m_type_system->IsScalarType(m_type);
+}
+
+bool
+CompilerType::IsTypedefType () const
+{
+ if (!IsValid())
+ return false;
+ return m_type_system->IsTypedefType(m_type);
+}
+
+bool
+CompilerType::IsVoidType () const
+{
+ if (!IsValid())
+ return false;
+ return m_type_system->IsVoidType(m_type);
+}
+
+bool
+CompilerType::IsPointerToScalarType () const
+{
+ if (!IsValid())
+ return false;
+
+ return IsPointerType() && GetPointeeType().IsScalarType();
+}
+
+bool
+CompilerType::IsArrayOfScalarType () const
+{
+ CompilerType element_type;
+ if (IsArrayType(&element_type, nullptr, nullptr))
+ return element_type.IsScalarType();
+ return false;
+}
+
+bool
+CompilerType::IsBeingDefined () const
+{
+ if (!IsValid())
+ return false;
+ return m_type_system->IsBeingDefined(m_type);
+}
+
+//----------------------------------------------------------------------
+// Type Completion
+//----------------------------------------------------------------------
+
+bool
+CompilerType::GetCompleteType () const
+{
+ if (!IsValid())
+ return false;
+ return m_type_system->GetCompleteType(m_type);
+}
+
+//----------------------------------------------------------------------
+// AST related queries
+//----------------------------------------------------------------------
+size_t
+CompilerType::GetPointerByteSize () const
+{
+ if (m_type_system)
+ return m_type_system->GetPointerByteSize();
+ return 0;
+}
+
+ConstString
+CompilerType::GetConstQualifiedTypeName () const
+{
+ return GetConstTypeName ();
+}
+
+ConstString
+CompilerType::GetConstTypeName () const
+{
+ if (IsValid())
+ {
+ ConstString type_name (GetTypeName());
+ if (type_name)
+ return type_name;
+ }
+ return ConstString("<invalid>");
+}
+
+ConstString
+CompilerType::GetTypeName () const
+{
+ if (IsValid())
+ {
+ return m_type_system->GetTypeName(m_type);
+ }
+ return ConstString("<invalid>");
+}
+
+ConstString
+CompilerType::GetDisplayTypeName () const
+{
+ return GetTypeName();
+}
+
+uint32_t
+CompilerType::GetTypeInfo (CompilerType *pointee_or_element_compiler_type) const
+{
+ if (!IsValid())
+ return 0;
+
+ return m_type_system->GetTypeInfo(m_type, pointee_or_element_compiler_type);
+}
+
+
+
+lldb::LanguageType
+CompilerType::GetMinimumLanguage ()
+{
+ if (!IsValid())
+ return lldb::eLanguageTypeC;
+
+ return m_type_system->GetMinimumLanguage(m_type);
+}
+
+lldb::TypeClass
+CompilerType::GetTypeClass () const
+{
+ if (!IsValid())
+ return lldb::eTypeClassInvalid;
+
+ return m_type_system->GetTypeClass(m_type);
+
+}
+
+void
+CompilerType::SetCompilerType (TypeSystem* type_system, lldb::opaque_compiler_type_t type)
+{
+ m_type_system = type_system;
+ m_type = type;
+}
+
+void
+CompilerType::SetCompilerType (clang::ASTContext *ast, clang::QualType qual_type)
+{
+ m_type_system = ClangASTContext::GetASTContext(ast);
+ m_type = qual_type.getAsOpaquePtr();
+}
+
+unsigned
+CompilerType::GetTypeQualifiers() const
+{
+ if (IsValid())
+ return m_type_system->GetTypeQualifiers(m_type);
+ return 0;
+}
+
+//----------------------------------------------------------------------
+// Creating related types
+//----------------------------------------------------------------------
+
+CompilerType
+CompilerType::GetArrayElementType (uint64_t *stride) const
+{
+ if (IsValid())
+ {
+ return m_type_system->GetArrayElementType(m_type, stride);
+
+ }
+ return CompilerType();
+}
+
+CompilerType
+CompilerType::GetCanonicalType () const
+{
+ if (IsValid())
+ return m_type_system->GetCanonicalType(m_type);
+ return CompilerType();
+}
+
+CompilerType
+CompilerType::GetFullyUnqualifiedType () const
+{
+ if (IsValid())
+ return m_type_system->GetFullyUnqualifiedType(m_type);
+ return CompilerType();
+}
+
+
+int
+CompilerType::GetFunctionArgumentCount () const
+{
+ if (IsValid())
+ {
+ return m_type_system->GetFunctionArgumentCount(m_type);
+ }
+ return -1;
+}
+
+CompilerType
+CompilerType::GetFunctionArgumentTypeAtIndex (size_t idx) const
+{
+ if (IsValid())
+ {
+ return m_type_system->GetFunctionArgumentTypeAtIndex(m_type, idx);
+ }
+ return CompilerType();
+}
+
+CompilerType
+CompilerType::GetFunctionReturnType () const
+{
+ if (IsValid())
+ {
+ return m_type_system->GetFunctionReturnType(m_type);
+ }
+ return CompilerType();
+}
+
+size_t
+CompilerType::GetNumMemberFunctions () const
+{
+ if (IsValid())
+ {
+ return m_type_system->GetNumMemberFunctions(m_type);
+ }
+ return 0;
+}
+
+TypeMemberFunctionImpl
+CompilerType::GetMemberFunctionAtIndex (size_t idx)
+{
+ if (IsValid())
+ {
+ return m_type_system->GetMemberFunctionAtIndex(m_type, idx);
+ }
+ return TypeMemberFunctionImpl();
+}
+
+CompilerType
+CompilerType::GetNonReferenceType () const
+{
+ if (IsValid())
+ return m_type_system->GetNonReferenceType(m_type);
+ return CompilerType();
+}
+
+CompilerType
+CompilerType::GetPointeeType () const
+{
+ if (IsValid())
+ {
+ return m_type_system->GetPointeeType(m_type);
+ }
+ return CompilerType();
+}
+
+CompilerType
+CompilerType::GetPointerType () const
+{
+ if (IsValid())
+ {
+ return m_type_system->GetPointerType(m_type);
+ }
+ return CompilerType();
+}
+
+CompilerType
+CompilerType::GetLValueReferenceType () const
+{
+ if (IsValid())
+ return m_type_system->GetLValueReferenceType(m_type);
+ else
+ return CompilerType();
+}
+
+CompilerType
+CompilerType::GetRValueReferenceType () const
+{
+ if (IsValid())
+ return m_type_system->GetRValueReferenceType(m_type);
+ else
+ return CompilerType();
+}
+
+CompilerType
+CompilerType::AddConstModifier () const
+{
+ if (IsValid())
+ return m_type_system->AddConstModifier(m_type);
+ else
+ return CompilerType();
+}
+
+CompilerType
+CompilerType::AddVolatileModifier () const
+{
+ if (IsValid())
+ return m_type_system->AddVolatileModifier(m_type);
+ else
+ return CompilerType();
+}
+
+CompilerType
+CompilerType::AddRestrictModifier () const
+{
+ if (IsValid())
+ return m_type_system->AddRestrictModifier(m_type);
+ else
+ return CompilerType();
+}
+
+CompilerType
+CompilerType::CreateTypedef (const char *name, const CompilerDeclContext &decl_ctx) const
+{
+ if (IsValid())
+ return m_type_system->CreateTypedef(m_type, name, decl_ctx);
+ else
+ return CompilerType();
+}
+
+CompilerType
+CompilerType::GetTypedefedType () const
+{
+ if (IsValid())
+ return m_type_system->GetTypedefedType(m_type);
+ else
+ return CompilerType();
+}
+
+//----------------------------------------------------------------------
+// Create related types using the current type's AST
+//----------------------------------------------------------------------
+
+CompilerType
+CompilerType::GetBasicTypeFromAST (lldb::BasicType basic_type) const
+{
+ if (IsValid())
+ return m_type_system->GetBasicTypeFromAST(basic_type);
+ return CompilerType();
+}
+//----------------------------------------------------------------------
+// Exploring the type
+//----------------------------------------------------------------------
+
+uint64_t
+CompilerType::GetBitSize (ExecutionContextScope *exe_scope) const
+{
+ if (IsValid())
+ {
+ return m_type_system->GetBitSize(m_type, exe_scope);
+ }
+ return 0;
+}
+
+uint64_t
+CompilerType::GetByteSize (ExecutionContextScope *exe_scope) const
+{
+ return (GetBitSize (exe_scope) + 7) / 8;
+}
+
+
+size_t
+CompilerType::GetTypeBitAlign () const
+{
+ if (IsValid())
+ return m_type_system->GetTypeBitAlign(m_type);
+ return 0;
+}
+
+
+lldb::Encoding
+CompilerType::GetEncoding (uint64_t &count) const
+{
+ if (!IsValid())
+ return lldb::eEncodingInvalid;
+
+ return m_type_system->GetEncoding(m_type, count);
+}
+
+lldb::Format
+CompilerType::GetFormat () const
+{
+ if (!IsValid())
+ return lldb::eFormatDefault;
+
+ return m_type_system->GetFormat(m_type);
+}
+
+uint32_t
+CompilerType::GetNumChildren (bool omit_empty_base_classes) const
+{
+ if (!IsValid())
+ return 0;
+ return m_type_system->GetNumChildren(m_type, omit_empty_base_classes);
+}
+
+lldb::BasicType
+CompilerType::GetBasicTypeEnumeration () const
+{
+ if (IsValid())
+ return m_type_system->GetBasicTypeEnumeration(m_type);
+ return eBasicTypeInvalid;
+}
+
+void
+CompilerType::ForEachEnumerator (std::function <bool (const CompilerType &integer_type, const ConstString &name, const llvm::APSInt &value)> const &callback) const
+{
+ if (IsValid())
+ return m_type_system->ForEachEnumerator (m_type, callback);
+}
+
+
+uint32_t
+CompilerType::GetNumFields () const
+{
+ if (!IsValid())
+ return 0;
+ return m_type_system->GetNumFields(m_type);
+}
+
+CompilerType
+CompilerType::GetFieldAtIndex (size_t idx,
+ std::string& name,
+ uint64_t *bit_offset_ptr,
+ uint32_t *bitfield_bit_size_ptr,
+ bool *is_bitfield_ptr) const
+{
+ if (!IsValid())
+ return CompilerType();
+ return m_type_system->GetFieldAtIndex(m_type, idx, name, bit_offset_ptr, bitfield_bit_size_ptr, is_bitfield_ptr);
+}
+
+uint32_t
+CompilerType::GetNumDirectBaseClasses () const
+{
+ if (IsValid())
+ return m_type_system->GetNumDirectBaseClasses (m_type);
+ return 0;
+}
+
+uint32_t
+CompilerType::GetNumVirtualBaseClasses () const
+{
+ if (IsValid())
+ return m_type_system->GetNumVirtualBaseClasses (m_type);
+ return 0;
+}
+
+CompilerType
+CompilerType::GetDirectBaseClassAtIndex (size_t idx, uint32_t *bit_offset_ptr) const
+{
+ if (IsValid())
+ return m_type_system->GetDirectBaseClassAtIndex (m_type, idx, bit_offset_ptr);
+ return CompilerType();
+}
+
+CompilerType
+CompilerType::GetVirtualBaseClassAtIndex (size_t idx, uint32_t *bit_offset_ptr) const
+{
+ if (IsValid())
+ return m_type_system->GetVirtualBaseClassAtIndex (m_type, idx, bit_offset_ptr);
+ return CompilerType();
+}
+
+uint32_t
+CompilerType::GetIndexOfFieldWithName (const char* name,
+ CompilerType* field_compiler_type_ptr,
+ uint64_t *bit_offset_ptr,
+ uint32_t *bitfield_bit_size_ptr,
+ bool *is_bitfield_ptr) const
+{
+ unsigned count = GetNumFields();
+ std::string field_name;
+ for (unsigned index = 0; index < count; index++)
+ {
+ CompilerType field_compiler_type (GetFieldAtIndex(index, field_name, bit_offset_ptr, bitfield_bit_size_ptr, is_bitfield_ptr));
+ if (strcmp(field_name.c_str(), name) == 0)
+ {
+ if (field_compiler_type_ptr)
+ *field_compiler_type_ptr = field_compiler_type;
+ return index;
+ }
+ }
+ return UINT32_MAX;
+}
+
+
+CompilerType
+CompilerType::GetChildCompilerTypeAtIndex (ExecutionContext *exe_ctx,
+ size_t idx,
+ bool transparent_pointers,
+ bool omit_empty_base_classes,
+ bool ignore_array_bounds,
+ std::string& child_name,
+ uint32_t &child_byte_size,
+ int32_t &child_byte_offset,
+ uint32_t &child_bitfield_bit_size,
+ uint32_t &child_bitfield_bit_offset,
+ bool &child_is_base_class,
+ bool &child_is_deref_of_parent,
+ ValueObject *valobj,
+ uint64_t &language_flags) const
+{
+ if (!IsValid())
+ return CompilerType();
+ return m_type_system->GetChildCompilerTypeAtIndex(m_type,
+ exe_ctx,
+ idx,
+ transparent_pointers,
+ omit_empty_base_classes,
+ ignore_array_bounds,
+ child_name,
+ child_byte_size,
+ child_byte_offset,
+ child_bitfield_bit_size,
+ child_bitfield_bit_offset,
+ child_is_base_class,
+ child_is_deref_of_parent,
+ valobj,
+ language_flags);
+}
+
+// Look for a child member (doesn't include base classes, but it does include
+// their members) in the type hierarchy. Returns an index path into "clang_type"
+// on how to reach the appropriate member.
+//
+// class A
+// {
+// public:
+// int m_a;
+// int m_b;
+// };
+//
+// class B
+// {
+// };
+//
+// class C :
+// public B,
+// public A
+// {
+// };
+//
+// If we have a clang type that describes "class C", and we wanted to looked
+// "m_b" in it:
+//
+// With omit_empty_base_classes == false we would get an integer array back with:
+// { 1, 1 }
+// The first index 1 is the child index for "class A" within class C
+// The second index 1 is the child index for "m_b" within class A
+//
+// With omit_empty_base_classes == true we would get an integer array back with:
+// { 0, 1 }
+// The first index 0 is the child index for "class A" within class C (since class B doesn't have any members it doesn't count)
+// The second index 1 is the child index for "m_b" within class A
+
+size_t
+CompilerType::GetIndexOfChildMemberWithName (const char *name,
+ bool omit_empty_base_classes,
+ std::vector<uint32_t>& child_indexes) const
+{
+ if (IsValid() && name && name[0])
+ {
+ return m_type_system->GetIndexOfChildMemberWithName(m_type, name, omit_empty_base_classes, child_indexes);
+ }
+ return 0;
+}
+
+size_t
+CompilerType::GetNumTemplateArguments () const
+{
+ if (IsValid())
+ {
+ return m_type_system->GetNumTemplateArguments(m_type);
+ }
+ return 0;
+}
+
+CompilerType
+CompilerType::GetTemplateArgument (size_t idx,
+ lldb::TemplateArgumentKind &kind) const
+{
+ if (IsValid())
+ {
+ return m_type_system->GetTemplateArgument(m_type, idx, kind);
+ }
+ return CompilerType();
+}
+
+CompilerType
+CompilerType::GetTypeForFormatters () const
+{
+ if (IsValid())
+ return m_type_system->GetTypeForFormatters(m_type);
+ return CompilerType();
+}
+
+LazyBool
+CompilerType::ShouldPrintAsOneLiner (ValueObject* valobj) const
+{
+ if (IsValid())
+ return m_type_system->ShouldPrintAsOneLiner(m_type, valobj);
+ return eLazyBoolCalculate;
+}
+
+bool
+CompilerType::IsMeaninglessWithoutDynamicResolution () const
+{
+ if (IsValid())
+ return m_type_system->IsMeaninglessWithoutDynamicResolution(m_type);
+ return false;
+}
+
+// Get the index of the child of "clang_type" whose name matches. This function
+// doesn't descend into the children, but only looks one level deep and name
+// matches can include base class names.
+
+uint32_t
+CompilerType::GetIndexOfChildWithName (const char *name, bool omit_empty_base_classes) const
+{
+ if (IsValid() && name && name[0])
+ {
+ return m_type_system->GetIndexOfChildWithName(m_type, name, omit_empty_base_classes);
+ }
+ return UINT32_MAX;
+}
+
+size_t
+CompilerType::ConvertStringToFloatValue (const char *s, uint8_t *dst, size_t dst_size) const
+{
+ if (IsValid())
+ return m_type_system->ConvertStringToFloatValue(m_type, s, dst, dst_size);
+ return 0;
+}
+
+
+
+//----------------------------------------------------------------------
+// Dumping types
+//----------------------------------------------------------------------
+#define DEPTH_INCREMENT 2
+
+void
+CompilerType::DumpValue (ExecutionContext *exe_ctx,
+ Stream *s,
+ lldb::Format format,
+ const lldb_private::DataExtractor &data,
+ lldb::offset_t data_byte_offset,
+ size_t data_byte_size,
+ uint32_t bitfield_bit_size,
+ uint32_t bitfield_bit_offset,
+ bool show_types,
+ bool show_summary,
+ bool verbose,
+ uint32_t depth)
+{
+ if (!IsValid())
+ return;
+ m_type_system->DumpValue(m_type, exe_ctx, s, format, data, data_byte_offset, data_byte_size, bitfield_bit_size, bitfield_bit_offset, show_types, show_summary, verbose, depth);
+}
+
+
+
+
+bool
+CompilerType::DumpTypeValue (Stream *s,
+ lldb::Format format,
+ const lldb_private::DataExtractor &data,
+ lldb::offset_t byte_offset,
+ size_t byte_size,
+ uint32_t bitfield_bit_size,
+ uint32_t bitfield_bit_offset,
+ ExecutionContextScope *exe_scope)
+{
+ if (!IsValid())
+ return false;
+ return m_type_system->DumpTypeValue(m_type, s, format, data, byte_offset, byte_size, bitfield_bit_size, bitfield_bit_offset, exe_scope);
+}
+
+
+
+void
+CompilerType::DumpSummary (ExecutionContext *exe_ctx,
+ Stream *s,
+ const lldb_private::DataExtractor &data,
+ lldb::offset_t data_byte_offset,
+ size_t data_byte_size)
+{
+ if (IsValid())
+ m_type_system->DumpSummary(m_type, exe_ctx, s, data, data_byte_offset, data_byte_size);
+}
+
+void
+CompilerType::DumpTypeDescription () const
+{
+ if (IsValid())
+ m_type_system->DumpTypeDescription(m_type);
+}
+
+void
+CompilerType::DumpTypeDescription (Stream *s) const
+{
+ if (IsValid())
+ {
+ m_type_system->DumpTypeDescription(m_type, s);
+ }
+}
+
+bool
+CompilerType::GetValueAsScalar (const lldb_private::DataExtractor &data,
+ lldb::offset_t data_byte_offset,
+ size_t data_byte_size,
+ Scalar &value) const
+{
+ if (!IsValid())
+ return false;
+
+ if (IsAggregateType ())
+ {
+ return false; // Aggregate types don't have scalar values
+ }
+ else
+ {
+ uint64_t count = 0;
+ lldb::Encoding encoding = GetEncoding (count);
+
+ if (encoding == lldb::eEncodingInvalid || count != 1)
+ return false;
+
+ const uint64_t byte_size = GetByteSize(nullptr);
+ lldb::offset_t offset = data_byte_offset;
+ switch (encoding)
+ {
+ case lldb::eEncodingInvalid:
+ break;
+ case lldb::eEncodingVector:
+ break;
+ case lldb::eEncodingUint:
+ if (byte_size <= sizeof(unsigned long long))
+ {
+ uint64_t uval64 = data.GetMaxU64 (&offset, byte_size);
+ if (byte_size <= sizeof(unsigned int))
+ {
+ value = (unsigned int)uval64;
+ return true;
+ }
+ else if (byte_size <= sizeof(unsigned long))
+ {
+ value = (unsigned long)uval64;
+ return true;
+ }
+ else if (byte_size <= sizeof(unsigned long long))
+ {
+ value = (unsigned long long )uval64;
+ return true;
+ }
+ else
+ value.Clear();
+ }
+ break;
+
+ case lldb::eEncodingSint:
+ if (byte_size <= sizeof(long long))
+ {
+ int64_t sval64 = data.GetMaxS64 (&offset, byte_size);
+ if (byte_size <= sizeof(int))
+ {
+ value = (int)sval64;
+ return true;
+ }
+ else if (byte_size <= sizeof(long))
+ {
+ value = (long)sval64;
+ return true;
+ }
+ else if (byte_size <= sizeof(long long))
+ {
+ value = (long long )sval64;
+ return true;
+ }
+ else
+ value.Clear();
+ }
+ break;
+
+ case lldb::eEncodingIEEE754:
+ if (byte_size <= sizeof(long double))
+ {
+ uint32_t u32;
+ uint64_t u64;
+ if (byte_size == sizeof(float))
+ {
+ if (sizeof(float) == sizeof(uint32_t))
+ {
+ u32 = data.GetU32(&offset);
+ value = *((float *)&u32);
+ return true;
+ }
+ else if (sizeof(float) == sizeof(uint64_t))
+ {
+ u64 = data.GetU64(&offset);
+ value = *((float *)&u64);
+ return true;
+ }
+ }
+ else
+ if (byte_size == sizeof(double))
+ {
+ if (sizeof(double) == sizeof(uint32_t))
+ {
+ u32 = data.GetU32(&offset);
+ value = *((double *)&u32);
+ return true;
+ }
+ else if (sizeof(double) == sizeof(uint64_t))
+ {
+ u64 = data.GetU64(&offset);
+ value = *((double *)&u64);
+ return true;
+ }
+ }
+ else
+ if (byte_size == sizeof(long double))
+ {
+ if (sizeof(long double) == sizeof(uint32_t))
+ {
+ u32 = data.GetU32(&offset);
+ value = *((long double *)&u32);
+ return true;
+ }
+ else if (sizeof(long double) == sizeof(uint64_t))
+ {
+ u64 = data.GetU64(&offset);
+ value = *((long double *)&u64);
+ return true;
+ }
+ }
+ }
+ break;
+ }
+ }
+ return false;
+}
+
+bool
+CompilerType::SetValueFromScalar (const Scalar &value, Stream &strm)
+{
+ if (!IsValid())
+ return false;
+
+ // Aggregate types don't have scalar values
+ if (!IsAggregateType ())
+ {
+ strm.GetFlags().Set(Stream::eBinary);
+ uint64_t count = 0;
+ lldb::Encoding encoding = GetEncoding (count);
+
+ if (encoding == lldb::eEncodingInvalid || count != 1)
+ return false;
+
+ const uint64_t bit_width = GetBitSize(nullptr);
+ // This function doesn't currently handle non-byte aligned assignments
+ if ((bit_width % 8) != 0)
+ return false;
+
+ const uint64_t byte_size = (bit_width + 7 ) / 8;
+ switch (encoding)
+ {
+ case lldb::eEncodingInvalid:
+ break;
+ case lldb::eEncodingVector:
+ break;
+ case lldb::eEncodingUint:
+ switch (byte_size)
+ {
+ case 1: strm.PutHex8(value.UInt()); return true;
+ case 2: strm.PutHex16(value.UInt()); return true;
+ case 4: strm.PutHex32(value.UInt()); return true;
+ case 8: strm.PutHex64(value.ULongLong()); return true;
+ default:
+ break;
+ }
+ break;
+
+ case lldb::eEncodingSint:
+ switch (byte_size)
+ {
+ case 1: strm.PutHex8(value.SInt()); return true;
+ case 2: strm.PutHex16(value.SInt()); return true;
+ case 4: strm.PutHex32(value.SInt()); return true;
+ case 8: strm.PutHex64(value.SLongLong()); return true;
+ default:
+ break;
+ }
+ break;
+
+ case lldb::eEncodingIEEE754:
+ if (byte_size <= sizeof(long double))
+ {
+ if (byte_size == sizeof(float))
+ {
+ strm.PutFloat(value.Float());
+ return true;
+ }
+ else
+ if (byte_size == sizeof(double))
+ {
+ strm.PutDouble(value.Double());
+ return true;
+ }
+ else
+ if (byte_size == sizeof(long double))
+ {
+ strm.PutDouble(value.LongDouble());
+ return true;
+ }
+ }
+ break;
+ }
+ }
+ return false;
+}
+
+bool
+CompilerType::ReadFromMemory (lldb_private::ExecutionContext *exe_ctx,
+ lldb::addr_t addr,
+ AddressType address_type,
+ lldb_private::DataExtractor &data)
+{
+ if (!IsValid())
+ return false;
+
+ // Can't convert a file address to anything valid without more
+ // context (which Module it came from)
+ if (address_type == eAddressTypeFile)
+ return false;
+
+ if (!GetCompleteType())
+ return false;
+
+ const uint64_t byte_size = GetByteSize(exe_ctx ? exe_ctx->GetBestExecutionContextScope() : NULL);
+ if (data.GetByteSize() < byte_size)
+ {
+ lldb::DataBufferSP data_sp(new DataBufferHeap (byte_size, '\0'));
+ data.SetData(data_sp);
+ }
+
+ uint8_t* dst = const_cast<uint8_t*>(data.PeekData(0, byte_size));
+ if (dst != nullptr)
+ {
+ if (address_type == eAddressTypeHost)
+ {
+ if (addr == 0)
+ return false;
+ // The address is an address in this process, so just copy it
+ memcpy (dst, (uint8_t*)nullptr + addr, byte_size);
+ return true;
+ }
+ else
+ {
+ Process *process = nullptr;
+ if (exe_ctx)
+ process = exe_ctx->GetProcessPtr();
+ if (process)
+ {
+ Error error;
+ return process->ReadMemory(addr, dst, byte_size, error) == byte_size;
+ }
+ }
+ }
+ return false;
+}
+
+bool
+CompilerType::WriteToMemory (lldb_private::ExecutionContext *exe_ctx,
+ lldb::addr_t addr,
+ AddressType address_type,
+ StreamString &new_value)
+{
+ if (!IsValid())
+ return false;
+
+ // Can't convert a file address to anything valid without more
+ // context (which Module it came from)
+ if (address_type == eAddressTypeFile)
+ return false;
+
+ if (!GetCompleteType())
+ return false;
+
+ const uint64_t byte_size = GetByteSize(exe_ctx ? exe_ctx->GetBestExecutionContextScope() : NULL);
+
+ if (byte_size > 0)
+ {
+ if (address_type == eAddressTypeHost)
+ {
+ // The address is an address in this process, so just copy it
+ memcpy ((void *)addr, new_value.GetData(), byte_size);
+ return true;
+ }
+ else
+ {
+ Process *process = nullptr;
+ if (exe_ctx)
+ process = exe_ctx->GetProcessPtr();
+ if (process)
+ {
+ Error error;
+ return process->WriteMemory(addr, new_value.GetData(), byte_size, error) == byte_size;
+ }
+ }
+ }
+ return false;
+}
+
+//clang::CXXRecordDecl *
+//CompilerType::GetAsCXXRecordDecl (lldb::opaque_compiler_type_t opaque_compiler_qual_type)
+//{
+// if (opaque_compiler_qual_type)
+// return clang::QualType::getFromOpaquePtr(opaque_compiler_qual_type)->getAsCXXRecordDecl();
+// return NULL;
+//}
+
+bool
+lldb_private::operator == (const lldb_private::CompilerType &lhs, const lldb_private::CompilerType &rhs)
+{
+ return lhs.GetTypeSystem() == rhs.GetTypeSystem() && lhs.GetOpaqueQualType() == rhs.GetOpaqueQualType();
+}
+
+
+bool
+lldb_private::operator != (const lldb_private::CompilerType &lhs, const lldb_private::CompilerType &rhs)
+{
+ return lhs.GetTypeSystem() != rhs.GetTypeSystem() || lhs.GetOpaqueQualType() != rhs.GetOpaqueQualType();
+}
+
+
+
diff --git a/source/Symbol/DWARFCallFrameInfo.cpp b/source/Symbol/DWARFCallFrameInfo.cpp
index a5f9017918ddc..c357a50016902 100644
--- a/source/Symbol/DWARFCallFrameInfo.cpp
+++ b/source/Symbol/DWARFCallFrameInfo.cpp
@@ -342,7 +342,7 @@ DWARFCallFrameInfo::GetFDEIndex ()
"error: Invalid fde/cie next entry offset of 0x%x found in cie/fde at 0x%x\n",
next_entry,
current_entry);
- // Don't trust anything in this eh_frame section if we find blatently
+ // Don't trust anything in this eh_frame section if we find blatantly
// invalid data.
m_fde_index.Clear();
m_fde_index_initialized = true;
@@ -354,7 +354,7 @@ DWARFCallFrameInfo::GetFDEIndex ()
"error: Invalid cie offset of 0x%x found in cie/fde at 0x%x\n",
cie_offset,
current_entry);
- // Don't trust anything in this eh_frame section if we find blatently
+ // Don't trust anything in this eh_frame section if we find blatantly
// invalid data.
m_fde_index.Clear();
m_fde_index_initialized = true;
@@ -535,7 +535,7 @@ DWARFCallFrameInfo::FDEToUnwindPlan (dw_offset_t dwarf_offset, Address startaddr
// We only keep enough register locations around to
// unwind what is in our thread, and these are organized
// by the register index in that state, so we need to convert our
- // GCC register number from the EH frame info, to a register index
+ // eh_frame register number from the EH frame info, to a register index
if (unwind_plan.IsValidRowIndex(0) && unwind_plan.GetRowAtIndex(0)->GetRegisterInfo(reg_num, reg_location))
row->SetRegisterInfo (reg_num, reg_location);
diff --git a/source/Symbol/DebugMacros.cpp b/source/Symbol/DebugMacros.cpp
new file mode 100644
index 0000000000000..88a28ba75e699
--- /dev/null
+++ b/source/Symbol/DebugMacros.cpp
@@ -0,0 +1,65 @@
+//===-- DebugMacros.cpp -----------------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "lldb/Symbol/DebugMacros.h"
+
+#include "lldb/Symbol/CompileUnit.h"
+
+using namespace lldb_private;
+
+DebugMacroEntry::DebugMacroEntry(EntryType type,
+ uint32_t line,
+ uint32_t debug_line_file_idx,
+ const char *str)
+ : m_type(type),
+ m_line(line),
+ m_debug_line_file_idx(debug_line_file_idx),
+ m_str(str)
+{ }
+
+DebugMacroEntry::DebugMacroEntry(EntryType type,
+ const DebugMacrosSP &debug_macros_sp)
+ : m_type(type), m_line(0), m_debug_line_file_idx(0), m_debug_macros_sp(debug_macros_sp)
+{ }
+
+const FileSpec&
+DebugMacroEntry::GetFileSpec(CompileUnit *comp_unit) const
+{
+ return comp_unit->GetSupportFiles().GetFileSpecAtIndex(m_debug_line_file_idx);
+}
+
+DebugMacroEntry
+DebugMacroEntry::CreateDefineEntry(uint32_t line, const char *str)
+{
+ return DebugMacroEntry(DebugMacroEntry::DEFINE, line, 0, str);
+}
+
+DebugMacroEntry
+DebugMacroEntry::CreateUndefEntry(uint32_t line, const char *str)
+{
+ return DebugMacroEntry(DebugMacroEntry::UNDEF, line, 0, str);
+}
+
+DebugMacroEntry
+DebugMacroEntry::CreateStartFileEntry(uint32_t line, uint32_t debug_line_file_idx)
+{
+ return DebugMacroEntry(DebugMacroEntry::START_FILE, line, debug_line_file_idx, nullptr);
+}
+
+DebugMacroEntry
+DebugMacroEntry::CreateEndFileEntry()
+{
+ return DebugMacroEntry(DebugMacroEntry::END_FILE, 0, 0, nullptr);
+}
+
+DebugMacroEntry
+DebugMacroEntry::CreateIndirectEntry(const DebugMacrosSP &debug_macros_sp)
+{
+ return DebugMacroEntry(DebugMacroEntry::INDIRECT, debug_macros_sp);
+}
diff --git a/source/Symbol/FuncUnwinders.cpp b/source/Symbol/FuncUnwinders.cpp
index 000df722bb9e1..4c96b1a2bb1b4 100644
--- a/source/Symbol/FuncUnwinders.cpp
+++ b/source/Symbol/FuncUnwinders.cpp
@@ -10,6 +10,7 @@
#include "lldb/Core/AddressRange.h"
#include "lldb/Core/Address.h"
#include "lldb/Symbol/FuncUnwinders.h"
+#include "lldb/Symbol/ArmUnwindInfo.h"
#include "lldb/Symbol/DWARFCallFrameInfo.h"
#include "lldb/Symbol/CompactUnwindInfo.h"
#include "lldb/Symbol/ObjectFile.h"
@@ -37,6 +38,7 @@ FuncUnwinders::FuncUnwinders (UnwindTable& unwind_table, AddressRange range) :
m_unwind_plan_eh_frame_sp (),
m_unwind_plan_eh_frame_augmented_sp (),
m_unwind_plan_compact_unwind (),
+ m_unwind_plan_arm_unwind_sp (),
m_unwind_plan_fast_sp (),
m_unwind_plan_arch_default_sp (),
m_unwind_plan_arch_default_at_func_entry_sp (),
@@ -44,6 +46,7 @@ FuncUnwinders::FuncUnwinders (UnwindTable& unwind_table, AddressRange range) :
m_tried_unwind_plan_eh_frame (false),
m_tried_unwind_plan_eh_frame_augmented (false),
m_tried_unwind_plan_compact_unwind (false),
+ m_tried_unwind_plan_arm_unwind (false),
m_tried_unwind_fast (false),
m_tried_unwind_arch_default (false),
m_tried_unwind_arch_default_at_func_entry (false),
@@ -65,12 +68,18 @@ FuncUnwinders::GetUnwindPlanAtCallSite (Target &target, int current_offset)
Mutex::Locker locker (m_mutex);
UnwindPlanSP unwind_plan_sp = GetEHFrameUnwindPlan (target, current_offset);
- if (unwind_plan_sp.get() == nullptr)
- {
- unwind_plan_sp = GetCompactUnwindUnwindPlan (target, current_offset);
- }
+ if (unwind_plan_sp)
+ return unwind_plan_sp;
+
+ unwind_plan_sp = GetCompactUnwindUnwindPlan (target, current_offset);
+ if (unwind_plan_sp)
+ return unwind_plan_sp;
+
+ unwind_plan_sp = GetArmUnwindUnwindPlan (target, current_offset);
+ if (unwind_plan_sp)
+ return unwind_plan_sp;
- return unwind_plan_sp;
+ return nullptr;
}
UnwindPlanSP
@@ -127,6 +136,30 @@ FuncUnwinders::GetEHFrameUnwindPlan (Target &target, int current_offset)
}
UnwindPlanSP
+FuncUnwinders::GetArmUnwindUnwindPlan (Target &target, int current_offset)
+{
+ if (m_unwind_plan_arm_unwind_sp.get() || m_tried_unwind_plan_arm_unwind)
+ return m_unwind_plan_arm_unwind_sp;
+
+ Mutex::Locker lock (m_mutex);
+ m_tried_unwind_plan_arm_unwind = true;
+ if (m_range.GetBaseAddress().IsValid())
+ {
+ Address current_pc (m_range.GetBaseAddress ());
+ if (current_offset != -1)
+ current_pc.SetOffset (current_pc.GetOffset() + current_offset);
+ ArmUnwindInfo *arm_unwind_info = m_unwind_table.GetArmUnwindInfo();
+ if (arm_unwind_info)
+ {
+ m_unwind_plan_arm_unwind_sp.reset (new UnwindPlan (lldb::eRegisterKindGeneric));
+ if (!arm_unwind_info->GetUnwindPlan (target, current_pc, *m_unwind_plan_arm_unwind_sp))
+ m_unwind_plan_arm_unwind_sp.reset();
+ }
+ }
+ return m_unwind_plan_arm_unwind_sp;
+}
+
+UnwindPlanSP
FuncUnwinders::GetEHFrameAugmentedUnwindPlan (Target &target, Thread &thread, int current_offset)
{
if (m_unwind_plan_eh_frame_augmented_sp.get() || m_tried_unwind_plan_eh_frame_augmented)
diff --git a/source/Symbol/Function.cpp b/source/Symbol/Function.cpp
index 77448d4f2a220..33cc0c4e264c2 100644
--- a/source/Symbol/Function.cpp
+++ b/source/Symbol/Function.cpp
@@ -12,11 +12,12 @@
#include "lldb/Core/Module.h"
#include "lldb/Core/Section.h"
#include "lldb/Host/Host.h"
-#include "lldb/Symbol/ClangASTType.h"
+#include "lldb/Symbol/CompilerType.h"
#include "lldb/Symbol/CompileUnit.h"
#include "lldb/Symbol/LineTable.h"
#include "lldb/Symbol/SymbolFile.h"
#include "lldb/Symbol/SymbolVendor.h"
+#include "lldb/Target/Language.h"
#include "llvm/Support/Casting.h"
using namespace lldb;
@@ -217,7 +218,7 @@ Function::Function
m_mangled (mangled),
m_block (func_uid),
m_range (range),
- m_frame_base (),
+ m_frame_base (nullptr),
m_flags (),
m_prologue_byte_size (0)
{
@@ -241,7 +242,7 @@ Function::Function
m_mangled (ConstString(mangled), true),
m_block (func_uid),
m_range (range),
- m_frame_base (),
+ m_frame_base (nullptr),
m_flags (),
m_prologue_byte_size (0)
{
@@ -466,6 +467,32 @@ Function::MemorySize () const
return mem_size;
}
+bool
+Function::GetIsOptimized ()
+{
+ bool result = false;
+
+ // Currently optimization is only indicted by the
+ // vendor extension DW_AT_APPLE_optimized which
+ // is set on a compile unit level.
+ if (m_comp_unit)
+ {
+ result = m_comp_unit->GetIsOptimized();
+ }
+ return result;
+}
+
+bool
+Function::IsTopLevelFunction ()
+{
+ bool result = false;
+
+ if (Language* language = Language::FindPlugin(GetLanguage()))
+ result = language->IsTopLevelFunction(*this);
+
+ return result;
+}
+
ConstString
Function::GetDisplayName () const
{
@@ -474,27 +501,24 @@ Function::GetDisplayName () const
return m_mangled.GetDisplayDemangledName(GetLanguage());
}
-clang::DeclContext *
-Function::GetClangDeclContext()
+CompilerDeclContext
+Function::GetDeclContext()
{
- SymbolContext sc;
-
- CalculateSymbolContext (&sc);
-
- if (!sc.module_sp)
- return nullptr;
-
- SymbolVendor *sym_vendor = sc.module_sp->GetSymbolVendor();
-
- if (!sym_vendor)
- return nullptr;
-
- SymbolFile *sym_file = sym_vendor->GetSymbolFile();
-
- if (!sym_file)
- return nullptr;
-
- return sym_file->GetClangDeclContextForTypeUID (sc, m_uid);
+ ModuleSP module_sp = CalculateSymbolContextModule ();
+
+ if (module_sp)
+ {
+ SymbolVendor *sym_vendor = module_sp->GetSymbolVendor();
+
+ if (sym_vendor)
+ {
+ SymbolFile *sym_file = sym_vendor->GetSymbolFile();
+
+ if (sym_file)
+ return sym_file->GetDeclContextForUID (GetID());
+ }
+ }
+ return CompilerDeclContext();
}
Type*
@@ -530,13 +554,13 @@ Function::GetType() const
return m_type;
}
-ClangASTType
-Function::GetClangType()
+CompilerType
+Function::GetCompilerType()
{
Type *function_type = GetType();
if (function_type)
- return function_type->GetClangFullType();
- return ClangASTType();
+ return function_type->GetFullCompilerType ();
+ return CompilerType();
}
uint32_t
diff --git a/source/Symbol/GoASTContext.cpp b/source/Symbol/GoASTContext.cpp
new file mode 100644
index 0000000000000..4ba51f7580d7a
--- /dev/null
+++ b/source/Symbol/GoASTContext.cpp
@@ -0,0 +1,1519 @@
+//===-- GoASTContext.cpp ----------------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include <mutex>
+#include <utility>
+#include <vector>
+
+#include "lldb/Core/Module.h"
+#include "lldb/Core/PluginManager.h"
+#include "lldb/Core/UniqueCStringMap.h"
+#include "lldb/Core/ValueObject.h"
+#include "lldb/DataFormatters/StringPrinter.h"
+#include "lldb/Symbol/CompilerType.h"
+#include "lldb/Symbol/ObjectFile.h"
+#include "lldb/Symbol/SymbolFile.h"
+#include "lldb/Symbol/GoASTContext.h"
+#include "lldb/Symbol/Type.h"
+#include "lldb/Target/ExecutionContext.h"
+#include "lldb/Target/Target.h"
+
+#include "Plugins/ExpressionParser/Go/GoUserExpression.h"
+#include "Plugins/SymbolFile/DWARF/DWARFASTParserGo.h"
+
+using namespace lldb;
+
+namespace lldb_private
+{
+class GoArray;
+class GoFunction;
+class GoStruct;
+
+class GoType
+{
+ public:
+ enum
+ {
+ KIND_BOOL = 1,
+ KIND_INT = 2,
+ KIND_INT8 = 3,
+ KIND_INT16 = 4,
+ KIND_INT32 = 5,
+ KIND_INT64 = 6,
+ KIND_UINT = 7,
+ KIND_UINT8 = 8,
+ KIND_UINT16 = 9,
+ KIND_UINT32 = 10,
+ KIND_UINT64 = 11,
+ KIND_UINTPTR = 12,
+ KIND_FLOAT32 = 13,
+ KIND_FLOAT64 = 14,
+ KIND_COMPLEX64 = 15,
+ KIND_COMPLEX128 = 16,
+ KIND_ARRAY = 17,
+ KIND_CHAN = 18,
+ KIND_FUNC = 19,
+ KIND_INTERFACE = 20,
+ KIND_MAP = 21,
+ KIND_PTR = 22,
+ KIND_SLICE = 23,
+ KIND_STRING = 24,
+ KIND_STRUCT = 25,
+ KIND_UNSAFEPOINTER = 26,
+ KIND_LLDB_VOID, // Extension for LLDB, not used by go runtime.
+ KIND_MASK = (1 << 5) - 1,
+ KIND_DIRECT_IFACE = 1 << 5
+ };
+ GoType(int kind, const ConstString &name)
+ : m_kind(kind & KIND_MASK)
+ , m_name(name)
+ {
+ if (m_kind == KIND_FUNC)
+ m_kind = KIND_FUNC;
+ }
+ virtual ~GoType() {}
+
+ int
+ GetGoKind() const
+ {
+ return m_kind;
+ }
+ const ConstString &
+ GetName() const
+ {
+ return m_name;
+ }
+ virtual CompilerType
+ GetElementType() const
+ {
+ return CompilerType();
+ }
+
+ bool
+ IsTypedef() const
+ {
+ switch (m_kind)
+ {
+ case KIND_CHAN:
+ case KIND_MAP:
+ case KIND_INTERFACE:
+ return true;
+ default:
+ return false;
+ }
+ }
+
+ GoArray *GetArray();
+ GoFunction *GetFunction();
+ GoStruct *GetStruct();
+
+ private:
+ int m_kind;
+ ConstString m_name;
+ GoType(const GoType &) = delete;
+ const GoType &operator=(const GoType &) = delete;
+};
+
+class GoElem : public GoType
+{
+ public:
+ GoElem(int kind, const ConstString &name, const CompilerType &elem)
+ : GoType(kind, name)
+ , m_elem(elem)
+ {
+ }
+ virtual CompilerType
+ GetElementType() const
+ {
+ return m_elem;
+ }
+
+ private:
+ // TODO: should we store this differently?
+ CompilerType m_elem;
+
+ GoElem(const GoElem &) = delete;
+ const GoElem &operator=(const GoElem &) = delete;
+};
+
+class GoArray : public GoElem
+{
+ public:
+ GoArray(const ConstString &name, uint64_t length, const CompilerType &elem)
+ : GoElem(KIND_ARRAY, name, elem)
+ , m_length(length)
+ {
+ }
+
+ uint64_t
+ GetLength() const
+ {
+ return m_length;
+ }
+
+ private:
+ uint64_t m_length;
+ GoArray(const GoArray &) = delete;
+ const GoArray &operator=(const GoArray &) = delete;
+};
+
+class GoFunction : public GoType
+{
+ public:
+ GoFunction(const ConstString &name, bool is_variadic)
+ : GoType(KIND_FUNC, name)
+ , m_is_variadic(is_variadic)
+ {
+ }
+
+ bool
+ IsVariadic() const
+ {
+ return m_is_variadic;
+ }
+
+ private:
+ bool m_is_variadic;
+ GoFunction(const GoFunction &) = delete;
+ const GoFunction &operator=(const GoFunction &) = delete;
+};
+
+class GoStruct : public GoType
+{
+ public:
+ struct Field
+ {
+ Field(const ConstString &name, const CompilerType &type, uint64_t offset)
+ : m_name(name)
+ , m_type(type)
+ , m_byte_offset(offset)
+ {
+ }
+ ConstString m_name;
+ CompilerType m_type;
+ uint64_t m_byte_offset;
+ };
+
+ GoStruct(int kind, const ConstString &name, int64_t byte_size)
+ : GoType(kind == 0 ? KIND_STRUCT : kind, name), m_is_complete(false), m_byte_size(byte_size)
+ {
+ }
+
+ uint32_t
+ GetNumFields() const
+ {
+ return m_fields.size();
+ }
+
+ const Field *
+ GetField(uint32_t i) const
+ {
+ if (i < m_fields.size())
+ return &m_fields[i];
+ return nullptr;
+ }
+
+ void
+ AddField(const ConstString &name, const CompilerType &type, uint64_t offset)
+ {
+ m_fields.push_back(Field(name, type, offset));
+ }
+
+ bool
+ IsComplete() const
+ {
+ return m_is_complete;
+ }
+
+ void
+ SetComplete()
+ {
+ m_is_complete = true;
+ }
+
+ int64_t
+ GetByteSize() const
+ {
+ return m_byte_size;
+ }
+
+ private:
+ bool m_is_complete;
+ int64_t m_byte_size;
+ std::vector<Field> m_fields;
+
+ GoStruct(const GoStruct &) = delete;
+ const GoStruct &operator=(const GoStruct &) = delete;
+};
+
+GoArray *
+GoType::GetArray()
+{
+ if (m_kind == KIND_ARRAY)
+ {
+ return static_cast<GoArray *>(this);
+ }
+ return nullptr;
+}
+
+GoFunction *
+GoType::GetFunction()
+{
+ if (m_kind == KIND_FUNC)
+ {
+ return static_cast<GoFunction *>(this);
+ }
+ return nullptr;
+}
+
+GoStruct *
+GoType::GetStruct()
+{
+ switch (m_kind)
+ {
+ case KIND_STRING:
+ case KIND_STRUCT:
+ case KIND_SLICE:
+ return static_cast<GoStruct *>(this);
+ }
+ return nullptr;
+}
+} // namespace lldb_private
+using namespace lldb_private;
+
+GoASTContext::GoASTContext()
+ : TypeSystem(eKindGo)
+ , m_pointer_byte_size(0)
+ , m_int_byte_size(0)
+ , m_types(new TypeMap)
+{
+}
+GoASTContext::~GoASTContext()
+{
+}
+
+//------------------------------------------------------------------
+// PluginInterface functions
+//------------------------------------------------------------------
+
+ConstString
+GoASTContext::GetPluginNameStatic()
+{
+ return ConstString("go");
+}
+
+ConstString
+GoASTContext::GetPluginName()
+{
+ return GoASTContext::GetPluginNameStatic();
+}
+
+uint32_t
+GoASTContext::GetPluginVersion()
+{
+ return 1;
+}
+
+lldb::TypeSystemSP
+GoASTContext::CreateInstance (lldb::LanguageType language, Module *module, Target *target)
+{
+ if (language == eLanguageTypeGo)
+ {
+ ArchSpec arch;
+ std::shared_ptr<GoASTContext> go_ast_sp;
+ if (module)
+ {
+ arch = module->GetArchitecture();
+ go_ast_sp = std::shared_ptr<GoASTContext>(new GoASTContext);
+ }
+ else if (target)
+ {
+ arch = target->GetArchitecture();
+ go_ast_sp = std::shared_ptr<GoASTContextForExpr>(new GoASTContextForExpr(target->shared_from_this()));
+ }
+
+ if (arch.IsValid())
+ {
+ go_ast_sp->SetAddressByteSize(arch.GetAddressByteSize());
+ return go_ast_sp;
+ }
+ }
+ return lldb::TypeSystemSP();
+}
+
+void
+GoASTContext::EnumerateSupportedLanguages(std::set<lldb::LanguageType> &languages_for_types, std::set<lldb::LanguageType> &languages_for_expressions)
+{
+ static std::vector<lldb::LanguageType> s_supported_languages_for_types({
+ lldb::eLanguageTypeGo});
+
+ static std::vector<lldb::LanguageType> s_supported_languages_for_expressions({});
+
+ languages_for_types.insert(s_supported_languages_for_types.begin(), s_supported_languages_for_types.end());
+ languages_for_expressions.insert(s_supported_languages_for_expressions.begin(), s_supported_languages_for_expressions.end());
+}
+
+
+void
+GoASTContext::Initialize()
+{
+ PluginManager::RegisterPlugin (GetPluginNameStatic(),
+ "AST context plug-in",
+ CreateInstance,
+ EnumerateSupportedLanguages);
+}
+
+void
+GoASTContext::Terminate()
+{
+ PluginManager::UnregisterPlugin (CreateInstance);
+}
+
+
+//----------------------------------------------------------------------
+// Tests
+//----------------------------------------------------------------------
+
+bool
+GoASTContext::IsArrayType(lldb::opaque_compiler_type_t type, CompilerType *element_type, uint64_t *size, bool *is_incomplete)
+{
+ if (element_type)
+ element_type->Clear();
+ if (size)
+ *size = 0;
+ if (is_incomplete)
+ *is_incomplete = false;
+ GoArray *array = static_cast<GoType *>(type)->GetArray();
+ if (array)
+ {
+ if (size)
+ *size = array->GetLength();
+ if (element_type)
+ *element_type = array->GetElementType();
+ return true;
+ }
+ return false;
+}
+
+bool
+GoASTContext::IsVectorType(lldb::opaque_compiler_type_t type, CompilerType *element_type, uint64_t *size)
+{
+ if (element_type)
+ element_type->Clear();
+ if (size)
+ *size = 0;
+ return false;
+}
+
+bool
+GoASTContext::IsAggregateType(lldb::opaque_compiler_type_t type)
+{
+ int kind = static_cast<GoType *>(type)->GetGoKind();
+ if (kind < GoType::KIND_ARRAY)
+ return false;
+ if (kind == GoType::KIND_PTR)
+ return false;
+ if (kind == GoType::KIND_CHAN)
+ return false;
+ if (kind == GoType::KIND_MAP)
+ return false;
+ if (kind == GoType::KIND_STRING)
+ return false;
+ if (kind == GoType::KIND_UNSAFEPOINTER)
+ return false;
+ return true;
+}
+
+bool
+GoASTContext::IsBeingDefined(lldb::opaque_compiler_type_t type)
+{
+ return false;
+}
+
+bool
+GoASTContext::IsCharType(lldb::opaque_compiler_type_t type)
+{
+ // Go's DWARF doesn't distinguish between rune and int32.
+ return false;
+}
+
+bool
+GoASTContext::IsCompleteType(lldb::opaque_compiler_type_t type)
+{
+ if (!type)
+ return false;
+ GoType *t = static_cast<GoType *>(type);
+ if (GoStruct *s = t->GetStruct())
+ return s->IsComplete();
+ if (t->IsTypedef() || t->GetGoKind() == GoType::KIND_PTR)
+ return t->GetElementType().IsCompleteType();
+ return true;
+}
+
+bool
+GoASTContext::IsConst(lldb::opaque_compiler_type_t type)
+{
+ return false;
+}
+
+bool
+GoASTContext::IsCStringType(lldb::opaque_compiler_type_t type, uint32_t &length)
+{
+ return false;
+}
+
+bool
+GoASTContext::IsDefined(lldb::opaque_compiler_type_t type)
+{
+ return type != nullptr;
+}
+
+bool
+GoASTContext::IsFloatingPointType(lldb::opaque_compiler_type_t type, uint32_t &count, bool &is_complex)
+{
+ int kind = static_cast<GoType *>(type)->GetGoKind();
+ if (kind >= GoType::KIND_FLOAT32 && kind <= GoType::KIND_COMPLEX128)
+ {
+ if (kind >= GoType::KIND_COMPLEX64)
+ {
+ is_complex = true;
+ count = 2;
+ }
+ else
+ {
+ is_complex = false;
+ count = 1;
+ }
+ return true;
+ }
+ count = 0;
+ is_complex = false;
+ return false;
+}
+
+bool
+GoASTContext::IsFunctionType(lldb::opaque_compiler_type_t type, bool *is_variadic_ptr)
+{
+ GoFunction *func = static_cast<GoType *>(type)->GetFunction();
+ if (func)
+ {
+ if (is_variadic_ptr)
+ *is_variadic_ptr = func->IsVariadic();
+ return true;
+ }
+ if (is_variadic_ptr)
+ *is_variadic_ptr = false;
+ return false;
+}
+
+uint32_t
+GoASTContext::IsHomogeneousAggregate(lldb::opaque_compiler_type_t type, CompilerType *base_type_ptr)
+{
+ return false;
+}
+
+size_t
+GoASTContext::GetNumberOfFunctionArguments(lldb::opaque_compiler_type_t type)
+{
+ return 0;
+}
+
+CompilerType
+GoASTContext::GetFunctionArgumentAtIndex(lldb::opaque_compiler_type_t type, const size_t index)
+{
+ return CompilerType();
+}
+
+bool
+GoASTContext::IsFunctionPointerType(lldb::opaque_compiler_type_t type)
+{
+ return IsFunctionType(type);
+}
+
+bool
+GoASTContext::IsIntegerType(lldb::opaque_compiler_type_t type, bool &is_signed)
+{
+ is_signed = false;
+ // TODO: Is bool an integer?
+ if (type)
+ {
+ int kind = static_cast<GoType *>(type)->GetGoKind();
+ if (kind <= GoType::KIND_UINTPTR)
+ {
+ is_signed = (kind != GoType::KIND_BOOL) & (kind <= GoType::KIND_INT64);
+ return true;
+ }
+ }
+ return false;
+}
+
+bool
+GoASTContext::IsPolymorphicClass(lldb::opaque_compiler_type_t type)
+{
+ return false;
+}
+
+bool
+GoASTContext::IsPossibleDynamicType(lldb::opaque_compiler_type_t type,
+ CompilerType *target_type, // Can pass NULL
+ bool check_cplusplus, bool check_objc)
+{
+ if (target_type)
+ target_type->Clear();
+ if (type)
+ return static_cast<GoType *>(type)->GetGoKind() == GoType::KIND_INTERFACE;
+ return false;
+}
+
+bool
+GoASTContext::IsRuntimeGeneratedType(lldb::opaque_compiler_type_t type)
+{
+ return false;
+}
+
+bool
+GoASTContext::IsPointerType(lldb::opaque_compiler_type_t type, CompilerType *pointee_type)
+{
+ if (!type)
+ return false;
+ GoType *t = static_cast<GoType *>(type);
+ if (pointee_type)
+ {
+ *pointee_type = t->GetElementType();
+ }
+ switch (t->GetGoKind())
+ {
+ case GoType::KIND_PTR:
+ case GoType::KIND_UNSAFEPOINTER:
+ case GoType::KIND_CHAN:
+ case GoType::KIND_MAP:
+ // TODO: is function a pointer?
+ return true;
+ default:
+ return false;
+ }
+}
+
+bool
+GoASTContext::IsPointerOrReferenceType(lldb::opaque_compiler_type_t type, CompilerType *pointee_type)
+{
+ return IsPointerType(type, pointee_type);
+}
+
+bool
+GoASTContext::IsReferenceType(lldb::opaque_compiler_type_t type, CompilerType *pointee_type, bool *is_rvalue)
+{
+ return false;
+}
+
+bool
+GoASTContext::IsScalarType(lldb::opaque_compiler_type_t type)
+{
+ return !IsAggregateType(type);
+}
+
+bool
+GoASTContext::IsTypedefType(lldb::opaque_compiler_type_t type)
+{
+ if (type)
+ return static_cast<GoType *>(type)->IsTypedef();
+ return false;
+}
+
+bool
+GoASTContext::IsVoidType(lldb::opaque_compiler_type_t type)
+{
+ if (!type)
+ return false;
+ return static_cast<GoType *>(type)->GetGoKind() == GoType::KIND_LLDB_VOID;
+}
+
+bool
+GoASTContext::SupportsLanguage (lldb::LanguageType language)
+{
+ return language == eLanguageTypeGo;
+}
+
+//----------------------------------------------------------------------
+// Type Completion
+//----------------------------------------------------------------------
+
+bool
+GoASTContext::GetCompleteType(lldb::opaque_compiler_type_t type)
+{
+ if (!type)
+ return false;
+ GoType *t = static_cast<GoType *>(type);
+ if (t->IsTypedef() || t->GetGoKind() == GoType::KIND_PTR || t->GetArray())
+ return t->GetElementType().GetCompleteType();
+ if (GoStruct *s = t->GetStruct())
+ {
+ if (s->IsComplete())
+ return true;
+ CompilerType compiler_type(this, s);
+ SymbolFile *symbols = GetSymbolFile();
+ return symbols && symbols->CompleteType(compiler_type);
+ }
+ return true;
+}
+
+//----------------------------------------------------------------------
+// AST related queries
+//----------------------------------------------------------------------
+
+uint32_t
+GoASTContext::GetPointerByteSize()
+{
+ return m_pointer_byte_size;
+}
+
+//----------------------------------------------------------------------
+// Accessors
+//----------------------------------------------------------------------
+
+ConstString
+GoASTContext::GetTypeName(lldb::opaque_compiler_type_t type)
+{
+ if (type)
+ return static_cast<GoType *>(type)->GetName();
+ return ConstString();
+}
+
+uint32_t
+GoASTContext::GetTypeInfo(lldb::opaque_compiler_type_t type, CompilerType *pointee_or_element_compiler_type)
+{
+ if (pointee_or_element_compiler_type)
+ pointee_or_element_compiler_type->Clear();
+ if (!type)
+ return 0;
+ GoType *t = static_cast<GoType *>(type);
+ if (pointee_or_element_compiler_type)
+ *pointee_or_element_compiler_type = t->GetElementType();
+ int kind = t->GetGoKind();
+ if (kind == GoType::KIND_ARRAY)
+ return eTypeHasChildren | eTypeIsArray;
+ if (kind < GoType::KIND_ARRAY)
+ {
+ uint32_t builtin_type_flags = eTypeIsBuiltIn | eTypeHasValue;
+ if (kind < GoType::KIND_FLOAT32)
+ {
+ builtin_type_flags |= eTypeIsInteger | eTypeIsScalar;
+ if (kind >= GoType::KIND_INT && kind <= GoType::KIND_INT64)
+ builtin_type_flags |= eTypeIsSigned;
+ }
+ else
+ {
+ builtin_type_flags |= eTypeIsFloat;
+ if (kind < GoType::KIND_COMPLEX64)
+ builtin_type_flags |= eTypeIsComplex;
+ else
+ builtin_type_flags |= eTypeIsScalar;
+ }
+ return builtin_type_flags;
+ }
+ if (kind == GoType::KIND_STRING)
+ return eTypeHasValue | eTypeIsBuiltIn;
+ if (kind == GoType::KIND_FUNC)
+ return eTypeIsFuncPrototype | eTypeHasValue;
+ if (IsPointerType(type))
+ return eTypeIsPointer | eTypeHasValue | eTypeHasChildren;
+ if (kind == GoType::KIND_LLDB_VOID)
+ return 0;
+ return eTypeHasChildren | eTypeIsStructUnion;
+}
+
+lldb::TypeClass
+GoASTContext::GetTypeClass(lldb::opaque_compiler_type_t type)
+{
+ if (!type)
+ return eTypeClassInvalid;
+ int kind = static_cast<GoType *>(type)->GetGoKind();
+ if (kind == GoType::KIND_FUNC)
+ return eTypeClassFunction;
+ if (IsPointerType(type))
+ return eTypeClassPointer;
+ if (kind < GoType::KIND_COMPLEX64)
+ return eTypeClassBuiltin;
+ if (kind <= GoType::KIND_COMPLEX128)
+ return eTypeClassComplexFloat;
+ if (kind == GoType::KIND_LLDB_VOID)
+ return eTypeClassInvalid;
+ return eTypeClassStruct;
+}
+
+lldb::BasicType
+GoASTContext::GetBasicTypeEnumeration(lldb::opaque_compiler_type_t type)
+{
+ ConstString name = GetTypeName(type);
+ if (name)
+ {
+ typedef UniqueCStringMap<lldb::BasicType> TypeNameToBasicTypeMap;
+ static TypeNameToBasicTypeMap g_type_map;
+ static std::once_flag g_once_flag;
+ std::call_once(g_once_flag, [](){
+ // "void"
+ g_type_map.Append(ConstString("void").GetCString(), eBasicTypeVoid);
+ // "int"
+ g_type_map.Append(ConstString("int").GetCString(), eBasicTypeInt);
+ g_type_map.Append(ConstString("uint").GetCString(), eBasicTypeUnsignedInt);
+
+ // Miscellaneous
+ g_type_map.Append(ConstString("bool").GetCString(), eBasicTypeBool);
+
+ // Others. Should these map to C types?
+ g_type_map.Append(ConstString("byte").GetCString(), eBasicTypeOther);
+ g_type_map.Append(ConstString("uint8").GetCString(), eBasicTypeOther);
+ g_type_map.Append(ConstString("uint16").GetCString(), eBasicTypeOther);
+ g_type_map.Append(ConstString("uint32").GetCString(), eBasicTypeOther);
+ g_type_map.Append(ConstString("uint64").GetCString(), eBasicTypeOther);
+ g_type_map.Append(ConstString("int8").GetCString(), eBasicTypeOther);
+ g_type_map.Append(ConstString("int16").GetCString(), eBasicTypeOther);
+ g_type_map.Append(ConstString("int32").GetCString(), eBasicTypeOther);
+ g_type_map.Append(ConstString("int64").GetCString(), eBasicTypeOther);
+ g_type_map.Append(ConstString("float32").GetCString(), eBasicTypeOther);
+ g_type_map.Append(ConstString("float64").GetCString(), eBasicTypeOther);
+ g_type_map.Append(ConstString("uintptr").GetCString(), eBasicTypeOther);
+
+ g_type_map.Sort();
+ });
+
+ return g_type_map.Find(name.GetCString(), eBasicTypeInvalid);
+ }
+ return eBasicTypeInvalid;
+}
+
+lldb::LanguageType
+GoASTContext::GetMinimumLanguage(lldb::opaque_compiler_type_t type)
+{
+ return lldb::eLanguageTypeGo;
+}
+
+unsigned
+GoASTContext::GetTypeQualifiers(lldb::opaque_compiler_type_t type)
+{
+ return 0;
+}
+
+//----------------------------------------------------------------------
+// Creating related types
+//----------------------------------------------------------------------
+
+CompilerType
+GoASTContext::GetArrayElementType(lldb::opaque_compiler_type_t type, uint64_t *stride)
+{
+ GoArray *array = static_cast<GoType *>(type)->GetArray();
+ if (array)
+ {
+ if (stride)
+ {
+ *stride = array->GetElementType().GetByteSize(nullptr);
+ }
+ return array->GetElementType();
+ }
+ return CompilerType();
+}
+
+CompilerType
+GoASTContext::GetCanonicalType(lldb::opaque_compiler_type_t type)
+{
+ GoType *t = static_cast<GoType *>(type);
+ if (t->IsTypedef())
+ return t->GetElementType();
+ return CompilerType(this, type);
+}
+
+CompilerType
+GoASTContext::GetFullyUnqualifiedType(lldb::opaque_compiler_type_t type)
+{
+ return CompilerType(this, type);
+}
+
+// Returns -1 if this isn't a function of if the function doesn't have a prototype
+// Returns a value >= 0 if there is a prototype.
+int
+GoASTContext::GetFunctionArgumentCount(lldb::opaque_compiler_type_t type)
+{
+ return GetNumberOfFunctionArguments(type);
+}
+
+CompilerType
+GoASTContext::GetFunctionArgumentTypeAtIndex(lldb::opaque_compiler_type_t type, size_t idx)
+{
+ return GetFunctionArgumentAtIndex(type, idx);
+}
+
+CompilerType
+GoASTContext::GetFunctionReturnType(lldb::opaque_compiler_type_t type)
+{
+ CompilerType result;
+ if (type)
+ {
+ GoType *t = static_cast<GoType *>(type);
+ if (t->GetGoKind() == GoType::KIND_FUNC)
+ result = t->GetElementType();
+ }
+ return result;
+}
+
+size_t
+GoASTContext::GetNumMemberFunctions(lldb::opaque_compiler_type_t type)
+{
+ return 0;
+}
+
+TypeMemberFunctionImpl
+GoASTContext::GetMemberFunctionAtIndex(lldb::opaque_compiler_type_t type, size_t idx)
+{
+ return TypeMemberFunctionImpl();
+}
+
+CompilerType
+GoASTContext::GetNonReferenceType(lldb::opaque_compiler_type_t type)
+{
+ return CompilerType(this, type);
+}
+
+CompilerType
+GoASTContext::GetPointeeType(lldb::opaque_compiler_type_t type)
+{
+ if (!type)
+ return CompilerType();
+ return static_cast<GoType *>(type)->GetElementType();
+}
+
+CompilerType
+GoASTContext::GetPointerType(lldb::opaque_compiler_type_t type)
+{
+ if (!type)
+ return CompilerType();
+ ConstString type_name = GetTypeName(type);
+ ConstString pointer_name(std::string("*") + type_name.GetCString());
+ GoType *pointer = (*m_types)[pointer_name].get();
+ if (pointer == nullptr)
+ {
+ pointer = new GoElem(GoType::KIND_PTR, pointer_name, CompilerType(this, type));
+ (*m_types)[pointer_name].reset(pointer);
+ }
+ return CompilerType(this, pointer);
+}
+
+// If the current object represents a typedef type, get the underlying type
+CompilerType
+GoASTContext::GetTypedefedType(lldb::opaque_compiler_type_t type)
+{
+ if (IsTypedefType(type))
+ return static_cast<GoType *>(type)->GetElementType();
+ return CompilerType();
+}
+
+//----------------------------------------------------------------------
+// Create related types using the current type's AST
+//----------------------------------------------------------------------
+CompilerType
+GoASTContext::GetBasicTypeFromAST(lldb::BasicType basic_type)
+{
+ return CompilerType();
+}
+
+CompilerType
+GoASTContext::GetBuiltinTypeForEncodingAndBitSize (lldb::Encoding encoding,
+ size_t bit_size)
+{
+ return CompilerType();
+}
+
+
+//----------------------------------------------------------------------
+// Exploring the type
+//----------------------------------------------------------------------
+
+uint64_t
+GoASTContext::GetBitSize(lldb::opaque_compiler_type_t type, ExecutionContextScope *exe_scope)
+{
+ if (!type)
+ return 0;
+ if (!GetCompleteType(type))
+ return 0;
+ GoType *t = static_cast<GoType *>(type);
+ GoArray *array = nullptr;
+ switch (t->GetGoKind())
+ {
+ case GoType::KIND_BOOL:
+ case GoType::KIND_INT8:
+ case GoType::KIND_UINT8:
+ return 8;
+ case GoType::KIND_INT16:
+ case GoType::KIND_UINT16:
+ return 16;
+ case GoType::KIND_INT32:
+ case GoType::KIND_UINT32:
+ case GoType::KIND_FLOAT32:
+ return 32;
+ case GoType::KIND_INT64:
+ case GoType::KIND_UINT64:
+ case GoType::KIND_FLOAT64:
+ case GoType::KIND_COMPLEX64:
+ return 64;
+ case GoType::KIND_COMPLEX128:
+ return 128;
+ case GoType::KIND_INT:
+ case GoType::KIND_UINT:
+ return m_int_byte_size * 8;
+ case GoType::KIND_UINTPTR:
+ case GoType::KIND_FUNC: // I assume this is a pointer?
+ case GoType::KIND_CHAN:
+ case GoType::KIND_PTR:
+ case GoType::KIND_UNSAFEPOINTER:
+ case GoType::KIND_MAP:
+ return m_pointer_byte_size * 8;
+ case GoType::KIND_ARRAY:
+ array = t->GetArray();
+ return array->GetLength() * array->GetElementType().GetBitSize(exe_scope);
+ case GoType::KIND_INTERFACE:
+ return t->GetElementType().GetBitSize(exe_scope);
+ case GoType::KIND_SLICE:
+ case GoType::KIND_STRING:
+ case GoType::KIND_STRUCT:
+ return t->GetStruct()->GetByteSize() * 8;
+ default:
+ assert(false);
+ }
+ return 0;
+}
+
+lldb::Encoding
+GoASTContext::GetEncoding(lldb::opaque_compiler_type_t type, uint64_t &count)
+{
+ count = 1;
+ bool is_signed;
+ if (IsIntegerType(type, is_signed))
+ return is_signed ? lldb::eEncodingSint : eEncodingUint;
+ bool is_complex;
+ uint32_t complex_count;
+ if (IsFloatingPointType(type, complex_count, is_complex))
+ {
+ count = complex_count;
+ return eEncodingIEEE754;
+ }
+ if (IsPointerType(type))
+ return eEncodingUint;
+ return eEncodingInvalid;
+}
+
+lldb::Format
+GoASTContext::GetFormat(lldb::opaque_compiler_type_t type)
+{
+ if (!type)
+ return eFormatDefault;
+ switch (static_cast<GoType *>(type)->GetGoKind())
+ {
+ case GoType::KIND_BOOL:
+ return eFormatBoolean;
+ case GoType::KIND_INT:
+ case GoType::KIND_INT8:
+ case GoType::KIND_INT16:
+ case GoType::KIND_INT32:
+ case GoType::KIND_INT64:
+ return eFormatDecimal;
+ case GoType::KIND_UINT:
+ case GoType::KIND_UINT8:
+ case GoType::KIND_UINT16:
+ case GoType::KIND_UINT32:
+ case GoType::KIND_UINT64:
+ return eFormatUnsigned;
+ case GoType::KIND_FLOAT32:
+ case GoType::KIND_FLOAT64:
+ return eFormatFloat;
+ case GoType::KIND_COMPLEX64:
+ case GoType::KIND_COMPLEX128:
+ return eFormatComplexFloat;
+ case GoType::KIND_UINTPTR:
+ case GoType::KIND_CHAN:
+ case GoType::KIND_PTR:
+ case GoType::KIND_MAP:
+ case GoType::KIND_UNSAFEPOINTER:
+ return eFormatHex;
+ case GoType::KIND_STRING:
+ return eFormatCString;
+ case GoType::KIND_ARRAY:
+ case GoType::KIND_INTERFACE:
+ case GoType::KIND_SLICE:
+ case GoType::KIND_STRUCT:
+ default:
+ // Don't know how to display this.
+ return eFormatBytes;
+ }
+}
+
+size_t
+GoASTContext::GetTypeBitAlign(lldb::opaque_compiler_type_t type)
+{
+ return 0;
+}
+
+uint32_t
+GoASTContext::GetNumChildren(lldb::opaque_compiler_type_t type, bool omit_empty_base_classes)
+{
+ if (!type || !GetCompleteType(type))
+ return 0;
+ GoType *t = static_cast<GoType *>(type);
+ if (t->GetGoKind() == GoType::KIND_PTR)
+ {
+ CompilerType elem = t->GetElementType();
+ if (elem.IsAggregateType())
+ return elem.GetNumChildren(omit_empty_base_classes);
+ return 1;
+ }
+ else if (GoArray *array = t->GetArray())
+ {
+ return array->GetLength();
+ }
+ else if (t->IsTypedef())
+ {
+ return t->GetElementType().GetNumChildren(omit_empty_base_classes);
+ }
+
+ return GetNumFields(type);
+}
+
+uint32_t
+GoASTContext::GetNumFields(lldb::opaque_compiler_type_t type)
+{
+ if (!type || !GetCompleteType(type))
+ return 0;
+ GoType *t = static_cast<GoType *>(type);
+ if (t->IsTypedef())
+ return t->GetElementType().GetNumFields();
+ GoStruct *s = t->GetStruct();
+ if (s)
+ return s->GetNumFields();
+ return 0;
+}
+
+CompilerType
+GoASTContext::GetFieldAtIndex(lldb::opaque_compiler_type_t type, size_t idx, std::string &name, uint64_t *bit_offset_ptr,
+ uint32_t *bitfield_bit_size_ptr, bool *is_bitfield_ptr)
+{
+ if (bit_offset_ptr)
+ *bit_offset_ptr = 0;
+ if (bitfield_bit_size_ptr)
+ *bitfield_bit_size_ptr = 0;
+ if (is_bitfield_ptr)
+ *is_bitfield_ptr = false;
+
+ if (!type || !GetCompleteType(type))
+ return CompilerType();
+
+ GoType *t = static_cast<GoType *>(type);
+ if (t->IsTypedef())
+ return t->GetElementType().GetFieldAtIndex(idx, name, bit_offset_ptr, bitfield_bit_size_ptr, is_bitfield_ptr);
+
+ GoStruct *s = t->GetStruct();
+ if (s)
+ {
+ const auto *field = s->GetField(idx);
+ if (field)
+ {
+ name = field->m_name.GetStringRef();
+ if (bit_offset_ptr)
+ *bit_offset_ptr = field->m_byte_offset * 8;
+ return field->m_type;
+ }
+ }
+ return CompilerType();
+}
+
+CompilerType
+GoASTContext::GetChildCompilerTypeAtIndex(lldb::opaque_compiler_type_t type, ExecutionContext *exe_ctx, size_t idx, bool transparent_pointers,
+ bool omit_empty_base_classes, bool ignore_array_bounds, std::string &child_name,
+ uint32_t &child_byte_size, int32_t &child_byte_offset,
+ uint32_t &child_bitfield_bit_size, uint32_t &child_bitfield_bit_offset,
+ bool &child_is_base_class, bool &child_is_deref_of_parent, ValueObject *valobj, uint64_t &language_flags)
+{
+ child_name.clear();
+ child_byte_size = 0;
+ child_byte_offset = 0;
+ child_bitfield_bit_size = 0;
+ child_bitfield_bit_offset = 0;
+ child_is_base_class = false;
+ child_is_deref_of_parent = false;
+ language_flags = 0;
+
+ if (!type || !GetCompleteType(type))
+ return CompilerType();
+
+ GoType *t = static_cast<GoType *>(type);
+ if (t->GetStruct())
+ {
+ uint64_t bit_offset;
+ CompilerType ret = GetFieldAtIndex(type, idx, child_name, &bit_offset, nullptr, nullptr);
+ child_byte_size = ret.GetByteSize(exe_ctx ? exe_ctx->GetBestExecutionContextScope() : nullptr);
+ child_byte_offset = bit_offset / 8;
+ return ret;
+ }
+ else if (t->GetGoKind() == GoType::KIND_PTR)
+ {
+ CompilerType pointee = t->GetElementType();
+ if (!pointee.IsValid() || pointee.IsVoidType())
+ return CompilerType();
+ if (transparent_pointers && pointee.IsAggregateType())
+ {
+ bool tmp_child_is_deref_of_parent = false;
+ return pointee.GetChildCompilerTypeAtIndex(exe_ctx, idx, transparent_pointers, omit_empty_base_classes,
+ ignore_array_bounds, child_name, child_byte_size, child_byte_offset,
+ child_bitfield_bit_size, child_bitfield_bit_offset,
+ child_is_base_class, tmp_child_is_deref_of_parent, valobj, language_flags);
+ }
+ else
+ {
+ child_is_deref_of_parent = true;
+ const char *parent_name = valobj ? valobj->GetName().GetCString() : NULL;
+ if (parent_name)
+ {
+ child_name.assign(1, '*');
+ child_name += parent_name;
+ }
+
+ // We have a pointer to an simple type
+ if (idx == 0 && pointee.GetCompleteType())
+ {
+ child_byte_size = pointee.GetByteSize(exe_ctx ? exe_ctx->GetBestExecutionContextScope() : NULL);
+ child_byte_offset = 0;
+ return pointee;
+ }
+ }
+ }
+ else if (GoArray *a = t->GetArray())
+ {
+ if (ignore_array_bounds || idx < a->GetLength())
+ {
+ CompilerType element_type = a->GetElementType();
+ if (element_type.GetCompleteType())
+ {
+ char element_name[64];
+ ::snprintf(element_name, sizeof(element_name), "[%zu]", idx);
+ child_name.assign(element_name);
+ child_byte_size = element_type.GetByteSize(exe_ctx ? exe_ctx->GetBestExecutionContextScope() : NULL);
+ child_byte_offset = (int32_t)idx * (int32_t)child_byte_size;
+ return element_type;
+ }
+ }
+ }
+ else if (t->IsTypedef())
+ {
+ return t->GetElementType().GetChildCompilerTypeAtIndex(
+ exe_ctx, idx, transparent_pointers, omit_empty_base_classes, ignore_array_bounds, child_name,
+ child_byte_size, child_byte_offset, child_bitfield_bit_size, child_bitfield_bit_offset, child_is_base_class,
+ child_is_deref_of_parent, valobj, language_flags);
+ }
+ return CompilerType();
+}
+
+// Lookup a child given a name. This function will match base class names
+// and member member names in "clang_type" only, not descendants.
+uint32_t
+GoASTContext::GetIndexOfChildWithName(lldb::opaque_compiler_type_t type, const char *name, bool omit_empty_base_classes)
+{
+ if (!type || !GetCompleteType(type))
+ return UINT_MAX;
+
+ GoType *t = static_cast<GoType *>(type);
+ GoStruct *s = t->GetStruct();
+ if (s)
+ {
+ for (uint32_t i = 0; i < s->GetNumFields(); ++i)
+ {
+ const GoStruct::Field *f = s->GetField(i);
+ if (f->m_name.GetStringRef() == name)
+ return i;
+ }
+ }
+ else if (t->GetGoKind() == GoType::KIND_PTR || t->IsTypedef())
+ {
+ return t->GetElementType().GetIndexOfChildWithName(name, omit_empty_base_classes);
+ }
+ return UINT_MAX;
+}
+
+// Lookup a child member given a name. This function will match member names
+// only and will descend into "clang_type" children in search for the first
+// member in this class, or any base class that matches "name".
+// TODO: Return all matches for a given name by returning a vector<vector<uint32_t>>
+// so we catch all names that match a given child name, not just the first.
+size_t
+GoASTContext::GetIndexOfChildMemberWithName(lldb::opaque_compiler_type_t type, const char *name, bool omit_empty_base_classes,
+ std::vector<uint32_t> &child_indexes)
+{
+ uint32_t index = GetIndexOfChildWithName(type, name, omit_empty_base_classes);
+ if (index == UINT_MAX)
+ return 0;
+ child_indexes.push_back(index);
+ return 1;
+}
+
+// Converts "s" to a floating point value and place resulting floating
+// point bytes in the "dst" buffer.
+size_t
+GoASTContext::ConvertStringToFloatValue(lldb::opaque_compiler_type_t type, const char *s, uint8_t *dst, size_t dst_size)
+{
+ assert(false);
+ return 0;
+}
+//----------------------------------------------------------------------
+// Dumping types
+//----------------------------------------------------------------------
+void
+GoASTContext::DumpValue(lldb::opaque_compiler_type_t type, ExecutionContext *exe_ctx, Stream *s, lldb::Format format,
+ const DataExtractor &data, lldb::offset_t data_offset, size_t data_byte_size,
+ uint32_t bitfield_bit_size, uint32_t bitfield_bit_offset, bool show_types, bool show_summary,
+ bool verbose, uint32_t depth)
+{
+ assert(false);
+}
+
+bool
+GoASTContext::DumpTypeValue(lldb::opaque_compiler_type_t type, Stream *s, lldb::Format format, const DataExtractor &data,
+ lldb::offset_t byte_offset, size_t byte_size, uint32_t bitfield_bit_size,
+ uint32_t bitfield_bit_offset, ExecutionContextScope *exe_scope)
+{
+ if (!type)
+ return false;
+ if (IsAggregateType(type))
+ {
+ return false;
+ }
+ else
+ {
+ GoType *t = static_cast<GoType *>(type);
+ if (t->IsTypedef())
+ {
+ CompilerType typedef_compiler_type = t->GetElementType();
+ if (format == eFormatDefault)
+ format = typedef_compiler_type.GetFormat();
+ uint64_t typedef_byte_size = typedef_compiler_type.GetByteSize(exe_scope);
+
+ return typedef_compiler_type.DumpTypeValue(
+ s,
+ format, // The format with which to display the element
+ data, // Data buffer containing all bytes for this type
+ byte_offset, // Offset into "data" where to grab value from
+ typedef_byte_size, // Size of this type in bytes
+ bitfield_bit_size, // Size in bits of a bitfield value, if zero don't treat as a bitfield
+ bitfield_bit_offset, // Offset in bits of a bitfield value if bitfield_bit_size != 0
+ exe_scope);
+ }
+
+ uint32_t item_count = 1;
+ // A few formats, we might need to modify our size and count for depending
+ // on how we are trying to display the value...
+ switch (format)
+ {
+ default:
+ case eFormatBoolean:
+ case eFormatBinary:
+ case eFormatComplex:
+ case eFormatCString: // NULL terminated C strings
+ case eFormatDecimal:
+ case eFormatEnum:
+ case eFormatHex:
+ case eFormatHexUppercase:
+ case eFormatFloat:
+ case eFormatOctal:
+ case eFormatOSType:
+ case eFormatUnsigned:
+ case eFormatPointer:
+ case eFormatVectorOfChar:
+ case eFormatVectorOfSInt8:
+ case eFormatVectorOfUInt8:
+ case eFormatVectorOfSInt16:
+ case eFormatVectorOfUInt16:
+ case eFormatVectorOfSInt32:
+ case eFormatVectorOfUInt32:
+ case eFormatVectorOfSInt64:
+ case eFormatVectorOfUInt64:
+ case eFormatVectorOfFloat32:
+ case eFormatVectorOfFloat64:
+ case eFormatVectorOfUInt128:
+ break;
+
+ case eFormatChar:
+ case eFormatCharPrintable:
+ case eFormatCharArray:
+ case eFormatBytes:
+ case eFormatBytesWithASCII:
+ item_count = byte_size;
+ byte_size = 1;
+ break;
+
+ case eFormatUnicode16:
+ item_count = byte_size / 2;
+ byte_size = 2;
+ break;
+
+ case eFormatUnicode32:
+ item_count = byte_size / 4;
+ byte_size = 4;
+ break;
+ }
+ return data.Dump(s, byte_offset, format, byte_size, item_count, UINT32_MAX, LLDB_INVALID_ADDRESS,
+ bitfield_bit_size, bitfield_bit_offset, exe_scope);
+ }
+ return 0;
+}
+
+void
+GoASTContext::DumpSummary(lldb::opaque_compiler_type_t type, ExecutionContext *exe_ctx, Stream *s, const DataExtractor &data,
+ lldb::offset_t data_offset, size_t data_byte_size)
+{
+ assert(false);
+}
+
+void
+GoASTContext::DumpTypeDescription(lldb::opaque_compiler_type_t type)
+{
+ assert(false);
+} // Dump to stdout
+
+void
+GoASTContext::DumpTypeDescription(lldb::opaque_compiler_type_t type, Stream *s)
+{
+ assert(false);
+}
+
+CompilerType
+GoASTContext::CreateArrayType(const ConstString &name, const CompilerType &element_type, uint64_t length)
+{
+ GoType *type = new GoArray(name, length, element_type);
+ (*m_types)[name].reset(type);
+ return CompilerType(this, type);
+}
+
+CompilerType
+GoASTContext::CreateBaseType(int go_kind, const lldb_private::ConstString &name, uint64_t byte_size)
+{
+ if (go_kind == GoType::KIND_UINT || go_kind == GoType::KIND_INT)
+ m_int_byte_size = byte_size;
+ GoType *type = new GoType(go_kind, name);
+ (*m_types)[name].reset(type);
+ return CompilerType(this, type);
+}
+
+CompilerType
+GoASTContext::CreateTypedefType(int kind, const ConstString &name, CompilerType impl)
+{
+ GoType *type = new GoElem(kind, name, impl);
+ (*m_types)[name].reset(type);
+ return CompilerType(this, type);
+}
+
+CompilerType
+GoASTContext::CreateVoidType(const lldb_private::ConstString &name)
+{
+ GoType *type = new GoType(GoType::KIND_LLDB_VOID, name);
+ (*m_types)[name].reset(type);
+ return CompilerType(this, type);
+}
+
+CompilerType
+GoASTContext::CreateStructType(int kind, const lldb_private::ConstString &name, uint32_t byte_size)
+{
+ GoType *type = new GoStruct(kind, name, byte_size);
+ (*m_types)[name].reset(type);
+ return CompilerType(this, type);
+}
+
+void
+GoASTContext::AddFieldToStruct(const lldb_private::CompilerType &struct_type, const lldb_private::ConstString &name,
+ const lldb_private::CompilerType &field_type, uint32_t byte_offset)
+{
+ if (!struct_type)
+ return;
+ GoASTContext *ast = llvm::dyn_cast_or_null<GoASTContext>(struct_type.GetTypeSystem());
+ if (!ast)
+ return;
+ GoType *type = static_cast<GoType *>(struct_type.GetOpaqueQualType());
+ if (GoStruct *s = type->GetStruct())
+ s->AddField(name, field_type, byte_offset);
+}
+
+void
+GoASTContext::CompleteStructType(const lldb_private::CompilerType &struct_type)
+{
+ if (!struct_type)
+ return;
+ GoASTContext *ast = llvm::dyn_cast_or_null<GoASTContext>(struct_type.GetTypeSystem());
+ if (!ast)
+ return;
+ GoType *type = static_cast<GoType *>(struct_type.GetOpaqueQualType());
+ if (GoStruct *s = type->GetStruct())
+ s->SetComplete();
+}
+
+CompilerType
+GoASTContext::CreateFunctionType(const lldb_private::ConstString &name, CompilerType *params, size_t params_count,
+ bool is_variadic)
+{
+ GoType *type = new GoFunction(name, is_variadic);
+ (*m_types)[name].reset(type);
+ return CompilerType(this, type);
+}
+
+bool
+GoASTContext::IsGoString(const lldb_private::CompilerType &type)
+{
+ if (!type.IsValid() || !llvm::dyn_cast_or_null<GoASTContext>(type.GetTypeSystem()))
+ return false;
+ return GoType::KIND_STRING == static_cast<GoType *>(type.GetOpaqueQualType())->GetGoKind();
+}
+
+bool
+GoASTContext::IsGoSlice(const lldb_private::CompilerType &type)
+{
+ if (!type.IsValid() || !llvm::dyn_cast_or_null<GoASTContext>(type.GetTypeSystem()))
+ return false;
+ return GoType::KIND_SLICE == static_cast<GoType *>(type.GetOpaqueQualType())->GetGoKind();
+}
+
+bool
+GoASTContext::IsGoInterface(const lldb_private::CompilerType &type)
+{
+ if (!type.IsValid() || !llvm::dyn_cast_or_null<GoASTContext>(type.GetTypeSystem()))
+ return false;
+ return GoType::KIND_INTERFACE == static_cast<GoType *>(type.GetOpaqueQualType())->GetGoKind();
+}
+
+bool
+GoASTContext::IsPointerKind(uint8_t kind)
+{
+ return (kind & GoType::KIND_MASK) == GoType::KIND_PTR;
+}
+
+bool
+GoASTContext::IsDirectIface(uint8_t kind)
+{
+ return (kind & GoType::KIND_DIRECT_IFACE) == GoType::KIND_DIRECT_IFACE;
+}
+
+DWARFASTParser *
+GoASTContext::GetDWARFParser()
+{
+ if (!m_dwarf_ast_parser_ap)
+ m_dwarf_ast_parser_ap.reset(new DWARFASTParserGo(*this));
+ return m_dwarf_ast_parser_ap.get();
+}
+
+UserExpression *
+GoASTContextForExpr::GetUserExpression(const char *expr, const char *expr_prefix, lldb::LanguageType language,
+ Expression::ResultType desired_type, const EvaluateExpressionOptions &options)
+{
+ TargetSP target = m_target_wp.lock();
+ if (target)
+ return new GoUserExpression(*target, expr, expr_prefix, language, desired_type, options);
+ return nullptr;
+}
diff --git a/source/Symbol/LineEntry.cpp b/source/Symbol/LineEntry.cpp
index 08a2392e1136c..815101368bd14 100644
--- a/source/Symbol/LineEntry.cpp
+++ b/source/Symbol/LineEntry.cpp
@@ -244,3 +244,42 @@ LineEntry::Compare (const LineEntry& a, const LineEntry& b)
return FileSpec::Compare (a.file, b.file, true);
}
+AddressRange
+LineEntry::GetSameLineContiguousAddressRange () const
+{
+ // Add each LineEntry's range to complete_line_range until we find
+ // a different file / line number.
+ AddressRange complete_line_range = range;
+
+ while (true)
+ {
+ SymbolContext next_line_sc;
+ Address range_end (complete_line_range.GetBaseAddress());
+ range_end.Slide (complete_line_range.GetByteSize());
+ range_end.CalculateSymbolContext (&next_line_sc, lldb::eSymbolContextLineEntry);
+
+ if (next_line_sc.line_entry.IsValid()
+ && next_line_sc.line_entry.range.GetByteSize() > 0
+ && file == next_line_sc.line_entry.file)
+ {
+ // Include any line 0 entries - they indicate that this is compiler-generated code
+ // that does not correspond to user source code.
+ if (next_line_sc.line_entry.line == 0)
+ {
+ complete_line_range.SetByteSize (complete_line_range.GetByteSize() + next_line_sc.line_entry.range.GetByteSize());
+ continue;
+ }
+
+ if (line == next_line_sc.line_entry.line)
+ {
+ // next_line_sc is the same file & line as this LineEntry, so extend our
+ // AddressRange by its size and continue to see if there are more LineEntries
+ // that we can combine.
+ complete_line_range.SetByteSize (complete_line_range.GetByteSize() + next_line_sc.line_entry.range.GetByteSize());
+ continue;
+ }
+ }
+ break;
+ }
+ return complete_line_range;
+}
diff --git a/source/Symbol/LineTable.cpp b/source/Symbol/LineTable.cpp
index 3b951f567660e..01c171886430c 100644
--- a/source/Symbol/LineTable.cpp
+++ b/source/Symbol/LineTable.cpp
@@ -104,7 +104,17 @@ LineTable::AppendLineEntryToSequence
// here to avoid these kinds of inconsistencies. We will need tor revisit this if the DWARF line
// tables are updated to allow multiple entries at the same address legally.
if (!entries.empty() && entries.back().file_addr == file_addr)
+ {
+ // GCC don't use the is_prologue_end flag to mark the first instruction after the prologue.
+ // Instead of it it is issueing a line table entry for the first instruction of the prologue
+ // and one for the first instruction after the prologue. If the size of the prologue is 0
+ // instruction then the 2 line entry will have the same file address. Removing it will remove
+ // our ability to properly detect the location of the end of prologe so we set the prologue_end
+ // flag to preserve this information (setting the prologue_end flag for an entry what is after
+ // the prologue end don't have any effect)
+ entry.is_prologue_end = entry.file_idx == entries.back().file_idx;
entries.back() = entry;
+ }
else
entries.push_back (entry);
}
@@ -215,7 +225,7 @@ LineTable::FindLineEntryByAddress (const Address &so_addr, LineEntry& line_entry
--pos;
else if (pos->file_addr == search_entry.file_addr)
{
- // If this is a termination entry, it should't match since
+ // If this is a termination entry, it shouldn't match since
// entries with the "is_terminal_entry" member set to true
// are termination entries that define the range for the
// previous entry.
@@ -529,7 +539,7 @@ LineTable::LinkLineTable (const FileRangeMap &file_range_map)
{
entry_linked_file_addr = entry.file_addr - file_range_entry->GetRangeBase() + file_range_entry->data;
// Determine if we need to terminate the previous entry when the previous
- // entry was not contguous with this one after being linked.
+ // entry was not contiguous with this one after being linked.
if (range_changed && prev_file_range_entry)
{
prev_end_entry_linked_file_addr = std::min<lldb::addr_t>(entry.file_addr, prev_file_range_entry->GetRangeEnd()) - prev_file_range_entry->GetRangeBase() + prev_file_range_entry->data;
diff --git a/source/Symbol/ObjectFile.cpp b/source/Symbol/ObjectFile.cpp
index 22a313cf6a20d..99f9236a2cd96 100644
--- a/source/Symbol/ObjectFile.cpp
+++ b/source/Symbol/ObjectFile.cpp
@@ -351,25 +351,31 @@ ObjectFile::GetAddressClass (addr_t file_addr)
case eSectionTypeZeroFill:
case eSectionTypeDataObjCMessageRefs:
case eSectionTypeDataObjCCFStrings:
+ case eSectionTypeGoSymtab:
return eAddressClassData;
case eSectionTypeDebug:
case eSectionTypeDWARFDebugAbbrev:
+ case eSectionTypeDWARFDebugAddr:
case eSectionTypeDWARFDebugAranges:
case eSectionTypeDWARFDebugFrame:
case eSectionTypeDWARFDebugInfo:
case eSectionTypeDWARFDebugLine:
case eSectionTypeDWARFDebugLoc:
case eSectionTypeDWARFDebugMacInfo:
+ case eSectionTypeDWARFDebugMacro:
case eSectionTypeDWARFDebugPubNames:
case eSectionTypeDWARFDebugPubTypes:
case eSectionTypeDWARFDebugRanges:
case eSectionTypeDWARFDebugStr:
+ case eSectionTypeDWARFDebugStrOffsets:
case eSectionTypeDWARFAppleNames:
case eSectionTypeDWARFAppleTypes:
case eSectionTypeDWARFAppleNamespaces:
case eSectionTypeDWARFAppleObjC:
return eAddressClassDebug;
case eSectionTypeEHFrame:
+ case eSectionTypeARMexidx:
+ case eSectionTypeARMextab:
case eSectionTypeCompactUnwind:
return eAddressClassRuntime;
case eSectionTypeELFSymbolTable:
@@ -532,6 +538,7 @@ ObjectFile::ReadSectionData (const Section *section, DataExtractor& section_data
}
}
}
+ return GetData(section->GetFileOffset(), section->GetFileSize(), section_data);
}
else
{
@@ -600,16 +607,49 @@ ObjectFile::ClearSymtab ()
}
SectionList *
-ObjectFile::GetSectionList()
+ObjectFile::GetSectionList(bool update_module_section_list)
{
if (m_sections_ap.get() == nullptr)
{
- ModuleSP module_sp(GetModule());
- if (module_sp)
+ if (update_module_section_list)
+ {
+ ModuleSP module_sp(GetModule());
+ if (module_sp)
+ {
+ lldb_private::Mutex::Locker locker(module_sp->GetMutex());
+ CreateSections(*module_sp->GetUnifiedSectionList());
+ }
+ }
+ else
{
- lldb_private::Mutex::Locker locker(module_sp->GetMutex());
- CreateSections(*module_sp->GetUnifiedSectionList());
+ SectionList unified_section_list;
+ CreateSections(unified_section_list);
}
}
return m_sections_ap.get();
}
+
+lldb::SymbolType
+ObjectFile::GetSymbolTypeFromName (llvm::StringRef name,
+ lldb::SymbolType symbol_type_hint)
+{
+ if (!name.empty())
+ {
+ if (name.startswith("_OBJC_"))
+ {
+ // ObjC
+ if (name.startswith("_OBJC_CLASS_$_"))
+ return lldb::eSymbolTypeObjCClass;
+ if (name.startswith("_OBJC_METACLASS_$_"))
+ return lldb::eSymbolTypeObjCMetaClass;
+ if (name.startswith("_OBJC_IVAR_$_"))
+ return lldb::eSymbolTypeObjCIVar;
+ }
+ else if (name.startswith(".objc_class_name_"))
+ {
+ // ObjC v1
+ return lldb::eSymbolTypeObjCClass;
+ }
+ }
+ return symbol_type_hint;
+}
diff --git a/source/Symbol/SymbolContext.cpp b/source/Symbol/SymbolContext.cpp
index 4fb0dbc237c86..54db5e090b805 100644
--- a/source/Symbol/SymbolContext.cpp
+++ b/source/Symbol/SymbolContext.cpp
@@ -391,24 +391,24 @@ SymbolContext::GetResolvedMask () const
void
SymbolContext::Dump(Stream *s, Target *target) const
{
- *s << (void *)this << ": ";
+ *s << this << ": ";
s->Indent();
s->PutCString("SymbolContext");
s->IndentMore();
s->EOL();
s->IndentMore();
s->Indent();
- *s << "Module = " << (void *)module_sp.get() << ' ';
+ *s << "Module = " << module_sp.get() << ' ';
if (module_sp)
module_sp->GetFileSpec().Dump(s);
s->EOL();
s->Indent();
- *s << "CompileUnit = " << (void *)comp_unit;
+ *s << "CompileUnit = " << comp_unit;
if (comp_unit != nullptr)
*s << " {0x" << comp_unit->GetID() << "} " << *(static_cast<FileSpec*> (comp_unit));
s->EOL();
s->Indent();
- *s << "Function = " << (void *)function;
+ *s << "Function = " << function;
if (function != nullptr)
{
*s << " {0x" << function->GetID() << "} " << function->GetType()->GetName() << ", address-range = ";
@@ -424,7 +424,7 @@ SymbolContext::Dump(Stream *s, Target *target) const
}
s->EOL();
s->Indent();
- *s << "Block = " << (void *)block;
+ *s << "Block = " << block;
if (block != nullptr)
*s << " {0x" << block->GetID() << '}';
// Dump the block and pass it a negative depth to we print all the parent blocks
@@ -436,11 +436,11 @@ SymbolContext::Dump(Stream *s, Target *target) const
line_entry.Dump (s, target, true, Address::DumpStyleLoadAddress, Address::DumpStyleModuleWithFileAddress, true);
s->EOL();
s->Indent();
- *s << "Symbol = " << (void *)symbol;
+ *s << "Symbol = " << symbol;
if (symbol != nullptr && symbol->GetMangled())
*s << ' ' << symbol->GetName().AsCString();
s->EOL();
- *s << "Variable = " << (void *)variable;
+ *s << "Variable = " << variable;
if (variable != nullptr)
{
*s << " {0x" << variable->GetID() << "} " << variable->GetType()->GetName();
@@ -525,6 +525,38 @@ SymbolContext::GetAddressRange (uint32_t scope,
return false;
}
+LanguageType
+SymbolContext::GetLanguage () const
+{
+ LanguageType lang;
+ if (function &&
+ (lang = function->GetLanguage()) != eLanguageTypeUnknown)
+ {
+ return lang;
+ }
+ else if (variable &&
+ (lang = variable->GetLanguage()) != eLanguageTypeUnknown)
+ {
+ return lang;
+ }
+ else if (symbol &&
+ (lang = symbol->GetLanguage()) != eLanguageTypeUnknown)
+ {
+ return lang;
+ }
+ else if (comp_unit &&
+ (lang = comp_unit->GetLanguage()) != eLanguageTypeUnknown)
+ {
+ return lang;
+ }
+ else if (symbol)
+ {
+ // If all else fails, try to guess the language from the name.
+ return symbol->GetMangled().GuessLanguage();
+ }
+ return eLanguageTypeUnknown;
+}
+
bool
SymbolContext::GetParentOfInlinedScope (const Address &curr_frame_pc,
SymbolContext &next_frame_sc,
@@ -649,23 +681,124 @@ SymbolContext::GetFunctionMethodInfo (lldb::LanguageType &language,
{
- Block *function_block = GetFunctionBlock ();
+ Block *function_block = GetFunctionBlock();
if (function_block)
{
- clang::DeclContext *decl_context = function_block->GetClangDeclContext();
-
- if (decl_context)
+ CompilerDeclContext decl_ctx = function_block->GetDeclContext();
+ if (decl_ctx)
+ return decl_ctx.IsClassMethod(&language, &is_instance_method, &language_object_name);
+ }
+ return false;
+}
+
+void
+SymbolContext::SortTypeList(TypeMap &type_map, TypeList &type_list) const
+{
+ Block * curr_block = block;
+ bool isInlinedblock = false;
+ if (curr_block != nullptr && curr_block->GetContainingInlinedBlock() != nullptr)
+ isInlinedblock = true;
+
+ //----------------------------------------------------------------------
+ // Find all types that match the current block if we have one and put
+ // them first in the list. Keep iterating up through all blocks.
+ //----------------------------------------------------------------------
+ while (curr_block != nullptr && !isInlinedblock)
+ {
+ type_map.ForEach([curr_block, &type_list](const lldb::TypeSP& type_sp) -> bool {
+ SymbolContextScope *scs = type_sp->GetSymbolContextScope();
+ if (scs && curr_block == scs->CalculateSymbolContextBlock())
+ type_list.Insert(type_sp);
+ return true; // Keep iterating
+ });
+
+ // Remove any entries that are now in "type_list" from "type_map"
+ // since we can't remove from type_map while iterating
+ type_list.ForEach([&type_map](const lldb::TypeSP& type_sp) -> bool {
+ type_map.Remove(type_sp);
+ return true; // Keep iterating
+ });
+ curr_block = curr_block->GetParent();
+ }
+ //----------------------------------------------------------------------
+ // Find all types that match the current function, if we have onem, and
+ // put them next in the list.
+ //----------------------------------------------------------------------
+ if (function != nullptr && !type_map.Empty())
+ {
+ const size_t old_type_list_size = type_list.GetSize();
+ type_map.ForEach([this, &type_list](const lldb::TypeSP& type_sp) -> bool {
+ SymbolContextScope *scs = type_sp->GetSymbolContextScope();
+ if (scs && function == scs->CalculateSymbolContextFunction())
+ type_list.Insert(type_sp);
+ return true; // Keep iterating
+ });
+
+ // Remove any entries that are now in "type_list" from "type_map"
+ // since we can't remove from type_map while iterating
+ const size_t new_type_list_size = type_list.GetSize();
+ if (new_type_list_size > old_type_list_size)
{
- return ClangASTContext::GetClassMethodInfoForDeclContext (decl_context,
- language,
- is_instance_method,
- language_object_name);
+ for (size_t i=old_type_list_size; i<new_type_list_size; ++i)
+ type_map.Remove(type_list.GetTypeAtIndex(i));
}
}
- language = eLanguageTypeUnknown;
- is_instance_method = false;
- language_object_name.Clear();
- return false;
+ //----------------------------------------------------------------------
+ // Find all types that match the current compile unit, if we have one,
+ // and put them next in the list.
+ //----------------------------------------------------------------------
+ if (comp_unit != nullptr && !type_map.Empty())
+ {
+ const size_t old_type_list_size = type_list.GetSize();
+
+ type_map.ForEach([this, &type_list](const lldb::TypeSP& type_sp) -> bool {
+ SymbolContextScope *scs = type_sp->GetSymbolContextScope();
+ if (scs && comp_unit == scs->CalculateSymbolContextCompileUnit())
+ type_list.Insert(type_sp);
+ return true; // Keep iterating
+ });
+
+ // Remove any entries that are now in "type_list" from "type_map"
+ // since we can't remove from type_map while iterating
+ const size_t new_type_list_size = type_list.GetSize();
+ if (new_type_list_size > old_type_list_size)
+ {
+ for (size_t i=old_type_list_size; i<new_type_list_size; ++i)
+ type_map.Remove(type_list.GetTypeAtIndex(i));
+ }
+ }
+ //----------------------------------------------------------------------
+ // Find all types that match the current module, if we have one, and put
+ // them next in the list.
+ //----------------------------------------------------------------------
+ if (module_sp && !type_map.Empty())
+ {
+ const size_t old_type_list_size = type_list.GetSize();
+ type_map.ForEach([this, &type_list](const lldb::TypeSP& type_sp) -> bool {
+ SymbolContextScope *scs = type_sp->GetSymbolContextScope();
+ if (scs && module_sp == scs->CalculateSymbolContextModule())
+ type_list.Insert(type_sp);
+ return true; // Keep iterating
+ });
+ // Remove any entries that are now in "type_list" from "type_map"
+ // since we can't remove from type_map while iterating
+ const size_t new_type_list_size = type_list.GetSize();
+ if (new_type_list_size > old_type_list_size)
+ {
+ for (size_t i=old_type_list_size; i<new_type_list_size; ++i)
+ type_map.Remove(type_list.GetTypeAtIndex(i));
+ }
+ }
+ //----------------------------------------------------------------------
+ // Any types that are left get copied into the list an any order.
+ //----------------------------------------------------------------------
+ if (!type_map.Empty())
+ {
+ type_map.ForEach([&type_list](const lldb::TypeSP& type_sp) -> bool {
+ type_list.Insert(type_sp);
+ return true; // Keep iterating
+ });
+ }
}
ConstString
@@ -930,7 +1063,7 @@ SymbolContextSpecifier::SymbolContextMatches(SymbolContext &sc)
}
else if (sc.symbol != nullptr)
{
- if (!sc.symbol->GetMangled().NameMatches(func_name, sc.function->GetLanguage()))
+ if (!sc.symbol->GetMangled().NameMatches(func_name, sc.symbol->GetLanguage()))
return false;
}
}
@@ -1178,7 +1311,7 @@ void
SymbolContextList::Dump(Stream *s, Target *target) const
{
- *s << (void *)this << ": ";
+ *s << this << ": ";
s->Indent();
s->PutCString("SymbolContextList");
s->EOL();
diff --git a/source/Symbol/SymbolFile.cpp b/source/Symbol/SymbolFile.cpp
index a5b138bb52afb..51e35048d5cdb 100644
--- a/source/Symbol/SymbolFile.cpp
+++ b/source/Symbol/SymbolFile.cpp
@@ -15,6 +15,9 @@
#include "lldb/Core/PluginManager.h"
#include "lldb/Core/StreamString.h"
#include "lldb/Symbol/ObjectFile.h"
+#include "lldb/Symbol/TypeMap.h"
+#include "lldb/Symbol/TypeSystem.h"
+#include "lldb/Symbol/VariableList.h"
using namespace lldb_private;
@@ -82,8 +85,68 @@ SymbolFile::GetTypeList ()
return nullptr;
}
-lldb_private::ClangASTContext &
-SymbolFile::GetClangASTContext ()
+TypeSystem *
+SymbolFile::GetTypeSystemForLanguage (lldb::LanguageType language)
{
- return m_obj_file->GetModule()->GetClangASTContext();
+ TypeSystem *type_system = m_obj_file->GetModule()->GetTypeSystemForLanguage(language);
+ if (type_system)
+ type_system->SetSymbolFile(this);
+ return type_system;
+}
+
+uint32_t
+SymbolFile::ResolveSymbolContext (const FileSpec& file_spec, uint32_t line, bool check_inlines, uint32_t resolve_scope, SymbolContextList& sc_list)
+{
+ return 0;
+}
+
+
+uint32_t
+SymbolFile::FindGlobalVariables (const ConstString &name, const CompilerDeclContext *parent_decl_ctx, bool append, uint32_t max_matches, VariableList& variables)
+{
+ if (!append)
+ variables.Clear();
+ return 0;
+}
+
+
+uint32_t
+SymbolFile::FindGlobalVariables (const RegularExpression& regex, bool append, uint32_t max_matches, VariableList& variables)
+{
+ if (!append)
+ variables.Clear();
+ return 0;
+}
+
+uint32_t
+SymbolFile::FindFunctions (const ConstString &name, const CompilerDeclContext *parent_decl_ctx, uint32_t name_type_mask, bool include_inlines, bool append, SymbolContextList& sc_list)
+{
+ if (!append)
+ sc_list.Clear();
+ return 0;
+}
+
+uint32_t
+SymbolFile::FindFunctions (const RegularExpression& regex, bool include_inlines, bool append, SymbolContextList& sc_list)
+{
+ if (!append)
+ sc_list.Clear();
+ return 0;
+}
+
+uint32_t
+SymbolFile::FindTypes (const SymbolContext& sc, const ConstString &name, const CompilerDeclContext *parent_decl_ctx, bool append, uint32_t max_matches, TypeMap& types)
+{
+ if (!append)
+ types.Clear();
+ return 0;
+}
+
+
+size_t
+SymbolFile::FindTypes (const std::vector<CompilerContext> &context, bool append, TypeMap& types)
+{
+ if (!append)
+ types.Clear();
+ return 0;
}
diff --git a/source/Symbol/SymbolVendor.cpp b/source/Symbol/SymbolVendor.cpp
index 6ec9f3861ecff..b9ec9a1c8a797 100644
--- a/source/Symbol/SymbolVendor.cpp
+++ b/source/Symbol/SymbolVendor.cpp
@@ -77,7 +77,7 @@ SymbolVendor::~SymbolVendor()
}
//----------------------------------------------------------------------
-// Add a represention given an object file.
+// Add a representation given an object file.
//----------------------------------------------------------------------
void
SymbolVendor::AddSymbolFileRepresentation(const ObjectFileSP &objfile_sp)
@@ -186,6 +186,18 @@ SymbolVendor::ParseCompileUnitLineTable (const SymbolContext &sc)
}
bool
+SymbolVendor::ParseCompileUnitDebugMacros (const SymbolContext &sc)
+{
+ ModuleSP module_sp(GetModule());
+ if (module_sp)
+ {
+ lldb_private::Mutex::Locker locker(module_sp->GetMutex());
+ if (m_sym_file_ap.get())
+ return m_sym_file_ap->ParseCompileUnitDebugMacros(sc);
+ }
+ return false;
+}
+bool
SymbolVendor::ParseCompileUnitSupportFiles (const SymbolContext& sc, FileSpecList& support_files)
{
ModuleSP module_sp(GetModule());
@@ -293,14 +305,14 @@ SymbolVendor::ResolveSymbolContext (const FileSpec& file_spec, uint32_t line, bo
}
size_t
-SymbolVendor::FindGlobalVariables (const ConstString &name, const ClangNamespaceDecl *namespace_decl, bool append, size_t max_matches, VariableList& variables)
+SymbolVendor::FindGlobalVariables (const ConstString &name, const CompilerDeclContext *parent_decl_ctx, bool append, size_t max_matches, VariableList& variables)
{
ModuleSP module_sp(GetModule());
if (module_sp)
{
lldb_private::Mutex::Locker locker(module_sp->GetMutex());
if (m_sym_file_ap.get())
- return m_sym_file_ap->FindGlobalVariables(name, namespace_decl, append, max_matches, variables);
+ return m_sym_file_ap->FindGlobalVariables(name, parent_decl_ctx, append, max_matches, variables);
}
return 0;
}
@@ -319,14 +331,14 @@ SymbolVendor::FindGlobalVariables (const RegularExpression& regex, bool append,
}
size_t
-SymbolVendor::FindFunctions(const ConstString &name, const ClangNamespaceDecl *namespace_decl, uint32_t name_type_mask, bool include_inlines, bool append, SymbolContextList& sc_list)
+SymbolVendor::FindFunctions(const ConstString &name, const CompilerDeclContext *parent_decl_ctx, uint32_t name_type_mask, bool include_inlines, bool append, SymbolContextList& sc_list)
{
ModuleSP module_sp(GetModule());
if (module_sp)
{
lldb_private::Mutex::Locker locker(module_sp->GetMutex());
if (m_sym_file_ap.get())
- return m_sym_file_ap->FindFunctions(name, namespace_decl, name_type_mask, include_inlines, append, sc_list);
+ return m_sym_file_ap->FindFunctions(name, parent_decl_ctx, name_type_mask, include_inlines, append, sc_list);
}
return 0;
}
@@ -346,14 +358,29 @@ SymbolVendor::FindFunctions(const RegularExpression& regex, bool include_inlines
size_t
-SymbolVendor::FindTypes (const SymbolContext& sc, const ConstString &name, const ClangNamespaceDecl *namespace_decl, bool append, size_t max_matches, TypeList& types)
+SymbolVendor::FindTypes (const SymbolContext& sc, const ConstString &name, const CompilerDeclContext *parent_decl_ctx, bool append, size_t max_matches, TypeMap& types)
+{
+ ModuleSP module_sp(GetModule());
+ if (module_sp)
+ {
+ lldb_private::Mutex::Locker locker(module_sp->GetMutex());
+ if (m_sym_file_ap.get())
+ return m_sym_file_ap->FindTypes(sc, name, parent_decl_ctx, append, max_matches, types);
+ }
+ if (!append)
+ types.Clear();
+ return 0;
+}
+
+size_t
+SymbolVendor::FindTypes (const std::vector<CompilerContext> &context, bool append, TypeMap& types)
{
ModuleSP module_sp(GetModule());
if (module_sp)
{
lldb_private::Mutex::Locker locker(module_sp->GetMutex());
if (m_sym_file_ap.get())
- return m_sym_file_ap->FindTypes(sc, name, namespace_decl, append, max_matches, types);
+ return m_sym_file_ap->FindTypes(context, append, types);
}
if (!append)
types.Clear();
@@ -375,18 +402,18 @@ SymbolVendor::GetTypes (SymbolContextScope *sc_scope,
return 0;
}
-ClangNamespaceDecl
-SymbolVendor::FindNamespace(const SymbolContext& sc, const ConstString &name, const ClangNamespaceDecl *parent_namespace_decl)
+CompilerDeclContext
+SymbolVendor::FindNamespace(const SymbolContext& sc, const ConstString &name, const CompilerDeclContext *parent_decl_ctx)
{
- ClangNamespaceDecl namespace_decl;
+ CompilerDeclContext namespace_decl_ctx;
ModuleSP module_sp(GetModule());
if (module_sp)
{
lldb_private::Mutex::Locker locker(module_sp->GetMutex());
if (m_sym_file_ap.get())
- namespace_decl = m_sym_file_ap->FindNamespace (sc, name, parent_namespace_decl);
+ namespace_decl_ctx = m_sym_file_ap->FindNamespace (sc, name, parent_decl_ctx);
}
- return namespace_decl;
+ return namespace_decl_ctx;
}
void
diff --git a/source/Symbol/Symtab.cpp b/source/Symbol/Symtab.cpp
index c11efc0d9b24c..b20504addec92 100644
--- a/source/Symbol/Symtab.cpp
+++ b/source/Symbol/Symtab.cpp
@@ -8,17 +8,19 @@
//===----------------------------------------------------------------------===//
#include <map>
+#include <set>
#include "lldb/Core/Module.h"
#include "lldb/Core/RegularExpression.h"
#include "lldb/Core/Section.h"
+#include "lldb/Core/Stream.h"
#include "lldb/Core/Timer.h"
#include "lldb/Symbol/ObjectFile.h"
#include "lldb/Symbol/Symbol.h"
#include "lldb/Symbol/SymbolContext.h"
#include "lldb/Symbol/Symtab.h"
-#include "lldb/Target/CPPLanguageRuntime.h"
-#include "lldb/Target/ObjCLanguageRuntime.h"
+#include "Plugins/Language/ObjC/ObjCLanguage.h"
+#include "Plugins/Language/CPlusPlus/CPlusPlusLanguage.h"
using namespace lldb;
using namespace lldb_private;
@@ -329,7 +331,7 @@ Symtab::InitNameIndexes()
entry.cstring[2] != 'G' && // avoid guard variables
entry.cstring[2] != 'Z')) // named local entities (if we eventually handle eSymbolTypeData, we will want this back)
{
- CPPLanguageRuntime::MethodName cxx_method (mangled.GetDemangledName(lldb::eLanguageTypeC_plus_plus));
+ CPlusPlusLanguage::MethodName cxx_method (mangled.GetDemangledName(lldb::eLanguageTypeC_plus_plus));
entry.cstring = ConstString(cxx_method.GetBasename()).GetCString();
if (entry.cstring && entry.cstring[0])
{
@@ -392,7 +394,7 @@ Symtab::InitNameIndexes()
// If the demangled name turns out to be an ObjC name, and
// is a category name, add the version without categories to the index too.
- ObjCLanguageRuntime::MethodName objc_method (entry.cstring, true);
+ ObjCLanguage::MethodName objc_method (entry.cstring, true);
if (objc_method.IsValid(true))
{
entry.cstring = objc_method.GetSelector().GetCString();
diff --git a/source/Symbol/Type.cpp b/source/Symbol/Type.cpp
index 0927d55f1ee20..8061e016ca591 100644
--- a/source/Symbol/Type.cpp
+++ b/source/Symbol/Type.cpp
@@ -7,22 +7,26 @@
//
//===----------------------------------------------------------------------===//
-// Other libraries and framework includes
+// C Includes
+#include <stdio.h>
+// C++ Includes
+// Other libraries and framework includes
+// Project includes
#include "lldb/Core/DataExtractor.h"
#include "lldb/Core/DataBufferHeap.h"
#include "lldb/Core/Module.h"
#include "lldb/Core/Scalar.h"
#include "lldb/Core/StreamString.h"
-#include "lldb/Symbol/ClangASTType.h"
-#include "lldb/Symbol/ClangASTContext.h"
+#include "lldb/Symbol/CompilerType.h"
#include "lldb/Symbol/ObjectFile.h"
#include "lldb/Symbol/SymbolContextScope.h"
#include "lldb/Symbol/SymbolFile.h"
#include "lldb/Symbol/SymbolVendor.h"
#include "lldb/Symbol/Type.h"
#include "lldb/Symbol/TypeList.h"
+#include "lldb/Symbol/TypeSystem.h"
#include "lldb/Target/ExecutionContext.h"
#include "lldb/Target/Process.h"
@@ -36,6 +40,26 @@
using namespace lldb;
using namespace lldb_private;
+void
+CompilerContext::Dump() const
+{
+ switch (type)
+ {
+ case CompilerContextKind::Invalid: printf("Invalid"); break;
+ case CompilerContextKind::TranslationUnit: printf("TranslationUnit"); break;
+ case CompilerContextKind::Module: printf("Module"); break;
+ case CompilerContextKind::Namespace: printf("Namespace"); break;
+ case CompilerContextKind::Class: printf("Class"); break;
+ case CompilerContextKind::Structure: printf("Structure"); break;
+ case CompilerContextKind::Union: printf("Union"); break;
+ case CompilerContextKind::Function: printf("Function"); break;
+ case CompilerContextKind::Variable: printf("Variable"); break;
+ case CompilerContextKind::Enumeration: printf("Enumeration"); break;
+ case CompilerContextKind::Typedef: printf("Typedef"); break;
+ }
+ printf("(\"%s\")\n", name.GetCString());
+}
+
class TypeAppendVisitor
{
public:
@@ -62,6 +86,13 @@ TypeListImpl::Append (const lldb_private::TypeList &type_list)
type_list.ForEach(cb);
}
+SymbolFileType::SymbolFileType (SymbolFile &symbol_file, const lldb::TypeSP &type_sp) :
+ UserID (type_sp ? type_sp->GetID() : LLDB_INVALID_UID),
+ m_symbol_file (symbol_file),
+ m_type_sp (type_sp)
+{
+}
+
Type *
SymbolFileType::GetType ()
@@ -86,8 +117,8 @@ Type::Type
user_id_t encoding_uid,
EncodingDataType encoding_uid_type,
const Declaration& decl,
- const ClangASTType &clang_type,
- ResolveState clang_type_resolve_state
+ const CompilerType &compiler_type,
+ ResolveState compiler_type_resolve_state
) :
std::enable_shared_from_this<Type> (),
UserID (uid),
@@ -99,9 +130,9 @@ Type::Type
m_encoding_uid_type (encoding_uid_type),
m_byte_size (byte_size),
m_decl (decl),
- m_clang_type (clang_type)
+ m_compiler_type (compiler_type)
{
- m_flags.clang_type_resolve_state = (clang_type ? clang_type_resolve_state : eResolveStateUnresolved);
+ m_flags.compiler_type_resolve_state = (compiler_type ? compiler_type_resolve_state : eResolveStateUnresolved);
m_flags.is_complete_objc_class = false;
}
@@ -116,9 +147,9 @@ Type::Type () :
m_encoding_uid_type (eEncodingInvalid),
m_byte_size (0),
m_decl (),
- m_clang_type ()
+ m_compiler_type ()
{
- m_flags.clang_type_resolve_state = eResolveStateUnresolved;
+ m_flags.compiler_type_resolve_state = eResolveStateUnresolved;
m_flags.is_complete_objc_class = false;
}
@@ -134,7 +165,7 @@ Type::Type (const Type &rhs) :
m_encoding_uid_type (rhs.m_encoding_uid_type),
m_byte_size (rhs.m_byte_size),
m_decl (rhs.m_decl),
- m_clang_type (rhs.m_clang_type),
+ m_compiler_type (rhs.m_compiler_type),
m_flags (rhs.m_flags)
{
}
@@ -175,10 +206,10 @@ Type::GetDescription (Stream *s, lldb::DescriptionLevel level, bool show_name)
bool show_fullpaths = (level == lldb::eDescriptionLevelVerbose);
m_decl.Dump(s, show_fullpaths);
- if (m_clang_type.IsValid())
+ if (m_compiler_type.IsValid())
{
- *s << ", clang_type = \"";
- GetClangForwardType().DumpTypeDescription(s);
+ *s << ", compiler_type = \"";
+ GetForwardCompilerType ().DumpTypeDescription(s);
*s << '"';
}
else if (m_encoding_uid != LLDB_INVALID_UID)
@@ -223,10 +254,10 @@ Type::Dump (Stream *s, bool show_context)
bool show_fullpaths = false;
m_decl.Dump (s,show_fullpaths);
- if (m_clang_type.IsValid())
+ if (m_compiler_type.IsValid())
{
- *s << ", clang_type = " << m_clang_type.GetOpaqueQualType() << ' ';
- GetClangForwardType().DumpTypeDescription (s);
+ *s << ", compiler_type = " << m_compiler_type.GetOpaqueQualType() << ' ';
+ GetForwardCompilerType ().DumpTypeDescription (s);
}
else if (m_encoding_uid != LLDB_INVALID_UID)
{
@@ -256,7 +287,7 @@ const ConstString &
Type::GetName()
{
if (!m_name)
- m_name = GetClangForwardType().GetConstTypeName();
+ m_name = GetForwardCompilerType ().GetConstTypeName();
return m_name;
}
@@ -291,7 +322,7 @@ Type::DumpValue
s->PutCString(") ");
}
- GetClangForwardType().DumpValue (exe_ctx,
+ GetForwardCompilerType ().DumpValue (exe_ctx,
s,
format == lldb::eFormatDefault ? GetFormat() : format,
data,
@@ -336,7 +367,7 @@ Type::GetByteSize()
if (encoding_type)
m_byte_size = encoding_type->GetByteSize();
if (m_byte_size == 0)
- m_byte_size = GetClangLayoutType().GetByteSize(nullptr);
+ m_byte_size = GetLayoutCompilerType ().GetByteSize(nullptr);
}
break;
@@ -344,7 +375,11 @@ Type::GetByteSize()
case eEncodingIsPointerUID:
case eEncodingIsLValueReferenceUID:
case eEncodingIsRValueReferenceUID:
- m_byte_size = m_symbol_file->GetClangASTContext().GetPointerByteSize();
+ {
+ ArchSpec arch;
+ if (m_symbol_file->GetObjectFile()->GetArchitecture(arch))
+ m_byte_size = arch.GetAddressByteSize();
+ }
break;
}
}
@@ -355,13 +390,13 @@ Type::GetByteSize()
uint32_t
Type::GetNumChildren (bool omit_empty_base_classes)
{
- return GetClangForwardType().GetNumChildren(omit_empty_base_classes);
+ return GetForwardCompilerType ().GetNumChildren(omit_empty_base_classes);
}
bool
Type::IsAggregateType ()
{
- return GetClangForwardType().IsAggregateType();
+ return GetForwardCompilerType ().IsAggregateType();
}
lldb::TypeSP
@@ -382,7 +417,7 @@ Type::GetTypedefType()
lldb::Format
Type::GetFormat ()
{
- return GetClangForwardType().GetFormat();
+ return GetForwardCompilerType ().GetFormat();
}
@@ -391,7 +426,7 @@ lldb::Encoding
Type::GetEncoding (uint64_t &count)
{
// Make sure we resolve our type if it already hasn't been.
- return GetClangForwardType().GetEncoding(count);
+ return GetForwardCompilerType ().GetEncoding(count);
}
bool
@@ -441,7 +476,7 @@ Type::ReadFromMemory (ExecutionContext *exe_ctx, lldb::addr_t addr, AddressType
data.SetData(data_sp);
}
- uint8_t* dst = (uint8_t*)data.PeekData(0, byte_size);
+ uint8_t* dst = const_cast<uint8_t*>(data.PeekData(0, byte_size));
if (dst != nullptr)
{
if (address_type == eAddressTypeHost)
@@ -489,10 +524,11 @@ Type::GetDeclaration () const
}
bool
-Type::ResolveClangType (ResolveState clang_type_resolve_state)
+Type::ResolveClangType (ResolveState compiler_type_resolve_state)
{
+ // TODO: This needs to consider the correct type system to use.
Type *encoding_type = nullptr;
- if (!m_clang_type.IsValid())
+ if (!m_compiler_type.IsValid())
{
encoding_type = GetEncodingType();
if (encoding_type)
@@ -501,43 +537,43 @@ Type::ResolveClangType (ResolveState clang_type_resolve_state)
{
case eEncodingIsUID:
{
- ClangASTType encoding_clang_type = encoding_type->GetClangForwardType();
- if (encoding_clang_type.IsValid())
+ CompilerType encoding_compiler_type = encoding_type->GetForwardCompilerType ();
+ if (encoding_compiler_type.IsValid())
{
- m_clang_type = encoding_clang_type;
- m_flags.clang_type_resolve_state = encoding_type->m_flags.clang_type_resolve_state;
+ m_compiler_type = encoding_compiler_type;
+ m_flags.compiler_type_resolve_state = encoding_type->m_flags.compiler_type_resolve_state;
}
}
break;
case eEncodingIsConstUID:
- m_clang_type = encoding_type->GetClangForwardType().AddConstModifier();
+ m_compiler_type = encoding_type->GetForwardCompilerType ().AddConstModifier();
break;
case eEncodingIsRestrictUID:
- m_clang_type = encoding_type->GetClangForwardType().AddRestrictModifier();
+ m_compiler_type = encoding_type->GetForwardCompilerType ().AddRestrictModifier();
break;
case eEncodingIsVolatileUID:
- m_clang_type = encoding_type->GetClangForwardType().AddVolatileModifier();
+ m_compiler_type = encoding_type->GetForwardCompilerType ().AddVolatileModifier();
break;
case eEncodingIsTypedefUID:
- m_clang_type = encoding_type->GetClangForwardType().CreateTypedefType (GetName().AsCString(),
- GetSymbolFile()->GetClangDeclContextContainingTypeUID(GetID()));
+ m_compiler_type = encoding_type->GetForwardCompilerType ().CreateTypedef(GetName().AsCString(),
+ GetSymbolFile()->GetDeclContextContainingUID(GetID()));
m_name.Clear();
break;
case eEncodingIsPointerUID:
- m_clang_type = encoding_type->GetClangForwardType().GetPointerType();
+ m_compiler_type = encoding_type->GetForwardCompilerType ().GetPointerType();
break;
case eEncodingIsLValueReferenceUID:
- m_clang_type = encoding_type->GetClangForwardType().GetLValueReferenceType();
+ m_compiler_type = encoding_type->GetForwardCompilerType ().GetLValueReferenceType();
break;
case eEncodingIsRValueReferenceUID:
- m_clang_type = encoding_type->GetClangForwardType().GetRValueReferenceType();
+ m_compiler_type = encoding_type->GetForwardCompilerType ().GetRValueReferenceType();
break;
default:
@@ -548,40 +584,41 @@ Type::ResolveClangType (ResolveState clang_type_resolve_state)
else
{
// We have no encoding type, return void?
- ClangASTType void_clang_type (ClangASTContext::GetBasicType(GetClangASTContext().getASTContext(), eBasicTypeVoid));
+ TypeSystem *type_system = m_symbol_file->GetTypeSystemForLanguage(eLanguageTypeC);
+ CompilerType void_compiler_type = type_system->GetBasicTypeFromAST(eBasicTypeVoid);
switch (m_encoding_uid_type)
{
case eEncodingIsUID:
- m_clang_type = void_clang_type;
+ m_compiler_type = void_compiler_type;
break;
case eEncodingIsConstUID:
- m_clang_type = void_clang_type.AddConstModifier ();
+ m_compiler_type = void_compiler_type.AddConstModifier();
break;
case eEncodingIsRestrictUID:
- m_clang_type = void_clang_type.AddRestrictModifier ();
+ m_compiler_type = void_compiler_type.AddRestrictModifier();
break;
case eEncodingIsVolatileUID:
- m_clang_type = void_clang_type.AddVolatileModifier ();
+ m_compiler_type = void_compiler_type.AddVolatileModifier();
break;
case eEncodingIsTypedefUID:
- m_clang_type = void_clang_type.CreateTypedefType (GetName().AsCString(),
- GetSymbolFile()->GetClangDeclContextContainingTypeUID(GetID()));
+ m_compiler_type = void_compiler_type.CreateTypedef(GetName().AsCString(),
+ GetSymbolFile()->GetDeclContextContainingUID(GetID()));
break;
case eEncodingIsPointerUID:
- m_clang_type = void_clang_type.GetPointerType ();
+ m_compiler_type = void_compiler_type.GetPointerType ();
break;
case eEncodingIsLValueReferenceUID:
- m_clang_type = void_clang_type.GetLValueReferenceType ();
+ m_compiler_type = void_compiler_type.GetLValueReferenceType();
break;
case eEncodingIsRValueReferenceUID:
- m_clang_type = void_clang_type.GetRValueReferenceType ();
+ m_compiler_type = void_compiler_type.GetRValueReferenceType();
break;
default:
@@ -590,25 +627,25 @@ Type::ResolveClangType (ResolveState clang_type_resolve_state)
}
}
- // When we have a EncodingUID, our "m_flags.clang_type_resolve_state" is set to eResolveStateUnresolved
+ // When we have a EncodingUID, our "m_flags.compiler_type_resolve_state" is set to eResolveStateUnresolved
// so we need to update it to say that we now have a forward declaration since that is what we created
// above.
- if (m_clang_type.IsValid())
- m_flags.clang_type_resolve_state = eResolveStateForward;
+ if (m_compiler_type.IsValid())
+ m_flags.compiler_type_resolve_state = eResolveStateForward;
}
// Check if we have a forward reference to a class/struct/union/enum?
- if (clang_type_resolve_state == eResolveStateLayout || clang_type_resolve_state == eResolveStateFull)
+ if (compiler_type_resolve_state == eResolveStateLayout || compiler_type_resolve_state == eResolveStateFull)
{
// Check if we have a forward reference to a class/struct/union/enum?
- if (m_clang_type.IsValid() && m_flags.clang_type_resolve_state < clang_type_resolve_state)
+ if (m_compiler_type.IsValid() && m_flags.compiler_type_resolve_state < compiler_type_resolve_state)
{
- m_flags.clang_type_resolve_state = eResolveStateFull;
- if (!m_clang_type.IsDefined ())
+ m_flags.compiler_type_resolve_state = eResolveStateFull;
+ if (!m_compiler_type.IsDefined ())
{
// We have a forward declaration, we need to resolve it to a complete definition.
- m_symbol_file->ResolveClangOpaqueTypeDefinition (m_clang_type);
+ m_symbol_file->CompleteType (m_compiler_type);
}
}
}
@@ -621,25 +658,25 @@ Type::ResolveClangType (ResolveState clang_type_resolve_state)
encoding_type = GetEncodingType();
if (encoding_type)
{
- ResolveState encoding_clang_type_resolve_state = clang_type_resolve_state;
+ ResolveState encoding_compiler_type_resolve_state = compiler_type_resolve_state;
- if (clang_type_resolve_state == eResolveStateLayout)
+ if (compiler_type_resolve_state == eResolveStateLayout)
{
switch (m_encoding_uid_type)
{
case eEncodingIsPointerUID:
case eEncodingIsLValueReferenceUID:
case eEncodingIsRValueReferenceUID:
- encoding_clang_type_resolve_state = eResolveStateForward;
+ encoding_compiler_type_resolve_state = eResolveStateForward;
break;
default:
break;
}
}
- encoding_type->ResolveClangType (encoding_clang_type_resolve_state);
+ encoding_type->ResolveClangType (encoding_compiler_type_resolve_state);
}
}
- return m_clang_type.IsValid();
+ return m_compiler_type.IsValid();
}
uint32_t
Type::GetEncodingMask ()
@@ -652,31 +689,25 @@ Type::GetEncodingMask ()
return encoding_mask;
}
-ClangASTType
-Type::GetClangFullType ()
+CompilerType
+Type::GetFullCompilerType ()
{
ResolveClangType(eResolveStateFull);
- return m_clang_type;
+ return m_compiler_type;
}
-ClangASTType
-Type::GetClangLayoutType ()
+CompilerType
+Type::GetLayoutCompilerType ()
{
ResolveClangType(eResolveStateLayout);
- return m_clang_type;
+ return m_compiler_type;
}
-ClangASTType
-Type::GetClangForwardType ()
+CompilerType
+Type::GetForwardCompilerType ()
{
ResolveClangType (eResolveStateForward);
- return m_clang_type;
-}
-
-ClangASTContext &
-Type::GetClangASTContext ()
-{
- return m_symbol_file->GetClangASTContext();
+ return m_compiler_type;
}
int
@@ -690,64 +721,14 @@ Type::Compare(const Type &a, const Type &b)
if (a_uid > b_uid)
return 1;
return 0;
-// if (a.getQualType() == b.getQualType())
-// return 0;
-}
-
-
-#if 0 // START REMOVE
-// Move this into ClangASTType
-void *
-Type::CreateClangPointerType (Type *type)
-{
- assert(type);
- return GetClangASTContext().CreatePointerType(type->GetClangForwardType());
-}
-
-void *
-Type::CreateClangTypedefType (Type *typedef_type, Type *base_type)
-{
- assert(typedef_type && base_type);
- return GetClangASTContext().CreateTypedefType (typedef_type->GetName().AsCString(),
- base_type->GetClangForwardType(),
- typedef_type->GetSymbolFile()->GetClangDeclContextContainingTypeUID(typedef_type->GetID()));
-}
-
-void *
-Type::CreateClangLValueReferenceType (Type *type)
-{
- assert(type);
- return GetClangASTContext().CreateLValueReferenceType(type->GetClangForwardType());
-}
-
-void *
-Type::CreateClangRValueReferenceType (Type *type)
-{
- assert(type);
- return GetClangASTContext().CreateRValueReferenceType (type->GetClangForwardType());
-}
-#endif // END REMOVE
-
-bool
-Type::IsRealObjCClass()
-{
- // For now we are just skipping ObjC classes that get made by hand from the runtime, because
- // those don't have any information. We could extend this to only return true for "full
- // definitions" if we can figure that out.
-
- if (m_clang_type.IsObjCObjectOrInterfaceType() && GetByteSize() != 0)
- return true;
- else
- return false;
}
ConstString
Type::GetQualifiedName ()
{
- return GetClangForwardType().GetConstTypeName();
+ return GetForwardCompilerType ().GetConstTypeName();
}
-
bool
Type::GetTypeScopeAndBasename (const char* &name_cstr,
std::string &scope,
@@ -905,9 +886,9 @@ TypeAndOrName::SetTypeSP (lldb::TypeSP type_sp)
}
void
-TypeAndOrName::SetClangASTType (ClangASTType clang_type)
+TypeAndOrName::SetCompilerType (CompilerType compiler_type)
{
- m_type_pair.SetType(clang_type);
+ m_type_pair.SetType(compiler_type);
if (m_type_pair)
m_type_name = m_type_pair.GetName();
}
@@ -941,9 +922,9 @@ TypeAndOrName::HasTypeSP () const
}
bool
-TypeAndOrName::HasClangASTType () const
+TypeAndOrName::HasCompilerType () const
{
- return m_type_pair.GetClangASTType().IsValid();
+ return m_type_pair.GetCompilerType().IsValid();
}
@@ -969,15 +950,15 @@ TypeImpl::TypeImpl (const lldb::TypeSP &type_sp) :
SetType (type_sp);
}
-TypeImpl::TypeImpl (const ClangASTType &clang_type) :
+TypeImpl::TypeImpl (const CompilerType &compiler_type) :
m_module_wp (),
m_static_type(),
m_dynamic_type()
{
- SetType (clang_type);
+ SetType (compiler_type);
}
-TypeImpl::TypeImpl (const lldb::TypeSP &type_sp, const ClangASTType &dynamic) :
+TypeImpl::TypeImpl (const lldb::TypeSP &type_sp, const CompilerType &dynamic) :
m_module_wp (),
m_static_type (type_sp),
m_dynamic_type(dynamic)
@@ -985,7 +966,7 @@ TypeImpl::TypeImpl (const lldb::TypeSP &type_sp, const ClangASTType &dynamic) :
SetType (type_sp, dynamic);
}
-TypeImpl::TypeImpl (const ClangASTType &static_type, const ClangASTType &dynamic_type) :
+TypeImpl::TypeImpl (const CompilerType &static_type, const CompilerType &dynamic_type) :
m_module_wp (),
m_static_type (),
m_dynamic_type()
@@ -993,7 +974,7 @@ TypeImpl::TypeImpl (const ClangASTType &static_type, const ClangASTType &dynamic
SetType (static_type, dynamic_type);
}
-TypeImpl::TypeImpl (const TypePair &pair, const ClangASTType &dynamic) :
+TypeImpl::TypeImpl (const TypePair &pair, const CompilerType &dynamic) :
m_module_wp (),
m_static_type (),
m_dynamic_type()
@@ -1012,29 +993,29 @@ TypeImpl::SetType (const lldb::TypeSP &type_sp)
}
void
-TypeImpl::SetType (const ClangASTType &clang_type)
+TypeImpl::SetType (const CompilerType &compiler_type)
{
m_module_wp = lldb::ModuleWP();
- m_static_type.SetType (clang_type);
+ m_static_type.SetType (compiler_type);
}
void
-TypeImpl::SetType (const lldb::TypeSP &type_sp, const ClangASTType &dynamic)
+TypeImpl::SetType (const lldb::TypeSP &type_sp, const CompilerType &dynamic)
{
SetType (type_sp);
m_dynamic_type = dynamic;
}
void
-TypeImpl::SetType (const ClangASTType &clang_type, const ClangASTType &dynamic)
+TypeImpl::SetType (const CompilerType &compiler_type, const CompilerType &dynamic)
{
m_module_wp = lldb::ModuleWP();
- m_static_type.SetType (clang_type);
+ m_static_type.SetType (compiler_type);
m_dynamic_type = dynamic;
}
void
-TypeImpl::SetType (const TypePair &pair, const ClangASTType &dynamic)
+TypeImpl::SetType (const TypePair &pair, const CompilerType &dynamic)
{
m_module_wp = pair.GetModule();
m_static_type = pair;
@@ -1249,8 +1230,8 @@ TypeImpl::GetCanonicalType() const
return TypeImpl();
}
-ClangASTType
-TypeImpl::GetClangASTType (bool prefer_dynamic)
+CompilerType
+TypeImpl::GetCompilerType (bool prefer_dynamic)
{
ModuleSP module_sp;
if (CheckModule (module_sp))
@@ -1260,13 +1241,13 @@ TypeImpl::GetClangASTType (bool prefer_dynamic)
if (m_dynamic_type.IsValid())
return m_dynamic_type;
}
- return m_static_type.GetClangASTType();
+ return m_static_type.GetCompilerType();
}
- return ClangASTType();
+ return CompilerType();
}
-clang::ASTContext *
-TypeImpl::GetClangASTContext (bool prefer_dynamic)
+TypeSystem *
+TypeImpl::GetTypeSystem (bool prefer_dynamic)
{
ModuleSP module_sp;
if (CheckModule (module_sp))
@@ -1274,9 +1255,9 @@ TypeImpl::GetClangASTContext (bool prefer_dynamic)
if (prefer_dynamic)
{
if (m_dynamic_type.IsValid())
- return m_dynamic_type.GetASTContext();
+ return m_dynamic_type.GetTypeSystem();
}
- return m_static_type.GetClangASTContext();
+ return m_static_type.GetCompilerType().GetTypeSystem();
}
return NULL;
}
@@ -1294,7 +1275,7 @@ TypeImpl::GetDescription (lldb_private::Stream &strm,
m_dynamic_type.DumpTypeDescription(&strm);
strm.Printf("\nStatic:\n");
}
- m_static_type.GetClangASTType().DumpTypeDescription(&strm);
+ m_static_type.GetCompilerType().DumpTypeDescription(&strm);
}
else
{
@@ -1303,19 +1284,6 @@ TypeImpl::GetDescription (lldb_private::Stream &strm,
return true;
}
-TypeMemberFunctionImpl&
-TypeMemberFunctionImpl::operator = (const TypeMemberFunctionImpl& rhs)
-{
- if (this != &rhs)
- {
- m_type = rhs.m_type;
- m_objc_method_decl = rhs.m_objc_method_decl;
- m_name = rhs.m_name;
- m_kind = rhs.m_kind;
- }
- return *this;
-}
-
bool
TypeMemberFunctionImpl::IsValid ()
{
@@ -1328,7 +1296,13 @@ TypeMemberFunctionImpl::GetName () const
return m_name;
}
-ClangASTType
+ConstString
+TypeMemberFunctionImpl::GetMangledName () const
+{
+ return m_decl.GetMangledName();
+}
+
+CompilerType
TypeMemberFunctionImpl::GetType () const
{
return m_type;
@@ -1340,21 +1314,6 @@ TypeMemberFunctionImpl::GetKind () const
return m_kind;
}
-std::string
-TypeMemberFunctionImpl::GetPrintableTypeName ()
-{
- if (m_type)
- return m_type.GetTypeName().AsCString("<unknown>");
- if (m_objc_method_decl)
- {
- if (m_objc_method_decl->getClassInterface())
- {
- return m_objc_method_decl->getClassInterface()->getName();
- }
- }
- return "<unknown>";
-}
-
bool
TypeMemberFunctionImpl::GetDescription (Stream& stream)
{
@@ -1362,33 +1321,31 @@ TypeMemberFunctionImpl::GetDescription (Stream& stream)
case lldb::eMemberFunctionKindUnknown:
return false;
case lldb::eMemberFunctionKindConstructor:
- stream.Printf("constructor for %s", GetPrintableTypeName().c_str());
+ stream.Printf("constructor for %s", m_type.GetTypeName().AsCString("<unknown>"));
break;
case lldb::eMemberFunctionKindDestructor:
- stream.Printf("destructor for %s", GetPrintableTypeName().c_str());
+ stream.Printf("destructor for %s", m_type.GetTypeName().AsCString("<unknown>"));
break;
case lldb::eMemberFunctionKindInstanceMethod:
stream.Printf("instance method %s of type %s",
m_name.AsCString(),
- GetPrintableTypeName().c_str());
+ m_decl.GetDeclContext().GetName().AsCString());
break;
case lldb::eMemberFunctionKindStaticMethod:
stream.Printf("static method %s of type %s",
m_name.AsCString(),
- GetPrintableTypeName().c_str());
+ m_decl.GetDeclContext().GetName().AsCString());
break;
}
return true;
}
-ClangASTType
+CompilerType
TypeMemberFunctionImpl::GetReturnType () const
{
if (m_type)
return m_type.GetFunctionReturnType();
- if (m_objc_method_decl)
- return ClangASTType(&m_objc_method_decl->getASTContext(),m_objc_method_decl->getReturnType().getAsOpaquePtr());
- return ClangASTType();
+ return m_decl.GetFunctionReturnType();
}
size_t
@@ -1396,37 +1353,26 @@ TypeMemberFunctionImpl::GetNumArguments () const
{
if (m_type)
return m_type.GetNumberOfFunctionArguments();
- if (m_objc_method_decl)
- return m_objc_method_decl->param_size();
- return 0;
+ else
+ return m_decl.GetNumFunctionArguments();
}
-ClangASTType
+CompilerType
TypeMemberFunctionImpl::GetArgumentAtIndex (size_t idx) const
{
if (m_type)
return m_type.GetFunctionArgumentAtIndex (idx);
- if (m_objc_method_decl)
- {
- if (idx < m_objc_method_decl->param_size())
- return ClangASTType(&m_objc_method_decl->getASTContext(), m_objc_method_decl->parameters()[idx]->getOriginalType().getAsOpaquePtr());
- }
- return ClangASTType();
+ else
+ return m_decl.GetFunctionArgumentType(idx);
}
-TypeEnumMemberImpl::TypeEnumMemberImpl (const clang::EnumConstantDecl* enum_member_decl,
- const lldb_private::ClangASTType& integer_type) :
- m_integer_type_sp(),
- m_name(),
- m_value(),
- m_valid(false)
+TypeEnumMemberImpl::TypeEnumMemberImpl (const lldb::TypeImplSP &integer_type_sp,
+ const ConstString &name,
+ const llvm::APSInt &value) :
+ m_integer_type_sp(integer_type_sp),
+ m_name(name),
+ m_value(value),
+ m_valid((bool)name && (bool)integer_type_sp)
{
- if (enum_member_decl)
- {
- m_integer_type_sp.reset(new TypeImpl(integer_type));
- m_name = ConstString(enum_member_decl->getNameAsString().c_str());
- m_value = enum_member_decl->getInitVal();
- m_valid = true;
- }
}
diff --git a/source/Symbol/TypeList.cpp b/source/Symbol/TypeList.cpp
index 8d97b2ba25cc5..f181dd66463c7 100644
--- a/source/Symbol/TypeList.cpp
+++ b/source/Symbol/TypeList.cpp
@@ -13,18 +13,6 @@
#include <vector>
// Other libraries and framework includes
-#include "clang/AST/ASTConsumer.h"
-#include "clang/AST/ASTContext.h"
-#include "clang/AST/Decl.h"
-#include "clang/AST/DeclCXX.h"
-#include "clang/AST/DeclGroup.h"
-
-#include "clang/Basic/Builtins.h"
-#include "clang/Basic/IdentifierTable.h"
-#include "clang/Basic/LangOptions.h"
-#include "clang/Basic/SourceManager.h"
-#include "clang/Basic/TargetInfo.h"
-
#include "llvm/Support/FormattedStream.h"
#include "llvm/Support/raw_ostream.h"
@@ -36,7 +24,6 @@
using namespace lldb;
using namespace lldb_private;
-using namespace clang;
TypeList::TypeList() :
m_types ()
@@ -55,26 +42,7 @@ TypeList::Insert (const TypeSP& type_sp)
{
// Just push each type on the back for now. We will worry about uniquing later
if (type_sp)
- m_types.insert(std::make_pair(type_sp->GetID(), type_sp));
-}
-
-
-bool
-TypeList::InsertUnique (const TypeSP& type_sp)
-{
- if (type_sp)
- {
- user_id_t type_uid = type_sp->GetID();
- iterator pos, end = m_types.end();
-
- for (pos = m_types.find(type_uid); pos != end && pos->second->GetID() == type_uid; ++pos)
- {
- if (pos->second.get() == type_sp.get())
- return false;
- }
- }
- Insert (type_sp);
- return true;
+ m_types.push_back(type_sp);
}
//----------------------------------------------------------------------
@@ -129,7 +97,7 @@ TypeList::GetTypeAtIndex(uint32_t idx)
for (pos = m_types.begin(), end = m_types.end(); pos != end; ++pos)
{
if (i == 0)
- return pos->second;
+ return *pos;
--i;
}
return TypeSP();
@@ -140,7 +108,7 @@ TypeList::ForEach (std::function <bool(const lldb::TypeSP &type_sp)> const &call
{
for (auto pos = m_types.begin(), end = m_types.end(); pos != end; ++pos)
{
- if (!callback(pos->second))
+ if (!callback(*pos))
break;
}
}
@@ -150,32 +118,17 @@ TypeList::ForEach (std::function <bool(lldb::TypeSP &type_sp)> const &callback)
{
for (auto pos = m_types.begin(), end = m_types.end(); pos != end; ++pos)
{
- if (!callback(pos->second))
+ if (!callback(*pos))
break;
}
}
-
-bool
-TypeList::RemoveTypeWithUID (user_id_t uid)
-{
- iterator pos = m_types.find(uid);
-
- if (pos != m_types.end())
- {
- m_types.erase(pos);
- return true;
- }
- return false;
-}
-
-
void
TypeList::Dump(Stream *s, bool show_context)
{
for (iterator pos = m_types.begin(), end = m_types.end(); pos != end; ++pos)
{
- pos->second->Dump(s, show_context);
+ pos->get()->Dump(s, show_context);
}
}
@@ -210,13 +163,13 @@ TypeList::RemoveMismatchedTypes (const std::string &type_scope,
for (pos = m_types.begin(); pos != end; ++pos)
{
- Type* the_type = pos->second.get();
+ Type* the_type = pos->get();
bool keep_match = false;
TypeClass match_type_class = eTypeClassAny;
if (type_class != eTypeClassAny)
{
- match_type_class = the_type->GetClangForwardType().GetTypeClass ();
+ match_type_class = the_type->GetForwardCompilerType ().GetTypeClass ();
if ((match_type_class & type_class) == 0)
continue;
}
@@ -249,9 +202,9 @@ TypeList::RemoveMismatchedTypes (const std::string &type_scope,
{
if (type_scope_pos >= 2)
{
- // Our match scope ends with the type scope we were lookikng for,
+ // Our match scope ends with the type scope we were looking for,
// but we need to make sure what comes before the matching
- // type scope is a namepace boundary in case we are trying to match:
+ // type scope is a namespace boundary in case we are trying to match:
// type_basename = "d"
// type_scope = "b::c::"
// We want to match:
@@ -282,7 +235,7 @@ TypeList::RemoveMismatchedTypes (const std::string &type_scope,
if (keep_match)
{
- matching_types.insert (*pos);
+ matching_types.push_back(*pos);
}
}
m_types.swap(matching_types);
@@ -304,10 +257,10 @@ TypeList::RemoveMismatchedTypes (TypeClass type_class)
for (pos = m_types.begin(); pos != end; ++pos)
{
- Type* the_type = pos->second.get();
- TypeClass match_type_class = the_type->GetClangForwardType().GetTypeClass ();
+ Type* the_type = pos->get();
+ TypeClass match_type_class = the_type->GetForwardCompilerType ().GetTypeClass ();
if (match_type_class & type_class)
- matching_types.insert (*pos);
+ matching_types.push_back (*pos);
}
m_types.swap(matching_types);
}
diff --git a/source/Symbol/TypeMap.cpp b/source/Symbol/TypeMap.cpp
new file mode 100644
index 0000000000000..6dc22ccbda967
--- /dev/null
+++ b/source/Symbol/TypeMap.cpp
@@ -0,0 +1,322 @@
+//===-- TypeMap.cpp --------------------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+
+// C Includes
+// C++ Includes
+#include <vector>
+
+// Other libraries and framework includes
+#include "clang/AST/ASTConsumer.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/Decl.h"
+#include "clang/AST/DeclCXX.h"
+#include "clang/AST/DeclGroup.h"
+
+#include "clang/Basic/Builtins.h"
+#include "clang/Basic/IdentifierTable.h"
+#include "clang/Basic/LangOptions.h"
+#include "clang/Basic/SourceManager.h"
+#include "clang/Basic/TargetInfo.h"
+
+#include "llvm/Support/FormattedStream.h"
+#include "llvm/Support/raw_ostream.h"
+
+// Project includes
+#include "lldb/Symbol/SymbolFile.h"
+#include "lldb/Symbol/SymbolVendor.h"
+#include "lldb/Symbol/Type.h"
+#include "lldb/Symbol/TypeMap.h"
+
+using namespace lldb;
+using namespace lldb_private;
+using namespace clang;
+
+TypeMap::TypeMap() :
+ m_types ()
+{
+}
+
+//----------------------------------------------------------------------
+// Destructor
+//----------------------------------------------------------------------
+TypeMap::~TypeMap()
+{
+}
+
+void
+TypeMap::Insert (const TypeSP& type_sp)
+{
+ // Just push each type on the back for now. We will worry about uniquing later
+ if (type_sp)
+ m_types.insert(std::make_pair(type_sp->GetID(), type_sp));
+}
+
+
+bool
+TypeMap::InsertUnique (const TypeSP& type_sp)
+{
+ if (type_sp)
+ {
+ user_id_t type_uid = type_sp->GetID();
+ iterator pos, end = m_types.end();
+
+ for (pos = m_types.find(type_uid); pos != end && pos->second->GetID() == type_uid; ++pos)
+ {
+ if (pos->second.get() == type_sp.get())
+ return false;
+ }
+ Insert (type_sp);
+ }
+ return true;
+}
+
+//----------------------------------------------------------------------
+// Find a base type by its unique ID.
+//----------------------------------------------------------------------
+//TypeSP
+//TypeMap::FindType(lldb::user_id_t uid)
+//{
+// iterator pos = m_types.find(uid);
+// if (pos != m_types.end())
+// return pos->second;
+// return TypeSP();
+//}
+
+//----------------------------------------------------------------------
+// Find a type by name.
+//----------------------------------------------------------------------
+//TypeMap
+//TypeMap::FindTypes (const ConstString &name)
+//{
+// // Do we ever need to make a lookup by name map? Here we are doing
+// // a linear search which isn't going to be fast.
+// TypeMap types(m_ast.getTargetInfo()->getTriple().getTriple().c_str());
+// iterator pos, end;
+// for (pos = m_types.begin(), end = m_types.end(); pos != end; ++pos)
+// if (pos->second->GetName() == name)
+// types.Insert (pos->second);
+// return types;
+//}
+
+void
+TypeMap::Clear()
+{
+ m_types.clear();
+}
+
+uint32_t
+TypeMap::GetSize() const
+{
+ return m_types.size();
+}
+
+bool
+TypeMap::Empty() const
+{
+ return m_types.empty();
+}
+
+// GetTypeAtIndex isn't used a lot for large type lists, currently only for
+// type lists that are returned for "image dump -t TYPENAME" commands and other
+// simple symbol queries that grab the first result...
+
+TypeSP
+TypeMap::GetTypeAtIndex(uint32_t idx)
+{
+ iterator pos, end;
+ uint32_t i = idx;
+ for (pos = m_types.begin(), end = m_types.end(); pos != end; ++pos)
+ {
+ if (i == 0)
+ return pos->second;
+ --i;
+ }
+ return TypeSP();
+}
+
+void
+TypeMap::ForEach (std::function <bool(const lldb::TypeSP &type_sp)> const &callback) const
+{
+ for (auto pos = m_types.begin(), end = m_types.end(); pos != end; ++pos)
+ {
+ if (!callback(pos->second))
+ break;
+ }
+}
+
+void
+TypeMap::ForEach (std::function <bool(lldb::TypeSP &type_sp)> const &callback)
+{
+ for (auto pos = m_types.begin(), end = m_types.end(); pos != end; ++pos)
+ {
+ if (!callback(pos->second))
+ break;
+ }
+}
+
+bool
+TypeMap::Remove (const lldb::TypeSP &type_sp)
+{
+ if (type_sp)
+ {
+ lldb::user_id_t uid = type_sp->GetID();
+ for (iterator pos = m_types.find(uid), end = m_types.end(); pos != end && pos->first == uid; ++pos)
+ {
+ if (pos->second == type_sp)
+ {
+ m_types.erase(pos);
+ return true;
+ }
+ }
+ }
+ return false;
+}
+
+void
+TypeMap::Dump(Stream *s, bool show_context)
+{
+ for (iterator pos = m_types.begin(), end = m_types.end(); pos != end; ++pos)
+ {
+ pos->second->Dump(s, show_context);
+ }
+}
+
+void
+TypeMap::RemoveMismatchedTypes (const char *qualified_typename,
+ bool exact_match)
+{
+ std::string type_scope;
+ std::string type_basename;
+ TypeClass type_class = eTypeClassAny;
+ if (!Type::GetTypeScopeAndBasename (qualified_typename, type_scope, type_basename, type_class))
+ {
+ type_basename = qualified_typename;
+ type_scope.clear();
+ }
+ return RemoveMismatchedTypes (type_scope, type_basename, type_class, exact_match);
+}
+
+void
+TypeMap::RemoveMismatchedTypes (const std::string &type_scope,
+ const std::string &type_basename,
+ TypeClass type_class,
+ bool exact_match)
+{
+ // Our "collection" type currently is a std::map which doesn't
+ // have any good way to iterate and remove items from the map
+ // so we currently just make a new list and add all of the matching
+ // types to it, and then swap it into m_types at the end
+ collection matching_types;
+
+ iterator pos, end = m_types.end();
+
+ for (pos = m_types.begin(); pos != end; ++pos)
+ {
+ Type* the_type = pos->second.get();
+ bool keep_match = false;
+ TypeClass match_type_class = eTypeClassAny;
+
+ if (type_class != eTypeClassAny)
+ {
+ match_type_class = the_type->GetForwardCompilerType ().GetTypeClass ();
+ if ((match_type_class & type_class) == 0)
+ continue;
+ }
+
+ ConstString match_type_name_const_str (the_type->GetQualifiedName());
+ if (match_type_name_const_str)
+ {
+ const char *match_type_name = match_type_name_const_str.GetCString();
+ std::string match_type_scope;
+ std::string match_type_basename;
+ if (Type::GetTypeScopeAndBasename (match_type_name,
+ match_type_scope,
+ match_type_basename,
+ match_type_class))
+ {
+ if (match_type_basename == type_basename)
+ {
+ const size_t type_scope_size = type_scope.size();
+ const size_t match_type_scope_size = match_type_scope.size();
+ if (exact_match || (type_scope_size == match_type_scope_size))
+ {
+ keep_match = match_type_scope == type_scope;
+ }
+ else
+ {
+ if (match_type_scope_size > type_scope_size)
+ {
+ const size_t type_scope_pos = match_type_scope.rfind(type_scope);
+ if (type_scope_pos == match_type_scope_size - type_scope_size)
+ {
+ if (type_scope_pos >= 2)
+ {
+ // Our match scope ends with the type scope we were looking for,
+ // but we need to make sure what comes before the matching
+ // type scope is a namespace boundary in case we are trying to match:
+ // type_basename = "d"
+ // type_scope = "b::c::"
+ // We want to match:
+ // match_type_scope "a::b::c::"
+ // But not:
+ // match_type_scope "a::bb::c::"
+ // So below we make sure what comes before "b::c::" in match_type_scope
+ // is "::", or the namespace boundary
+ if (match_type_scope[type_scope_pos - 1] == ':' &&
+ match_type_scope[type_scope_pos - 2] == ':')
+ {
+ keep_match = true;
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ else
+ {
+ // The type we are currently looking at doesn't exists
+ // in a namespace or class, so it only matches if there
+ // is no type scope...
+ keep_match = type_scope.empty() && type_basename.compare(match_type_name) == 0;
+ }
+ }
+
+ if (keep_match)
+ {
+ matching_types.insert (*pos);
+ }
+ }
+ m_types.swap(matching_types);
+}
+
+void
+TypeMap::RemoveMismatchedTypes (TypeClass type_class)
+{
+ if (type_class == eTypeClassAny)
+ return;
+
+ // Our "collection" type currently is a std::map which doesn't
+ // have any good way to iterate and remove items from the map
+ // so we currently just make a new list and add all of the matching
+ // types to it, and then swap it into m_types at the end
+ collection matching_types;
+
+ iterator pos, end = m_types.end();
+
+ for (pos = m_types.begin(); pos != end; ++pos)
+ {
+ Type* the_type = pos->second.get();
+ TypeClass match_type_class = the_type->GetForwardCompilerType ().GetTypeClass ();
+ if (match_type_class & type_class)
+ matching_types.insert (*pos);
+ }
+ m_types.swap(matching_types);
+}
diff --git a/source/Symbol/TypeSystem.cpp b/source/Symbol/TypeSystem.cpp
new file mode 100644
index 0000000000000..5c2ab5cceab6a
--- /dev/null
+++ b/source/Symbol/TypeSystem.cpp
@@ -0,0 +1,255 @@
+//
+// TypeSystem.cpp
+// lldb
+//
+// Created by Ryan Brown on 3/29/15.
+//
+//
+
+#include "lldb/Symbol/TypeSystem.h"
+
+#include <set>
+
+#include "lldb/Core/PluginManager.h"
+#include "lldb/Symbol/CompilerType.h"
+
+using namespace lldb_private;
+
+TypeSystem::TypeSystem(LLVMCastKind kind) :
+ m_kind (kind),
+ m_sym_file (nullptr)
+{
+}
+
+TypeSystem::~TypeSystem()
+{
+}
+
+lldb::TypeSystemSP
+TypeSystem::CreateInstance (lldb::LanguageType language, Module *module)
+{
+ uint32_t i = 0;
+ TypeSystemCreateInstance create_callback;
+ while ((create_callback = PluginManager::GetTypeSystemCreateCallbackAtIndex (i++)) != nullptr)
+ {
+ lldb::TypeSystemSP type_system_sp = create_callback(language, module, nullptr);
+ if (type_system_sp)
+ return type_system_sp;
+ }
+
+ return lldb::TypeSystemSP();
+}
+
+lldb::TypeSystemSP
+TypeSystem::CreateInstance (lldb::LanguageType language, Target *target)
+{
+ uint32_t i = 0;
+ TypeSystemCreateInstance create_callback;
+ while ((create_callback = PluginManager::GetTypeSystemCreateCallbackAtIndex (i++)) != nullptr)
+ {
+ lldb::TypeSystemSP type_system_sp = create_callback(language, nullptr, target);
+ if (type_system_sp)
+ return type_system_sp;
+ }
+
+ return lldb::TypeSystemSP();
+}
+
+bool
+TypeSystem::IsAnonymousType (lldb::opaque_compiler_type_t type)
+{
+ return false;
+}
+
+CompilerType
+TypeSystem::GetLValueReferenceType (lldb::opaque_compiler_type_t type)
+{
+ return CompilerType();
+}
+
+CompilerType
+TypeSystem::GetRValueReferenceType (lldb::opaque_compiler_type_t type)
+{
+ return CompilerType();
+}
+
+CompilerType
+TypeSystem::AddConstModifier (lldb::opaque_compiler_type_t type)
+{
+ return CompilerType();
+}
+
+CompilerType
+TypeSystem::AddVolatileModifier (lldb::opaque_compiler_type_t type)
+{
+ return CompilerType();
+}
+
+CompilerType
+TypeSystem::AddRestrictModifier (lldb::opaque_compiler_type_t type)
+{
+ return CompilerType();
+}
+
+CompilerType
+TypeSystem::CreateTypedef (lldb::opaque_compiler_type_t type, const char *name, const CompilerDeclContext &decl_ctx)
+{
+ return CompilerType();
+}
+
+CompilerType
+TypeSystem::GetBuiltinTypeByName (const ConstString &name)
+{
+ return CompilerType();
+}
+
+CompilerType
+TypeSystem::GetTypeForFormatters (void* type)
+{
+ return CompilerType(this, type);
+}
+
+LazyBool
+TypeSystem::ShouldPrintAsOneLiner (void* type, ValueObject* valobj)
+{
+ return eLazyBoolCalculate;
+}
+
+bool
+TypeSystem::IsMeaninglessWithoutDynamicResolution (void* type)
+{
+ return false;
+}
+
+ConstString
+TypeSystem::DeclGetMangledName (void *opaque_decl)
+{
+ return ConstString();
+}
+
+CompilerDeclContext
+TypeSystem::DeclGetDeclContext (void *opaque_decl)
+{
+ return CompilerDeclContext();
+}
+
+CompilerType
+TypeSystem::DeclGetFunctionReturnType(void *opaque_decl)
+{
+ return CompilerType();
+}
+
+size_t
+TypeSystem::DeclGetFunctionNumArguments(void *opaque_decl)
+{
+ return 0;
+}
+
+CompilerType
+TypeSystem::DeclGetFunctionArgumentType (void *opaque_decl, size_t arg_idx)
+{
+ return CompilerType();
+}
+
+
+std::vector<CompilerDecl>
+TypeSystem::DeclContextFindDeclByName (void *opaque_decl_ctx, ConstString name)
+{
+ return std::vector<CompilerDecl>();
+}
+
+
+#pragma mark TypeSystemMap
+
+TypeSystemMap::TypeSystemMap() :
+ m_mutex (),
+ m_map ()
+{
+}
+
+TypeSystemMap::~TypeSystemMap()
+{
+}
+
+void
+TypeSystemMap::Clear ()
+{
+ Mutex::Locker locker (m_mutex);
+ m_map.clear();
+}
+
+
+void
+TypeSystemMap::ForEach (std::function <bool(TypeSystem *)> const &callback)
+{
+ Mutex::Locker locker (m_mutex);
+ // Use a std::set so we only call the callback once for each unique
+ // TypeSystem instance
+ std::set<TypeSystem *> visited;
+ for (auto pair : m_map)
+ {
+ TypeSystem *type_system = pair.second.get();
+ if (type_system && !visited.count(type_system))
+ {
+ visited.insert(type_system);
+ if (callback (type_system) == false)
+ break;
+ }
+ }
+}
+
+TypeSystem *
+TypeSystemMap::GetTypeSystemForLanguage (lldb::LanguageType language, Module *module, bool can_create)
+{
+ Mutex::Locker locker (m_mutex);
+ collection::iterator pos = m_map.find(language);
+ if (pos != m_map.end())
+ return pos->second.get();
+
+ for (const auto &pair : m_map)
+ {
+ if (pair.second && pair.second->SupportsLanguage(language))
+ {
+ // Add a new mapping for "language" to point to an already existing
+ // TypeSystem that supports this language
+ m_map[language] = pair.second;
+ return pair.second.get();
+ }
+ }
+
+ if (!can_create)
+ return nullptr;
+
+ // Cache even if we get a shared pointer that contains null type system back
+ lldb::TypeSystemSP type_system_sp = TypeSystem::CreateInstance (language, module);
+ m_map[language] = type_system_sp;
+ return type_system_sp.get();
+}
+
+TypeSystem *
+TypeSystemMap::GetTypeSystemForLanguage (lldb::LanguageType language, Target *target, bool can_create)
+{
+ Mutex::Locker locker (m_mutex);
+ collection::iterator pos = m_map.find(language);
+ if (pos != m_map.end())
+ return pos->second.get();
+
+ for (const auto &pair : m_map)
+ {
+ if (pair.second && pair.second->SupportsLanguage(language))
+ {
+ // Add a new mapping for "language" to point to an already existing
+ // TypeSystem that supports this language
+ m_map[language] = pair.second;
+ return pair.second.get();
+ }
+ }
+
+ if (!can_create)
+ return nullptr;
+
+ // Cache even if we get a shared pointer that contains null type system back
+ lldb::TypeSystemSP type_system_sp = TypeSystem::CreateInstance (language, target);
+ m_map[language] = type_system_sp;
+ return type_system_sp.get();
+}
diff --git a/source/Symbol/UnwindTable.cpp b/source/Symbol/UnwindTable.cpp
index 90b33a69a789b..ac7a9b0fda87d 100644
--- a/source/Symbol/UnwindTable.cpp
+++ b/source/Symbol/UnwindTable.cpp
@@ -17,6 +17,7 @@
#include "lldb/Symbol/FuncUnwinders.h"
#include "lldb/Symbol/SymbolContext.h"
#include "lldb/Symbol/DWARFCallFrameInfo.h"
+#include "lldb/Symbol/ArmUnwindInfo.h"
#include "lldb/Symbol/CompactUnwindInfo.h"
// There is one UnwindTable object per ObjectFile.
@@ -31,8 +32,9 @@ UnwindTable::UnwindTable (ObjectFile& objfile) :
m_unwinds (),
m_initialized (false),
m_mutex (),
- m_eh_frame (nullptr),
- m_compact_unwind (nullptr)
+ m_eh_frame_up (),
+ m_compact_unwind_up (),
+ m_arm_unwind_up ()
{
}
@@ -56,12 +58,21 @@ UnwindTable::Initialize ()
SectionSP sect = sl->FindSectionByType (eSectionTypeEHFrame, true);
if (sect.get())
{
- m_eh_frame = new DWARFCallFrameInfo(m_object_file, sect, eRegisterKindGCC, true);
+ m_eh_frame_up.reset(new DWARFCallFrameInfo(m_object_file, sect, eRegisterKindEHFrame, true));
}
sect = sl->FindSectionByType (eSectionTypeCompactUnwind, true);
if (sect.get())
{
- m_compact_unwind = new CompactUnwindInfo(m_object_file, sect);
+ m_compact_unwind_up.reset(new CompactUnwindInfo(m_object_file, sect));
+ }
+ sect = sl->FindSectionByType (eSectionTypeARMexidx, true);
+ if (sect.get())
+ {
+ SectionSP sect_extab = sl->FindSectionByType (eSectionTypeARMextab, true);
+ if (sect_extab.get())
+ {
+ m_arm_unwind_up.reset(new ArmUnwindInfo(m_object_file, sect, sect_extab));
+ }
}
}
@@ -70,8 +81,6 @@ UnwindTable::Initialize ()
UnwindTable::~UnwindTable ()
{
- if (m_eh_frame)
- delete m_eh_frame;
}
FuncUnwindersSP
@@ -102,7 +111,7 @@ UnwindTable::GetFuncUnwindersContainingAddress (const Address& addr, SymbolConte
if (!sc.GetAddressRange(eSymbolContextFunction | eSymbolContextSymbol, 0, false, range) || !range.GetBaseAddress().IsValid())
{
// Does the eh_frame unwind info has a function bounds for this addr?
- if (m_eh_frame == nullptr || !m_eh_frame->GetAddressRange (addr, range))
+ if (m_eh_frame_up == nullptr || !m_eh_frame_up->GetAddressRange (addr, range))
{
return no_unwind_found;
}
@@ -129,7 +138,7 @@ UnwindTable::GetUncachedFuncUnwindersContainingAddress (const Address& addr, Sym
if (!sc.GetAddressRange(eSymbolContextFunction | eSymbolContextSymbol, 0, false, range) || !range.GetBaseAddress().IsValid())
{
// Does the eh_frame unwind info has a function bounds for this addr?
- if (m_eh_frame == nullptr || !m_eh_frame->GetAddressRange (addr, range))
+ if (m_eh_frame_up == nullptr || !m_eh_frame_up->GetAddressRange (addr, range))
{
return no_unwind_found;
}
@@ -158,14 +167,21 @@ DWARFCallFrameInfo *
UnwindTable::GetEHFrameInfo ()
{
Initialize();
- return m_eh_frame;
+ return m_eh_frame_up.get();
}
CompactUnwindInfo *
UnwindTable::GetCompactUnwindInfo ()
{
Initialize();
- return m_compact_unwind;
+ return m_compact_unwind_up.get();
+}
+
+ArmUnwindInfo *
+UnwindTable::GetArmUnwindInfo ()
+{
+ Initialize();
+ return m_arm_unwind_up.get();
}
bool
diff --git a/source/Symbol/Variable.cpp b/source/Symbol/Variable.cpp
index 2490e98ac1e84..51d11b7ca8e90 100644
--- a/source/Symbol/Variable.cpp
+++ b/source/Symbol/Variable.cpp
@@ -15,10 +15,14 @@
#include "lldb/Core/ValueObject.h"
#include "lldb/Core/ValueObjectVariable.h"
#include "lldb/Symbol/Block.h"
+#include "lldb/Symbol/CompilerDecl.h"
+#include "lldb/Symbol/CompilerDeclContext.h"
#include "lldb/Symbol/CompileUnit.h"
#include "lldb/Symbol/Function.h"
#include "lldb/Symbol/SymbolContext.h"
+#include "lldb/Symbol/SymbolFile.h"
#include "lldb/Symbol/Type.h"
+#include "lldb/Symbol/TypeSystem.h"
#include "lldb/Symbol/VariableList.h"
#include "lldb/Target/ABI.h"
#include "lldb/Target/Process.h"
@@ -33,19 +37,17 @@ using namespace lldb_private;
//----------------------------------------------------------------------
// Variable constructor
//----------------------------------------------------------------------
-Variable::Variable
-(
- lldb::user_id_t uid,
- const char *name,
- const char *mangled, // The mangled or fully qualified name of the variable.
- const lldb::SymbolFileTypeSP &symfile_type_sp,
- ValueType scope,
- SymbolContextScope *context,
- Declaration* decl_ptr,
- const DWARFExpression& location,
- bool external,
- bool artificial
-) :
+Variable::Variable (lldb::user_id_t uid,
+ const char *name,
+ const char *mangled, // The mangled or fully qualified name of the variable.
+ const lldb::SymbolFileTypeSP &symfile_type_sp,
+ ValueType scope,
+ SymbolContextScope *context,
+ Declaration* decl_ptr,
+ const DWARFExpression& location,
+ bool external,
+ bool artificial,
+ bool static_member) :
UserID(uid),
m_name(name),
m_mangled (ConstString(mangled)),
@@ -55,7 +57,8 @@ Variable::Variable
m_declaration(decl_ptr),
m_location(location),
m_external(external),
- m_artificial(artificial)
+ m_artificial(artificial),
+ m_static_member(static_member)
{
}
@@ -87,6 +90,13 @@ Variable::GetName() const
return m_name;
}
+ConstString
+Variable::GetUnqualifiedName() const
+{
+ return m_name;
+}
+
+
bool
Variable::NameMatches (const ConstString &name) const
{
@@ -228,6 +238,22 @@ Variable::MemorySize() const
return sizeof(Variable);
}
+CompilerDeclContext
+Variable::GetDeclContext ()
+{
+ Type *type = GetType();
+ return type->GetSymbolFile()->GetDeclContextContainingUID(GetID());
+}
+
+CompilerDecl
+Variable::GetDecl ()
+{
+ Type *type = GetType();
+ CompilerDecl decl = type->GetSymbolFile()->GetDeclForUID(GetID());
+ if (decl)
+ decl.GetTypeSystem()->DeclLinkToObject(decl.GetOpaqueDecl(), shared_from_this());
+ return decl;
+}
void
Variable::CalculateSymbolContext (SymbolContext *sc)
@@ -558,7 +584,7 @@ static void
PrivateAutoComplete (StackFrame *frame,
const std::string &partial_path,
const std::string &prefix_path, // Anything that has been resolved already will be in here
- const ClangASTType& clang_type,
+ const CompilerType& compiler_type,
StringList &matches,
bool &word_complete);
@@ -567,7 +593,7 @@ PrivateAutoCompleteMembers (StackFrame *frame,
const std::string &partial_member_name,
const std::string &partial_path,
const std::string &prefix_path, // Anything that has been resolved already will be in here
- const ClangASTType& clang_type,
+ const CompilerType& compiler_type,
StringList &matches,
bool &word_complete);
@@ -576,19 +602,19 @@ PrivateAutoCompleteMembers (StackFrame *frame,
const std::string &partial_member_name,
const std::string &partial_path,
const std::string &prefix_path, // Anything that has been resolved already will be in here
- const ClangASTType& clang_type,
+ const CompilerType& compiler_type,
StringList &matches,
bool &word_complete)
{
// We are in a type parsing child members
- const uint32_t num_bases = clang_type.GetNumDirectBaseClasses();
+ const uint32_t num_bases = compiler_type.GetNumDirectBaseClasses();
if (num_bases > 0)
{
for (uint32_t i = 0; i < num_bases; ++i)
{
- ClangASTType base_class_type (clang_type.GetDirectBaseClassAtIndex (i, nullptr));
+ CompilerType base_class_type = compiler_type.GetDirectBaseClassAtIndex(i, nullptr);
PrivateAutoCompleteMembers (frame,
partial_member_name,
@@ -600,13 +626,13 @@ PrivateAutoCompleteMembers (StackFrame *frame,
}
}
- const uint32_t num_vbases = clang_type.GetNumVirtualBaseClasses();
+ const uint32_t num_vbases = compiler_type.GetNumVirtualBaseClasses();
if (num_vbases > 0)
{
for (uint32_t i = 0; i < num_vbases; ++i)
{
- ClangASTType vbase_class_type (clang_type.GetVirtualBaseClassAtIndex(i,nullptr));
+ CompilerType vbase_class_type = compiler_type.GetVirtualBaseClassAtIndex(i,nullptr);
PrivateAutoCompleteMembers (frame,
partial_member_name,
@@ -619,7 +645,7 @@ PrivateAutoCompleteMembers (StackFrame *frame,
}
// We are in a type parsing child members
- const uint32_t num_fields = clang_type.GetNumFields();
+ const uint32_t num_fields = compiler_type.GetNumFields();
if (num_fields > 0)
{
@@ -627,7 +653,7 @@ PrivateAutoCompleteMembers (StackFrame *frame,
{
std::string member_name;
- ClangASTType member_clang_type = clang_type.GetFieldAtIndex (i, member_name, nullptr, nullptr, nullptr);
+ CompilerType member_compiler_type = compiler_type.GetFieldAtIndex (i, member_name, nullptr, nullptr, nullptr);
if (partial_member_name.empty() ||
member_name.find(partial_member_name) == 0)
@@ -637,7 +663,7 @@ PrivateAutoCompleteMembers (StackFrame *frame,
PrivateAutoComplete (frame,
partial_path,
prefix_path + member_name, // Anything that has been resolved already will be in here
- member_clang_type.GetCanonicalType(),
+ member_compiler_type.GetCanonicalType(),
matches,
word_complete);
}
@@ -654,17 +680,17 @@ static void
PrivateAutoComplete (StackFrame *frame,
const std::string &partial_path,
const std::string &prefix_path, // Anything that has been resolved already will be in here
- const ClangASTType& clang_type,
+ const CompilerType& compiler_type,
StringList &matches,
bool &word_complete)
{
// printf ("\nPrivateAutoComplete()\n\tprefix_path = '%s'\n\tpartial_path = '%s'\n", prefix_path.c_str(), partial_path.c_str());
std::string remaining_partial_path;
- const lldb::TypeClass type_class = clang_type.GetTypeClass();
+ const lldb::TypeClass type_class = compiler_type.GetTypeClass();
if (partial_path.empty())
{
- if (clang_type.IsValid())
+ if (compiler_type.IsValid())
{
switch (type_class)
{
@@ -700,7 +726,7 @@ PrivateAutoComplete (StackFrame *frame,
case eTypeClassPointer:
{
bool omit_empty_base_classes = true;
- if (clang_type.GetNumChildren (omit_empty_base_classes) > 0)
+ if (compiler_type.GetNumChildren (omit_empty_base_classes) > 0)
matches.AppendString (prefix_path + "->");
else
{
@@ -742,7 +768,7 @@ PrivateAutoComplete (StackFrame *frame,
PrivateAutoComplete (frame,
partial_path.substr(1),
std::string("*"),
- clang_type,
+ compiler_type,
matches,
word_complete);
}
@@ -754,7 +780,7 @@ PrivateAutoComplete (StackFrame *frame,
PrivateAutoComplete (frame,
partial_path.substr(1),
std::string("&"),
- clang_type,
+ compiler_type,
matches,
word_complete);
}
@@ -767,7 +793,7 @@ PrivateAutoComplete (StackFrame *frame,
{
case lldb::eTypeClassPointer:
{
- ClangASTType pointee_type(clang_type.GetPointeeType());
+ CompilerType pointee_type(compiler_type.GetPointeeType());
if (partial_path[2])
{
// If there is more after the "->", then search deeper
@@ -797,7 +823,7 @@ PrivateAutoComplete (StackFrame *frame,
break;
case '.':
- if (clang_type.IsValid())
+ if (compiler_type.IsValid())
{
switch (type_class)
{
@@ -810,7 +836,7 @@ PrivateAutoComplete (StackFrame *frame,
PrivateAutoComplete (frame,
partial_path.substr(1),
prefix_path + ".",
- clang_type,
+ compiler_type,
matches,
word_complete);
@@ -822,7 +848,7 @@ PrivateAutoComplete (StackFrame *frame,
std::string(),
partial_path,
prefix_path + ".",
- clang_type,
+ compiler_type,
matches,
word_complete);
}
@@ -850,13 +876,13 @@ PrivateAutoComplete (StackFrame *frame,
std::string token(partial_path, 0, pos);
remaining_partial_path = partial_path.substr(pos);
- if (clang_type.IsValid())
+ if (compiler_type.IsValid())
{
PrivateAutoCompleteMembers (frame,
token,
remaining_partial_path,
prefix_path,
- clang_type,
+ compiler_type,
matches,
word_complete);
}
@@ -886,11 +912,11 @@ PrivateAutoComplete (StackFrame *frame,
Type *variable_type = variable->GetType();
if (variable_type)
{
- ClangASTType variable_clang_type (variable_type->GetClangForwardType());
+ CompilerType variable_compiler_type (variable_type->GetForwardCompilerType ());
PrivateAutoComplete (frame,
remaining_partial_path,
prefix_path + token, // Anything that has been resolved already will be in here
- variable_clang_type.GetCanonicalType(),
+ variable_compiler_type.GetCanonicalType(),
matches,
word_complete);
}
@@ -923,14 +949,14 @@ Variable::AutoComplete (const ExecutionContext &exe_ctx,
word_complete = false;
std::string partial_path;
std::string prefix_path;
- ClangASTType clang_type;
+ CompilerType compiler_type;
if (partial_path_cstr && partial_path_cstr[0])
partial_path = partial_path_cstr;
PrivateAutoComplete (exe_ctx.GetFramePtr(),
partial_path,
prefix_path,
- clang_type,
+ compiler_type,
matches,
word_complete);
diff --git a/source/Symbol/VariableList.cpp b/source/Symbol/VariableList.cpp
index 75eb8700c9ff0..487c57194346f 100644
--- a/source/Symbol/VariableList.cpp
+++ b/source/Symbol/VariableList.cpp
@@ -100,7 +100,7 @@ VariableList::FindVariableIndex (const VariableSP &var_sp)
}
VariableSP
-VariableList::FindVariable(const ConstString& name)
+VariableList::FindVariable(const ConstString& name, bool include_static_members)
{
VariableSP var_sp;
iterator pos, end = m_variables.end();
@@ -108,15 +108,18 @@ VariableList::FindVariable(const ConstString& name)
{
if ((*pos)->NameMatches(name))
{
- var_sp = (*pos);
- break;
+ if (include_static_members || !(*pos)->IsStaticMember())
+ {
+ var_sp = (*pos);
+ break;
+ }
}
}
return var_sp;
}
VariableSP
-VariableList::FindVariable (const ConstString& name, lldb::ValueType value_type)
+VariableList::FindVariable (const ConstString& name, lldb::ValueType value_type, bool include_static_members)
{
VariableSP var_sp;
iterator pos, end = m_variables.end();
@@ -124,8 +127,11 @@ VariableList::FindVariable (const ConstString& name, lldb::ValueType value_type)
{
if ((*pos)->NameMatches(name) && (*pos)->GetScope() == value_type)
{
- var_sp = (*pos);
- break;
+ if (include_static_members || !(*pos)->IsStaticMember())
+ {
+ var_sp = (*pos);
+ break;
+ }
}
}
return var_sp;