Changeset 478
- Timestamp:
- 05/10/10 18:43:10 (15 years ago)
- Files:
-
- branches/dmd-1.x/src/expression.c (modified) (1 diff)
- branches/dmd-1.x/src/func.c (modified) (1 diff)
- branches/dmd-1.x/src/struct.c (modified) (1 diff)
- trunk/src/expression.c (modified) (2 diffs)
- trunk/src/func.c (modified) (1 diff)
- trunk/src/struct.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/dmd-1.x/src/expression.c
r473 r478 2263 2263 { 2264 2264 e = type->defaultInit(); 2265 2265 e->loc = loc; 2266 2266 return e; 2267 2267 } 2268 2268 } 2269 2269 e = new VarExp(loc, v); 2270 2270 e->type = type; 2271 2271 e = e->semantic(sc); 2272 2272 return e->deref(); 2273 2273 } 2274 2274 fld = s->isFuncLiteralDeclaration(); 2275 2275 if (fld) 2276 2276 { //printf("'%s' is a function literal\n", fld->toChars()); 2277 2277 e = new FuncExp(loc, fld); 2278 2278 return e->semantic(sc); 2279 2279 } 2280 2280 f = s->isFuncDeclaration(); 2281 2281 if (f) 2282 2282 { //printf("'%s' is a function\n", f->toChars()); 2283 2284 if (!f->originalType && f->scope) // semantic not yet run 2285 f->semantic(f->scope); 2283 2286 if (!f->type->deco) 2284 2287 { 2285 2288 error("forward reference to %s", toChars()); 2286 2289 return new ErrorExp(); 2287 2290 } 2288 2291 return new VarExp(loc, f); 2289 2292 } 2290 2293 cd = s->isClassDeclaration(); 2291 2294 if (cd && thiscd && cd->isBaseOf(thiscd, NULL) && sc->func->needThis()) 2292 2295 { 2293 2296 // We need to add an implicit 'this' if cd is this class or a base class. 2294 2297 DotTypeExp *dte; 2295 2298 2296 2299 dte = new DotTypeExp(loc, new ThisExp(loc), s); 2297 2300 return dte->semantic(sc); 2298 2301 } 2299 2302 imp = s->isImport(); 2300 2303 if (imp) 2301 2304 { 2302 2305 if (!imp->pkg) branches/dmd-1.x/src/func.c
r428 r478 116 116 #if 0 117 117 printf("FuncDeclaration::semantic(sc = %p, this = %p, '%s', linkage = %d)\n", sc, this, toPrettyChars(), sc->linkage); 118 118 if (isFuncLiteralDeclaration()) 119 119 printf("\tFuncLiteralDeclaration()\n"); 120 120 printf("sc->parent = %s, parent = %s\n", sc->parent->toChars(), parent ? parent->toChars() : ""); 121 121 printf("type: %p, %s\n", type, type->toChars()); 122 122 #endif 123 123 124 124 if (semanticRun != PASSinit && isFuncLiteralDeclaration()) 125 125 { 126 126 /* Member functions that have return types that are 127 127 * forward references can have semantic() run more than 128 128 * once on them. 129 129 * See test\interface2.d, test20 130 130 */ 131 131 return; 132 132 } 133 133 parent = sc->parent; 134 134 Dsymbol *parent = toParent(); 135 135 136 if (semanticRun == PASSsemanticdone)136 if (semanticRun >= PASSsemanticdone) 137 137 { 138 138 if (!parent->isClassDeclaration()) 139 139 return; 140 140 // need to re-run semantic() in order to set the class's vtbl[] 141 141 } 142 142 else 143 143 { 144 144 assert(semanticRun <= PASSsemantic); 145 145 semanticRun = PASSsemantic; 146 146 } 147 147 148 148 unsigned dprogress_save = Module::dprogress; 149 149 150 150 foverrides.setDim(0); // reset in case semantic() is being retried for this function 151 151 152 152 if (!type->deco) 153 153 { 154 154 type = type->semantic(loc, sc); 155 155 } 156 156 //type->print(); branches/dmd-1.x/src/struct.c
r428 r478 154 154 155 155 void AggregateDeclaration::addField(Scope *sc, VarDeclaration *v) 156 156 { 157 157 unsigned memsize; // size of member 158 158 unsigned memalignsize; // size of member for alignment purposes 159 159 unsigned xalign; // alignment boundaries 160 160 161 161 //printf("AggregateDeclaration::addField('%s') %s\n", v->toChars(), toChars()); 162 162 163 163 // Check for forward referenced types which will fail the size() call 164 164 Type *t = v->type->toBasetype(); 165 165 if (t->ty == Tstruct /*&& isStructDeclaration()*/) 166 166 { TypeStruct *ts = (TypeStruct *)t; 167 167 #if DMDV2 168 168 if (ts->sym == this) 169 169 { 170 170 error("cannot have field %s with same struct type", v->toChars()); 171 171 } 172 172 #endif 173 173 174 if (ts->sym->sizeok != 1 && ts->sym->scope) 175 ts->sym->semantic(NULL); 174 176 if (ts->sym->sizeok != 1) 175 177 { 176 178 sizeok = 2; // cannot finish; flag as forward referenced 177 179 return; 178 180 } 179 181 } 180 182 if (t->ty == Tident) 181 183 { 182 184 sizeok = 2; // cannot finish; flag as forward referenced 183 185 return; 184 186 } 185 187 186 188 memsize = v->type->size(loc); 187 189 memalignsize = v->type->alignsize(); 188 190 xalign = v->type->memalign(sc->structalign); 189 191 alignmember(xalign, memalignsize, &sc->offset); 190 192 v->offset = sc->offset; 191 193 sc->offset += memsize; 192 194 if (sc->offset > structsize) 193 195 structsize = sc->offset; trunk/src/expression.c
r477 r478 258 258 s = s->toParent()) 259 259 { FuncDeclaration *f = s->isFuncDeclaration(); 260 260 if (f->vthis) 261 261 { 262 262 //printf("rewriting e1 to %s's this\n", f->toChars()); 263 263 n++; 264 264 e1 = new VarExp(loc, f->vthis); 265 265 } 266 266 } 267 267 if (s && s->isClassDeclaration()) 268 268 { e1->type = s->isClassDeclaration()->type; 269 269 if (n > 1) 270 270 e1 = e1->semantic(sc); 271 271 } 272 272 else 273 273 e1 = e1->semantic(sc); 274 274 goto L1; 275 275 } 276 276 /* Can't find a path from e1 to ad 277 277 */ 278 printf("t->ty = %d\n", t->ty);279 278 e1->error("this for %s needs to be type %s not type %s", 280 279 var->toChars(), ad->toChars(), t->toChars()); 281 280 e1 = new ErrorExp(); 282 281 } 283 282 } 284 283 return e1; 285 284 } 286 285 287 286 /***************************************** 288 287 * Determine if 'this' is available. 289 288 * If it is, return the FuncDeclaration that has it. 290 289 */ 291 290 292 291 FuncDeclaration *hasThis(Scope *sc) 293 292 { FuncDeclaration *fd; 294 293 FuncDeclaration *fdthis; 295 294 296 295 //printf("hasThis()\n"); 297 296 fdthis = sc->parent->isFuncDeclaration(); 298 297 //printf("fdthis = %p, '%s'\n", fdthis, fdthis ? fdthis->toChars() : ""); … … 2428 2427 } 2429 2428 e = e->semantic(sc); 2430 2429 return e; 2431 2430 } 2432 2431 2433 2432 e = new VarExp(loc, v); 2434 2433 e->type = type; 2435 2434 e = e->semantic(sc); 2436 2435 return e->deref(); 2437 2436 } 2438 2437 fld = s->isFuncLiteralDeclaration(); 2439 2438 if (fld) 2440 2439 { //printf("'%s' is a function literal\n", fld->toChars()); 2441 2440 e = new FuncExp(loc, fld); 2442 2441 return e->semantic(sc); 2443 2442 } 2444 2443 f = s->isFuncDeclaration(); 2445 2444 if (f) 2446 2445 { //printf("'%s' is a function\n", f->toChars()); 2447 2446 2447 if (!f->originalType && f->scope) // semantic not yet run 2448 f->semantic(f->scope); 2448 2449 if (!f->type->deco) 2449 2450 { 2450 2451 error("forward reference to %s", toChars()); 2451 2452 return new ErrorExp(); 2452 2453 } 2453 2454 return new VarExp(loc, f, hasOverloads); 2454 2455 } 2455 2456 o = s->isOverloadSet(); 2456 2457 if (o) 2457 2458 { //printf("'%s' is an overload set\n", o->toChars()); 2458 2459 return new OverExp(o); 2459 2460 } 2460 2461 cd = s->isClassDeclaration(); 2461 2462 if (cd && thiscd && cd->isBaseOf(thiscd, NULL) && sc->func->needThis()) 2462 2463 { 2463 2464 // We need to add an implicit 'this' if cd is this class or a base class. 2464 2465 DotTypeExp *dte; 2465 2466 2466 2467 dte = new DotTypeExp(loc, new ThisExp(loc), s); 2467 2468 return dte->semantic(sc); trunk/src/func.c
r436 r478 117 117 printf("FuncDeclaration::semantic(sc = %p, this = %p, '%s', linkage = %d)\n", sc, this, toPrettyChars(), sc->linkage); 118 118 if (isFuncLiteralDeclaration()) 119 119 printf("\tFuncLiteralDeclaration()\n"); 120 120 printf("sc->parent = %s, parent = %s\n", sc->parent->toChars(), parent ? parent->toChars() : ""); 121 121 printf("type: %p, %s\n", type, type->toChars()); 122 122 #endif 123 123 124 124 if (semanticRun != PASSinit && isFuncLiteralDeclaration()) 125 125 { 126 126 /* Member functions that have return types that are 127 127 * forward references can have semantic() run more than 128 128 * once on them. 129 129 * See test\interface2.d, test20 130 130 */ 131 131 return; 132 132 } 133 133 134 134 parent = sc->parent; 135 135 Dsymbol *parent = toParent(); 136 136 137 if (semanticRun == PASSsemanticdone)137 if (semanticRun >= PASSsemanticdone) 138 138 { 139 139 if (!parent->isClassDeclaration()) 140 140 return; 141 141 // need to re-run semantic() in order to set the class's vtbl[] 142 142 } 143 143 else 144 144 { 145 145 assert(semanticRun <= PASSsemantic); 146 146 semanticRun = PASSsemantic; 147 147 } 148 148 149 149 unsigned dprogress_save = Module::dprogress; 150 150 151 151 foverrides.setDim(0); // reset in case semantic() is being retried for this function 152 152 153 153 storage_class |= sc->stc & ~STCref; 154 154 //printf("function storage_class = x%llx, sc->stc = x%llx, %x\n", storage_class, sc->stc, Declaration::isFinal()); 155 155 156 156 if (!originalType) 157 157 originalType = type; trunk/src/struct.c
r428 r478 162 162 unsigned xalign; // alignment boundaries 163 163 164 164 //printf("AggregateDeclaration::addField('%s') %s\n", v->toChars(), toChars()); 165 165 assert(!(v->storage_class & (STCstatic | STCextern | STCparameter | STCtls))); 166 166 167 167 // Check for forward referenced types which will fail the size() call 168 168 Type *t = v->type->toBasetype(); 169 169 if (v->storage_class & STCref) 170 170 { // References are the size of a pointer 171 171 t = Type::tvoidptr; 172 172 } 173 173 if (t->ty == Tstruct /*&& isStructDeclaration()*/) 174 174 { TypeStruct *ts = (TypeStruct *)t; 175 175 #if DMDV2 176 176 if (ts->sym == this) 177 177 { 178 178 error("cannot have field %s with same struct type", v->toChars()); 179 179 } 180 180 #endif 181 181 182 if (ts->sym->sizeok != 1 && ts->sym->scope) 183 ts->sym->semantic(NULL); 182 184 if (ts->sym->sizeok != 1) 183 185 { 184 186 sizeok = 2; // cannot finish; flag as forward referenced 185 187 return; 186 188 } 187 189 } 188 190 if (t->ty == Tident) 189 191 { 190 192 sizeok = 2; // cannot finish; flag as forward referenced 191 193 return; 192 194 } 193 195 194 196 memsize = t->size(loc); 195 197 memalignsize = t->alignsize(); 196 198 xalign = t->memalign(sc->structalign); 197 199 alignmember(xalign, memalignsize, &sc->offset); 198 200 v->offset = sc->offset; 199 201 sc->offset += memsize; 200 202 if (sc->offset > structsize) 201 203 structsize = sc->offset;
