mangle

mangle

part of shnell – a source to source compiler enhancement tool

© Jens Gustedt, 2017

Mangle names according to a common C++ strategy

We use mangling of the form _ZN#1s1#2s2…E where #1 is the length of identifier s1 etc. All names are prefixed with a specific prefix that avoids conflicts with mangled identifiers such as produced by C++. By default this is _C.

manglePrefix=${manglePrefix:-_C}

SRC="$_" . "${0%%/${0##*/}}/import.sh"
import join
import match
import echo
import list

Declared functions

mangleRaw: This is the core of the mangle algorithm.

A list of identifiers is transformed to a string that precedes each of the identifiers by its character length.

mangleComp: mangle a sequence of identifiers as it where a template with

arguments

splitlong: Split along a long separator that may consist of several characters The return value is stored in the variable splitlongRet.

mangleIDlocal: partially mangle a list of identifiers separated by ‘#’

mangleLocal: completely mangle a composed identifier The return value is stored in mangleRet.

mangle: Same as mangleLocal but the result is echoed to stdout

checkMangle: check if we have to mangle and return the symbol in mangleRet