}
public String name() {
- return "sum("+sd.getSafeSymbol()+"."+rd.getSafeSymbol()+")";
+ return "sum("+sd.toString()+"."+rd.toString()+")";
}
public boolean equals(Map remap, Expr e) {
}
public Descriptor getDescriptor() {
- throw new Error();
+ throw new Error("Sum shouldn't appear on left hand side!");
}
public boolean inverted() {
}
public void generate(CodeWriter writer, VarDescriptor dest) {
- throw new Error();
+ writer.addDeclaration("int",dest.getSafeSymbol());
+ writer.outputline(dest.getSafeSymbol()+"=0;");
+
+
+ VarDescriptor itvd=VarDescriptor.makeNew("iterator");
+ writer.addDeclaration("struct SimpleIterator",itvd.getSafeSymbol());
+ writer.outputline("SimpleHashiterator("+sd.getSafeSymbol()+"_hash , &"+itvd.getSafeSymbol()+");");
+ writer.outputline("while (hasNext(&"+itvd.getSafeSymbol()+")) {");
+ VarDescriptor keyvd=VarDescriptor.makeNew("key");
+ writer.addDeclaration("int",keyvd.getSafeSymbol());
+ writer.outputline(keyvd.getSafeSymbol()+"=next(&"+itvd.getSafeSymbol()+");");
+ VarDescriptor tmpvar=VarDescriptor.makeNew("tmp");
+ writer.addDeclaration("int",tmpvar.getSafeSymbol());
+ writer.outputline("SimpleHashget("+rd.getSafeSymbol()+"_hash, "+keyvd.getSafeSymbol()+", &"+tmpvar.getSafeSymbol()+");");
+ writer.outputline(dest.getSafeSymbol()+"+="+tmpvar.getSafeSymbol()+";");
+ writer.outputline("}");
}
public void prettyPrint(PrettyPrinter pp) {
pp.output("sum(");
- pp.output(sd.getSafeSymbol());
+ pp.output(sd.toString());
pp.output(".");
- pp.output(rd.getSafeSymbol());
+ pp.output(rd.toString());
pp.output(")");
}