1    
2    /*
3    
4      The author of this software is Ian Kaplan
5      Bear Products International
6      www.bearcave.com
7      iank@bearcave.com
8    
9      Copyright (c) Ian Kaplan, 1999, 2000
10   
11     See copyright file for usage and licensing
12   
13   */
14   
15   package attr;
16   
17   import java.io.*;
18   import util.*;
19   import jconst.*;
20   
21   /**
22   
23      Represent a ConstantValue attribute.
24   
25     <p>
26      The JVM Specification (4.7.3) states:
27   
28   <blockquote>
29        The constValueAttr is a fixed length attribute used in the
30        "attributes" table of the field info structure.  A constValueAttr
31        represents the value of a constant field that must be (explicitly
32        or implicitly) static; that is the ACC_STATIC bit in the flags
33        item o fthe field_info structure must be set.  The field is not
34        required to be final.  There can be no more than one
35        constValueAttr attribute in the attributes table of a given field
36        info structure.  The constant field represented by the field_info
37        structure is assigned the value referenced by its constValueAttr
38        attribute as part of its initialization.
39   </blockquote>
40   
41   <p>
42      Every JVM is required to recognize the constValueAttr.  There
43      may be other locally defined attributes which are ignored in
44      general but may be used by a specific combination of Java
45      compiler and JVM (so much for portability).
46   
47   <p>
48      The constValueAttr is
49   
50   <pre>
51        ConstantValue_attribute {
52          u2 attribute_name_index;
53          u4 attribute_length;    
54          u2 constantvalue_index;
55        }
56   </pre>
57   
58   <p>
59      The attribute_name_index and attribute length are read by the
60      attrFactory.allocAttr method.  These values are passed into the class
61      constructor.
62   
63   <p>
64      The constantvalue_index is the index into the constant pool
65      for a long, float, double, int (for int, short, char, byte
66      and boolean) or String.
67   
68      Question:
69   
70         What is the ConstantValue attribute for mondoRef, since
71         its type is not a base type, but it is static.
72   
73           class mondo {
74              int p, d, q;
75           }
76           
77           class foobar {
78             static mondo mondoRef = null;
79             ...
80           }
81   
82      @author Ian Kaplan
83   
84    */
85   public class constValueAttr extends attrInfo {
86     constBase constValue = null;
87   
88     public constValueAttr( String name, int length, 
89   			 DataInputStream dStream, constPool constPoolSec ) {
90       // read the attribute type string and the length
91       super( name, length );
92   
93       int constValueIx = readU2( dStream );
94       if (constValueIx > 0) {
95         constValue = constPoolSec.constPoolElem( constValueIx );
96       }
97   
98     } // constValueAttr constructor
99   
100  
101    public constBase getConstVal() { return constValue; }
102  
103    public void pr() {
104      super.pr();
105      if (constValue != null) {
106        constValue.pr();
107      }
108    } // pr
109  
110  } // constValueAttr
111