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 expr.generate(writer, domain);
26 writer.outputline(relation.getRange().getType().getSafeSymbol() + " " + dest.getSymbol() + " = " + relation.getSafeSymbol() + "_hash->get(" + domain.getSafeSymbol() + ");");
29 public void generate_set(CodeWriter writer, VarDescriptor dest) {
30 VarDescriptor domain = VarDescriptor.makeNew("domain");
31 expr.generate(writer, domain);
32 writer.outputline(relation.getRange().getType().getSafeSymbol() + " " + dest.getSymbol() + " = " + relation.getSafeSymbol() + "_hash->get(" + domain.getSafeSymbol() + ");");
35 public void prettyPrint(PrettyPrinter pp) {
43 pp.output(relation.getSafeSymbol());
46 public TypeDescriptor typecheck(SemanticAnalyzer sa) {
48 TypeDescriptor type = expr.typecheck(sa);
54 /* check to make sure that the types of the relation match up */
56 TypeDescriptor rangetype = relation.getRange().getType();
58 if (rangetype != type) {
59 sa.getErrorReporter().report(null, "Type of left side of relation operator '.' is '" + type.getSymbol() +
60 "' but must be the '" + rangetype.getSymbol() +
61 "', the type of the range of the relation '" + relation.getSymbol() + "'");
65 this.td = relation.getDomain().getType();
67 } else { /* not inverse */
68 TypeDescriptor domaintype = relation.getDomain().getType();
70 if (domaintype != type) {
71 sa.getErrorReporter().report(null, "Type of left side of relation operator '.' is '" + type.getSymbol() +
72 "' but must be the '" + domaintype.getSymbol() +
73 "', the type of the range of the relation '" + relation.getSymbol() + "'");
77 this.td = relation.getRange().getType();