Skip to main content

Crate swift_demangler

Crate swift_demangler 

Source
Expand description

Swift symbol demangling library with high-level semantic types.

This crate provides both low-level (raw) and high-level APIs for working with Swift mangled symbols.

§High-Level API

The high-level API provides semantic types that make it easy to work with demangled symbols. Create a Context and use Symbol::parse to get started:

use swift_demangler::{Context, HasFunctionSignature, HasModule, Symbol};

let ctx = Context::new();
if let Some(symbol) = Symbol::parse(&ctx, "$s4main5helloSSyYaKF") {
    if let Some(func) = symbol.as_function() {
        println!("Function: {}", func.name().unwrap_or("?"));
        println!("Module: {}", func.module().unwrap_or("?"));
        println!("Async: {}", func.is_async());
        println!("Throws: {}", func.is_throwing());
    }
}

§Low-Level API

The raw module provides direct access to the node tree:

use swift_demangler::Context;
use swift_demangler::raw::{Node, NodeKind};

let ctx = Context::new();
if let Some(root) = Node::parse(&ctx, "$s4main5helloSSyYaKF") {
    for node in root.descendants() {
        println!("{:?}: {:?}", node.kind(), node.text());
    }
}

Re-exports§

pub use raw::demangle;
pub use raw::Context;

Modules§

raw
Low-level Swift symbol demangling API.

Structs§

Accessor
A Swift property accessor symbol.
AsyncSymbol
A Swift async or coroutine symbol.
AttributedSymbol
A symbol with an attribute modifier (@objc, @nonobjc, dynamic, distributed).
AutoDiff
A Swift automatic differentiation symbol.
AutoDiffThunk
An automatic differentiation thunk.
Closure
A Swift closure symbol.
Constructor
A Swift constructor (initializer) symbol.
DefaultArgument
A default argument initializer.
Descriptor
A Swift metadata descriptor symbol.
Destructor
A Swift destructor (deinitializer) symbol.
EnumCase
A Swift enum case constructor symbol.
Function
A Swift function symbol.
FunctionParam
A parameter in a function type.
FunctionSignatureParam
A parameter in a function signature specialization.
FunctionSignatureParamFlags
Option flags that can be combined with the base param kind.
FunctionType
A Swift function type.
GenericRequirement
A generic requirement (constraint) on a generic parameter.
GenericSignature
A generic signature describing generic parameters and their constraints.
ImplFunctionType
A SIL implementation function type.
ImplParam
A parameter in a SIL implementation function type.
ImplResult
A result in a SIL implementation function type.
MacroSymbol
A Swift macro symbol.
Metadata
A Swift type metadata symbol.
NamedType
A named Swift type (class, struct, enum, protocol, type alias).
OpaqueSource
Information about the source of an opaque return type.
Outlined
A Swift outlined operation symbol.
OutlinedSymbol
An outlined symbol containing both the outlined operation metadata and the context symbol.
ProtocolConformance
Information about a protocol conformance.
ProtocolWitnessThunk
A protocol witness thunk that adapts a concrete implementation to a protocol requirement.
ReabstractionThunk
A reabstraction thunk that converts between calling conventions.
Specialization
A Swift specialization symbol.
SpecializedSymbol
A specialized symbol containing both the specialization metadata and the inner symbol.
SuffixedSymbol
A symbol with an unmangled suffix.
SymbolContext
The context (location) of a Swift symbol.
TupleElement
A tuple element.
TypeRef
A reference to a Swift type.
Variable
A global variable symbol.
WitnessTable
A Swift witness table symbol.

Enums§

AccessorKind
The kind of accessor.
AsyncSymbolKind
The kind of async or coroutine symbol.
AutoDiffKind
The kind of automatic differentiation symbol.
AutoDiffThunkKind
The kind of autodiff thunk.
ClosureKind
The kind of closure.
ConstructorKind
The kind of constructor.
ContextComponent
A component in a symbol’s context path.
DescriptorKind
The kind of metadata descriptor.
DestructorKind
The kind of destructor.
DispatchKind
The kind of dispatch thunk.
FunctionConvention
The calling convention of a function type.
FunctionSignatureParamKind
The base kind of function signature parameter transformation.
GenericRequirementKind
The kind of generic requirement.
MacroSymbolKind
The kind of macro symbol.
MetadataKind
The kind of type metadata.
OtherThunkKind
Other thunk kinds that don’t need specialized handling.
OutlinedKind
The kind of outlined operation.
SpecializationKind
The kind of specialization.
Symbol
A parsed Swift symbol.
SymbolAttribute
Symbol attributes that can be applied to declarations.
Thunk
A Swift thunk symbol.
TypeKind
The kind of a Swift type.
ValueWitnessKind
The kind of value witness.
WitnessTableKind
The kind of witness table.

Traits§

HasExtensionContext
Trait for types that can be defined in an extension.
HasFunctionSignature
Trait for types that have a function signature.
HasGenericSignature
Trait for types that may have a generic signature.
HasModule
Trait for types that can provide their containing module.