Browse Source

[ItaniumAbi] Improve compression in name mangling

pull/1/head
Alex Corrado 14 years ago
parent
commit
58566ee37c
  1. 53
      src/Mono.Cxxi/Abi/Impl/ItaniumAbi.cs

53
src/Mono.Cxxi/Abi/Impl/ItaniumAbi.cs

@ -108,11 +108,10 @@ namespace Mono.Cxxi.Abi {
if (type.Namespaces != null) { if (type.Namespaces != null) {
foreach (var ns in type.Namespaces) foreach (var ns in type.Namespaces)
nm.Append (ns.Length).Append (ns); nm.Append (GetIdentifier (compressMap, ns));
} }
nm.Append (className.Length).Append (className); nm.Append (GetIdentifier (compressMap, className));
compressMap [className] = compressMap.Count;
// FIXME: Implement compression completely // FIXME: Implement compression completely
@ -180,29 +179,45 @@ namespace Mono.Cxxi.Abi {
case CppTypes.Class: case CppTypes.Class:
case CppTypes.Struct: case CppTypes.Struct:
case CppTypes.Union: case CppTypes.Union:
case CppTypes.Enum: { case CppTypes.Enum:
int cid; if (mangleType.Namespaces != null) {
if (compressMap.TryGetValue (mangleType.ElementTypeName, out cid)) { code.Append ('N');
if (cid == 0) foreach (var ns in mangleType.Namespaces)
code.Append ("S_"); code.Append (GetIdentifier (compressMap, ns));
else
throw new NotImplementedException ();
} else {
if (mangleType.Namespaces != null) {
code.Append ('N');
foreach (var ns in mangleType.Namespaces)
code.Append (ns.Length).Append (ns);
}
code.Append (mangleType.ElementTypeName.Length).Append (mangleType.ElementTypeName);
} }
code.Append (GetIdentifier (compressMap, mangleType.ElementTypeName));
if (mangleType.Namespaces != null)
code.Append ('E');
break; break;
}
} }
return code.ToString (); return code.ToString ();
} }
string GetIdentifier (Dictionary<string, int> compressMap, string identifier)
{
int cid;
if (compressMap.TryGetValue (identifier, out cid))
return cid == 0 ? "S_" : ToBase36String (cid - 1);
compressMap [identifier] = compressMap.Count;
return identifier.Length.ToString () + identifier;
}
const string Base36 = "0123456789abcdefghijklmnopqrstuvwxyz";
string ToBase36String (int input)
{
var result = new Stack<char> ();
while (input != 0)
{
result.Push (Base36 [input % 36]);
input /= 36;
}
return new string (result.ToArray ());
}
// Section 3.1.4: // Section 3.1.4:
// Classes with non-default copy ctors/destructors are returned using a hidden // Classes with non-default copy ctors/destructors are returned using a hidden
// argument // argument

Loading…
Cancel
Save