Mercurial > projects > ddmd
comparison dmd/ClassDeclaration.d @ 130:60bb0fe4563e
dmdfe 2.037 first main iteration
author | Eldar Insafutdinov <e.insafutdinov@gmail.com> |
---|---|
date | Thu, 09 Sep 2010 22:51:44 +0100 |
parents | 1765f3ef917d |
children | af1bebfd96a4 |
comparison
equal
deleted
inserted
replaced
129:010eb8f0e18d | 130:60bb0fe4563e |
---|---|
8 import dmd.DeleteDeclaration; | 8 import dmd.DeleteDeclaration; |
9 import dmd.NewDeclaration; | 9 import dmd.NewDeclaration; |
10 import dmd.CtorDeclaration; | 10 import dmd.CtorDeclaration; |
11 import dmd.TypeIdentifier; | 11 import dmd.TypeIdentifier; |
12 import dmd.STC; | 12 import dmd.STC; |
13 import dmd.Argument; | 13 import dmd.Parameter; |
14 import dmd.TypeTuple; | 14 import dmd.TypeTuple; |
15 import dmd.TY; | 15 import dmd.TY; |
16 import dmd.LINK; | 16 import dmd.LINK; |
17 import dmd.DsymbolTable; | 17 import dmd.DsymbolTable; |
18 import dmd.FuncDeclaration; | 18 import dmd.FuncDeclaration; |
23 import dmd.Type; | 23 import dmd.Type; |
24 import dmd.OverloadSet; | 24 import dmd.OverloadSet; |
25 import dmd.ArrayTypes; | 25 import dmd.ArrayTypes; |
26 import dmd.BaseClass; | 26 import dmd.BaseClass; |
27 import dmd.ClassInfoDeclaration; | 27 import dmd.ClassInfoDeclaration; |
28 import dmd.TypeInfoClassDeclaration; | |
28 import dmd.Loc; | 29 import dmd.Loc; |
29 import dmd.Identifier; | 30 import dmd.Identifier; |
30 import dmd.Dsymbol; | 31 import dmd.Dsymbol; |
31 import dmd.Scope; | 32 import dmd.Scope; |
32 import dmd.TypeFunction; | 33 import dmd.TypeFunction; |
61 import dmd.codegen.Util; | 62 import dmd.codegen.Util; |
62 | 63 |
63 import std.string; | 64 import std.string; |
64 | 65 |
65 version (DMDV2) { | 66 version (DMDV2) { |
66 enum CLASSINFO_SIZE = (0x3C+16+4); // value of ClassInfo.size | 67 enum CLASSINFO_SIZE = (0x3C+12+4); // value of ClassInfo.size |
67 } else { | 68 } else { |
68 enum CLASSINFO_SIZE = (0x3C+12+4); // value of ClassInfo.size | 69 enum CLASSINFO_SIZE = (0x3C+12+4); // value of ClassInfo.size |
69 } | 70 } |
70 | 71 |
71 enum OFFSET_RUNTIME = 0x76543210; | 72 enum OFFSET_RUNTIME = 0x76543210; |
85 { | 86 { |
86 static __gshared ClassDeclaration object; | 87 static __gshared ClassDeclaration object; |
87 static __gshared ClassDeclaration classinfo; | 88 static __gshared ClassDeclaration classinfo; |
88 | 89 |
89 ClassDeclaration baseClass; // null only if this is Object | 90 ClassDeclaration baseClass; // null only if this is Object |
91 version(DMDV1) { | |
92 CtorDeclaration *ctor; | |
93 CtorDeclaration *defaultCtor; // default constructor | |
94 } | |
90 FuncDeclaration staticCtor; | 95 FuncDeclaration staticCtor; |
91 FuncDeclaration staticDtor; | 96 FuncDeclaration staticDtor; |
92 Array vtbl; // Array of FuncDeclaration's making up the vtbl[] | 97 Array vtbl; // Array of FuncDeclaration's making up the vtbl[] |
93 Array vtblFinal; // More FuncDeclaration's that aren't in vtbl[] | 98 Array vtblFinal; // More FuncDeclaration's that aren't in vtbl[] |
94 | 99 |
100 // (does not include baseClass) | 105 // (does not include baseClass) |
101 | 106 |
102 BaseClasses vtblInterfaces; // array of base interfaces that have | 107 BaseClasses vtblInterfaces; // array of base interfaces that have |
103 // their own vtbl[] | 108 // their own vtbl[] |
104 | 109 |
105 ClassInfoDeclaration vclassinfo; // the ClassInfo object for this ClassDeclaration | 110 TypeInfoClassDeclaration vclassinfo; // the ClassInfo object for this ClassDeclaration |
106 bool com; // true if this is a COM class (meaning | 111 bool com; // true if this is a COM class (meaning |
107 // it derives from IUnknown) | 112 // it derives from IUnknown) |
108 bool isauto; // true if this is an auto class | 113 bool isauto; // true if this is an auto class |
109 bool isabstract; // true if abstract class | 114 bool isabstract; // true if abstract class |
110 | 115 version(DMDV1) { |
116 int isnested; // !=0 if is nested | |
117 } | |
111 int inuse; // to prevent recursive attempts | 118 int inuse; // to prevent recursive attempts |
112 | 119 |
113 this(Loc loc, Identifier id, BaseClasses baseclasses) | 120 this(Loc loc, Identifier id, BaseClasses baseclasses) |
114 { | 121 { |
115 super(loc, id); | 122 super(loc, id); |
259 if (object) | 266 if (object) |
260 object.error("%s", msg); | 267 object.error("%s", msg); |
261 object = this; | 268 object = this; |
262 } | 269 } |
263 | 270 |
264 if (id is Id.ClassInfo) | 271 // if (id is Id.ClassInfo) |
272 if (id is Id.TypeInfo_Class) | |
265 { | 273 { |
266 if (classinfo) | 274 if (classinfo) |
267 classinfo.error("%s", msg); | 275 classinfo.error("%s", msg); |
268 classinfo = this; | 276 classinfo = this; |
269 } | 277 } |
375 if (tb.ty == TY.Ttuple) | 383 if (tb.ty == TY.Ttuple) |
376 { | 384 { |
377 TypeTuple tup = cast(TypeTuple)tb; | 385 TypeTuple tup = cast(TypeTuple)tb; |
378 enum PROT protection = b.protection; | 386 enum PROT protection = b.protection; |
379 baseclasses.remove(i); | 387 baseclasses.remove(i); |
380 size_t dim = Argument.dim(tup.arguments); | 388 size_t dim = Parameter.dim(tup.arguments); |
381 for (size_t j = 0; j < dim; j++) | 389 for (size_t j = 0; j < dim; j++) |
382 { | 390 { |
383 Argument arg = Argument.getNth(tup.arguments, j); | 391 auto arg = Parameter.getNth(tup.arguments, j); |
384 b = new BaseClass(arg.type, protection); | 392 b = new BaseClass(arg.type, protection); |
385 baseclasses.insert(i + j, b); | 393 baseclasses.insert(i + j, b); |
386 } | 394 } |
387 } | 395 } |
388 else | 396 else |
1010 vtblInterfaces.push(b); | 1018 vtblInterfaces.push(b); |
1011 b.copyBaseInterfaces(vtblInterfaces); | 1019 b.copyBaseInterfaces(vtblInterfaces); |
1012 } | 1020 } |
1013 } | 1021 } |
1014 | 1022 |
1023 version(DMDV1) | |
1024 { | |
1025 int isNested() | |
1026 { | |
1027 assert(false); | |
1028 } | |
1029 } | |
1015 bool isCOMclass() | 1030 bool isCOMclass() |
1016 { | 1031 { |
1017 return com; | 1032 return com; |
1018 } | 1033 } |
1019 | 1034 |
1276 | 1291 |
1277 ////////////////////////////////////////////// | 1292 ////////////////////////////////////////////// |
1278 | 1293 |
1279 // Put out the TypeInfo | 1294 // Put out the TypeInfo |
1280 type.getTypeInfo(null); | 1295 type.getTypeInfo(null); |
1281 type.vtinfo.toObjFile(multiobj); | 1296 //type.vtinfo.toObjFile(multiobj); |
1282 | 1297 |
1283 ////////////////////////////////////////////// | 1298 ////////////////////////////////////////////// |
1284 | 1299 |
1285 // Put out the ClassInfo | 1300 // Put out the ClassInfo |
1286 csym.Sclass = scclass; | 1301 csym.Sclass = scclass; |
1300 uint flags; | 1315 uint flags; |
1301 void *deallocator; | 1316 void *deallocator; |
1302 OffsetTypeInfo[] offTi; | 1317 OffsetTypeInfo[] offTi; |
1303 void *defaultConstructor; | 1318 void *defaultConstructor; |
1304 const(MemberInfo[]) function(string) xgetMembers; // module getMembers() function | 1319 const(MemberInfo[]) function(string) xgetMembers; // module getMembers() function |
1305 TypeInfo typeinfo; | 1320 //TypeInfo typeinfo; |
1306 } | 1321 } |
1307 */ | 1322 */ |
1308 dt_t* dt = null; | 1323 dt_t* dt = null; |
1309 offset = CLASSINFO_SIZE; // must be ClassInfo.size | 1324 offset = CLASSINFO_SIZE; // must be ClassInfo.size |
1310 if (classinfo) | 1325 if (classinfo) |
1413 dtxoff(&dt, sgetmembers.toSymbol(), 0, TYnptr); | 1428 dtxoff(&dt, sgetmembers.toSymbol(), 0, TYnptr); |
1414 else | 1429 else |
1415 dtdword(&dt, 0); // module getMembers() function | 1430 dtdword(&dt, 0); // module getMembers() function |
1416 } | 1431 } |
1417 | 1432 |
1418 dtxoff(&dt, type.vtinfo.toSymbol(), 0, TYnptr); // typeinfo | 1433 //dtxoff(&dt, type.vtinfo.toSymbol(), 0, TYnptr); // typeinfo |
1419 //dtdword(&dt, 0); | 1434 //dtdword(&dt, 0); |
1420 | 1435 |
1421 ////////////////////////////////////////////// | 1436 ////////////////////////////////////////////// |
1422 | 1437 |
1423 // Put out vtblInterfaces.data[]. Must immediately follow csym, because | 1438 // Put out vtblInterfaces.data[]. Must immediately follow csym, because |
1427 foreach (b; vtblInterfaces) | 1442 foreach (b; vtblInterfaces) |
1428 { | 1443 { |
1429 ClassDeclaration id = b.base; | 1444 ClassDeclaration id = b.base; |
1430 | 1445 |
1431 /* The layout is: | 1446 /* The layout is: |
1432 * { | 1447 * struct Interface |
1448 * { | |
1433 * ClassInfo *interface; | 1449 * ClassInfo *interface; |
1434 * void *[] vtbl; | 1450 * void *[] vtbl; |
1435 * unsigned offset; | 1451 * ptrdiff_t offset; |
1436 * } | 1452 * } |
1437 */ | 1453 */ |
1438 | 1454 |
1439 // Fill in vtbl[] | 1455 // Fill in vtbl[] |
1440 b.fillVtbl(this, b.vtbl, 1); | 1456 b.fillVtbl(this, b.vtbl, 1); |
1471 } | 1487 } |
1472 | 1488 |
1473 assert(id.vtbl.dim == b.vtbl.dim); | 1489 assert(id.vtbl.dim == b.vtbl.dim); |
1474 for (; j < id.vtbl.dim; j++) | 1490 for (; j < id.vtbl.dim; j++) |
1475 { | 1491 { |
1476 FuncDeclaration fd; | |
1477 | |
1478 assert(j < b.vtbl.dim); | 1492 assert(j < b.vtbl.dim); |
1479 static if (false) { | 1493 static if (false) { |
1480 Object o = cast(Object)b.vtbl.data[j]; | 1494 Object o = cast(Object)b.vtbl.data[j]; |
1481 if (o) | 1495 if (o) |
1482 { | 1496 { |
1484 assert(o.dyncast() == DYNCAST_DSYMBOL); | 1498 assert(o.dyncast() == DYNCAST_DSYMBOL); |
1485 Dsymbol s = cast(Dsymbol)o; | 1499 Dsymbol s = cast(Dsymbol)o; |
1486 printf("s.kind() = '%s'\n", s.kind()); | 1500 printf("s.kind() = '%s'\n", s.kind()); |
1487 } | 1501 } |
1488 } | 1502 } |
1489 fd = cast(FuncDeclaration)b.vtbl.data[j]; | 1503 auto fd = cast(FuncDeclaration)b.vtbl.data[j]; |
1490 if (fd) | 1504 if (fd) |
1491 dtxoff(&dt, fd.toThunkSymbol(b.offset), 0, TYnptr); | 1505 dtxoff(&dt, fd.toThunkSymbol(b.offset), 0, TYnptr); |
1492 else | 1506 else |
1493 dtdword(&dt, 0); | 1507 dtdword(&dt, 0); |
1494 } | 1508 } |
1633 { | 1647 { |
1634 if (global.params.warnings) | 1648 if (global.params.warnings) |
1635 { | 1649 { |
1636 TypeFunction tf = cast(TypeFunction)fd.type; | 1650 TypeFunction tf = cast(TypeFunction)fd.type; |
1637 if (tf.ty == Tfunction) | 1651 if (tf.ty == Tfunction) |
1638 warning("%s%s is hidden by %s\n", fd.toPrettyChars(), Argument.argsTypesToChars(tf.parameters, tf.varargs), toChars()); | 1652 warning("%s%s is hidden by %s\n", fd.toPrettyChars(), Parameter.argsTypesToChars(tf.parameters, tf.varargs), toChars()); |
1639 else | 1653 else |
1640 warning("%s is hidden by %s\n", fd.toPrettyChars(), toChars()); | 1654 warning("%s is hidden by %s\n", fd.toPrettyChars(), toChars()); |
1641 } | 1655 } |
1642 s = rtlsym[RTLSYM_DHIDDENFUNC]; | 1656 s = rtlsym[RTLSYM_DHIDDENFUNC]; |
1643 break; | 1657 break; |