5 public class RelationExpr extends Expr {
8 RelationDescriptor relation;
11 public RelationExpr(Expr expr, RelationDescriptor relation, boolean inverse) {
13 this.relation = relation;
14 this.inverse = inverse;
17 public Set getRequiredDescriptors() {
18 Set v = expr.getRequiredDescriptors();
23 public void generate(CodeWriter writer, VarDescriptor dest) {
24 VarDescriptor domain = VarDescriptor.makeNew("domain");
25 String found = (VarDescriptor.makeNew("found")).getSafeSymbol();
26 expr.generate(writer, domain);
27 writer.outputline(relation.getRange().getType().getGenerateType().getSafeSymbol() + " " + dest.getSafeSymbol() + ";");
28 writer.outputline("int " + found + " = " + relation.getSafeSymbol() + "_hash->get(" + domain.getSafeSymbol() + ", " + dest.getSafeSymbol() + ");");
29 writer.outputline("if (!" + found + ") { maybe = 1; }");
32 // #TBD#: don't think this method is needed (or even called/referenced)
34 public void generate_set(CodeWriter writer, VarDescriptor dest) {
35 VarDescriptor domain = VarDescriptor.makeNew("domain");
36 expr.generate(writer, domain);
37 writer.outputline(relation.getRange().getType().getGenerateType().getSafeSymbol() + " " + dest.getSafeSymbol() + " = " + relation.getSafeSymbol() + "_hash->get(" + domain.getSafeSymbol() + ");");
41 public void prettyPrint(PrettyPrinter pp) {
49 pp.output(relation.getSafeSymbol());
52 public TypeDescriptor typecheck(SemanticAnalyzer sa) {
54 TypeDescriptor type = expr.typecheck(sa);
60 /* check to make sure that the types of the relation match up */
62 TypeDescriptor rangetype = relation.getRange().getType();
64 if (rangetype != type) {
65 sa.getErrorReporter().report(null, "Type of left side of relation operator '.' is '" + type.getSymbol() +
66 "' but must be '" + rangetype.getSymbol() +
67 "', the type of the range of the relation '" + relation.getSymbol() + "'");
71 this.td = relation.getDomain().getType();
73 } else { /* not inverse */
74 TypeDescriptor domaintype = relation.getDomain().getType();
76 if (domaintype != type) {
77 sa.getErrorReporter().report(null, "Type of left side of relation operator '.' is '" + type.getSymbol() +
78 "' but must be '" + domaintype.getSymbol() +
79 "', the type of the domain of the relation '" + relation.getSymbol() + "'");
83 this.td = relation.getRange().getType();