Changeset 608
- Timestamp:
- 08/09/10 05:30:23 (14 years ago)
- Files:
-
- branches/dmd-1.x/src/declaration.c (modified) (1 diff)
- trunk/src/declaration.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/dmd-1.x/src/declaration.c
r607 r608 1304 1304 * rather than the current one. 1305 1305 */ 1306 1306 1307 1307 void VarDeclaration::checkNestedReference(Scope *sc, Loc loc) 1308 1308 { 1309 1309 //printf("VarDeclaration::checkNestedReference() %s\n", toChars()); 1310 1310 if (parent && !isDataseg() && parent != sc->parent) 1311 1311 { 1312 1312 // The function that this variable is in 1313 1313 FuncDeclaration *fdv = toParent()->isFuncDeclaration(); 1314 1314 // The current function 1315 1315 FuncDeclaration *fdthis = sc->parent->isFuncDeclaration(); 1316 1316 1317 1317 if (fdv && fdthis) 1318 1318 { 1319 1319 if (loc.filename) 1320 1320 fdthis->getLevel(loc, fdv); 1321 1321 nestedref = 1; 1322 1322 fdv->nestedFrameRef = 1; 1323 1323 //printf("var %s in function %s is nested ref\n", toChars(), fdv->toChars()); 1324 // __dollar creates problems because it isn't a real variable Bugzilla 3326 1325 if (ident == Id::dollar) 1326 ::error(loc, "cannnot use $ inside a function literal"); 1324 1327 } 1325 1328 } 1326 1329 } 1327 1330 1328 1331 /******************************* 1329 1332 * Does symbol go into data segment? 1330 1333 * Includes extern variables. 1331 1334 */ 1332 1335 1333 1336 int VarDeclaration::isDataseg() 1334 1337 { 1335 1338 #if 0 1336 1339 printf("VarDeclaration::isDataseg(%p, '%s')\n", this, toChars()); 1337 1340 printf("%llx, %p, %p\n", storage_class & (STCstatic | STCconst), parent->isModule(), parent->isTemplateInstance()); 1338 1341 printf("parent = '%s'\n", parent->toChars()); 1339 1342 #endif 1340 1343 Dsymbol *parent = this->toParent(); 1341 1344 if (!parent && !(storage_class & (STCstatic | STCconst))) 1342 1345 { error("forward referenced"); 1343 1346 type = Type::terror; trunk/src/declaration.c
r607 r608 1426 1426 for (int i = 0; i < nestedrefs.dim; i++) 1427 1427 { FuncDeclaration *f = (FuncDeclaration *)nestedrefs.data[i]; 1428 1428 if (f == fdthis) 1429 1429 goto L1; 1430 1430 } 1431 1431 nestedrefs.push(fdthis); 1432 1432 L1: ; 1433 1433 1434 1434 1435 1435 for (int i = 0; i < fdv->closureVars.dim; i++) 1436 1436 { Dsymbol *s = (Dsymbol *)fdv->closureVars.data[i]; 1437 1437 if (s == this) 1438 1438 goto L2; 1439 1439 } 1440 1440 1441 1441 fdv->closureVars.push(this); 1442 1442 L2: ; 1443 1443 1444 1444 //printf("fdthis is %s\n", fdthis->toChars()); 1445 1445 //printf("var %s in function %s is nested ref\n", toChars(), fdv->toChars()); 1446 // __dollar creates problems because it isn't a real variable Bugzilla 3326 1447 if (ident == Id::dollar) 1448 ::error(loc, "cannnot use $ inside a function literal"); 1446 1449 } 1447 1450 } 1448 1451 } 1449 1452 1450 1453 /**************************** 1451 1454 * Get ExpInitializer for a variable, if there is one. 1452 1455 */ 1453 1456 1454 1457 ExpInitializer *VarDeclaration::getExpInitializer() 1455 1458 { 1456 1459 ExpInitializer *ei; 1457 1460 1458 1461 if (init) 1459 1462 ei = init->isExpInitializer(); 1460 1463 else 1461 1464 { 1462 1465 Expression *e = type->defaultInit(loc); 1463 1466 if (e) 1464 1467 ei = new ExpInitializer(loc, e); 1465 1468 else
