diff options
author | Kate Stone <katherine.stone@apple.com> | 2016-09-06 20:57:50 +0000 |
---|---|---|
committer | Kate Stone <katherine.stone@apple.com> | 2016-09-06 20:57:50 +0000 |
commit | b9c1b51e45b845debb76d8658edabca70ca56079 (patch) | |
tree | dfcb5a13ef2b014202340f47036da383eaee74aa /lldb/source/Plugins/SymbolFile/PDB/PDBASTParser.cpp | |
parent | d5aa73376966339caad04013510626ec2e42c760 (diff) | |
download | llvm-b9c1b51e45b845debb76d8658edabca70ca56079.zip llvm-b9c1b51e45b845debb76d8658edabca70ca56079.tar.gz llvm-b9c1b51e45b845debb76d8658edabca70ca56079.tar.bz2 |
*** This commit represents a complete reformatting of the LLDB source code
*** to conform to clang-format’s LLVM style. This kind of mass change has
*** two obvious implications:
Firstly, merging this particular commit into a downstream fork may be a huge
effort. Alternatively, it may be worth merging all changes up to this commit,
performing the same reformatting operation locally, and then discarding the
merge for this particular commit. The commands used to accomplish this
reformatting were as follows (with current working directory as the root of
the repository):
find . \( -iname "*.c" -or -iname "*.cpp" -or -iname "*.h" -or -iname "*.mm" \) -exec clang-format -i {} +
find . -iname "*.py" -exec autopep8 --in-place --aggressive --aggressive {} + ;
The version of clang-format used was 3.9.0, and autopep8 was 1.2.4.
Secondly, “blame” style tools will generally point to this commit instead of
a meaningful prior commit. There are alternatives available that will attempt
to look through this change and find the appropriate prior commit. YMMV.
llvm-svn: 280751
Diffstat (limited to 'lldb/source/Plugins/SymbolFile/PDB/PDBASTParser.cpp')
-rw-r--r-- | lldb/source/Plugins/SymbolFile/PDB/PDBASTParser.cpp | 367 |
1 files changed, 181 insertions, 186 deletions
diff --git a/lldb/source/Plugins/SymbolFile/PDB/PDBASTParser.cpp b/lldb/source/Plugins/SymbolFile/PDB/PDBASTParser.cpp index 1e8e040..b48de2e 100644 --- a/lldb/source/Plugins/SymbolFile/PDB/PDBASTParser.cpp +++ b/lldb/source/Plugins/SymbolFile/PDB/PDBASTParser.cpp @@ -34,204 +34,199 @@ using namespace lldb_private; using namespace llvm; using namespace llvm::pdb; -namespace -{ -int -TranslateUdtKind(PDB_UdtType pdb_kind) -{ - switch (pdb_kind) - { - case PDB_UdtType::Class: - return clang::TTK_Class; - case PDB_UdtType::Struct: - return clang::TTK_Struct; - case PDB_UdtType::Union: - return clang::TTK_Union; - case PDB_UdtType::Interface: - return clang::TTK_Interface; - } +namespace { +int TranslateUdtKind(PDB_UdtType pdb_kind) { + switch (pdb_kind) { + case PDB_UdtType::Class: return clang::TTK_Class; + case PDB_UdtType::Struct: + return clang::TTK_Struct; + case PDB_UdtType::Union: + return clang::TTK_Union; + case PDB_UdtType::Interface: + return clang::TTK_Interface; + } + return clang::TTK_Class; } -lldb::Encoding -TranslateBuiltinEncoding(PDB_BuiltinType type) -{ - switch (type) - { - case PDB_BuiltinType::Float: - return lldb::eEncodingIEEE754; - case PDB_BuiltinType::Int: - case PDB_BuiltinType::Long: - case PDB_BuiltinType::Char: - return lldb::eEncodingSint; - case PDB_BuiltinType::Bool: - case PDB_BuiltinType::UInt: - case PDB_BuiltinType::ULong: - case PDB_BuiltinType::HResult: - return lldb::eEncodingUint; - default: - return lldb::eEncodingInvalid; - } +lldb::Encoding TranslateBuiltinEncoding(PDB_BuiltinType type) { + switch (type) { + case PDB_BuiltinType::Float: + return lldb::eEncodingIEEE754; + case PDB_BuiltinType::Int: + case PDB_BuiltinType::Long: + case PDB_BuiltinType::Char: + return lldb::eEncodingSint; + case PDB_BuiltinType::Bool: + case PDB_BuiltinType::UInt: + case PDB_BuiltinType::ULong: + case PDB_BuiltinType::HResult: + return lldb::eEncodingUint; + default: + return lldb::eEncodingInvalid; + } } } -PDBASTParser::PDBASTParser(lldb_private::ClangASTContext &ast) : m_ast(ast) -{ -} +PDBASTParser::PDBASTParser(lldb_private::ClangASTContext &ast) : m_ast(ast) {} -PDBASTParser::~PDBASTParser() -{ -} +PDBASTParser::~PDBASTParser() {} // DebugInfoASTParser interface -lldb::TypeSP -PDBASTParser::CreateLLDBTypeFromPDBType(const PDBSymbol &type) -{ - // PDB doesn't maintain enough information to robustly rebuild the entire - // tree, and this is most problematic when it comes to figure out the - // right DeclContext to put a type in. So for now, everything goes in - // the translation unit decl as a fully qualified type. - clang::DeclContext *tu_decl_ctx = m_ast.GetTranslationUnitDecl(); - Declaration decl; - - if (auto udt = llvm::dyn_cast<PDBSymbolTypeUDT>(&type)) - { - AccessType access = lldb::eAccessPublic; - PDB_UdtType udt_kind = udt->getUdtKind(); - - if (udt_kind == PDB_UdtType::Class) - access = lldb::eAccessPrivate; - - CompilerType clang_type = - m_ast.CreateRecordType(tu_decl_ctx, access, udt->getName().c_str(), TranslateUdtKind(udt_kind), - lldb::eLanguageTypeC_plus_plus, nullptr); - - m_ast.SetHasExternalStorage(clang_type.GetOpaqueQualType(), true); - - return std::make_shared<Type>(type.getSymIndexId(), m_ast.GetSymbolFile(), ConstString(udt->getName()), - udt->getLength(), nullptr, LLDB_INVALID_UID, Type::eEncodingIsUID, decl, - clang_type, Type::eResolveStateForward); - } - else if (auto enum_type = llvm::dyn_cast<PDBSymbolTypeEnum>(&type)) - { - std::string name = enum_type->getName(); - lldb::Encoding encoding = TranslateBuiltinEncoding(enum_type->getBuiltinType()); - uint64_t bytes = enum_type->getLength(); - CompilerType builtin_type = m_ast.GetBuiltinTypeForEncodingAndBitSize(encoding, bytes * 8); - - CompilerType ast_enum = m_ast.CreateEnumerationType(name.c_str(), tu_decl_ctx, decl, builtin_type); - auto enum_values = enum_type->findAllChildren<PDBSymbolData>(); - while (auto enum_value = enum_values->getNext()) - { - if (enum_value->getDataKind() != PDB_DataKind::Constant) - continue; - AddEnumValue(ast_enum, *enum_value); - } - - return std::make_shared<Type>(type.getSymIndexId(), m_ast.GetSymbolFile(), ConstString(name), bytes, nullptr, - LLDB_INVALID_UID, Type::eEncodingIsUID, decl, ast_enum, Type::eResolveStateFull); +lldb::TypeSP PDBASTParser::CreateLLDBTypeFromPDBType(const PDBSymbol &type) { + // PDB doesn't maintain enough information to robustly rebuild the entire + // tree, and this is most problematic when it comes to figure out the + // right DeclContext to put a type in. So for now, everything goes in + // the translation unit decl as a fully qualified type. + clang::DeclContext *tu_decl_ctx = m_ast.GetTranslationUnitDecl(); + Declaration decl; + + if (auto udt = llvm::dyn_cast<PDBSymbolTypeUDT>(&type)) { + AccessType access = lldb::eAccessPublic; + PDB_UdtType udt_kind = udt->getUdtKind(); + + if (udt_kind == PDB_UdtType::Class) + access = lldb::eAccessPrivate; + + CompilerType clang_type = m_ast.CreateRecordType( + tu_decl_ctx, access, udt->getName().c_str(), TranslateUdtKind(udt_kind), + lldb::eLanguageTypeC_plus_plus, nullptr); + + m_ast.SetHasExternalStorage(clang_type.GetOpaqueQualType(), true); + + return std::make_shared<Type>(type.getSymIndexId(), m_ast.GetSymbolFile(), + ConstString(udt->getName()), udt->getLength(), + nullptr, LLDB_INVALID_UID, + Type::eEncodingIsUID, decl, clang_type, + Type::eResolveStateForward); + } else if (auto enum_type = llvm::dyn_cast<PDBSymbolTypeEnum>(&type)) { + std::string name = enum_type->getName(); + lldb::Encoding encoding = + TranslateBuiltinEncoding(enum_type->getBuiltinType()); + uint64_t bytes = enum_type->getLength(); + CompilerType builtin_type = + m_ast.GetBuiltinTypeForEncodingAndBitSize(encoding, bytes * 8); + + CompilerType ast_enum = m_ast.CreateEnumerationType( + name.c_str(), tu_decl_ctx, decl, builtin_type); + auto enum_values = enum_type->findAllChildren<PDBSymbolData>(); + while (auto enum_value = enum_values->getNext()) { + if (enum_value->getDataKind() != PDB_DataKind::Constant) + continue; + AddEnumValue(ast_enum, *enum_value); } - else if (auto type_def = llvm::dyn_cast<PDBSymbolTypeTypedef>(&type)) - { - Type *target_type = m_ast.GetSymbolFile()->ResolveTypeUID(type_def->getTypeId()); - std::string name = type_def->getName(); - uint64_t bytes = type_def->getLength(); - if (!target_type) - return nullptr; - CompilerType target_ast_type = target_type->GetFullCompilerType(); - CompilerDeclContext target_decl_ctx = m_ast.GetSymbolFile()->GetDeclContextForUID(target_type->GetID()); - CompilerType ast_typedef = m_ast.CreateTypedefType(target_ast_type, name.c_str(), target_decl_ctx); - return std::make_shared<Type>(type_def->getSymIndexId(), m_ast.GetSymbolFile(), ConstString(name), bytes, - nullptr, target_type->GetID(), Type::eEncodingIsTypedefUID, decl, ast_typedef, - Type::eResolveStateFull); - } - else if (auto func_sig = llvm::dyn_cast<PDBSymbolTypeFunctionSig>(&type)) - { - auto arg_enum = func_sig->getArguments(); - uint32_t num_args = arg_enum->getChildCount(); - std::vector<CompilerType> arg_list(num_args); - while (auto arg = arg_enum->getNext()) - { - Type *arg_type = m_ast.GetSymbolFile()->ResolveTypeUID(arg->getSymIndexId()); - // If there's some error looking up one of the dependent types of this function signature, bail. - if (!arg_type) - return nullptr; - CompilerType arg_ast_type = arg_type->GetFullCompilerType(); - arg_list.push_back(arg_ast_type); - } - auto pdb_return_type = func_sig->getReturnType(); - Type *return_type = m_ast.GetSymbolFile()->ResolveTypeUID(pdb_return_type->getSymIndexId()); - // If there's some error looking up one of the dependent types of this function signature, bail. - if (!return_type) - return nullptr; - CompilerType return_ast_type = return_type->GetFullCompilerType(); - uint32_t type_quals = 0; - if (func_sig->isConstType()) - type_quals |= clang::Qualifiers::Const; - if (func_sig->isVolatileType()) - type_quals |= clang::Qualifiers::Volatile; - CompilerType func_sig_ast_type = - m_ast.CreateFunctionType(return_ast_type, &arg_list[0], num_args, false, type_quals); - - return std::make_shared<Type>(func_sig->getSymIndexId(), m_ast.GetSymbolFile(), ConstString(), 0, nullptr, - LLDB_INVALID_UID, Type::eEncodingIsUID, decl, func_sig_ast_type, - Type::eResolveStateFull); - } - else if (auto array_type = llvm::dyn_cast<PDBSymbolTypeArray>(&type)) - { - uint32_t num_elements = array_type->getCount(); - uint32_t element_uid = array_type->getElementType()->getSymIndexId(); - uint32_t bytes = array_type->getLength(); - - Type *element_type = m_ast.GetSymbolFile()->ResolveTypeUID(element_uid); - CompilerType element_ast_type = element_type->GetFullCompilerType(); - CompilerType array_ast_type = m_ast.CreateArrayType(element_ast_type, num_elements, false); - return std::make_shared<Type>(array_type->getSymIndexId(), m_ast.GetSymbolFile(), ConstString(), bytes, nullptr, - LLDB_INVALID_UID, Type::eEncodingIsUID, decl, array_ast_type, - Type::eResolveStateFull); + + return std::make_shared<Type>(type.getSymIndexId(), m_ast.GetSymbolFile(), + ConstString(name), bytes, nullptr, + LLDB_INVALID_UID, Type::eEncodingIsUID, decl, + ast_enum, Type::eResolveStateFull); + } else if (auto type_def = llvm::dyn_cast<PDBSymbolTypeTypedef>(&type)) { + Type *target_type = + m_ast.GetSymbolFile()->ResolveTypeUID(type_def->getTypeId()); + std::string name = type_def->getName(); + uint64_t bytes = type_def->getLength(); + if (!target_type) + return nullptr; + CompilerType target_ast_type = target_type->GetFullCompilerType(); + CompilerDeclContext target_decl_ctx = + m_ast.GetSymbolFile()->GetDeclContextForUID(target_type->GetID()); + CompilerType ast_typedef = + m_ast.CreateTypedefType(target_ast_type, name.c_str(), target_decl_ctx); + return std::make_shared<Type>( + type_def->getSymIndexId(), m_ast.GetSymbolFile(), ConstString(name), + bytes, nullptr, target_type->GetID(), Type::eEncodingIsTypedefUID, decl, + ast_typedef, Type::eResolveStateFull); + } else if (auto func_sig = llvm::dyn_cast<PDBSymbolTypeFunctionSig>(&type)) { + auto arg_enum = func_sig->getArguments(); + uint32_t num_args = arg_enum->getChildCount(); + std::vector<CompilerType> arg_list(num_args); + while (auto arg = arg_enum->getNext()) { + Type *arg_type = + m_ast.GetSymbolFile()->ResolveTypeUID(arg->getSymIndexId()); + // If there's some error looking up one of the dependent types of this + // function signature, bail. + if (!arg_type) + return nullptr; + CompilerType arg_ast_type = arg_type->GetFullCompilerType(); + arg_list.push_back(arg_ast_type); } - return nullptr; + auto pdb_return_type = func_sig->getReturnType(); + Type *return_type = + m_ast.GetSymbolFile()->ResolveTypeUID(pdb_return_type->getSymIndexId()); + // If there's some error looking up one of the dependent types of this + // function signature, bail. + if (!return_type) + return nullptr; + CompilerType return_ast_type = return_type->GetFullCompilerType(); + uint32_t type_quals = 0; + if (func_sig->isConstType()) + type_quals |= clang::Qualifiers::Const; + if (func_sig->isVolatileType()) + type_quals |= clang::Qualifiers::Volatile; + CompilerType func_sig_ast_type = m_ast.CreateFunctionType( + return_ast_type, &arg_list[0], num_args, false, type_quals); + + return std::make_shared<Type>( + func_sig->getSymIndexId(), m_ast.GetSymbolFile(), ConstString(), 0, + nullptr, LLDB_INVALID_UID, Type::eEncodingIsUID, decl, + func_sig_ast_type, Type::eResolveStateFull); + } else if (auto array_type = llvm::dyn_cast<PDBSymbolTypeArray>(&type)) { + uint32_t num_elements = array_type->getCount(); + uint32_t element_uid = array_type->getElementType()->getSymIndexId(); + uint32_t bytes = array_type->getLength(); + + Type *element_type = m_ast.GetSymbolFile()->ResolveTypeUID(element_uid); + CompilerType element_ast_type = element_type->GetFullCompilerType(); + CompilerType array_ast_type = + m_ast.CreateArrayType(element_ast_type, num_elements, false); + return std::make_shared<Type>( + array_type->getSymIndexId(), m_ast.GetSymbolFile(), ConstString(), + bytes, nullptr, LLDB_INVALID_UID, Type::eEncodingIsUID, decl, + array_ast_type, Type::eResolveStateFull); + } + return nullptr; } -bool -PDBASTParser::AddEnumValue(CompilerType enum_type, const PDBSymbolData &enum_value) const -{ - Declaration decl; - Variant v = enum_value.getValue(); - std::string name = enum_value.getName(); - int64_t raw_value; - switch (v.Type) - { - case PDB_VariantType::Int8: - raw_value = v.Value.Int8; - break; - case PDB_VariantType::Int16: - raw_value = v.Value.Int16; - break; - case PDB_VariantType::Int32: - raw_value = v.Value.Int32; - break; - case PDB_VariantType::Int64: - raw_value = v.Value.Int64; - break; - case PDB_VariantType::UInt8: - raw_value = v.Value.UInt8; - break; - case PDB_VariantType::UInt16: - raw_value = v.Value.UInt16; - break; - case PDB_VariantType::UInt32: - raw_value = v.Value.UInt32; - break; - case PDB_VariantType::UInt64: - raw_value = v.Value.UInt64; - break; - default: - return false; - } - CompilerType underlying_type = m_ast.GetEnumerationIntegerType(enum_type.GetOpaqueQualType()); - uint32_t byte_size = m_ast.getASTContext()->getTypeSize(ClangUtil::GetQualType(underlying_type)); - return m_ast.AddEnumerationValueToEnumerationType(enum_type.GetOpaqueQualType(), underlying_type, decl, - name.c_str(), raw_value, byte_size * 8); +bool PDBASTParser::AddEnumValue(CompilerType enum_type, + const PDBSymbolData &enum_value) const { + Declaration decl; + Variant v = enum_value.getValue(); + std::string name = enum_value.getName(); + int64_t raw_value; + switch (v.Type) { + case PDB_VariantType::Int8: + raw_value = v.Value.Int8; + break; + case PDB_VariantType::Int16: + raw_value = v.Value.Int16; + break; + case PDB_VariantType::Int32: + raw_value = v.Value.Int32; + break; + case PDB_VariantType::Int64: + raw_value = v.Value.Int64; + break; + case PDB_VariantType::UInt8: + raw_value = v.Value.UInt8; + break; + case PDB_VariantType::UInt16: + raw_value = v.Value.UInt16; + break; + case PDB_VariantType::UInt32: + raw_value = v.Value.UInt32; + break; + case PDB_VariantType::UInt64: + raw_value = v.Value.UInt64; + break; + default: + return false; + } + CompilerType underlying_type = + m_ast.GetEnumerationIntegerType(enum_type.GetOpaqueQualType()); + uint32_t byte_size = m_ast.getASTContext()->getTypeSize( + ClangUtil::GetQualType(underlying_type)); + return m_ast.AddEnumerationValueToEnumerationType( + enum_type.GetOpaqueQualType(), underlying_type, decl, name.c_str(), + raw_value, byte_size * 8); } |