ItaniumDemangleTest.cpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. //===------------------ ItaniumDemangleTest.cpp ---------------------------===//
  2. //
  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
  6. //
  7. //===----------------------------------------------------------------------===//
  8. #include "llvm/Demangle/ItaniumDemangle.h"
  9. #include "llvm/Support/Allocator.h"
  10. #include "gmock/gmock.h"
  11. #include "gtest/gtest.h"
  12. #include <cstdlib>
  13. #include <vector>
  14. using namespace llvm;
  15. using namespace llvm::itanium_demangle;
  16. namespace {
  17. class TestAllocator {
  18. BumpPtrAllocator Alloc;
  19. public:
  20. void reset() { Alloc.Reset(); }
  21. template <typename T, typename... Args> T *makeNode(Args &&... args) {
  22. return new (Alloc.Allocate(sizeof(T), alignof(T)))
  23. T(std::forward<Args>(args)...);
  24. }
  25. void *allocateNodeArray(size_t sz) {
  26. return Alloc.Allocate(sizeof(Node *) * sz, alignof(Node *));
  27. }
  28. };
  29. } // namespace
  30. TEST(ItaniumDemangle, MethodOverride) {
  31. struct TestParser : AbstractManglingParser<TestParser, TestAllocator> {
  32. std::vector<char> Types;
  33. TestParser(const char *Str)
  34. : AbstractManglingParser(Str, Str + strlen(Str)) {}
  35. Node *parseType() {
  36. Types.push_back(*First);
  37. return AbstractManglingParser<TestParser, TestAllocator>::parseType();
  38. }
  39. };
  40. TestParser Parser("_Z1fIiEjl");
  41. ASSERT_NE(nullptr, Parser.parse());
  42. EXPECT_THAT(Parser.Types, testing::ElementsAre('i', 'j', 'l'));
  43. }