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