blob: a765bb795acf7087bcde74880e29f77fc6f84da3 [file] [log] [blame]
Zachary Turner42dff792016-04-15 00:21:26 +00001//===-- PDBASTParser.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 "PDBASTParser.h"
11
12#include "clang/AST/CharUnits.h"
13#include "clang/AST/Decl.h"
14#include "clang/AST/DeclCXX.h"
15
16#include "lldb/Symbol/ClangASTContext.h"
17#include "lldb/Symbol/ClangUtil.h"
18#include "lldb/Symbol/Declaration.h"
19#include "lldb/Symbol/SymbolFile.h"
20#include "lldb/Symbol/TypeSystem.h"
21
Aaron Smith7ac1c782018-02-09 05:31:28 +000022#include "llvm/DebugInfo/PDB/IPDBLineNumber.h"
23#include "llvm/DebugInfo/PDB/IPDBSourceFile.h"
Zachary Turner42dff792016-04-15 00:21:26 +000024#include "llvm/DebugInfo/PDB/PDBSymbol.h"
25#include "llvm/DebugInfo/PDB/PDBSymbolData.h"
Aaron Smith7ac1c782018-02-09 05:31:28 +000026#include "llvm/DebugInfo/PDB/PDBSymbolFunc.h"
Zachary Turner42dff792016-04-15 00:21:26 +000027#include "llvm/DebugInfo/PDB/PDBSymbolTypeArray.h"
28#include "llvm/DebugInfo/PDB/PDBSymbolTypeBuiltin.h"
29#include "llvm/DebugInfo/PDB/PDBSymbolTypeEnum.h"
30#include "llvm/DebugInfo/PDB/PDBSymbolTypeFunctionArg.h"
31#include "llvm/DebugInfo/PDB/PDBSymbolTypeFunctionSig.h"
Aaron Smithec40f812018-01-23 20:35:19 +000032#include "llvm/DebugInfo/PDB/PDBSymbolTypePointer.h"
Zachary Turner42dff792016-04-15 00:21:26 +000033#include "llvm/DebugInfo/PDB/PDBSymbolTypeTypedef.h"
34#include "llvm/DebugInfo/PDB/PDBSymbolTypeUDT.h"
35
36using namespace lldb;
37using namespace lldb_private;
Zachary Turner54fd7ff2016-05-04 20:33:53 +000038using namespace llvm::pdb;
Zachary Turner42dff792016-04-15 00:21:26 +000039
Kate Stoneb9c1b512016-09-06 20:57:50 +000040namespace {
41int TranslateUdtKind(PDB_UdtType pdb_kind) {
42 switch (pdb_kind) {
43 case PDB_UdtType::Class:
Zachary Turner42dff792016-04-15 00:21:26 +000044 return clang::TTK_Class;
Kate Stoneb9c1b512016-09-06 20:57:50 +000045 case PDB_UdtType::Struct:
46 return clang::TTK_Struct;
47 case PDB_UdtType::Union:
48 return clang::TTK_Union;
49 case PDB_UdtType::Interface:
50 return clang::TTK_Interface;
51 }
Aaron Smithec40f812018-01-23 20:35:19 +000052 return -1;
Zachary Turner42dff792016-04-15 00:21:26 +000053}
54
Kate Stoneb9c1b512016-09-06 20:57:50 +000055lldb::Encoding TranslateBuiltinEncoding(PDB_BuiltinType type) {
56 switch (type) {
57 case PDB_BuiltinType::Float:
58 return lldb::eEncodingIEEE754;
59 case PDB_BuiltinType::Int:
60 case PDB_BuiltinType::Long:
61 case PDB_BuiltinType::Char:
62 return lldb::eEncodingSint;
63 case PDB_BuiltinType::Bool:
64 case PDB_BuiltinType::UInt:
65 case PDB_BuiltinType::ULong:
66 case PDB_BuiltinType::HResult:
67 return lldb::eEncodingUint;
68 default:
69 return lldb::eEncodingInvalid;
70 }
Zachary Turner42dff792016-04-15 00:21:26 +000071}
Aaron Smithec40f812018-01-23 20:35:19 +000072
73lldb::Encoding TranslateEnumEncoding(PDB_VariantType type) {
74 switch (type) {
75 case PDB_VariantType::Int8:
76 case PDB_VariantType::Int16:
77 case PDB_VariantType::Int32:
78 case PDB_VariantType::Int64:
79 return lldb::eEncodingSint;
80
81 case PDB_VariantType::UInt8:
82 case PDB_VariantType::UInt16:
83 case PDB_VariantType::UInt32:
84 case PDB_VariantType::UInt64:
85 return lldb::eEncodingUint;
86
87 default:
88 break;
89 }
90
91 return lldb::eEncodingSint;
92}
93
94CompilerType GetBuiltinTypeForPDBEncodingAndBitSize(
95 ClangASTContext *clang_ast, const PDBSymbolTypeBuiltin *pdb_type,
96 Encoding encoding, uint32_t width) {
97 if (!pdb_type)
98 return CompilerType();
99 if (!clang_ast)
100 return CompilerType();
101 auto *ast = clang_ast->getASTContext();
102 if (!ast)
103 return CompilerType();
104
105 switch (pdb_type->getBuiltinType()) {
106 default: break;
107 case PDB_BuiltinType::None:
108 return CompilerType();
109 case PDB_BuiltinType::Void:
110 // FIXME: where is non-zero size of `void` from?
111 if (width == 0)
112 return clang_ast->GetBasicType(eBasicTypeVoid);
113 case PDB_BuiltinType::Bool:
114 return clang_ast->GetBasicType(eBasicTypeBool);
115 case PDB_BuiltinType::Long:
116 if (width == ast->getTypeSize(ast->LongTy))
117 return CompilerType(ast, ast->LongTy);
118 if (width == ast->getTypeSize(ast->LongLongTy))
119 return CompilerType(ast, ast->LongLongTy);
120 break;
121 case PDB_BuiltinType::ULong:
122 if (width == ast->getTypeSize(ast->UnsignedLongTy))
123 return CompilerType(ast, ast->UnsignedLongTy);
124 if (width == ast->getTypeSize(ast->UnsignedLongLongTy))
125 return CompilerType(ast, ast->UnsignedLongLongTy);
126 break;
127 case PDB_BuiltinType::WCharT:
128 if (width == ast->getTypeSize(ast->WCharTy))
129 return CompilerType(ast, ast->WCharTy);
130 break;
131 case PDB_BuiltinType::Float:
132 // Note: types `long double` and `double` have same bit size in MSVC and there
133 // is no information in the PDB to distinguish them. So when falling back
134 // to default search, the compiler type of `long double` will be represented by
135 // the one generated for `double`.
136 break;
137 }
138 // If there is no match on PDB_BuiltinType, fall back to default search
139 // by encoding and width only
140 return clang_ast->GetBuiltinTypeForEncodingAndBitSize(encoding, width);
141}
142
143ConstString GetPDBBuiltinTypeName(const PDBSymbolTypeBuiltin *pdb_type,
144 CompilerType &compiler_type) {
145 if (!pdb_type)
146 return compiler_type.GetTypeName();
147
148 PDB_BuiltinType kind = pdb_type->getBuiltinType();
149 switch (kind) {
150 default: break;
151 case PDB_BuiltinType::Currency:
152 return ConstString("CURRENCY");
153 case PDB_BuiltinType::Date:
154 return ConstString("DATE");
155 case PDB_BuiltinType::Variant:
156 return ConstString("VARIANT");
157 case PDB_BuiltinType::Complex:
158 return ConstString("complex");
159 case PDB_BuiltinType::Bitfield:
160 return ConstString("bitfield");
161 case PDB_BuiltinType::BSTR:
162 return ConstString("BSTR");
163 case PDB_BuiltinType::HResult:
164 return ConstString("HRESULT");
165 case PDB_BuiltinType::BCD:
166 return ConstString("BCD");
167 case PDB_BuiltinType::None:
168 return ConstString("...");
169 }
170 return compiler_type.GetTypeName();
171}
Aaron Smith7ac1c782018-02-09 05:31:28 +0000172
173bool GetDeclarationForSymbol(const PDBSymbol &symbol, Declaration &decl) {
174 auto &raw_sym = symbol.getRawSymbol();
175 auto lines_up = symbol.getSession().findLineNumbersByAddress(
176 raw_sym.getVirtualAddress(), raw_sym.getLength());
177 if (!lines_up)
178 return false;
179 auto first_line_up = lines_up->getNext();
180 if (!first_line_up)
181 return false;
182
183 uint32_t src_file_id = first_line_up->getSourceFileId();
184 auto src_file_up = symbol.getSession().getSourceFileById(src_file_id);
185 if (!src_file_up)
186 return false;
187
188 FileSpec spec(src_file_up->getFileName(), /*resolve_path*/false);
189 decl.SetFile(spec);
190 decl.SetColumn(first_line_up->getColumnNumber());
191 decl.SetLine(first_line_up->getLineNumber());
192 return true;
193}
Zachary Turner42dff792016-04-15 00:21:26 +0000194}
195
Kate Stoneb9c1b512016-09-06 20:57:50 +0000196PDBASTParser::PDBASTParser(lldb_private::ClangASTContext &ast) : m_ast(ast) {}
Zachary Turner42dff792016-04-15 00:21:26 +0000197
Kate Stoneb9c1b512016-09-06 20:57:50 +0000198PDBASTParser::~PDBASTParser() {}
Zachary Turner42dff792016-04-15 00:21:26 +0000199
200// DebugInfoASTParser interface
201
Kate Stoneb9c1b512016-09-06 20:57:50 +0000202lldb::TypeSP PDBASTParser::CreateLLDBTypeFromPDBType(const PDBSymbol &type) {
203 // PDB doesn't maintain enough information to robustly rebuild the entire
204 // tree, and this is most problematic when it comes to figure out the
205 // right DeclContext to put a type in. So for now, everything goes in
206 // the translation unit decl as a fully qualified type.
207 clang::DeclContext *tu_decl_ctx = m_ast.GetTranslationUnitDecl();
208 Declaration decl;
Zachary Turner42dff792016-04-15 00:21:26 +0000209
Aaron Smith7ac1c782018-02-09 05:31:28 +0000210 switch (type.getSymTag()) {
211 case PDB_SymType::UDT: {
212 auto udt = llvm::dyn_cast<PDBSymbolTypeUDT>(&type);
213 assert(udt);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000214 AccessType access = lldb::eAccessPublic;
215 PDB_UdtType udt_kind = udt->getUdtKind();
Aaron Smithec40f812018-01-23 20:35:19 +0000216 auto tag_type_kind = TranslateUdtKind(udt_kind);
217 if (tag_type_kind == -1)
218 return nullptr;
Zachary Turner42dff792016-04-15 00:21:26 +0000219
Kate Stoneb9c1b512016-09-06 20:57:50 +0000220 if (udt_kind == PDB_UdtType::Class)
221 access = lldb::eAccessPrivate;
Zachary Turner42dff792016-04-15 00:21:26 +0000222
Kate Stoneb9c1b512016-09-06 20:57:50 +0000223 CompilerType clang_type = m_ast.CreateRecordType(
Aaron Smithec40f812018-01-23 20:35:19 +0000224 tu_decl_ctx, access, udt->getName().c_str(), tag_type_kind,
Kate Stoneb9c1b512016-09-06 20:57:50 +0000225 lldb::eLanguageTypeC_plus_plus, nullptr);
Zachary Turner42dff792016-04-15 00:21:26 +0000226
Kate Stoneb9c1b512016-09-06 20:57:50 +0000227 m_ast.SetHasExternalStorage(clang_type.GetOpaqueQualType(), true);
Zachary Turner42dff792016-04-15 00:21:26 +0000228
Saleem Abdulrasool6c135102017-09-09 00:13:49 +0000229 return std::make_shared<lldb_private::Type>(
230 type.getSymIndexId(), m_ast.GetSymbolFile(),
231 ConstString(udt->getName()), udt->getLength(), nullptr,
232 LLDB_INVALID_UID, lldb_private::Type::eEncodingIsUID, decl, clang_type,
233 lldb_private::Type::eResolveStateForward);
Aaron Smith7ac1c782018-02-09 05:31:28 +0000234 } break;
235 case PDB_SymType::Enum: {
236 auto enum_type = llvm::dyn_cast<PDBSymbolTypeEnum>(&type);
237 assert(enum_type);
Aaron Smithec40f812018-01-23 20:35:19 +0000238 auto underlying_type_up = enum_type->getUnderlyingType();
239 if (!underlying_type_up)
240 return nullptr;
Pavel Labath11d0b2942018-01-22 11:51:56 +0000241 lldb::Encoding encoding =
Aaron Smithec40f812018-01-23 20:35:19 +0000242 TranslateBuiltinEncoding(underlying_type_up->getBuiltinType());
243 // FIXME: Type of underlying builtin is always `Int`. We correct it with
244 // the very first enumerator's encoding if any.
245 auto first_child = enum_type->findOneChild<PDBSymbolData>();
246 if (first_child) {
247 encoding = TranslateEnumEncoding(first_child->getValue().Type);
248 }
249 std::string name = enum_type->getName();
Kate Stoneb9c1b512016-09-06 20:57:50 +0000250 uint64_t bytes = enum_type->getLength();
Aaron Smithec40f812018-01-23 20:35:19 +0000251 CompilerType builtin_type;
252 if (bytes > 0)
253 builtin_type = GetBuiltinTypeForPDBEncodingAndBitSize(
254 &m_ast, underlying_type_up.get(), encoding, bytes * 8);
255 else
256 builtin_type = m_ast.GetBasicType(eBasicTypeInt);
257 // FIXME: PDB does not have information about scoped enumeration (Enum Class).
258 // Set it false for now.
259 bool isScoped = false;
Kate Stoneb9c1b512016-09-06 20:57:50 +0000260
261 CompilerType ast_enum = m_ast.CreateEnumerationType(
Aaron Smithec40f812018-01-23 20:35:19 +0000262 name.c_str(), tu_decl_ctx, decl, builtin_type, isScoped);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000263 auto enum_values = enum_type->findAllChildren<PDBSymbolData>();
Aaron Smithec40f812018-01-23 20:35:19 +0000264 if (enum_values) {
265 while (auto enum_value = enum_values->getNext()) {
266 if (enum_value->getDataKind() != PDB_DataKind::Constant)
267 continue;
268 AddEnumValue(ast_enum, *enum_value);
269 }
Zachary Turner42dff792016-04-15 00:21:26 +0000270 }
Aaron Smithec40f812018-01-23 20:35:19 +0000271 if (ClangASTContext::StartTagDeclarationDefinition(ast_enum))
272 ClangASTContext::CompleteTagDeclarationDefinition(ast_enum);
Zachary Turner42dff792016-04-15 00:21:26 +0000273
Saleem Abdulrasool6c135102017-09-09 00:13:49 +0000274 return std::make_shared<lldb_private::Type>(
275 type.getSymIndexId(), m_ast.GetSymbolFile(), ConstString(name), bytes,
276 nullptr, LLDB_INVALID_UID, lldb_private::Type::eEncodingIsUID, decl,
277 ast_enum, lldb_private::Type::eResolveStateFull);
Aaron Smith7ac1c782018-02-09 05:31:28 +0000278 } break;
279 case PDB_SymType::Typedef: {
280 auto type_def = llvm::dyn_cast<PDBSymbolTypeTypedef>(&type);
281 assert(type_def);
Saleem Abdulrasool6c135102017-09-09 00:13:49 +0000282 lldb_private::Type *target_type =
Kate Stoneb9c1b512016-09-06 20:57:50 +0000283 m_ast.GetSymbolFile()->ResolveTypeUID(type_def->getTypeId());
Aaron Smith86e94342017-12-22 05:26:50 +0000284 if (!target_type)
285 return nullptr;
Kate Stoneb9c1b512016-09-06 20:57:50 +0000286 std::string name = type_def->getName();
287 uint64_t bytes = type_def->getLength();
Kate Stoneb9c1b512016-09-06 20:57:50 +0000288 CompilerType target_ast_type = target_type->GetFullCompilerType();
289 CompilerDeclContext target_decl_ctx =
290 m_ast.GetSymbolFile()->GetDeclContextForUID(target_type->GetID());
291 CompilerType ast_typedef =
292 m_ast.CreateTypedefType(target_ast_type, name.c_str(), target_decl_ctx);
Saleem Abdulrasool6c135102017-09-09 00:13:49 +0000293 return std::make_shared<lldb_private::Type>(
Kate Stoneb9c1b512016-09-06 20:57:50 +0000294 type_def->getSymIndexId(), m_ast.GetSymbolFile(), ConstString(name),
Saleem Abdulrasool6c135102017-09-09 00:13:49 +0000295 bytes, nullptr, target_type->GetID(),
296 lldb_private::Type::eEncodingIsTypedefUID, decl, ast_typedef,
297 lldb_private::Type::eResolveStateFull);
Aaron Smith7ac1c782018-02-09 05:31:28 +0000298 } break;
299 case PDB_SymType::Function:
300 case PDB_SymType::FunctionSig: {
301 std::string name;
302 PDBSymbolTypeFunctionSig *func_sig = nullptr;
303 if (auto pdb_func = llvm::dyn_cast<PDBSymbolFunc>(&type)) {
304 auto sig = pdb_func->getSignature();
305 if (!sig)
306 return nullptr;
307 func_sig = sig.release();
308 // Function type is named.
309 name = pdb_func->getName();
310 } else if (auto pdb_func_sig =
311 llvm::dyn_cast<PDBSymbolTypeFunctionSig>(&type)) {
312 func_sig = const_cast<PDBSymbolTypeFunctionSig*>(pdb_func_sig);
313 } else
314 llvm_unreachable("Unexpected PDB symbol!");
315
Kate Stoneb9c1b512016-09-06 20:57:50 +0000316 auto arg_enum = func_sig->getArguments();
317 uint32_t num_args = arg_enum->getChildCount();
Aaron Smithec40f812018-01-23 20:35:19 +0000318 std::vector<CompilerType> arg_list;
319
320 bool is_variadic = func_sig->isCVarArgs();
321 // Drop last variadic argument.
322 if (is_variadic)
323 --num_args;
Kirill Bobyrevde6fad62018-01-29 12:59:07 +0000324 for (uint32_t arg_idx = 0; arg_idx < num_args; arg_idx++) {
Aaron Smithec40f812018-01-23 20:35:19 +0000325 auto arg = arg_enum->getChildAtIndex(arg_idx);
326 if (!arg)
327 break;
Saleem Abdulrasool6c135102017-09-09 00:13:49 +0000328 lldb_private::Type *arg_type =
Kate Stoneb9c1b512016-09-06 20:57:50 +0000329 m_ast.GetSymbolFile()->ResolveTypeUID(arg->getSymIndexId());
330 // If there's some error looking up one of the dependent types of this
331 // function signature, bail.
332 if (!arg_type)
333 return nullptr;
334 CompilerType arg_ast_type = arg_type->GetFullCompilerType();
335 arg_list.push_back(arg_ast_type);
336 }
Aaron Smithec40f812018-01-23 20:35:19 +0000337 lldbassert(arg_list.size() <= num_args);
338
Kate Stoneb9c1b512016-09-06 20:57:50 +0000339 auto pdb_return_type = func_sig->getReturnType();
Saleem Abdulrasool6c135102017-09-09 00:13:49 +0000340 lldb_private::Type *return_type =
Kate Stoneb9c1b512016-09-06 20:57:50 +0000341 m_ast.GetSymbolFile()->ResolveTypeUID(pdb_return_type->getSymIndexId());
342 // If there's some error looking up one of the dependent types of this
343 // function signature, bail.
344 if (!return_type)
345 return nullptr;
346 CompilerType return_ast_type = return_type->GetFullCompilerType();
347 uint32_t type_quals = 0;
348 if (func_sig->isConstType())
349 type_quals |= clang::Qualifiers::Const;
350 if (func_sig->isVolatileType())
351 type_quals |= clang::Qualifiers::Volatile;
352 CompilerType func_sig_ast_type = m_ast.CreateFunctionType(
Aaron Smithec40f812018-01-23 20:35:19 +0000353 return_ast_type, arg_list.data(), arg_list.size(), is_variadic,
354 type_quals);
Zachary Turner42dff792016-04-15 00:21:26 +0000355
Aaron Smith7ac1c782018-02-09 05:31:28 +0000356 GetDeclarationForSymbol(type, decl);
Saleem Abdulrasool6c135102017-09-09 00:13:49 +0000357 return std::make_shared<lldb_private::Type>(
Aaron Smith7ac1c782018-02-09 05:31:28 +0000358 type.getSymIndexId(), m_ast.GetSymbolFile(), ConstString(name), 0,
Saleem Abdulrasool6c135102017-09-09 00:13:49 +0000359 nullptr, LLDB_INVALID_UID, lldb_private::Type::eEncodingIsUID, decl,
360 func_sig_ast_type, lldb_private::Type::eResolveStateFull);
Aaron Smith7ac1c782018-02-09 05:31:28 +0000361 } break;
362 case PDB_SymType::ArrayType: {
363 auto array_type = llvm::dyn_cast<PDBSymbolTypeArray>(&type);
364 assert(array_type);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000365 uint32_t num_elements = array_type->getCount();
366 uint32_t element_uid = array_type->getElementType()->getSymIndexId();
367 uint32_t bytes = array_type->getLength();
Zachary Turner42dff792016-04-15 00:21:26 +0000368
Saleem Abdulrasool6c135102017-09-09 00:13:49 +0000369 lldb_private::Type *element_type =
370 m_ast.GetSymbolFile()->ResolveTypeUID(element_uid);
Aaron Smith86e94342017-12-22 05:26:50 +0000371 if (!element_type)
372 return nullptr;
Kate Stoneb9c1b512016-09-06 20:57:50 +0000373 CompilerType element_ast_type = element_type->GetFullCompilerType();
374 CompilerType array_ast_type =
375 m_ast.CreateArrayType(element_ast_type, num_elements, false);
Saleem Abdulrasool6c135102017-09-09 00:13:49 +0000376 return std::make_shared<lldb_private::Type>(
Kate Stoneb9c1b512016-09-06 20:57:50 +0000377 array_type->getSymIndexId(), m_ast.GetSymbolFile(), ConstString(),
Saleem Abdulrasool6c135102017-09-09 00:13:49 +0000378 bytes, nullptr, LLDB_INVALID_UID, lldb_private::Type::eEncodingIsUID,
379 decl, array_ast_type, lldb_private::Type::eResolveStateFull);
Aaron Smith7ac1c782018-02-09 05:31:28 +0000380 } break;
381 case PDB_SymType::BuiltinType: {
382 auto *builtin_type = llvm::dyn_cast<PDBSymbolTypeBuiltin>(&type);
383 assert(builtin_type);
Aaron Smithec40f812018-01-23 20:35:19 +0000384 PDB_BuiltinType builtin_kind = builtin_type->getBuiltinType();
385 if (builtin_kind == PDB_BuiltinType::None)
386 return nullptr;
387
388 uint64_t bytes = builtin_type->getLength();
389 Encoding encoding = TranslateBuiltinEncoding(builtin_kind);
390 CompilerType builtin_ast_type = GetBuiltinTypeForPDBEncodingAndBitSize(
391 &m_ast, builtin_type, encoding, bytes * 8);
392
393 Type::EncodingDataType encoding_data_type = Type::eEncodingIsUID;
394 if (builtin_type->isConstType()) {
395 encoding_data_type = Type::eEncodingIsConstUID;
396 builtin_ast_type = builtin_ast_type.AddConstModifier();
397 }
398 if (builtin_type->isVolatileType()) {
399 encoding_data_type = Type::eEncodingIsVolatileUID;
400 builtin_ast_type = builtin_ast_type.AddVolatileModifier();
401 }
402 auto type_name = GetPDBBuiltinTypeName(builtin_type, builtin_ast_type);
403
404 return std::make_shared<lldb_private::Type>(
405 builtin_type->getSymIndexId(), m_ast.GetSymbolFile(), type_name,
406 bytes, nullptr, LLDB_INVALID_UID, encoding_data_type,
407 decl, builtin_ast_type, lldb_private::Type::eResolveStateFull);
Aaron Smith7ac1c782018-02-09 05:31:28 +0000408 } break;
409 case PDB_SymType::PointerType: {
410 auto *pointer_type = llvm::dyn_cast<PDBSymbolTypePointer>(&type);
411 assert(pointer_type);
Aaron Smithec40f812018-01-23 20:35:19 +0000412 Type *pointee_type = m_ast.GetSymbolFile()->ResolveTypeUID(
413 pointer_type->getPointeeType()->getSymIndexId());
414 if (!pointee_type)
415 return nullptr;
416
417 CompilerType pointer_ast_type;
418 Type::EncodingDataType encoding_data_type = Type::eEncodingIsPointerUID;
419 if (pointer_type->isReference()) {
420 encoding_data_type = Type::eEncodingIsLValueReferenceUID;
421 pointer_ast_type =
422 pointee_type->GetFullCompilerType().GetLValueReferenceType();
423 } else
424 pointer_ast_type = pointee_type->GetFullCompilerType().GetPointerType();
425
426 return std::make_shared<lldb_private::Type>(
427 pointer_type->getSymIndexId(), m_ast.GetSymbolFile(), ConstString(),
428 pointer_type->getLength(), nullptr, LLDB_INVALID_UID,
429 encoding_data_type, decl, pointer_ast_type,
430 lldb_private::Type::eResolveStateFull);
Aaron Smith7ac1c782018-02-09 05:31:28 +0000431 } break;
432 default: break;
Kate Stoneb9c1b512016-09-06 20:57:50 +0000433 }
434 return nullptr;
Zachary Turner42dff792016-04-15 00:21:26 +0000435}
436
Kate Stoneb9c1b512016-09-06 20:57:50 +0000437bool PDBASTParser::AddEnumValue(CompilerType enum_type,
438 const PDBSymbolData &enum_value) const {
439 Declaration decl;
440 Variant v = enum_value.getValue();
441 std::string name = enum_value.getName();
442 int64_t raw_value;
443 switch (v.Type) {
444 case PDB_VariantType::Int8:
445 raw_value = v.Value.Int8;
446 break;
447 case PDB_VariantType::Int16:
448 raw_value = v.Value.Int16;
449 break;
450 case PDB_VariantType::Int32:
451 raw_value = v.Value.Int32;
452 break;
453 case PDB_VariantType::Int64:
454 raw_value = v.Value.Int64;
455 break;
456 case PDB_VariantType::UInt8:
457 raw_value = v.Value.UInt8;
458 break;
459 case PDB_VariantType::UInt16:
460 raw_value = v.Value.UInt16;
461 break;
462 case PDB_VariantType::UInt32:
463 raw_value = v.Value.UInt32;
464 break;
465 case PDB_VariantType::UInt64:
466 raw_value = v.Value.UInt64;
467 break;
468 default:
469 return false;
470 }
471 CompilerType underlying_type =
472 m_ast.GetEnumerationIntegerType(enum_type.GetOpaqueQualType());
473 uint32_t byte_size = m_ast.getASTContext()->getTypeSize(
474 ClangUtil::GetQualType(underlying_type));
475 return m_ast.AddEnumerationValueToEnumerationType(
476 enum_type.GetOpaqueQualType(), underlying_type, decl, name.c_str(),
477 raw_value, byte_size * 8);
Zachary Turner42dff792016-04-15 00:21:26 +0000478}