return target;
}
public int translate(int level, Expr.Comprehension expr,
Environment environment, SpecFile file) {
Type type = expr.attribute(Attribute.Type.class).type;
int target = environment.allocate(type);
// first, translate all source expressions
int[] sources = new int[expr.sources.size()];
for (int i = 0; i != sources.length; ++i) {
Pair<Expr.Variable, Expr> p = expr.sources.get(i);
int operand = translate(level, p.second(), environment, file);
operand = coerceFromRef(level, p.second(), operand, environment);
sources[i] = operand;
}
// TODO: initialise result set
myOut(level, "Automaton.List t" + target + " = new Automaton.List();");
int startLevel = level;
// initialise result register if needed
switch (expr.cop) {
case NONE:
myOut(level, type2JavaType(type) + " r" + target + " = true;");
myOut(level, "outer:");
break;
case SOME:
myOut(level, type2JavaType(type) + " r" + target + " = false;");
myOut(level, "outer:");
break;
}
// second, generate all the for loops
for (int i = 0; i != sources.length; ++i) {
Pair<Expr.Variable, Expr> p = expr.sources.get(i);
Expr.Variable variable = p.first();
Expr source = p.second();
Type.Collection sourceType = (Type.Collection) source
.attribute(Attribute.Type.class).type;
Type elementType = variable.attribute(Attribute.Type.class).type;
int index = environment.allocate(elementType, variable.var);
myOut(level++, "for(int i" + index + "=0;i" + index + "<r"
+ sources[i] + ".size();i" + index + "++) {");
String rhs = "r" + sources[i] + ".get(i" + index + ")";
// FIXME: need a more general test for a reference type