test
[repair.git] / Repair / RepairCompiler / MCC / IR / TupleOfExpr.java
1 package MCC.IR;
2
3 import java.util.*;
4
5 public class TupleOfExpr extends Expr {
6
7     Expr left = null;
8     Expr right = null;
9     RelationDescriptor relation = null;
10
11     public TupleOfExpr(Expr left, Expr right, RelationDescriptor relation) {
12         if ((left == null) || (right == null) || (relation == null)) {
13             throw new NullPointerException();
14         }
15         
16         this.left = left;
17         this.right = right;
18         this.relation = relation;
19     }
20
21     public Set getRequiredDescriptors() {
22         Set v = left.getRequiredDescriptors();
23         v.addAll(right.getRequiredDescriptors());
24         v.add(relation);
25         return v;
26     }
27
28     public void generate(CodeWriter writer, VarDescriptor dest) {
29         VarDescriptor ld = VarDescriptor.makeNew();
30         left.generate(writer, ld);
31
32         VarDescriptor rd = VarDescriptor.makeNew();
33         right.generate(writer, rd);
34
35         writer.outputline("int " + dest.getSafeSymbol() + " = " + 
36                           relation.getSafeSymbol() + "_hash->contains(" + 
37                           ld.getSafeSymbol() + ", " +
38                           rd.getSafeSymbol() + ");");
39     }
40
41     public void prettyPrint(PrettyPrinter pp) {
42         pp.output("<");
43         left.prettyPrint(pp);
44         pp.output(", ");
45         right.prettyPrint(pp);
46         pp.output("> in? " + relation.getSafeSymbol());
47     }
48
49     public TypeDescriptor typecheck(SemanticAnalyzer sa) {
50         TypeDescriptor ld = left.typecheck(sa);
51         TypeDescriptor rd = right.typecheck(sa);
52         
53         if (ld == null || rd == null) {
54             return null;
55         }
56
57         boolean ok = true;
58
59         if (ld != relation.getDomain().getType()) {
60             sa.getErrorReporter().report(null, "Type of left element '" + ld.getSymbol() + "' must match domain type '" + relation.getDomain().getType().getSymbol() + "'");
61             ok = false;
62         }
63
64         if (rd != relation.getRange().getType()) {
65             sa.getErrorReporter().report(null, "Type of right element '" + rd.getSymbol() + "' must match range type '" + relation.getRange().getType().getSymbol() + "'");
66             ok = false;
67         }
68
69         if (!ok) {
70             return null;
71         }
72
73         this.td = ReservedTypeDescriptor.INT;
74         return this.td;
75     }
76
77
78 }