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

package IR2;

//import Token;
import java.util.*;

public class Descriptor implements Walkable, Typed {
  protected String name;
  protected int declaration_line;
  protected int type;

  public Descriptor(String n, int t)  { 
      name = n; declaration_line = -1; type = t;
  }


  public Descriptor(String n, int t, int line) {
      name = n;
      type = t;
      declaration_line = line;
  }

  // Accessor for the declaration line 
  public int get_line() {
	return declaration_line;
  }

  // Accessor for the name
  public String get_name() {
	return name;
  }

  public String toString() {
	if (declaration_line != -1) {
	  return name + " (line " + declaration_line + ")";
	} else {
	  return name;
	}
  }

  public void set_type(int t) { type = t; }

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

  /* Walkable implementation. */
  public String node_name() {
	return "descriptor";
  }
  public Enumeration neighbors() {
	return new ShortEnumeration();
  }
    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;
    }
}
