ConstantPoolGen.java revision 286
0N/A * DO NOT REMOVE OR ALTER! 0N/A/* ==================================================================== 0N/A * The Apache Software License, Version 1.1 0N/A * Copyright (c) 2001 The Apache Software Foundation. All rights 0N/A * Redistribution and use in source and binary forms, with or without 0N/A * modification, are permitted provided that the following conditions 0N/A * 1. Redistributions of source code must retain the above copyright 0N/A * notice, this list of conditions and the following disclaimer. 1472N/A * 2. Redistributions in binary form must reproduce the above copyright 1472N/A * notice, this list of conditions and the following disclaimer in 0N/A * the documentation and/or other materials provided with the 1879N/A * 3. The end-user documentation included with the redistribution, 1879N/A * if any, must include the following acknowledgment: 1879N/A * "This product includes software developed by the 1879N/A * Alternately, this acknowledgment may appear in the software itself, 1879N/A * if and wherever such third-party acknowledgments normally appear. 1879N/A * 4. The names "Apache" and "Apache Software Foundation" and 1879N/A * "Apache BCEL" must not be used to endorse or promote products 0N/A * derived from this software without prior written permission. For 0N/A * written permission, please contact apache@apache.org. 0N/A * 5. Products derived from this software may not be called "Apache", 0N/A * "Apache BCEL", nor may "Apache" appear in their name, without 0N/A * prior written permission of the Apache Software Foundation. 0N/A * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED 0N/A * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 0N/A * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 0N/A * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR 0N/A * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 0N/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 0N/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 0N/A * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 0N/A * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 0N/A * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 0N/A * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 0N/A * ==================================================================== 0N/A * This software consists of voluntary contributions made by many 0N/A * individuals on behalf of the Apache Software Foundation. For more 2168N/A * information on the Apache Software Foundation, please see 2886N/A * This class is used to build up a constant pool. The user adds 0N/A * constants via `addXXX' methods, `addString', `addClass', 0N/A * etc.. These methods return an index into the constant 342N/A * pool. Finally, `getFinalConstantPool()' returns the constant pool 342N/A * built up. Intermediate versions of the constant pool can be 0N/A * obtained with `getConstantPool()'. A constant pool has capacity for 0N/A * Constants.MAX_SHORT entries. Note that the first (0) is used by the 0N/A * JVM and that Double and Long constants need two slots. 0N/A * @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A> 0N/A protected int size =
1024;
// Inital size, sufficient in most cases 0N/A protected int index =
1;
// First entry (0) used by JVM 0N/A * Initialize with given array of constants. 0N/A * @param c array of given constants, new ones will be appended 0N/A * Initialize with given constant pool. 0N/A * Create empty constant pool. 1668N/A /** Resize internal array of constants. 0N/A * Look for ConstantString in ConstantPool containing String `str'. 0N/A * @param str String to search for 0N/A * @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 ret;
// Already in CP * Look for ConstantClass in ConstantPool named `str'. * @param str String to search for * @return index on success, -1 otherwise return ret;
// Already in CP * Add a new Class reference to the ConstantPool, if it is not already in there. * @param str Class to add * Add a new Class reference to the ConstantPool for a given type. * @param str Class to add * 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 * Look for ConstantInteger in ConstantPool. * @param n integer number to look for * @return index on success, -1 otherwise for(
int i=
1; i <
index; i++) {
* Add a new Integer constant to the ConstantPool, if it is not already in there. * @param n integer number to add return ret;
// Already in CP * Look for ConstantFloat in ConstantPool. * @param n Float number to look for * @return index on success, -1 otherwise for(
int i=
1; i <
index; i++) {
* Add a new Float constant to the ConstantPool, if it is not already in there. * @param n Float number to add return ret;
// Already in CP * 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 ret;
// Already in CP * Look for ConstantLong in ConstantPool. * @param n Long number to look for * @return index on success, -1 otherwise for(
int i=
1; i <
index; i++) {
* Add a new long constant to the ConstantPool, if it is not already in there. * @param n Long number to add return ret;
// Already in CP index +=
2;
// Wastes one entry according to spec * Look for ConstantDouble in ConstantPool. * @param n Double number to look for * @return index on success, -1 otherwise for(
int i=
1; i <
index; i++) {
* Add a new double constant to the ConstantPool, if it is not already in there. * @param n Double number to add return ret;
// Already in CP index +=
2;
// Wastes one entry according to spec * Look for ConstantNameAndType in ConstantPool. * @return index on success, -1 otherwise * Add a new NameAndType constant to the ConstantPool if it is not already * @param n NameAndType string to add return ret;
// Already in CP * 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 * Add a new Methodref constant to the ConstantPool, if it is not already * @param n Methodref string to add return ret;
// Already in CP * 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 * Add a new InterfaceMethodref constant to the ConstantPool, if it is not already * @param n InterfaceMethodref string to add return ret;
// Already in CP * 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 * @param n Fieldref string to add return ret;
// Already in CP * @param i index in constant pool * @return constant pool entry at index i * @param i index in constant pool * @param c new constant pool entry at index i * @return intermediate constant pool * @return current size of constant pool * @return constant pool with proper length * @return String representation. for(
int i=
1; i <
index; i++)
/** Import constant from another ConstantPool and return new index. default:
// Never reached default:
// Never reached