5 public class ElementOfExpr extends Expr {
10 public Set freeVars() {
11 return element.freeVars();
14 public ElementOfExpr(Expr element, SetDescriptor set) {
15 if (element == null || set == null) {
16 throw new NullPointerException();
18 this.element = element;
21 public boolean usesDescriptor(Descriptor d) {
24 return element.usesDescriptor(d);
26 public String name() {
27 return element.name()+" in "+set.toString();
30 public boolean equals(Map remap, Expr e) {
31 if (e==null||!(e instanceof ElementOfExpr))
33 ElementOfExpr eoe=(ElementOfExpr)e;
36 if (!element.equals(remap,eoe.element))
41 public Set getRequiredDescriptors() {
42 Set v = element.getRequiredDescriptors();
47 public void generate(CodeWriter writer, VarDescriptor dest) {
48 VarDescriptor ed = VarDescriptor.makeNew("element");
49 element.generate(writer, ed);
50 writer.outputline("int " + dest.getSafeSymbol() + " = " +
51 set.getSafeSymbol() + "_hash->contains(" + ed.getSafeSymbol() + ");");
54 public void prettyPrint(PrettyPrinter pp) {
55 element.prettyPrint(pp);
56 pp.output(" in? " + set.getSafeSymbol());
59 public TypeDescriptor typecheck(SemanticAnalyzer sa) {
60 TypeDescriptor td = element.typecheck(sa);
66 TypeDescriptor settype = set.getType();
68 if (!td.equals(settype)) {
69 sa.getErrorReporter().report(null, "Type mismatch: attempting to test for types '" + td.getSymbol() + "' in set of type '" + settype.getSymbol() + "'");
73 this.td = ReservedTypeDescriptor.INT;