Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 1 | //===-- GoASTContext.cpp ----------------------------------------*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #include <mutex> |
| 11 | #include <utility> |
| 12 | #include <vector> |
| 13 | |
Greg Clayton | 56939cb | 2015-09-17 22:23:34 +0000 | [diff] [blame] | 14 | #include "lldb/Core/Module.h" |
| 15 | #include "lldb/Core/PluginManager.h" |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 16 | #include "lldb/Core/UniqueCStringMap.h" |
| 17 | #include "lldb/Core/ValueObject.h" |
| 18 | #include "lldb/DataFormatters/StringPrinter.h" |
| 19 | #include "lldb/Symbol/CompilerType.h" |
Greg Clayton | 56939cb | 2015-09-17 22:23:34 +0000 | [diff] [blame] | 20 | #include "lldb/Symbol/ObjectFile.h" |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 21 | #include "lldb/Symbol/SymbolFile.h" |
| 22 | #include "lldb/Symbol/GoASTContext.h" |
| 23 | #include "lldb/Symbol/Type.h" |
| 24 | #include "lldb/Target/ExecutionContext.h" |
Greg Clayton | 5beec21 | 2015-10-08 21:04:34 +0000 | [diff] [blame] | 25 | #include "lldb/Target/Target.h" |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 26 | |
| 27 | #include "Plugins/SymbolFile/DWARF/DWARFASTParserGo.h" |
| 28 | |
| 29 | using namespace lldb; |
| 30 | |
| 31 | namespace lldb_private |
| 32 | { |
| 33 | class GoArray; |
| 34 | class GoFunction; |
| 35 | class GoStruct; |
| 36 | |
| 37 | class GoType |
| 38 | { |
| 39 | public: |
| 40 | enum |
| 41 | { |
| 42 | KIND_BOOL = 1, |
| 43 | KIND_INT = 2, |
| 44 | KIND_INT8 = 3, |
| 45 | KIND_INT16 = 4, |
| 46 | KIND_INT32 = 5, |
| 47 | KIND_INT64 = 6, |
| 48 | KIND_UINT = 7, |
| 49 | KIND_UINT8 = 8, |
| 50 | KIND_UINT16 = 9, |
| 51 | KIND_UINT32 = 10, |
| 52 | KIND_UINT64 = 11, |
| 53 | KIND_UINTPTR = 12, |
| 54 | KIND_FLOAT32 = 13, |
| 55 | KIND_FLOAT64 = 14, |
| 56 | KIND_COMPLEX64 = 15, |
| 57 | KIND_COMPLEX128 = 16, |
| 58 | KIND_ARRAY = 17, |
| 59 | KIND_CHAN = 18, |
| 60 | KIND_FUNC = 19, |
| 61 | KIND_INTERFACE = 20, |
| 62 | KIND_MAP = 21, |
| 63 | KIND_PTR = 22, |
| 64 | KIND_SLICE = 23, |
| 65 | KIND_STRING = 24, |
| 66 | KIND_STRUCT = 25, |
| 67 | KIND_UNSAFEPOINTER = 26, |
| 68 | KIND_LLDB_VOID, // Extension for LLDB, not used by go runtime. |
| 69 | KIND_MASK = (1 << 5) - 1, |
| 70 | KIND_DIRECT_IFACE = 1 << 5 |
| 71 | }; |
| 72 | GoType(int kind, const ConstString &name) |
| 73 | : m_kind(kind & KIND_MASK) |
| 74 | , m_name(name) |
| 75 | { |
| 76 | if (m_kind == KIND_FUNC) |
| 77 | m_kind = KIND_FUNC; |
| 78 | } |
| 79 | virtual ~GoType() {} |
| 80 | |
| 81 | int |
| 82 | GetGoKind() const |
| 83 | { |
| 84 | return m_kind; |
| 85 | } |
| 86 | const ConstString & |
| 87 | GetName() const |
| 88 | { |
| 89 | return m_name; |
| 90 | } |
| 91 | virtual CompilerType |
| 92 | GetElementType() const |
| 93 | { |
| 94 | return CompilerType(); |
| 95 | } |
| 96 | |
| 97 | bool |
| 98 | IsTypedef() const |
| 99 | { |
| 100 | switch (m_kind) |
| 101 | { |
| 102 | case KIND_CHAN: |
| 103 | case KIND_MAP: |
| 104 | case KIND_INTERFACE: |
| 105 | return true; |
| 106 | default: |
| 107 | return false; |
| 108 | } |
| 109 | } |
| 110 | |
| 111 | GoArray *GetArray(); |
| 112 | GoFunction *GetFunction(); |
| 113 | GoStruct *GetStruct(); |
| 114 | |
| 115 | private: |
| 116 | int m_kind; |
| 117 | ConstString m_name; |
| 118 | GoType(const GoType &) = delete; |
| 119 | const GoType &operator=(const GoType &) = delete; |
| 120 | }; |
| 121 | |
| 122 | class GoElem : public GoType |
| 123 | { |
| 124 | public: |
| 125 | GoElem(int kind, const ConstString &name, const CompilerType &elem) |
| 126 | : GoType(kind, name) |
| 127 | , m_elem(elem) |
| 128 | { |
| 129 | } |
| 130 | virtual CompilerType |
| 131 | GetElementType() const |
| 132 | { |
| 133 | return m_elem; |
| 134 | } |
| 135 | |
| 136 | private: |
| 137 | // TODO: should we store this differently? |
| 138 | CompilerType m_elem; |
| 139 | |
| 140 | GoElem(const GoElem &) = delete; |
| 141 | const GoElem &operator=(const GoElem &) = delete; |
| 142 | }; |
| 143 | |
| 144 | class GoArray : public GoElem |
| 145 | { |
| 146 | public: |
Bruce Mitchener | 500737e | 2015-09-15 04:33:48 +0000 | [diff] [blame] | 147 | GoArray(const ConstString &name, uint64_t length, const CompilerType &elem) |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 148 | : GoElem(KIND_ARRAY, name, elem) |
| 149 | , m_length(length) |
| 150 | { |
| 151 | } |
| 152 | |
Bruce Mitchener | 500737e | 2015-09-15 04:33:48 +0000 | [diff] [blame] | 153 | uint64_t |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 154 | GetLength() const |
| 155 | { |
| 156 | return m_length; |
| 157 | } |
| 158 | |
| 159 | private: |
Bruce Mitchener | 500737e | 2015-09-15 04:33:48 +0000 | [diff] [blame] | 160 | uint64_t m_length; |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 161 | GoArray(const GoArray &) = delete; |
| 162 | const GoArray &operator=(const GoArray &) = delete; |
| 163 | }; |
| 164 | |
| 165 | class GoFunction : public GoType |
| 166 | { |
| 167 | public: |
| 168 | GoFunction(const ConstString &name, bool is_variadic) |
| 169 | : GoType(KIND_FUNC, name) |
| 170 | , m_is_variadic(is_variadic) |
| 171 | { |
| 172 | } |
| 173 | |
| 174 | bool |
| 175 | IsVariadic() const |
| 176 | { |
| 177 | return m_is_variadic; |
| 178 | } |
| 179 | |
| 180 | private: |
| 181 | bool m_is_variadic; |
| 182 | GoFunction(const GoFunction &) = delete; |
| 183 | const GoFunction &operator=(const GoFunction &) = delete; |
| 184 | }; |
| 185 | |
| 186 | class GoStruct : public GoType |
| 187 | { |
| 188 | public: |
| 189 | struct Field |
| 190 | { |
| 191 | Field(const ConstString &name, const CompilerType &type, uint64_t offset) |
| 192 | : m_name(name) |
| 193 | , m_type(type) |
| 194 | , m_byte_offset(offset) |
| 195 | { |
| 196 | } |
| 197 | ConstString m_name; |
| 198 | CompilerType m_type; |
| 199 | uint64_t m_byte_offset; |
| 200 | }; |
| 201 | |
| 202 | GoStruct(int kind, const ConstString &name, int64_t byte_size) |
| 203 | : GoType(kind, name) |
| 204 | , m_is_complete(false) |
| 205 | , m_byte_size(byte_size) |
| 206 | { |
| 207 | } |
| 208 | |
| 209 | uint32_t |
| 210 | GetNumFields() const |
| 211 | { |
| 212 | return m_fields.size(); |
| 213 | } |
| 214 | |
| 215 | const Field * |
| 216 | GetField(uint32_t i) const |
| 217 | { |
| 218 | if (i < m_fields.size()) |
| 219 | return &m_fields[i]; |
| 220 | return nullptr; |
| 221 | } |
| 222 | |
| 223 | void |
| 224 | AddField(const ConstString &name, const CompilerType &type, uint64_t offset) |
| 225 | { |
| 226 | m_fields.push_back(Field(name, type, offset)); |
| 227 | } |
| 228 | |
| 229 | bool |
| 230 | IsComplete() const |
| 231 | { |
| 232 | return m_is_complete; |
| 233 | } |
| 234 | |
| 235 | void |
| 236 | SetComplete() |
| 237 | { |
| 238 | m_is_complete = true; |
| 239 | } |
| 240 | |
| 241 | int64_t |
| 242 | GetByteSize() const |
| 243 | { |
| 244 | return m_byte_size; |
| 245 | } |
| 246 | |
| 247 | private: |
| 248 | bool m_is_complete; |
| 249 | int64_t m_byte_size; |
| 250 | std::vector<Field> m_fields; |
| 251 | |
| 252 | GoStruct(const GoStruct &) = delete; |
| 253 | const GoStruct &operator=(const GoStruct &) = delete; |
| 254 | }; |
| 255 | |
| 256 | GoArray * |
| 257 | GoType::GetArray() |
| 258 | { |
| 259 | if (m_kind == KIND_ARRAY) |
| 260 | { |
| 261 | return static_cast<GoArray *>(this); |
| 262 | } |
| 263 | return nullptr; |
| 264 | } |
| 265 | |
| 266 | GoFunction * |
| 267 | GoType::GetFunction() |
| 268 | { |
| 269 | if (m_kind == KIND_FUNC) |
| 270 | { |
| 271 | return static_cast<GoFunction *>(this); |
| 272 | } |
| 273 | return nullptr; |
| 274 | } |
| 275 | |
| 276 | GoStruct * |
| 277 | GoType::GetStruct() |
| 278 | { |
| 279 | switch (m_kind) |
| 280 | { |
| 281 | case KIND_STRING: |
| 282 | case KIND_STRUCT: |
| 283 | case KIND_SLICE: |
| 284 | return static_cast<GoStruct *>(this); |
| 285 | } |
| 286 | return nullptr; |
| 287 | } |
| 288 | } // namespace lldb_private |
| 289 | using namespace lldb_private; |
| 290 | |
| 291 | GoASTContext::GoASTContext() |
| 292 | : TypeSystem(eKindGo) |
| 293 | , m_pointer_byte_size(0) |
| 294 | , m_int_byte_size(0) |
| 295 | , m_types(new TypeMap) |
| 296 | { |
| 297 | } |
| 298 | GoASTContext::~GoASTContext() |
| 299 | { |
| 300 | } |
| 301 | |
Greg Clayton | 56939cb | 2015-09-17 22:23:34 +0000 | [diff] [blame] | 302 | //------------------------------------------------------------------ |
| 303 | // PluginInterface functions |
| 304 | //------------------------------------------------------------------ |
| 305 | |
| 306 | ConstString |
| 307 | GoASTContext::GetPluginNameStatic() |
| 308 | { |
| 309 | return ConstString("go"); |
| 310 | } |
| 311 | |
| 312 | ConstString |
| 313 | GoASTContext::GetPluginName() |
| 314 | { |
| 315 | return GoASTContext::GetPluginNameStatic(); |
| 316 | } |
| 317 | |
| 318 | uint32_t |
| 319 | GoASTContext::GetPluginVersion() |
| 320 | { |
| 321 | return 1; |
| 322 | } |
| 323 | |
| 324 | lldb::TypeSystemSP |
Greg Clayton | 5beec21 | 2015-10-08 21:04:34 +0000 | [diff] [blame] | 325 | GoASTContext::CreateInstance (lldb::LanguageType language, Module *module, Target *target) |
Greg Clayton | 56939cb | 2015-09-17 22:23:34 +0000 | [diff] [blame] | 326 | { |
| 327 | if (language == eLanguageTypeGo) |
| 328 | { |
Greg Clayton | 5beec21 | 2015-10-08 21:04:34 +0000 | [diff] [blame] | 329 | ArchSpec arch; |
| 330 | if (module) |
| 331 | arch = module->GetArchitecture(); |
| 332 | else if (target) |
| 333 | arch = target->GetArchitecture(); |
| 334 | |
Greg Clayton | 56939cb | 2015-09-17 22:23:34 +0000 | [diff] [blame] | 335 | if (arch.IsValid()) |
| 336 | { |
| 337 | std::shared_ptr<GoASTContext> go_ast_sp(new GoASTContext); |
| 338 | go_ast_sp->SetAddressByteSize(arch.GetAddressByteSize()); |
| 339 | return go_ast_sp; |
| 340 | } |
| 341 | } |
| 342 | return lldb::TypeSystemSP(); |
| 343 | } |
| 344 | |
Sean Callanan | fe38c85 | 2015-10-08 23:07:53 +0000 | [diff] [blame^] | 345 | void |
| 346 | GoASTContext::EnumerateSupportedLanguages(std::set<lldb::LanguageType> &languages_for_types, std::set<lldb::LanguageType> &languages_for_expressions) |
| 347 | { |
| 348 | static std::vector<lldb::LanguageType> s_supported_languages_for_types({ |
| 349 | lldb::eLanguageTypeGo}); |
| 350 | |
| 351 | static std::vector<lldb::LanguageType> s_supported_languages_for_expressions({}); |
| 352 | |
| 353 | languages_for_types.insert(s_supported_languages_for_types.begin(), s_supported_languages_for_types.end()); |
| 354 | languages_for_expressions.insert(s_supported_languages_for_expressions.begin(), s_supported_languages_for_expressions.end()); |
| 355 | } |
| 356 | |
Greg Clayton | 56939cb | 2015-09-17 22:23:34 +0000 | [diff] [blame] | 357 | |
| 358 | void |
| 359 | GoASTContext::Initialize() |
| 360 | { |
| 361 | PluginManager::RegisterPlugin (GetPluginNameStatic(), |
| 362 | "AST context plug-in", |
Sean Callanan | fe38c85 | 2015-10-08 23:07:53 +0000 | [diff] [blame^] | 363 | CreateInstance, |
| 364 | EnumerateSupportedLanguages); |
Greg Clayton | 56939cb | 2015-09-17 22:23:34 +0000 | [diff] [blame] | 365 | } |
| 366 | |
| 367 | void |
| 368 | GoASTContext::Terminate() |
| 369 | { |
| 370 | PluginManager::UnregisterPlugin (CreateInstance); |
| 371 | } |
| 372 | |
| 373 | |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 374 | //---------------------------------------------------------------------- |
| 375 | // Tests |
| 376 | //---------------------------------------------------------------------- |
| 377 | |
| 378 | bool |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 379 | GoASTContext::IsArrayType(lldb::opaque_compiler_type_t type, CompilerType *element_type, uint64_t *size, bool *is_incomplete) |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 380 | { |
| 381 | if (element_type) |
| 382 | element_type->Clear(); |
| 383 | if (size) |
| 384 | *size = 0; |
| 385 | if (is_incomplete) |
| 386 | *is_incomplete = false; |
| 387 | GoArray *array = static_cast<GoType *>(type)->GetArray(); |
| 388 | if (array) |
| 389 | { |
Bruce Mitchener | 500737e | 2015-09-15 04:33:48 +0000 | [diff] [blame] | 390 | if (size) |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 391 | *size = array->GetLength(); |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 392 | if (element_type) |
| 393 | *element_type = array->GetElementType(); |
| 394 | return true; |
| 395 | } |
| 396 | return false; |
| 397 | } |
| 398 | |
| 399 | bool |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 400 | GoASTContext::IsVectorType(lldb::opaque_compiler_type_t type, CompilerType *element_type, uint64_t *size) |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 401 | { |
| 402 | if (element_type) |
| 403 | element_type->Clear(); |
| 404 | if (size) |
| 405 | *size = 0; |
| 406 | return false; |
| 407 | } |
| 408 | |
| 409 | bool |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 410 | GoASTContext::IsAggregateType(lldb::opaque_compiler_type_t type) |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 411 | { |
| 412 | int kind = static_cast<GoType *>(type)->GetGoKind(); |
| 413 | if (kind < GoType::KIND_ARRAY) |
| 414 | return false; |
| 415 | if (kind == GoType::KIND_PTR) |
| 416 | return false; |
| 417 | if (kind == GoType::KIND_STRING) |
| 418 | return false; |
| 419 | if (kind == GoType::KIND_UNSAFEPOINTER) |
| 420 | return false; |
| 421 | return true; |
| 422 | } |
| 423 | |
| 424 | bool |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 425 | GoASTContext::IsBeingDefined(lldb::opaque_compiler_type_t type) |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 426 | { |
| 427 | return false; |
| 428 | } |
| 429 | |
| 430 | bool |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 431 | GoASTContext::IsCharType(lldb::opaque_compiler_type_t type) |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 432 | { |
| 433 | // Go's DWARF doesn't distinguish between rune and int32. |
| 434 | return false; |
| 435 | } |
| 436 | |
| 437 | bool |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 438 | GoASTContext::IsCompleteType(lldb::opaque_compiler_type_t type) |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 439 | { |
| 440 | if (!type) |
| 441 | return false; |
| 442 | GoType *t = static_cast<GoType *>(type); |
| 443 | if (GoStruct *s = t->GetStruct()) |
| 444 | return s->IsComplete(); |
| 445 | if (t->IsTypedef() || t->GetGoKind() == GoType::KIND_PTR) |
| 446 | return t->GetElementType().IsCompleteType(); |
| 447 | return true; |
| 448 | } |
| 449 | |
| 450 | bool |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 451 | GoASTContext::IsConst(lldb::opaque_compiler_type_t type) |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 452 | { |
| 453 | return false; |
| 454 | } |
| 455 | |
| 456 | bool |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 457 | GoASTContext::IsCStringType(lldb::opaque_compiler_type_t type, uint32_t &length) |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 458 | { |
| 459 | return false; |
| 460 | } |
| 461 | |
| 462 | bool |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 463 | GoASTContext::IsDefined(lldb::opaque_compiler_type_t type) |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 464 | { |
| 465 | return type != nullptr; |
| 466 | } |
| 467 | |
| 468 | bool |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 469 | GoASTContext::IsFloatingPointType(lldb::opaque_compiler_type_t type, uint32_t &count, bool &is_complex) |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 470 | { |
| 471 | int kind = static_cast<GoType *>(type)->GetGoKind(); |
| 472 | if (kind >= GoType::KIND_FLOAT32 && kind <= GoType::KIND_COMPLEX128) |
| 473 | { |
| 474 | if (kind >= GoType::KIND_COMPLEX64) |
| 475 | { |
| 476 | is_complex = true; |
| 477 | count = 2; |
| 478 | } |
| 479 | else |
| 480 | { |
| 481 | is_complex = false; |
| 482 | count = 1; |
| 483 | } |
| 484 | return true; |
| 485 | } |
| 486 | count = 0; |
| 487 | is_complex = false; |
| 488 | return false; |
| 489 | } |
| 490 | |
| 491 | bool |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 492 | GoASTContext::IsFunctionType(lldb::opaque_compiler_type_t type, bool *is_variadic_ptr) |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 493 | { |
| 494 | GoFunction *func = static_cast<GoType *>(type)->GetFunction(); |
| 495 | if (func) |
| 496 | { |
| 497 | if (is_variadic_ptr) |
| 498 | *is_variadic_ptr = func->IsVariadic(); |
| 499 | return true; |
| 500 | } |
| 501 | if (is_variadic_ptr) |
| 502 | *is_variadic_ptr = false; |
| 503 | return false; |
| 504 | } |
| 505 | |
| 506 | uint32_t |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 507 | GoASTContext::IsHomogeneousAggregate(lldb::opaque_compiler_type_t type, CompilerType *base_type_ptr) |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 508 | { |
| 509 | return false; |
| 510 | } |
| 511 | |
| 512 | size_t |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 513 | GoASTContext::GetNumberOfFunctionArguments(lldb::opaque_compiler_type_t type) |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 514 | { |
| 515 | return 0; |
| 516 | } |
| 517 | |
| 518 | CompilerType |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 519 | GoASTContext::GetFunctionArgumentAtIndex(lldb::opaque_compiler_type_t type, const size_t index) |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 520 | { |
| 521 | return CompilerType(); |
| 522 | } |
| 523 | |
| 524 | bool |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 525 | GoASTContext::IsFunctionPointerType(lldb::opaque_compiler_type_t type) |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 526 | { |
| 527 | return IsFunctionType(type); |
| 528 | } |
| 529 | |
| 530 | bool |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 531 | GoASTContext::IsIntegerType(lldb::opaque_compiler_type_t type, bool &is_signed) |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 532 | { |
| 533 | is_signed = false; |
| 534 | // TODO: Is bool an integer? |
| 535 | if (type) |
| 536 | { |
| 537 | int kind = static_cast<GoType *>(type)->GetGoKind(); |
| 538 | if (kind <= GoType::KIND_UINTPTR) |
| 539 | { |
| 540 | is_signed = (kind != GoType::KIND_BOOL) & (kind <= GoType::KIND_INT64); |
| 541 | return true; |
| 542 | } |
| 543 | } |
| 544 | return false; |
| 545 | } |
| 546 | |
| 547 | bool |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 548 | GoASTContext::IsPolymorphicClass(lldb::opaque_compiler_type_t type) |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 549 | { |
| 550 | return false; |
| 551 | } |
| 552 | |
| 553 | bool |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 554 | GoASTContext::IsPossibleDynamicType(lldb::opaque_compiler_type_t type, |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 555 | CompilerType *target_type, // Can pass NULL |
| 556 | bool check_cplusplus, bool check_objc) |
| 557 | { |
| 558 | if (target_type) |
| 559 | target_type->Clear(); |
| 560 | if (type) |
| 561 | return static_cast<GoType *>(type)->GetGoKind() == GoType::KIND_INTERFACE; |
| 562 | return false; |
| 563 | } |
| 564 | |
| 565 | bool |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 566 | GoASTContext::IsRuntimeGeneratedType(lldb::opaque_compiler_type_t type) |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 567 | { |
| 568 | return false; |
| 569 | } |
| 570 | |
| 571 | bool |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 572 | GoASTContext::IsPointerType(lldb::opaque_compiler_type_t type, CompilerType *pointee_type) |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 573 | { |
| 574 | if (!type) |
| 575 | return false; |
| 576 | GoType *t = static_cast<GoType *>(type); |
| 577 | if (pointee_type) |
| 578 | { |
| 579 | *pointee_type = t->GetElementType(); |
| 580 | } |
| 581 | switch (t->GetGoKind()) |
| 582 | { |
| 583 | case GoType::KIND_PTR: |
| 584 | case GoType::KIND_UNSAFEPOINTER: |
| 585 | case GoType::KIND_CHAN: |
| 586 | // TODO: is map a pointer? string? function? |
| 587 | return true; |
| 588 | default: |
| 589 | return false; |
| 590 | } |
| 591 | } |
| 592 | |
| 593 | bool |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 594 | GoASTContext::IsPointerOrReferenceType(lldb::opaque_compiler_type_t type, CompilerType *pointee_type) |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 595 | { |
| 596 | return IsPointerType(type, pointee_type); |
| 597 | } |
| 598 | |
| 599 | bool |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 600 | GoASTContext::IsReferenceType(lldb::opaque_compiler_type_t type, CompilerType *pointee_type, bool *is_rvalue) |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 601 | { |
| 602 | return false; |
| 603 | } |
| 604 | |
| 605 | bool |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 606 | GoASTContext::IsScalarType(lldb::opaque_compiler_type_t type) |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 607 | { |
| 608 | return !IsAggregateType(type); |
| 609 | } |
| 610 | |
| 611 | bool |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 612 | GoASTContext::IsTypedefType(lldb::opaque_compiler_type_t type) |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 613 | { |
| 614 | if (type) |
| 615 | return static_cast<GoType *>(type)->IsTypedef(); |
| 616 | return false; |
| 617 | } |
| 618 | |
| 619 | bool |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 620 | GoASTContext::IsVoidType(lldb::opaque_compiler_type_t type) |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 621 | { |
| 622 | if (!type) |
| 623 | return false; |
| 624 | return static_cast<GoType *>(type)->GetGoKind() == GoType::KIND_LLDB_VOID; |
| 625 | } |
| 626 | |
Greg Clayton | 56939cb | 2015-09-17 22:23:34 +0000 | [diff] [blame] | 627 | bool |
| 628 | GoASTContext::SupportsLanguage (lldb::LanguageType language) |
| 629 | { |
| 630 | return language == eLanguageTypeGo; |
| 631 | } |
| 632 | |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 633 | //---------------------------------------------------------------------- |
| 634 | // Type Completion |
| 635 | //---------------------------------------------------------------------- |
| 636 | |
| 637 | bool |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 638 | GoASTContext::GetCompleteType(lldb::opaque_compiler_type_t type) |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 639 | { |
| 640 | if (!type) |
| 641 | return false; |
| 642 | GoType *t = static_cast<GoType *>(type); |
| 643 | if (t->IsTypedef() || t->GetGoKind() == GoType::KIND_PTR || t->GetArray()) |
| 644 | return t->GetElementType().GetCompleteType(); |
| 645 | if (GoStruct *s = t->GetStruct()) |
| 646 | { |
| 647 | if (s->IsComplete()) |
| 648 | return true; |
| 649 | CompilerType compiler_type(this, s); |
| 650 | SymbolFile *symbols = GetSymbolFile(); |
| 651 | return symbols && symbols->CompleteType(compiler_type); |
| 652 | } |
| 653 | return true; |
| 654 | } |
| 655 | |
| 656 | //---------------------------------------------------------------------- |
| 657 | // AST related queries |
| 658 | //---------------------------------------------------------------------- |
| 659 | |
| 660 | uint32_t |
| 661 | GoASTContext::GetPointerByteSize() |
| 662 | { |
| 663 | return m_pointer_byte_size; |
| 664 | } |
| 665 | |
| 666 | //---------------------------------------------------------------------- |
| 667 | // Accessors |
| 668 | //---------------------------------------------------------------------- |
| 669 | |
| 670 | ConstString |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 671 | GoASTContext::GetTypeName(lldb::opaque_compiler_type_t type) |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 672 | { |
| 673 | if (type) |
| 674 | return static_cast<GoType *>(type)->GetName(); |
| 675 | return ConstString(); |
| 676 | } |
| 677 | |
| 678 | uint32_t |
Bruce Mitchener | 3ad353f | 2015-09-24 03:54:50 +0000 | [diff] [blame] | 679 | GoASTContext::GetTypeInfo(lldb::opaque_compiler_type_t type, CompilerType *pointee_or_element_compiler_type) |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 680 | { |
Bruce Mitchener | 3ad353f | 2015-09-24 03:54:50 +0000 | [diff] [blame] | 681 | if (pointee_or_element_compiler_type) |
| 682 | pointee_or_element_compiler_type->Clear(); |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 683 | if (!type) |
| 684 | return 0; |
| 685 | GoType *t = static_cast<GoType *>(type); |
Bruce Mitchener | 3ad353f | 2015-09-24 03:54:50 +0000 | [diff] [blame] | 686 | if (pointee_or_element_compiler_type) |
| 687 | *pointee_or_element_compiler_type = t->GetElementType(); |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 688 | int kind = t->GetGoKind(); |
| 689 | if (kind == GoType::KIND_ARRAY) |
| 690 | return eTypeHasChildren | eTypeIsArray; |
| 691 | if (kind < GoType::KIND_ARRAY) |
| 692 | { |
| 693 | uint32_t builtin_type_flags = eTypeIsBuiltIn | eTypeHasValue; |
| 694 | if (kind < GoType::KIND_FLOAT32) |
| 695 | { |
| 696 | builtin_type_flags |= eTypeIsInteger | eTypeIsScalar; |
| 697 | if (kind >= GoType::KIND_INT && kind <= GoType::KIND_INT64) |
| 698 | builtin_type_flags |= eTypeIsSigned; |
| 699 | } |
| 700 | else |
| 701 | { |
| 702 | builtin_type_flags |= eTypeIsFloat; |
| 703 | if (kind < GoType::KIND_COMPLEX64) |
| 704 | builtin_type_flags |= eTypeIsComplex; |
| 705 | else |
| 706 | builtin_type_flags |= eTypeIsScalar; |
| 707 | } |
| 708 | return builtin_type_flags; |
| 709 | } |
| 710 | if (kind == GoType::KIND_STRING) |
| 711 | return eTypeHasValue | eTypeIsBuiltIn; |
| 712 | if (kind == GoType::KIND_FUNC) |
| 713 | return eTypeIsFuncPrototype | eTypeHasValue; |
| 714 | if (IsPointerType(type)) |
| 715 | return eTypeIsPointer | eTypeHasValue | eTypeHasChildren; |
| 716 | if (kind == GoType::KIND_LLDB_VOID) |
| 717 | return 0; |
| 718 | return eTypeHasChildren | eTypeIsStructUnion; |
| 719 | } |
| 720 | |
| 721 | lldb::TypeClass |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 722 | GoASTContext::GetTypeClass(lldb::opaque_compiler_type_t type) |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 723 | { |
| 724 | if (!type) |
| 725 | return eTypeClassInvalid; |
| 726 | int kind = static_cast<GoType *>(type)->GetGoKind(); |
| 727 | if (kind == GoType::KIND_FUNC) |
| 728 | return eTypeClassFunction; |
| 729 | if (IsPointerType(type)) |
| 730 | return eTypeClassPointer; |
| 731 | if (kind < GoType::KIND_COMPLEX64) |
| 732 | return eTypeClassBuiltin; |
| 733 | if (kind <= GoType::KIND_COMPLEX128) |
| 734 | return eTypeClassComplexFloat; |
| 735 | if (kind == GoType::KIND_LLDB_VOID) |
| 736 | return eTypeClassInvalid; |
| 737 | return eTypeClassStruct; |
| 738 | } |
| 739 | |
| 740 | lldb::BasicType |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 741 | GoASTContext::GetBasicTypeEnumeration(lldb::opaque_compiler_type_t type) |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 742 | { |
| 743 | ConstString name = GetTypeName(type); |
| 744 | if (name) |
| 745 | { |
| 746 | typedef UniqueCStringMap<lldb::BasicType> TypeNameToBasicTypeMap; |
| 747 | static TypeNameToBasicTypeMap g_type_map; |
| 748 | static std::once_flag g_once_flag; |
| 749 | std::call_once(g_once_flag, [](){ |
| 750 | // "void" |
| 751 | g_type_map.Append(ConstString("void").GetCString(), eBasicTypeVoid); |
| 752 | // "int" |
| 753 | g_type_map.Append(ConstString("int").GetCString(), eBasicTypeInt); |
| 754 | g_type_map.Append(ConstString("uint").GetCString(), eBasicTypeUnsignedInt); |
| 755 | |
| 756 | // Miscellaneous |
| 757 | g_type_map.Append(ConstString("bool").GetCString(), eBasicTypeBool); |
| 758 | |
| 759 | // Others. Should these map to C types? |
| 760 | g_type_map.Append(ConstString("byte").GetCString(), eBasicTypeOther); |
| 761 | g_type_map.Append(ConstString("uint8").GetCString(), eBasicTypeOther); |
| 762 | g_type_map.Append(ConstString("uint16").GetCString(), eBasicTypeOther); |
| 763 | g_type_map.Append(ConstString("uint32").GetCString(), eBasicTypeOther); |
| 764 | g_type_map.Append(ConstString("uint64").GetCString(), eBasicTypeOther); |
| 765 | g_type_map.Append(ConstString("int8").GetCString(), eBasicTypeOther); |
| 766 | g_type_map.Append(ConstString("int16").GetCString(), eBasicTypeOther); |
| 767 | g_type_map.Append(ConstString("int32").GetCString(), eBasicTypeOther); |
| 768 | g_type_map.Append(ConstString("int64").GetCString(), eBasicTypeOther); |
| 769 | g_type_map.Append(ConstString("float32").GetCString(), eBasicTypeOther); |
| 770 | g_type_map.Append(ConstString("float64").GetCString(), eBasicTypeOther); |
| 771 | g_type_map.Append(ConstString("uintptr").GetCString(), eBasicTypeOther); |
| 772 | |
| 773 | g_type_map.Sort(); |
| 774 | }); |
| 775 | |
| 776 | return g_type_map.Find(name.GetCString(), eBasicTypeInvalid); |
| 777 | } |
| 778 | return eBasicTypeInvalid; |
| 779 | } |
| 780 | |
| 781 | lldb::LanguageType |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 782 | GoASTContext::GetMinimumLanguage(lldb::opaque_compiler_type_t type) |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 783 | { |
| 784 | return lldb::eLanguageTypeGo; |
| 785 | } |
| 786 | |
| 787 | unsigned |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 788 | GoASTContext::GetTypeQualifiers(lldb::opaque_compiler_type_t type) |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 789 | { |
| 790 | return 0; |
| 791 | } |
| 792 | |
| 793 | //---------------------------------------------------------------------- |
| 794 | // Creating related types |
| 795 | //---------------------------------------------------------------------- |
| 796 | |
| 797 | CompilerType |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 798 | GoASTContext::GetArrayElementType(lldb::opaque_compiler_type_t type, uint64_t *stride) |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 799 | { |
| 800 | GoArray *array = static_cast<GoType *>(type)->GetArray(); |
| 801 | if (array) |
| 802 | { |
| 803 | if (stride) |
| 804 | { |
| 805 | *stride = array->GetElementType().GetByteSize(nullptr); |
| 806 | } |
| 807 | return array->GetElementType(); |
| 808 | } |
| 809 | return CompilerType(); |
| 810 | } |
| 811 | |
| 812 | CompilerType |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 813 | GoASTContext::GetCanonicalType(lldb::opaque_compiler_type_t type) |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 814 | { |
| 815 | GoType *t = static_cast<GoType *>(type); |
| 816 | if (t->IsTypedef()) |
| 817 | return t->GetElementType(); |
| 818 | return CompilerType(this, type); |
| 819 | } |
| 820 | |
| 821 | CompilerType |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 822 | GoASTContext::GetFullyUnqualifiedType(lldb::opaque_compiler_type_t type) |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 823 | { |
| 824 | return CompilerType(this, type); |
| 825 | } |
| 826 | |
| 827 | // Returns -1 if this isn't a function of if the function doesn't have a prototype |
| 828 | // Returns a value >= 0 if there is a prototype. |
| 829 | int |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 830 | GoASTContext::GetFunctionArgumentCount(lldb::opaque_compiler_type_t type) |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 831 | { |
| 832 | return GetNumberOfFunctionArguments(type); |
| 833 | } |
| 834 | |
| 835 | CompilerType |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 836 | GoASTContext::GetFunctionArgumentTypeAtIndex(lldb::opaque_compiler_type_t type, size_t idx) |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 837 | { |
| 838 | return GetFunctionArgumentAtIndex(type, idx); |
| 839 | } |
| 840 | |
| 841 | CompilerType |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 842 | GoASTContext::GetFunctionReturnType(lldb::opaque_compiler_type_t type) |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 843 | { |
| 844 | CompilerType result; |
| 845 | if (type) |
| 846 | { |
| 847 | GoType *t = static_cast<GoType *>(type); |
| 848 | if (t->GetGoKind() == GoType::KIND_FUNC) |
| 849 | result = t->GetElementType(); |
| 850 | } |
| 851 | return result; |
| 852 | } |
| 853 | |
| 854 | size_t |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 855 | GoASTContext::GetNumMemberFunctions(lldb::opaque_compiler_type_t type) |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 856 | { |
| 857 | return 0; |
| 858 | } |
| 859 | |
| 860 | TypeMemberFunctionImpl |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 861 | GoASTContext::GetMemberFunctionAtIndex(lldb::opaque_compiler_type_t type, size_t idx) |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 862 | { |
| 863 | return TypeMemberFunctionImpl(); |
| 864 | } |
| 865 | |
| 866 | CompilerType |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 867 | GoASTContext::GetNonReferenceType(lldb::opaque_compiler_type_t type) |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 868 | { |
| 869 | return CompilerType(this, type); |
| 870 | } |
| 871 | |
| 872 | CompilerType |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 873 | GoASTContext::GetPointeeType(lldb::opaque_compiler_type_t type) |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 874 | { |
| 875 | if (!type) |
| 876 | return CompilerType(); |
| 877 | return static_cast<GoType *>(type)->GetElementType(); |
| 878 | } |
| 879 | |
| 880 | CompilerType |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 881 | GoASTContext::GetPointerType(lldb::opaque_compiler_type_t type) |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 882 | { |
| 883 | if (!type) |
| 884 | return CompilerType(); |
| 885 | ConstString type_name = GetTypeName(type); |
| 886 | ConstString pointer_name(std::string("*") + type_name.GetCString()); |
| 887 | GoType *pointer = (*m_types)[pointer_name].get(); |
| 888 | if (pointer == nullptr) |
| 889 | { |
| 890 | pointer = new GoElem(GoType::KIND_PTR, pointer_name, CompilerType(this, type)); |
| 891 | (*m_types)[pointer_name].reset(pointer); |
| 892 | } |
| 893 | return CompilerType(this, pointer); |
| 894 | } |
| 895 | |
| 896 | // If the current object represents a typedef type, get the underlying type |
| 897 | CompilerType |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 898 | GoASTContext::GetTypedefedType(lldb::opaque_compiler_type_t type) |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 899 | { |
| 900 | if (IsTypedefType(type)) |
| 901 | return static_cast<GoType *>(type)->GetElementType(); |
| 902 | return CompilerType(); |
| 903 | } |
| 904 | |
| 905 | //---------------------------------------------------------------------- |
| 906 | // Create related types using the current type's AST |
| 907 | //---------------------------------------------------------------------- |
| 908 | CompilerType |
| 909 | GoASTContext::GetBasicTypeFromAST(lldb::BasicType basic_type) |
| 910 | { |
| 911 | return CompilerType(); |
| 912 | } |
| 913 | |
Greg Clayton | 56939cb | 2015-09-17 22:23:34 +0000 | [diff] [blame] | 914 | CompilerType |
| 915 | GoASTContext::GetBuiltinTypeForEncodingAndBitSize (lldb::Encoding encoding, |
| 916 | size_t bit_size) |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 917 | { |
| 918 | return CompilerType(); |
| 919 | } |
| 920 | |
| 921 | |
| 922 | //---------------------------------------------------------------------- |
| 923 | // Exploring the type |
| 924 | //---------------------------------------------------------------------- |
| 925 | |
| 926 | uint64_t |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 927 | GoASTContext::GetBitSize(lldb::opaque_compiler_type_t type, ExecutionContextScope *exe_scope) |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 928 | { |
| 929 | if (!type) |
| 930 | return 0; |
| 931 | if (!GetCompleteType(type)) |
| 932 | return 0; |
| 933 | GoType *t = static_cast<GoType *>(type); |
| 934 | GoArray *array = nullptr; |
| 935 | switch (t->GetGoKind()) |
| 936 | { |
| 937 | case GoType::KIND_BOOL: |
| 938 | case GoType::KIND_INT8: |
| 939 | case GoType::KIND_UINT8: |
| 940 | return 8; |
| 941 | case GoType::KIND_INT16: |
| 942 | case GoType::KIND_UINT16: |
| 943 | return 16; |
| 944 | case GoType::KIND_INT32: |
| 945 | case GoType::KIND_UINT32: |
| 946 | case GoType::KIND_FLOAT32: |
| 947 | return 32; |
| 948 | case GoType::KIND_INT64: |
| 949 | case GoType::KIND_UINT64: |
| 950 | case GoType::KIND_FLOAT64: |
| 951 | case GoType::KIND_COMPLEX64: |
| 952 | return 64; |
| 953 | case GoType::KIND_COMPLEX128: |
| 954 | return 128; |
| 955 | case GoType::KIND_INT: |
| 956 | case GoType::KIND_UINT: |
| 957 | return m_int_byte_size * 8; |
| 958 | case GoType::KIND_UINTPTR: |
| 959 | case GoType::KIND_FUNC: // I assume this is a pointer? |
| 960 | case GoType::KIND_CHAN: |
| 961 | case GoType::KIND_PTR: |
| 962 | case GoType::KIND_UNSAFEPOINTER: |
| 963 | case GoType::KIND_MAP: |
| 964 | return m_pointer_byte_size * 8; |
| 965 | case GoType::KIND_ARRAY: |
| 966 | array = t->GetArray(); |
| 967 | return array->GetLength() * array->GetElementType().GetBitSize(exe_scope); |
| 968 | case GoType::KIND_INTERFACE: |
| 969 | return t->GetElementType().GetBitSize(exe_scope); |
| 970 | case GoType::KIND_SLICE: |
| 971 | case GoType::KIND_STRING: |
| 972 | case GoType::KIND_STRUCT: |
| 973 | return t->GetStruct()->GetByteSize() * 8; |
| 974 | default: |
| 975 | assert(false); |
| 976 | } |
Ryan Brown | d03c2e0 | 2015-09-15 00:50:43 +0000 | [diff] [blame] | 977 | return 0; |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 978 | } |
| 979 | |
| 980 | lldb::Encoding |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 981 | GoASTContext::GetEncoding(lldb::opaque_compiler_type_t type, uint64_t &count) |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 982 | { |
| 983 | count = 1; |
| 984 | bool is_signed; |
| 985 | if (IsIntegerType(type, is_signed)) |
| 986 | return is_signed ? lldb::eEncodingSint : eEncodingUint; |
| 987 | bool is_complex; |
| 988 | uint32_t complex_count; |
| 989 | if (IsFloatingPointType(type, complex_count, is_complex)) |
| 990 | { |
| 991 | count = complex_count; |
| 992 | return eEncodingIEEE754; |
| 993 | } |
| 994 | if (IsPointerType(type)) |
| 995 | return eEncodingUint; |
| 996 | return eEncodingInvalid; |
| 997 | } |
| 998 | |
| 999 | lldb::Format |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 1000 | GoASTContext::GetFormat(lldb::opaque_compiler_type_t type) |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 1001 | { |
| 1002 | if (!type) |
| 1003 | return eFormatDefault; |
| 1004 | switch (static_cast<GoType *>(type)->GetGoKind()) |
| 1005 | { |
| 1006 | case GoType::KIND_BOOL: |
| 1007 | return eFormatBoolean; |
| 1008 | case GoType::KIND_INT: |
| 1009 | case GoType::KIND_INT8: |
| 1010 | case GoType::KIND_INT16: |
| 1011 | case GoType::KIND_INT32: |
| 1012 | case GoType::KIND_INT64: |
| 1013 | return eFormatDecimal; |
| 1014 | case GoType::KIND_UINT: |
| 1015 | case GoType::KIND_UINT8: |
| 1016 | case GoType::KIND_UINT16: |
| 1017 | case GoType::KIND_UINT32: |
| 1018 | case GoType::KIND_UINT64: |
| 1019 | return eFormatUnsigned; |
| 1020 | case GoType::KIND_FLOAT32: |
| 1021 | case GoType::KIND_FLOAT64: |
| 1022 | return eFormatFloat; |
| 1023 | case GoType::KIND_COMPLEX64: |
| 1024 | case GoType::KIND_COMPLEX128: |
| 1025 | return eFormatComplexFloat; |
| 1026 | case GoType::KIND_UINTPTR: |
| 1027 | case GoType::KIND_CHAN: |
| 1028 | case GoType::KIND_PTR: |
| 1029 | case GoType::KIND_MAP: |
| 1030 | case GoType::KIND_UNSAFEPOINTER: |
| 1031 | return eFormatHex; |
| 1032 | case GoType::KIND_STRING: |
| 1033 | return eFormatCString; |
| 1034 | case GoType::KIND_ARRAY: |
| 1035 | case GoType::KIND_INTERFACE: |
| 1036 | case GoType::KIND_SLICE: |
| 1037 | case GoType::KIND_STRUCT: |
| 1038 | default: |
| 1039 | // Don't know how to display this. |
| 1040 | return eFormatBytes; |
| 1041 | } |
| 1042 | } |
| 1043 | |
| 1044 | size_t |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 1045 | GoASTContext::GetTypeBitAlign(lldb::opaque_compiler_type_t type) |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 1046 | { |
| 1047 | return 0; |
| 1048 | } |
| 1049 | |
| 1050 | uint32_t |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 1051 | GoASTContext::GetNumChildren(lldb::opaque_compiler_type_t type, bool omit_empty_base_classes) |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 1052 | { |
| 1053 | if (!type || !GetCompleteType(type)) |
| 1054 | return 0; |
| 1055 | GoType *t = static_cast<GoType *>(type); |
| 1056 | if (t->GetGoKind() == GoType::KIND_PTR) |
| 1057 | { |
| 1058 | CompilerType elem = t->GetElementType(); |
| 1059 | if (elem.IsAggregateType()) |
| 1060 | return elem.GetNumChildren(omit_empty_base_classes); |
| 1061 | return 1; |
| 1062 | } |
| 1063 | else if (GoArray *array = t->GetArray()) |
| 1064 | { |
| 1065 | return array->GetLength(); |
| 1066 | } |
| 1067 | return GetNumFields(type); |
| 1068 | } |
| 1069 | |
| 1070 | uint32_t |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 1071 | GoASTContext::GetNumFields(lldb::opaque_compiler_type_t type) |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 1072 | { |
| 1073 | if (!type || !GetCompleteType(type)) |
| 1074 | return 0; |
| 1075 | GoType *t = static_cast<GoType *>(type); |
| 1076 | if (t->IsTypedef()) |
| 1077 | return t->GetElementType().GetNumFields(); |
| 1078 | GoStruct *s = t->GetStruct(); |
| 1079 | if (s) |
| 1080 | return s->GetNumFields(); |
| 1081 | return 0; |
| 1082 | } |
| 1083 | |
| 1084 | CompilerType |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 1085 | GoASTContext::GetFieldAtIndex(lldb::opaque_compiler_type_t type, size_t idx, std::string &name, uint64_t *bit_offset_ptr, |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 1086 | uint32_t *bitfield_bit_size_ptr, bool *is_bitfield_ptr) |
| 1087 | { |
| 1088 | if (bit_offset_ptr) |
| 1089 | *bit_offset_ptr = 0; |
| 1090 | if (bitfield_bit_size_ptr) |
| 1091 | *bitfield_bit_size_ptr = 0; |
| 1092 | if (is_bitfield_ptr) |
| 1093 | *is_bitfield_ptr = false; |
| 1094 | |
| 1095 | if (!type || !GetCompleteType(type)) |
| 1096 | return CompilerType(); |
| 1097 | |
| 1098 | GoType *t = static_cast<GoType *>(type); |
| 1099 | if (t->IsTypedef()) |
| 1100 | return t->GetElementType().GetFieldAtIndex(idx, name, bit_offset_ptr, bitfield_bit_size_ptr, is_bitfield_ptr); |
| 1101 | |
| 1102 | GoStruct *s = t->GetStruct(); |
| 1103 | if (s) |
| 1104 | { |
| 1105 | const auto *field = s->GetField(idx); |
| 1106 | if (field) |
| 1107 | { |
| 1108 | name = field->m_name.GetStringRef(); |
| 1109 | if (bit_offset_ptr) |
| 1110 | *bit_offset_ptr = field->m_byte_offset * 8; |
| 1111 | return field->m_type; |
| 1112 | } |
| 1113 | } |
| 1114 | return CompilerType(); |
| 1115 | } |
| 1116 | |
| 1117 | CompilerType |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 1118 | GoASTContext::GetChildCompilerTypeAtIndex(lldb::opaque_compiler_type_t type, ExecutionContext *exe_ctx, size_t idx, bool transparent_pointers, |
Bruce Mitchener | 4ad8334 | 2015-09-21 16:48:48 +0000 | [diff] [blame] | 1119 | bool omit_empty_base_classes, bool ignore_array_bounds, std::string &child_name, |
| 1120 | uint32_t &child_byte_size, int32_t &child_byte_offset, |
| 1121 | uint32_t &child_bitfield_bit_size, uint32_t &child_bitfield_bit_offset, |
| 1122 | bool &child_is_base_class, bool &child_is_deref_of_parent, ValueObject *valobj) |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 1123 | { |
| 1124 | child_name.clear(); |
| 1125 | child_byte_size = 0; |
| 1126 | child_byte_offset = 0; |
| 1127 | child_bitfield_bit_size = 0; |
| 1128 | child_bitfield_bit_offset = 0; |
| 1129 | child_is_base_class = false; |
| 1130 | child_is_deref_of_parent = false; |
| 1131 | |
| 1132 | if (!type || !GetCompleteType(type)) |
| 1133 | return CompilerType(); |
| 1134 | |
| 1135 | GoType *t = static_cast<GoType *>(type); |
| 1136 | if (t->GetStruct()) |
| 1137 | { |
| 1138 | uint64_t bit_offset; |
| 1139 | CompilerType ret = GetFieldAtIndex(type, idx, child_name, &bit_offset, nullptr, nullptr); |
| 1140 | child_byte_size = ret.GetByteSize(exe_ctx ? exe_ctx->GetBestExecutionContextScope() : nullptr); |
| 1141 | child_byte_offset = bit_offset / 8; |
| 1142 | return ret; |
| 1143 | } |
| 1144 | else if (t->GetGoKind() == GoType::KIND_PTR) |
| 1145 | { |
| 1146 | CompilerType pointee = t->GetElementType(); |
| 1147 | if (!pointee.IsValid() || pointee.IsVoidType()) |
| 1148 | return CompilerType(); |
| 1149 | if (transparent_pointers && pointee.IsAggregateType()) |
| 1150 | { |
| 1151 | bool tmp_child_is_deref_of_parent = false; |
Bruce Mitchener | 4ad8334 | 2015-09-21 16:48:48 +0000 | [diff] [blame] | 1152 | return pointee.GetChildCompilerTypeAtIndex(exe_ctx, idx, transparent_pointers, omit_empty_base_classes, |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 1153 | ignore_array_bounds, child_name, child_byte_size, child_byte_offset, |
| 1154 | child_bitfield_bit_size, child_bitfield_bit_offset, |
| 1155 | child_is_base_class, tmp_child_is_deref_of_parent, valobj); |
| 1156 | } |
| 1157 | else |
| 1158 | { |
| 1159 | child_is_deref_of_parent = true; |
| 1160 | const char *parent_name = valobj ? valobj->GetName().GetCString() : NULL; |
| 1161 | if (parent_name) |
| 1162 | { |
| 1163 | child_name.assign(1, '*'); |
| 1164 | child_name += parent_name; |
| 1165 | } |
| 1166 | |
| 1167 | // We have a pointer to an simple type |
| 1168 | if (idx == 0 && pointee.GetCompleteType()) |
| 1169 | { |
| 1170 | child_byte_size = pointee.GetByteSize(exe_ctx ? exe_ctx->GetBestExecutionContextScope() : NULL); |
| 1171 | child_byte_offset = 0; |
| 1172 | return pointee; |
| 1173 | } |
| 1174 | } |
| 1175 | } |
| 1176 | else if (GoArray *a = t->GetArray()) |
| 1177 | { |
| 1178 | if (ignore_array_bounds || idx < a->GetLength()) |
| 1179 | { |
| 1180 | CompilerType element_type = a->GetElementType(); |
| 1181 | if (element_type.GetCompleteType()) |
| 1182 | { |
| 1183 | char element_name[64]; |
| 1184 | ::snprintf(element_name, sizeof(element_name), "[%zu]", idx); |
| 1185 | child_name.assign(element_name); |
| 1186 | child_byte_size = element_type.GetByteSize(exe_ctx ? exe_ctx->GetBestExecutionContextScope() : NULL); |
| 1187 | child_byte_offset = (int32_t)idx * (int32_t)child_byte_size; |
| 1188 | return element_type; |
| 1189 | } |
| 1190 | } |
| 1191 | } |
| 1192 | else if (t->IsTypedef()) |
| 1193 | { |
Bruce Mitchener | 4ad8334 | 2015-09-21 16:48:48 +0000 | [diff] [blame] | 1194 | return t->GetElementType().GetChildCompilerTypeAtIndex( |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 1195 | exe_ctx, idx, transparent_pointers, omit_empty_base_classes, ignore_array_bounds, child_name, |
| 1196 | child_byte_size, child_byte_offset, child_bitfield_bit_size, child_bitfield_bit_offset, child_is_base_class, |
| 1197 | child_is_deref_of_parent, valobj); |
| 1198 | } |
| 1199 | return CompilerType(); |
| 1200 | } |
| 1201 | |
| 1202 | // Lookup a child given a name. This function will match base class names |
| 1203 | // and member member names in "clang_type" only, not descendants. |
| 1204 | uint32_t |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 1205 | GoASTContext::GetIndexOfChildWithName(lldb::opaque_compiler_type_t type, const char *name, bool omit_empty_base_classes) |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 1206 | { |
Ryan Brown | 07a1c45 | 2015-10-06 20:29:31 +0000 | [diff] [blame] | 1207 | if (!type || !GetCompleteType(type)) |
| 1208 | return UINT_MAX; |
| 1209 | |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 1210 | GoType *t = static_cast<GoType *>(type); |
| 1211 | GoStruct *s = t->GetStruct(); |
| 1212 | if (s) |
| 1213 | { |
| 1214 | for (uint32_t i = 0; i < s->GetNumFields(); ++i) |
| 1215 | { |
| 1216 | const GoStruct::Field *f = s->GetField(i); |
| 1217 | if (f->m_name.GetStringRef() == name) |
| 1218 | return i; |
| 1219 | } |
| 1220 | } |
| 1221 | else if (t->GetGoKind() == GoType::KIND_PTR || t->IsTypedef()) |
| 1222 | { |
| 1223 | return t->GetElementType().GetIndexOfChildWithName(name, omit_empty_base_classes); |
| 1224 | } |
| 1225 | return UINT_MAX; |
| 1226 | } |
| 1227 | |
| 1228 | // Lookup a child member given a name. This function will match member names |
| 1229 | // only and will descend into "clang_type" children in search for the first |
| 1230 | // member in this class, or any base class that matches "name". |
| 1231 | // TODO: Return all matches for a given name by returning a vector<vector<uint32_t>> |
| 1232 | // so we catch all names that match a given child name, not just the first. |
| 1233 | size_t |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 1234 | GoASTContext::GetIndexOfChildMemberWithName(lldb::opaque_compiler_type_t type, const char *name, bool omit_empty_base_classes, |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 1235 | std::vector<uint32_t> &child_indexes) |
| 1236 | { |
| 1237 | uint32_t index = GetIndexOfChildWithName(type, name, omit_empty_base_classes); |
| 1238 | if (index == UINT_MAX) |
| 1239 | return 0; |
| 1240 | child_indexes.push_back(index); |
| 1241 | return 1; |
| 1242 | } |
| 1243 | |
| 1244 | // Converts "s" to a floating point value and place resulting floating |
| 1245 | // point bytes in the "dst" buffer. |
| 1246 | size_t |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 1247 | GoASTContext::ConvertStringToFloatValue(lldb::opaque_compiler_type_t type, const char *s, uint8_t *dst, size_t dst_size) |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 1248 | { |
| 1249 | assert(false); |
Ryan Brown | d03c2e0 | 2015-09-15 00:50:43 +0000 | [diff] [blame] | 1250 | return 0; |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 1251 | } |
| 1252 | //---------------------------------------------------------------------- |
| 1253 | // Dumping types |
| 1254 | //---------------------------------------------------------------------- |
| 1255 | void |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 1256 | GoASTContext::DumpValue(lldb::opaque_compiler_type_t type, ExecutionContext *exe_ctx, Stream *s, lldb::Format format, |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 1257 | const DataExtractor &data, lldb::offset_t data_offset, size_t data_byte_size, |
| 1258 | uint32_t bitfield_bit_size, uint32_t bitfield_bit_offset, bool show_types, bool show_summary, |
| 1259 | bool verbose, uint32_t depth) |
| 1260 | { |
| 1261 | assert(false); |
| 1262 | } |
| 1263 | |
| 1264 | bool |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 1265 | GoASTContext::DumpTypeValue(lldb::opaque_compiler_type_t type, Stream *s, lldb::Format format, const DataExtractor &data, |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 1266 | lldb::offset_t byte_offset, size_t byte_size, uint32_t bitfield_bit_size, |
| 1267 | uint32_t bitfield_bit_offset, ExecutionContextScope *exe_scope) |
| 1268 | { |
| 1269 | if (!type) |
| 1270 | return false; |
| 1271 | if (IsAggregateType(type)) |
| 1272 | { |
| 1273 | return false; |
| 1274 | } |
| 1275 | else |
| 1276 | { |
| 1277 | GoType *t = static_cast<GoType *>(type); |
| 1278 | if (t->IsTypedef()) |
| 1279 | { |
Bruce Mitchener | 3ad353f | 2015-09-24 03:54:50 +0000 | [diff] [blame] | 1280 | CompilerType typedef_compiler_type = t->GetElementType(); |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 1281 | if (format == eFormatDefault) |
Bruce Mitchener | 3ad353f | 2015-09-24 03:54:50 +0000 | [diff] [blame] | 1282 | format = typedef_compiler_type.GetFormat(); |
| 1283 | uint64_t typedef_byte_size = typedef_compiler_type.GetByteSize(exe_scope); |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 1284 | |
Bruce Mitchener | 3ad353f | 2015-09-24 03:54:50 +0000 | [diff] [blame] | 1285 | return typedef_compiler_type.DumpTypeValue( |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 1286 | s, |
| 1287 | format, // The format with which to display the element |
| 1288 | data, // Data buffer containing all bytes for this type |
| 1289 | byte_offset, // Offset into "data" where to grab value from |
| 1290 | typedef_byte_size, // Size of this type in bytes |
| 1291 | bitfield_bit_size, // Size in bits of a bitfield value, if zero don't treat as a bitfield |
| 1292 | bitfield_bit_offset, // Offset in bits of a bitfield value if bitfield_bit_size != 0 |
| 1293 | exe_scope); |
| 1294 | } |
| 1295 | |
| 1296 | uint32_t item_count = 1; |
| 1297 | // A few formats, we might need to modify our size and count for depending |
| 1298 | // on how we are trying to display the value... |
| 1299 | switch (format) |
| 1300 | { |
| 1301 | default: |
| 1302 | case eFormatBoolean: |
| 1303 | case eFormatBinary: |
| 1304 | case eFormatComplex: |
| 1305 | case eFormatCString: // NULL terminated C strings |
| 1306 | case eFormatDecimal: |
| 1307 | case eFormatEnum: |
| 1308 | case eFormatHex: |
| 1309 | case eFormatHexUppercase: |
| 1310 | case eFormatFloat: |
| 1311 | case eFormatOctal: |
| 1312 | case eFormatOSType: |
| 1313 | case eFormatUnsigned: |
| 1314 | case eFormatPointer: |
| 1315 | case eFormatVectorOfChar: |
| 1316 | case eFormatVectorOfSInt8: |
| 1317 | case eFormatVectorOfUInt8: |
| 1318 | case eFormatVectorOfSInt16: |
| 1319 | case eFormatVectorOfUInt16: |
| 1320 | case eFormatVectorOfSInt32: |
| 1321 | case eFormatVectorOfUInt32: |
| 1322 | case eFormatVectorOfSInt64: |
| 1323 | case eFormatVectorOfUInt64: |
| 1324 | case eFormatVectorOfFloat32: |
| 1325 | case eFormatVectorOfFloat64: |
| 1326 | case eFormatVectorOfUInt128: |
| 1327 | break; |
| 1328 | |
| 1329 | case eFormatChar: |
| 1330 | case eFormatCharPrintable: |
| 1331 | case eFormatCharArray: |
| 1332 | case eFormatBytes: |
| 1333 | case eFormatBytesWithASCII: |
| 1334 | item_count = byte_size; |
| 1335 | byte_size = 1; |
| 1336 | break; |
| 1337 | |
| 1338 | case eFormatUnicode16: |
| 1339 | item_count = byte_size / 2; |
| 1340 | byte_size = 2; |
| 1341 | break; |
| 1342 | |
| 1343 | case eFormatUnicode32: |
| 1344 | item_count = byte_size / 4; |
| 1345 | byte_size = 4; |
| 1346 | break; |
| 1347 | } |
| 1348 | return data.Dump(s, byte_offset, format, byte_size, item_count, UINT32_MAX, LLDB_INVALID_ADDRESS, |
| 1349 | bitfield_bit_size, bitfield_bit_offset, exe_scope); |
| 1350 | } |
| 1351 | return 0; |
| 1352 | } |
| 1353 | |
| 1354 | void |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 1355 | GoASTContext::DumpSummary(lldb::opaque_compiler_type_t type, ExecutionContext *exe_ctx, Stream *s, const DataExtractor &data, |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 1356 | lldb::offset_t data_offset, size_t data_byte_size) |
| 1357 | { |
| 1358 | assert(false); |
| 1359 | } |
| 1360 | |
| 1361 | void |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 1362 | GoASTContext::DumpTypeDescription(lldb::opaque_compiler_type_t type) |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 1363 | { |
| 1364 | assert(false); |
| 1365 | } // Dump to stdout |
| 1366 | |
| 1367 | void |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 1368 | GoASTContext::DumpTypeDescription(lldb::opaque_compiler_type_t type, Stream *s) |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 1369 | { |
| 1370 | assert(false); |
| 1371 | } |
| 1372 | |
| 1373 | CompilerType |
Bruce Mitchener | 500737e | 2015-09-15 04:33:48 +0000 | [diff] [blame] | 1374 | GoASTContext::CreateArrayType(const ConstString &name, const CompilerType &element_type, uint64_t length) |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 1375 | { |
| 1376 | GoType *type = new GoArray(name, length, element_type); |
| 1377 | (*m_types)[name].reset(type); |
| 1378 | return CompilerType(this, type); |
| 1379 | } |
| 1380 | |
| 1381 | CompilerType |
| 1382 | GoASTContext::CreateBaseType(int go_kind, const lldb_private::ConstString &name, uint64_t byte_size) |
| 1383 | { |
| 1384 | if (go_kind == GoType::KIND_UINT || go_kind == GoType::KIND_INT) |
| 1385 | m_int_byte_size = byte_size; |
| 1386 | GoType *type = new GoType(go_kind, name); |
| 1387 | (*m_types)[name].reset(type); |
| 1388 | return CompilerType(this, type); |
| 1389 | } |
| 1390 | |
| 1391 | CompilerType |
Greg Clayton | 56939cb | 2015-09-17 22:23:34 +0000 | [diff] [blame] | 1392 | GoASTContext::CreateTypedefType(int kind, const ConstString &name, CompilerType impl) |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 1393 | { |
| 1394 | GoType *type = new GoElem(kind, name, impl); |
| 1395 | (*m_types)[name].reset(type); |
| 1396 | return CompilerType(this, type); |
| 1397 | } |
| 1398 | |
| 1399 | CompilerType |
| 1400 | GoASTContext::CreateVoidType(const lldb_private::ConstString &name) |
| 1401 | { |
| 1402 | GoType *type = new GoType(GoType::KIND_LLDB_VOID, name); |
| 1403 | (*m_types)[name].reset(type); |
| 1404 | return CompilerType(this, type); |
| 1405 | } |
| 1406 | |
| 1407 | CompilerType |
| 1408 | GoASTContext::CreateStructType(int kind, const lldb_private::ConstString &name, uint32_t byte_size) |
| 1409 | { |
| 1410 | GoType *type = new GoStruct(kind, name, byte_size); |
| 1411 | (*m_types)[name].reset(type); |
| 1412 | return CompilerType(this, type); |
| 1413 | } |
| 1414 | |
| 1415 | void |
| 1416 | GoASTContext::AddFieldToStruct(const lldb_private::CompilerType &struct_type, const lldb_private::ConstString &name, |
| 1417 | const lldb_private::CompilerType &field_type, uint32_t byte_offset) |
| 1418 | { |
| 1419 | if (!struct_type) |
| 1420 | return; |
| 1421 | GoASTContext *ast = llvm::dyn_cast_or_null<GoASTContext>(struct_type.GetTypeSystem()); |
| 1422 | if (!ast) |
| 1423 | return; |
| 1424 | GoType *type = static_cast<GoType *>(struct_type.GetOpaqueQualType()); |
| 1425 | if (GoStruct *s = type->GetStruct()) |
| 1426 | s->AddField(name, field_type, byte_offset); |
| 1427 | } |
| 1428 | |
| 1429 | void |
| 1430 | GoASTContext::CompleteStructType(const lldb_private::CompilerType &struct_type) |
| 1431 | { |
| 1432 | if (!struct_type) |
| 1433 | return; |
| 1434 | GoASTContext *ast = llvm::dyn_cast_or_null<GoASTContext>(struct_type.GetTypeSystem()); |
| 1435 | if (!ast) |
| 1436 | return; |
| 1437 | GoType *type = static_cast<GoType *>(struct_type.GetOpaqueQualType()); |
| 1438 | if (GoStruct *s = type->GetStruct()) |
| 1439 | s->SetComplete(); |
| 1440 | } |
| 1441 | |
| 1442 | CompilerType |
| 1443 | GoASTContext::CreateFunctionType(const lldb_private::ConstString &name, CompilerType *params, size_t params_count, |
| 1444 | bool is_variadic) |
| 1445 | { |
| 1446 | GoType *type = new GoFunction(name, is_variadic); |
| 1447 | (*m_types)[name].reset(type); |
| 1448 | return CompilerType(this, type); |
| 1449 | } |
| 1450 | |
| 1451 | bool |
| 1452 | GoASTContext::IsGoString(const lldb_private::CompilerType &type) |
| 1453 | { |
| 1454 | if (!type.IsValid() || !llvm::dyn_cast_or_null<GoASTContext>(type.GetTypeSystem())) |
| 1455 | return false; |
| 1456 | return GoType::KIND_STRING == static_cast<GoType *>(type.GetOpaqueQualType())->GetGoKind(); |
| 1457 | } |
| 1458 | |
| 1459 | bool |
| 1460 | GoASTContext::IsGoSlice(const lldb_private::CompilerType &type) |
| 1461 | { |
| 1462 | if (!type.IsValid() || !llvm::dyn_cast_or_null<GoASTContext>(type.GetTypeSystem())) |
| 1463 | return false; |
| 1464 | return GoType::KIND_SLICE == static_cast<GoType *>(type.GetOpaqueQualType())->GetGoKind(); |
| 1465 | } |
| 1466 | |
| 1467 | bool |
| 1468 | GoASTContext::IsGoInterface(const lldb_private::CompilerType &type) |
| 1469 | { |
| 1470 | if (!type.IsValid() || !llvm::dyn_cast_or_null<GoASTContext>(type.GetTypeSystem())) |
| 1471 | return false; |
| 1472 | return GoType::KIND_INTERFACE == static_cast<GoType *>(type.GetOpaqueQualType())->GetGoKind(); |
| 1473 | } |
| 1474 | |
| 1475 | bool |
| 1476 | GoASTContext::IsPointerKind(uint8_t kind) |
| 1477 | { |
| 1478 | return (kind & GoType::KIND_MASK) == GoType::KIND_PTR; |
| 1479 | } |
| 1480 | |
| 1481 | bool |
| 1482 | GoASTContext::IsDirectIface(uint8_t kind) |
| 1483 | { |
| 1484 | return (kind & GoType::KIND_DIRECT_IFACE) == GoType::KIND_DIRECT_IFACE; |
| 1485 | } |
| 1486 | |
| 1487 | DWARFASTParser * |
| 1488 | GoASTContext::GetDWARFParser() |
| 1489 | { |
| 1490 | if (!m_dwarf_ast_parser_ap) |
| 1491 | m_dwarf_ast_parser_ap.reset(new DWARFASTParserGo(*this)); |
| 1492 | return m_dwarf_ast_parser_ap.get(); |
| 1493 | } |