5 public class VarExpr extends Expr {
8 VarDescriptor vd = null;
9 boolean typechecked = false;
11 public Set freeVars() {
12 HashSet hs=new HashSet();
17 public VarExpr(String varname) {
18 this.varname = varname;
21 public VarExpr(VarDescriptor vd) {
23 varname=vd.getSymbol();
24 this.td = vd.getType();
27 public String name() {
31 public boolean usesDescriptor(Descriptor d) {
37 public boolean isNonNull() {
41 public boolean equals(Map remap, Expr e) {
42 if (e==null||!(e instanceof VarExpr))
44 VarExpr ve=(VarExpr)e;
46 throw new Error("Uninitialized VarDescriptor");
48 throw new Error("e has uninitialized VarDescriptor");
50 if (remap!=null&&remap.containsKey(nvd))
51 nvd=(VarDescriptor)remap.get(nvd);
57 public Set getInversedRelations() {
61 public Set getRequiredDescriptors() {
65 public VarDescriptor getVar() {
69 public void generate(CodeWriter writer, VarDescriptor dest) {
71 // #TBD#: bit of a hack, really should have been type checked properly
73 vd = (VarDescriptor) writer.getSymbolTable().get(varname);
75 assert vd.getType() != null;
76 this.td = vd.getType();
78 writer.outputline(vd.getType().getGenerateType().getSafeSymbol() + " " + dest.getSafeSymbol() +
79 " = (" + vd.getType().getGenerateType().getSafeSymbol() + ") " + vd.getSafeSymbol() + "; //varexpr");
82 public void prettyPrint(PrettyPrinter pp) {
86 public TypeDescriptor typecheck(SemanticAnalyzer sa) {
88 vd = (VarDescriptor) sa.getSymbolTable().get(varname);
91 System.out.println(varname);
92 sa.getErrorReporter().report(null, "Undefined variable '" + varname + "'");
96 assert vd.getType() != null;
98 this.td = vd.getType();