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->contains(" +
37 ld.getSafeSymbol() + ", " +
38 rd.getSafeSymbol() + ");");
41 public void prettyPrint(PrettyPrinter pp) {
45 right.prettyPrint(pp);
46 pp.output("> in? " + relation.getSafeSymbol());
49 public TypeDescriptor typecheck(SemanticAnalyzer sa) {
50 TypeDescriptor ld = left.typecheck(sa);
51 TypeDescriptor rd = right.typecheck(sa);
53 if (ld == null || rd == null) {
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() + "'");
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() + "'");
73 this.td = ReservedTypeDescriptor.INT;