@@ -1303,8 +1303,16 @@ public void visit(final TypeDecl n, final SymbolTable env) {
1303
1303
/** {@inheritDoc} */
1304
1304
@ Override
1305
1305
public void visit (final ArrayType n , final SymbolTable env ) {
1306
- n .env = env ;
1307
- n .getValue ().accept (this , env );
1306
+ SymbolTable st ;
1307
+
1308
+ try {
1309
+ st = env .cloneNonLocals ();
1310
+ } catch (final IOException e ) {
1311
+ throw new RuntimeException (e .getClass ().getSimpleName () + " caught" , e );
1312
+ }
1313
+
1314
+ n .env = st ;
1315
+ n .getValue ().accept (this , st );
1308
1316
final BoaType t = n .getValue ().type ;
1309
1317
if (!(t instanceof BoaScalar ))
1310
1318
if (!(t instanceof BoaTuple ))
@@ -1340,23 +1348,39 @@ public void visit(final FunctionType n, final SymbolTable env) {
1340
1348
/** {@inheritDoc} */
1341
1349
@ Override
1342
1350
public void visit (final MapType n , final SymbolTable env ) {
1343
- n .env = env ;
1344
- n .getValue ().accept (this , env );
1345
- n .getIndex ().accept (this , env );
1351
+ SymbolTable st ;
1352
+
1353
+ try {
1354
+ st = env .cloneNonLocals ();
1355
+ } catch (final IOException e ) {
1356
+ throw new RuntimeException (e .getClass ().getSimpleName () + " caught" , e );
1357
+ }
1358
+
1359
+ n .env = st ;
1360
+ n .getValue ().accept (this , st );
1361
+ n .getIndex ().accept (this , st );
1346
1362
n .type = new BoaMap (n .getValue ().type , n .getIndex ().type );
1347
1363
}
1348
1364
1349
1365
/** {@inheritDoc} */
1350
1366
@ Override
1351
1367
public void visit (final OutputType n , final SymbolTable env ) {
1352
- n .env = env ;
1368
+ SymbolTable st ;
1369
+
1370
+ try {
1371
+ st = env .cloneNonLocals ();
1372
+ } catch (final IOException e ) {
1373
+ throw new RuntimeException (e .getClass ().getSimpleName () + " caught" , e );
1374
+ }
1375
+
1376
+ n .env = st ;
1353
1377
1354
1378
List <BoaScalar > indexTypes = null ;
1355
1379
if (n .getIndicesSize () > 0 ) {
1356
1380
indexTypes = new ArrayList <BoaScalar >();
1357
1381
1358
1382
for (final Component c : n .getIndices ()) {
1359
- c .accept (this , env );
1383
+ c .accept (this , st );
1360
1384
1361
1385
if (!(c .type instanceof BoaScalar ))
1362
1386
throw new TypeCheckException (c , "incorrect type '" + c .type + "' for index" );
@@ -1365,12 +1389,12 @@ public void visit(final OutputType n, final SymbolTable env) {
1365
1389
}
1366
1390
}
1367
1391
1368
- n .getType ().accept (this , env );
1392
+ n .getType ().accept (this , st );
1369
1393
final BoaType type = n .getType ().type ;
1370
1394
1371
1395
final AggregatorSpec annotation ;
1372
1396
try {
1373
- annotation = env .getAggregators (n .getId ().getToken (), type ).get (0 ).getAnnotation (AggregatorSpec .class );
1397
+ annotation = st .getAggregators (n .getId ().getToken (), type ).get (0 ).getAnnotation (AggregatorSpec .class );
1374
1398
} catch (final RuntimeException e ) {
1375
1399
throw new TypeCheckException (n , e .getMessage (), e );
1376
1400
}
@@ -1381,7 +1405,7 @@ public void visit(final OutputType n, final SymbolTable env) {
1381
1405
throw new TypeCheckException (n .getWeight (), "output aggregator '" + n .getId ().getToken () + "' does not expect a weight" );
1382
1406
1383
1407
final BoaType aweight = SymbolTable .getType (annotation .weightType ());
1384
- n .getWeight ().accept (this , env );
1408
+ n .getWeight ().accept (this , st );
1385
1409
tweight = (BoaScalar ) n .getWeight ().type ;
1386
1410
1387
1411
if (!aweight .assigns (tweight ))
@@ -1393,23 +1417,41 @@ public void visit(final OutputType n, final SymbolTable env) {
1393
1417
throw new TypeCheckException (n .getArgs (), "output aggregator '" + n .getId ().getToken () + "' takes no arguments" );
1394
1418
1395
1419
n .type = new BoaTable (type , indexTypes , tweight , annotation .canOmitWeight ());
1420
+
1421
+ n .env = env ;
1396
1422
env .set (n .getId ().getToken (), n .type );
1397
1423
n .getId ().accept (this , env );
1398
1424
}
1399
1425
1400
1426
/** {@inheritDoc} */
1401
1427
@ Override
1402
1428
public void visit (final StackType n , final SymbolTable env ) {
1403
- n .env = env ;
1404
- n .getValue ().accept (this , env );
1429
+ SymbolTable st ;
1430
+
1431
+ try {
1432
+ st = env .cloneNonLocals ();
1433
+ } catch (final IOException e ) {
1434
+ throw new RuntimeException (e .getClass ().getSimpleName () + " caught" , e );
1435
+ }
1436
+
1437
+ n .env = st ;
1438
+ n .getValue ().accept (this , st );
1405
1439
n .type = new BoaStack (n .getValue ().type );
1406
1440
}
1407
1441
1408
1442
/** {@inheritDoc} */
1409
1443
@ Override
1410
1444
public void visit (final SetType n , final SymbolTable env ) {
1411
- n .env = env ;
1412
- n .getValue ().accept (this , env );
1445
+ SymbolTable st ;
1446
+
1447
+ try {
1448
+ st = env .cloneNonLocals ();
1449
+ } catch (final IOException e ) {
1450
+ throw new RuntimeException (e .getClass ().getSimpleName () + " caught" , e );
1451
+ }
1452
+
1453
+ n .env = st ;
1454
+ n .getValue ().accept (this , st );
1413
1455
n .type = new BoaSet (n .getValue ().type );
1414
1456
}
1415
1457
0 commit comments