// ** This class was generated with DemFGen (vers:09/27/2009)

package gen;

import edu.neu.ccs.demeterf.lib.*;
import edu.neu.ccs.demeterf.*;
import edu.neu.ccs.demeterf.lib.*;




/** Representation of Def */
public class Def extends Exp{
    protected final ident id;
    protected final Exp e;
    protected final Exp body;

    /** Construct a(n) Def Instance */
    public Def(ident id, Exp e, Exp body){
        this.id = id;
        this.e = e;
        this.body = body;
    }
    /** Is the given object Equal to this Def? */
    public boolean equals(Object o){
        if(!(o instanceof Def))return false;
        if(o == this)return true;
        Def oo = (Def)o;
        return (((Object)id).equals(oo.id))&&(((Object)e).equals(oo.e))&&(((Object)body).equals(oo.body));
    }
    /** Parse an instance of Def from the given String */
    public static Def parse(String inpt) throws ParseException{
        return new TheParser(new java.io.StringReader(inpt)).parse_Def();
    }
    /** Parse an instance of Def from the given Stream */
    public static Def parse(java.io.InputStream inpt) throws ParseException{
        return new TheParser(inpt).parse_Def();
    }
    /** Parse an instance of Def from the given Reader */
    public static Def parse(java.io.Reader inpt) throws ParseException{
        return new TheParser(inpt).parse_Def();
    }

    /** Field Class for Def.id */
    public static class id extends edu.neu.ccs.demeterf.control.Fields.any{}
    /** Field Class for Def.e */
    public static class e extends edu.neu.ccs.demeterf.control.Fields.any{}
    /** Field Class for Def.body */
    public static class body extends edu.neu.ccs.demeterf.control.Fields.any{}

    public int eval(Env ev){ return body.eval(ev.extend(id, e.eval(ev))); }
    public List<Op> compile(List<ident> env){
        return e.compile(env)
            .append(new Define())
            .append(body.compile(env.push(id)))
            .append(new Undef());
    }
    public <X> X accept(Vis<X> v){ return v.visit(this); }
    public Exp simplify(){
        Exp ee = e.simplify(),
            b = body.simplify();
        if(b.isNum())return b;
        return new Def(id,ee,b);
    }
    public int maxEnv(){ return Math.max(e.maxEnv(),1+body.maxEnv()); }
 
    /** DGP method from Class Print */
    public String print(){ return gen.Print.PrintM(this); }
    /** Getter for field Def.body */
    public Exp getBody(){ return body; }
    /** Getter for field Def.e */
    public Exp getE(){ return e; }
    /** Getter for field Def.id */
    public ident getId(){ return id; }

}