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