5 public class TupleOfExpr extends Expr {
9 RelationDescriptor relation = null;
11 public TupleOfExpr(Expr left, Expr right, RelationDescriptor relation) {
12 if ((left == null) || (right == null) || (relation == null)) {
13 throw new NullPointerException();
18 this.relation = relation;
21 public Set getRequiredDescriptors() {
22 Set v = left.getRequiredDescriptors();
23 v.addAll(right.getRequiredDescriptors());
28 public void generate(CodeWriter writer, VarDescriptor dest) {
29 VarDescriptor ld = VarDescriptor.makeNew();
30 left.generate(writer, ld);
32 VarDescriptor rd = VarDescriptor.makeNew();
33 right.generate(writer, rd);
35 writer.outputline("int " + dest.getSafeSymbol() + " = " +
36 relation.getSafeSymbol() + "_hash->get(" + ld.getSafeSymbol() +
37 ") == " + rd.getSafeSymbol() + ";");
40 public void prettyPrint(PrettyPrinter pp) {
44 right.prettyPrint(pp);
45 pp.output("> in? " + relation.getSafeSymbol());
48 public TypeDescriptor typecheck(SemanticAnalyzer sa) {
49 TypeDescriptor ld = left.typecheck(sa);
50 TypeDescriptor rd = right.typecheck(sa);
52 if (ld == null || rd == null) {
58 if (ld != relation.getDomain().getType()) {
59 sa.getErrorReporter().report(null, "Type of left element '" + ld.getSymbol() + "' must match domain type '" + relation.getDomain().getType().getSymbol() + "'");
63 if (rd != relation.getRange().getType()) {
64 sa.getErrorReporter().report(null, "Type of right element '" + rd.getSymbol() + "' must match range type '" + relation.getRange().getType().getSymbol() + "'");
72 this.td = ReservedTypeDescriptor.INT;