/** {@inheritDoc} */
@Override
public SizzleType visit(final EmitStatement n, final SymbolTable argu) {
final String id = n.f1.f0.tokenImage;
final SizzleTable t = (SizzleTable) argu.get(id);
if (t == null)
throw new TypeException("emitting to undeclared table " + id);
if (n.f2.present()) {
final List<SizzleType> indices = new ArrayList<SizzleType>();
for (final Node node : n.f2.nodes)
indices.add(((NodeSequence) node).nodes.get(1).accept(this, argu));
if (indices.size() != t.countIndices())
throw new TypeException("incorrect number of indices for " + id);
for (int i = 0; i < t.countIndices(); i++)
if (!t.getIndex(i).assigns(indices.get(i)))
throw new TypeException("incorrect type " + indices.get(i) + " for index " + i);
} else if (t.countIndices() > 0)
throw new TypeException("indices missing from emit");
final SizzleType expression = n.f4.accept(this, argu);
if (!t.accepts(expression))
throw new TypeException("incorrect type " + expression + " for " + id + ":" + t);
if (n.f5.present()) {
if (t.getWeightType() == null)
throw new TypeException("unexpected weight specified by emit");
final SizzleType wtype = ((NodeSequence) n.f5.node).nodes.get(1).accept(this, argu);
if (!t.acceptsWeight(wtype))
throw new TypeException("incorrect type " + wtype + " for weight of " + id + ":" + t.getWeightType());
} else if (t.getWeightType() != null)
throw new TypeException("no weight specified by emit");
return null;
}