Add support for Enum type for mgc version and also add default constructor. Comment...
[IRC.git] / Robust / src / IR / FieldDescriptor.java
1 package IR;
2 import IR.Tree.Modifiers;
3 import IR.Tree.ExpressionNode;
4
5 /**
6  * Descriptor
7  *
8  * represents a symbol in the language (var name, function name, etc).
9  */
10
11 public class FieldDescriptor extends Descriptor {
12
13   public static FieldDescriptor arrayLength=new FieldDescriptor(new Modifiers(Modifiers.PUBLIC|Modifiers.FINAL), new TypeDescriptor(TypeDescriptor.INT), "length", null, false);
14
15   protected Modifiers modifier;
16   protected TypeDescriptor td;
17   protected String identifier;
18   protected ExpressionNode en;
19   private boolean isglobal;
20   private boolean isenum;
21   private int enumvalue;
22
23   public FieldDescriptor(Modifiers m, TypeDescriptor t, String identifier, ExpressionNode e, boolean isglobal) {
24     super(identifier);
25     this.modifier=m;
26     this.td=t;
27     this.en=e;
28     this.safename = "___" + name + "___";
29     this.uniqueid=count++;
30     this.isglobal=isglobal;
31     this.isenum = false;
32     this.enumvalue = -1;
33   }
34   
35   public boolean isEnum() {
36     return this.isenum;
37   }
38   
39   public int enumValue() {
40     return this.enumvalue;
41   }
42   
43   public void setAsEnum() {
44     this.isenum = true;
45   }
46   
47   public void setEnumValue(int value) {
48     this.enumvalue = value;
49   }
50
51   public ExpressionNode getExpressionNode(){
52       return en;
53   }
54
55   public boolean isStatic() {
56     return modifier.isStatic();
57   }
58   
59   public boolean isVolatile() {
60     return modifier.isVolatile();
61   }
62   
63   public boolean isGlobal() {
64     return isglobal;
65   }
66
67   public TypeDescriptor getType() {
68     return td;
69   }
70
71   public String toString() {
72     if (en==null)
73       return modifier.toString()+td.toString()+" "+getSymbol()+";";
74     else
75       return modifier.toString()+td.toString()+" "+getSymbol()+"="+en.printNode(0)+";";
76   }
77
78   public String toStringBrief() {
79     return td.toString()+" "+getSymbol();
80   }
81
82   public String toPrettyStringBrief() {
83     return td.toPrettyString()+" "+getSymbol();
84   }
85 }