/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2001 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache BCEL" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* "Apache BCEL", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
*/
/**
* This class is used to 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.
*
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
* @see Constant
*/
int index;
}
/**
* Initialize with given array of constants.
*
* @param c array of given constants, new ones will be appended
*/
}
for(int i=1; i < index; i++) {
if(c instanceof ConstantString) {
ConstantString s = (ConstantString)c;
} else if(c instanceof ConstantClass) {
ConstantClass s = (ConstantClass)c;
} else if(c instanceof ConstantNameAndType) {
} else if(c instanceof ConstantUtf8) {
ConstantUtf8 u = (ConstantUtf8)c;
} else if(c instanceof ConstantCP) {
ConstantCP m = (ConstantCP)c;
if(c instanceof ConstantInterfaceMethodref)
else if(c instanceof ConstantFieldref)
}
}
}
/**
* Initialize with given constant pool.
*/
this(cp.getConstantPool());
}
/**
* Create empty constant pool.
*/
public ConstantPoolGen() {}
/** Resize internal array of constants.
*/
protected void adjustSize() {
size *= 2;
}
}
/**
* Look for ConstantString in ConstantPool containing String `str'.
*
* @param str String to search for
* @return index on success, -1 otherwise
*/
}
/**
* Add a new String constant to the ConstantPool, if it is not already in there.
*
* @param str String to add
* @return index of entry
*/
int ret;
return ret; // Already in CP
adjustSize();
return ret;
}
/**
* Look for ConstantClass in ConstantPool named `str'.
*
* @param str String to search for
* @return index on success, -1 otherwise
*/
}
int ret;
return ret; // Already in CP
adjustSize();
return ret;
}
/**
* Add a new Class reference to the ConstantPool, if it is not already in there.
*
* @param str Class to add
* @return index of entry
*/
}
/**
* Add a new Class reference to the ConstantPool for a given type.
*
* @param str Class to add
* @return index of entry
*/
}
/**
* Add a reference to an array class (e.g. String[][]) as needed by MULTIANEWARRAY
* instruction, e.g. to the ConstantPool.
*
* @param type type of array class
* @return index of entry
*/
}
/**
* Look for ConstantInteger in ConstantPool.
*
* @param n integer number to look for
* @return index on success, -1 otherwise
*/
public int lookupInteger(int n) {
for(int i=1; i < index; i++) {
if(constants[i] instanceof ConstantInteger) {
if(c.getBytes() == n)
return i;
}
}
return -1;
}
/**
* Add a new Integer constant to the ConstantPool, if it is not already in there.
*
* @param n integer number to add
* @return index of entry
*/
public int addInteger(int n) {
int ret;
return ret; // Already in CP
adjustSize();
return ret;
}
/**
* Look for ConstantFloat in ConstantPool.
*
* @param n Float number to look for
* @return index on success, -1 otherwise
*/
public int lookupFloat(float n) {
for(int i=1; i < index; i++) {
if(constants[i] instanceof ConstantFloat) {
return i;
}
}
return -1;
}
/**
* Add a new Float constant to the ConstantPool, if it is not already in there.
*
* @param n Float number to add
* @return index of entry
*/
public int addFloat(float n) {
int ret;
return ret; // Already in CP
adjustSize();
return ret;
}
/**
* Look for ConstantUtf8 in ConstantPool.
*
* @param n Utf8 string to look for
* @return index on success, -1 otherwise
*/
}
/**
* Add a new Utf8 constant to the ConstantPool, if it is not already in there.
*
* @param n Utf8 string to add
* @return index of entry
*/
int ret;
return ret; // Already in CP
adjustSize();
return ret;
}
/**
* Look for ConstantLong in ConstantPool.
*
* @param n Long number to look for
* @return index on success, -1 otherwise
*/
public int lookupLong(long n) {
for(int i=1; i < index; i++) {
if(constants[i] instanceof ConstantLong) {
if(c.getBytes() == n)
return i;
}
}
return -1;
}
/**
* Add a new long constant to the ConstantPool, if it is not already in there.
*
* @param n Long number to add
* @return index of entry
*/
public int addLong(long n) {
int ret;
return ret; // Already in CP
adjustSize();
return ret;
}
/**
* Look for ConstantDouble in ConstantPool.
*
* @param n Double number to look for
* @return index on success, -1 otherwise
*/
public int lookupDouble(double n) {
for(int i=1; i < index; i++) {
if(constants[i] instanceof ConstantDouble) {
return i;
}
}
return -1;
}
/**
* Add a new double constant to the ConstantPool, if it is not already in there.
*
* @param n Double number to add
* @return index of entry
*/
public int addDouble(double n) {
int ret;
return ret; // Already in CP
adjustSize();
return ret;
}
/**
* Look for ConstantNameAndType in ConstantPool.
*
* @return index on success, -1 otherwise
*/
}
/**
* Add a new NameAndType constant to the ConstantPool if it is not already
* in there.
*
* @param n NameAndType string to add
* @return index of entry
*/
int ret;
int name_index, signature_index;
return ret; // Already in CP
adjustSize();
return ret;
}
/**
* Look for ConstantMethodref in ConstantPool.
*
* @param class_name Where to find method
* @param method_name Guess what
* @param signature return and argument types
* @return index on success, -1 otherwise
*/
}
method.getSignature());
}
/**
* Add a new Methodref constant to the ConstantPool, if it is not already
* in there.
*
* @param n Methodref string to add
* @return index of entry
*/
return ret; // Already in CP
adjustSize();
return ret;
}
method.getSignature());
}
/**
* Look for ConstantInterfaceMethodref in ConstantPool.
*
* @param class_name Where to find method
* @param method_name Guess what
* @param signature return and argument types
* @return index on success, -1 otherwise
*/
}
method.getSignature());
}
/**
* Add a new InterfaceMethodref constant to the ConstantPool, if it is not already
* in there.
*
* @param n InterfaceMethodref string to add
* @return index of entry
*/
return ret; // Already in CP
adjustSize();
return ret;
}
method.getSignature());
}
/**
* Look for ConstantFieldref in ConstantPool.
*
* @param class_name Where to find method
* @param field_name Guess what
* @param signature return and argument types
* @return index on success, -1 otherwise
*/
}
/**
* Add a new Fieldref constant to the ConstantPool, if it is not already
* in there.
*
* @param n Fieldref string to add
* @return index of entry
*/
int ret;
return ret; // Already in CP
adjustSize();
cp_table.put(class_name + FIELDREF_DELIM + field_name + FIELDREF_DELIM + signature, new Index(ret));
return ret;
}
/**
* @param i index in constant pool
* @return constant pool entry at index i
*/
/**
* Use with care!
*
* @param i index in constant pool
* @param c new constant pool entry at index i
*/
/**
* @return intermediate constant pool
*/
return new ConstantPool(constants);
}
/**
* @return current size of constant pool
*/
public int getSize() {
return index;
}
/**
* @return constant pool with proper length
*/
return new ConstantPool(cs);
}
/**
* @return String representation.
*/
for(int i=1; i < index; i++)
}
/** Import constant from another ConstantPool and return new index.
*/
switch(c.getTag()) {
case Constants.CONSTANT_String: {
ConstantString s = (ConstantString)c;
}
case Constants.CONSTANT_Class: {
ConstantClass s = (ConstantClass)c;
}
case Constants.CONSTANT_NameAndType: {
}
case Constants.CONSTANT_Utf8:
case Constants.CONSTANT_Double:
case Constants.CONSTANT_Float:
case Constants.CONSTANT_Long:
case Constants.CONSTANT_Integer:
case Constants.CONSTANT_Fieldref: {
ConstantCP m = (ConstantCP)c;
switch(c.getTag()) {
case Constants.CONSTANT_Methodref:
case Constants.CONSTANT_Fieldref:
default: // Never reached
throw new RuntimeException("Unknown constant type " + c);
}
}
default: // Never reached
throw new RuntimeException("Unknown constant type " + c);
}
}
}