Mangling scheme for method signatures

The following grammar documents the name mangling scheme used by the Titanium compiler for translating Titanium method signatures into unique C identifiers.

MethodNameStaticMethodNameDynamic MANGLE_METHOD_NAME_END_MARKER containerType
MethodNameDynamicEncodedMethodName paramTypes

// mangling method name
EncodedMethodNamem MethodTypeMarkers MethodName | o N Operator
MethodTypeMarkersMethodLocalInferred MethodSharing | DeclaredLocal MethodSharing | ε
MethodLocalInferredMANGLE_LQI_NAMESPACE_MARKER
DeclaredLocalMANGLE_LOCAL_NAMESPACE_MARKER
MethodSharingMANGLE_NONSHARED_NAMESPACE_MARKER | MANGLE_POLYSHARED_NAMESPACE_MARKER | ε

// mangling parameters
ParamTypesFormalSignature ParamTypes | TypeModifiers cType ParamTypes | ε
TypeModifiersTypeLocalInferred SharingInferred TypeSharing | TypeLocalInferred TypeSharing | SharingInferred TypeSharing | ε
TypeLocalInferredMANGLE_LQI_FORMAL_MARKER
SharingInferredMANGLE_SHARING_INFERENCE_FORMAL_MARKER
TypeSharingMANGLE_TYPE_NONSHARED_MARKER | MANGLE_TYPE_POLYSHARED_MARKER

// for primitive types
FormalSignatureB | C | D | F | I | J | S | Z

cTypeClassOrInterfaceType | TemplateType | ArrayType
ClassOrInterfaceTypeQualifier MANGLE_TYPE_MARKER TypeName
ArrayTypeTiArray | JavaArray
TiArrayMANGLE_TYPE_MARKER MANGLE_TI_ARRAY_TYPE_MARKER Qualifier ArrayDim BaseType
JavaArrayQualifier MANGLE_TYPE_MARKER MANGLE_JAVA_ARRAY_MARKER BaseType
BaseTypePrimitiveType | cType
PrimitiveTypejboolean | jbyte | jchar | jdouble | jfloat | jint | jlong | jshort
ArrayDim → [1-9][0-9]*
QualifierMANGLE_TYPE_GLOBAL_MARKER | MANGLE_TYPE_LOCAL_MARKER
TypeName → // see notes below
ContainerType → // see notes below

// Operators
Operator

LogicalComplementEX
BitwiseComplementTI
LessLE
GreaterGT
LessEqualLEEQ
GreaterEqualGTEQ
EqualityEQEQ
InequalityEXEQ
AdditionPL
SubtractionMI
MultiplicationST
DivisionSL
BitwiseAndAN
BitwiseOrBA
BitwiseXorCA
RemainderPE
LeftShiftLELE
SignedRightShiftGTGT
UnsignedRightShiftGTGTGT
AdditionAssignPLEQ
SubtractionAssignMIEQ
MultipliationAssignSTEQ
DivisionAssignSLEQ
RemainderAssignPEEQ
LeftShiftAssignLELEEQ
RightShiftAssignGTGTEQ
UnsignedRightShiftAssignGTGTGTEQ
BitwiseAndAssignANEQ
BitwiseXorAssignCAEQ
BitwiseOrAssignBAEQ
ArrayAccessOBCB
ArrayAccessAssignOBCBEQ
// Markers
MANGLE_LQI_NAMESPACE_MARKERm
MANGLE_LOCAL_NAMESPACE_MARKERl
MANGLE_NONSHARED_NAMESPACE_MARKERn
MANGLE_POLYSHARED_NAMESPACE_MARKERp
MANGLE_LQI_FORMAL_MARKERM
MANGLE_SHARING_INFERENCE_FORMAL_MARKERs
MANGLE_TYPE_NONSHARED_MARKERn
MANGLE_TYPE_POLYSHARED_MARKERp
MANGLE_TYPE_MARKERT
MANGLE_TYPE_GLOBAL_MARKERP
MANGLE_TYPE_LOCAL_MARKERL
MANGLE_TI_ARRAY_MARKERB
MANGLE_JAVA_ARRAY_MARKERA

Notes:
TypeName and ContainerType are either of the form n1s1n2s2n3s3...nksk, where ni is the length of the string si and si is a member of the package si+1, or of the form nc_n1s1n2s2n3s3...nksk where si is the enclosing class of si+1. MethodName may also take the latter form.