5 public class TupleOfExpr extends Expr {
9 RelationDescriptor relation = null;
11 public Set freeVars() {
12 Set lset=left.freeVars();
13 Set rset=right.freeVars();
21 public TupleOfExpr(Expr left, Expr right, RelationDescriptor relation) {
22 if ((left == null) || (right == null) || (relation == null)) {
23 throw new NullPointerException();
28 this.relation = relation;
31 public String name() {
32 return "<"+left.name()+","+right.name()+"> in "+relation.toString();
35 public boolean usesDescriptor(Descriptor d) {
39 return left.usesDescriptor(d)||right.usesDescriptor(d);
42 public boolean equals(Map remap, Expr e) {
43 if (e==null||!(e instanceof TupleOfExpr))
45 TupleOfExpr toe=(TupleOfExpr)e;
46 if (!left.equals(remap,toe.left))
48 if (!right.equals(remap,toe.right))
50 if (relation!=toe.relation)
55 public Set getRequiredDescriptors() {
56 Set v = left.getRequiredDescriptors();
57 v.addAll(right.getRequiredDescriptors());
62 public void generate(CodeWriter writer, VarDescriptor dest) {
63 VarDescriptor ld = VarDescriptor.makeNew();
64 left.generate(writer, ld);
66 VarDescriptor rd = VarDescriptor.makeNew();
67 right.generate(writer, rd);
69 writer.outputline("int " + dest.getSafeSymbol() + " = " +
70 relation.getSafeSymbol() + "_hash->contains(" +
71 ld.getSafeSymbol() + ", " +
72 rd.getSafeSymbol() + ");");
75 public void prettyPrint(PrettyPrinter pp) {
79 right.prettyPrint(pp);
80 pp.output("> in? " + relation.getSafeSymbol());
83 public TypeDescriptor typecheck(SemanticAnalyzer sa) {
84 TypeDescriptor ld = left.typecheck(sa);
85 TypeDescriptor rd = right.typecheck(sa);
87 if (ld == null || rd == null) {
93 if (ld != relation.getDomain().getType()) {
94 sa.getErrorReporter().report(null, "Type of left element '" + ld.getSymbol() + "' must match domain type '" + relation.getDomain().getType().getSymbol() + "'");
98 if (rd != relation.getRange().getType()) {
99 sa.getErrorReporter().report(null, "Type of right element '" + rd.getSymbol() + "' must match range type '" + relation.getRange().getType().getSymbol() + "'");
107 this.td = ReservedTypeDescriptor.INT;