Skip to content

Commit 8f280fc

Browse files
committed
fixes #155 - keeping component names used for documentation only out of the environment
1 parent ddc1529 commit 8f280fc

File tree

1 file changed

+56
-14
lines changed

1 file changed

+56
-14
lines changed

src/java/boa/compiler/visitors/TypeCheckingVisitor.java

Lines changed: 56 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1303,8 +1303,16 @@ public void visit(final TypeDecl n, final SymbolTable env) {
13031303
/** {@inheritDoc} */
13041304
@Override
13051305
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);
13081316
final BoaType t = n.getValue().type;
13091317
if (!(t instanceof BoaScalar))
13101318
if (!(t instanceof BoaTuple))
@@ -1340,23 +1348,39 @@ public void visit(final FunctionType n, final SymbolTable env) {
13401348
/** {@inheritDoc} */
13411349
@Override
13421350
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);
13461362
n.type = new BoaMap(n.getValue().type, n.getIndex().type);
13471363
}
13481364

13491365
/** {@inheritDoc} */
13501366
@Override
13511367
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;
13531377

13541378
List<BoaScalar> indexTypes = null;
13551379
if (n.getIndicesSize() > 0) {
13561380
indexTypes = new ArrayList<BoaScalar>();
13571381

13581382
for (final Component c : n.getIndices()) {
1359-
c.accept(this, env);
1383+
c.accept(this, st);
13601384

13611385
if (!(c.type instanceof BoaScalar))
13621386
throw new TypeCheckException(c, "incorrect type '" + c.type + "' for index");
@@ -1365,12 +1389,12 @@ public void visit(final OutputType n, final SymbolTable env) {
13651389
}
13661390
}
13671391

1368-
n.getType().accept(this, env);
1392+
n.getType().accept(this, st);
13691393
final BoaType type = n.getType().type;
13701394

13711395
final AggregatorSpec annotation;
13721396
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);
13741398
} catch (final RuntimeException e) {
13751399
throw new TypeCheckException(n, e.getMessage(), e);
13761400
}
@@ -1381,7 +1405,7 @@ public void visit(final OutputType n, final SymbolTable env) {
13811405
throw new TypeCheckException(n.getWeight(), "output aggregator '" + n.getId().getToken() + "' does not expect a weight");
13821406

13831407
final BoaType aweight = SymbolTable.getType(annotation.weightType());
1384-
n.getWeight().accept(this, env);
1408+
n.getWeight().accept(this, st);
13851409
tweight = (BoaScalar) n.getWeight().type;
13861410

13871411
if (!aweight.assigns(tweight))
@@ -1393,23 +1417,41 @@ public void visit(final OutputType n, final SymbolTable env) {
13931417
throw new TypeCheckException(n.getArgs(), "output aggregator '" + n.getId().getToken() + "' takes no arguments");
13941418

13951419
n.type = new BoaTable(type, indexTypes, tweight, annotation.canOmitWeight());
1420+
1421+
n.env = env;
13961422
env.set(n.getId().getToken(), n.type);
13971423
n.getId().accept(this, env);
13981424
}
13991425

14001426
/** {@inheritDoc} */
14011427
@Override
14021428
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);
14051439
n.type = new BoaStack(n.getValue().type);
14061440
}
14071441

14081442
/** {@inheritDoc} */
14091443
@Override
14101444
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);
14131455
n.type = new BoaSet(n.getValue().type);
14141456
}
14151457

0 commit comments

Comments
 (0)