demangle

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 19, 2021 License: Apache-2.0, BSD-3-Clause Imports: 4 Imported by: 0

Documentation

Overview

Package demangle defines functions that demangle GCC/LLVM C++ symbol names. This package recognizes names that were mangled according to the C++ ABI defined at http://codesourcery.com/cxx-abi/.

Most programs will want to call Filter or ToString.

Index

Constants

This section is empty.

Variables

View Source
var ErrNotMangledName = errors.New("not a C++ mangled name")

ErrNotMangledName is returned by CheckedDemangle if the string does not appear to be a C++ symbol name.

Functions

func ASTToString

func ASTToString(a AST, options ...Option) string

ASTToString returns the demangled name of the AST.

func Demangle

func Demangle(name string) string

Demangle demangle todo

func Filter

func Filter(name string, options ...Option) string

Filter demangles a C++ symbol name, returning the human-readable C++ name. If any error occurs during demangling, the input string is returned.

func MsvcFilter

func MsvcFilter(name string) string

func ToString

func ToString(name string, options ...Option) (string, error)

ToString demangles a C++ symbol name, returning a human-readable C++ name or an error. If the name does not appear to be a C++ symbol name at all, the error will be ErrNotMangledName.

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.

func ToAST

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.

type ArgumentPack

type ArgumentPack struct {
	Args []AST
}

ArgumentPack is an argument pack.

func (*ArgumentPack) Copy

func (ap *ArgumentPack) Copy(fn func(AST) AST, skip func(AST) bool) AST

func (*ArgumentPack) GoString

func (ap *ArgumentPack) GoString() string

func (*ArgumentPack) Traverse

func (ap *ArgumentPack) Traverse(fn func(AST) bool)

type ArrayType

type ArrayType struct {
	Dimension AST
	Element   AST
}

ArrayType is an array type.

func (*ArrayType) Copy

func (at *ArrayType) Copy(fn func(AST) AST, skip func(AST) bool) AST

func (*ArrayType) GoString

func (at *ArrayType) GoString() string

func (*ArrayType) Traverse

func (at *ArrayType) Traverse(fn func(AST) bool)

type Binary

type Binary struct {
	Op    AST
	Left  AST
	Right AST
}

Binary is a binary operation in an expression.

func (*Binary) Copy

func (b *Binary) Copy(fn func(AST) AST, skip func(AST) bool) AST

func (*Binary) GoString

func (b *Binary) GoString() string

func (*Binary) Traverse

func (b *Binary) Traverse(fn func(AST) bool)

type BuiltinType

type BuiltinType struct {
	Name string
}

BuiltinType is a builtin type, like "int".

func (*BuiltinType) Copy

func (bt *BuiltinType) Copy(fn func(AST) AST, skip func(AST) bool) AST

func (*BuiltinType) GoString

func (bt *BuiltinType) GoString() string

func (*BuiltinType) Traverse

func (bt *BuiltinType) Traverse(fn func(AST) bool)

type Cast

type Cast struct {
	To AST
}

Cast is a type cast.

func (*Cast) Copy

func (c *Cast) Copy(fn func(AST) AST, skip func(AST) bool) AST

func (*Cast) GoString

func (c *Cast) GoString() string

func (*Cast) Traverse

func (c *Cast) Traverse(fn func(AST) bool)

type Clone

type Clone struct {
	Base   AST
	Suffix string
}

Clone is a clone of a function, with a distinguishing suffix.

func (*Clone) Copy

func (c *Clone) Copy(fn func(AST) AST, skip func(AST) bool) AST

func (*Clone) GoString

func (c *Clone) GoString() string

func (*Clone) Traverse

func (c *Clone) Traverse(fn func(AST) bool)

type Closure

type Closure struct {
	Types []AST
	Num   int
}

Closure is a closure, or lambda expression.

func (*Closure) Copy

func (cl *Closure) Copy(fn func(AST) AST, skip func(AST) bool) AST

func (*Closure) GoString

func (cl *Closure) GoString() string

func (*Closure) Traverse

func (cl *Closure) Traverse(fn func(AST) bool)

type ComplexType

type ComplexType struct {
	Base AST
}

ComplexType is a complex type.

func (*ComplexType) Copy

func (ct *ComplexType) Copy(fn func(AST) AST, skip func(AST) bool) AST

func (*ComplexType) GoString

func (ct *ComplexType) GoString() string

func (*ComplexType) Traverse

func (ct *ComplexType) Traverse(fn func(AST) bool)

type Constructor

type Constructor struct {
	Name AST
}

Constructor is a constructor.

func (*Constructor) Copy

func (c *Constructor) Copy(fn func(AST) AST, skip func(AST) bool) AST

func (*Constructor) GoString

func (c *Constructor) GoString() string

func (*Constructor) Traverse

func (c *Constructor) Traverse(fn func(AST) bool)

type Decltype

type Decltype struct {
	Expr AST
}

Decltype is the decltype operator.

func (*Decltype) Copy

func (dt *Decltype) Copy(fn func(AST) AST, skip func(AST) bool) AST

func (*Decltype) GoString

func (dt *Decltype) GoString() string

func (*Decltype) Traverse

func (dt *Decltype) Traverse(fn func(AST) bool)

type DefaultArg

type DefaultArg struct {
	Num int
	Arg AST
}

DefaultArg holds a default argument for a local name.

func (*DefaultArg) Copy

func (da *DefaultArg) Copy(fn func(AST) AST, skip func(AST) bool) AST

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) Copy

func (d *Destructor) Copy(fn func(AST) AST, skip func(AST) bool) AST

func (*Destructor) GoString

func (d *Destructor) GoString() string

func (*Destructor) Traverse

func (d *Destructor) Traverse(fn func(AST) bool)

type EnableIf

type EnableIf struct {
	Type AST
	Args []AST
}

EnableIf is used by clang for an enable_if attribute.

func (*EnableIf) Copy

func (ei *EnableIf) Copy(fn func(AST) AST, skip func(AST) bool) AST

func (*EnableIf) GoString

func (ei *EnableIf) GoString() string

func (*EnableIf) Traverse

func (ei *EnableIf) 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.

func (*ExprList) Copy

func (el *ExprList) Copy(fn func(AST) AST, skip func(AST) bool) AST

func (*ExprList) GoString

func (el *ExprList) GoString() string

func (*ExprList) Traverse

func (el *ExprList) Traverse(fn func(AST) bool)

type FixedType

type FixedType struct {
	Base  AST
	Accum bool
	Sat   bool
}

FixedType is a fixed numeric type of unknown size.

func (*FixedType) Copy

func (ft *FixedType) Copy(fn func(AST) AST, skip func(AST) bool) AST

func (*FixedType) GoString

func (ft *FixedType) GoString() string

func (*FixedType) Traverse

func (ft *FixedType) Traverse(fn func(AST) bool)

type Fold

type Fold struct {
	Left bool
	Op   AST
	Arg1 AST
	Arg2 AST
}

Fold is a C++17 fold-expression. Arg2 is nil for a unary operator.

func (*Fold) Copy

func (f *Fold) Copy(fn func(AST) AST, skip func(AST) bool) AST

func (*Fold) GoString

func (f *Fold) GoString() string

func (*Fold) Traverse

func (f *Fold) 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) Copy

func (fp *FunctionParam) Copy(fn func(AST) AST, skip func(AST) bool) AST

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
}

FunctionType is a function type. The Return field may be nil for cases where the return type is not part of the mangled name.

func (*FunctionType) Copy

func (ft *FunctionType) Copy(fn func(AST) AST, skip func(AST) bool) AST

func (*FunctionType) GoString

func (ft *FunctionType) GoString() string

func (*FunctionType) Traverse

func (ft *FunctionType) Traverse(fn func(AST) bool)

type GlobalCDtor

type GlobalCDtor struct {
	Ctor bool
	Key  AST
}

GlobalCDtor is a global constructor or destructor.

func (*GlobalCDtor) Copy

func (gcd *GlobalCDtor) Copy(fn func(AST) AST, skip func(AST) bool) AST

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) Copy

func (it *ImaginaryType) Copy(fn func(AST) AST, skip func(AST) bool) AST

func (*ImaginaryType) GoString

func (it *ImaginaryType) GoString() string

func (*ImaginaryType) Traverse

func (it *ImaginaryType) Traverse(fn func(AST) bool)

type InitializerList

type InitializerList struct {
	Type  AST
	Exprs AST
}

InitializerList is an initializer list: an optional type with a list of expressions.

func (*InitializerList) Copy

func (il *InitializerList) Copy(fn func(AST) AST, skip func(AST) bool) AST

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) Copy

func (la *LambdaAuto) Copy(fn func(AST) AST, skip func(AST) bool) AST

func (*LambdaAuto) GoString

func (la *LambdaAuto) GoString() string

func (*LambdaAuto) Traverse

func (la *LambdaAuto) Traverse(fn func(AST) bool)

type Literal

type Literal struct {
	Type AST
	Val  string
	Neg  bool
}

Literal is a literal in an expression.

func (*Literal) Copy

func (l *Literal) Copy(fn func(AST) AST, skip func(AST) bool) AST

func (*Literal) GoString

func (l *Literal) GoString() string

func (*Literal) Traverse

func (l *Literal) 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) Copy

func (mwq *MethodWithQualifiers) Copy(fn func(AST) AST, skip func(AST) bool) AST

func (*MethodWithQualifiers) GoString

func (mwq *MethodWithQualifiers) GoString() string

func (*MethodWithQualifiers) Traverse

func (mwq *MethodWithQualifiers) Traverse(fn func(AST) bool)

type Name

type Name struct {
	Name string
}

Name is an unqualified name.

func (*Name) Copy

func (n *Name) Copy(fn func(AST) AST, skip func(AST) bool) AST

func (*Name) GoString

func (n *Name) GoString() string

func (*Name) Traverse

func (n *Name) Traverse(fn func(AST) bool)

type New

type New struct {
	Op    AST
	Place AST
	Type  AST
	Init  AST
}

New is a use of operator new in an expression.

func (*New) Copy

func (n *New) Copy(fn func(AST) AST, skip func(AST) bool) AST

func (*New) GoString

func (n *New) GoString() string

func (*New) Traverse

func (n *New) 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.

func (*Nullary) Copy

func (n *Nullary) Copy(fn func(AST) AST, skip func(AST) bool) AST

func (*Nullary) GoString

func (n *Nullary) GoString() string

func (*Nullary) Traverse

func (n *Nullary) Traverse(fn func(AST) bool)

type Operator

type Operator struct {
	Name string
}

Operator is an operator.

func (*Operator) Copy

func (op *Operator) Copy(fn func(AST) AST, skip func(AST) bool) AST

func (*Operator) GoString

func (op *Operator) GoString() string

func (*Operator) Traverse

func (op *Operator) Traverse(fn func(AST) bool)

type Option

type Option int

Option is the type of demangler options.

const (
	// The NoParams option disables demangling of function parameters.
	NoParams Option = iota

	// The NoTemplateParams option disables demangling of template parameters.
	NoTemplateParams

	// The NoClones option disables inclusion of clone suffixes.
	// NoParams implies NoClones.
	NoClones

	// The Verbose option turns on more verbose demangling.
	Verbose
)

type PackExpansion

type PackExpansion struct {
	Base AST
	Pack *ArgumentPack
}

PackExpansion is a pack expansion. The Pack field may be nil.

func (*PackExpansion) Copy

func (pe *PackExpansion) Copy(fn func(AST) AST, skip func(AST) bool) AST

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) Copy

func (pt *PointerType) Copy(fn func(AST) AST, skip func(AST) bool) AST

func (*PointerType) GoString

func (pt *PointerType) GoString() string

func (*PointerType) Traverse

func (pt *PointerType) Traverse(fn func(AST) bool)

type PtrMem

type PtrMem struct {
	Class  AST
	Member AST
}

PtrMem is a pointer-to-member expression.

func (*PtrMem) Copy

func (pm *PtrMem) Copy(fn func(AST) AST, skip func(AST) bool) AST

func (*PtrMem) GoString

func (pm *PtrMem) GoString() string

func (*PtrMem) Traverse

func (pm *PtrMem) 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.

func (*Qualified) Copy

func (q *Qualified) Copy(fn func(AST) AST, skip func(AST) bool) AST

func (*Qualified) GoString

func (q *Qualified) GoString() string

func (*Qualified) Traverse

func (q *Qualified) Traverse(fn func(AST) bool)

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.

func (*Qualifier) Copy

func (q *Qualifier) Copy(fn func(AST) AST, skip func(AST) bool) AST

func (*Qualifier) GoString

func (q *Qualifier) GoString() string

func (*Qualifier) Traverse

func (q *Qualifier) Traverse(fn func(AST) bool)

type Qualifiers

type Qualifiers struct {
	Qualifiers []AST
}

Qualifiers is an ordered list of type qualifiers.

func (*Qualifiers) Copy

func (qs *Qualifiers) Copy(fn func(AST) AST, skip func(AST) bool) AST

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) Copy

func (rt *ReferenceType) Copy(fn func(AST) AST, skip func(AST) bool) AST

func (*ReferenceType) GoString

func (rt *ReferenceType) GoString() string

func (*ReferenceType) Traverse

func (rt *ReferenceType) Traverse(fn func(AST) bool)

type RvalueReferenceType

type RvalueReferenceType struct {
	Base AST
}

RvalueReferenceType is an rvalue reference type.

func (*RvalueReferenceType) Copy

func (rt *RvalueReferenceType) Copy(fn func(AST) AST, skip func(AST) bool) AST

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) Copy

func (sa *SizeofArgs) Copy(fn func(AST) AST, skip func(AST) bool) AST

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) Copy

func (sp *SizeofPack) Copy(fn func(AST) AST, skip func(AST) bool) AST

func (*SizeofPack) GoString

func (sp *SizeofPack) GoString() string

func (*SizeofPack) Traverse

func (sp *SizeofPack) Traverse(fn func(AST) bool)

type Special

type Special struct {
	Prefix string
	Val    AST
}

Special is a special symbol, printed as a prefix plus another value.

func (*Special) Copy

func (s *Special) Copy(fn func(AST) AST, skip func(AST) bool) AST

func (*Special) GoString

func (s *Special) GoString() string

func (*Special) Traverse

func (s *Special) Traverse(fn func(AST) bool)

type Special2

type Special2 struct {
	Prefix string
	Val1   AST
	Middle string
	Val2   AST
}

Special2 is like special, but uses two values.

func (*Special2) Copy

func (s *Special2) Copy(fn func(AST) AST, skip func(AST) bool) AST

func (*Special2) GoString

func (s *Special2) GoString() string

func (*Special2) Traverse

func (s *Special2) Traverse(fn func(AST) bool)

type TaggedName

type TaggedName struct {
	Name AST
	Tag  AST
}

TaggedName is a name with an ABI tag.

func (*TaggedName) Copy

func (t *TaggedName) Copy(fn func(AST) AST, skip func(AST) bool) AST

func (*TaggedName) GoString

func (t *TaggedName) GoString() string

func (*TaggedName) Traverse

func (t *TaggedName) Traverse(fn func(AST) bool)

type Template

type Template struct {
	Name AST
	Args []AST
}

Template is a template with arguments.

func (*Template) Copy

func (t *Template) Copy(fn func(AST) AST, skip func(AST) bool) AST

func (*Template) GoString

func (t *Template) GoString() string

func (*Template) Traverse

func (t *Template) Traverse(fn func(AST) bool)

type TemplateParam

type TemplateParam struct {
	Index    int
	Template *Template
}

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) Copy

func (tp *TemplateParam) Copy(fn func(AST) AST, skip func(AST) bool) AST

func (*TemplateParam) GoString

func (tp *TemplateParam) GoString() string

func (*TemplateParam) Traverse

func (tp *TemplateParam) Traverse(fn func(AST) bool)

type Trinary

type Trinary struct {
	Op     AST
	First  AST
	Second AST
	Third  AST
}

Trinary is the ?: trinary operation in an expression.

func (*Trinary) Copy

func (t *Trinary) Copy(fn func(AST) AST, skip func(AST) bool) AST

func (*Trinary) GoString

func (t *Trinary) GoString() string

func (*Trinary) Traverse

func (t *Trinary) Traverse(fn func(AST) bool)

type TypeWithQualifiers

type TypeWithQualifiers struct {
	Base       AST
	Qualifiers AST
}

TypeWithQualifiers is a type with standard qualifiers.

func (*TypeWithQualifiers) Copy

func (twq *TypeWithQualifiers) Copy(fn func(AST) AST, skip func(AST) bool) AST

func (*TypeWithQualifiers) GoString

func (twq *TypeWithQualifiers) GoString() string

func (*TypeWithQualifiers) Traverse

func (twq *TypeWithQualifiers) Traverse(fn func(AST) bool)

type Typed

type Typed struct {
	Name AST
	Type AST
}

Typed is a typed name.

func (*Typed) Copy

func (t *Typed) Copy(fn func(AST) AST, skip func(AST) bool) AST

func (*Typed) GoString

func (t *Typed) GoString() string

func (*Typed) Traverse

func (t *Typed) 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.

func (*Unary) Copy

func (u *Unary) Copy(fn func(AST) AST, skip func(AST) bool) AST

func (*Unary) GoString

func (u *Unary) GoString() string

func (*Unary) Traverse

func (u *Unary) Traverse(fn func(AST) bool)

type UnnamedType

type UnnamedType struct {
	Num int
}

UnnamedType is an unnamed type, that just has an index.

func (*UnnamedType) Copy

func (ut *UnnamedType) Copy(fn func(AST) AST, skip func(AST) bool) AST

func (*UnnamedType) GoString

func (ut *UnnamedType) GoString() string

func (*UnnamedType) Traverse

func (ut *UnnamedType) Traverse(fn func(AST) bool)

type VectorType

type VectorType struct {
	Dimension AST
	Base      AST
}

VectorType is a vector type.

func (*VectorType) Copy

func (vt *VectorType) Copy(fn func(AST) AST, skip func(AST) bool) AST

func (*VectorType) GoString

func (vt *VectorType) GoString() string

func (*VectorType) Traverse

func (vt *VectorType) Traverse(fn func(AST) bool)

type VendorQualifier

type VendorQualifier struct {
	Qualifier AST
	Type      AST
}

VendorQualifier is a type qualified by a vendor-specific qualifier.

func (*VendorQualifier) Copy

func (vq *VendorQualifier) Copy(fn func(AST) AST, skip func(AST) bool) AST

func (*VendorQualifier) GoString

func (vq *VendorQualifier) GoString() string

func (*VendorQualifier) Traverse

func (vq *VendorQualifier) Traverse(fn func(AST) bool)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL