Changeset 610
- Timestamp:
- 08/10/10 10:24:07 (14 years ago)
- Files:
-
- trunk/src/declaration.c (modified) (1 diff)
- trunk/src/func.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/declaration.c
r608 r610 1393 1393 (storage_class & STCstatic || parent->isModule())) 1394 1394 return TRUE; 1395 1395 return FALSE; 1396 1396 } 1397 1397 1398 1398 void VarDeclaration::checkCtorConstInit() 1399 1399 { 1400 1400 #if 0 /* doesn't work if more than one static ctor */ 1401 1401 if (ctorinit == 0 && isCtorinit() && !(storage_class & STCfield)) 1402 1402 error("missing initializer in static constructor for const variable"); 1403 1403 #endif 1404 1404 } 1405 1405 1406 1406 /************************************ 1407 1407 * Check to see if this variable is actually in an enclosing function 1408 1408 * rather than the current one. 1409 1409 */ 1410 1410 1411 1411 void VarDeclaration::checkNestedReference(Scope *sc, Loc loc) 1412 1412 { 1413 //printf("VarDeclaration::checkNestedReference() %s\n", toChars()); 1413 1414 if (parent && !isDataseg() && parent != sc->parent && 1414 1415 !(storage_class & STCmanifest)) 1415 1416 { 1416 1417 // The function that this variable is in 1417 1418 FuncDeclaration *fdv = toParent()->isFuncDeclaration(); 1418 1419 // The current function 1419 1420 FuncDeclaration *fdthis = sc->parent->isFuncDeclaration(); 1420 1421 1421 1422 if (fdv && fdthis && fdv != fdthis) 1422 1423 { 1423 1424 if (loc.filename) 1424 1425 fdthis->getLevel(loc, fdv); 1425 1426 1426 1427 for (int i = 0; i < nestedrefs.dim; i++) 1427 1428 { FuncDeclaration *f = (FuncDeclaration *)nestedrefs.data[i]; 1428 1429 if (f == fdthis) 1429 1430 goto L1; 1430 1431 } 1431 1432 nestedrefs.push(fdthis); 1432 1433 L1: ; trunk/src/func.c
r603 r610 1501 1501 1502 1502 fbody = new CompoundStatement(0, a); 1503 1503 #if DMDV2 1504 1504 /* Append destructor calls for parameters as finally blocks. 1505 1505 */ 1506 1506 if (parameters) 1507 1507 { for (size_t i = 0; i < parameters->dim; i++) 1508 1508 { 1509 1509 VarDeclaration *v = (VarDeclaration *)parameters->data[i]; 1510 1510 1511 1511 if (v->storage_class & (STCref | STCout)) 1512 1512 continue; 1513 1513 1514 1514 /* Don't do this for static arrays, since static 1515 1515 * arrays are called by reference. Remove this 1516 1516 * when we change them to call by value. 1517 1517 */ 1518 1518 if (v->type->toBasetype()->ty == Tsarray) 1519 1519 continue; 1520 1520 1521 Expression *e = v->callAutoDtor(sc );1521 Expression *e = v->callAutoDtor(sc2); 1522 1522 if (e) 1523 1523 { Statement *s = new ExpStatement(0, e); 1524 s = s->semantic(sc );1524 s = s->semantic(sc2); 1525 1525 if (fbody->blockExit() == BEfallthru) 1526 1526 fbody = new CompoundStatement(0, fbody, s); 1527 1527 else 1528 1528 fbody = new TryFinallyStatement(0, fbody, s); 1529 1529 } 1530 1530 } 1531 1531 } 1532 1532 #endif 1533 1533 1534 1534 #if 1 1535 1535 if (isSynchronized()) 1536 1536 { /* Wrap the entire function body in a synchronized statement 1537 1537 */ 1538 1538 ClassDeclaration *cd = parent->isClassDeclaration(); 1539 1539 if (cd) 1540 1540 { 1541 1541 #if TARGET_WINDOS 1542 1542 if (/*config.flags2 & CFG2seh &&*/ // always on for WINDOS 1543 1543 !isStatic() && !fbody->usesEH()) 1544 1544 { … … 2352 2352 * Error if this cannot call fd. 2353 2353 * Returns: 2354 2354 * 0 same level 2355 2355 * -1 increase nesting by 1 (fd is nested within 'this') 2356 2356 * >0 decrease nesting by number 2357 2357 */ 2358 2358 2359 2359 int FuncDeclaration::getLevel(Loc loc, FuncDeclaration *fd) 2360 2360 { int level; 2361 2361 Dsymbol *s; 2362 2362 Dsymbol *fdparent; 2363 2363 2364 2364 //printf("FuncDeclaration::getLevel(fd = '%s')\n", fd->toChars()); 2365 2365 fdparent = fd->toParent2(); 2366 2366 if (fdparent == this) 2367 2367 return -1; 2368 2368 s = this; 2369 2369 level = 0; 2370 2370 while (fd != s && fdparent != s->toParent2()) 2371 2371 { 2372 //printf("\ts = '%s'\n", s->toChars());2372 //printf("\ts = %s, '%s'\n", s->kind(), s->toChars()); 2373 2373 FuncDeclaration *thisfd = s->isFuncDeclaration(); 2374 2374 if (thisfd) 2375 2375 { if (!thisfd->isNested() && !thisfd->vthis) 2376 2376 goto Lerr; 2377 2377 } 2378 2378 else 2379 2379 { 2380 2380 AggregateDeclaration *thiscd = s->isAggregateDeclaration(); 2381 2381 if (thiscd) 2382 2382 { if (!thiscd->isNested()) 2383 2383 goto Lerr; 2384 2384 } 2385 2385 else 2386 2386 goto Lerr; 2387 2387 } 2388 2388 2389 2389 s = s->toParent2(); 2390 2390 assert(s); 2391 2391 level++; 2392 2392 } 2393 2393 return level; 2394 2394 2395 2395 Lerr: 2396 error(loc, "cannot access frame of function %s", fd->toChars()); 2396 error(loc, "cannot access frame of function %s", fd->toPrettyChars()); 2397 halt(); 2397 2398 return 1; 2398 2399 } 2399 2400 2400 2401 void FuncDeclaration::appendExp(Expression *e) 2401 2402 { Statement *s; 2402 2403 2403 2404 s = new ExpStatement(0, e); 2404 2405 appendState(s); 2405 2406 } 2406 2407 2407 2408 void FuncDeclaration::appendState(Statement *s) 2408 2409 { 2409 2410 if (!fbody) 2410 2411 fbody = s; 2411 2412 else 2412 2413 { 2413 2414 CompoundStatement *cs = fbody->isCompoundStatement(); 2414 2415 if (cs) 2415 2416 { 2416 2417 if (!cs->statements)
