5 public class ElementOfExpr extends Expr {
10 public ElementOfExpr(Expr element, SetDescriptor set) {
11 if (element == null || set == null) {
12 throw new NullPointerException();
15 this.element = element;
19 public Set getRequiredDescriptors() {
20 Set v = element.getRequiredDescriptors();
25 public void generate(CodeWriter writer, VarDescriptor dest) {
26 VarDescriptor ed = VarDescriptor.makeNew("element");
27 element.generate(writer, ed);
28 writer.outputline("int " + dest.getSafeSymbol() + " = " +
29 set.getSafeSymbol() + "_hash->contains(" + ed.getSafeSymbol() + ");");
32 public void prettyPrint(PrettyPrinter pp) {
33 element.prettyPrint(pp);
34 pp.output(" in? " + set.getSafeSymbol());
37 public TypeDescriptor typecheck(SemanticAnalyzer sa) {
38 TypeDescriptor td = element.typecheck(sa);
44 TypeDescriptor settype = set.getType();
46 if (!td.equals(settype)) {
47 sa.getErrorReporter().report(null, "Type mismatch: attempting to test for types '" + td.getSymbol() + "' in set of type '" + settype.getSymbol() + "'");
51 this.td = ReservedTypeDescriptor.INT;