comparison 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
comparison
equal deleted inserted replaced
95:6aecbe5a7706 96:438e6ed4cda1
94 return myPointer; 94 return myPointer;
95 myPointer = new DPointer(this); 95 myPointer = new DPointer(this);
96 return myPointer; 96 return myPointer;
97 } 97 }
98 private DPointer myPointer; 98 private DPointer myPointer;
99
100 /**
101 Mangle the DType following the specs at http://digitalmars.com/d/1.0/abi.html
102 **/
103 char[] mangle()
104 {
105 /// expects to be void
106 return "v";
107 }
99 108
100 /** 109 /**
101 Get a type representing a static array of this type with length 'size' 110 Get a type representing a static array of this type with length 'size'
102 */ 111 */
103 DArray getAsArray(int size) 112 DArray getAsArray(int size)
135 /** 144 /**
136 Class to represent the built-in integer types, from byte to long. 145 Class to represent the built-in integer types, from byte to long.
137 */ 146 */
138 class DInteger : DType 147 class DInteger : DType
139 { 148 {
149 private static char[][DInteger] mangle_types;
150
151 static this()
152 {
153 mangle_types =
154 [
155 Bool : "b",
156 Byte : "g",
157 UByte : "h",
158 Short : "s",
159 UShort : "t",
160 Int : "i",
161 UInt : "k",
162 Long : "l",
163 ULong : "m"
164 ];
165 }
166
140 this(char[] name, int bits, bool unsigned) 167 this(char[] name, int bits, bool unsigned)
141 { 168 {
142 super(name, null); 169 super(name, null);
143 this.bits = bits; 170 this.bits = bits;
144 this.unsigned = unsigned; 171 this.unsigned = unsigned;
155 } 182 }
156 183
157 override bool isInteger() { return true; } 184 override bool isInteger() { return true; }
158 override DInteger asInteger() { return this; } 185 override DInteger asInteger() { return this; }
159 186
187 override char[] mangle()
188 {
189 return mangle_types[this];
190 }
191
160 int bits; 192 int bits;
161 bool unsigned; 193 bool unsigned;
162 } 194 }
163 195
164 class DStruct : DType 196 class DStruct : DType
197 } 229 }
198 230
199 DStructMember[char[]] members; 231 DStructMember[char[]] members;
200 private int bytes_total; 232 private int bytes_total;
201 233
234 override char[] mangle()
235 {
236 return "S"~Integer.toString(name.length)~name;
237 }
238
202 struct DStructMember 239 struct DStructMember
203 { 240 {
204 DType type; 241 DType type;
205 int index; 242 int index;
206 } 243 }
218 override bool isArray() { return true; } 255 override bool isArray() { return true; }
219 override DArray asArray() { return this; } 256 override DArray asArray() { return this; }
220 257
221 int byteSize() { return arrayOf.byteSize * size; } 258 int byteSize() { return arrayOf.byteSize * size; }
222 259
260 override char[] mangle()
261 {
262 return "G"~Integer.toString(size)~arrayOf.mangle;
263 }
264
223 DType arrayOf; 265 DType arrayOf;
224 const int size; 266 const int size;
225 } 267 }
226 268
227 class DPointer : DType 269 class DPointer : DType
235 override bool isPointer() { return true; } 277 override bool isPointer() { return true; }
236 override DPointer asPointer() { return this; } 278 override DPointer asPointer() { return this; }
237 279
238 int byteSize() { return DType.Int.byteSize; } 280 int byteSize() { return DType.Int.byteSize; }
239 281
282 override char[] mangle()
283 {
284 return "P"~pointerOf.mangle;
285 }
286
240 DType pointerOf; 287 DType pointerOf;
241 } 288 }
242 289
243 class DFunction : DType 290 class DFunction : DType
244 { 291 {
247 super(id, actual); 294 super(id, actual);
248 } 295 }
249 296
250 override bool isFunction() { return true; } 297 override bool isFunction() { return true; }
251 override DFunction asFunction() { return this; } 298 override DFunction asFunction() { return this; }
299
300 override char[] mangle()
301 {
302 char[] res;
303 res ~= "F";
304
305 foreach(param ; params)
306 res ~= "J" ~ param.mangle;
307
308 res ~= "Z" ~ returnType.mangle;
309
310 return res;
311 }
252 312
253 DType[] params; 313 DType[] params;
254 DType returnType; 314 DType returnType;
255 bool firstParamIsReturnValue = false; 315 bool firstParamIsReturnValue = false;
256 } 316 }