Module Structured_mangling
Structured name mangling for OxCaml symbols.
This module implements a mangling scheme that encodes OxCaml identifiers into a restricted character set (ASCII alphanumeric and underscore) suitable for use in linker symbols. The scheme preserves the lexical structure of the source program by encoding each scope (compilation unit, module, function, etc.) as a tagged path item.
Mangled symbol format
A mangled symbol has the form _Caml<path> where <path> is a sequence of tagged, length-prefixed identifiers:
U- compilation UnitI- Inline markerM- ModuleS- anonymous StructO- class (O for object)F- FunctionL- anonymous function (L for lambda)P- Partial application
For example, Foo.Bar.baz in compilation unit Foo mangles to _CamlU3FooM3BarF3baz.
type path_item = | Compilation_unit of Compilation_unit.t(*A compilation unit (file)
*)| Inline_marker(*A separator (between destination and source) to track inlining
*)| Module of string(*A named module
*)| Anonymous_module of int * int * string option(*
*)struct ... endat (line, col, file)| Class of string(*A class definition
*)| Function of string(*A named function
*)| Anonymous_function of int * int * string option(*
*)fun ... -> ...at (line, col, file)| Partial_function of int * int * string option(*A partial application at (line, col, file)
*)
A path item represents a single lexical scope in the mangling path.
type path = path_item listA mangling path is a list of path items representing the full lexical context of an identifier.
val mangle_ident : Compilation_unit.t -> path -> stringTransform a Compilation_unit.t and a path into a mangled name suitable for creating a LinkageName.t