From c204cee642ee794901d2e8a9819b52ac12f92bc9 Mon Sep 17 00:00:00 2001 From: Nathan Sidwell Date: Tue, 29 Mar 2022 04:43:16 -0700 Subject: [PATCH] [demangler] Update node match calls Each demangler node's match function needs to call the provided functor with constructor arguments. That was omitted from D120905. This adds the new Precedence argument where necessary (and a missing boolean for a module node). The two visitors need updating with a printer for that type, and this adds a stub to cxa_demangle's version. blaikie added one to llvm's. I'll fill out those printers in a followup, rather than wait, so that downstream consumers are unbroken. --- libcxxabi/src/cxa_demangle.cpp | 3 ++ libcxxabi/src/demangle/ItaniumDemangle.h | 54 +++++++++++++++----- llvm/include/llvm/Demangle/ItaniumDemangle.h | 50 +++++++++++++----- 3 files changed, 80 insertions(+), 27 deletions(-) diff --git a/libcxxabi/src/cxa_demangle.cpp b/libcxxabi/src/cxa_demangle.cpp index bee4cfd5a119..794cd770d484 100644 --- a/libcxxabi/src/cxa_demangle.cpp +++ b/libcxxabi/src/cxa_demangle.cpp @@ -173,6 +173,9 @@ struct DumpVisitor { return printStr("TemplateParamKind::Template"); } } + void print(Node::Prec) { + // FIXME: Print Prec enumerator + } void newLine() { printStr("\n"); diff --git a/libcxxabi/src/demangle/ItaniumDemangle.h b/libcxxabi/src/demangle/ItaniumDemangle.h index 85b4923a2101..be2cf882bfc2 100644 --- a/libcxxabi/src/demangle/ItaniumDemangle.h +++ b/libcxxabi/src/demangle/ItaniumDemangle.h @@ -1056,7 +1056,9 @@ struct ModuleName : Node { : Node(KModuleName), Parent(Parent_), Name(Name_), IsPartition(IsPartition_) {} - template void match(Fn F) const { F(Parent, Name); } + template void match(Fn F) const { + F(Parent, Name, IsPartition); + } void printLeft(OutputBuffer &OB) const override { if (Parent) @@ -1782,7 +1784,9 @@ public: : Node(KBinaryExpr, Prec_), LHS(LHS_), InfixOperator(InfixOperator_), RHS(RHS_) {} - template void match(Fn F) const { F(LHS, InfixOperator, RHS); } + template void match(Fn F) const { + F(LHS, InfixOperator, RHS, getPrecedence()); + } void printLeft(OutputBuffer &OB) const override { bool ParenAll = OB.isGtInsideTemplateArgs() && InfixOperator == ">"; @@ -1810,7 +1814,9 @@ public: ArraySubscriptExpr(const Node *Op1_, const Node *Op2_, Prec Prec_) : Node(KArraySubscriptExpr, Prec_), Op1(Op1_), Op2(Op2_) {} - template void match(Fn F) const { F(Op1, Op2); } + template void match(Fn F) const { + F(Op1, Op2, getPrecedence()); + } void printLeft(OutputBuffer &OB) const override { Op1->printAsOperand(OB, getPrecedence()); @@ -1828,7 +1834,9 @@ public: PostfixExpr(const Node *Child_, StringView Operator_, Prec Prec_) : Node(KPostfixExpr, Prec_), Child(Child_), Operator(Operator_) {} - template void match(Fn F) const { F(Child, Operator); } + template void match(Fn F) const { + F(Child, Operator, getPrecedence()); + } void printLeft(OutputBuffer &OB) const override { Child->printAsOperand(OB, getPrecedence(), true); @@ -1846,7 +1854,9 @@ public: Prec Prec_) : Node(KConditionalExpr, Prec_), Cond(Cond_), Then(Then_), Else(Else_) {} - template void match(Fn F) const { F(Cond, Then, Else); } + template void match(Fn F) const { + F(Cond, Then, Else, getPrecedence()); + } void printLeft(OutputBuffer &OB) const override { Cond->printAsOperand(OB, getPrecedence()); @@ -1866,7 +1876,9 @@ public: MemberExpr(const Node *LHS_, StringView Kind_, const Node *RHS_, Prec Prec_) : Node(KMemberExpr, Prec_), LHS(LHS_), Kind(Kind_), RHS(RHS_) {} - template void match(Fn F) const { F(LHS, Kind, RHS); } + template void match(Fn F) const { + F(LHS, Kind, RHS, getPrecedence()); + } void printLeft(OutputBuffer &OB) const override { LHS->printAsOperand(OB, getPrecedence(), true); @@ -1918,7 +1930,9 @@ public: EnclosingExpr(StringView Prefix_, Node *Infix_, Prec Prec_ = Prec::Primary) : Node(KEnclosingExpr, Prec_), Prefix(Prefix_), Infix(Infix_) {} - template void match(Fn F) const { F(Prefix, Infix); } + template void match(Fn F) const { + F(Prefix, Infix, getPrecedence()); + } void printLeft(OutputBuffer &OB) const override { OB += Prefix; @@ -1939,7 +1953,9 @@ public: CastExpr(StringView CastKind_, const Node *To_, const Node *From_, Prec Prec_) : Node(KCastExpr, Prec_), CastKind(CastKind_), To(To_), From(From_) {} - template void match(Fn F) const { F(CastKind, To, From); } + template void match(Fn F) const { + F(CastKind, To, From, getPrecedence()); + } void printLeft(OutputBuffer &OB) const override { OB += CastKind; @@ -1983,7 +1999,9 @@ public: CallExpr(const Node *Callee_, NodeArray Args_, Prec Prec_) : Node(KCallExpr, Prec_), Callee(Callee_), Args(Args_) {} - template void match(Fn F) const { F(Callee, Args); } + template void match(Fn F) const { + F(Callee, Args, getPrecedence()); + } void printLeft(OutputBuffer &OB) const override { Callee->print(OB); @@ -2007,7 +2025,7 @@ public: InitList(InitList_), IsGlobal(IsGlobal_), IsArray(IsArray_) {} template void match(Fn F) const { - F(ExprList, Type, InitList, IsGlobal, IsArray); + F(ExprList, Type, InitList, IsGlobal, IsArray, getPrecedence()); } void printLeft(OutputBuffer &OB) const override { @@ -2041,7 +2059,9 @@ public: : Node(KDeleteExpr, Prec_), Op(Op_), IsGlobal(IsGlobal_), IsArray(IsArray_) {} - template void match(Fn F) const { F(Op, IsGlobal, IsArray); } + template void match(Fn F) const { + F(Op, IsGlobal, IsArray, getPrecedence()); + } void printLeft(OutputBuffer &OB) const override { if (IsGlobal) @@ -2062,7 +2082,9 @@ public: PrefixExpr(StringView Prefix_, Node *Child_, Prec Prec_) : Node(KPrefixExpr, Prec_), Prefix(Prefix_), Child(Child_) {} - template void match(Fn F) const { F(Prefix, Child); } + template void match(Fn F) const { + F(Prefix, Child, getPrecedence()); + } void printLeft(OutputBuffer &OB) const override { OB += Prefix; @@ -2092,7 +2114,9 @@ public: ConversionExpr(const Node *Type_, NodeArray Expressions_, Prec Prec_) : Node(KConversionExpr, Prec_), Type(Type_), Expressions(Expressions_) {} - template void match(Fn F) const { F(Type, Expressions); } + template void match(Fn F) const { + F(Type, Expressions, getPrecedence()); + } void printLeft(OutputBuffer &OB) const override { OB.printOpen(); @@ -2115,7 +2139,9 @@ public: : Node(KPointerToMemberConversionExpr, Prec_), Type(Type_), SubExpr(SubExpr_), Offset(Offset_) {} - template void match(Fn F) const { F(Type, SubExpr, Offset); } + template void match(Fn F) const { + F(Type, SubExpr, Offset, getPrecedence()); + } void printLeft(OutputBuffer &OB) const override { OB.printOpen(); diff --git a/llvm/include/llvm/Demangle/ItaniumDemangle.h b/llvm/include/llvm/Demangle/ItaniumDemangle.h index 037e94818d28..778342e7fd59 100644 --- a/llvm/include/llvm/Demangle/ItaniumDemangle.h +++ b/llvm/include/llvm/Demangle/ItaniumDemangle.h @@ -1056,7 +1056,9 @@ struct ModuleName : Node { : Node(KModuleName), Parent(Parent_), Name(Name_), IsPartition(IsPartition_) {} - template void match(Fn F) const { F(Parent, Name); } + template void match(Fn F) const { + F(Parent, Name, IsPartition); + } void printLeft(OutputBuffer &OB) const override { if (Parent) @@ -1812,7 +1814,9 @@ public: ArraySubscriptExpr(const Node *Op1_, const Node *Op2_, Prec Prec_) : Node(KArraySubscriptExpr, Prec_), Op1(Op1_), Op2(Op2_) {} - template void match(Fn F) const { F(Op1, Op2); } + template void match(Fn F) const { + F(Op1, Op2, getPrecedence()); + } void printLeft(OutputBuffer &OB) const override { Op1->printAsOperand(OB, getPrecedence()); @@ -1830,7 +1834,9 @@ public: PostfixExpr(const Node *Child_, StringView Operator_, Prec Prec_) : Node(KPostfixExpr, Prec_), Child(Child_), Operator(Operator_) {} - template void match(Fn F) const { F(Child, Operator); } + template void match(Fn F) const { + F(Child, Operator, getPrecedence()); + } void printLeft(OutputBuffer &OB) const override { Child->printAsOperand(OB, getPrecedence(), true); @@ -1848,7 +1854,9 @@ public: Prec Prec_) : Node(KConditionalExpr, Prec_), Cond(Cond_), Then(Then_), Else(Else_) {} - template void match(Fn F) const { F(Cond, Then, Else); } + template void match(Fn F) const { + F(Cond, Then, Else, getPrecedence()); + } void printLeft(OutputBuffer &OB) const override { Cond->printAsOperand(OB, getPrecedence()); @@ -1868,7 +1876,9 @@ public: MemberExpr(const Node *LHS_, StringView Kind_, const Node *RHS_, Prec Prec_) : Node(KMemberExpr, Prec_), LHS(LHS_), Kind(Kind_), RHS(RHS_) {} - template void match(Fn F) const { F(LHS, Kind, RHS); } + template void match(Fn F) const { + F(LHS, Kind, RHS, getPrecedence()); + } void printLeft(OutputBuffer &OB) const override { LHS->printAsOperand(OB, getPrecedence(), true); @@ -1920,7 +1930,9 @@ public: EnclosingExpr(StringView Prefix_, Node *Infix_, Prec Prec_ = Prec::Primary) : Node(KEnclosingExpr, Prec_), Prefix(Prefix_), Infix(Infix_) {} - template void match(Fn F) const { F(Prefix, Infix); } + template void match(Fn F) const { + F(Prefix, Infix, getPrecedence()); + } void printLeft(OutputBuffer &OB) const override { OB += Prefix; @@ -1941,7 +1953,9 @@ public: CastExpr(StringView CastKind_, const Node *To_, const Node *From_, Prec Prec_) : Node(KCastExpr, Prec_), CastKind(CastKind_), To(To_), From(From_) {} - template void match(Fn F) const { F(CastKind, To, From); } + template void match(Fn F) const { + F(CastKind, To, From, getPrecedence()); + } void printLeft(OutputBuffer &OB) const override { OB += CastKind; @@ -1985,7 +1999,9 @@ public: CallExpr(const Node *Callee_, NodeArray Args_, Prec Prec_) : Node(KCallExpr, Prec_), Callee(Callee_), Args(Args_) {} - template void match(Fn F) const { F(Callee, Args); } + template void match(Fn F) const { + F(Callee, Args, getPrecedence()); + } void printLeft(OutputBuffer &OB) const override { Callee->print(OB); @@ -2009,7 +2025,7 @@ public: InitList(InitList_), IsGlobal(IsGlobal_), IsArray(IsArray_) {} template void match(Fn F) const { - F(ExprList, Type, InitList, IsGlobal, IsArray); + F(ExprList, Type, InitList, IsGlobal, IsArray, getPrecedence()); } void printLeft(OutputBuffer &OB) const override { @@ -2043,7 +2059,9 @@ public: : Node(KDeleteExpr, Prec_), Op(Op_), IsGlobal(IsGlobal_), IsArray(IsArray_) {} - template void match(Fn F) const { F(Op, IsGlobal, IsArray); } + template void match(Fn F) const { + F(Op, IsGlobal, IsArray, getPrecedence()); + } void printLeft(OutputBuffer &OB) const override { if (IsGlobal) @@ -2064,7 +2082,9 @@ public: PrefixExpr(StringView Prefix_, Node *Child_, Prec Prec_) : Node(KPrefixExpr, Prec_), Prefix(Prefix_), Child(Child_) {} - template void match(Fn F) const { F(Prefix, Child); } + template void match(Fn F) const { + F(Prefix, Child, getPrecedence()); + } void printLeft(OutputBuffer &OB) const override { OB += Prefix; @@ -2094,7 +2114,9 @@ public: ConversionExpr(const Node *Type_, NodeArray Expressions_, Prec Prec_) : Node(KConversionExpr, Prec_), Type(Type_), Expressions(Expressions_) {} - template void match(Fn F) const { F(Type, Expressions); } + template void match(Fn F) const { + F(Type, Expressions, getPrecedence()); + } void printLeft(OutputBuffer &OB) const override { OB.printOpen(); @@ -2117,7 +2139,9 @@ public: : Node(KPointerToMemberConversionExpr, Prec_), Type(Type_), SubExpr(SubExpr_), Offset(Offset_) {} - template void match(Fn F) const { F(Type, SubExpr, Offset); } + template void match(Fn F) const { + F(Type, SubExpr, Offset, getPrecedence()); + } void printLeft(OutputBuffer &OB) const override { OB.printOpen();