Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS | NEXT CLASS FRAMES  | NO FRAMES
SUMMARY:  INNER | FIELD | CONSTR | METHOD DETAIL:  FIELD | CONSTR | METHOD

Class DE.fub.inf.JVM.ClassGen.ConstantPoolGen

java.lang.Object
  |
  +--DE.fub.inf.JVM.ClassGen.ConstantPoolGen

public final class ConstantPoolGen
extends java.lang.Object
implements Constants
This class is used to consequently build up a constant pool. The user adds constants via `addXXX' methods, `addString', `addClass', etc.. These methods return an index into the constant pool. Finally, `getFinalConstantPool()' returns the constant pool built up. Intermediate versions of the constant pool can be obtained with `getConstantPool()'. A constant pool has capacity for Constants.MAX_SHORT entries. Note that the first (0) is used by the JVM and that Double and Long constants need two slots entries.

Version:
$Id: ConstantPoolGen.java,v 1.5 1998/10/14 16:11:14 dahm Exp $
Author:
M. Dahm
See Also:
Constant

Constructor Summary
ConstantPoolGen(Constant[] c)
          Initialize with given array of constants.
ConstantPoolGen(ConstantPool cp)
          Initialize with given constant pool.
ConstantPoolGen()
          Create empty constant pool.
 
Method Summary
int addArrayClass(Type type)
          Add a reference to an array class (e.g.
int addClass(java.lang.String str)
          Add a new Class reference to the ConstantPool, if it is not already in there.
int addConstant(Constant c)
          Add a given constant (without checking for double entries).
int addDouble(double n)
          Add a new double constant to the ConstantPool, if it is not already in there.
int addFieldref(java.lang.String class_name, java.lang.String field_name, java.lang.String signature)
          Add a new Fieldref constant to the ConstantPool, if it is not already in there.
int addFloat(float n)
          Add a new Float constant to the ConstantPool, if it is not already in there.
int addInteger(int n)
          Add a new Integer constant to the ConstantPool, if it is not already in there.
int addInterfaceMethodref(java.lang.String class_name, java.lang.String method_name, java.lang.String signature)
          Add a new InterfaceMethodref constant to the ConstantPool, if it is not already in there.
int addLong(long n)
          Add a new long constant to the ConstantPool, if it is not already in there.
int addMethodref(java.lang.String class_name, java.lang.String method_name, java.lang.String signature)
          Add a new Methodref constant to the ConstantPool, if it is not already in there.
int addNameAndType(java.lang.String name, java.lang.String signature)
          Add a new NameAndType constant to the ConstantPool if it is not already in there.
int addString(java.lang.String str)
          Add a new String constant to the ConstantPool, if it is not already in there.
int addUnicode(java.lang.String n)
          Add a new Unicode constant to the ConstantPool, if it is not already in there.
int addUtf8(java.lang.String n)
          Add a new Utf8 constant to the ConstantPool, if it is not already in there.
Constant getConstant(int i)
           
ConstantPool getConstantPool()
           
ConstantPool getFinalConstantPool()
           
int getSize()
           
int lookupClass(java.lang.String str)
          Look for ConstantClass in ConstantPool named `str'.
int lookupConstant(Constant c)
          Look up constant in ConstantPool.
int lookupDouble(double n)
          Look for ConstantDouble in ConstantPool.
int lookupFieldref(java.lang.String class_name, java.lang.String field_name, java.lang.String signature)
          Look for ConstantFieldref in ConstantPool.
int lookupFloat(float n)
          Look for ConstantFloat in ConstantPool.
int lookupInteger(int n)
          Look for ConstantInteger in ConstantPool.
int lookupInterfaceMethodref(java.lang.String class_name, java.lang.String method_name, java.lang.String signature)
          Look for ConstantInterfaceMethodref in ConstantPool.
int lookupLong(long n)
          Look for ConstantLong in ConstantPool.
int lookupMethodref(java.lang.String class_name, java.lang.String method_name, java.lang.String signature)
          Look for ConstantMethodref in ConstantPool.
int lookupNameAndType(java.lang.String name, java.lang.String signature)
          Look for ConstantNameAndType in ConstantPool.
int lookupString(java.lang.String str)
          Look for ConstantString in ConstantPool containing String `str'.
int lookupUnicode(java.lang.String n)
          Look for ConstantUnicode in ConstantPool.
int lookupUtf8(java.lang.String n)
          Look for ConstantUtf8 in ConstantPool.
void setConstant(int i, Constant c)
          Use with care!
java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notifyAll, notify, toString, wait, wait, wait
 

Constructor Detail

ConstantPoolGen

public ConstantPoolGen(Constant[] c)
Initialize with given array of constants.
Parameters:
c - array of given constants, new ones will be appended

ConstantPoolGen

public ConstantPoolGen(ConstantPool cp)
Initialize with given constant pool.

ConstantPoolGen

public ConstantPoolGen()
Create empty constant pool.
Method Detail

lookupString

public final int lookupString(java.lang.String str)
Look for ConstantString in ConstantPool containing String `str'.
Parameters:
str - String to search for
Returns:
index on success, -1 otherwise

addString

public final int addString(java.lang.String str)
Add a new String constant to the ConstantPool, if it is not already in there.
Parameters:
str - String to add
Returns:
index of entry

lookupClass

public final int lookupClass(java.lang.String str)
Look for ConstantClass in ConstantPool named `str'.
Parameters:
str - String to search for
Returns:
index on success, -1 otherwise

addClass

public final int addClass(java.lang.String str)
Add a new Class reference to the ConstantPool, if it is not already in there.
Parameters:
str - Class to add
Returns:
index of entry

addArrayClass

public final int addArrayClass(Type type)
Add a reference to an array class (e.g. String[][]) as needed by MULTIANEWARRAY instruction, e.g. to the ConstantPool.
Parameters:
type - type of array class
Returns:
index of entry

lookupInteger

public final int lookupInteger(int n)
Look for ConstantInteger in ConstantPool.
Parameters:
n - integer number to look for
Returns:
index on success, -1 otherwise

addInteger

public final int addInteger(int n)
Add a new Integer constant to the ConstantPool, if it is not already in there.
Parameters:
n - integer number to add
Returns:
index of entry

lookupFloat

public final int lookupFloat(float n)
Look for ConstantFloat in ConstantPool.
Parameters:
n - Float number to look for
Returns:
index on success, -1 otherwise

addFloat

public final int addFloat(float n)
Add a new Float constant to the ConstantPool, if it is not already in there.
Parameters:
n - Float number to add
Returns:
index of entry

lookupUnicode

public final int lookupUnicode(java.lang.String n)
Look for ConstantUnicode in ConstantPool.
Parameters:
n - Unicode string to look for
Returns:
index on success, -1 otherwise

addUnicode

public final int addUnicode(java.lang.String n)
Add a new Unicode constant to the ConstantPool, if it is not already in there.
Parameters:
n - Unicode string to add
Returns:
index of entry

lookupUtf8

public final int lookupUtf8(java.lang.String n)
Look for ConstantUtf8 in ConstantPool.
Parameters:
n - Utf8 string to look for
Returns:
index on success, -1 otherwise

addUtf8

public final int addUtf8(java.lang.String n)
Add a new Utf8 constant to the ConstantPool, if it is not already in there.
Parameters:
n - Utf8 string to add
Returns:
index of entry

lookupLong

public final int lookupLong(long n)
Look for ConstantLong in ConstantPool.
Parameters:
n - Long number to look for
Returns:
index on success, -1 otherwise

addLong

public final int addLong(long n)
Add a new long constant to the ConstantPool, if it is not already in there.
Parameters:
n - Long number to add
Returns:
index of entry

lookupDouble

public final int lookupDouble(double n)
Look for ConstantDouble in ConstantPool.
Parameters:
n - Double number to look for
Returns:
index on success, -1 otherwise

addDouble

public final int addDouble(double n)
Add a new double constant to the ConstantPool, if it is not already in there.
Parameters:
n - Double number to add
Returns:
index of entry

lookupNameAndType

public final int lookupNameAndType(java.lang.String name,
                                   java.lang.String signature)
Look for ConstantNameAndType in ConstantPool.
Parameters:
name - of variable/method
signature - of variable/method
Returns:
index on success, -1 otherwise

addNameAndType

public final int addNameAndType(java.lang.String name,
                                java.lang.String signature)
Add a new NameAndType constant to the ConstantPool if it is not already in there.
Parameters:
n - NameAndType string to add
Returns:
index of entry

lookupMethodref

public final int lookupMethodref(java.lang.String class_name,
                                 java.lang.String method_name,
                                 java.lang.String signature)
Look for ConstantMethodref in ConstantPool.
Parameters:
class_name - Where to find method
method_name - Guess what
signature - return and argument types
Returns:
index on success, -1 otherwise

addMethodref

public final int addMethodref(java.lang.String class_name,
                              java.lang.String method_name,
                              java.lang.String signature)
Add a new Methodref constant to the ConstantPool, if it is not already in there.
Parameters:
n - Methodref string to add
Returns:
index of entry

lookupInterfaceMethodref

public final int lookupInterfaceMethodref(java.lang.String class_name,
                                          java.lang.String method_name,
                                          java.lang.String signature)
Look for ConstantInterfaceMethodref in ConstantPool.
Parameters:
class_name - Where to find method
method_name - Guess what
signature - return and argument types
Returns:
index on success, -1 otherwise

addInterfaceMethodref

public final int addInterfaceMethodref(java.lang.String class_name,
                                       java.lang.String method_name,
                                       java.lang.String signature)
Add a new InterfaceMethodref constant to the ConstantPool, if it is not already in there.
Parameters:
n - InterfaceMethodref string to add
Returns:
index of entry

lookupFieldref

public final int lookupFieldref(java.lang.String class_name,
                                java.lang.String field_name,
                                java.lang.String signature)
Look for ConstantFieldref in ConstantPool.
Parameters:
class_name - Where to find method
field_name - Guess what
signature - return and argument types
Returns:
index on success, -1 otherwise

addFieldref

public final int addFieldref(java.lang.String class_name,
                             java.lang.String field_name,
                             java.lang.String signature)
Add a new Fieldref constant to the ConstantPool, if it is not already in there.
Parameters:
n - Fieldref string to add
Returns:
index of entry

addConstant

public final int addConstant(Constant c)
Add a given constant (without checking for double entries).
Parameters:
c - Constant to add
Returns:
index of entry

lookupConstant

public final int lookupConstant(Constant c)
Look up constant in ConstantPool.
Parameters:
c - constant to look up
Returns:
index on success, -1 otherwise

getConstant

public Constant getConstant(int i)
Parameters:
i - index in constant pool
Returns:
constant pool entry at index i

setConstant

public void setConstant(int i,
                        Constant c)
Use with care!
Parameters:
i - index in constant pool
c - new constant pool entry at index i

getConstantPool

public ConstantPool getConstantPool()
Returns:
intermediate constant pool

getSize

public int getSize()
Returns:
current size of constant pool

getFinalConstantPool

public ConstantPool getFinalConstantPool()
Returns:
constant pool with proper length

toString

public final java.lang.String toString()
Returns:
String representation.
Overrides:
toString in class java.lang.Object

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS | NEXT CLASS FRAMES  | NO FRAMES
SUMMARY:  INNER | FIELD | CONSTR | METHOD DETAIL:  FIELD | CONSTR | METHOD