| 1 |
/** |
| 2 |
* Defines the building blocks for creating the mangled names for basic types. |
| 3 |
* |
| 4 |
* Copyright: Copyright (C) 1999-2025 by The D Language Foundation, All Rights Reserved |
| 5 |
* License: $(LINK2 https://www.boost.org/LICENSE_1_0.txt, Boost License 1.0) |
| 6 |
* Source: $(LINK2 https://github.com/dlang/dmd/blob/master/compiler/src/dmd/mangle/basic.d, _basicmangle.d) |
| 7 |
* Documentation: https://dlang.org/phobos/dmd_basicmangle.html |
| 8 |
* Coverage: https://codecov.io/gh/dlang/dmd/src/master/compiler/src/dmd/mangle/basic.d |
| 9 |
*/ |
| 10 |
module dmd.mangle.basic; |
| 11 |
|
| 12 |
import dmd.astenums; |
| 13 |
import dmd.common.outbuffer : OutBuffer; |
| 14 |
|
| 15 |
/// Type mangling mapping for basic, derived and user defined types |
| 16 |
immutable char[TMAX] mangleChar = |
| 17 |
[ |
| 18 |
Tchar : 'a', |
| 19 |
Tbool : 'b', |
| 20 |
Tcomplex80 : 'c', |
| 21 |
Tfloat64 : 'd', |
| 22 |
Tfloat80 : 'e', |
| 23 |
Tfloat32 : 'f', |
| 24 |
Tint8 : 'g', |
| 25 |
Tuns8 : 'h', |
| 26 |
Tint32 : 'i', |
| 27 |
Timaginary80 : 'j', |
| 28 |
Tuns32 : 'k', |
| 29 |
Tint64 : 'l', |
| 30 |
Tuns64 : 'm', |
| 31 |
Tnull : 'n', |
| 32 |
Timaginary32 : 'o', |
| 33 |
Timaginary64 : 'p', |
| 34 |
Tcomplex32 : 'q', |
| 35 |
Tcomplex64 : 'r', |
| 36 |
Tint16 : 's', |
| 37 |
Tuns16 : 't', |
| 38 |
Twchar : 'u', |
| 39 |
Tvoid : 'v', |
| 40 |
Tdchar : 'w', |
| 41 |
// x // const |
| 42 |
// y // immutable |
| 43 |
Tint128 : 'z', // zi |
| 44 |
Tuns128 : 'z', // zk |
| 45 |
|
| 46 |
Tarray : 'A', |
| 47 |
Ttuple : 'B', |
| 48 |
Tclass : 'C', |
| 49 |
Tdelegate : 'D', |
| 50 |
Tenum : 'E', |
| 51 |
Tfunction : 'F', // D function |
| 52 |
Tsarray : 'G', |
| 53 |
Taarray : 'H', |
| 54 |
// I // in |
| 55 |
// J // out |
| 56 |
// K // ref |
| 57 |
// L // lazy |
| 58 |
// M // has this, or scope |
| 59 |
// N // Nh:vector Ng:wild Nn:noreturn |
| 60 |
// O // shared |
| 61 |
Tpointer : 'P', |
| 62 |
// Q // Type/symbol/identifier backward reference |
| 63 |
Treference : 'R', |
| 64 |
Tstruct : 'S', |
| 65 |
// T // Ttypedef |
| 66 |
// U // C function |
| 67 |
// W // Windows function |
| 68 |
// X // variadic T t...) |
| 69 |
// Y // variadic T t,...) |
| 70 |
// Z // not variadic, end of parameters |
| 71 |
|
| 72 |
// '@' shouldn't appear anywhere in the deco'd names |
| 73 |
Tnone : '@', |
| 74 |
Tident : '@', |
| 75 |
Tinstance : '@', |
| 76 |
Terror : '@', |
| 77 |
Ttypeof : '@', |
| 78 |
Tslice : '@', |
| 79 |
Treturn : '@', |
| 80 |
Tvector : '@', |
| 81 |
Ttraits : '@', |
| 82 |
Tmixin : '@', |
| 83 |
Ttag : '@', |
| 84 |
Tnoreturn : '@', // becomes 'Nn' |
| 85 |
]; |
| 86 |
|
| 87 |
unittest |
| 88 |
{ |
| 89 |
foreach (i, mangle; mangleChar) |
| 90 |
{ |
| 91 |
if (mangle == char.init) |
| 92 |
{ |
| 93 |
import core.stdc.stdio; |
| 94 |
fprintf(stderr, "ty = %u\n", cast(uint)i); |
| 95 |
assert(0); |
| 96 |
} |
| 97 |
} |
| 98 |
} |
| 99 |
|
| 100 |
/*********************** |
| 101 |
* Mangle basic type ty to buf. |
| 102 |
*/ |
| 103 |
void tyToDecoBuffer(ref OutBuffer buf, int ty) @safe |
| 104 |
{ |
| 105 |
const c = mangleChar[ty]; |
| 106 |
buf.writeByte(c); |
| 107 |
if (c == 'z') |
| 108 |
buf.writeByte(ty == Tint128 ? 'i' : 'k'); |
| 109 |
} |