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 Set useDescriptor(Descriptor d) {
43 HashSet newset=new HashSet();
46 newset.addAll(left.useDescriptor(d));
47 newset.addAll(right.useDescriptor(d));
51 public boolean equals(Map remap, Expr e) {
52 if (e==null||!(e instanceof TupleOfExpr))
54 TupleOfExpr toe=(TupleOfExpr)e;
55 if (!left.equals(remap,toe.left))
57 if (!right.equals(remap,toe.right))
59 if (relation!=toe.relation)
64 public Set getRequiredDescriptors() {
65 Set v = left.getRequiredDescriptors();
66 v.addAll(right.getRequiredDescriptors());
71 public void generate(CodeWriter writer, VarDescriptor dest) {
72 VarDescriptor ld = VarDescriptor.makeNew();
73 left.generate(writer, ld);
75 VarDescriptor rd = VarDescriptor.makeNew();
76 right.generate(writer, rd);
78 writer.outputline("int " + dest.getSafeSymbol() + " = " +
79 relation.getSafeSymbol() + "_hash->contains(" +
80 ld.getSafeSymbol() + ", " +
81 rd.getSafeSymbol() + ");");
84 public void prettyPrint(PrettyPrinter pp) {
88 right.prettyPrint(pp);
89 pp.output("> in? " + relation.getSafeSymbol());
92 public TypeDescriptor typecheck(SemanticAnalyzer sa) {
93 TypeDescriptor ld = left.typecheck(sa);
94 TypeDescriptor rd = right.typecheck(sa);
96 if (ld == null || rd == null) {
102 if (ld != relation.getDomain().getType()) {
103 sa.getErrorReporter().report(null, "Type of left element '" + ld.getSymbol() + "' must match domain type '" + relation.getDomain().getType().getSymbol() + "'");
107 if (rd != relation.getRange().getType()) {
108 sa.getErrorReporter().report(null, "Type of right element '" + rd.getSymbol() + "' must match range type '" + relation.getRange().getType().getSymbol() + "'");
116 this.td = ReservedTypeDescriptor.INT;