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 | |
| 345 | |
| 346 | void |
| 347 | GoASTContext::Initialize() |
| 348 | { |
| 349 | PluginManager::RegisterPlugin (GetPluginNameStatic(), |
| 350 | "AST context plug-in", |
| 351 | CreateInstance); |
| 352 | } |
| 353 | |
| 354 | void |
| 355 | GoASTContext::Terminate() |
| 356 | { |
| 357 | PluginManager::UnregisterPlugin (CreateInstance); |
| 358 | } |
| 359 | |
| 360 | |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 361 | //---------------------------------------------------------------------- |
| 362 | // Tests |
| 363 | //---------------------------------------------------------------------- |
| 364 | |
| 365 | bool |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 366 | 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] | 367 | { |
| 368 | if (element_type) |
| 369 | element_type->Clear(); |
| 370 | if (size) |
| 371 | *size = 0; |
| 372 | if (is_incomplete) |
| 373 | *is_incomplete = false; |
| 374 | GoArray *array = static_cast<GoType *>(type)->GetArray(); |
| 375 | if (array) |
| 376 | { |
Bruce Mitchener | 500737e | 2015-09-15 04:33:48 +0000 | [diff] [blame] | 377 | if (size) |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 378 | *size = array->GetLength(); |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 379 | if (element_type) |
| 380 | *element_type = array->GetElementType(); |
| 381 | return true; |
| 382 | } |
| 383 | return false; |
| 384 | } |
| 385 | |
| 386 | bool |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 387 | 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] | 388 | { |
| 389 | if (element_type) |
| 390 | element_type->Clear(); |
| 391 | if (size) |
| 392 | *size = 0; |
| 393 | return false; |
| 394 | } |
| 395 | |
| 396 | bool |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 397 | GoASTContext::IsAggregateType(lldb::opaque_compiler_type_t type) |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 398 | { |
| 399 | int kind = static_cast<GoType *>(type)->GetGoKind(); |
| 400 | if (kind < GoType::KIND_ARRAY) |
| 401 | return false; |
| 402 | if (kind == GoType::KIND_PTR) |
| 403 | return false; |
| 404 | if (kind == GoType::KIND_STRING) |
| 405 | return false; |
| 406 | if (kind == GoType::KIND_UNSAFEPOINTER) |
| 407 | return false; |
| 408 | return true; |
| 409 | } |
| 410 | |
| 411 | bool |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 412 | GoASTContext::IsBeingDefined(lldb::opaque_compiler_type_t type) |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 413 | { |
| 414 | return false; |
| 415 | } |
| 416 | |
| 417 | bool |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 418 | GoASTContext::IsCharType(lldb::opaque_compiler_type_t type) |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 419 | { |
| 420 | // Go's DWARF doesn't distinguish between rune and int32. |
| 421 | return false; |
| 422 | } |
| 423 | |
| 424 | bool |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 425 | GoASTContext::IsCompleteType(lldb::opaque_compiler_type_t type) |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 426 | { |
| 427 | if (!type) |
| 428 | return false; |
| 429 | GoType *t = static_cast<GoType *>(type); |
| 430 | if (GoStruct *s = t->GetStruct()) |
| 431 | return s->IsComplete(); |
| 432 | if (t->IsTypedef() || t->GetGoKind() == GoType::KIND_PTR) |
| 433 | return t->GetElementType().IsCompleteType(); |
| 434 | return true; |
| 435 | } |
| 436 | |
| 437 | bool |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 438 | GoASTContext::IsConst(lldb::opaque_compiler_type_t type) |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 439 | { |
| 440 | return false; |
| 441 | } |
| 442 | |
| 443 | bool |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 444 | GoASTContext::IsCStringType(lldb::opaque_compiler_type_t type, uint32_t &length) |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 445 | { |
| 446 | return false; |
| 447 | } |
| 448 | |
| 449 | bool |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 450 | GoASTContext::IsDefined(lldb::opaque_compiler_type_t type) |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 451 | { |
| 452 | return type != nullptr; |
| 453 | } |
| 454 | |
| 455 | bool |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 456 | 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] | 457 | { |
| 458 | int kind = static_cast<GoType *>(type)->GetGoKind(); |
| 459 | if (kind >= GoType::KIND_FLOAT32 && kind <= GoType::KIND_COMPLEX128) |
| 460 | { |
| 461 | if (kind >= GoType::KIND_COMPLEX64) |
| 462 | { |
| 463 | is_complex = true; |
| 464 | count = 2; |
| 465 | } |
| 466 | else |
| 467 | { |
| 468 | is_complex = false; |
| 469 | count = 1; |
| 470 | } |
| 471 | return true; |
| 472 | } |
| 473 | count = 0; |
| 474 | is_complex = false; |
| 475 | return false; |
| 476 | } |
| 477 | |
| 478 | bool |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 479 | GoASTContext::IsFunctionType(lldb::opaque_compiler_type_t type, bool *is_variadic_ptr) |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 480 | { |
| 481 | GoFunction *func = static_cast<GoType *>(type)->GetFunction(); |
| 482 | if (func) |
| 483 | { |
| 484 | if (is_variadic_ptr) |
| 485 | *is_variadic_ptr = func->IsVariadic(); |
| 486 | return true; |
| 487 | } |
| 488 | if (is_variadic_ptr) |
| 489 | *is_variadic_ptr = false; |
| 490 | return false; |
| 491 | } |
| 492 | |
| 493 | uint32_t |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 494 | GoASTContext::IsHomogeneousAggregate(lldb::opaque_compiler_type_t type, CompilerType *base_type_ptr) |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 495 | { |
| 496 | return false; |
| 497 | } |
| 498 | |
| 499 | size_t |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 500 | GoASTContext::GetNumberOfFunctionArguments(lldb::opaque_compiler_type_t type) |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 501 | { |
| 502 | return 0; |
| 503 | } |
| 504 | |
| 505 | CompilerType |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 506 | GoASTContext::GetFunctionArgumentAtIndex(lldb::opaque_compiler_type_t type, const size_t index) |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 507 | { |
| 508 | return CompilerType(); |
| 509 | } |
| 510 | |
| 511 | bool |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 512 | GoASTContext::IsFunctionPointerType(lldb::opaque_compiler_type_t type) |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 513 | { |
| 514 | return IsFunctionType(type); |
| 515 | } |
| 516 | |
| 517 | bool |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 518 | GoASTContext::IsIntegerType(lldb::opaque_compiler_type_t type, bool &is_signed) |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 519 | { |
| 520 | is_signed = false; |
| 521 | // TODO: Is bool an integer? |
| 522 | if (type) |
| 523 | { |
| 524 | int kind = static_cast<GoType *>(type)->GetGoKind(); |
| 525 | if (kind <= GoType::KIND_UINTPTR) |
| 526 | { |
| 527 | is_signed = (kind != GoType::KIND_BOOL) & (kind <= GoType::KIND_INT64); |
| 528 | return true; |
| 529 | } |
| 530 | } |
| 531 | return false; |
| 532 | } |
| 533 | |
| 534 | bool |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 535 | GoASTContext::IsPolymorphicClass(lldb::opaque_compiler_type_t type) |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 536 | { |
| 537 | return false; |
| 538 | } |
| 539 | |
| 540 | bool |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 541 | GoASTContext::IsPossibleDynamicType(lldb::opaque_compiler_type_t type, |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 542 | CompilerType *target_type, // Can pass NULL |
| 543 | bool check_cplusplus, bool check_objc) |
| 544 | { |
| 545 | if (target_type) |
| 546 | target_type->Clear(); |
| 547 | if (type) |
| 548 | return static_cast<GoType *>(type)->GetGoKind() == GoType::KIND_INTERFACE; |
| 549 | return false; |
| 550 | } |
| 551 | |
| 552 | bool |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 553 | GoASTContext::IsRuntimeGeneratedType(lldb::opaque_compiler_type_t type) |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 554 | { |
| 555 | return false; |
| 556 | } |
| 557 | |
| 558 | bool |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 559 | GoASTContext::IsPointerType(lldb::opaque_compiler_type_t type, CompilerType *pointee_type) |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 560 | { |
| 561 | if (!type) |
| 562 | return false; |
| 563 | GoType *t = static_cast<GoType *>(type); |
| 564 | if (pointee_type) |
| 565 | { |
| 566 | *pointee_type = t->GetElementType(); |
| 567 | } |
| 568 | switch (t->GetGoKind()) |
| 569 | { |
| 570 | case GoType::KIND_PTR: |
| 571 | case GoType::KIND_UNSAFEPOINTER: |
| 572 | case GoType::KIND_CHAN: |
| 573 | // TODO: is map a pointer? string? function? |
| 574 | return true; |
| 575 | default: |
| 576 | return false; |
| 577 | } |
| 578 | } |
| 579 | |
| 580 | bool |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 581 | GoASTContext::IsPointerOrReferenceType(lldb::opaque_compiler_type_t type, CompilerType *pointee_type) |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 582 | { |
| 583 | return IsPointerType(type, pointee_type); |
| 584 | } |
| 585 | |
| 586 | bool |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 587 | 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] | 588 | { |
| 589 | return false; |
| 590 | } |
| 591 | |
| 592 | bool |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 593 | GoASTContext::IsScalarType(lldb::opaque_compiler_type_t type) |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 594 | { |
| 595 | return !IsAggregateType(type); |
| 596 | } |
| 597 | |
| 598 | bool |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 599 | GoASTContext::IsTypedefType(lldb::opaque_compiler_type_t type) |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 600 | { |
| 601 | if (type) |
| 602 | return static_cast<GoType *>(type)->IsTypedef(); |
| 603 | return false; |
| 604 | } |
| 605 | |
| 606 | bool |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 607 | GoASTContext::IsVoidType(lldb::opaque_compiler_type_t type) |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 608 | { |
| 609 | if (!type) |
| 610 | return false; |
| 611 | return static_cast<GoType *>(type)->GetGoKind() == GoType::KIND_LLDB_VOID; |
| 612 | } |
| 613 | |
Greg Clayton | 56939cb | 2015-09-17 22:23:34 +0000 | [diff] [blame] | 614 | bool |
| 615 | GoASTContext::SupportsLanguage (lldb::LanguageType language) |
| 616 | { |
| 617 | return language == eLanguageTypeGo; |
| 618 | } |
| 619 | |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 620 | //---------------------------------------------------------------------- |
| 621 | // Type Completion |
| 622 | //---------------------------------------------------------------------- |
| 623 | |
| 624 | bool |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 625 | GoASTContext::GetCompleteType(lldb::opaque_compiler_type_t type) |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 626 | { |
| 627 | if (!type) |
| 628 | return false; |
| 629 | GoType *t = static_cast<GoType *>(type); |
| 630 | if (t->IsTypedef() || t->GetGoKind() == GoType::KIND_PTR || t->GetArray()) |
| 631 | return t->GetElementType().GetCompleteType(); |
| 632 | if (GoStruct *s = t->GetStruct()) |
| 633 | { |
| 634 | if (s->IsComplete()) |
| 635 | return true; |
| 636 | CompilerType compiler_type(this, s); |
| 637 | SymbolFile *symbols = GetSymbolFile(); |
| 638 | return symbols && symbols->CompleteType(compiler_type); |
| 639 | } |
| 640 | return true; |
| 641 | } |
| 642 | |
| 643 | //---------------------------------------------------------------------- |
| 644 | // AST related queries |
| 645 | //---------------------------------------------------------------------- |
| 646 | |
| 647 | uint32_t |
| 648 | GoASTContext::GetPointerByteSize() |
| 649 | { |
| 650 | return m_pointer_byte_size; |
| 651 | } |
| 652 | |
| 653 | //---------------------------------------------------------------------- |
| 654 | // Accessors |
| 655 | //---------------------------------------------------------------------- |
| 656 | |
| 657 | ConstString |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 658 | GoASTContext::GetTypeName(lldb::opaque_compiler_type_t type) |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 659 | { |
| 660 | if (type) |
| 661 | return static_cast<GoType *>(type)->GetName(); |
| 662 | return ConstString(); |
| 663 | } |
| 664 | |
| 665 | uint32_t |
Bruce Mitchener | 3ad353f | 2015-09-24 03:54:50 +0000 | [diff] [blame] | 666 | 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] | 667 | { |
Bruce Mitchener | 3ad353f | 2015-09-24 03:54:50 +0000 | [diff] [blame] | 668 | if (pointee_or_element_compiler_type) |
| 669 | pointee_or_element_compiler_type->Clear(); |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 670 | if (!type) |
| 671 | return 0; |
| 672 | GoType *t = static_cast<GoType *>(type); |
Bruce Mitchener | 3ad353f | 2015-09-24 03:54:50 +0000 | [diff] [blame] | 673 | if (pointee_or_element_compiler_type) |
| 674 | *pointee_or_element_compiler_type = t->GetElementType(); |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 675 | int kind = t->GetGoKind(); |
| 676 | if (kind == GoType::KIND_ARRAY) |
| 677 | return eTypeHasChildren | eTypeIsArray; |
| 678 | if (kind < GoType::KIND_ARRAY) |
| 679 | { |
| 680 | uint32_t builtin_type_flags = eTypeIsBuiltIn | eTypeHasValue; |
| 681 | if (kind < GoType::KIND_FLOAT32) |
| 682 | { |
| 683 | builtin_type_flags |= eTypeIsInteger | eTypeIsScalar; |
| 684 | if (kind >= GoType::KIND_INT && kind <= GoType::KIND_INT64) |
| 685 | builtin_type_flags |= eTypeIsSigned; |
| 686 | } |
| 687 | else |
| 688 | { |
| 689 | builtin_type_flags |= eTypeIsFloat; |
| 690 | if (kind < GoType::KIND_COMPLEX64) |
| 691 | builtin_type_flags |= eTypeIsComplex; |
| 692 | else |
| 693 | builtin_type_flags |= eTypeIsScalar; |
| 694 | } |
| 695 | return builtin_type_flags; |
| 696 | } |
| 697 | if (kind == GoType::KIND_STRING) |
| 698 | return eTypeHasValue | eTypeIsBuiltIn; |
| 699 | if (kind == GoType::KIND_FUNC) |
| 700 | return eTypeIsFuncPrototype | eTypeHasValue; |
| 701 | if (IsPointerType(type)) |
| 702 | return eTypeIsPointer | eTypeHasValue | eTypeHasChildren; |
| 703 | if (kind == GoType::KIND_LLDB_VOID) |
| 704 | return 0; |
| 705 | return eTypeHasChildren | eTypeIsStructUnion; |
| 706 | } |
| 707 | |
| 708 | lldb::TypeClass |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 709 | GoASTContext::GetTypeClass(lldb::opaque_compiler_type_t type) |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 710 | { |
| 711 | if (!type) |
| 712 | return eTypeClassInvalid; |
| 713 | int kind = static_cast<GoType *>(type)->GetGoKind(); |
| 714 | if (kind == GoType::KIND_FUNC) |
| 715 | return eTypeClassFunction; |
| 716 | if (IsPointerType(type)) |
| 717 | return eTypeClassPointer; |
| 718 | if (kind < GoType::KIND_COMPLEX64) |
| 719 | return eTypeClassBuiltin; |
| 720 | if (kind <= GoType::KIND_COMPLEX128) |
| 721 | return eTypeClassComplexFloat; |
| 722 | if (kind == GoType::KIND_LLDB_VOID) |
| 723 | return eTypeClassInvalid; |
| 724 | return eTypeClassStruct; |
| 725 | } |
| 726 | |
| 727 | lldb::BasicType |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 728 | GoASTContext::GetBasicTypeEnumeration(lldb::opaque_compiler_type_t type) |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 729 | { |
| 730 | ConstString name = GetTypeName(type); |
| 731 | if (name) |
| 732 | { |
| 733 | typedef UniqueCStringMap<lldb::BasicType> TypeNameToBasicTypeMap; |
| 734 | static TypeNameToBasicTypeMap g_type_map; |
| 735 | static std::once_flag g_once_flag; |
| 736 | std::call_once(g_once_flag, [](){ |
| 737 | // "void" |
| 738 | g_type_map.Append(ConstString("void").GetCString(), eBasicTypeVoid); |
| 739 | // "int" |
| 740 | g_type_map.Append(ConstString("int").GetCString(), eBasicTypeInt); |
| 741 | g_type_map.Append(ConstString("uint").GetCString(), eBasicTypeUnsignedInt); |
| 742 | |
| 743 | // Miscellaneous |
| 744 | g_type_map.Append(ConstString("bool").GetCString(), eBasicTypeBool); |
| 745 | |
| 746 | // Others. Should these map to C types? |
| 747 | g_type_map.Append(ConstString("byte").GetCString(), eBasicTypeOther); |
| 748 | g_type_map.Append(ConstString("uint8").GetCString(), eBasicTypeOther); |
| 749 | g_type_map.Append(ConstString("uint16").GetCString(), eBasicTypeOther); |
| 750 | g_type_map.Append(ConstString("uint32").GetCString(), eBasicTypeOther); |
| 751 | g_type_map.Append(ConstString("uint64").GetCString(), eBasicTypeOther); |
| 752 | g_type_map.Append(ConstString("int8").GetCString(), eBasicTypeOther); |
| 753 | g_type_map.Append(ConstString("int16").GetCString(), eBasicTypeOther); |
| 754 | g_type_map.Append(ConstString("int32").GetCString(), eBasicTypeOther); |
| 755 | g_type_map.Append(ConstString("int64").GetCString(), eBasicTypeOther); |
| 756 | g_type_map.Append(ConstString("float32").GetCString(), eBasicTypeOther); |
| 757 | g_type_map.Append(ConstString("float64").GetCString(), eBasicTypeOther); |
| 758 | g_type_map.Append(ConstString("uintptr").GetCString(), eBasicTypeOther); |
| 759 | |
| 760 | g_type_map.Sort(); |
| 761 | }); |
| 762 | |
| 763 | return g_type_map.Find(name.GetCString(), eBasicTypeInvalid); |
| 764 | } |
| 765 | return eBasicTypeInvalid; |
| 766 | } |
| 767 | |
| 768 | lldb::LanguageType |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 769 | GoASTContext::GetMinimumLanguage(lldb::opaque_compiler_type_t type) |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 770 | { |
| 771 | return lldb::eLanguageTypeGo; |
| 772 | } |
| 773 | |
| 774 | unsigned |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 775 | GoASTContext::GetTypeQualifiers(lldb::opaque_compiler_type_t type) |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 776 | { |
| 777 | return 0; |
| 778 | } |
| 779 | |
| 780 | //---------------------------------------------------------------------- |
| 781 | // Creating related types |
| 782 | //---------------------------------------------------------------------- |
| 783 | |
| 784 | CompilerType |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 785 | GoASTContext::GetArrayElementType(lldb::opaque_compiler_type_t type, uint64_t *stride) |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 786 | { |
| 787 | GoArray *array = static_cast<GoType *>(type)->GetArray(); |
| 788 | if (array) |
| 789 | { |
| 790 | if (stride) |
| 791 | { |
| 792 | *stride = array->GetElementType().GetByteSize(nullptr); |
| 793 | } |
| 794 | return array->GetElementType(); |
| 795 | } |
| 796 | return CompilerType(); |
| 797 | } |
| 798 | |
| 799 | CompilerType |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 800 | GoASTContext::GetCanonicalType(lldb::opaque_compiler_type_t type) |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 801 | { |
| 802 | GoType *t = static_cast<GoType *>(type); |
| 803 | if (t->IsTypedef()) |
| 804 | return t->GetElementType(); |
| 805 | return CompilerType(this, type); |
| 806 | } |
| 807 | |
| 808 | CompilerType |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 809 | GoASTContext::GetFullyUnqualifiedType(lldb::opaque_compiler_type_t type) |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 810 | { |
| 811 | return CompilerType(this, type); |
| 812 | } |
| 813 | |
| 814 | // Returns -1 if this isn't a function of if the function doesn't have a prototype |
| 815 | // Returns a value >= 0 if there is a prototype. |
| 816 | int |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 817 | GoASTContext::GetFunctionArgumentCount(lldb::opaque_compiler_type_t type) |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 818 | { |
| 819 | return GetNumberOfFunctionArguments(type); |
| 820 | } |
| 821 | |
| 822 | CompilerType |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 823 | GoASTContext::GetFunctionArgumentTypeAtIndex(lldb::opaque_compiler_type_t type, size_t idx) |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 824 | { |
| 825 | return GetFunctionArgumentAtIndex(type, idx); |
| 826 | } |
| 827 | |
| 828 | CompilerType |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 829 | GoASTContext::GetFunctionReturnType(lldb::opaque_compiler_type_t type) |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 830 | { |
| 831 | CompilerType result; |
| 832 | if (type) |
| 833 | { |
| 834 | GoType *t = static_cast<GoType *>(type); |
| 835 | if (t->GetGoKind() == GoType::KIND_FUNC) |
| 836 | result = t->GetElementType(); |
| 837 | } |
| 838 | return result; |
| 839 | } |
| 840 | |
| 841 | size_t |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 842 | GoASTContext::GetNumMemberFunctions(lldb::opaque_compiler_type_t type) |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 843 | { |
| 844 | return 0; |
| 845 | } |
| 846 | |
| 847 | TypeMemberFunctionImpl |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 848 | GoASTContext::GetMemberFunctionAtIndex(lldb::opaque_compiler_type_t type, size_t idx) |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 849 | { |
| 850 | return TypeMemberFunctionImpl(); |
| 851 | } |
| 852 | |
| 853 | CompilerType |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 854 | GoASTContext::GetNonReferenceType(lldb::opaque_compiler_type_t type) |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 855 | { |
| 856 | return CompilerType(this, type); |
| 857 | } |
| 858 | |
| 859 | CompilerType |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 860 | GoASTContext::GetPointeeType(lldb::opaque_compiler_type_t type) |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 861 | { |
| 862 | if (!type) |
| 863 | return CompilerType(); |
| 864 | return static_cast<GoType *>(type)->GetElementType(); |
| 865 | } |
| 866 | |
| 867 | CompilerType |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 868 | GoASTContext::GetPointerType(lldb::opaque_compiler_type_t type) |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 869 | { |
| 870 | if (!type) |
| 871 | return CompilerType(); |
| 872 | ConstString type_name = GetTypeName(type); |
| 873 | ConstString pointer_name(std::string("*") + type_name.GetCString()); |
| 874 | GoType *pointer = (*m_types)[pointer_name].get(); |
| 875 | if (pointer == nullptr) |
| 876 | { |
| 877 | pointer = new GoElem(GoType::KIND_PTR, pointer_name, CompilerType(this, type)); |
| 878 | (*m_types)[pointer_name].reset(pointer); |
| 879 | } |
| 880 | return CompilerType(this, pointer); |
| 881 | } |
| 882 | |
| 883 | // If the current object represents a typedef type, get the underlying type |
| 884 | CompilerType |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 885 | GoASTContext::GetTypedefedType(lldb::opaque_compiler_type_t type) |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 886 | { |
| 887 | if (IsTypedefType(type)) |
| 888 | return static_cast<GoType *>(type)->GetElementType(); |
| 889 | return CompilerType(); |
| 890 | } |
| 891 | |
| 892 | //---------------------------------------------------------------------- |
| 893 | // Create related types using the current type's AST |
| 894 | //---------------------------------------------------------------------- |
| 895 | CompilerType |
| 896 | GoASTContext::GetBasicTypeFromAST(lldb::BasicType basic_type) |
| 897 | { |
| 898 | return CompilerType(); |
| 899 | } |
| 900 | |
Greg Clayton | 56939cb | 2015-09-17 22:23:34 +0000 | [diff] [blame] | 901 | CompilerType |
| 902 | GoASTContext::GetBuiltinTypeForEncodingAndBitSize (lldb::Encoding encoding, |
| 903 | size_t bit_size) |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 904 | { |
| 905 | return CompilerType(); |
| 906 | } |
| 907 | |
| 908 | |
| 909 | //---------------------------------------------------------------------- |
| 910 | // Exploring the type |
| 911 | //---------------------------------------------------------------------- |
| 912 | |
| 913 | uint64_t |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 914 | GoASTContext::GetBitSize(lldb::opaque_compiler_type_t type, ExecutionContextScope *exe_scope) |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 915 | { |
| 916 | if (!type) |
| 917 | return 0; |
| 918 | if (!GetCompleteType(type)) |
| 919 | return 0; |
| 920 | GoType *t = static_cast<GoType *>(type); |
| 921 | GoArray *array = nullptr; |
| 922 | switch (t->GetGoKind()) |
| 923 | { |
| 924 | case GoType::KIND_BOOL: |
| 925 | case GoType::KIND_INT8: |
| 926 | case GoType::KIND_UINT8: |
| 927 | return 8; |
| 928 | case GoType::KIND_INT16: |
| 929 | case GoType::KIND_UINT16: |
| 930 | return 16; |
| 931 | case GoType::KIND_INT32: |
| 932 | case GoType::KIND_UINT32: |
| 933 | case GoType::KIND_FLOAT32: |
| 934 | return 32; |
| 935 | case GoType::KIND_INT64: |
| 936 | case GoType::KIND_UINT64: |
| 937 | case GoType::KIND_FLOAT64: |
| 938 | case GoType::KIND_COMPLEX64: |
| 939 | return 64; |
| 940 | case GoType::KIND_COMPLEX128: |
| 941 | return 128; |
| 942 | case GoType::KIND_INT: |
| 943 | case GoType::KIND_UINT: |
| 944 | return m_int_byte_size * 8; |
| 945 | case GoType::KIND_UINTPTR: |
| 946 | case GoType::KIND_FUNC: // I assume this is a pointer? |
| 947 | case GoType::KIND_CHAN: |
| 948 | case GoType::KIND_PTR: |
| 949 | case GoType::KIND_UNSAFEPOINTER: |
| 950 | case GoType::KIND_MAP: |
| 951 | return m_pointer_byte_size * 8; |
| 952 | case GoType::KIND_ARRAY: |
| 953 | array = t->GetArray(); |
| 954 | return array->GetLength() * array->GetElementType().GetBitSize(exe_scope); |
| 955 | case GoType::KIND_INTERFACE: |
| 956 | return t->GetElementType().GetBitSize(exe_scope); |
| 957 | case GoType::KIND_SLICE: |
| 958 | case GoType::KIND_STRING: |
| 959 | case GoType::KIND_STRUCT: |
| 960 | return t->GetStruct()->GetByteSize() * 8; |
| 961 | default: |
| 962 | assert(false); |
| 963 | } |
Ryan Brown | d03c2e0 | 2015-09-15 00:50:43 +0000 | [diff] [blame] | 964 | return 0; |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 965 | } |
| 966 | |
| 967 | lldb::Encoding |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 968 | GoASTContext::GetEncoding(lldb::opaque_compiler_type_t type, uint64_t &count) |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 969 | { |
| 970 | count = 1; |
| 971 | bool is_signed; |
| 972 | if (IsIntegerType(type, is_signed)) |
| 973 | return is_signed ? lldb::eEncodingSint : eEncodingUint; |
| 974 | bool is_complex; |
| 975 | uint32_t complex_count; |
| 976 | if (IsFloatingPointType(type, complex_count, is_complex)) |
| 977 | { |
| 978 | count = complex_count; |
| 979 | return eEncodingIEEE754; |
| 980 | } |
| 981 | if (IsPointerType(type)) |
| 982 | return eEncodingUint; |
| 983 | return eEncodingInvalid; |
| 984 | } |
| 985 | |
| 986 | lldb::Format |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 987 | GoASTContext::GetFormat(lldb::opaque_compiler_type_t type) |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 988 | { |
| 989 | if (!type) |
| 990 | return eFormatDefault; |
| 991 | switch (static_cast<GoType *>(type)->GetGoKind()) |
| 992 | { |
| 993 | case GoType::KIND_BOOL: |
| 994 | return eFormatBoolean; |
| 995 | case GoType::KIND_INT: |
| 996 | case GoType::KIND_INT8: |
| 997 | case GoType::KIND_INT16: |
| 998 | case GoType::KIND_INT32: |
| 999 | case GoType::KIND_INT64: |
| 1000 | return eFormatDecimal; |
| 1001 | case GoType::KIND_UINT: |
| 1002 | case GoType::KIND_UINT8: |
| 1003 | case GoType::KIND_UINT16: |
| 1004 | case GoType::KIND_UINT32: |
| 1005 | case GoType::KIND_UINT64: |
| 1006 | return eFormatUnsigned; |
| 1007 | case GoType::KIND_FLOAT32: |
| 1008 | case GoType::KIND_FLOAT64: |
| 1009 | return eFormatFloat; |
| 1010 | case GoType::KIND_COMPLEX64: |
| 1011 | case GoType::KIND_COMPLEX128: |
| 1012 | return eFormatComplexFloat; |
| 1013 | case GoType::KIND_UINTPTR: |
| 1014 | case GoType::KIND_CHAN: |
| 1015 | case GoType::KIND_PTR: |
| 1016 | case GoType::KIND_MAP: |
| 1017 | case GoType::KIND_UNSAFEPOINTER: |
| 1018 | return eFormatHex; |
| 1019 | case GoType::KIND_STRING: |
| 1020 | return eFormatCString; |
| 1021 | case GoType::KIND_ARRAY: |
| 1022 | case GoType::KIND_INTERFACE: |
| 1023 | case GoType::KIND_SLICE: |
| 1024 | case GoType::KIND_STRUCT: |
| 1025 | default: |
| 1026 | // Don't know how to display this. |
| 1027 | return eFormatBytes; |
| 1028 | } |
| 1029 | } |
| 1030 | |
| 1031 | size_t |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 1032 | GoASTContext::GetTypeBitAlign(lldb::opaque_compiler_type_t type) |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 1033 | { |
| 1034 | return 0; |
| 1035 | } |
| 1036 | |
| 1037 | uint32_t |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 1038 | 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] | 1039 | { |
| 1040 | if (!type || !GetCompleteType(type)) |
| 1041 | return 0; |
| 1042 | GoType *t = static_cast<GoType *>(type); |
| 1043 | if (t->GetGoKind() == GoType::KIND_PTR) |
| 1044 | { |
| 1045 | CompilerType elem = t->GetElementType(); |
| 1046 | if (elem.IsAggregateType()) |
| 1047 | return elem.GetNumChildren(omit_empty_base_classes); |
| 1048 | return 1; |
| 1049 | } |
| 1050 | else if (GoArray *array = t->GetArray()) |
| 1051 | { |
| 1052 | return array->GetLength(); |
| 1053 | } |
| 1054 | return GetNumFields(type); |
| 1055 | } |
| 1056 | |
| 1057 | uint32_t |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 1058 | GoASTContext::GetNumFields(lldb::opaque_compiler_type_t type) |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 1059 | { |
| 1060 | if (!type || !GetCompleteType(type)) |
| 1061 | return 0; |
| 1062 | GoType *t = static_cast<GoType *>(type); |
| 1063 | if (t->IsTypedef()) |
| 1064 | return t->GetElementType().GetNumFields(); |
| 1065 | GoStruct *s = t->GetStruct(); |
| 1066 | if (s) |
| 1067 | return s->GetNumFields(); |
| 1068 | return 0; |
| 1069 | } |
| 1070 | |
| 1071 | CompilerType |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 1072 | 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] | 1073 | uint32_t *bitfield_bit_size_ptr, bool *is_bitfield_ptr) |
| 1074 | { |
| 1075 | if (bit_offset_ptr) |
| 1076 | *bit_offset_ptr = 0; |
| 1077 | if (bitfield_bit_size_ptr) |
| 1078 | *bitfield_bit_size_ptr = 0; |
| 1079 | if (is_bitfield_ptr) |
| 1080 | *is_bitfield_ptr = false; |
| 1081 | |
| 1082 | if (!type || !GetCompleteType(type)) |
| 1083 | return CompilerType(); |
| 1084 | |
| 1085 | GoType *t = static_cast<GoType *>(type); |
| 1086 | if (t->IsTypedef()) |
| 1087 | return t->GetElementType().GetFieldAtIndex(idx, name, bit_offset_ptr, bitfield_bit_size_ptr, is_bitfield_ptr); |
| 1088 | |
| 1089 | GoStruct *s = t->GetStruct(); |
| 1090 | if (s) |
| 1091 | { |
| 1092 | const auto *field = s->GetField(idx); |
| 1093 | if (field) |
| 1094 | { |
| 1095 | name = field->m_name.GetStringRef(); |
| 1096 | if (bit_offset_ptr) |
| 1097 | *bit_offset_ptr = field->m_byte_offset * 8; |
| 1098 | return field->m_type; |
| 1099 | } |
| 1100 | } |
| 1101 | return CompilerType(); |
| 1102 | } |
| 1103 | |
| 1104 | CompilerType |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 1105 | 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] | 1106 | bool omit_empty_base_classes, bool ignore_array_bounds, std::string &child_name, |
| 1107 | uint32_t &child_byte_size, int32_t &child_byte_offset, |
| 1108 | uint32_t &child_bitfield_bit_size, uint32_t &child_bitfield_bit_offset, |
| 1109 | 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] | 1110 | { |
| 1111 | child_name.clear(); |
| 1112 | child_byte_size = 0; |
| 1113 | child_byte_offset = 0; |
| 1114 | child_bitfield_bit_size = 0; |
| 1115 | child_bitfield_bit_offset = 0; |
| 1116 | child_is_base_class = false; |
| 1117 | child_is_deref_of_parent = false; |
| 1118 | |
| 1119 | if (!type || !GetCompleteType(type)) |
| 1120 | return CompilerType(); |
| 1121 | |
| 1122 | GoType *t = static_cast<GoType *>(type); |
| 1123 | if (t->GetStruct()) |
| 1124 | { |
| 1125 | uint64_t bit_offset; |
| 1126 | CompilerType ret = GetFieldAtIndex(type, idx, child_name, &bit_offset, nullptr, nullptr); |
| 1127 | child_byte_size = ret.GetByteSize(exe_ctx ? exe_ctx->GetBestExecutionContextScope() : nullptr); |
| 1128 | child_byte_offset = bit_offset / 8; |
| 1129 | return ret; |
| 1130 | } |
| 1131 | else if (t->GetGoKind() == GoType::KIND_PTR) |
| 1132 | { |
| 1133 | CompilerType pointee = t->GetElementType(); |
| 1134 | if (!pointee.IsValid() || pointee.IsVoidType()) |
| 1135 | return CompilerType(); |
| 1136 | if (transparent_pointers && pointee.IsAggregateType()) |
| 1137 | { |
| 1138 | bool tmp_child_is_deref_of_parent = false; |
Bruce Mitchener | 4ad8334 | 2015-09-21 16:48:48 +0000 | [diff] [blame] | 1139 | return pointee.GetChildCompilerTypeAtIndex(exe_ctx, idx, transparent_pointers, omit_empty_base_classes, |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 1140 | ignore_array_bounds, child_name, child_byte_size, child_byte_offset, |
| 1141 | child_bitfield_bit_size, child_bitfield_bit_offset, |
| 1142 | child_is_base_class, tmp_child_is_deref_of_parent, valobj); |
| 1143 | } |
| 1144 | else |
| 1145 | { |
| 1146 | child_is_deref_of_parent = true; |
| 1147 | const char *parent_name = valobj ? valobj->GetName().GetCString() : NULL; |
| 1148 | if (parent_name) |
| 1149 | { |
| 1150 | child_name.assign(1, '*'); |
| 1151 | child_name += parent_name; |
| 1152 | } |
| 1153 | |
| 1154 | // We have a pointer to an simple type |
| 1155 | if (idx == 0 && pointee.GetCompleteType()) |
| 1156 | { |
| 1157 | child_byte_size = pointee.GetByteSize(exe_ctx ? exe_ctx->GetBestExecutionContextScope() : NULL); |
| 1158 | child_byte_offset = 0; |
| 1159 | return pointee; |
| 1160 | } |
| 1161 | } |
| 1162 | } |
| 1163 | else if (GoArray *a = t->GetArray()) |
| 1164 | { |
| 1165 | if (ignore_array_bounds || idx < a->GetLength()) |
| 1166 | { |
| 1167 | CompilerType element_type = a->GetElementType(); |
| 1168 | if (element_type.GetCompleteType()) |
| 1169 | { |
| 1170 | char element_name[64]; |
| 1171 | ::snprintf(element_name, sizeof(element_name), "[%zu]", idx); |
| 1172 | child_name.assign(element_name); |
| 1173 | child_byte_size = element_type.GetByteSize(exe_ctx ? exe_ctx->GetBestExecutionContextScope() : NULL); |
| 1174 | child_byte_offset = (int32_t)idx * (int32_t)child_byte_size; |
| 1175 | return element_type; |
| 1176 | } |
| 1177 | } |
| 1178 | } |
| 1179 | else if (t->IsTypedef()) |
| 1180 | { |
Bruce Mitchener | 4ad8334 | 2015-09-21 16:48:48 +0000 | [diff] [blame] | 1181 | return t->GetElementType().GetChildCompilerTypeAtIndex( |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 1182 | exe_ctx, idx, transparent_pointers, omit_empty_base_classes, ignore_array_bounds, child_name, |
| 1183 | child_byte_size, child_byte_offset, child_bitfield_bit_size, child_bitfield_bit_offset, child_is_base_class, |
| 1184 | child_is_deref_of_parent, valobj); |
| 1185 | } |
| 1186 | return CompilerType(); |
| 1187 | } |
| 1188 | |
| 1189 | // Lookup a child given a name. This function will match base class names |
| 1190 | // and member member names in "clang_type" only, not descendants. |
| 1191 | uint32_t |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 1192 | 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] | 1193 | { |
Ryan Brown | 07a1c45 | 2015-10-06 20:29:31 +0000 | [diff] [blame] | 1194 | if (!type || !GetCompleteType(type)) |
| 1195 | return UINT_MAX; |
| 1196 | |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 1197 | GoType *t = static_cast<GoType *>(type); |
| 1198 | GoStruct *s = t->GetStruct(); |
| 1199 | if (s) |
| 1200 | { |
| 1201 | for (uint32_t i = 0; i < s->GetNumFields(); ++i) |
| 1202 | { |
| 1203 | const GoStruct::Field *f = s->GetField(i); |
| 1204 | if (f->m_name.GetStringRef() == name) |
| 1205 | return i; |
| 1206 | } |
| 1207 | } |
| 1208 | else if (t->GetGoKind() == GoType::KIND_PTR || t->IsTypedef()) |
| 1209 | { |
| 1210 | return t->GetElementType().GetIndexOfChildWithName(name, omit_empty_base_classes); |
| 1211 | } |
| 1212 | return UINT_MAX; |
| 1213 | } |
| 1214 | |
| 1215 | // Lookup a child member given a name. This function will match member names |
| 1216 | // only and will descend into "clang_type" children in search for the first |
| 1217 | // member in this class, or any base class that matches "name". |
| 1218 | // TODO: Return all matches for a given name by returning a vector<vector<uint32_t>> |
| 1219 | // so we catch all names that match a given child name, not just the first. |
| 1220 | size_t |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 1221 | 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] | 1222 | std::vector<uint32_t> &child_indexes) |
| 1223 | { |
| 1224 | uint32_t index = GetIndexOfChildWithName(type, name, omit_empty_base_classes); |
| 1225 | if (index == UINT_MAX) |
| 1226 | return 0; |
| 1227 | child_indexes.push_back(index); |
| 1228 | return 1; |
| 1229 | } |
| 1230 | |
| 1231 | // Converts "s" to a floating point value and place resulting floating |
| 1232 | // point bytes in the "dst" buffer. |
| 1233 | size_t |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 1234 | 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] | 1235 | { |
| 1236 | assert(false); |
Ryan Brown | d03c2e0 | 2015-09-15 00:50:43 +0000 | [diff] [blame] | 1237 | return 0; |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 1238 | } |
| 1239 | //---------------------------------------------------------------------- |
| 1240 | // Dumping types |
| 1241 | //---------------------------------------------------------------------- |
| 1242 | void |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 1243 | 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] | 1244 | const DataExtractor &data, lldb::offset_t data_offset, size_t data_byte_size, |
| 1245 | uint32_t bitfield_bit_size, uint32_t bitfield_bit_offset, bool show_types, bool show_summary, |
| 1246 | bool verbose, uint32_t depth) |
| 1247 | { |
| 1248 | assert(false); |
| 1249 | } |
| 1250 | |
| 1251 | bool |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 1252 | 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] | 1253 | lldb::offset_t byte_offset, size_t byte_size, uint32_t bitfield_bit_size, |
| 1254 | uint32_t bitfield_bit_offset, ExecutionContextScope *exe_scope) |
| 1255 | { |
| 1256 | if (!type) |
| 1257 | return false; |
| 1258 | if (IsAggregateType(type)) |
| 1259 | { |
| 1260 | return false; |
| 1261 | } |
| 1262 | else |
| 1263 | { |
| 1264 | GoType *t = static_cast<GoType *>(type); |
| 1265 | if (t->IsTypedef()) |
| 1266 | { |
Bruce Mitchener | 3ad353f | 2015-09-24 03:54:50 +0000 | [diff] [blame] | 1267 | CompilerType typedef_compiler_type = t->GetElementType(); |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 1268 | if (format == eFormatDefault) |
Bruce Mitchener | 3ad353f | 2015-09-24 03:54:50 +0000 | [diff] [blame] | 1269 | format = typedef_compiler_type.GetFormat(); |
| 1270 | uint64_t typedef_byte_size = typedef_compiler_type.GetByteSize(exe_scope); |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 1271 | |
Bruce Mitchener | 3ad353f | 2015-09-24 03:54:50 +0000 | [diff] [blame] | 1272 | return typedef_compiler_type.DumpTypeValue( |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 1273 | s, |
| 1274 | format, // The format with which to display the element |
| 1275 | data, // Data buffer containing all bytes for this type |
| 1276 | byte_offset, // Offset into "data" where to grab value from |
| 1277 | typedef_byte_size, // Size of this type in bytes |
| 1278 | bitfield_bit_size, // Size in bits of a bitfield value, if zero don't treat as a bitfield |
| 1279 | bitfield_bit_offset, // Offset in bits of a bitfield value if bitfield_bit_size != 0 |
| 1280 | exe_scope); |
| 1281 | } |
| 1282 | |
| 1283 | uint32_t item_count = 1; |
| 1284 | // A few formats, we might need to modify our size and count for depending |
| 1285 | // on how we are trying to display the value... |
| 1286 | switch (format) |
| 1287 | { |
| 1288 | default: |
| 1289 | case eFormatBoolean: |
| 1290 | case eFormatBinary: |
| 1291 | case eFormatComplex: |
| 1292 | case eFormatCString: // NULL terminated C strings |
| 1293 | case eFormatDecimal: |
| 1294 | case eFormatEnum: |
| 1295 | case eFormatHex: |
| 1296 | case eFormatHexUppercase: |
| 1297 | case eFormatFloat: |
| 1298 | case eFormatOctal: |
| 1299 | case eFormatOSType: |
| 1300 | case eFormatUnsigned: |
| 1301 | case eFormatPointer: |
| 1302 | case eFormatVectorOfChar: |
| 1303 | case eFormatVectorOfSInt8: |
| 1304 | case eFormatVectorOfUInt8: |
| 1305 | case eFormatVectorOfSInt16: |
| 1306 | case eFormatVectorOfUInt16: |
| 1307 | case eFormatVectorOfSInt32: |
| 1308 | case eFormatVectorOfUInt32: |
| 1309 | case eFormatVectorOfSInt64: |
| 1310 | case eFormatVectorOfUInt64: |
| 1311 | case eFormatVectorOfFloat32: |
| 1312 | case eFormatVectorOfFloat64: |
| 1313 | case eFormatVectorOfUInt128: |
| 1314 | break; |
| 1315 | |
| 1316 | case eFormatChar: |
| 1317 | case eFormatCharPrintable: |
| 1318 | case eFormatCharArray: |
| 1319 | case eFormatBytes: |
| 1320 | case eFormatBytesWithASCII: |
| 1321 | item_count = byte_size; |
| 1322 | byte_size = 1; |
| 1323 | break; |
| 1324 | |
| 1325 | case eFormatUnicode16: |
| 1326 | item_count = byte_size / 2; |
| 1327 | byte_size = 2; |
| 1328 | break; |
| 1329 | |
| 1330 | case eFormatUnicode32: |
| 1331 | item_count = byte_size / 4; |
| 1332 | byte_size = 4; |
| 1333 | break; |
| 1334 | } |
| 1335 | return data.Dump(s, byte_offset, format, byte_size, item_count, UINT32_MAX, LLDB_INVALID_ADDRESS, |
| 1336 | bitfield_bit_size, bitfield_bit_offset, exe_scope); |
| 1337 | } |
| 1338 | return 0; |
| 1339 | } |
| 1340 | |
| 1341 | void |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 1342 | 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] | 1343 | lldb::offset_t data_offset, size_t data_byte_size) |
| 1344 | { |
| 1345 | assert(false); |
| 1346 | } |
| 1347 | |
| 1348 | void |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 1349 | GoASTContext::DumpTypeDescription(lldb::opaque_compiler_type_t type) |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 1350 | { |
| 1351 | assert(false); |
| 1352 | } // Dump to stdout |
| 1353 | |
| 1354 | void |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 1355 | GoASTContext::DumpTypeDescription(lldb::opaque_compiler_type_t type, Stream *s) |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 1356 | { |
| 1357 | assert(false); |
| 1358 | } |
| 1359 | |
| 1360 | CompilerType |
Bruce Mitchener | 500737e | 2015-09-15 04:33:48 +0000 | [diff] [blame] | 1361 | GoASTContext::CreateArrayType(const ConstString &name, const CompilerType &element_type, uint64_t length) |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 1362 | { |
| 1363 | GoType *type = new GoArray(name, length, element_type); |
| 1364 | (*m_types)[name].reset(type); |
| 1365 | return CompilerType(this, type); |
| 1366 | } |
| 1367 | |
| 1368 | CompilerType |
| 1369 | GoASTContext::CreateBaseType(int go_kind, const lldb_private::ConstString &name, uint64_t byte_size) |
| 1370 | { |
| 1371 | if (go_kind == GoType::KIND_UINT || go_kind == GoType::KIND_INT) |
| 1372 | m_int_byte_size = byte_size; |
| 1373 | GoType *type = new GoType(go_kind, name); |
| 1374 | (*m_types)[name].reset(type); |
| 1375 | return CompilerType(this, type); |
| 1376 | } |
| 1377 | |
| 1378 | CompilerType |
Greg Clayton | 56939cb | 2015-09-17 22:23:34 +0000 | [diff] [blame] | 1379 | GoASTContext::CreateTypedefType(int kind, const ConstString &name, CompilerType impl) |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 1380 | { |
| 1381 | GoType *type = new GoElem(kind, name, impl); |
| 1382 | (*m_types)[name].reset(type); |
| 1383 | return CompilerType(this, type); |
| 1384 | } |
| 1385 | |
| 1386 | CompilerType |
| 1387 | GoASTContext::CreateVoidType(const lldb_private::ConstString &name) |
| 1388 | { |
| 1389 | GoType *type = new GoType(GoType::KIND_LLDB_VOID, name); |
| 1390 | (*m_types)[name].reset(type); |
| 1391 | return CompilerType(this, type); |
| 1392 | } |
| 1393 | |
| 1394 | CompilerType |
| 1395 | GoASTContext::CreateStructType(int kind, const lldb_private::ConstString &name, uint32_t byte_size) |
| 1396 | { |
| 1397 | GoType *type = new GoStruct(kind, name, byte_size); |
| 1398 | (*m_types)[name].reset(type); |
| 1399 | return CompilerType(this, type); |
| 1400 | } |
| 1401 | |
| 1402 | void |
| 1403 | GoASTContext::AddFieldToStruct(const lldb_private::CompilerType &struct_type, const lldb_private::ConstString &name, |
| 1404 | const lldb_private::CompilerType &field_type, uint32_t byte_offset) |
| 1405 | { |
| 1406 | if (!struct_type) |
| 1407 | return; |
| 1408 | GoASTContext *ast = llvm::dyn_cast_or_null<GoASTContext>(struct_type.GetTypeSystem()); |
| 1409 | if (!ast) |
| 1410 | return; |
| 1411 | GoType *type = static_cast<GoType *>(struct_type.GetOpaqueQualType()); |
| 1412 | if (GoStruct *s = type->GetStruct()) |
| 1413 | s->AddField(name, field_type, byte_offset); |
| 1414 | } |
| 1415 | |
| 1416 | void |
| 1417 | GoASTContext::CompleteStructType(const lldb_private::CompilerType &struct_type) |
| 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->SetComplete(); |
| 1427 | } |
| 1428 | |
| 1429 | CompilerType |
| 1430 | GoASTContext::CreateFunctionType(const lldb_private::ConstString &name, CompilerType *params, size_t params_count, |
| 1431 | bool is_variadic) |
| 1432 | { |
| 1433 | GoType *type = new GoFunction(name, is_variadic); |
| 1434 | (*m_types)[name].reset(type); |
| 1435 | return CompilerType(this, type); |
| 1436 | } |
| 1437 | |
| 1438 | bool |
| 1439 | GoASTContext::IsGoString(const lldb_private::CompilerType &type) |
| 1440 | { |
| 1441 | if (!type.IsValid() || !llvm::dyn_cast_or_null<GoASTContext>(type.GetTypeSystem())) |
| 1442 | return false; |
| 1443 | return GoType::KIND_STRING == static_cast<GoType *>(type.GetOpaqueQualType())->GetGoKind(); |
| 1444 | } |
| 1445 | |
| 1446 | bool |
| 1447 | GoASTContext::IsGoSlice(const lldb_private::CompilerType &type) |
| 1448 | { |
| 1449 | if (!type.IsValid() || !llvm::dyn_cast_or_null<GoASTContext>(type.GetTypeSystem())) |
| 1450 | return false; |
| 1451 | return GoType::KIND_SLICE == static_cast<GoType *>(type.GetOpaqueQualType())->GetGoKind(); |
| 1452 | } |
| 1453 | |
| 1454 | bool |
| 1455 | GoASTContext::IsGoInterface(const lldb_private::CompilerType &type) |
| 1456 | { |
| 1457 | if (!type.IsValid() || !llvm::dyn_cast_or_null<GoASTContext>(type.GetTypeSystem())) |
| 1458 | return false; |
| 1459 | return GoType::KIND_INTERFACE == static_cast<GoType *>(type.GetOpaqueQualType())->GetGoKind(); |
| 1460 | } |
| 1461 | |
| 1462 | bool |
| 1463 | GoASTContext::IsPointerKind(uint8_t kind) |
| 1464 | { |
| 1465 | return (kind & GoType::KIND_MASK) == GoType::KIND_PTR; |
| 1466 | } |
| 1467 | |
| 1468 | bool |
| 1469 | GoASTContext::IsDirectIface(uint8_t kind) |
| 1470 | { |
| 1471 | return (kind & GoType::KIND_DIRECT_IFACE) == GoType::KIND_DIRECT_IFACE; |
| 1472 | } |
| 1473 | |
| 1474 | DWARFASTParser * |
| 1475 | GoASTContext::GetDWARFParser() |
| 1476 | { |
| 1477 | if (!m_dwarf_ast_parser_ap) |
| 1478 | m_dwarf_ast_parser_ap.reset(new DWARFASTParserGo(*this)); |
| 1479 | return m_dwarf_ast_parser_ap.get(); |
| 1480 | } |