[PATCH] D47248: [demangler] Add ItaniumPartialDemangler::isCtorOrDtor
Peter Collingbourne via llvm-commits
llvm-commits at lists.llvm.org
Thu May 24 10:13:32 PDT 2018
Are you planning to use this for anything aside from D47249 which was
abandoned?
Peter
On Thu, May 24, 2018 at 12:02 AM, Fangrui Song via Phabricator <
reviews at reviews.llvm.org> wrote:
> This revision was automatically updated to reflect the committed changes.
> Closed by commit rL333159: [demangler] Add ItaniumPartialDemangler::isCtorOrDtor
> (authored by MaskRay, committed by ).
>
> Repository:
> rL LLVM
>
> https://reviews.llvm.org/D47248
>
> Files:
> llvm/trunk/include/llvm/Demangle/Demangle.h
> llvm/trunk/lib/Demangle/ItaniumDemangle.cpp
> llvm/trunk/unittests/Demangle/PartialDemangleTest.cpp
>
>
> Index: llvm/trunk/lib/Demangle/ItaniumDemangle.cpp
> ===================================================================
> --- llvm/trunk/lib/Demangle/ItaniumDemangle.cpp
> +++ llvm/trunk/lib/Demangle/ItaniumDemangle.cpp
> @@ -5264,6 +5264,38 @@
> return E->getCVQuals() != QualNone || E->getRefQual() != FrefQualNone;
> }
>
> +bool ItaniumPartialDemangler::isCtorOrDtor() const {
> + Node *N = static_cast<Node *>(RootNode);
> + while (N) {
> + switch (N->getKind()) {
> + default:
> + return false;
> + case Node::KCtorDtorName:
> + return true;
> +
> + case Node::KAbiTagAttr:
> + N = static_cast<AbiTagAttr *>(N)->Base;
> + break;
> + case Node::KFunctionEncoding:
> + N = static_cast<FunctionEncoding *>(N)->getName();
> + break;
> + case Node::KLocalName:
> + N = static_cast<LocalName *>(N)->Entity;
> + break;
> + case Node::KNameWithTemplateArgs:
> + N = static_cast<NameWithTemplateArgs *>(N)->Name;
> + break;
> + case Node::KNestedName:
> + N = static_cast<NestedName *>(N)->Name;
> + break;
> + case Node::KStdQualifiedName:
> + N = static_cast<StdQualifiedName *>(N)->Child;
> + break;
> + }
> + }
> + return false;
> +}
> +
> bool ItaniumPartialDemangler::isFunction() const {
> assert(RootNode != nullptr && "must call partialDemangle()");
> return static_cast<Node *>(RootNode)->getKind() ==
> Node::KFunctionEncoding;
> Index: llvm/trunk/unittests/Demangle/PartialDemangleTest.cpp
> ===================================================================
> --- llvm/trunk/unittests/Demangle/PartialDemangleTest.cpp
> +++ llvm/trunk/unittests/Demangle/PartialDemangleTest.cpp
> @@ -109,6 +109,32 @@
> EXPECT_TRUE(Demangler.isData());
> }
>
> +TEST(PartialDemanglerTest, TestCtorOrDtor) {
> + static const char *Pos[] = {
> + "_ZN1AC1Ev", // A::A()
> + "_ZN1AC1IiEET_", // A::A<int>(int)
> + "_ZN1AD2Ev", // A::~A()
> + "_ZN1BIiEC1IcEET_", // B<int>::B<char>(char)
> + "_ZN1AC1B1TEv", // A::A[abi:T]()
> + "_ZNSt1AD2Ev", // std::A::~A()
> + "_ZN2ns1AD1Ev", // ns::A::~A()
> + };
> + static const char *Neg[] = {
> + "_Z1fv",
> + "_ZN1A1gIiEEvT_", // void A::g<int>(int)
> + };
> +
> + llvm::ItaniumPartialDemangler D;
> + for (const char *N : Pos) {
> + EXPECT_FALSE(D.partialDemangle(N));
> + EXPECT_TRUE(D.isCtorOrDtor());
> + }
> + for (const char *N : Neg) {
> + EXPECT_FALSE(D.partialDemangle(N));
> + EXPECT_FALSE(D.isCtorOrDtor());
> + }
> +}
> +
> TEST(PartialDemanglerTest, TestMisc) {
> llvm::ItaniumPartialDemangler D1, D2;
>
> Index: llvm/trunk/include/llvm/Demangle/Demangle.h
> ===================================================================
> --- llvm/trunk/include/llvm/Demangle/Demangle.h
> +++ llvm/trunk/include/llvm/Demangle/Demangle.h
> @@ -63,6 +63,9 @@
> /// the function is a non-static member function.
> bool hasFunctionQualifiers() const;
>
> + /// If this symbol describes a constructor or destructor.
> + bool isCtorOrDtor() const;
> +
> /// If this symbol describes a function.
> bool isFunction() const;
>
>
>
>
--
--
Peter
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180524/e35e4630/attachment.html>
More information about the llvm-commits
mailing list