been forgetting to make tabbing
[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
21   public FieldDescriptor(Modifiers m, TypeDescriptor t, String identifier, ExpressionNode e, boolean isglobal) {
22     super(identifier);
23     this.modifier=m;
24     this.td=t;
25     this.en=e;
26     this.safename = "___" + name + "___";
27     this.uniqueid=count++;
28     this.isglobal=isglobal;
29     if (en!=null) throw new Error("Field initializers not implemented");
30   }
31
32   public boolean isGlobal() {
33     return isglobal;
34   }
35
36   public TypeDescriptor getType() {
37     return td;
38   }
39
40   public boolean equals(Object o) {
41     if( o == null ) return false;
42     if( !(o instanceof FieldDescriptor) ) return false;
43
44     FieldDescriptor fd = (FieldDescriptor) o;
45     if( modifier == null && fd.modifier != null ) return false;
46     if( modifier != null && !modifier.equals(fd.modifier) ) return false;
47     if( !(td == fd.td) ) return false;
48     if( !(en == fd.en) ) return false;
49     if( !isglobal == fd.isglobal ) return false;
50     if( identifier == null && fd.identifier != null ) return false;
51     if( identifier != null && !identifier.equals(fd.identifier) ) return false;
52     return true;
53   }
54
55   public int hashCode() {
56     int hashCode = modifier.hashCode();
57     hashCode += td.hashCode();
58     if( en != null ) hashCode += 81;
59     if( isglobal ) hashCode += 11;
60     if( identifier != null ) hashCode += identifier.hashCode();
61     return hashCode;
62   }
63
64   public String toString() {
65     if (en==null)
66       return modifier.toString()+td.toString()+" "+getSymbol()+";";
67     else
68       return modifier.toString()+td.toString()+" "+getSymbol()+"="+en.printNode(0)+";";
69   }
70
71   public String toStringBrief() {
72     return td.toString()+" "+getSymbol();
73   }
74 }