Fix the bug of assignment conversion: 'short s = 12' should be allowed. And for such...
[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 isFinal() {
56     return modifier.isFinal();
57   }
58   
59   public boolean isStatic() {
60     return modifier.isStatic();
61   }
62   
63   public boolean isVolatile() {
64     return modifier.isVolatile();
65   }
66   
67   public boolean isGlobal() {
68     return isglobal;
69   }
70
71   public TypeDescriptor getType() {
72     return td;
73   }
74
75   public String toString() {
76     if (en==null)
77       return modifier.toString()+td.toString()+" "+getSymbol()+";";
78     else
79       return modifier.toString()+td.toString()+" "+getSymbol()+"="+en.printNode(0)+";";
80   }
81
82   public String toStringBrief() {
83     return td.toString()+" "+getSymbol();
84   }
85
86   public String toPrettyStringBrief() {
87     return td.toPrettyString()+" "+getSymbol();
88   }
89 }