comparison dmd/ClassDeclaration.d @ 166:d8565fbd755c

Moved object and classinfo from ClassDeclaration to Global (as part of getting rid of the global state)
author korDen
date Thu, 30 Sep 2010 10:30:15 +0400
parents 80f4806ffa13
children e7769d53e750
comparison
equal deleted inserted replaced
165:25ede4f66bda 166:d8565fbd755c
69 enum CLASSINFO_SIZE = (0x3C+12+4); // value of ClassInfo.size 69 enum CLASSINFO_SIZE = (0x3C+12+4); // value of ClassInfo.size
70 } 70 }
71 71
72 enum OFFSET_RUNTIME = 0x76543210; 72 enum OFFSET_RUNTIME = 0x76543210;
73 73
74 struct Param 74 struct FuncDeclarationFinder
75 { 75 {
76 bool visit(FuncDeclaration fd2) 76 bool visit(FuncDeclaration fd2)
77 { 77 {
78 //printf("param = %p, fd = %p %s\n", param, fd, fd.toChars()); 78 //printf("param = %p, fd = %p %s\n", param, fd, fd.toChars());
79 return fd is fd2; 79 return fd is fd2;
82 FuncDeclaration fd; 82 FuncDeclaration fd;
83 } 83 }
84 84
85 class ClassDeclaration : AggregateDeclaration 85 class ClassDeclaration : AggregateDeclaration
86 { 86 {
87 static __gshared ClassDeclaration object;
88 static __gshared ClassDeclaration classinfo;
89
90 ClassDeclaration baseClass; // null only if this is Object 87 ClassDeclaration baseClass; // null only if this is Object
91 version(DMDV1) { 88 version(DMDV1) {
92 CtorDeclaration *ctor; 89 CtorDeclaration *ctor;
93 CtorDeclaration *defaultCtor; // default constructor 90 CtorDeclaration *defaultCtor; // default constructor
94 } 91 }
268 } 265 }
269 } 266 }
270 267
271 if (id is Id.Object_) 268 if (id is Id.Object_)
272 { 269 {
273 if (object) 270 if (global.object)
274 object.error("%s", msg); 271 global.object.error("%s", msg);
275 object = this; 272 global.object = this;
276 } 273 }
277 274
278 // if (id is Id.ClassInfo) 275 // if (id is Id.ClassInfo)
279 if (id is Id.TypeInfo_Class) 276 if (id is Id.TypeInfo_Class)
280 { 277 {
281 if (classinfo) 278 if (global.classinfo)
282 classinfo.error("%s", msg); 279 global.classinfo.error("%s", msg);
283 classinfo = this; 280 global.classinfo = this;
284 } 281 }
285 282
286 if (id is Id.ModuleInfo) 283 if (id is Id.ModuleInfo)
287 { 284 {
288 if (Module.moduleinfo) 285 if (Module.moduleinfo)
544 Type tbase = new TypeIdentifier(Loc(0), Id.Object_); 541 Type tbase = new TypeIdentifier(Loc(0), Id.Object_);
545 BaseClass b; 542 BaseClass b;
546 TypeClass tc; 543 TypeClass tc;
547 Type bt; 544 Type bt;
548 545
549 if (!object) 546 if (!global.object)
550 { 547 {
551 error("missing or corrupt object.d"); 548 error("missing or corrupt object.d");
552 fatal(); 549 fatal();
553 } 550 }
554 bt = tbase.semantic(loc, sc).toBasetype(); 551 bt = tbase.semantic(loc, sc).toBasetype();
961 * of fd.ident, null is returned. 958 * of fd.ident, null is returned.
962 */ 959 */
963 return false; 960 return false;
964 } 961 }
965 962
966 Param p; p.fd = fd; 963 FuncDeclarationFinder p; p.fd = fd;
967 964
968 s = s.toAlias(); 965 s = s.toAlias();
969 OverloadSet os = s.isOverloadSet(); 966 OverloadSet os = s.isOverloadSet();
970 if (os) 967 if (os)
971 { 968 {
1114 // ident is Id.Exception || 1111 // ident is Id.Exception ||
1115 ident is Id.TypeInfo_Struct || 1112 ident is Id.TypeInfo_Struct ||
1116 ident is Id.TypeInfo_Class || 1113 ident is Id.TypeInfo_Class ||
1117 ident is Id.TypeInfo_Typedef || 1114 ident is Id.TypeInfo_Typedef ||
1118 ident is Id.TypeInfo_Tuple || 1115 ident is Id.TypeInfo_Tuple ||
1119 this is object || 1116 this is global.object ||
1120 this is classinfo || 1117 this is global.classinfo ||
1121 this is Module.moduleinfo || 1118 this is Module.moduleinfo ||
1122 ident.toChars().startsWith("TypeInfo_") 1119 ident.toChars().startsWith("TypeInfo_")
1123 ) 1120 )
1124 { 1121 {
1125 parent = null; 1122 parent = null;
1343 //TypeInfo typeinfo; 1340 //TypeInfo typeinfo;
1344 } 1341 }
1345 */ 1342 */
1346 dt_t* dt = null; 1343 dt_t* dt = null;
1347 offset = CLASSINFO_SIZE; // must be ClassInfo.size 1344 offset = CLASSINFO_SIZE; // must be ClassInfo.size
1348 if (classinfo) 1345 if (global.classinfo)
1349 { 1346 {
1350 if (classinfo.structsize != CLASSINFO_SIZE) 1347 if (global.classinfo.structsize != CLASSINFO_SIZE)
1351 error("D compiler and phobos' object.d are mismatched"); 1348 error("D compiler and phobos' object.d are mismatched");
1352 } 1349
1353 1350 dtxoff(&dt, global.classinfo.toVtblSymbol(), 0, TYnptr); // vtbl for ClassInfo
1354 if (classinfo) 1351 }
1355 dtxoff(&dt, classinfo.toVtblSymbol(), 0, TYnptr); // vtbl for ClassInfo
1356 else 1352 else
1353 {
1357 dtdword(&dt, 0); // BUG: should be an assert() 1354 dtdword(&dt, 0); // BUG: should be an assert()
1355 }
1358 1356
1359 dtdword(&dt, 0); // monitor 1357 dtdword(&dt, 0); // monitor
1360 1358
1361 // initializer[] 1359 // initializer[]
1362 assert(structsize >= 8); 1360 assert(structsize >= 8);