Documentation ¶
Overview ¶
Package demangle defines functions that demangle GCC/LLVM C++ and Rust symbol names. This package recognizes names that were mangled according to the C++ ABI defined at http://codesourcery.com/cxx-abi/ and the Rust ABI defined at https://rust-lang.github.io/rfcs/2603-rust-symbol-name-mangling-v0.html
Most programs will want to call Filter or ToString.
Index ¶
- Variables
- func ASTToString(a AST, options ...Option) string
- func Filter(name string, options ...Option) string
- func ToString(name string, options ...Option) (string, error)
- type AST
- type ArgumentPack
- type ArrayType
- type Binary
- type BinaryFP
- type BitIntType
- type BuiltinType
- type Cast
- type Clone
- type Closure
- type ComplexType
- type ConstrainedTypeTemplateParam
- type Constraint
- type Constructor
- type Decltype
- type DefaultArg
- type Destructor
- type ElaboratedType
- type EnableIf
- type ExplicitObjectParameter
- type ExprList
- type ExprRequirement
- type FixedType
- type Fold
- type Friend
- type FunctionParam
- type FunctionType
- type GlobalCDtor
- type ImaginaryType
- type InitializerList
- type LambdaAuto
- type LambdaExpr
- type Literal
- type MethodWithQualifiers
- type ModuleEntity
- type ModuleName
- type Name
- type NestedRequirement
- type New
- type NonTypeTemplateParam
- type Nullary
- type Operator
- type Option
- type PackExpansion
- type PointerType
- type PtrMem
- type PtrMemCast
- type Qualified
- type Qualifier
- type Qualifiers
- type ReferenceType
- type RequiresExpr
- type RvalueReferenceType
- type SizeofArgs
- type SizeofPack
- type Special
- type Special2
- type StringLiteral
- type StructuredBindings
- type Subobject
- type SuffixType
- type TaggedName
- type Template
- type TemplateParam
- type TemplateParamName
- type TemplateParamPack
- type TemplateParamQualifiedArg
- type TemplateTemplateParam
- type TransformedType
- type Trinary
- type TypeRequirement
- type TypeTemplateParam
- type TypeWithQualifiers
- type Typed
- type Unary
- type UnnamedType
- type VectorType
- type VendorQualifier
Constants ¶
This section is empty.
Variables ¶
var ErrNotMangledName = errors.New("not a C++ or Rust mangled name")
ErrNotMangledName is returned by CheckedDemangle if the string does not appear to be a C++ symbol name.
Functions ¶
func ASTToString ¶
ASTToString returns the demangled name of the AST.
Types ¶
type AST ¶
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 }
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.
func ToAST ¶
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.
type ArgumentPack ¶
type ArgumentPack struct {
Args []AST
}
ArgumentPack is an argument pack.
func (*ArgumentPack) GoString ¶
func (ap *ArgumentPack) GoString() string
func (*ArgumentPack) Traverse ¶
func (ap *ArgumentPack) Traverse(fn func(AST) bool)
type BitIntType ¶
BitIntType is the C++23 _BitInt(N) type.
func (*BitIntType) GoString ¶
func (bt *BitIntType) GoString() string
func (*BitIntType) Traverse ¶
func (bt *BitIntType) Traverse(fn func(AST) bool)
type BuiltinType ¶
type BuiltinType struct {
Name string
}
BuiltinType is a builtin type, like "int".
func (*BuiltinType) GoString ¶
func (bt *BuiltinType) GoString() string
func (*BuiltinType) Traverse ¶
func (bt *BuiltinType) Traverse(fn func(AST) bool)
type Closure ¶
type Closure struct { TemplateArgs []AST TemplateArgsConstraint AST Types []AST Num int CallConstraint AST }
Closure is a closure, or lambda expression.
type ComplexType ¶
type ComplexType struct {
Base AST
}
ComplexType is a complex type.
func (*ComplexType) GoString ¶
func (ct *ComplexType) GoString() string
func (*ComplexType) Traverse ¶
func (ct *ComplexType) Traverse(fn func(AST) bool)
type ConstrainedTypeTemplateParam ¶
ConstrainedTypeTemplateParam is a constrained template type parameter declaration.
func (*ConstrainedTypeTemplateParam) GoString ¶
func (cttp *ConstrainedTypeTemplateParam) GoString() string
func (*ConstrainedTypeTemplateParam) Traverse ¶
func (cttp *ConstrainedTypeTemplateParam) Traverse(fn func(AST) bool)
type Constraint ¶
Constraint represents an AST with a constraint.
func (*Constraint) GoString ¶
func (c *Constraint) GoString() string
func (*Constraint) Traverse ¶
func (c *Constraint) Traverse(fn func(AST) bool)
type Constructor ¶
Constructor is a constructor.
func (*Constructor) GoString ¶
func (c *Constructor) GoString() string
func (*Constructor) Traverse ¶
func (c *Constructor) Traverse(fn func(AST) bool)
type DefaultArg ¶
DefaultArg holds a default argument for a local name.
func (*DefaultArg) GoString ¶
func (da *DefaultArg) GoString() string
func (*DefaultArg) Traverse ¶
func (da *DefaultArg) Traverse(fn func(AST) bool)
type Destructor ¶
type Destructor struct {
Name AST
}
Destructor is a destructor.
func (*Destructor) GoString ¶
func (d *Destructor) GoString() string
func (*Destructor) Traverse ¶
func (d *Destructor) Traverse(fn func(AST) bool)
type ElaboratedType ¶
ElaboratedType is an elaborated struct/union/enum type.
func (*ElaboratedType) GoString ¶
func (et *ElaboratedType) GoString() string
func (*ElaboratedType) Traverse ¶
func (et *ElaboratedType) Traverse(fn func(AST) bool)
type ExplicitObjectParameter ¶
type ExplicitObjectParameter struct {
Base AST
}
ExplicitObjectParameter represents a C++23 explicit object parameter.
func (*ExplicitObjectParameter) GoString ¶
func (eop *ExplicitObjectParameter) GoString() string
func (*ExplicitObjectParameter) Traverse ¶
func (eop *ExplicitObjectParameter) Traverse(fn func(AST) bool)
type ExprList ¶
type ExprList struct {
Exprs []AST
}
ExprList is a list of expressions, typically arguments to a function call in an expression.
type ExprRequirement ¶
ExprRequirement is a simple requirement in a requires expression. This is an arbitrary expression.
func (*ExprRequirement) GoString ¶
func (er *ExprRequirement) GoString() string
func (*ExprRequirement) Traverse ¶
func (er *ExprRequirement) Traverse(fn func(AST) bool)
type FunctionParam ¶
type FunctionParam struct {
Index int
}
FunctionParam is a parameter of a function, used for last-specified return type in a closure.
func (*FunctionParam) GoString ¶
func (fp *FunctionParam) GoString() string
func (*FunctionParam) Traverse ¶
func (fp *FunctionParam) Traverse(fn func(AST) bool)
type FunctionType ¶
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 }
FunctionType is a function type.
func (*FunctionType) GoString ¶
func (ft *FunctionType) GoString() string
func (*FunctionType) Traverse ¶
func (ft *FunctionType) Traverse(fn func(AST) bool)
type GlobalCDtor ¶
GlobalCDtor is a global constructor or destructor.
func (*GlobalCDtor) GoString ¶
func (gcd *GlobalCDtor) GoString() string
func (*GlobalCDtor) Traverse ¶
func (gcd *GlobalCDtor) Traverse(fn func(AST) bool)
type ImaginaryType ¶
type ImaginaryType struct {
Base AST
}
ImaginaryType is an imaginary type.
func (*ImaginaryType) GoString ¶
func (it *ImaginaryType) GoString() string
func (*ImaginaryType) Traverse ¶
func (it *ImaginaryType) Traverse(fn func(AST) bool)
type InitializerList ¶
InitializerList is an initializer list: an optional type with a list of expressions.
func (*InitializerList) GoString ¶
func (il *InitializerList) GoString() string
func (*InitializerList) Traverse ¶
func (il *InitializerList) Traverse(fn func(AST) bool)
type LambdaAuto ¶
type LambdaAuto struct {
Index int
}
LambdaAuto is a lambda auto parameter.
func (*LambdaAuto) GoString ¶
func (la *LambdaAuto) GoString() string
func (*LambdaAuto) Traverse ¶
func (la *LambdaAuto) Traverse(fn func(AST) bool)
type LambdaExpr ¶
type LambdaExpr struct {
Type AST
}
LambdaExpr is a literal that is a lambda expression.
func (*LambdaExpr) GoString ¶
func (le *LambdaExpr) GoString() string
func (*LambdaExpr) Traverse ¶
func (le *LambdaExpr) Traverse(fn func(AST) bool)
type MethodWithQualifiers ¶
type MethodWithQualifiers struct { Method AST Qualifiers AST RefQualifier string // "" or "&" or "&&" }
MethodWithQualifiers is a method with qualifiers.
func (*MethodWithQualifiers) GoString ¶
func (mwq *MethodWithQualifiers) GoString() string
func (*MethodWithQualifiers) Traverse ¶
func (mwq *MethodWithQualifiers) Traverse(fn func(AST) bool)
type ModuleEntity ¶
ModuleEntity is a name inside a module.
func (*ModuleEntity) GoString ¶
func (me *ModuleEntity) GoString() string
func (*ModuleEntity) Traverse ¶
func (me *ModuleEntity) Traverse(fn func(AST) bool)
type ModuleName ¶
ModuleName is a C++20 module.
func (*ModuleName) GoString ¶
func (mn *ModuleName) GoString() string
func (*ModuleName) Traverse ¶
func (mn *ModuleName) Traverse(fn func(AST) bool)
type NestedRequirement ¶
type NestedRequirement struct {
Constraint AST
}
NestedRequirement is a nested requirement in a requires expression.
func (*NestedRequirement) GoString ¶
func (nr *NestedRequirement) GoString() string
func (*NestedRequirement) Traverse ¶
func (nr *NestedRequirement) Traverse(fn func(AST) bool)
type NonTypeTemplateParam ¶
NonTypeTemplateParam is a non-type template parameter that appears in a lambda with explicit template parameters.
func (*NonTypeTemplateParam) GoString ¶
func (nttp *NonTypeTemplateParam) GoString() string
func (*NonTypeTemplateParam) Traverse ¶
func (nttp *NonTypeTemplateParam) Traverse(fn func(AST) bool)
type Nullary ¶
type Nullary struct {
Op AST
}
Nullary is an operator in an expression with no arguments, such as throw.
type Operator ¶
type Operator struct { Name string // contains filtered or unexported fields }
Operator is an operator.
type Option ¶
type Option int
Option is the type of demangler options.
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 ¶
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.
type PackExpansion ¶
type PackExpansion struct { Base AST Pack *ArgumentPack }
PackExpansion is a pack expansion. The Pack field may be nil.
func (*PackExpansion) GoString ¶
func (pe *PackExpansion) GoString() string
func (*PackExpansion) Traverse ¶
func (pe *PackExpansion) Traverse(fn func(AST) bool)
type PointerType ¶
type PointerType struct {
Base AST
}
PointerType is a pointer type.
func (*PointerType) GoString ¶
func (pt *PointerType) GoString() string
func (*PointerType) Traverse ¶
func (pt *PointerType) Traverse(fn func(AST) bool)
type PtrMemCast ¶
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.
func (*PtrMemCast) GoString ¶
func (pmc *PtrMemCast) GoString() string
func (*PtrMemCast) Traverse ¶
func (pmc *PtrMemCast) Traverse(fn func(AST) bool)
type Qualified ¶
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 }
Qualified is a name in a scope.
type Qualifier ¶
type Qualifier struct { Name string // qualifier name: const, volatile, etc. Exprs []AST // can be non-nil for noexcept and throw }
Qualifier is a single type qualifier.
type Qualifiers ¶
type Qualifiers struct {
Qualifiers []AST
}
Qualifiers is an ordered list of type qualifiers.
func (*Qualifiers) GoString ¶
func (qs *Qualifiers) GoString() string
func (*Qualifiers) Traverse ¶
func (qs *Qualifiers) Traverse(fn func(AST) bool)
type ReferenceType ¶
type ReferenceType struct {
Base AST
}
ReferenceType is a reference type.
func (*ReferenceType) GoString ¶
func (rt *ReferenceType) GoString() string
func (*ReferenceType) Traverse ¶
func (rt *ReferenceType) Traverse(fn func(AST) bool)
type RequiresExpr ¶
RequiresExpr is a C++20 requires expression.
func (*RequiresExpr) GoString ¶
func (re *RequiresExpr) GoString() string
func (*RequiresExpr) Traverse ¶
func (re *RequiresExpr) Traverse(fn func(AST) bool)
type RvalueReferenceType ¶
type RvalueReferenceType struct {
Base AST
}
RvalueReferenceType is an rvalue reference type.
func (*RvalueReferenceType) GoString ¶
func (rt *RvalueReferenceType) GoString() string
func (*RvalueReferenceType) Traverse ¶
func (rt *RvalueReferenceType) Traverse(fn func(AST) bool)
type SizeofArgs ¶
type SizeofArgs struct {
Args []AST
}
SizeofArgs is the size of a captured template parameter pack from an alias template.
func (*SizeofArgs) GoString ¶
func (sa *SizeofArgs) GoString() string
func (*SizeofArgs) Traverse ¶
func (sa *SizeofArgs) Traverse(fn func(AST) bool)
type SizeofPack ¶
type SizeofPack struct {
Pack *ArgumentPack
}
SizeofPack is the sizeof operator applied to an argument pack.
func (*SizeofPack) GoString ¶
func (sp *SizeofPack) GoString() string
func (*SizeofPack) Traverse ¶
func (sp *SizeofPack) Traverse(fn func(AST) bool)
type StringLiteral ¶
type StringLiteral struct {
Type AST
}
StringLiteral is a string literal.
func (*StringLiteral) GoString ¶
func (sl *StringLiteral) GoString() string
func (*StringLiteral) Traverse ¶
func (sl *StringLiteral) Traverse(fn func(AST) bool)
type StructuredBindings ¶
type StructuredBindings struct {
Bindings []AST
}
StructuredBindings is a structured binding declaration.
func (*StructuredBindings) GoString ¶
func (sb *StructuredBindings) GoString() string
func (*StructuredBindings) Traverse ¶
func (sb *StructuredBindings) Traverse(fn func(AST) bool)
type Subobject ¶
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.
type SuffixType ¶
SuffixType is an type with an arbitrary suffix.
func (*SuffixType) GoString ¶
func (st *SuffixType) GoString() string
func (*SuffixType) Traverse ¶
func (st *SuffixType) Traverse(fn func(AST) bool)
type TaggedName ¶
TaggedName is a name with an ABI tag.
func (*TaggedName) GoString ¶
func (t *TaggedName) GoString() string
func (*TaggedName) Traverse ¶
func (t *TaggedName) Traverse(fn func(AST) bool)
type TemplateParam ¶
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.
func (*TemplateParam) GoString ¶
func (tp *TemplateParam) GoString() string
func (*TemplateParam) Traverse ¶
func (tp *TemplateParam) Traverse(fn func(AST) bool)
type TemplateParamName ¶
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.
func (*TemplateParamName) GoString ¶
func (tpn *TemplateParamName) GoString() string
func (*TemplateParamName) Traverse ¶
func (tpn *TemplateParamName) Traverse(fn func(AST) bool)
type TemplateParamPack ¶
type TemplateParamPack struct {
Param AST
}
TemplateParamPack is a template parameter pack that appears in a lambda with explicit template parameters.
func (*TemplateParamPack) GoString ¶
func (tpp *TemplateParamPack) GoString() string
func (*TemplateParamPack) Traverse ¶
func (tpp *TemplateParamPack) Traverse(fn func(AST) bool)
type TemplateParamQualifiedArg ¶
TemplateParamQualifiedArg is used when the mangled name includes both the template parameter declaration and the template argument. See https://github.com/itanium-cxx-abi/cxx-abi/issues/47.
func (*TemplateParamQualifiedArg) GoString ¶
func (tpqa *TemplateParamQualifiedArg) GoString() string
func (*TemplateParamQualifiedArg) Traverse ¶
func (tpqa *TemplateParamQualifiedArg) Traverse(fn func(AST) bool)
type TemplateTemplateParam ¶
TemplateTemplateParam is a template template parameter that appears in a lambda with explicit template parameters.
func (*TemplateTemplateParam) GoString ¶
func (ttp *TemplateTemplateParam) GoString() string
func (*TemplateTemplateParam) Traverse ¶
func (ttp *TemplateTemplateParam) Traverse(fn func(AST) bool)
type TransformedType ¶
TransformedType is a builtin type with a template argument.
func (*TransformedType) GoString ¶
func (tt *TransformedType) GoString() string
func (*TransformedType) Traverse ¶
func (tt *TransformedType) Traverse(fn func(AST) bool)
type TypeRequirement ¶
type TypeRequirement struct {
Type AST
}
TypeRequirement is a type requirement in a requires expression.
func (*TypeRequirement) GoString ¶
func (tr *TypeRequirement) GoString() string
func (*TypeRequirement) Traverse ¶
func (tr *TypeRequirement) Traverse(fn func(AST) bool)
type TypeTemplateParam ¶
type TypeTemplateParam struct {
Name AST
}
TypeTemplateParam is a type template parameter that appears in a lambda with explicit template parameters.
func (*TypeTemplateParam) GoString ¶
func (ttp *TypeTemplateParam) GoString() string
func (*TypeTemplateParam) Traverse ¶
func (ttp *TypeTemplateParam) Traverse(fn func(AST) bool)
type TypeWithQualifiers ¶
TypeWithQualifiers is a type with standard qualifiers.
func (*TypeWithQualifiers) GoString ¶
func (twq *TypeWithQualifiers) GoString() string
func (*TypeWithQualifiers) Traverse ¶
func (twq *TypeWithQualifiers) Traverse(fn func(AST) bool)
type Unary ¶
type Unary struct { Op AST Expr AST Suffix bool // true for ++ -- when used as postfix SizeofType bool // true for sizeof (type) }
Unary is a unary operation in an expression.
type UnnamedType ¶
type UnnamedType struct {
Num int
}
UnnamedType is an unnamed type, that just has an index.
func (*UnnamedType) GoString ¶
func (ut *UnnamedType) GoString() string
func (*UnnamedType) Traverse ¶
func (ut *UnnamedType) Traverse(fn func(AST) bool)
type VectorType ¶
VectorType is a vector type.
func (*VectorType) GoString ¶
func (vt *VectorType) GoString() string
func (*VectorType) Traverse ¶
func (vt *VectorType) Traverse(fn func(AST) bool)
type VendorQualifier ¶
VendorQualifier is a type qualified by a vendor-specific qualifier.
func (*VendorQualifier) GoString ¶
func (vq *VendorQualifier) GoString() string
func (*VendorQualifier) Traverse ¶
func (vq *VendorQualifier) Traverse(fn func(AST) bool)