| 1 |
/+ |
|---|
| 2 |
Copyright (c) 2005 Eric Anderton, Don Clugston |
|---|
| 3 |
|
|---|
| 4 |
Based on demangler.d written by James Dunne, Copyright (C) 2005 |
|---|
| 5 |
|
|---|
| 6 |
Permission is hereby granted, free of charge, to any person |
|---|
| 7 |
obtaining a copy of this software and associated documentation |
|---|
| 8 |
files (the "Software"), to deal in the Software without |
|---|
| 9 |
restriction, including without limitation the rights to use, |
|---|
| 10 |
copy, modify, merge, publish, distribute, sublicense, and/or |
|---|
| 11 |
sell copies of the Software, and to permit persons to whom the |
|---|
| 12 |
Software is furnished to do so, subject to the following |
|---|
| 13 |
conditions: |
|---|
| 14 |
|
|---|
| 15 |
The above copyright notice and this permission notice shall be |
|---|
| 16 |
included in all copies or substantial portions of the Software. |
|---|
| 17 |
|
|---|
| 18 |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
|---|
| 19 |
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES |
|---|
| 20 |
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
|---|
| 21 |
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT |
|---|
| 22 |
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
|---|
| 23 |
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
|---|
| 24 |
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
|---|
| 25 |
OTHER DEALINGS IN THE SOFTWARE. |
|---|
| 26 |
+/ |
|---|
| 27 |
/* |
|---|
| 28 |
Template Library to support compile-time symbol demangling. |
|---|
| 29 |
This is put to good use by the DynamicLibrary class. |
|---|
| 30 |
|
|---|
| 31 |
Authors: Eric Anderton, Don Clugston |
|---|
| 32 |
License: BSD Derivative (see source for details) |
|---|
| 33 |
Copyright: 2005 Eric Anderton |
|---|
| 34 |
*/ |
|---|
| 35 |
module ddl.Mangle; |
|---|
| 36 |
|
|---|
| 37 |
import meta.conv; |
|---|
| 38 |
|
|---|
| 39 |
import Integer = tango.text.convert.Integer; |
|---|
| 40 |
|
|---|
| 41 |
/* char [] mangleSymbolName!(char [] name); |
|---|
| 42 |
* Convert a name of the form "module.func" to the form |
|---|
| 43 |
* "6module4func". |
|---|
| 44 |
*/ |
|---|
| 45 |
template mangleSymbolName(char[] text, char [] latestword="") |
|---|
| 46 |
{ |
|---|
| 47 |
static if (text.length<1) { |
|---|
| 48 |
static if (latestword.length==0) |
|---|
| 49 |
const char[] mangleSymbolName = ""; |
|---|
| 50 |
else const char[] mangleSymbolName = itoa!(latestword.length) ~ latestword; |
|---|
| 51 |
} else static if (text[0]=='.') { |
|---|
| 52 |
const char[] mangleSymbolName = |
|---|
| 53 |
itoa!(latestword.length) ~ latestword ~ .mangleSymbolName!(text[1..(text.length)], ""); |
|---|
| 54 |
} else |
|---|
| 55 |
const char[] mangleSymbolName = .mangleSymbolName!( text[1..(text.length)], latestword ~ text[0..(1)]); |
|---|
| 56 |
} |
|---|
| 57 |
|
|---|
| 58 |
/* |
|---|
| 59 |
Runtime function that converts a name of the form "module.func" to the form "6module4func" per |
|---|
| 60 |
the D ABI name-mangling specification. |
|---|
| 61 |
*/ |
|---|
| 62 |
char[] mangleNamespace(char[] text){ |
|---|
| 63 |
char[] result; |
|---|
| 64 |
char[] buffer = new char[16]; |
|---|
| 65 |
uint i=0; |
|---|
| 66 |
uint last=0; |
|---|
| 67 |
while(i < text.length){ |
|---|
| 68 |
if(text[i] == '.'){ |
|---|
| 69 |
result ~= Integer.format(buffer,(i-last)) ~ text[last..i]; |
|---|
| 70 |
i++; |
|---|
| 71 |
last = i; |
|---|
| 72 |
} |
|---|
| 73 |
i++; |
|---|
| 74 |
} |
|---|
| 75 |
result ~= Integer.format(buffer,(text.length-last)) ~ text[last..text.length]; |
|---|
| 76 |
return result; |
|---|
| 77 |
} |
|---|