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 String name() {
22 return "<"+left.name()+","+right.name()+"> in "+relation.toString();
25 public boolean usesDescriptor(Descriptor d) {
29 return left.usesDescriptor(d)||right.usesDescriptor(d);
32 public boolean equals(Map remap, Expr e) {
33 if (e==null||!(e instanceof TupleOfExpr))
35 TupleOfExpr toe=(TupleOfExpr)e;
36 if (!left.equals(remap,toe.left))
38 if (!right.equals(remap,toe.right))
40 if (relation!=toe.relation)
45 public Set getRequiredDescriptors() {
46 Set v = left.getRequiredDescriptors();
47 v.addAll(right.getRequiredDescriptors());
52 public void generate(CodeWriter writer, VarDescriptor dest) {
53 VarDescriptor ld = VarDescriptor.makeNew();
54 left.generate(writer, ld);
56 VarDescriptor rd = VarDescriptor.makeNew();
57 right.generate(writer, rd);
59 writer.outputline("int " + dest.getSafeSymbol() + " = " +
60 relation.getSafeSymbol() + "_hash->contains(" +
61 ld.getSafeSymbol() + ", " +
62 rd.getSafeSymbol() + ");");
65 public void prettyPrint(PrettyPrinter pp) {
69 right.prettyPrint(pp);
70 pp.output("> in? " + relation.getSafeSymbol());
73 public TypeDescriptor typecheck(SemanticAnalyzer sa) {
74 TypeDescriptor ld = left.typecheck(sa);
75 TypeDescriptor rd = right.typecheck(sa);
77 if (ld == null || rd == null) {
83 if (ld != relation.getDomain().getType()) {
84 sa.getErrorReporter().report(null, "Type of left element '" + ld.getSymbol() + "' must match domain type '" + relation.getDomain().getType().getSymbol() + "'");
88 if (rd != relation.getRange().getType()) {
89 sa.getErrorReporter().report(null, "Type of right element '" + rd.getSymbol() + "' must match range type '" + relation.getRange().getType().getSymbol() + "'");
97 this.td = ReservedTypeDescriptor.INT;