Support: Add dwarf::getVirtuality()

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@228474 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Duncan P. N. Exon Smith 2015-02-07 00:37:15 +00:00
parent a496490358
commit 5a504d487c
3 changed files with 27 additions and 3 deletions

View File

@ -38,7 +38,8 @@ namespace dwarf {
enum LLVMConstants : uint32_t { enum LLVMConstants : uint32_t {
// LLVM mock tags (see also llvm/Support/Dwarf.def). // LLVM mock tags (see also llvm/Support/Dwarf.def).
DW_TAG_invalid = ~0U, // Tag for invalid results. DW_TAG_invalid = ~0U, // Tag for invalid results.
DW_VIRTUALITY_invalid = ~0U, // Virtuality for invalid results.
// Other constants. // Other constants.
DWARF_VERSION = 4, // Default dwarf version we output. DWARF_VERSION = 4, // Default dwarf version we output.
@ -742,11 +743,14 @@ const char *GDBIndexEntryLinkageString(GDBIndexEntryLinkage Linkage);
/// \defgroup DwarfConstantsParsing Dwarf constants parsing functions /// \defgroup DwarfConstantsParsing Dwarf constants parsing functions
/// ///
/// These functions map their strings back to the corresponding enumeration /// These functions map their strings back to the corresponding enumeration
/// value or return 0 if there is none. As an exception, \a getTag() returns /// value or return 0 if there is none, except for these exceptions:
/// \a DW_TAG_invalid on invalid input. ///
/// \li \a getTag() returns \a DW_TAG_invalid on invalid input.
/// \li \a getVirtuality() returns \a DW_VIRTUALITY_invalid on invalid input.
/// ///
/// @{ /// @{
unsigned getTag(StringRef TagString); unsigned getTag(StringRef TagString);
unsigned getVirtuality(StringRef VirtualityString);
unsigned getLanguage(StringRef LanguageString); unsigned getLanguage(StringRef LanguageString);
unsigned getAttributeEncoding(StringRef EncodingString); unsigned getAttributeEncoding(StringRef EncodingString);
/// @} /// @}

View File

@ -473,6 +473,14 @@ const char *llvm::dwarf::VirtualityString(unsigned Virtuality) {
} }
} }
unsigned llvm::dwarf::getVirtuality(StringRef VirtualityString) {
return StringSwitch<unsigned>(VirtualityString)
#define HANDLE_DW_VIRTUALITY(ID, NAME) \
.Case("DW_VIRTUALITY_" #NAME, DW_VIRTUALITY_##NAME)
#include "llvm/Support/Dwarf.def"
.Default(DW_VIRTUALITY_invalid);
}
const char *llvm::dwarf::LanguageString(unsigned Language) { const char *llvm::dwarf::LanguageString(unsigned Language) {
switch (Language) { switch (Language) {
default: default:

View File

@ -109,4 +109,16 @@ TEST(DwarfTest, VirtualityString) {
EXPECT_EQ(nullptr, VirtualityString(DW_VIRTUALITY_max + 77)); EXPECT_EQ(nullptr, VirtualityString(DW_VIRTUALITY_max + 77));
} }
TEST(DwarfTest, getVirtuality) {
EXPECT_EQ(DW_VIRTUALITY_none, getVirtuality("DW_VIRTUALITY_none"));
EXPECT_EQ(DW_VIRTUALITY_virtual, getVirtuality("DW_VIRTUALITY_virtual"));
EXPECT_EQ(DW_VIRTUALITY_pure_virtual,
getVirtuality("DW_VIRTUALITY_pure_virtual"));
// Invalid strings.
EXPECT_EQ(DW_VIRTUALITY_invalid, getVirtuality("DW_VIRTUALITY_invalid"));
EXPECT_EQ(DW_VIRTUALITY_invalid, getVirtuality("DW_VIRTUALITY_max"));
EXPECT_EQ(DW_VIRTUALITY_invalid, getVirtuality("something else"));
}
} // end namespace } // end namespace