1 cananian 1.1.2.2 // ConstantInteger.java, created Mon Jan 18 22:44:37 1999 by cananian
 2 cananian 1.1.2.1 // Copyright (C) 1998 C. Scott Ananian <cananian@alumni.princeton.edu>
 3 cananian 1.1.2.1 // Licensed under the terms of the GNU GPL; see COPYING for details.
 4 cananian 1.1.2.1 package harpoon.IR.RawClass;
 5 cananian 1.1.2.1 
 6 cananian 1.1.2.1 /**
 7 cananian 1.1.2.1  * The <code>CONSTANT_Integer_info</code> structure represents
 8 cananian 1.1.2.1  * four-byte integer numeric constants.
 9 cananian 1.1.2.1  *
10 cananian 1.1.2.1  * @author  C. Scott Ananian <cananian@alumni.princeton.edu>
11 cananian 1.2      * @version $Id: ConstantInteger.java,v 1.2 2002/02/25 21:05:27 cananian Exp $
12 cananian 1.1.2.1  * @see "The Java Virtual Machine Specification, section 4.4.4"
13 cananian 1.1.2.1  * @see Constant
14 cananian 1.1.2.1  * @see ConstantFloat
15 cananian 1.1.2.1  */
16 cananian 1.1.2.1 public class ConstantInteger extends ConstantValue {
17 cananian 1.1.2.1   /** The value of the <code>int</code> constant. */
18 cananian 1.1.2.1   public int val;
19 cananian 1.1.2.1 
20 cananian 1.1.2.1   /** Constructor. */
21 cananian 1.1.2.1   ConstantInteger(ClassFile parent, ClassDataInputStream in) 
22 cananian 1.1.2.1     throws java.io.IOException {
23 cananian 1.1.2.1     super(parent);
24 cananian 1.1.2.1     val = in.readInt();
25 cananian 1.1.2.1   }
26 cananian 1.1.2.1   /** Constructor. */
27 cananian 1.1.2.1   public ConstantInteger(ClassFile parent, int val) { 
28 cananian 1.1.2.1     super(parent);
29 cananian 1.1.2.1     this.val = val; 
30 cananian 1.1.2.1   }
31 cananian 1.1.2.1 
32 cananian 1.1.2.1   /** Write to a bytecode file. */
33 cananian 1.1.2.1   public void write(ClassDataOutputStream out) throws java.io.IOException {
34 cananian 1.1.2.1     out.write_u1(CONSTANT_Integer);
35 cananian 1.1.2.1     out.writeInt(val);
36 cananian 1.1.2.1   }
37 cananian 1.1.2.1 
38 cananian 1.1.2.1   /** Returns the integer value of this constant. */
39 cananian 1.1.2.1   public int intValue() { return val; }
40 cananian 1.1.2.1   /** Returns the value of this constant, wrapped as a 
41 cananian 1.1.2.1    *  <code>java.lang.Integer</code>. */
42 cananian 1.1.2.1   public Object value() { return new Integer(val); }
43 cananian 1.1.2.1 
44 cananian 1.1.2.1   /** Create a human-readable representation of this constant. */
45 cananian 1.1.2.1   public String toString() {
46 cananian 1.1.2.1     return "CONSTANT_Integer: "+intValue();
47 cananian 1.1.2.1   }
48 cananian 1.2     }