forked from OSchip/llvm-project
Port libcxxabi r344607 into llvm
Summary: The original commit message was: This uses CRTP (for performance reasons) to allow a user the override demangler functions to implement custom parsing logic. The motivation for this is LLDB, which needs to occasionaly modify the mangled names. One such instance is already implemented via the TypeCallback member, but this is very specific functionality which does not help with any other use case. Currently we have a use case for modifying the constructor flavours, which would require adding another callback. This approach does not scale. With CRTP, the user (LLDB) can override any function it needs without any special support from the demangler library. After LLDB is ported to use this instead of the TypeCallback mechanism, the callback can be removed. The only difference here is the addition of a unit test which exercises the CRTP mechanism to override a function in the parser. Reviewers: erik.pilkington, rsmith, EricWF Subscribers: mgorny, kristina, llvm-commits Differential Revision: https://reviews.llvm.org/D53300 llvm-svn: 344703
This commit is contained in:
parent
40968955ff
commit
f4c1582476
File diff suppressed because it is too large
Load Diff
|
@ -322,7 +322,7 @@ public:
|
|||
// Code beyond this point should not be synchronized with libc++abi.
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
using Demangler = itanium_demangle::Db<DefaultAllocator>;
|
||||
using Demangler = itanium_demangle::ManglingParser<DefaultAllocator>;
|
||||
|
||||
char *llvm::itaniumDemangle(const char *MangledName, char *Buf,
|
||||
size_t *N, int *Status) {
|
||||
|
|
|
@ -221,7 +221,8 @@ struct CanonicalizerAllocator::MakeNodeImpl<
|
|||
|
||||
// FIXME: Also expand built-in substitutions?
|
||||
|
||||
using CanonicalizingDemangler = itanium_demangle::Db<CanonicalizerAllocator>;
|
||||
using CanonicalizingDemangler =
|
||||
itanium_demangle::ManglingParser<CanonicalizerAllocator>;
|
||||
}
|
||||
|
||||
struct ItaniumManglingCanonicalizer::Impl {
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
set(LLVM_LINK_COMPONENTS
|
||||
Demangle
|
||||
Support
|
||||
)
|
||||
|
||||
add_llvm_unittest(DemangleTests
|
||||
ItaniumDemangleTest.cpp
|
||||
PartialDemangleTest.cpp
|
||||
FindTypesInMangledNameTest.cpp
|
||||
)
|
||||
|
|
|
@ -0,0 +1,54 @@
|
|||
//===------------------ ItaniumDemangleTest.cpp ---------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "llvm/Demangle/ItaniumDemangle.h"
|
||||
#include "llvm/Support/Allocator.h"
|
||||
#include "gmock/gmock.h"
|
||||
#include "gtest/gtest.h"
|
||||
#include <cstdlib>
|
||||
#include <vector>
|
||||
|
||||
using namespace llvm;
|
||||
using namespace llvm::itanium_demangle;
|
||||
|
||||
namespace {
|
||||
class TestAllocator {
|
||||
BumpPtrAllocator Alloc;
|
||||
|
||||
public:
|
||||
void reset() { Alloc.Reset(); }
|
||||
|
||||
template <typename T, typename... Args> T *makeNode(Args &&... args) {
|
||||
return new (Alloc.Allocate(sizeof(T), alignof(T)))
|
||||
T(std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
void *allocateNodeArray(size_t sz) {
|
||||
return Alloc.Allocate(sizeof(Node *) * sz, alignof(Node *));
|
||||
}
|
||||
};
|
||||
} // namespace
|
||||
|
||||
TEST(ItaniumDemangle, MethodOverride) {
|
||||
struct TestParser : AbstractManglingParser<TestParser, TestAllocator> {
|
||||
std::vector<char> Types;
|
||||
|
||||
TestParser(const char *Str)
|
||||
: AbstractManglingParser(Str, Str + strlen(Str)) {}
|
||||
|
||||
Node *parseType() {
|
||||
Types.push_back(*First);
|
||||
return AbstractManglingParser<TestParser, TestAllocator>::parseType();
|
||||
}
|
||||
};
|
||||
|
||||
TestParser Parser("_Z1fIiEjl");
|
||||
ASSERT_NE(nullptr, Parser.parse());
|
||||
EXPECT_THAT(Parser.Types, testing::ElementsAre('i', 'j', 'l'));
|
||||
}
|
Loading…
Reference in New Issue