[llvm] r333159 - [demangler] Add ItaniumPartialDemangler::isCtorOrDtor
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Wed May 23 23:57:58 PDT 2018
Author: maskray
Date: Wed May 23 23:57:57 2018
New Revision: 333159
URL: http://llvm.org/viewvc/llvm-project?rev=333159&view=rev
Log:
[demangler] Add ItaniumPartialDemangler::isCtorOrDtor
Reviewers: erik.pilkington, ruiu, echristo, pcc
Subscribers: llvm-commits
Differential Revision: https://reviews.llvm.org/D47248
Modified:
llvm/trunk/include/llvm/Demangle/Demangle.h
llvm/trunk/lib/Demangle/ItaniumDemangle.cpp
llvm/trunk/unittests/Demangle/PartialDemangleTest.cpp
Modified: llvm/trunk/include/llvm/Demangle/Demangle.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Demangle/Demangle.h?rev=333159&r1=333158&r2=333159&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Demangle/Demangle.h (original)
+++ llvm/trunk/include/llvm/Demangle/Demangle.h Wed May 23 23:57:57 2018
@@ -63,6 +63,9 @@ struct ItaniumPartialDemangler {
/// 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;
Modified: llvm/trunk/lib/Demangle/ItaniumDemangle.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Demangle/ItaniumDemangle.cpp?rev=333159&r1=333158&r2=333159&view=diff
==============================================================================
--- llvm/trunk/lib/Demangle/ItaniumDemangle.cpp (original)
+++ llvm/trunk/lib/Demangle/ItaniumDemangle.cpp Wed May 23 23:57:57 2018
@@ -5264,6 +5264,38 @@ bool ItaniumPartialDemangler::hasFunctio
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;
Modified: llvm/trunk/unittests/Demangle/PartialDemangleTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Demangle/PartialDemangleTest.cpp?rev=333159&r1=333158&r2=333159&view=diff
==============================================================================
--- llvm/trunk/unittests/Demangle/PartialDemangleTest.cpp (original)
+++ llvm/trunk/unittests/Demangle/PartialDemangleTest.cpp Wed May 23 23:57:57 2018
@@ -109,6 +109,32 @@ TEST(PartialDemangleTest, TestNameMeta)
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;
More information about the llvm-commits
mailing list