ErrNotMangledName is returned by CheckedDemangle if the string does not appear to be a C++ symbol name.
var ErrNotMangledName = errors.New("not a C++ or Rust mangled name")
func ASTToString(a AST, options ...Option) string
ASTToString returns the demangled name of the AST.
func Filter(name string, options ...Option) string
Filter demangles a C++ or Rust symbol name, returning the human-readable C++ or Rust name. If any error occurs during demangling, the input string is returned.
func ToString(name string, options ...Option) (string, error)
ToString demangles a C++ or Rust symbol name, returning a human-readable C++ or Rust name or an error. If the name does not appear to be a C++ or Rust symbol name at all, the error will be ErrNotMangledName.
AST is an abstract syntax tree representing a C++ declaration. This is sufficient for the demangler but is by no means a general C++ AST. This abstract syntax tree is only used for C++ symbols, not Rust symbols.
type AST interface {
// Traverse each element of an AST. If the function returns
// false, traversal of children of that element is skipped.
Traverse(func(AST) bool)
// Copy an AST with possible transformations.
// If the skip function returns true, no copy is required.
// If the copy function returns nil, no copy is required.
// The Copy method will do the right thing if copy returns nil
// for some components of an AST but not others, so a good
// copy function will only return non-nil for AST values that
// need to change.
// Copy itself returns either a copy or nil.
Copy(copy func(AST) AST, skip func(AST) bool) AST
// Implement the fmt.GoStringer interface.
GoString() string
// contains filtered or unexported methods
}
func ToAST(name string, options ...Option) (AST, error)
ToAST demangles a C++ symbol name into an abstract syntax tree representing the symbol. If the NoParams option is passed, and the name has a function type, the parameter types are not demangled. If the name does not appear to be a C++ symbol name at all, the error will be ErrNotMangledName. This function does not currently support Rust symbol names.
ArgumentPack is an argument pack.
type ArgumentPack struct {
Args []AST
}
func (ap *ArgumentPack) Copy(fn func(AST) AST, skip func(AST) bool) AST
func (ap *ArgumentPack) GoString() string
func (ap *ArgumentPack) Traverse(fn func(AST) bool)
ArrayType is an array type.
type ArrayType struct {
Dimension AST
Element AST
}
func (at *ArrayType) Copy(fn func(AST) AST, skip func(AST) bool) AST
func (at *ArrayType) GoString() string
func (at *ArrayType) Traverse(fn func(AST) bool)
Binary is a binary operation in an expression.
type Binary struct {
Op AST
Left AST
Right AST
}
func (b *Binary) Copy(fn func(AST) AST, skip func(AST) bool) AST
func (b *Binary) GoString() string
func (b *Binary) Traverse(fn func(AST) bool)
BinaryFP is a binary floating-point type.
type BinaryFP struct {
Bits int
}
func (bfp *BinaryFP) Copy(fn func(AST) AST, skip func(AST) bool) AST
func (bfp *BinaryFP) GoString() string
func (bfp *BinaryFP) Traverse(fn func(AST) bool)
BuiltinType is a builtin type, like "int".
type BuiltinType struct {
Name string
}
func (bt *BuiltinType) Copy(fn func(AST) AST, skip func(AST) bool) AST
func (bt *BuiltinType) GoString() string
func (bt *BuiltinType) Traverse(fn func(AST) bool)
Cast is a type cast.
type Cast struct {
To AST
}
func (c *Cast) Copy(fn func(AST) AST, skip func(AST) bool) AST
func (c *Cast) GoString() string
func (c *Cast) Traverse(fn func(AST) bool)
Clone is a clone of a function, with a distinguishing suffix.
type Clone struct {
Base AST
Suffix string
}
func (c *Clone) Copy(fn func(AST) AST, skip func(AST) bool) AST
func (c *Clone) GoString() string
func (c *Clone) Traverse(fn func(AST) bool)
Closure is a closure, or lambda expression.
type Closure struct {
TemplateArgs []AST
Types []AST
Num int
}
func (cl *Closure) Copy(fn func(AST) AST, skip func(AST) bool) AST
func (cl *Closure) GoString() string
func (cl *Closure) Traverse(fn func(AST) bool)
ComplexType is a complex type.
type ComplexType struct {
Base AST
}
func (ct *ComplexType) Copy(fn func(AST) AST, skip func(AST) bool) AST
func (ct *ComplexType) GoString() string
func (ct *ComplexType) Traverse(fn func(AST) bool)
Constructor is a constructor.
type Constructor struct {
Name AST
Base AST // base class of inheriting constructor
}
func (c *Constructor) Copy(fn func(AST) AST, skip func(AST) bool) AST
func (c *Constructor) GoString() string
func (c *Constructor) Traverse(fn func(AST) bool)
Decltype is the decltype operator.
type Decltype struct {
Expr AST
}
func (dt *Decltype) Copy(fn func(AST) AST, skip func(AST) bool) AST
func (dt *Decltype) GoString() string
func (dt *Decltype) Traverse(fn func(AST) bool)
DefaultArg holds a default argument for a local name.
type DefaultArg struct {
Num int
Arg AST
}
func (da *DefaultArg) Copy(fn func(AST) AST, skip func(AST) bool) AST
func (da *DefaultArg) GoString() string
func (da *DefaultArg) Traverse(fn func(AST) bool)
Destructor is a destructor.
type Destructor struct {
Name AST
}
func (d *Destructor) Copy(fn func(AST) AST, skip func(AST) bool) AST
func (d *Destructor) GoString() string
func (d *Destructor) Traverse(fn func(AST) bool)
ElaboratedType is an elaborated struct/union/enum type.
type ElaboratedType struct {
Kind string
Type AST
}
func (et *ElaboratedType) Copy(fn func(AST) AST, skip func(AST) bool) AST
func (et *ElaboratedType) GoString() string
func (et *ElaboratedType) Traverse(fn func(AST) bool)
EnableIf is used by clang for an enable_if attribute.
type EnableIf struct {
Type AST
Args []AST
}
func (ei *EnableIf) Copy(fn func(AST) AST, skip func(AST) bool) AST
func (ei *EnableIf) GoString() string
func (ei *EnableIf) Traverse(fn func(AST) bool)
ExprList is a list of expressions, typically arguments to a function call in an expression.
type ExprList struct {
Exprs []AST
}
func (el *ExprList) Copy(fn func(AST) AST, skip func(AST) bool) AST
func (el *ExprList) GoString() string
func (el *ExprList) Traverse(fn func(AST) bool)
FixedType is a fixed numeric type of unknown size.
type FixedType struct {
Base AST
Accum bool
Sat bool
}
func (ft *FixedType) Copy(fn func(AST) AST, skip func(AST) bool) AST
func (ft *FixedType) GoString() string
func (ft *FixedType) Traverse(fn func(AST) bool)
Fold is a C++17 fold-expression. Arg2 is nil for a unary operator.
type Fold struct {
Left bool
Op AST
Arg1 AST
Arg2 AST
}
func (f *Fold) Copy(fn func(AST) AST, skip func(AST) bool) AST
func (f *Fold) GoString() string
func (f *Fold) Traverse(fn func(AST) bool)
FunctionParam is a parameter of a function, used for last-specified return type in a closure.
type FunctionParam struct {
Index int
}
func (fp *FunctionParam) Copy(fn func(AST) AST, skip func(AST) bool) AST
func (fp *FunctionParam) GoString() string
func (fp *FunctionParam) Traverse(fn func(AST) bool)
FunctionType is a function type.
type FunctionType struct {
Return AST
Args []AST
// The forLocalName field reports whether this FunctionType
// was created for a local name. With the default GNU demangling
// output we don't print the return type in that case.
ForLocalName bool
}
func (ft *FunctionType) Copy(fn func(AST) AST, skip func(AST) bool) AST
func (ft *FunctionType) GoString() string
func (ft *FunctionType) Traverse(fn func(AST) bool)
GlobalCDtor is a global constructor or destructor.
type GlobalCDtor struct {
Ctor bool
Key AST
}
func (gcd *GlobalCDtor) Copy(fn func(AST) AST, skip func(AST) bool) AST
func (gcd *GlobalCDtor) GoString() string
func (gcd *GlobalCDtor) Traverse(fn func(AST) bool)
ImaginaryType is an imaginary type.
type ImaginaryType struct {
Base AST
}
func (it *ImaginaryType) Copy(fn func(AST) AST, skip func(AST) bool) AST
func (it *ImaginaryType) GoString() string
func (it *ImaginaryType) Traverse(fn func(AST) bool)
InitializerList is an initializer list: an optional type with a list of expressions.
type InitializerList struct {
Type AST
Exprs AST
}
func (il *InitializerList) Copy(fn func(AST) AST, skip func(AST) bool) AST
func (il *InitializerList) GoString() string
func (il *InitializerList) Traverse(fn func(AST) bool)
LambdaAuto is a lambda auto parameter.
type LambdaAuto struct {
Index int
}
func (la *LambdaAuto) Copy(fn func(AST) AST, skip func(AST) bool) AST
func (la *LambdaAuto) GoString() string
func (la *LambdaAuto) Traverse(fn func(AST) bool)
LambdaExpr is a literal that is a lambda expression.
type LambdaExpr struct {
Type AST
}
func (le *LambdaExpr) Copy(fn func(AST) AST, skip func(AST) bool) AST
func (le *LambdaExpr) GoString() string
func (le *LambdaExpr) Traverse(fn func(AST) bool)
Literal is a literal in an expression.
type Literal struct {
Type AST
Val string
Neg bool
}
func (l *Literal) Copy(fn func(AST) AST, skip func(AST) bool) AST
func (l *Literal) GoString() string
func (l *Literal) Traverse(fn func(AST) bool)
MethodWithQualifiers is a method with qualifiers.
type MethodWithQualifiers struct {
Method AST
Qualifiers AST
RefQualifier string // "" or "&" or "&&"
}
func (mwq *MethodWithQualifiers) Copy(fn func(AST) AST, skip func(AST) bool) AST
func (mwq *MethodWithQualifiers) GoString() string
func (mwq *MethodWithQualifiers) Traverse(fn func(AST) bool)
Name is an unqualified name.
type Name struct {
Name string
}
func (n *Name) Copy(fn func(AST) AST, skip func(AST) bool) AST
func (n *Name) GoString() string
func (n *Name) Traverse(fn func(AST) bool)
New is a use of operator new in an expression.
type New struct {
Op AST
Place AST
Type AST
Init AST
}
func (n *New) Copy(fn func(AST) AST, skip func(AST) bool) AST
func (n *New) GoString() string
func (n *New) Traverse(fn func(AST) bool)
NonTypeTemplateParam is a non-type template parameter that appears in a lambda with explicit template parameters.
type NonTypeTemplateParam struct {
Name AST
Type AST
}
func (nttp *NonTypeTemplateParam) Copy(fn func(AST) AST, skip func(AST) bool) AST
func (nttp *NonTypeTemplateParam) GoString() string
func (nttp *NonTypeTemplateParam) Traverse(fn func(AST) bool)
Nullary is an operator in an expression with no arguments, such as throw.
type Nullary struct {
Op AST
}
func (n *Nullary) Copy(fn func(AST) AST, skip func(AST) bool) AST
func (n *Nullary) GoString() string
func (n *Nullary) Traverse(fn func(AST) bool)
Operator is an operator.
type Operator struct {
Name string
}
func (op *Operator) Copy(fn func(AST) AST, skip func(AST) bool) AST
func (op *Operator) GoString() string
func (op *Operator) Traverse(fn func(AST) bool)
Option is the type of demangler options.
type Option int
const (
// The NoParams option disables demangling of function parameters.
// It only omits the parameters of the function name being demangled,
// not the parameter types of other functions that may be mentioned.
// Using the option will speed up the demangler and cause it to
// use less memory.
NoParams Option = iota
// The NoTemplateParams option disables demangling of template parameters.
// This applies to both C++ and Rust.
NoTemplateParams
// The NoEnclosingParams option disables demangling of the function
// parameter types of the enclosing function when demangling a
// local name defined within a function.
NoEnclosingParams
// The NoClones option disables inclusion of clone suffixes.
// NoParams implies NoClones.
NoClones
// The NoRust option disables demangling of old-style Rust
// mangled names, which can be confused with C++ style mangled
// names. New style Rust mangled names are still recognized.
NoRust
// The Verbose option turns on more verbose demangling.
Verbose
// LLVMStyle tries to translate an AST to a string in the
// style of the LLVM demangler. This does not affect
// the parsing of the AST, only the conversion of the AST
// to a string.
LLVMStyle
)
func MaxLength(pow int) Option
MaxLength returns an Option that limits the maximum length of a demangled string. The maximum length is expressed as a power of 2, so a value of 1 limits the returned string to 2 characters, and a value of 16 limits the returned string to 65,536 characters. The value must be between 1 and 30.
PackExpansion is a pack expansion. The Pack field may be nil.
type PackExpansion struct {
Base AST
Pack *ArgumentPack
}
func (pe *PackExpansion) Copy(fn func(AST) AST, skip func(AST) bool) AST
func (pe *PackExpansion) GoString() string
func (pe *PackExpansion) Traverse(fn func(AST) bool)
PointerType is a pointer type.
type PointerType struct {
Base AST
}
func (pt *PointerType) Copy(fn func(AST) AST, skip func(AST) bool) AST
func (pt *PointerType) GoString() string
func (pt *PointerType) Traverse(fn func(AST) bool)
PtrMem is a pointer-to-member expression.
type PtrMem struct {
Class AST
Member AST
}
func (pm *PtrMem) Copy(fn func(AST) AST, skip func(AST) bool) AST
func (pm *PtrMem) GoString() string
func (pm *PtrMem) Traverse(fn func(AST) bool)
PtrMemCast is a conversion of an expression to a pointer-to-member type. This is used for C++20 manglings of class types used as the type of non-type template arguments.
See https://github.com/itanium-cxx-abi/cxx-abi/issues/47.
type PtrMemCast struct {
Type AST
Expr AST
Offset int
}
func (pmc *PtrMemCast) Copy(fn func(AST) AST, skip func(AST) bool) AST
func (pmc *PtrMemCast) GoString() string
func (pmc *PtrMemCast) Traverse(fn func(AST) bool)
Qualified is a name in a scope.
type Qualified struct {
Scope AST
Name AST
// The LocalName field is true if this is parsed as a
// <local-name>. We shouldn't really need this, but in some
// cases (for the unary sizeof operator) the standard
// demangler prints a local name slightly differently. We
// keep track of this for compatibility.
LocalName bool // A full local name encoding
}
func (q *Qualified) Copy(fn func(AST) AST, skip func(AST) bool) AST
func (q *Qualified) GoString() string
func (q *Qualified) Traverse(fn func(AST) bool)
Qualifier is a single type qualifier.
type Qualifier struct {
Name string // qualifier name: const, volatile, etc.
Exprs []AST // can be non-nil for noexcept and throw
}
func (q *Qualifier) Copy(fn func(AST) AST, skip func(AST) bool) AST
func (q *Qualifier) GoString() string
func (q *Qualifier) Traverse(fn func(AST) bool)
Qualifiers is an ordered list of type qualifiers.
type Qualifiers struct {
Qualifiers []AST
}
func (qs *Qualifiers) Copy(fn func(AST) AST, skip func(AST) bool) AST
func (qs *Qualifiers) GoString() string
func (qs *Qualifiers) Traverse(fn func(AST) bool)
ReferenceType is a reference type.
type ReferenceType struct {
Base AST
}
func (rt *ReferenceType) Copy(fn func(AST) AST, skip func(AST) bool) AST
func (rt *ReferenceType) GoString() string
func (rt *ReferenceType) Traverse(fn func(AST) bool)
RvalueReferenceType is an rvalue reference type.
type RvalueReferenceType struct {
Base AST
}
func (rt *RvalueReferenceType) Copy(fn func(AST) AST, skip func(AST) bool) AST
func (rt *RvalueReferenceType) GoString() string
func (rt *RvalueReferenceType) Traverse(fn func(AST) bool)
SizeofArgs is the size of a captured template parameter pack from an alias template.
type SizeofArgs struct {
Args []AST
}
func (sa *SizeofArgs) Copy(fn func(AST) AST, skip func(AST) bool) AST
func (sa *SizeofArgs) GoString() string
func (sa *SizeofArgs) Traverse(fn func(AST) bool)
SizeofPack is the sizeof operator applied to an argument pack.
type SizeofPack struct {
Pack *ArgumentPack
}
func (sp *SizeofPack) Copy(fn func(AST) AST, skip func(AST) bool) AST
func (sp *SizeofPack) GoString() string
func (sp *SizeofPack) Traverse(fn func(AST) bool)
Special is a special symbol, printed as a prefix plus another value.
type Special struct {
Prefix string
Val AST
}
func (s *Special) Copy(fn func(AST) AST, skip func(AST) bool) AST
func (s *Special) GoString() string
func (s *Special) Traverse(fn func(AST) bool)
Special2 is like special, but uses two values.
type Special2 struct {
Prefix string
Val1 AST
Middle string
Val2 AST
}
func (s *Special2) Copy(fn func(AST) AST, skip func(AST) bool) AST
func (s *Special2) GoString() string
func (s *Special2) Traverse(fn func(AST) bool)
StringLiteral is a string literal.
type StringLiteral struct {
Type AST
}
func (sl *StringLiteral) Copy(fn func(AST) AST, skip func(AST) bool) AST
func (sl *StringLiteral) GoString() string
func (sl *StringLiteral) Traverse(fn func(AST) bool)
StructuredBindings is a structured binding declaration.
type StructuredBindings struct {
Bindings []AST
}
func (sb *StructuredBindings) Copy(fn func(AST) AST, skip func(AST) bool) AST
func (sb *StructuredBindings) GoString() string
func (sb *StructuredBindings) Traverse(fn func(AST) bool)
Subobject is a a reference to an offset in an expression. This is used for C++20 manglings of class types used as the type of non-type template arguments.
See https://github.com/itanium-cxx-abi/cxx-abi/issues/47.
type Subobject struct {
Type AST
SubExpr AST
Offset int
Selectors []int
PastEnd bool
}
func (so *Subobject) Copy(fn func(AST) AST, skip func(AST) bool) AST
func (so *Subobject) GoString() string
func (so *Subobject) Traverse(fn func(AST) bool)
TaggedName is a name with an ABI tag.
type TaggedName struct {
Name AST
Tag AST
}
func (t *TaggedName) Copy(fn func(AST) AST, skip func(AST) bool) AST
func (t *TaggedName) GoString() string
func (t *TaggedName) Traverse(fn func(AST) bool)
Template is a template with arguments.
type Template struct {
Name AST
Args []AST
}
func (t *Template) Copy(fn func(AST) AST, skip func(AST) bool) AST
func (t *Template) GoString() string
func (t *Template) Traverse(fn func(AST) bool)
TemplateParam is a template parameter. The Template field is filled in while parsing the demangled string. We don't normally see these while printing--they are replaced by the simplify function.
type TemplateParam struct {
Index int
Template *Template
}
func (tp *TemplateParam) Copy(fn func(AST) AST, skip func(AST) bool) AST
func (tp *TemplateParam) GoString() string
func (tp *TemplateParam) Traverse(fn func(AST) bool)
TemplateParamName is the name of a template parameter that the demangler introduced for a lambda that has explicit template parameters. This is a prefix with an index.
type TemplateParamName struct {
Prefix string
Index int
}
func (tpn *TemplateParamName) Copy(fn func(AST) AST, skip func(AST) bool) AST
func (tpn *TemplateParamName) GoString() string
func (tpn *TemplateParamName) Traverse(fn func(AST) bool)
TemplateParamPack is a template parameter pack that appears in a lambda with explicit template parameters.
type TemplateParamPack struct {
Param AST
}
func (tpp *TemplateParamPack) Copy(fn func(AST) AST, skip func(AST) bool) AST
func (tpp *TemplateParamPack) GoString() string
func (tpp *TemplateParamPack) Traverse(fn func(AST) bool)
TemplateTemplateParam is a template template parameter that appears in a lambda with explicit template parameters.
type TemplateTemplateParam struct {
Name AST
Params []AST
}
func (ttp *TemplateTemplateParam) Copy(fn func(AST) AST, skip func(AST) bool) AST
func (ttp *TemplateTemplateParam) GoString() string
func (ttp *TemplateTemplateParam) Traverse(fn func(AST) bool)
Trinary is the ?: trinary operation in an expression.
type Trinary struct {
Op AST
First AST
Second AST
Third AST
}
func (t *Trinary) Copy(fn func(AST) AST, skip func(AST) bool) AST
func (t *Trinary) GoString() string
func (t *Trinary) Traverse(fn func(AST) bool)
TypeTemplateParam is a type template parameter that appears in a lambda with explicit template parameters.
type TypeTemplateParam struct {
Name AST
}
func (ttp *TypeTemplateParam) Copy(fn func(AST) AST, skip func(AST) bool) AST
func (ttp *TypeTemplateParam) GoString() string
func (ttp *TypeTemplateParam) Traverse(fn func(AST) bool)
TypeWithQualifiers is a type with standard qualifiers.
type TypeWithQualifiers struct {
Base AST
Qualifiers AST
}
func (twq *TypeWithQualifiers) Copy(fn func(AST) AST, skip func(AST) bool) AST
func (twq *TypeWithQualifiers) GoString() string
func (twq *TypeWithQualifiers) Traverse(fn func(AST) bool)
Typed is a typed name.
type Typed struct {
Name AST
Type AST
}
func (t *Typed) Copy(fn func(AST) AST, skip func(AST) bool) AST
func (t *Typed) GoString() string
func (t *Typed) Traverse(fn func(AST) bool)
Unary is a unary operation in an expression.
type Unary struct {
Op AST
Expr AST
Suffix bool // true for ++ -- when used as postfix
SizeofType bool // true for sizeof (type)
}
func (u *Unary) Copy(fn func(AST) AST, skip func(AST) bool) AST
func (u *Unary) GoString() string
func (u *Unary) Traverse(fn func(AST) bool)
UnnamedType is an unnamed type, that just has an index.
type UnnamedType struct {
Num int
}
func (ut *UnnamedType) Copy(fn func(AST) AST, skip func(AST) bool) AST
func (ut *UnnamedType) GoString() string
func (ut *UnnamedType) Traverse(fn func(AST) bool)
VectorType is a vector type.
type VectorType struct {
Dimension AST
Base AST
}
func (vt *VectorType) Copy(fn func(AST) AST, skip func(AST) bool) AST
func (vt *VectorType) GoString() string
func (vt *VectorType) Traverse(fn func(AST) bool)
VendorQualifier is a type qualified by a vendor-specific qualifier.
type VendorQualifier struct {
Qualifier AST
Type AST
}
func (vq *VendorQualifier) Copy(fn func(AST) AST, skip func(AST) bool) AST
func (vq *VendorQualifier) GoString() string
func (vq *VendorQualifier) Traverse(fn func(AST) bool)