Mercurial > projects > dang
diff sema/DType.d @ 96:438e6ed4cda1 new_gen
Now D-Mangling the function types. Still need to mangle "scopes" - by that i mean structs, classes and modules.
author | Anders Johnsen <skabet@gmail.com> |
---|---|
date | Tue, 06 May 2008 18:51:08 +0200 |
parents | eb5b2c719a39 |
children | 09b4d74cb3f5 |
line wrap: on
line diff
--- a/sema/DType.d Tue May 06 17:01:00 2008 +0200 +++ b/sema/DType.d Tue May 06 18:51:08 2008 +0200 @@ -97,6 +97,15 @@ } private DPointer myPointer; + /** + Mangle the DType following the specs at http://digitalmars.com/d/1.0/abi.html + **/ + char[] mangle() + { + /// expects to be void + return "v"; + } + /** Get a type representing a static array of this type with length 'size' */ @@ -137,6 +146,24 @@ */ class DInteger : DType { + private static char[][DInteger] mangle_types; + + static this() + { + mangle_types = + [ + Bool : "b", + Byte : "g", + UByte : "h", + Short : "s", + UShort : "t", + Int : "i", + UInt : "k", + Long : "l", + ULong : "m" + ]; + } + this(char[] name, int bits, bool unsigned) { super(name, null); @@ -157,6 +184,11 @@ override bool isInteger() { return true; } override DInteger asInteger() { return this; } + override char[] mangle() + { + return mangle_types[this]; + } + int bits; bool unsigned; } @@ -199,6 +231,11 @@ DStructMember[char[]] members; private int bytes_total; + override char[] mangle() + { + return "S"~Integer.toString(name.length)~name; + } + struct DStructMember { DType type; @@ -220,6 +257,11 @@ int byteSize() { return arrayOf.byteSize * size; } + override char[] mangle() + { + return "G"~Integer.toString(size)~arrayOf.mangle; + } + DType arrayOf; const int size; } @@ -237,6 +279,11 @@ int byteSize() { return DType.Int.byteSize; } + override char[] mangle() + { + return "P"~pointerOf.mangle; + } + DType pointerOf; } @@ -250,6 +297,19 @@ override bool isFunction() { return true; } override DFunction asFunction() { return this; } + override char[] mangle() + { + char[] res; + res ~= "F"; + + foreach(param ; params) + res ~= "J" ~ param.mangle; + + res ~= "Z" ~ returnType.mangle; + + return res; + } + DType[] params; DType returnType; bool firstParamIsReturnValue = false;