// $Id: ScalarVarExpr.java,v 1.1.1.1 1999/12/05 22:19:52 mpp Exp $

package IR2;

import java.util.*;

public class ScalarVarExpr extends LValue {
  protected ScalarVarDescriptor var;

  public ScalarVarExpr(ScalarVarDescriptor v) {
	var = v;
  }

  /* Typed implementation. */
  public int get_type() { return var.get_type(); }

  /* [RL]Value implementation. */
  public DelocalizedRValue generate_rvalue_asm
    (MethodDescriptor d, Codegen c, CFG output) {
    return var;
  }
  void generate_lvalue_asm(MethodDescriptor d,
                           Codegen c,
                           CFG output, 
                           DelocalizedRValue s) {
	output.addElement(new DelocalizedStoreInstruction(var, s));
  }

  /* Walkable implementation. */
  public String node_name() {
	return "scalar_var_expr";
  }
  public Enumeration neighbors() {
	return new ShortEnumeration(var);
  }
  public String pretty_print(int indent, boolean recursive) {
	String output = new String();

	for (int i = 0; i < indent; i++) output += " ";
	if (recursive) {
	  indent += 2;
	  output += "(" + this.node_name() + "\n";
	  /* stuff - calls to prettyprints of internals of this node*/
	  for (Enumeration e = this.neighbors(); e.hasMoreElements();) {
		Walkable foo = (Walkable)e.nextElement();
		if (foo == null) 
		  output += "-error-";
		else
		  output += foo.pretty_print(indent, true);
	  }
	  for (int i = 0; i < indent; i++) output += " ";
	  output += ") /* "+ this.node_name() + " */\n";
	} else {
	  output += "(" + this.node_name() + ")\n";
	}
	return output;
  }
}
