Fix a shadow field related bug in the compiler. Defined in Java language specificatio...
[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   private ClassDescriptor cn;
24
25   public FieldDescriptor(Modifiers m, TypeDescriptor t, String identifier, ExpressionNode e, boolean isglobal) {
26     super(identifier);
27     this.modifier=m;
28     this.td=t;
29     this.en=e;
30     this.safename = "___" + name + "___";
31     this.uniqueid=count++;
32     this.isglobal=isglobal;
33     this.isenum = false;
34     this.enumvalue = -1;
35   }
36   
37   public ClassDescriptor getClassDescriptor() {
38     return this.cn;
39   }
40   
41   public void setClassDescriptor(ClassDescriptor cn) {
42     this.cn = cn;
43   }
44   
45   public boolean isEnum() {
46     return this.isenum;
47   }
48   
49   public int enumValue() {
50     return this.enumvalue;
51   }
52   
53   public void setAsEnum() {
54     this.isenum = true;
55   }
56   
57   public void setEnumValue(int value) {
58     this.enumvalue = value;
59   }
60
61   public ExpressionNode getExpressionNode(){
62       return en;
63   }
64
65   public boolean isFinal() {
66     return modifier.isFinal();
67   }
68   
69   public boolean isStatic() {
70     return modifier.isStatic();
71   }
72   
73   public boolean isVolatile() {
74     return modifier.isVolatile();
75   }
76   
77   public boolean isGlobal() {
78     return isglobal;
79   }
80
81   public TypeDescriptor getType() {
82     return td;
83   }
84
85   public String toString() {
86     if (en==null)
87       return modifier.toString()+td.toString()+" "+getSymbol()+";";
88     else
89       return modifier.toString()+td.toString()+" "+getSymbol()+"="+en.printNode(0)+";";
90   }
91
92   public String toStringBrief() {
93     return td.toString()+" "+getSymbol();
94   }
95
96   public String toPrettyStringBrief() {
97     return td.toPrettyString()+" "+getSymbol();
98   }
99 }