[demangler][NFC] Use def file for node names

In order to add a unit test, we need to expose the node names beyond
ItaniumDemangle.h.  This breaks them out into a def file.

Reviewed By: dblaikie

Differential Revision: https://reviews.llvm.org/D122739
This commit is contained in:
Nathan Sidwell 2022-03-30 05:59:16 -07:00
parent e63b81d10e
commit 369337e3c2
5 changed files with 212 additions and 190 deletions

View File

@ -28,86 +28,6 @@
#include <limits>
#include <utility>
#define FOR_EACH_NODE_KIND(X) \
X(NodeArrayNode) \
X(DotSuffix) \
X(VendorExtQualType) \
X(QualType) \
X(ConversionOperatorType) \
X(PostfixQualifiedType) \
X(ElaboratedTypeSpefType) \
X(NameType) \
X(AbiTagAttr) \
X(EnableIfAttr) \
X(ObjCProtoName) \
X(PointerType) \
X(ReferenceType) \
X(PointerToMemberType) \
X(ArrayType) \
X(FunctionType) \
X(NoexceptSpec) \
X(DynamicExceptionSpec) \
X(FunctionEncoding) \
X(LiteralOperator) \
X(SpecialName) \
X(CtorVtableSpecialName) \
X(QualifiedName) \
X(NestedName) \
X(LocalName) \
X(ModuleName) \
X(ModuleEntity) \
X(VectorType) \
X(PixelVectorType) \
X(BinaryFPType) \
X(SyntheticTemplateParamName) \
X(TypeTemplateParamDecl) \
X(NonTypeTemplateParamDecl) \
X(TemplateTemplateParamDecl) \
X(TemplateParamPackDecl) \
X(ParameterPack) \
X(TemplateArgumentPack) \
X(ParameterPackExpansion) \
X(TemplateArgs) \
X(ForwardTemplateReference) \
X(NameWithTemplateArgs) \
X(GlobalQualifiedName) \
X(ExpandedSpecialSubstitution) \
X(SpecialSubstitution) \
X(CtorDtorName) \
X(DtorName) \
X(UnnamedTypeName) \
X(ClosureTypeName) \
X(StructuredBindingName) \
X(BinaryExpr) \
X(ArraySubscriptExpr) \
X(PostfixExpr) \
X(ConditionalExpr) \
X(MemberExpr) \
X(SubobjectExpr) \
X(EnclosingExpr) \
X(CastExpr) \
X(SizeofParamPackExpr) \
X(CallExpr) \
X(NewExpr) \
X(DeleteExpr) \
X(PrefixExpr) \
X(FunctionParam) \
X(ConversionExpr) \
X(PointerToMemberConversionExpr) \
X(InitListExpr) \
X(FoldExpr) \
X(ThrowExpr) \
X(BoolExpr) \
X(StringLiteral) \
X(LambdaExpr) \
X(EnumLiteral) \
X(IntegerLiteral) \
X(FloatLiteral) \
X(DoubleLiteral) \
X(LongDoubleLiteral) \
X(BracedExpr) \
X(BracedRangeExpr)
DEMANGLE_NAMESPACE_BEGIN
template <class T, size_t N> class PODSmallVector {
@ -235,9 +155,8 @@ public:
class Node {
public:
enum Kind : unsigned char {
#define ENUMERATOR(NodeKind) K ## NodeKind,
FOR_EACH_NODE_KIND(ENUMERATOR)
#undef ENUMERATOR
#define NODE(NodeKind) K##NodeKind,
#include "ItaniumNodes.def"
};
/// Three-way bool to track a cached value. Unknown is possible if this node
@ -2440,24 +2359,22 @@ using LongDoubleLiteral = FloatLiteralImpl<long double>;
template<typename Fn>
void Node::visit(Fn F) const {
switch (K) {
#define CASE(X) case K ## X: return F(static_cast<const X*>(this));
FOR_EACH_NODE_KIND(CASE)
#undef CASE
#define NODE(X) \
case K##X: \
return F(static_cast<const X *>(this));
#include "ItaniumNodes.def"
}
assert(0 && "unknown mangling node kind");
}
/// Determine the kind of a node from its type.
template<typename NodeT> struct NodeKind;
#define SPECIALIZATION(X) \
template<> struct NodeKind<X> { \
static constexpr Node::Kind Kind = Node::K##X; \
static constexpr const char *name() { return #X; } \
#define NODE(X) \
template <> struct NodeKind<X> { \
static constexpr Node::Kind Kind = Node::K##X; \
static constexpr const char *name() { return #X; } \
};
FOR_EACH_NODE_KIND(SPECIALIZATION)
#undef SPECIALIZATION
#undef FOR_EACH_NODE_KIND
#include "ItaniumNodes.def"
template <typename Derived, typename Alloc> struct AbstractManglingParser {
const char *First;

View File

@ -0,0 +1,94 @@
//===------------------------- ItaniumNodes.def ----------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// Define the demangler's node names
#ifndef NODE
#error Define NODE to handle nodes
#endif
NODE(NodeArrayNode)
NODE(DotSuffix)
NODE(VendorExtQualType)
NODE(QualType)
NODE(ConversionOperatorType)
NODE(PostfixQualifiedType)
NODE(ElaboratedTypeSpefType)
NODE(NameType)
NODE(AbiTagAttr)
NODE(EnableIfAttr)
NODE(ObjCProtoName)
NODE(PointerType)
NODE(ReferenceType)
NODE(PointerToMemberType)
NODE(ArrayType)
NODE(FunctionType)
NODE(NoexceptSpec)
NODE(DynamicExceptionSpec)
NODE(FunctionEncoding)
NODE(LiteralOperator)
NODE(SpecialName)
NODE(CtorVtableSpecialName)
NODE(QualifiedName)
NODE(NestedName)
NODE(LocalName)
NODE(ModuleName)
NODE(ModuleEntity)
NODE(VectorType)
NODE(PixelVectorType)
NODE(BinaryFPType)
NODE(SyntheticTemplateParamName)
NODE(TypeTemplateParamDecl)
NODE(NonTypeTemplateParamDecl)
NODE(TemplateTemplateParamDecl)
NODE(TemplateParamPackDecl)
NODE(ParameterPack)
NODE(TemplateArgumentPack)
NODE(ParameterPackExpansion)
NODE(TemplateArgs)
NODE(ForwardTemplateReference)
NODE(NameWithTemplateArgs)
NODE(GlobalQualifiedName)
NODE(ExpandedSpecialSubstitution)
NODE(SpecialSubstitution)
NODE(CtorDtorName)
NODE(DtorName)
NODE(UnnamedTypeName)
NODE(ClosureTypeName)
NODE(StructuredBindingName)
NODE(BinaryExpr)
NODE(ArraySubscriptExpr)
NODE(PostfixExpr)
NODE(ConditionalExpr)
NODE(MemberExpr)
NODE(SubobjectExpr)
NODE(EnclosingExpr)
NODE(CastExpr)
NODE(SizeofParamPackExpr)
NODE(CallExpr)
NODE(NewExpr)
NODE(DeleteExpr)
NODE(PrefixExpr)
NODE(FunctionParam)
NODE(ConversionExpr)
NODE(PointerToMemberConversionExpr)
NODE(InitListExpr)
NODE(FoldExpr)
NODE(ThrowExpr)
NODE(BoolExpr)
NODE(StringLiteral)
NODE(LambdaExpr)
NODE(EnumLiteral)
NODE(IntegerLiteral)
NODE(FloatLiteral)
NODE(DoubleLiteral)
NODE(LongDoubleLiteral)
NODE(BracedExpr)
NODE(BracedRangeExpr)
#undef NODE

View File

@ -6,7 +6,7 @@
set -e
cd $(dirname $0)
HDRS="ItaniumDemangle.h StringView.h Utility.h"
HDRS="ItaniumDemangle.h ItaniumNodes.def StringView.h Utility.h"
LLVM_DEMANGLE_DIR=$1
if [[ -z "$LLVM_DEMANGLE_DIR" ]]; then
@ -28,7 +28,7 @@ if [[ $ANSWER =~ ^[Yy]$ ]]; then
rm -f $LLVM_DEMANGLE_DIR/$I
dash=$(echo "$I---------------------------" | cut -c -27 |\
sed 's|[^-]*||')
sed -e '1s|^//=*-* .*\.h -*.*=*// *$|//===--- '"$I $dash"'-*- mode:c++;eval:(read-only-mode) -*-===//|' \
sed -e '1s|^//=*-* .*\..* -*.*=*// *$|//===--- '"$I $dash"'-*- mode:c++;eval:(read-only-mode) -*-===//|' \
-e '2s|^// *$|// Do not edit! See README.txt.|' \
$I >$LLVM_DEMANGLE_DIR/$I
chmod -w $LLVM_DEMANGLE_DIR/$I

View File

@ -28,86 +28,6 @@
#include <limits>
#include <utility>
#define FOR_EACH_NODE_KIND(X) \
X(NodeArrayNode) \
X(DotSuffix) \
X(VendorExtQualType) \
X(QualType) \
X(ConversionOperatorType) \
X(PostfixQualifiedType) \
X(ElaboratedTypeSpefType) \
X(NameType) \
X(AbiTagAttr) \
X(EnableIfAttr) \
X(ObjCProtoName) \
X(PointerType) \
X(ReferenceType) \
X(PointerToMemberType) \
X(ArrayType) \
X(FunctionType) \
X(NoexceptSpec) \
X(DynamicExceptionSpec) \
X(FunctionEncoding) \
X(LiteralOperator) \
X(SpecialName) \
X(CtorVtableSpecialName) \
X(QualifiedName) \
X(NestedName) \
X(LocalName) \
X(ModuleName) \
X(ModuleEntity) \
X(VectorType) \
X(PixelVectorType) \
X(BinaryFPType) \
X(SyntheticTemplateParamName) \
X(TypeTemplateParamDecl) \
X(NonTypeTemplateParamDecl) \
X(TemplateTemplateParamDecl) \
X(TemplateParamPackDecl) \
X(ParameterPack) \
X(TemplateArgumentPack) \
X(ParameterPackExpansion) \
X(TemplateArgs) \
X(ForwardTemplateReference) \
X(NameWithTemplateArgs) \
X(GlobalQualifiedName) \
X(ExpandedSpecialSubstitution) \
X(SpecialSubstitution) \
X(CtorDtorName) \
X(DtorName) \
X(UnnamedTypeName) \
X(ClosureTypeName) \
X(StructuredBindingName) \
X(BinaryExpr) \
X(ArraySubscriptExpr) \
X(PostfixExpr) \
X(ConditionalExpr) \
X(MemberExpr) \
X(SubobjectExpr) \
X(EnclosingExpr) \
X(CastExpr) \
X(SizeofParamPackExpr) \
X(CallExpr) \
X(NewExpr) \
X(DeleteExpr) \
X(PrefixExpr) \
X(FunctionParam) \
X(ConversionExpr) \
X(PointerToMemberConversionExpr) \
X(InitListExpr) \
X(FoldExpr) \
X(ThrowExpr) \
X(BoolExpr) \
X(StringLiteral) \
X(LambdaExpr) \
X(EnumLiteral) \
X(IntegerLiteral) \
X(FloatLiteral) \
X(DoubleLiteral) \
X(LongDoubleLiteral) \
X(BracedExpr) \
X(BracedRangeExpr)
DEMANGLE_NAMESPACE_BEGIN
template <class T, size_t N> class PODSmallVector {
@ -235,9 +155,8 @@ public:
class Node {
public:
enum Kind : unsigned char {
#define ENUMERATOR(NodeKind) K ## NodeKind,
FOR_EACH_NODE_KIND(ENUMERATOR)
#undef ENUMERATOR
#define NODE(NodeKind) K##NodeKind,
#include "ItaniumNodes.def"
};
/// Three-way bool to track a cached value. Unknown is possible if this node
@ -2440,24 +2359,22 @@ using LongDoubleLiteral = FloatLiteralImpl<long double>;
template<typename Fn>
void Node::visit(Fn F) const {
switch (K) {
#define CASE(X) case K ## X: return F(static_cast<const X*>(this));
FOR_EACH_NODE_KIND(CASE)
#undef CASE
#define NODE(X) \
case K##X: \
return F(static_cast<const X *>(this));
#include "ItaniumNodes.def"
}
assert(0 && "unknown mangling node kind");
}
/// Determine the kind of a node from its type.
template<typename NodeT> struct NodeKind;
#define SPECIALIZATION(X) \
template<> struct NodeKind<X> { \
static constexpr Node::Kind Kind = Node::K##X; \
static constexpr const char *name() { return #X; } \
#define NODE(X) \
template <> struct NodeKind<X> { \
static constexpr Node::Kind Kind = Node::K##X; \
static constexpr const char *name() { return #X; } \
};
FOR_EACH_NODE_KIND(SPECIALIZATION)
#undef SPECIALIZATION
#undef FOR_EACH_NODE_KIND
#include "ItaniumNodes.def"
template <typename Derived, typename Alloc> struct AbstractManglingParser {
const char *First;

View File

@ -0,0 +1,94 @@
//===--- ItaniumNodes.def ------------*- mode:c++;eval:(read-only-mode) -*-===//
// Do not edit! See README.txt.
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// Define the demangler's node names
#ifndef NODE
#error Define NODE to handle nodes
#endif
NODE(NodeArrayNode)
NODE(DotSuffix)
NODE(VendorExtQualType)
NODE(QualType)
NODE(ConversionOperatorType)
NODE(PostfixQualifiedType)
NODE(ElaboratedTypeSpefType)
NODE(NameType)
NODE(AbiTagAttr)
NODE(EnableIfAttr)
NODE(ObjCProtoName)
NODE(PointerType)
NODE(ReferenceType)
NODE(PointerToMemberType)
NODE(ArrayType)
NODE(FunctionType)
NODE(NoexceptSpec)
NODE(DynamicExceptionSpec)
NODE(FunctionEncoding)
NODE(LiteralOperator)
NODE(SpecialName)
NODE(CtorVtableSpecialName)
NODE(QualifiedName)
NODE(NestedName)
NODE(LocalName)
NODE(ModuleName)
NODE(ModuleEntity)
NODE(VectorType)
NODE(PixelVectorType)
NODE(BinaryFPType)
NODE(SyntheticTemplateParamName)
NODE(TypeTemplateParamDecl)
NODE(NonTypeTemplateParamDecl)
NODE(TemplateTemplateParamDecl)
NODE(TemplateParamPackDecl)
NODE(ParameterPack)
NODE(TemplateArgumentPack)
NODE(ParameterPackExpansion)
NODE(TemplateArgs)
NODE(ForwardTemplateReference)
NODE(NameWithTemplateArgs)
NODE(GlobalQualifiedName)
NODE(ExpandedSpecialSubstitution)
NODE(SpecialSubstitution)
NODE(CtorDtorName)
NODE(DtorName)
NODE(UnnamedTypeName)
NODE(ClosureTypeName)
NODE(StructuredBindingName)
NODE(BinaryExpr)
NODE(ArraySubscriptExpr)
NODE(PostfixExpr)
NODE(ConditionalExpr)
NODE(MemberExpr)
NODE(SubobjectExpr)
NODE(EnclosingExpr)
NODE(CastExpr)
NODE(SizeofParamPackExpr)
NODE(CallExpr)
NODE(NewExpr)
NODE(DeleteExpr)
NODE(PrefixExpr)
NODE(FunctionParam)
NODE(ConversionExpr)
NODE(PointerToMemberConversionExpr)
NODE(InitListExpr)
NODE(FoldExpr)
NODE(ThrowExpr)
NODE(BoolExpr)
NODE(StringLiteral)
NODE(LambdaExpr)
NODE(EnumLiteral)
NODE(IntegerLiteral)
NODE(FloatLiteral)
NODE(DoubleLiteral)
NODE(LongDoubleLiteral)
NODE(BracedExpr)
NODE(BracedRangeExpr)
#undef NODE