1 //===-- PDBASTParser.cpp ----------------------------------------*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #include "PDBASTParser.h"
11 #include "SymbolFilePDB.h"
13 #include "clang/AST/CharUnits.h"
14 #include "clang/AST/Decl.h"
15 #include "clang/AST/DeclCXX.h"
17 #include "lldb/Core/Module.h"
18 #include "lldb/Symbol/ClangASTContext.h"
19 #include "lldb/Symbol/ClangExternalASTSourceCommon.h"
20 #include "lldb/Symbol/ClangUtil.h"
21 #include "lldb/Symbol/Declaration.h"
22 #include "lldb/Symbol/SymbolFile.h"
23 #include "lldb/Symbol/TypeMap.h"
24 #include "lldb/Symbol/TypeSystem.h"
26 #include "llvm/DebugInfo/PDB/IPDBLineNumber.h"
27 #include "llvm/DebugInfo/PDB/IPDBSourceFile.h"
28 #include "llvm/DebugInfo/PDB/PDBSymbol.h"
29 #include "llvm/DebugInfo/PDB/PDBSymbolData.h"
30 #include "llvm/DebugInfo/PDB/PDBSymbolFunc.h"
31 #include "llvm/DebugInfo/PDB/PDBSymbolTypeArray.h"
32 #include "llvm/DebugInfo/PDB/PDBSymbolTypeBuiltin.h"
33 #include "llvm/DebugInfo/PDB/PDBSymbolTypeEnum.h"
34 #include "llvm/DebugInfo/PDB/PDBSymbolTypeFunctionArg.h"
35 #include "llvm/DebugInfo/PDB/PDBSymbolTypeFunctionSig.h"
36 #include "llvm/DebugInfo/PDB/PDBSymbolTypePointer.h"
37 #include "llvm/DebugInfo/PDB/PDBSymbolTypeTypedef.h"
38 #include "llvm/DebugInfo/PDB/PDBSymbolTypeUDT.h"
40 #include "Plugins/Language/CPlusPlus/MSVCUndecoratedNameParser.h"
43 using namespace lldb_private;
44 using namespace llvm::pdb;
46 static int TranslateUdtKind(PDB_UdtType pdb_kind) {
48 case PDB_UdtType::Class:
49 return clang::TTK_Class;
50 case PDB_UdtType::Struct:
51 return clang::TTK_Struct;
52 case PDB_UdtType::Union:
53 return clang::TTK_Union;
54 case PDB_UdtType::Interface:
55 return clang::TTK_Interface;
57 llvm_unreachable("unsuported PDB UDT type");
60 static lldb::Encoding TranslateBuiltinEncoding(PDB_BuiltinType type) {
62 case PDB_BuiltinType::Float:
63 return lldb::eEncodingIEEE754;
64 case PDB_BuiltinType::Int:
65 case PDB_BuiltinType::Long:
66 case PDB_BuiltinType::Char:
67 return lldb::eEncodingSint;
68 case PDB_BuiltinType::Bool:
69 case PDB_BuiltinType::Char16:
70 case PDB_BuiltinType::Char32:
71 case PDB_BuiltinType::UInt:
72 case PDB_BuiltinType::ULong:
73 case PDB_BuiltinType::HResult:
74 case PDB_BuiltinType::WCharT:
75 return lldb::eEncodingUint;
77 return lldb::eEncodingInvalid;
81 static lldb::Encoding TranslateEnumEncoding(PDB_VariantType type) {
83 case PDB_VariantType::Int8:
84 case PDB_VariantType::Int16:
85 case PDB_VariantType::Int32:
86 case PDB_VariantType::Int64:
87 return lldb::eEncodingSint;
89 case PDB_VariantType::UInt8:
90 case PDB_VariantType::UInt16:
91 case PDB_VariantType::UInt32:
92 case PDB_VariantType::UInt64:
93 return lldb::eEncodingUint;
99 return lldb::eEncodingSint;
103 GetBuiltinTypeForPDBEncodingAndBitSize(ClangASTContext &clang_ast,
104 const PDBSymbolTypeBuiltin &pdb_type,
105 Encoding encoding, uint32_t width) {
106 auto *ast = clang_ast.getASTContext();
108 return CompilerType();
110 switch (pdb_type.getBuiltinType()) {
113 case PDB_BuiltinType::None:
114 return CompilerType();
115 case PDB_BuiltinType::Void:
116 return clang_ast.GetBasicType(eBasicTypeVoid);
117 case PDB_BuiltinType::Char:
118 return clang_ast.GetBasicType(eBasicTypeChar);
119 case PDB_BuiltinType::Bool:
120 return clang_ast.GetBasicType(eBasicTypeBool);
121 case PDB_BuiltinType::Long:
122 if (width == ast->getTypeSize(ast->LongTy))
123 return CompilerType(ast, ast->LongTy);
124 if (width == ast->getTypeSize(ast->LongLongTy))
125 return CompilerType(ast, ast->LongLongTy);
127 case PDB_BuiltinType::ULong:
128 if (width == ast->getTypeSize(ast->UnsignedLongTy))
129 return CompilerType(ast, ast->UnsignedLongTy);
130 if (width == ast->getTypeSize(ast->UnsignedLongLongTy))
131 return CompilerType(ast, ast->UnsignedLongLongTy);
133 case PDB_BuiltinType::WCharT:
134 if (width == ast->getTypeSize(ast->WCharTy))
135 return CompilerType(ast, ast->WCharTy);
137 case PDB_BuiltinType::Char16:
138 return CompilerType(ast, ast->Char16Ty);
139 case PDB_BuiltinType::Char32:
140 return CompilerType(ast, ast->Char32Ty);
141 case PDB_BuiltinType::Float:
142 // Note: types `long double` and `double` have same bit size in MSVC and
143 // there is no information in the PDB to distinguish them. So when falling
144 // back to default search, the compiler type of `long double` will be
145 // represented by the one generated for `double`.
148 // If there is no match on PDB_BuiltinType, fall back to default search by
149 // encoding and width only
150 return clang_ast.GetBuiltinTypeForEncodingAndBitSize(encoding, width);
153 static ConstString GetPDBBuiltinTypeName(const PDBSymbolTypeBuiltin &pdb_type,
154 CompilerType &compiler_type) {
155 PDB_BuiltinType kind = pdb_type.getBuiltinType();
159 case PDB_BuiltinType::Currency:
160 return ConstString("CURRENCY");
161 case PDB_BuiltinType::Date:
162 return ConstString("DATE");
163 case PDB_BuiltinType::Variant:
164 return ConstString("VARIANT");
165 case PDB_BuiltinType::Complex:
166 return ConstString("complex");
167 case PDB_BuiltinType::Bitfield:
168 return ConstString("bitfield");
169 case PDB_BuiltinType::BSTR:
170 return ConstString("BSTR");
171 case PDB_BuiltinType::HResult:
172 return ConstString("HRESULT");
173 case PDB_BuiltinType::BCD:
174 return ConstString("BCD");
175 case PDB_BuiltinType::Char16:
176 return ConstString("char16_t");
177 case PDB_BuiltinType::Char32:
178 return ConstString("char32_t");
179 case PDB_BuiltinType::None:
180 return ConstString("...");
182 return compiler_type.GetTypeName();
185 static bool GetDeclarationForSymbol(const PDBSymbol &symbol,
187 auto &raw_sym = symbol.getRawSymbol();
188 auto first_line_up = raw_sym.getSrcLineOnTypeDefn();
190 if (!first_line_up) {
191 auto lines_up = symbol.getSession().findLineNumbersByAddress(
192 raw_sym.getVirtualAddress(), raw_sym.getLength());
195 first_line_up = lines_up->getNext();
199 uint32_t src_file_id = first_line_up->getSourceFileId();
200 auto src_file_up = symbol.getSession().getSourceFileById(src_file_id);
204 FileSpec spec(src_file_up->getFileName());
206 decl.SetColumn(first_line_up->getColumnNumber());
207 decl.SetLine(first_line_up->getLineNumber());
211 static AccessType TranslateMemberAccess(PDB_MemberAccess access) {
213 case PDB_MemberAccess::Private:
214 return eAccessPrivate;
215 case PDB_MemberAccess::Protected:
216 return eAccessProtected;
217 case PDB_MemberAccess::Public:
218 return eAccessPublic;
223 static AccessType GetDefaultAccessibilityForUdtKind(PDB_UdtType udt_kind) {
225 case PDB_UdtType::Struct:
226 case PDB_UdtType::Union:
227 return eAccessPublic;
228 case PDB_UdtType::Class:
229 case PDB_UdtType::Interface:
230 return eAccessPrivate;
232 llvm_unreachable("unsupported PDB UDT type");
235 static AccessType GetAccessibilityForUdt(const PDBSymbolTypeUDT &udt) {
236 AccessType access = TranslateMemberAccess(udt.getAccess());
237 if (access != lldb::eAccessNone || !udt.isNested())
240 auto parent = udt.getClassParent();
242 return lldb::eAccessNone;
244 auto parent_udt = llvm::dyn_cast<PDBSymbolTypeUDT>(parent.get());
246 return lldb::eAccessNone;
248 return GetDefaultAccessibilityForUdtKind(parent_udt->getUdtKind());
251 static clang::MSInheritanceAttr::Spelling
252 GetMSInheritance(const PDBSymbolTypeUDT &udt) {
254 bool has_virtual = false;
256 auto bases_enum = udt.findAllChildren<PDBSymbolTypeBaseClass>();
258 while (auto base = bases_enum->getNext()) {
260 has_virtual |= base->isVirtualBaseClass();
265 return clang::MSInheritanceAttr::Keyword_virtual_inheritance;
267 return clang::MSInheritanceAttr::Keyword_multiple_inheritance;
268 return clang::MSInheritanceAttr::Keyword_single_inheritance;
271 static std::unique_ptr<llvm::pdb::PDBSymbol>
272 GetClassOrFunctionParent(const llvm::pdb::PDBSymbol &symbol) {
273 const IPDBSession &session = symbol.getSession();
274 const IPDBRawSymbol &raw = symbol.getRawSymbol();
275 auto tag = symbol.getSymTag();
277 // For items that are nested inside of a class, return the class that it is
279 // Note that only certain items can be nested inside of classes.
281 case PDB_SymType::Function:
282 case PDB_SymType::Data:
283 case PDB_SymType::UDT:
284 case PDB_SymType::Enum:
285 case PDB_SymType::FunctionSig:
286 case PDB_SymType::Typedef:
287 case PDB_SymType::BaseClass:
288 case PDB_SymType::VTable: {
289 auto class_parent_id = raw.getClassParentId();
290 if (auto class_parent = session.getSymbolById(class_parent_id))
298 // Otherwise, if it is nested inside of a function, return the function.
299 // Note that only certain items can be nested inside of functions.
301 case PDB_SymType::Block:
302 case PDB_SymType::Data: {
303 auto lexical_parent_id = raw.getLexicalParentId();
304 auto lexical_parent = session.getSymbolById(lexical_parent_id);
308 auto lexical_parent_tag = lexical_parent->getSymTag();
309 if (lexical_parent_tag == PDB_SymType::Function)
310 return lexical_parent;
311 if (lexical_parent_tag == PDB_SymType::Exe)
314 return GetClassOrFunctionParent(*lexical_parent);
321 static clang::NamedDecl *
322 GetDeclFromContextByName(const clang::ASTContext &ast,
323 const clang::DeclContext &decl_context,
324 llvm::StringRef name) {
325 clang::IdentifierInfo &ident = ast.Idents.get(name);
326 clang::DeclarationName decl_name = ast.DeclarationNames.getIdentifier(&ident);
327 clang::DeclContext::lookup_result result = decl_context.lookup(decl_name);
334 static bool IsAnonymousNamespaceName(llvm::StringRef name) {
335 return name == "`anonymous namespace'" || name == "`anonymous-namespace'";
338 static clang::CallingConv TranslateCallingConvention(PDB_CallingConv pdb_cc) {
340 case llvm::codeview::CallingConvention::NearC:
342 case llvm::codeview::CallingConvention::NearStdCall:
343 return clang::CC_X86StdCall;
344 case llvm::codeview::CallingConvention::NearFast:
345 return clang::CC_X86FastCall;
346 case llvm::codeview::CallingConvention::ThisCall:
347 return clang::CC_X86ThisCall;
348 case llvm::codeview::CallingConvention::NearVector:
349 return clang::CC_X86VectorCall;
350 case llvm::codeview::CallingConvention::NearPascal:
351 return clang::CC_X86Pascal;
353 assert(false && "Unknown calling convention");
358 PDBASTParser::PDBASTParser(lldb_private::ClangASTContext &ast) : m_ast(ast) {}
360 PDBASTParser::~PDBASTParser() {}
362 // DebugInfoASTParser interface
364 lldb::TypeSP PDBASTParser::CreateLLDBTypeFromPDBType(const PDBSymbol &type) {
366 switch (type.getSymTag()) {
367 case PDB_SymType::BaseClass: {
368 auto symbol_file = m_ast.GetSymbolFile();
372 auto ty = symbol_file->ResolveTypeUID(type.getRawSymbol().getTypeId());
373 return ty ? ty->shared_from_this() : nullptr;
375 case PDB_SymType::UDT: {
376 auto udt = llvm::dyn_cast<PDBSymbolTypeUDT>(&type);
379 // Note that, unnamed UDT being typedef-ed is generated as a UDT symbol
380 // other than a Typedef symbol in PDB. For example,
381 // typedef union { short Row; short Col; } Union;
382 // is generated as a named UDT in PDB:
383 // union Union { short Row; short Col; }
384 // Such symbols will be handled here.
386 // Some UDT with trival ctor has zero length. Just ignore.
387 if (udt->getLength() == 0)
390 // Ignore unnamed-tag UDTs.
391 std::string name = MSVCUndecoratedNameParser::DropScope(udt->getName());
395 auto decl_context = GetDeclContextContainingSymbol(type);
397 // Check if such an UDT already exists in the current context.
398 // This may occur with const or volatile types. There are separate type
399 // symbols in PDB for types with const or volatile modifiers, but we need
400 // to create only one declaration for them all.
401 Type::ResolveStateTag type_resolve_state_tag;
402 CompilerType clang_type = m_ast.GetTypeForIdentifier<clang::CXXRecordDecl>(
403 ConstString(name), decl_context);
404 if (!clang_type.IsValid()) {
405 auto access = GetAccessibilityForUdt(*udt);
407 auto tag_type_kind = TranslateUdtKind(udt->getUdtKind());
409 ClangASTMetadata metadata;
410 metadata.SetUserID(type.getSymIndexId());
411 metadata.SetIsDynamicCXXType(false);
413 clang_type = m_ast.CreateRecordType(
414 decl_context, access, name.c_str(), tag_type_kind,
415 lldb::eLanguageTypeC_plus_plus, &metadata);
416 assert(clang_type.IsValid());
419 m_ast.GetAsCXXRecordDecl(clang_type.GetOpaqueQualType());
421 m_uid_to_decl[type.getSymIndexId()] = record_decl;
423 auto inheritance_attr = clang::MSInheritanceAttr::CreateImplicit(
424 *m_ast.getASTContext(), GetMSInheritance(*udt));
425 record_decl->addAttr(inheritance_attr);
427 ClangASTContext::StartTagDeclarationDefinition(clang_type);
429 auto children = udt->findAllChildren();
430 if (!children || children->getChildCount() == 0) {
431 // PDB does not have symbol of forwarder. We assume we get an udt w/o
432 // any fields. Just complete it at this point.
433 ClangASTContext::CompleteTagDeclarationDefinition(clang_type);
435 ClangASTContext::SetHasExternalStorage(clang_type.GetOpaqueQualType(),
438 type_resolve_state_tag = Type::eResolveStateFull;
440 // Add the type to the forward declarations. It will help us to avoid
441 // an endless recursion in CompleteTypeFromUdt function.
442 m_forward_decl_to_uid[record_decl] = type.getSymIndexId();
444 ClangASTContext::SetHasExternalStorage(clang_type.GetOpaqueQualType(),
447 type_resolve_state_tag = Type::eResolveStateForward;
450 type_resolve_state_tag = Type::eResolveStateForward;
452 if (udt->isConstType())
453 clang_type = clang_type.AddConstModifier();
455 if (udt->isVolatileType())
456 clang_type = clang_type.AddVolatileModifier();
458 GetDeclarationForSymbol(type, decl);
459 return std::make_shared<lldb_private::Type>(
460 type.getSymIndexId(), m_ast.GetSymbolFile(), ConstString(name),
461 udt->getLength(), nullptr, LLDB_INVALID_UID,
462 lldb_private::Type::eEncodingIsUID, decl, clang_type,
463 type_resolve_state_tag);
465 case PDB_SymType::Enum: {
466 auto enum_type = llvm::dyn_cast<PDBSymbolTypeEnum>(&type);
470 MSVCUndecoratedNameParser::DropScope(enum_type->getName());
471 auto decl_context = GetDeclContextContainingSymbol(type);
472 uint64_t bytes = enum_type->getLength();
474 // Check if such an enum already exists in the current context
475 CompilerType ast_enum = m_ast.GetTypeForIdentifier<clang::EnumDecl>(
476 ConstString(name), decl_context);
477 if (!ast_enum.IsValid()) {
478 auto underlying_type_up = enum_type->getUnderlyingType();
479 if (!underlying_type_up)
482 lldb::Encoding encoding =
483 TranslateBuiltinEncoding(underlying_type_up->getBuiltinType());
484 // FIXME: Type of underlying builtin is always `Int`. We correct it with
485 // the very first enumerator's encoding if any.
486 auto first_child = enum_type->findOneChild<PDBSymbolData>();
488 encoding = TranslateEnumEncoding(first_child->getValue().Type);
490 CompilerType builtin_type;
492 builtin_type = GetBuiltinTypeForPDBEncodingAndBitSize(
493 m_ast, *underlying_type_up, encoding, bytes * 8);
495 builtin_type = m_ast.GetBasicType(eBasicTypeInt);
497 // FIXME: PDB does not have information about scoped enumeration (Enum
498 // Class). Set it false for now.
499 bool isScoped = false;
501 ast_enum = m_ast.CreateEnumerationType(name.c_str(), decl_context, decl,
502 builtin_type, isScoped);
504 auto enum_decl = ClangASTContext::GetAsEnumDecl(ast_enum);
506 m_uid_to_decl[type.getSymIndexId()] = enum_decl;
508 auto enum_values = enum_type->findAllChildren<PDBSymbolData>();
510 while (auto enum_value = enum_values->getNext()) {
511 if (enum_value->getDataKind() != PDB_DataKind::Constant)
513 AddEnumValue(ast_enum, *enum_value);
517 if (ClangASTContext::StartTagDeclarationDefinition(ast_enum))
518 ClangASTContext::CompleteTagDeclarationDefinition(ast_enum);
521 if (enum_type->isConstType())
522 ast_enum = ast_enum.AddConstModifier();
524 if (enum_type->isVolatileType())
525 ast_enum = ast_enum.AddVolatileModifier();
527 GetDeclarationForSymbol(type, decl);
528 return std::make_shared<lldb_private::Type>(
529 type.getSymIndexId(), m_ast.GetSymbolFile(), ConstString(name), bytes,
530 nullptr, LLDB_INVALID_UID, lldb_private::Type::eEncodingIsUID, decl,
531 ast_enum, lldb_private::Type::eResolveStateFull);
533 case PDB_SymType::Typedef: {
534 auto type_def = llvm::dyn_cast<PDBSymbolTypeTypedef>(&type);
537 lldb_private::Type *target_type =
538 m_ast.GetSymbolFile()->ResolveTypeUID(type_def->getTypeId());
543 MSVCUndecoratedNameParser::DropScope(type_def->getName());
544 auto decl_ctx = GetDeclContextContainingSymbol(type);
546 // Check if such a typedef already exists in the current context
547 CompilerType ast_typedef =
548 m_ast.GetTypeForIdentifier<clang::TypedefNameDecl>(ConstString(name),
550 if (!ast_typedef.IsValid()) {
551 CompilerType target_ast_type = target_type->GetFullCompilerType();
553 ast_typedef = m_ast.CreateTypedefType(
554 target_ast_type, name.c_str(), CompilerDeclContext(&m_ast, decl_ctx));
558 auto typedef_decl = ClangASTContext::GetAsTypedefDecl(ast_typedef);
559 assert(typedef_decl);
560 m_uid_to_decl[type.getSymIndexId()] = typedef_decl;
563 if (type_def->isConstType())
564 ast_typedef = ast_typedef.AddConstModifier();
566 if (type_def->isVolatileType())
567 ast_typedef = ast_typedef.AddVolatileModifier();
569 GetDeclarationForSymbol(type, decl);
570 llvm::Optional<uint64_t> size;
571 if (type_def->getLength())
572 size = type_def->getLength();
573 return std::make_shared<lldb_private::Type>(
574 type_def->getSymIndexId(), m_ast.GetSymbolFile(), ConstString(name),
575 size, nullptr, target_type->GetID(),
576 lldb_private::Type::eEncodingIsTypedefUID, decl, ast_typedef,
577 lldb_private::Type::eResolveStateFull);
579 case PDB_SymType::Function:
580 case PDB_SymType::FunctionSig: {
582 PDBSymbolTypeFunctionSig *func_sig = nullptr;
583 if (auto pdb_func = llvm::dyn_cast<PDBSymbolFunc>(&type)) {
584 if (pdb_func->isCompilerGenerated())
587 auto sig = pdb_func->getSignature();
590 func_sig = sig.release();
591 // Function type is named.
592 name = MSVCUndecoratedNameParser::DropScope(pdb_func->getName());
593 } else if (auto pdb_func_sig =
594 llvm::dyn_cast<PDBSymbolTypeFunctionSig>(&type)) {
595 func_sig = const_cast<PDBSymbolTypeFunctionSig *>(pdb_func_sig);
597 llvm_unreachable("Unexpected PDB symbol!");
599 auto arg_enum = func_sig->getArguments();
600 uint32_t num_args = arg_enum->getChildCount();
601 std::vector<CompilerType> arg_list;
603 bool is_variadic = func_sig->isCVarArgs();
604 // Drop last variadic argument.
607 for (uint32_t arg_idx = 0; arg_idx < num_args; arg_idx++) {
608 auto arg = arg_enum->getChildAtIndex(arg_idx);
611 lldb_private::Type *arg_type =
612 m_ast.GetSymbolFile()->ResolveTypeUID(arg->getSymIndexId());
613 // If there's some error looking up one of the dependent types of this
614 // function signature, bail.
617 CompilerType arg_ast_type = arg_type->GetFullCompilerType();
618 arg_list.push_back(arg_ast_type);
620 lldbassert(arg_list.size() <= num_args);
622 auto pdb_return_type = func_sig->getReturnType();
623 lldb_private::Type *return_type =
624 m_ast.GetSymbolFile()->ResolveTypeUID(pdb_return_type->getSymIndexId());
625 // If there's some error looking up one of the dependent types of this
626 // function signature, bail.
629 CompilerType return_ast_type = return_type->GetFullCompilerType();
630 uint32_t type_quals = 0;
631 if (func_sig->isConstType())
632 type_quals |= clang::Qualifiers::Const;
633 if (func_sig->isVolatileType())
634 type_quals |= clang::Qualifiers::Volatile;
635 auto cc = TranslateCallingConvention(func_sig->getCallingConvention());
636 CompilerType func_sig_ast_type =
637 m_ast.CreateFunctionType(return_ast_type, arg_list.data(),
638 arg_list.size(), is_variadic, type_quals, cc);
640 GetDeclarationForSymbol(type, decl);
641 return std::make_shared<lldb_private::Type>(
642 type.getSymIndexId(), m_ast.GetSymbolFile(), ConstString(name),
643 llvm::None, nullptr, LLDB_INVALID_UID,
644 lldb_private::Type::eEncodingIsUID, decl, func_sig_ast_type,
645 lldb_private::Type::eResolveStateFull);
647 case PDB_SymType::ArrayType: {
648 auto array_type = llvm::dyn_cast<PDBSymbolTypeArray>(&type);
650 uint32_t num_elements = array_type->getCount();
651 uint32_t element_uid = array_type->getElementTypeId();
652 llvm::Optional<uint64_t> bytes;
653 if (uint64_t size = array_type->getLength())
656 // If array rank > 0, PDB gives the element type at N=0. So element type
657 // will parsed in the order N=0, N=1,..., N=rank sequentially.
658 lldb_private::Type *element_type =
659 m_ast.GetSymbolFile()->ResolveTypeUID(element_uid);
663 CompilerType element_ast_type = element_type->GetForwardCompilerType();
664 // If element type is UDT, it needs to be complete.
665 if (ClangASTContext::IsCXXClassType(element_ast_type) &&
666 !element_ast_type.GetCompleteType()) {
667 if (ClangASTContext::StartTagDeclarationDefinition(element_ast_type)) {
668 ClangASTContext::CompleteTagDeclarationDefinition(element_ast_type);
670 // We are not able to start defintion.
674 CompilerType array_ast_type = m_ast.CreateArrayType(
675 element_ast_type, num_elements, /*is_gnu_vector*/ false);
676 TypeSP type_sp = std::make_shared<lldb_private::Type>(
677 array_type->getSymIndexId(), m_ast.GetSymbolFile(), ConstString(),
678 bytes, nullptr, LLDB_INVALID_UID, lldb_private::Type::eEncodingIsUID,
679 decl, array_ast_type, lldb_private::Type::eResolveStateFull);
680 type_sp->SetEncodingType(element_type);
683 case PDB_SymType::BuiltinType: {
684 auto *builtin_type = llvm::dyn_cast<PDBSymbolTypeBuiltin>(&type);
685 assert(builtin_type);
686 PDB_BuiltinType builtin_kind = builtin_type->getBuiltinType();
687 if (builtin_kind == PDB_BuiltinType::None)
690 llvm::Optional<uint64_t> bytes;
691 if (uint64_t size = builtin_type->getLength())
693 Encoding encoding = TranslateBuiltinEncoding(builtin_kind);
694 CompilerType builtin_ast_type = GetBuiltinTypeForPDBEncodingAndBitSize(
695 m_ast, *builtin_type, encoding, bytes.getValueOr(0) * 8);
697 if (builtin_type->isConstType())
698 builtin_ast_type = builtin_ast_type.AddConstModifier();
700 if (builtin_type->isVolatileType())
701 builtin_ast_type = builtin_ast_type.AddVolatileModifier();
703 auto type_name = GetPDBBuiltinTypeName(*builtin_type, builtin_ast_type);
705 return std::make_shared<lldb_private::Type>(
706 builtin_type->getSymIndexId(), m_ast.GetSymbolFile(), type_name, bytes,
707 nullptr, LLDB_INVALID_UID, lldb_private::Type::eEncodingIsUID, decl,
708 builtin_ast_type, lldb_private::Type::eResolveStateFull);
710 case PDB_SymType::PointerType: {
711 auto *pointer_type = llvm::dyn_cast<PDBSymbolTypePointer>(&type);
712 assert(pointer_type);
713 Type *pointee_type = m_ast.GetSymbolFile()->ResolveTypeUID(
714 pointer_type->getPointeeType()->getSymIndexId());
718 if (pointer_type->isPointerToDataMember() ||
719 pointer_type->isPointerToMemberFunction()) {
720 auto class_parent_uid = pointer_type->getRawSymbol().getClassParentId();
721 auto class_parent_type =
722 m_ast.GetSymbolFile()->ResolveTypeUID(class_parent_uid);
723 assert(class_parent_type);
725 CompilerType pointer_ast_type;
726 pointer_ast_type = ClangASTContext::CreateMemberPointerType(
727 class_parent_type->GetLayoutCompilerType(),
728 pointee_type->GetForwardCompilerType());
729 assert(pointer_ast_type);
731 return std::make_shared<lldb_private::Type>(
732 pointer_type->getSymIndexId(), m_ast.GetSymbolFile(), ConstString(),
733 pointer_type->getLength(), nullptr, LLDB_INVALID_UID,
734 lldb_private::Type::eEncodingIsUID, decl, pointer_ast_type,
735 lldb_private::Type::eResolveStateForward);
738 CompilerType pointer_ast_type;
739 pointer_ast_type = pointee_type->GetFullCompilerType();
740 if (pointer_type->isReference())
741 pointer_ast_type = pointer_ast_type.GetLValueReferenceType();
742 else if (pointer_type->isRValueReference())
743 pointer_ast_type = pointer_ast_type.GetRValueReferenceType();
745 pointer_ast_type = pointer_ast_type.GetPointerType();
747 if (pointer_type->isConstType())
748 pointer_ast_type = pointer_ast_type.AddConstModifier();
750 if (pointer_type->isVolatileType())
751 pointer_ast_type = pointer_ast_type.AddVolatileModifier();
753 if (pointer_type->isRestrictedType())
754 pointer_ast_type = pointer_ast_type.AddRestrictModifier();
756 return std::make_shared<lldb_private::Type>(
757 pointer_type->getSymIndexId(), m_ast.GetSymbolFile(), ConstString(),
758 pointer_type->getLength(), nullptr, LLDB_INVALID_UID,
759 lldb_private::Type::eEncodingIsUID, decl, pointer_ast_type,
760 lldb_private::Type::eResolveStateFull);
768 bool PDBASTParser::CompleteTypeFromPDB(
769 lldb_private::CompilerType &compiler_type) {
770 if (GetClangASTImporter().CanImport(compiler_type))
771 return GetClangASTImporter().CompleteType(compiler_type);
773 // Remove the type from the forward declarations to avoid
774 // an endless recursion for types like a linked list.
775 clang::CXXRecordDecl *record_decl =
776 m_ast.GetAsCXXRecordDecl(compiler_type.GetOpaqueQualType());
777 auto uid_it = m_forward_decl_to_uid.find(record_decl);
778 if (uid_it == m_forward_decl_to_uid.end())
781 auto symbol_file = static_cast<SymbolFilePDB *>(m_ast.GetSymbolFile());
785 std::unique_ptr<PDBSymbol> symbol =
786 symbol_file->GetPDBSession().getSymbolById(uid_it->getSecond());
790 m_forward_decl_to_uid.erase(uid_it);
792 ClangASTContext::SetHasExternalStorage(compiler_type.GetOpaqueQualType(),
795 switch (symbol->getSymTag()) {
796 case PDB_SymType::UDT: {
797 auto udt = llvm::dyn_cast<PDBSymbolTypeUDT>(symbol.get());
801 return CompleteTypeFromUDT(*symbol_file, compiler_type, *udt);
804 llvm_unreachable("not a forward clang type decl!");
809 PDBASTParser::GetDeclForSymbol(const llvm::pdb::PDBSymbol &symbol) {
810 uint32_t sym_id = symbol.getSymIndexId();
811 auto it = m_uid_to_decl.find(sym_id);
812 if (it != m_uid_to_decl.end())
815 auto symbol_file = static_cast<SymbolFilePDB *>(m_ast.GetSymbolFile());
819 // First of all, check if the symbol is a member of a class. Resolve the full
820 // class type and return the declaration from the cache if so.
821 auto tag = symbol.getSymTag();
822 if (tag == PDB_SymType::Data || tag == PDB_SymType::Function) {
823 const IPDBSession &session = symbol.getSession();
824 const IPDBRawSymbol &raw = symbol.getRawSymbol();
826 auto class_parent_id = raw.getClassParentId();
827 if (std::unique_ptr<PDBSymbol> class_parent =
828 session.getSymbolById(class_parent_id)) {
829 auto class_parent_type = symbol_file->ResolveTypeUID(class_parent_id);
830 if (!class_parent_type)
833 CompilerType class_parent_ct = class_parent_type->GetFullCompilerType();
835 // Look a declaration up in the cache after completing the class
836 clang::Decl *decl = m_uid_to_decl.lookup(sym_id);
840 // A declaration was not found in the cache. It means that the symbol
841 // has the class parent, but the class doesn't have the symbol in its
843 if (auto func = llvm::dyn_cast_or_null<PDBSymbolFunc>(&symbol)) {
844 // Try to find a class child method with the same RVA and use its
845 // declaration if found.
846 if (uint32_t rva = func->getRelativeVirtualAddress()) {
847 if (std::unique_ptr<ConcreteSymbolEnumerator<PDBSymbolFunc>>
849 class_parent->findAllChildren<PDBSymbolFunc>()) {
850 while (std::unique_ptr<PDBSymbolFunc> method =
851 methods_enum->getNext()) {
852 if (method->getRelativeVirtualAddress() == rva) {
853 decl = m_uid_to_decl.lookup(method->getSymIndexId());
861 // If no class methods with the same RVA were found, then create a new
862 // method. It is possible for template methods.
864 decl = AddRecordMethod(*symbol_file, class_parent_ct, *func);
868 m_uid_to_decl[sym_id] = decl;
874 // If we are here, then the symbol is not belonging to a class and is not
875 // contained in the cache. So create a declaration for it.
876 switch (symbol.getSymTag()) {
877 case PDB_SymType::Data: {
878 auto data = llvm::dyn_cast<PDBSymbolData>(&symbol);
881 auto decl_context = GetDeclContextContainingSymbol(symbol);
882 assert(decl_context);
884 // May be the current context is a class really, but we haven't found
885 // any class parent. This happens e.g. in the case of class static
886 // variables - they has two symbols, one is a child of the class when
887 // another is a child of the exe. So always complete the parent and use
888 // an existing declaration if possible.
889 if (auto parent_decl = llvm::dyn_cast_or_null<clang::TagDecl>(decl_context))
890 m_ast.GetCompleteDecl(parent_decl);
892 std::string name = MSVCUndecoratedNameParser::DropScope(data->getName());
894 // Check if the current context already contains the symbol with the name.
896 GetDeclFromContextByName(*m_ast.getASTContext(), *decl_context, name);
898 auto type = symbol_file->ResolveTypeUID(data->getTypeId());
902 decl = m_ast.CreateVariableDeclaration(
903 decl_context, name.c_str(),
904 ClangUtil::GetQualType(type->GetLayoutCompilerType()));
907 m_uid_to_decl[sym_id] = decl;
911 case PDB_SymType::Function: {
912 auto func = llvm::dyn_cast<PDBSymbolFunc>(&symbol);
915 auto decl_context = GetDeclContextContainingSymbol(symbol);
916 assert(decl_context);
918 std::string name = MSVCUndecoratedNameParser::DropScope(func->getName());
920 Type *type = symbol_file->ResolveTypeUID(sym_id);
924 auto storage = func->isStatic() ? clang::StorageClass::SC_Static
925 : clang::StorageClass::SC_None;
927 auto decl = m_ast.CreateFunctionDeclaration(
928 decl_context, name.c_str(), type->GetForwardCompilerType(), storage,
929 func->hasInlineAttribute());
931 std::vector<clang::ParmVarDecl *> params;
932 if (std::unique_ptr<PDBSymbolTypeFunctionSig> sig = func->getSignature()) {
933 if (std::unique_ptr<ConcreteSymbolEnumerator<PDBSymbolTypeFunctionArg>>
934 arg_enum = sig->findAllChildren<PDBSymbolTypeFunctionArg>()) {
935 while (std::unique_ptr<PDBSymbolTypeFunctionArg> arg =
936 arg_enum->getNext()) {
937 Type *arg_type = symbol_file->ResolveTypeUID(arg->getTypeId());
941 clang::ParmVarDecl *param = m_ast.CreateParameterDeclaration(
942 decl, nullptr, arg_type->GetForwardCompilerType(),
945 params.push_back(param);
950 m_ast.SetFunctionParameters(decl, params.data(), params.size());
952 m_uid_to_decl[sym_id] = decl;
957 // It's not a variable and not a function, check if it's a type
958 Type *type = symbol_file->ResolveTypeUID(sym_id);
962 return m_uid_to_decl.lookup(sym_id);
968 PDBASTParser::GetDeclContextForSymbol(const llvm::pdb::PDBSymbol &symbol) {
969 if (symbol.getSymTag() == PDB_SymType::Function) {
970 clang::DeclContext *result =
971 llvm::dyn_cast_or_null<clang::FunctionDecl>(GetDeclForSymbol(symbol));
974 m_decl_context_to_uid[result] = symbol.getSymIndexId();
979 auto symbol_file = static_cast<SymbolFilePDB *>(m_ast.GetSymbolFile());
983 auto type = symbol_file->ResolveTypeUID(symbol.getSymIndexId());
987 clang::DeclContext *result =
988 m_ast.GetDeclContextForType(type->GetForwardCompilerType());
991 m_decl_context_to_uid[result] = symbol.getSymIndexId();
996 clang::DeclContext *PDBASTParser::GetDeclContextContainingSymbol(
997 const llvm::pdb::PDBSymbol &symbol) {
998 auto parent = GetClassOrFunctionParent(symbol);
1000 if (auto parent_context = GetDeclContextForSymbol(*parent))
1001 return parent_context;
1003 parent = GetClassOrFunctionParent(*parent);
1006 // We can't find any class or function parent of the symbol. So analyze
1007 // the full symbol name. The symbol may be belonging to a namespace
1008 // or function (or even to a class if it's e.g. a static variable symbol).
1010 // TODO: Make clang to emit full names for variables in namespaces
1013 std::string name(symbol.getRawSymbol().getName());
1014 MSVCUndecoratedNameParser parser(name);
1015 llvm::ArrayRef<MSVCUndecoratedNameSpecifier> specs = parser.GetSpecifiers();
1017 return m_ast.GetTranslationUnitDecl();
1019 auto symbol_file = static_cast<SymbolFilePDB *>(m_ast.GetSymbolFile());
1021 return m_ast.GetTranslationUnitDecl();
1023 auto global = symbol_file->GetPDBSession().getGlobalScope();
1025 return m_ast.GetTranslationUnitDecl();
1027 bool has_type_or_function_parent = false;
1028 clang::DeclContext *curr_context = m_ast.GetTranslationUnitDecl();
1029 for (std::size_t i = 0; i < specs.size() - 1; i++) {
1030 // Check if there is a function or a type with the current context's name.
1031 if (std::unique_ptr<IPDBEnumSymbols> children_enum = global->findChildren(
1032 PDB_SymType::None, specs[i].GetFullName(), NS_CaseSensitive)) {
1033 while (IPDBEnumChildren<PDBSymbol>::ChildTypePtr child =
1034 children_enum->getNext()) {
1035 if (clang::DeclContext *child_context =
1036 GetDeclContextForSymbol(*child)) {
1037 // Note that `GetDeclContextForSymbol' retrieves
1038 // a declaration context for functions and types only,
1039 // so if we are here then `child_context' is guaranteed
1040 // a function or a type declaration context.
1041 has_type_or_function_parent = true;
1042 curr_context = child_context;
1047 // If there were no functions or types above then retrieve a namespace with
1048 // the current context's name. There can be no namespaces inside a function
1049 // or a type. We check it to avoid fake namespaces such as `__l2':
1050 // `N0::N1::CClass::PrivateFunc::__l2::InnerFuncStruct'
1051 if (!has_type_or_function_parent) {
1052 std::string namespace_name = specs[i].GetBaseName();
1053 const char *namespace_name_c_str =
1054 IsAnonymousNamespaceName(namespace_name) ? nullptr
1055 : namespace_name.data();
1056 clang::NamespaceDecl *namespace_decl =
1057 m_ast.GetUniqueNamespaceDeclaration(namespace_name_c_str,
1060 m_parent_to_namespaces[curr_context].insert(namespace_decl);
1061 m_namespaces.insert(namespace_decl);
1063 curr_context = namespace_decl;
1067 return curr_context;
1070 void PDBASTParser::ParseDeclsForDeclContext(
1071 const clang::DeclContext *decl_context) {
1072 auto symbol_file = static_cast<SymbolFilePDB *>(m_ast.GetSymbolFile());
1076 IPDBSession &session = symbol_file->GetPDBSession();
1078 session.getSymbolById(m_decl_context_to_uid.lookup(decl_context));
1079 auto global_up = session.getGlobalScope();
1083 symbol = symbol_up.get();
1085 symbol = global_up.get();
1089 if (auto children = symbol->findAllChildren())
1090 while (auto child = children->getNext())
1091 GetDeclForSymbol(*child);
1094 clang::NamespaceDecl *
1095 PDBASTParser::FindNamespaceDecl(const clang::DeclContext *parent,
1096 llvm::StringRef name) {
1099 auto pit = m_parent_to_namespaces.find(parent);
1100 if (pit == m_parent_to_namespaces.end())
1105 set = &m_namespaces;
1109 for (clang::NamespaceDecl *namespace_decl : *set)
1110 if (namespace_decl->getName().equals(name))
1111 return namespace_decl;
1113 for (clang::NamespaceDecl *namespace_decl : *set)
1114 if (namespace_decl->isAnonymousNamespace())
1115 return FindNamespaceDecl(namespace_decl, name);
1120 bool PDBASTParser::AddEnumValue(CompilerType enum_type,
1121 const PDBSymbolData &enum_value) {
1123 Variant v = enum_value.getValue();
1124 std::string name = MSVCUndecoratedNameParser::DropScope(enum_value.getName());
1127 case PDB_VariantType::Int8:
1128 raw_value = v.Value.Int8;
1130 case PDB_VariantType::Int16:
1131 raw_value = v.Value.Int16;
1133 case PDB_VariantType::Int32:
1134 raw_value = v.Value.Int32;
1136 case PDB_VariantType::Int64:
1137 raw_value = v.Value.Int64;
1139 case PDB_VariantType::UInt8:
1140 raw_value = v.Value.UInt8;
1142 case PDB_VariantType::UInt16:
1143 raw_value = v.Value.UInt16;
1145 case PDB_VariantType::UInt32:
1146 raw_value = v.Value.UInt32;
1148 case PDB_VariantType::UInt64:
1149 raw_value = v.Value.UInt64;
1154 CompilerType underlying_type =
1155 m_ast.GetEnumerationIntegerType(enum_type.GetOpaqueQualType());
1156 uint32_t byte_size = m_ast.getASTContext()->getTypeSize(
1157 ClangUtil::GetQualType(underlying_type));
1158 auto enum_constant_decl = m_ast.AddEnumerationValueToEnumerationType(
1159 enum_type, decl, name.c_str(), raw_value, byte_size * 8);
1160 if (!enum_constant_decl)
1163 m_uid_to_decl[enum_value.getSymIndexId()] = enum_constant_decl;
1168 bool PDBASTParser::CompleteTypeFromUDT(
1169 lldb_private::SymbolFile &symbol_file,
1170 lldb_private::CompilerType &compiler_type,
1171 llvm::pdb::PDBSymbolTypeUDT &udt) {
1172 ClangASTImporter::LayoutInfo layout_info;
1173 layout_info.bit_size = udt.getLength() * 8;
1175 auto nested_enums = udt.findAllChildren<PDBSymbolTypeUDT>();
1177 while (auto nested = nested_enums->getNext())
1178 symbol_file.ResolveTypeUID(nested->getSymIndexId());
1180 auto bases_enum = udt.findAllChildren<PDBSymbolTypeBaseClass>();
1182 AddRecordBases(symbol_file, compiler_type,
1183 TranslateUdtKind(udt.getUdtKind()), *bases_enum,
1186 auto members_enum = udt.findAllChildren<PDBSymbolData>();
1188 AddRecordMembers(symbol_file, compiler_type, *members_enum, layout_info);
1190 auto methods_enum = udt.findAllChildren<PDBSymbolFunc>();
1192 AddRecordMethods(symbol_file, compiler_type, *methods_enum);
1194 m_ast.AddMethodOverridesForCXXRecordType(compiler_type.GetOpaqueQualType());
1195 ClangASTContext::BuildIndirectFields(compiler_type);
1196 ClangASTContext::CompleteTagDeclarationDefinition(compiler_type);
1198 clang::CXXRecordDecl *record_decl =
1199 m_ast.GetAsCXXRecordDecl(compiler_type.GetOpaqueQualType());
1201 return static_cast<bool>(compiler_type);
1203 GetClangASTImporter().InsertRecordDecl(record_decl, layout_info);
1205 return static_cast<bool>(compiler_type);
1208 void PDBASTParser::AddRecordMembers(
1209 lldb_private::SymbolFile &symbol_file,
1210 lldb_private::CompilerType &record_type,
1211 PDBDataSymbolEnumerator &members_enum,
1212 lldb_private::ClangASTImporter::LayoutInfo &layout_info) {
1213 while (auto member = members_enum.getNext()) {
1214 if (member->isCompilerGenerated())
1217 auto member_name = member->getName();
1219 auto member_type = symbol_file.ResolveTypeUID(member->getTypeId());
1223 auto member_comp_type = member_type->GetLayoutCompilerType();
1224 if (!member_comp_type.GetCompleteType()) {
1225 symbol_file.GetObjectFile()->GetModule()->ReportError(
1226 ":: Class '%s' has a member '%s' of type '%s' "
1227 "which does not have a complete definition.",
1228 record_type.GetTypeName().GetCString(), member_name.c_str(),
1229 member_comp_type.GetTypeName().GetCString());
1230 if (ClangASTContext::StartTagDeclarationDefinition(member_comp_type))
1231 ClangASTContext::CompleteTagDeclarationDefinition(member_comp_type);
1234 auto access = TranslateMemberAccess(member->getAccess());
1236 switch (member->getDataKind()) {
1237 case PDB_DataKind::Member: {
1238 auto location_type = member->getLocationType();
1240 auto bit_size = member->getLength();
1241 if (location_type == PDB_LocType::ThisRel)
1244 auto decl = ClangASTContext::AddFieldToRecordType(
1245 record_type, member_name.c_str(), member_comp_type, access, bit_size);
1249 m_uid_to_decl[member->getSymIndexId()] = decl;
1251 auto offset = member->getOffset() * 8;
1252 if (location_type == PDB_LocType::BitField)
1253 offset += member->getBitPosition();
1255 layout_info.field_offsets.insert(std::make_pair(decl, offset));
1259 case PDB_DataKind::StaticMember: {
1260 auto decl = ClangASTContext::AddVariableToRecordType(
1261 record_type, member_name.c_str(), member_comp_type, access);
1265 m_uid_to_decl[member->getSymIndexId()] = decl;
1270 llvm_unreachable("unsupported PDB data kind");
1275 void PDBASTParser::AddRecordBases(
1276 lldb_private::SymbolFile &symbol_file,
1277 lldb_private::CompilerType &record_type, int record_kind,
1278 PDBBaseClassSymbolEnumerator &bases_enum,
1279 lldb_private::ClangASTImporter::LayoutInfo &layout_info) const {
1280 std::vector<std::unique_ptr<clang::CXXBaseSpecifier>> base_classes;
1282 while (auto base = bases_enum.getNext()) {
1283 auto base_type = symbol_file.ResolveTypeUID(base->getTypeId());
1287 auto base_comp_type = base_type->GetFullCompilerType();
1288 if (!base_comp_type.GetCompleteType()) {
1289 symbol_file.GetObjectFile()->GetModule()->ReportError(
1290 ":: Class '%s' has a base class '%s' "
1291 "which does not have a complete definition.",
1292 record_type.GetTypeName().GetCString(),
1293 base_comp_type.GetTypeName().GetCString());
1294 if (ClangASTContext::StartTagDeclarationDefinition(base_comp_type))
1295 ClangASTContext::CompleteTagDeclarationDefinition(base_comp_type);
1298 auto access = TranslateMemberAccess(base->getAccess());
1300 auto is_virtual = base->isVirtualBaseClass();
1302 std::unique_ptr<clang::CXXBaseSpecifier> base_spec =
1303 m_ast.CreateBaseClassSpecifier(base_comp_type.GetOpaqueQualType(),
1305 record_kind == clang::TTK_Class);
1306 lldbassert(base_spec);
1308 base_classes.push_back(std::move(base_spec));
1313 auto decl = m_ast.GetAsCXXRecordDecl(base_comp_type.GetOpaqueQualType());
1317 auto offset = clang::CharUnits::fromQuantity(base->getOffset());
1318 layout_info.base_offsets.insert(std::make_pair(decl, offset));
1321 m_ast.TransferBaseClasses(record_type.GetOpaqueQualType(),
1322 std::move(base_classes));
1325 void PDBASTParser::AddRecordMethods(lldb_private::SymbolFile &symbol_file,
1326 lldb_private::CompilerType &record_type,
1327 PDBFuncSymbolEnumerator &methods_enum) {
1328 while (std::unique_ptr<PDBSymbolFunc> method = methods_enum.getNext())
1329 if (clang::CXXMethodDecl *decl =
1330 AddRecordMethod(symbol_file, record_type, *method))
1331 m_uid_to_decl[method->getSymIndexId()] = decl;
1334 clang::CXXMethodDecl *
1335 PDBASTParser::AddRecordMethod(lldb_private::SymbolFile &symbol_file,
1336 lldb_private::CompilerType &record_type,
1337 const llvm::pdb::PDBSymbolFunc &method) const {
1338 std::string name = MSVCUndecoratedNameParser::DropScope(method.getName());
1340 Type *method_type = symbol_file.ResolveTypeUID(method.getSymIndexId());
1341 // MSVC specific __vecDelDtor.
1345 CompilerType method_comp_type = method_type->GetFullCompilerType();
1346 if (!method_comp_type.GetCompleteType()) {
1347 symbol_file.GetObjectFile()->GetModule()->ReportError(
1348 ":: Class '%s' has a method '%s' whose type cannot be completed.",
1349 record_type.GetTypeName().GetCString(),
1350 method_comp_type.GetTypeName().GetCString());
1351 if (ClangASTContext::StartTagDeclarationDefinition(method_comp_type))
1352 ClangASTContext::CompleteTagDeclarationDefinition(method_comp_type);
1355 AccessType access = TranslateMemberAccess(method.getAccess());
1356 if (access == eAccessNone)
1357 access = eAccessPublic;
1359 // TODO: get mangled name for the method.
1360 return m_ast.AddMethodToCXXRecordType(
1361 record_type.GetOpaqueQualType(), name.c_str(),
1362 /*mangled_name*/ nullptr, method_comp_type, access, method.isVirtual(),
1363 method.isStatic(), method.hasInlineAttribute(),
1364 /*is_explicit*/ false, // FIXME: Need this field in CodeView.
1365 /*is_attr_used*/ false,
1366 /*is_artificial*/ method.isCompilerGenerated());