Fix a small bug about enumaration type: it should be able to recorgnize access patter...
[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   private boolean isEnumClass;
23
24   private ClassDescriptor cn;
25
26   public FieldDescriptor(Modifiers m, TypeDescriptor t, String identifier, ExpressionNode e, boolean isglobal) {
27     super(identifier);
28     this.modifier=m;
29     this.td=t;
30     this.en=e;
31     this.safename = "___" + name + "___";
32     this.uniqueid=count++;
33     this.isglobal=isglobal;
34     this.isenum = false;
35     this.enumvalue = -1;
36     this.isEnumClass = false;
37   }
38
39   public ClassDescriptor getClassDescriptor() {
40     return this.cn;
41   }
42
43   public void setClassDescriptor(ClassDescriptor cn) {
44     this.cn = cn;
45   }
46
47   public String getSafeSymbol() {
48     if (isStatic()) {
49       return cn.getSafeSymbol()+safename;
50     } else
51       return safename;
52   }
53
54   public boolean isEnum() {
55     return this.isenum;
56   }
57
58   public int enumValue() {
59     return this.enumvalue;
60   }
61
62   public void setAsEnum() {
63     this.isenum = true;
64   }
65
66   public void setEnumValue(int value) {
67     this.enumvalue = value;
68   }
69
70   public ExpressionNode getExpressionNode() {
71     return en;
72   }
73
74   public boolean isFinal() {
75     return modifier.isFinal();
76   }
77
78   public boolean isStatic() {
79     return modifier.isStatic();
80   }
81
82   public boolean isVolatile() {
83     return modifier.isVolatile();
84   }
85
86   public boolean isGlobal() {
87     return isglobal;
88   }
89
90   public TypeDescriptor getType() {
91     return td;
92   }
93
94   public void changeSafeSymbol(int id) {
95     safename+=id;
96   }
97
98   public String toString() {
99     if (en==null)
100       return modifier.toString()+td.toString()+" "+getSymbol()+";";
101     else
102       return modifier.toString()+td.toString()+" "+getSymbol()+"="+en.printNode(0)+";";
103   }
104
105   public String toStringBrief() {
106     return td.toPrettyString()+" "+getSymbol();
107   }
108
109   public String toPrettyStringBrief() {
110     return td.toPrettyString()+" "+getSymbol();
111   }
112   
113   public void setIsEnumClass() {
114     this.isEnumClass = true;
115   }
116
117   public boolean isEnumClass() {
118     return this.isEnumClass;
119   }
120
121 }