KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > gnu > expr > Literal


1 package gnu.expr;
2 import gnu.bytecode.*;
3
4 /** A Literal contains compile-time information about a constant. */
5
6 public class Literal
7 {
8   Literal next;
9
10   public Field field;
11
12   Object JavaDoc value;
13
14   /* If field is non-null, it is the number of the Field.
15    * I.e. if the index is 10, the value of the Literal is the value of
16    * the static Field named Lit10. */

17   int index;
18
19   public Type type;
20   
21   public int flags;
22
23   /** Set at the beginning of the call to writeObject. */
24   static final int WRITING = 1;
25
26   /** Set at the end of the call to writeObject. */
27   static final int WRITTEN = 2;
28
29   static final int CYCLIC = 4;
30
31   /** In pass 2, object has been at least allocated. */
32   static final int EMITTED = 8;
33
34   /** Values produced by calling writeObject on value. */
35   Object JavaDoc[] argValues;
36   /** Types produced by calling writeObject on value. */
37   Type[] argTypes;
38
39   public static final Literal nullLiteral
40     = new Literal(null, Type.nullType);
41
42   public final Object JavaDoc getValue() { return value; }
43
44   void assign (LitTable litTable)
45   {
46     assign((String JavaDoc) null, litTable);
47   }
48
49   /** Assign a static Field to hold the value of this Literal.
50    * This supports the same value being used multiple times or cyclically. */

51   void assign (String JavaDoc name, LitTable litTable)
52   {
53     int flags = litTable.comp.immediate ? Access.STATIC|Access.PUBLIC
54       : Access.STATIC|Access.FINAL;
55     if (name == null)
56       {
57     index = litTable.literalsCount++;
58     name = "Lit" + index;
59       }
60     else
61       flags |= Access.PUBLIC;
62     assign(litTable.mainClass.addField (name, type, flags), litTable);
63   }
64
65   void assign (Field field, LitTable litTable)
66   {
67     next = litTable.literalsChain;
68     litTable.literalsChain = this;
69     this.field = field;
70   }
71
72   /** Create a new Literal, where comp must be in immediate mode. */
73   public Literal (Object JavaDoc value, LitTable litTable)
74   {
75     this (value, (String JavaDoc) null, litTable);
76   }
77
78   public Literal (Object JavaDoc value, String JavaDoc name, LitTable litTable)
79   {
80     this.value = value;
81     litTable.literalTable.put (value, this);
82     this.type = Type.make(value.getClass());
83     assign(name, litTable);
84   }
85
86   /** Create a new Literal, for a value available from a static field.
87   * The field must be static and already exist. */

88   public Literal (Object JavaDoc value, Field field, LitTable litTable)
89   {
90     this.value = value;
91     litTable.literalTable.put(value, this);
92     this.field = field;
93     this.type = field.getType();
94     flags = WRITTEN|EMITTED;
95   }
96
97   public Literal (Object JavaDoc value, Type type, LitTable litTable)
98   {
99     this.value = value;
100     litTable.literalTable.put (value, this);
101     this.type = type;
102   }
103
104   Literal (Object JavaDoc value, Type type)
105   {
106     this.value = value;
107     this.type = type;
108   }
109 }
110
111
Popular Tags