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 Set useDescriptor(Descriptor d) {
27 HashSet newset=new HashSet();
30 newset.addAll(element.useDescriptor(d));
34 public String name() {
35 return element.name()+" in "+set.toString();
38 public boolean equals(Map remap, Expr e) {
39 if (e==null||!(e instanceof ElementOfExpr))
41 ElementOfExpr eoe=(ElementOfExpr)e;
44 if (!element.equals(remap,eoe.element))
49 public Set getRequiredDescriptors() {
50 Set v = element.getRequiredDescriptors();
55 public void generate(CodeWriter writer, VarDescriptor dest) {
56 VarDescriptor ed = VarDescriptor.makeNew("element");
57 element.generate(writer, ed);
58 writer.outputline("int " + dest.getSafeSymbol() + " = " +
59 set.getSafeSymbol() + "_hash->contains(" + ed.getSafeSymbol() + ");");
62 public void prettyPrint(PrettyPrinter pp) {
63 element.prettyPrint(pp);
64 pp.output(" in? " + set.getSafeSymbol());
67 public TypeDescriptor typecheck(SemanticAnalyzer sa) {
68 TypeDescriptor td = element.typecheck(sa);
74 TypeDescriptor settype = set.getType();
76 if (!td.equals(settype)) {
77 sa.getErrorReporter().report(null, "Type mismatch: attempting to test for types '" + td.getSymbol() + "' in set of type '" + settype.getSymbol() + "'");
81 this.td = ReservedTypeDescriptor.INT;