blob: bf353a46f21683927f71eb4cbc0147d1c0ec8672 [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:
Aaron Smith2a989f32018-03-07 05:43:05 +000062 case PDB_BuiltinType::Char16:
63 case PDB_BuiltinType::Char32:
Kate Stoneb9c1b512016-09-06 20:57:50 +000064 return lldb::eEncodingSint;
65 case PDB_BuiltinType::Bool:
66 case PDB_BuiltinType::UInt:
67 case PDB_BuiltinType::ULong:
68 case PDB_BuiltinType::HResult:
69 return lldb::eEncodingUint;
70 default:
71 return lldb::eEncodingInvalid;
72 }
Zachary Turner42dff792016-04-15 00:21:26 +000073}
Aaron Smithec40f812018-01-23 20:35:19 +000074
75lldb::Encoding TranslateEnumEncoding(PDB_VariantType type) {
76 switch (type) {
77 case PDB_VariantType::Int8:
78 case PDB_VariantType::Int16:
79 case PDB_VariantType::Int32:
80 case PDB_VariantType::Int64:
81 return lldb::eEncodingSint;
82
83 case PDB_VariantType::UInt8:
84 case PDB_VariantType::UInt16:
85 case PDB_VariantType::UInt32:
86 case PDB_VariantType::UInt64:
87 return lldb::eEncodingUint;
88
89 default:
90 break;
91 }
92
93 return lldb::eEncodingSint;
94}
95
96CompilerType GetBuiltinTypeForPDBEncodingAndBitSize(
97 ClangASTContext *clang_ast, const PDBSymbolTypeBuiltin *pdb_type,
98 Encoding encoding, uint32_t width) {
99 if (!pdb_type)
100 return CompilerType();
101 if (!clang_ast)
102 return CompilerType();
103 auto *ast = clang_ast->getASTContext();
104 if (!ast)
105 return CompilerType();
106
107 switch (pdb_type->getBuiltinType()) {
108 default: break;
109 case PDB_BuiltinType::None:
110 return CompilerType();
111 case PDB_BuiltinType::Void:
Adrian McCarthy1e368d12018-02-14 23:16:36 +0000112 return clang_ast->GetBasicType(eBasicTypeVoid);
Aaron Smithec40f812018-01-23 20:35:19 +0000113 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;
Aaron Smith2a989f32018-03-07 05:43:05 +0000131 case PDB_BuiltinType::Char16:
132 return CompilerType(ast, ast->Char16Ty);
133 case PDB_BuiltinType::Char32:
134 return CompilerType(ast, ast->Char32Ty);
Aaron Smithec40f812018-01-23 20:35:19 +0000135 case PDB_BuiltinType::Float:
136 // Note: types `long double` and `double` have same bit size in MSVC and there
137 // is no information in the PDB to distinguish them. So when falling back
138 // to default search, the compiler type of `long double` will be represented by
139 // the one generated for `double`.
140 break;
141 }
142 // If there is no match on PDB_BuiltinType, fall back to default search
143 // by encoding and width only
144 return clang_ast->GetBuiltinTypeForEncodingAndBitSize(encoding, width);
145}
146
147ConstString GetPDBBuiltinTypeName(const PDBSymbolTypeBuiltin *pdb_type,
148 CompilerType &compiler_type) {
149 if (!pdb_type)
150 return compiler_type.GetTypeName();
151
152 PDB_BuiltinType kind = pdb_type->getBuiltinType();
153 switch (kind) {
154 default: break;
155 case PDB_BuiltinType::Currency:
156 return ConstString("CURRENCY");
157 case PDB_BuiltinType::Date:
158 return ConstString("DATE");
159 case PDB_BuiltinType::Variant:
160 return ConstString("VARIANT");
161 case PDB_BuiltinType::Complex:
162 return ConstString("complex");
163 case PDB_BuiltinType::Bitfield:
164 return ConstString("bitfield");
165 case PDB_BuiltinType::BSTR:
166 return ConstString("BSTR");
167 case PDB_BuiltinType::HResult:
168 return ConstString("HRESULT");
169 case PDB_BuiltinType::BCD:
170 return ConstString("BCD");
Aaron Smith2a989f32018-03-07 05:43:05 +0000171 case PDB_BuiltinType::Char16:
172 return ConstString("char16_t");
173 case PDB_BuiltinType::Char32:
174 return ConstString("char32_t");
Aaron Smithec40f812018-01-23 20:35:19 +0000175 case PDB_BuiltinType::None:
176 return ConstString("...");
177 }
178 return compiler_type.GetTypeName();
179}
Aaron Smith7ac1c782018-02-09 05:31:28 +0000180
181bool GetDeclarationForSymbol(const PDBSymbol &symbol, Declaration &decl) {
182 auto &raw_sym = symbol.getRawSymbol();
Aaron Smith7abdf2d2018-03-07 00:35:27 +0000183 auto first_line_up = raw_sym.getSrcLineOnTypeDefn();
Aaron Smith7ac1c782018-02-09 05:31:28 +0000184
Aaron Smith7abdf2d2018-03-07 00:35:27 +0000185 if (!first_line_up) {
186 auto lines_up = symbol.getSession().findLineNumbersByAddress(
187 raw_sym.getVirtualAddress(), raw_sym.getLength());
188 if (!lines_up)
189 return false;
190 first_line_up = lines_up->getNext();
191 if (!first_line_up)
192 return false;
193 }
Aaron Smith7ac1c782018-02-09 05:31:28 +0000194 uint32_t src_file_id = first_line_up->getSourceFileId();
195 auto src_file_up = symbol.getSession().getSourceFileById(src_file_id);
196 if (!src_file_up)
197 return false;
198
199 FileSpec spec(src_file_up->getFileName(), /*resolve_path*/false);
200 decl.SetFile(spec);
201 decl.SetColumn(first_line_up->getColumnNumber());
202 decl.SetLine(first_line_up->getLineNumber());
203 return true;
204}
Zachary Turner42dff792016-04-15 00:21:26 +0000205}
206
Kate Stoneb9c1b512016-09-06 20:57:50 +0000207PDBASTParser::PDBASTParser(lldb_private::ClangASTContext &ast) : m_ast(ast) {}
Zachary Turner42dff792016-04-15 00:21:26 +0000208
Kate Stoneb9c1b512016-09-06 20:57:50 +0000209PDBASTParser::~PDBASTParser() {}
Zachary Turner42dff792016-04-15 00:21:26 +0000210
211// DebugInfoASTParser interface
212
Kate Stoneb9c1b512016-09-06 20:57:50 +0000213lldb::TypeSP PDBASTParser::CreateLLDBTypeFromPDBType(const PDBSymbol &type) {
214 // PDB doesn't maintain enough information to robustly rebuild the entire
215 // tree, and this is most problematic when it comes to figure out the
216 // right DeclContext to put a type in. So for now, everything goes in
217 // the translation unit decl as a fully qualified type.
218 clang::DeclContext *tu_decl_ctx = m_ast.GetTranslationUnitDecl();
219 Declaration decl;
Zachary Turner42dff792016-04-15 00:21:26 +0000220
Aaron Smith7ac1c782018-02-09 05:31:28 +0000221 switch (type.getSymTag()) {
222 case PDB_SymType::UDT: {
223 auto udt = llvm::dyn_cast<PDBSymbolTypeUDT>(&type);
224 assert(udt);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000225 AccessType access = lldb::eAccessPublic;
226 PDB_UdtType udt_kind = udt->getUdtKind();
Aaron Smithec40f812018-01-23 20:35:19 +0000227 auto tag_type_kind = TranslateUdtKind(udt_kind);
228 if (tag_type_kind == -1)
229 return nullptr;
Zachary Turner42dff792016-04-15 00:21:26 +0000230
Kate Stoneb9c1b512016-09-06 20:57:50 +0000231 if (udt_kind == PDB_UdtType::Class)
232 access = lldb::eAccessPrivate;
Zachary Turner42dff792016-04-15 00:21:26 +0000233
Kate Stoneb9c1b512016-09-06 20:57:50 +0000234 CompilerType clang_type = m_ast.CreateRecordType(
Aaron Smithec40f812018-01-23 20:35:19 +0000235 tu_decl_ctx, access, udt->getName().c_str(), tag_type_kind,
Kate Stoneb9c1b512016-09-06 20:57:50 +0000236 lldb::eLanguageTypeC_plus_plus, nullptr);
Zachary Turner42dff792016-04-15 00:21:26 +0000237
Kate Stoneb9c1b512016-09-06 20:57:50 +0000238 m_ast.SetHasExternalStorage(clang_type.GetOpaqueQualType(), true);
Zachary Turner42dff792016-04-15 00:21:26 +0000239
Saleem Abdulrasool6c135102017-09-09 00:13:49 +0000240 return std::make_shared<lldb_private::Type>(
241 type.getSymIndexId(), m_ast.GetSymbolFile(),
242 ConstString(udt->getName()), udt->getLength(), nullptr,
243 LLDB_INVALID_UID, lldb_private::Type::eEncodingIsUID, decl, clang_type,
244 lldb_private::Type::eResolveStateForward);
Aaron Smith7ac1c782018-02-09 05:31:28 +0000245 } break;
246 case PDB_SymType::Enum: {
247 auto enum_type = llvm::dyn_cast<PDBSymbolTypeEnum>(&type);
248 assert(enum_type);
Aaron Smithec40f812018-01-23 20:35:19 +0000249 auto underlying_type_up = enum_type->getUnderlyingType();
250 if (!underlying_type_up)
251 return nullptr;
Pavel Labath11d0b2942018-01-22 11:51:56 +0000252 lldb::Encoding encoding =
Aaron Smithec40f812018-01-23 20:35:19 +0000253 TranslateBuiltinEncoding(underlying_type_up->getBuiltinType());
254 // FIXME: Type of underlying builtin is always `Int`. We correct it with
255 // the very first enumerator's encoding if any.
256 auto first_child = enum_type->findOneChild<PDBSymbolData>();
257 if (first_child) {
258 encoding = TranslateEnumEncoding(first_child->getValue().Type);
259 }
260 std::string name = enum_type->getName();
Kate Stoneb9c1b512016-09-06 20:57:50 +0000261 uint64_t bytes = enum_type->getLength();
Aaron Smithec40f812018-01-23 20:35:19 +0000262 CompilerType builtin_type;
263 if (bytes > 0)
264 builtin_type = GetBuiltinTypeForPDBEncodingAndBitSize(
265 &m_ast, underlying_type_up.get(), encoding, bytes * 8);
266 else
267 builtin_type = m_ast.GetBasicType(eBasicTypeInt);
268 // FIXME: PDB does not have information about scoped enumeration (Enum Class).
269 // Set it false for now.
270 bool isScoped = false;
Kate Stoneb9c1b512016-09-06 20:57:50 +0000271
272 CompilerType ast_enum = m_ast.CreateEnumerationType(
Aaron Smithec40f812018-01-23 20:35:19 +0000273 name.c_str(), tu_decl_ctx, decl, builtin_type, isScoped);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000274 auto enum_values = enum_type->findAllChildren<PDBSymbolData>();
Aaron Smithec40f812018-01-23 20:35:19 +0000275 if (enum_values) {
276 while (auto enum_value = enum_values->getNext()) {
277 if (enum_value->getDataKind() != PDB_DataKind::Constant)
278 continue;
279 AddEnumValue(ast_enum, *enum_value);
280 }
Zachary Turner42dff792016-04-15 00:21:26 +0000281 }
Aaron Smithec40f812018-01-23 20:35:19 +0000282 if (ClangASTContext::StartTagDeclarationDefinition(ast_enum))
283 ClangASTContext::CompleteTagDeclarationDefinition(ast_enum);
Zachary Turner42dff792016-04-15 00:21:26 +0000284
Aaron Smith7abdf2d2018-03-07 00:35:27 +0000285 GetDeclarationForSymbol(type, decl);
Saleem Abdulrasool6c135102017-09-09 00:13:49 +0000286 return std::make_shared<lldb_private::Type>(
287 type.getSymIndexId(), m_ast.GetSymbolFile(), ConstString(name), bytes,
288 nullptr, LLDB_INVALID_UID, lldb_private::Type::eEncodingIsUID, decl,
289 ast_enum, lldb_private::Type::eResolveStateFull);
Aaron Smith7ac1c782018-02-09 05:31:28 +0000290 } break;
291 case PDB_SymType::Typedef: {
292 auto type_def = llvm::dyn_cast<PDBSymbolTypeTypedef>(&type);
293 assert(type_def);
Saleem Abdulrasool6c135102017-09-09 00:13:49 +0000294 lldb_private::Type *target_type =
Kate Stoneb9c1b512016-09-06 20:57:50 +0000295 m_ast.GetSymbolFile()->ResolveTypeUID(type_def->getTypeId());
Aaron Smith86e94342017-12-22 05:26:50 +0000296 if (!target_type)
297 return nullptr;
Kate Stoneb9c1b512016-09-06 20:57:50 +0000298 std::string name = type_def->getName();
299 uint64_t bytes = type_def->getLength();
Kate Stoneb9c1b512016-09-06 20:57:50 +0000300 CompilerType target_ast_type = target_type->GetFullCompilerType();
301 CompilerDeclContext target_decl_ctx =
302 m_ast.GetSymbolFile()->GetDeclContextForUID(target_type->GetID());
303 CompilerType ast_typedef =
304 m_ast.CreateTypedefType(target_ast_type, name.c_str(), target_decl_ctx);
Aaron Smitha0db2eb2018-03-07 00:39:25 +0000305 if (!ast_typedef)
306 return nullptr;
307
Saleem Abdulrasool6c135102017-09-09 00:13:49 +0000308 return std::make_shared<lldb_private::Type>(
Kate Stoneb9c1b512016-09-06 20:57:50 +0000309 type_def->getSymIndexId(), m_ast.GetSymbolFile(), ConstString(name),
Saleem Abdulrasool6c135102017-09-09 00:13:49 +0000310 bytes, nullptr, target_type->GetID(),
311 lldb_private::Type::eEncodingIsTypedefUID, decl, ast_typedef,
312 lldb_private::Type::eResolveStateFull);
Aaron Smith7ac1c782018-02-09 05:31:28 +0000313 } break;
314 case PDB_SymType::Function:
315 case PDB_SymType::FunctionSig: {
316 std::string name;
317 PDBSymbolTypeFunctionSig *func_sig = nullptr;
318 if (auto pdb_func = llvm::dyn_cast<PDBSymbolFunc>(&type)) {
319 auto sig = pdb_func->getSignature();
320 if (!sig)
321 return nullptr;
322 func_sig = sig.release();
323 // Function type is named.
324 name = pdb_func->getName();
325 } else if (auto pdb_func_sig =
326 llvm::dyn_cast<PDBSymbolTypeFunctionSig>(&type)) {
327 func_sig = const_cast<PDBSymbolTypeFunctionSig*>(pdb_func_sig);
328 } else
329 llvm_unreachable("Unexpected PDB symbol!");
330
Kate Stoneb9c1b512016-09-06 20:57:50 +0000331 auto arg_enum = func_sig->getArguments();
332 uint32_t num_args = arg_enum->getChildCount();
Aaron Smithec40f812018-01-23 20:35:19 +0000333 std::vector<CompilerType> arg_list;
334
335 bool is_variadic = func_sig->isCVarArgs();
336 // Drop last variadic argument.
337 if (is_variadic)
338 --num_args;
Kirill Bobyrevde6fad62018-01-29 12:59:07 +0000339 for (uint32_t arg_idx = 0; arg_idx < num_args; arg_idx++) {
Aaron Smithec40f812018-01-23 20:35:19 +0000340 auto arg = arg_enum->getChildAtIndex(arg_idx);
341 if (!arg)
342 break;
Saleem Abdulrasool6c135102017-09-09 00:13:49 +0000343 lldb_private::Type *arg_type =
Kate Stoneb9c1b512016-09-06 20:57:50 +0000344 m_ast.GetSymbolFile()->ResolveTypeUID(arg->getSymIndexId());
345 // If there's some error looking up one of the dependent types of this
346 // function signature, bail.
347 if (!arg_type)
348 return nullptr;
349 CompilerType arg_ast_type = arg_type->GetFullCompilerType();
350 arg_list.push_back(arg_ast_type);
351 }
Aaron Smithec40f812018-01-23 20:35:19 +0000352 lldbassert(arg_list.size() <= num_args);
353
Kate Stoneb9c1b512016-09-06 20:57:50 +0000354 auto pdb_return_type = func_sig->getReturnType();
Saleem Abdulrasool6c135102017-09-09 00:13:49 +0000355 lldb_private::Type *return_type =
Kate Stoneb9c1b512016-09-06 20:57:50 +0000356 m_ast.GetSymbolFile()->ResolveTypeUID(pdb_return_type->getSymIndexId());
357 // If there's some error looking up one of the dependent types of this
358 // function signature, bail.
359 if (!return_type)
360 return nullptr;
361 CompilerType return_ast_type = return_type->GetFullCompilerType();
362 uint32_t type_quals = 0;
363 if (func_sig->isConstType())
364 type_quals |= clang::Qualifiers::Const;
365 if (func_sig->isVolatileType())
366 type_quals |= clang::Qualifiers::Volatile;
367 CompilerType func_sig_ast_type = m_ast.CreateFunctionType(
Aaron Smithec40f812018-01-23 20:35:19 +0000368 return_ast_type, arg_list.data(), arg_list.size(), is_variadic,
369 type_quals);
Zachary Turner42dff792016-04-15 00:21:26 +0000370
Aaron Smith7ac1c782018-02-09 05:31:28 +0000371 GetDeclarationForSymbol(type, decl);
Saleem Abdulrasool6c135102017-09-09 00:13:49 +0000372 return std::make_shared<lldb_private::Type>(
Aaron Smith7ac1c782018-02-09 05:31:28 +0000373 type.getSymIndexId(), m_ast.GetSymbolFile(), ConstString(name), 0,
Saleem Abdulrasool6c135102017-09-09 00:13:49 +0000374 nullptr, LLDB_INVALID_UID, lldb_private::Type::eEncodingIsUID, decl,
375 func_sig_ast_type, lldb_private::Type::eResolveStateFull);
Aaron Smith7ac1c782018-02-09 05:31:28 +0000376 } break;
377 case PDB_SymType::ArrayType: {
378 auto array_type = llvm::dyn_cast<PDBSymbolTypeArray>(&type);
379 assert(array_type);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000380 uint32_t num_elements = array_type->getCount();
Aaron Smitha0db2eb2018-03-07 00:39:25 +0000381 uint32_t element_uid = array_type->getElementTypeId();
Kate Stoneb9c1b512016-09-06 20:57:50 +0000382 uint32_t bytes = array_type->getLength();
Zachary Turner42dff792016-04-15 00:21:26 +0000383
Aaron Smitha0db2eb2018-03-07 00:39:25 +0000384 // If array rank > 0, PDB gives the element type at N=0. So element type
385 // will parsed in the order N=0, N=1,..., N=rank sequentially.
Saleem Abdulrasool6c135102017-09-09 00:13:49 +0000386 lldb_private::Type *element_type =
387 m_ast.GetSymbolFile()->ResolveTypeUID(element_uid);
Aaron Smith86e94342017-12-22 05:26:50 +0000388 if (!element_type)
389 return nullptr;
Aaron Smitha0db2eb2018-03-07 00:39:25 +0000390
391 CompilerType element_ast_type = element_type->GetForwardCompilerType();
392 // If element type is UDT, it needs to be complete.
393 if (ClangASTContext::IsCXXClassType(element_ast_type) &&
394 element_ast_type.GetCompleteType() == false) {
395 if (ClangASTContext::StartTagDeclarationDefinition(element_ast_type)) {
396 ClangASTContext::CompleteTagDeclarationDefinition(element_ast_type);
397 } else {
398 // We are not able to start defintion.
399 return nullptr;
400 }
401 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000402 CompilerType array_ast_type =
Aaron Smitha0db2eb2018-03-07 00:39:25 +0000403 m_ast.CreateArrayType(element_ast_type, num_elements, /*is_gnu_vector*/false);
404 TypeSP type_sp = std::make_shared<lldb_private::Type>(
Kate Stoneb9c1b512016-09-06 20:57:50 +0000405 array_type->getSymIndexId(), m_ast.GetSymbolFile(), ConstString(),
Saleem Abdulrasool6c135102017-09-09 00:13:49 +0000406 bytes, nullptr, LLDB_INVALID_UID, lldb_private::Type::eEncodingIsUID,
407 decl, array_ast_type, lldb_private::Type::eResolveStateFull);
Aaron Smitha0db2eb2018-03-07 00:39:25 +0000408 type_sp->SetEncodingType(element_type);
409 return type_sp;
Aaron Smith7ac1c782018-02-09 05:31:28 +0000410 } break;
411 case PDB_SymType::BuiltinType: {
412 auto *builtin_type = llvm::dyn_cast<PDBSymbolTypeBuiltin>(&type);
413 assert(builtin_type);
Aaron Smithec40f812018-01-23 20:35:19 +0000414 PDB_BuiltinType builtin_kind = builtin_type->getBuiltinType();
415 if (builtin_kind == PDB_BuiltinType::None)
416 return nullptr;
417
418 uint64_t bytes = builtin_type->getLength();
419 Encoding encoding = TranslateBuiltinEncoding(builtin_kind);
420 CompilerType builtin_ast_type = GetBuiltinTypeForPDBEncodingAndBitSize(
421 &m_ast, builtin_type, encoding, bytes * 8);
422
Aaron Smitha0db2eb2018-03-07 00:39:25 +0000423 if (builtin_type->isConstType())
Aaron Smithec40f812018-01-23 20:35:19 +0000424 builtin_ast_type = builtin_ast_type.AddConstModifier();
Aaron Smitha0db2eb2018-03-07 00:39:25 +0000425
426 if (builtin_type->isVolatileType())
Aaron Smithec40f812018-01-23 20:35:19 +0000427 builtin_ast_type = builtin_ast_type.AddVolatileModifier();
Aaron Smitha0db2eb2018-03-07 00:39:25 +0000428
Aaron Smithec40f812018-01-23 20:35:19 +0000429 auto type_name = GetPDBBuiltinTypeName(builtin_type, builtin_ast_type);
430
431 return std::make_shared<lldb_private::Type>(
432 builtin_type->getSymIndexId(), m_ast.GetSymbolFile(), type_name,
Aaron Smitha0db2eb2018-03-07 00:39:25 +0000433 bytes, nullptr, LLDB_INVALID_UID, lldb_private::Type::eEncodingIsUID,
Aaron Smithec40f812018-01-23 20:35:19 +0000434 decl, builtin_ast_type, lldb_private::Type::eResolveStateFull);
Aaron Smith7ac1c782018-02-09 05:31:28 +0000435 } break;
436 case PDB_SymType::PointerType: {
437 auto *pointer_type = llvm::dyn_cast<PDBSymbolTypePointer>(&type);
438 assert(pointer_type);
Aaron Smithec40f812018-01-23 20:35:19 +0000439 Type *pointee_type = m_ast.GetSymbolFile()->ResolveTypeUID(
440 pointer_type->getPointeeType()->getSymIndexId());
441 if (!pointee_type)
442 return nullptr;
443
444 CompilerType pointer_ast_type;
Aaron Smitha0db2eb2018-03-07 00:39:25 +0000445 pointer_ast_type = pointee_type->GetFullCompilerType();
446 if (pointer_type->isReference())
447 pointer_ast_type = pointer_ast_type.GetLValueReferenceType();
448 else if (pointer_type->getRawSymbol().isRValueReference())
449 pointer_ast_type = pointer_ast_type.GetRValueReferenceType();
450 else
451 pointer_ast_type = pointer_ast_type.GetPointerType();
452
453 if (pointer_type->isConstType())
454 pointer_ast_type = pointer_ast_type.AddConstModifier();
455
456 if (pointer_type->isVolatileType())
457 pointer_ast_type = pointer_ast_type.AddVolatileModifier();
458
459 if (pointer_type->getRawSymbol().isRestrictedType())
460 pointer_ast_type = pointer_ast_type.AddRestrictModifier();
Aaron Smithec40f812018-01-23 20:35:19 +0000461
462 return std::make_shared<lldb_private::Type>(
463 pointer_type->getSymIndexId(), m_ast.GetSymbolFile(), ConstString(),
464 pointer_type->getLength(), nullptr, LLDB_INVALID_UID,
Aaron Smitha0db2eb2018-03-07 00:39:25 +0000465 lldb_private::Type::eEncodingIsUID, decl, pointer_ast_type,
Aaron Smithec40f812018-01-23 20:35:19 +0000466 lldb_private::Type::eResolveStateFull);
Aaron Smith7ac1c782018-02-09 05:31:28 +0000467 } break;
468 default: break;
Kate Stoneb9c1b512016-09-06 20:57:50 +0000469 }
470 return nullptr;
Zachary Turner42dff792016-04-15 00:21:26 +0000471}
472
Kate Stoneb9c1b512016-09-06 20:57:50 +0000473bool PDBASTParser::AddEnumValue(CompilerType enum_type,
474 const PDBSymbolData &enum_value) const {
475 Declaration decl;
476 Variant v = enum_value.getValue();
477 std::string name = enum_value.getName();
478 int64_t raw_value;
479 switch (v.Type) {
480 case PDB_VariantType::Int8:
481 raw_value = v.Value.Int8;
482 break;
483 case PDB_VariantType::Int16:
484 raw_value = v.Value.Int16;
485 break;
486 case PDB_VariantType::Int32:
487 raw_value = v.Value.Int32;
488 break;
489 case PDB_VariantType::Int64:
490 raw_value = v.Value.Int64;
491 break;
492 case PDB_VariantType::UInt8:
493 raw_value = v.Value.UInt8;
494 break;
495 case PDB_VariantType::UInt16:
496 raw_value = v.Value.UInt16;
497 break;
498 case PDB_VariantType::UInt32:
499 raw_value = v.Value.UInt32;
500 break;
501 case PDB_VariantType::UInt64:
502 raw_value = v.Value.UInt64;
503 break;
504 default:
505 return false;
506 }
507 CompilerType underlying_type =
508 m_ast.GetEnumerationIntegerType(enum_type.GetOpaqueQualType());
509 uint32_t byte_size = m_ast.getASTContext()->getTypeSize(
510 ClangUtil::GetQualType(underlying_type));
511 return m_ast.AddEnumerationValueToEnumerationType(
512 enum_type.GetOpaqueQualType(), underlying_type, decl, name.c_str(),
513 raw_value, byte_size * 8);
Zachary Turner42dff792016-04-15 00:21:26 +0000514}