comparison dmd/InterfaceDeclaration.d @ 176:fa9a71a9f5a8

Moved all the mutable globals to Global
author korDen
date Sun, 10 Oct 2010 05:22:45 +0400
parents d8565fbd755c
children e3afd1303184
comparison
equal deleted inserted replaced
175:94b6033c07f3 176:fa9a71a9f5a8
38 bool cpp; // true if this is a C++ interface 38 bool cpp; // true if this is a C++ interface
39 } 39 }
40 this(Loc loc, Identifier id, BaseClasses baseclasses) 40 this(Loc loc, Identifier id, BaseClasses baseclasses)
41 { 41 {
42 super(loc, id, baseclasses); 42 super(loc, id, baseclasses);
43 43
44 if (id is Id.IUnknown) // IUnknown is the root of all COM interfaces 44 if (id is Id.IUnknown) // IUnknown is the root of all COM interfaces
45 { 45 {
46 com = true; 46 com = true;
47 cpp = true; // IUnknown is also a C++ interface 47 cpp = true; // IUnknown is also a C++ interface
48 } 48 }
49 } 49 }
50 50
51 override Dsymbol syntaxCopy(Dsymbol s) 51 override Dsymbol syntaxCopy(Dsymbol s)
52 { 52 {
53 InterfaceDeclaration id; 53 InterfaceDeclaration id;
54 54
55 if (s) 55 if (s)
58 id = new InterfaceDeclaration(loc, ident, null); 58 id = new InterfaceDeclaration(loc, ident, null);
59 59
60 ClassDeclaration.syntaxCopy(id); 60 ClassDeclaration.syntaxCopy(id);
61 return id; 61 return id;
62 } 62 }
63 63
64 override void semantic(Scope sc) 64 override void semantic(Scope sc)
65 { 65 {
66 //printf("InterfaceDeclaration.semantic(%s), type = %p\n", toChars(), type); 66 //printf("InterfaceDeclaration.semantic(%s), type = %p\n", toChars(), type);
67 if (inuse) 67 if (inuse)
68 return; 68 return;
74 74
75 type = type.semantic(loc, sc); 75 type = type.semantic(loc, sc);
76 handle = type; 76 handle = type;
77 77
78 if (!members) // if forward reference 78 if (!members) // if forward reference
79 { 79 {
80 //printf("\tinterface '%s' is forward referenced\n", toChars()); 80 //printf("\tinterface '%s' is forward referenced\n", toChars());
81 return; 81 return;
82 } 82 }
83 if (symtab) // if already done 83 if (symtab) // if already done
84 { 84 {
85 if (!scope_) 85 if (!scope_)
86 return; 86 return;
87 } 87 }
88 else 88 else
89 symtab = new DsymbolTable(); 89 symtab = new DsymbolTable();
90 90
91 Scope scx = null; 91 Scope scx = null;
92 if (scope_) 92 if (scope_)
93 { 93 {
94 sc = scope_; 94 sc = scope_;
95 scx = scope_; // save so we don't make redundant copies 95 scx = scope_; // save so we don't make redundant copies
96 scope_ = null; 96 scope_ = null;
97 } 97 }
98 98
101 isdeprecated = true; 101 isdeprecated = true;
102 } 102 }
103 103
104 // Expand any tuples in baseclasses[] 104 // Expand any tuples in baseclasses[]
105 for (size_t i = 0; i < baseclasses.dim; ) 105 for (size_t i = 0; i < baseclasses.dim; )
106 { 106 {
107 auto b = baseclasses[0]; 107 auto b = baseclasses[0];
108 b.type = b.type.semantic(loc, sc); 108 b.type = b.type.semantic(loc, sc);
109 Type tb = b.type.toBasetype(); 109 Type tb = b.type.toBasetype();
110 110
111 if (tb.ty == TY.Ttuple) 111 if (tb.ty == TY.Ttuple)
126 if (!baseclasses.dim && sc.linkage == LINK.LINKcpp) 126 if (!baseclasses.dim && sc.linkage == LINK.LINKcpp)
127 cpp = 1; 127 cpp = 1;
128 128
129 // Check for errors, handle forward references 129 // Check for errors, handle forward references
130 for (size_t i = 0; i < baseclasses.dim; ) 130 for (size_t i = 0; i < baseclasses.dim; )
131 { 131 {
132 TypeClass tc; 132 TypeClass tc;
133 BaseClass b; 133 BaseClass b;
134 Type tb; 134 Type tb;
135 135
136 b = baseclasses[i]; 136 b = baseclasses[i];
162 error("circular inheritance of interface"); 162 error("circular inheritance of interface");
163 baseclasses.remove(i); 163 baseclasses.remove(i);
164 continue; 164 continue;
165 } 165 }
166 if (!b.base.symtab) 166 if (!b.base.symtab)
167 { 167 {
168 // Try to resolve forward reference 168 // Try to resolve forward reference
169 if (sc.mustsemantic && b.base.scope_) 169 if (sc.mustsemantic && b.base.scope_)
170 b.base.semantic(null); 170 b.base.semantic(null);
171 } 171 }
172 if (!b.base.symtab || b.base.scope_ || b.base.inuse) 172 if (!b.base.symtab || b.base.scope_ || b.base.inuse)
195 if (vtblOffset()) 195 if (vtblOffset())
196 vtbl.push(cast(void*)this); // leave room at vtbl[0] for classinfo 196 vtbl.push(cast(void*)this); // leave room at vtbl[0] for classinfo
197 197
198 // Cat together the vtbl[]'s from base interfaces 198 // Cat together the vtbl[]'s from base interfaces
199 for (size_t i = 0; i < interfaces_dim; i++) 199 for (size_t i = 0; i < interfaces_dim; i++)
200 { 200 {
201 BaseClass b = interfaces[i]; 201 BaseClass b = interfaces[i];
202 202
203 // Skip if b has already appeared 203 // Skip if b has already appeared
204 for (int k = 0; k < i; k++) 204 for (int k = 0; k < i; k++)
205 { 205 {
250 inuse--; 250 inuse--;
251 //members.print(); 251 //members.print();
252 sc.pop(); 252 sc.pop();
253 //printf("-InterfaceDeclaration.semantic(%s), type = %p\n", toChars(), type); 253 //printf("-InterfaceDeclaration.semantic(%s), type = %p\n", toChars(), type);
254 } 254 }
255 255
256 override bool isBaseOf(ClassDeclaration cd, int* poffset) 256 override bool isBaseOf(ClassDeclaration cd, int* poffset)
257 { 257 {
258 uint j; 258 uint j;
259 259
260 //printf("%s.InterfaceDeclaration.isBaseOf(cd = '%s')\n", toChars(), cd.toChars()); 260 //printf("%s.InterfaceDeclaration.isBaseOf(cd = '%s')\n", toChars(), cd.toChars());
266 //printf("\tbase %s\n", b.base.toChars()); 266 //printf("\tbase %s\n", b.base.toChars());
267 if (this == b.base) 267 if (this == b.base)
268 { 268 {
269 //printf("\tfound at offset %d\n", b.offset); 269 //printf("\tfound at offset %d\n", b.offset);
270 if (poffset) 270 if (poffset)
271 { 271 {
272 *poffset = b.offset; 272 *poffset = b.offset;
273 if (j && cd.isInterfaceDeclaration()) 273 if (j && cd.isInterfaceDeclaration())
274 *poffset = OFFSET_RUNTIME; 274 *poffset = OFFSET_RUNTIME;
275 } 275 }
276 return true; 276 return true;
277 } 277 }
278 if (isBaseOf(b, poffset)) 278 if (isBaseOf(b, poffset))
279 { 279 {
280 if (j && poffset && cd.isInterfaceDeclaration()) 280 if (j && poffset && cd.isInterfaceDeclaration())
281 *poffset = OFFSET_RUNTIME; 281 *poffset = OFFSET_RUNTIME;
282 return true; 282 return true;
283 } 283 }
284 } 284 }
288 288
289 if (poffset) 289 if (poffset)
290 *poffset = 0; 290 *poffset = 0;
291 return false; 291 return false;
292 } 292 }
293 293
294 bool isBaseOf(BaseClass bc, int* poffset) 294 bool isBaseOf(BaseClass bc, int* poffset)
295 { 295 {
296 //printf("%s.InterfaceDeclaration.isBaseOf(bc = '%s')\n", toChars(), bc.base.toChars()); 296 //printf("%s.InterfaceDeclaration.isBaseOf(bc = '%s')\n", toChars(), bc.base.toChars());
297 for (uint j = 0; j < bc.baseInterfaces.length; j++) 297 for (uint j = 0; j < bc.baseInterfaces.length; j++)
298 { 298 {
299 BaseClass b = bc.baseInterfaces[j]; 299 BaseClass b = bc.baseInterfaces[j];
300 300
301 if (this == b.base) 301 if (this == b.base)
302 { 302 {
303 if (poffset) 303 if (poffset)
304 { 304 {
305 *poffset = b.offset; 305 *poffset = b.offset;
306 if (j && bc.base.isInterfaceDeclaration()) 306 if (j && bc.base.isInterfaceDeclaration())
307 *poffset = OFFSET_RUNTIME; 307 *poffset = OFFSET_RUNTIME;
308 } 308 }
309 return true; 309 return true;
310 } 310 }
311 if (isBaseOf(b, poffset)) 311 if (isBaseOf(b, poffset))
312 { 312 {
313 if (j && poffset && bc.base.isInterfaceDeclaration()) 313 if (j && poffset && bc.base.isInterfaceDeclaration())
314 *poffset = OFFSET_RUNTIME; 314 *poffset = OFFSET_RUNTIME;
315 return true; 315 return true;
316 } 316 }
317 } 317 }
318 if (poffset) 318 if (poffset)
319 *poffset = 0; 319 *poffset = 0;
320 return false; 320 return false;
321 } 321 }
322 322
323 override string kind() 323 override string kind()
324 { 324 {
325 assert(false); 325 assert(false);
326 } 326 }
327 327
328 /**************************************** 328 /****************************************
329 * Determine if slot 0 of the vtbl[] is reserved for something else. 329 * Determine if slot 0 of the vtbl[] is reserved for something else.
330 * For class objects, yes, this is where the ClassInfo ptr goes. 330 * For class objects, yes, this is where the ClassInfo ptr goes.
331 * For COM interfaces, no. 331 * For COM interfaces, no.
332 * For non-COM interfaces, yes, this is where the Interface ptr goes. 332 * For non-COM interfaces, yes, this is where the Interface ptr goes.
335 { 335 {
336 if (isCOMinterface() || isCPPinterface()) 336 if (isCOMinterface() || isCPPinterface())
337 return 0; 337 return 0;
338 return 1; 338 return 1;
339 } 339 }
340 340
341 version (DMDV2) { 341 version (DMDV2) {
342 override bool isCPPinterface() 342 override bool isCPPinterface()
343 { 343 {
344 return cpp; 344 return cpp;
345 } 345 }
479 // Put out vtblInterfaces.data[]. Must immediately follow csym, because 479 // Put out vtblInterfaces.data[]. Must immediately follow csym, because
480 // of the fixup (*) 480 // of the fixup (*)
481 481
482 offset += vtblInterfaces.dim * (4 * PTRSIZE); 482 offset += vtblInterfaces.dim * (4 * PTRSIZE);
483 foreach (b; vtblInterfaces) 483 foreach (b; vtblInterfaces)
484 { 484 {
485 ClassDeclaration id = b.base; 485 ClassDeclaration id = b.base;
486 486
487 // ClassInfo 487 // ClassInfo
488 dtxoff(&dt, id.toSymbol(), 0, TYnptr); 488 dtxoff(&dt, id.toSymbol(), 0, TYnptr);
489 489
514 { 514 {
515 if (!csym) 515 if (!csym)
516 { 516 {
517 Symbol *s; 517 Symbol *s;
518 518
519 if (!scc) 519 s = toSymbolX("__Interface", SCextern, global.scc.Stype, "Z");
520 scc = fake_classsym(Id.ClassInfo);
521
522 s = toSymbolX("__Interface", SCextern, scc.Stype, "Z");
523 s.Sfl = FLextern; 520 s.Sfl = FLextern;
524 s.Sflags |= SFLnodebug; 521 s.Sflags |= SFLnodebug;
525 csym = s; 522 csym = s;
526 slist_add(s); 523 slist_add(s);
527 } 524 }