Skip to main content

swift_demangler/
lib.rs

1//! Swift symbol demangling library with high-level semantic types.
2//!
3//! This crate provides both low-level (`raw`) and high-level APIs for working
4//! with Swift mangled symbols.
5//!
6//! # High-Level API
7//!
8//! The high-level API provides semantic types that make it easy to work with
9//! demangled symbols. Create a [`Context`] and use [`Symbol::parse`] to
10//! get started:
11//!
12//! ```
13//! use swift_demangler::{Context, HasFunctionSignature, HasModule, Symbol};
14//!
15//! let ctx = Context::new();
16//! if let Some(symbol) = Symbol::parse(&ctx, "$s4main5helloSSyYaKF") {
17//!     if let Some(func) = symbol.as_function() {
18//!         println!("Function: {}", func.name().unwrap_or("?"));
19//!         println!("Module: {}", func.module().unwrap_or("?"));
20//!         println!("Async: {}", func.is_async());
21//!         println!("Throws: {}", func.is_throwing());
22//!     }
23//! }
24//! ```
25//!
26//! # Low-Level API
27//!
28//! The [`raw`] module provides direct access to the node tree:
29//!
30//! ```
31//! use swift_demangler::Context;
32//! use swift_demangler::raw::{Node, NodeKind};
33//!
34//! let ctx = Context::new();
35//! if let Some(root) = Node::parse(&ctx, "$s4main5helloSSyYaKF") {
36//!     for node in root.descendants() {
37//!         println!("{:?}: {:?}", node.kind(), node.text());
38//!     }
39//! }
40//! ```
41
42// Low-level raw API
43pub mod raw;
44
45// Shared helper utilities
46mod helpers;
47pub use helpers::{
48    HasExtensionContext, HasFunctionSignature, HasGenericSignature, HasModule,
49};
50
51// High-level semantic API modules
52mod accessor;
53mod async_symbol;
54mod autodiff;
55mod closure;
56mod constructor;
57mod context;
58mod descriptor;
59mod enum_case;
60mod function;
61mod macro_symbol;
62mod metadata;
63mod outlined;
64mod specialization;
65mod symbol;
66mod thunk;
67mod types;
68mod witness_table;
69
70// Re-export core types from raw module
71pub use raw::{demangle, Context};
72
73// Re-export high-level types at crate root
74pub use accessor::{Accessor, AccessorKind};
75pub use async_symbol::{AsyncSymbol, AsyncSymbolKind};
76pub use autodiff::{AutoDiff, AutoDiffKind};
77pub use closure::{Closure, ClosureKind};
78pub use constructor::{Constructor, ConstructorKind, Destructor, DestructorKind};
79pub use context::{ContextComponent, SymbolContext};
80pub use descriptor::{Descriptor, DescriptorKind};
81pub use enum_case::EnumCase;
82pub use function::Function;
83pub use macro_symbol::{MacroSymbol, MacroSymbolKind};
84pub use metadata::{Metadata, MetadataKind};
85pub use outlined::{Outlined, OutlinedKind};
86pub use specialization::{
87    FunctionSignatureParam, FunctionSignatureParamFlags, FunctionSignatureParamKind,
88    Specialization, SpecializationKind,
89};
90pub use symbol::{
91    AttributedSymbol, DefaultArgument, OutlinedSymbol, SpecializedSymbol, SuffixedSymbol, Symbol,
92    SymbolAttribute, Variable,
93};
94pub use thunk::{
95    AutoDiffThunk, AutoDiffThunkKind, DispatchKind, OtherThunkKind, ProtocolWitnessThunk,
96    ReabstractionThunk, Thunk,
97};
98pub use types::{
99    FunctionConvention, FunctionParam, FunctionType, GenericRequirement, GenericRequirementKind,
100    GenericSignature, ImplFunctionType, ImplParam, ImplResult, NamedType, OpaqueSource,
101    TupleElement, TypeKind, TypeRef,
102};
103pub use witness_table::{ProtocolConformance, ValueWitnessKind, WitnessTable, WitnessTableKind};