code clean up
[IRC.git] / Robust / src / IR / FieldDescriptor.java
index ce57b6276f4f0ba8a37caa4efbde56ecac87199e..2d5a7d5baa25703a0bd505225cd1851d9fcf07f1 100644 (file)
@@ -3,36 +3,108 @@ import IR.Tree.Modifiers;
 import IR.Tree.ExpressionNode;
 
 /**
- * Descriptor 
+ * Descriptor
  *
  * represents a symbol in the language (var name, function name, etc).
  */
 
 public class FieldDescriptor extends Descriptor {
 
-    protected Modifiers modifier;
-    protected TypeDescriptor td;
-    protected String identifier;
-    protected ExpressionNode en;
-    
-    public FieldDescriptor(Modifiers m, TypeDescriptor t, String identifier, ExpressionNode e) {
-       super(identifier);
-       this.modifier=m;
-       this.td=t;
-       this.identifier=identifier;
-       this.en=e;
-        this.safename = "__" + name + "__";
-       this.uniqueid=count++;
-    }
-
-    public TypeDescriptor getType() {
-       return td;
-    }
-
-    public String toString() {
-       if (en==null)
-           return modifier.toString()+td.toString()+" "+identifier+";";
-       else
-           return modifier.toString()+td.toString()+" "+identifier+"="+en.printNode(0)+";";
-    }
+  public static FieldDescriptor arrayLength=new FieldDescriptor(new Modifiers(Modifiers.PUBLIC|Modifiers.FINAL), new TypeDescriptor(TypeDescriptor.INT), "length", null, false);
+
+  protected Modifiers modifier;
+  protected TypeDescriptor td;
+  protected String identifier;
+  protected ExpressionNode en;
+  private boolean isglobal;
+  private boolean isenum;
+  private int enumvalue;
+
+  private ClassDescriptor cn;
+
+  public FieldDescriptor(Modifiers m, TypeDescriptor t, String identifier, ExpressionNode e, boolean isglobal) {
+    super(identifier);
+    this.modifier=m;
+    this.td=t;
+    this.en=e;
+    this.safename = "___" + name + "___";
+    this.uniqueid=count++;
+    this.isglobal=isglobal;
+    this.isenum = false;
+    this.enumvalue = -1;
+  }
+
+  public ClassDescriptor getClassDescriptor() {
+    return this.cn;
+  }
+
+  public void setClassDescriptor(ClassDescriptor cn) {
+    this.cn = cn;
+  }
+
+  public String getSafeSymbol() {
+    if (isStatic()) {
+      return cn.getSafeSymbol()+safename;
+    } else
+      return safename;
+  }
+
+  public boolean isEnum() {
+    return this.isenum;
+  }
+
+  public int enumValue() {
+    return this.enumvalue;
+  }
+
+  public void setAsEnum() {
+    this.isenum = true;
+  }
+
+  public void setEnumValue(int value) {
+    this.enumvalue = value;
+  }
+
+  public ExpressionNode getExpressionNode() {
+    return en;
+  }
+
+  public boolean isFinal() {
+    return modifier.isFinal();
+  }
+
+  public boolean isStatic() {
+    return modifier.isStatic();
+  }
+
+  public boolean isVolatile() {
+    return modifier.isVolatile();
+  }
+
+  public boolean isGlobal() {
+    return isglobal;
+  }
+
+  public TypeDescriptor getType() {
+    return td;
+  }
+
+  public void changeSafeSymbol(int id) {
+    safename+=id;
+  }
+
+  public String toString() {
+    if (en==null)
+      return modifier.toString()+td.toString()+" "+getSymbol()+";";
+    else
+      return modifier.toString()+td.toString()+" "+getSymbol()+"="+en.printNode(0)+";";
+  }
+
+  public String toStringBrief() {
+    return td.toPrettyString()+" "+getSymbol();
+  }
+
+  public String toPrettyStringBrief() {
+    return td.toPrettyString()+" "+getSymbol();
+  }
 }