< prev index next >

src/java.xml/share/classes/com/sun/org/apache/bcel/internal/classfile/StackMapEntry.java

Print this page




  14  *
  15  * Unless required by applicable law or agreed to in writing, software
  16  * distributed under the License is distributed on an "AS IS" BASIS,
  17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  18  * See the License for the specific language governing permissions and
  19  * limitations under the License.
  20  */
  21 
  22 package com.sun.org.apache.bcel.internal.classfile;
  23 
  24 import java.io.DataInput;
  25 import java.io.DataOutputStream;
  26 import java.io.IOException;
  27 import com.sun.org.apache.bcel.internal.Const;
  28 
  29 /**
  30  * This class represents a stack map entry recording the types of
  31  * local variables and the the of stack items at a given byte code offset.
  32  * See CLDC specification 5.3.1.2
  33  *
  34  * @version $Id$
  35  * @see     StackMap
  36  * @see     StackMapType
  37  */
  38 public final class StackMapEntry implements Node, Cloneable
  39 {
  40 
  41     private int frame_type;
  42     private int byte_code_offset;
  43     private StackMapType[] types_of_locals;
  44     private StackMapType[] types_of_stack_items;
  45     private ConstantPool constant_pool;
  46 
  47 
  48     /**
  49      * Construct object from input stream.
  50      *
  51      * @param input Input stream
  52      * @throws IOException
  53      */
  54     StackMapEntry(final DataInput input, final ConstantPool constantPool) throws IOException {


 125      * @param typesOfStackItems array ot {@link StackMapType}s of stack items
 126      * @param constantPool the constant pool
 127      */
 128     public StackMapEntry(final int tag, final int byteCodeOffset,
 129             final StackMapType[] typesOfLocals,
 130             final StackMapType[] typesOfStackItems, final ConstantPool constantPool) {
 131         this.frame_type = tag;
 132         this.byte_code_offset = byteCodeOffset;
 133         this.types_of_locals = typesOfLocals != null ? typesOfLocals : new StackMapType[0];
 134         this.types_of_stack_items = typesOfStackItems != null ? typesOfStackItems : new StackMapType[0];
 135         this.constant_pool = constantPool;
 136     }
 137 
 138 
 139     /**
 140      * Dump stack map entry
 141      *
 142      * @param file Output file stream
 143      * @throws IOException
 144      */
 145     public final void dump( final DataOutputStream file ) throws IOException {
 146         file.write(frame_type);
 147         if (frame_type >= Const.SAME_FRAME && frame_type <= Const.SAME_FRAME_MAX) {
 148             // nothing to be done
 149         } else if (frame_type >= Const.SAME_LOCALS_1_STACK_ITEM_FRAME &&
 150                    frame_type <= Const.SAME_LOCALS_1_STACK_ITEM_FRAME_MAX) {
 151             types_of_stack_items[0].dump(file);
 152         } else if (frame_type == Const.SAME_LOCALS_1_STACK_ITEM_FRAME_EXTENDED) {
 153             file.writeShort(byte_code_offset);
 154             types_of_stack_items[0].dump(file);
 155         } else if (frame_type >= Const.CHOP_FRAME && frame_type <= Const.CHOP_FRAME_MAX) {
 156             file.writeShort(byte_code_offset);
 157         } else if (frame_type == Const.SAME_FRAME_EXTENDED) {
 158             file.writeShort(byte_code_offset);
 159         } else if (frame_type >= Const.APPEND_FRAME && frame_type <= Const.APPEND_FRAME_MAX) {
 160             file.writeShort(byte_code_offset);
 161             for (final StackMapType type : types_of_locals) {
 162                 type.dump(file);
 163             }
 164         } else if (frame_type == Const.FULL_FRAME) {
 165             file.writeShort(byte_code_offset);
 166             file.writeShort(types_of_locals.length);
 167             for (final StackMapType type : types_of_locals) {
 168                 type.dump(file);
 169             }
 170             file.writeShort(types_of_stack_items.length);
 171             for (final StackMapType type : types_of_stack_items) {
 172                 type.dump(file);
 173             }
 174         } else {
 175             /* Can't happen */
 176             throw new ClassFormatException ("Invalid Stack map table tag: " + frame_type);
 177         }
 178     }
 179 
 180 
 181     /**
 182      * @return String representation.
 183      */
 184     @Override
 185     public final String toString() {
 186         final StringBuilder buf = new StringBuilder(64);
 187         buf.append("(");
 188         if (frame_type >= Const.SAME_FRAME && frame_type <= Const.SAME_FRAME_MAX) {
 189             buf.append("SAME");
 190         } else if (frame_type >= Const.SAME_LOCALS_1_STACK_ITEM_FRAME &&
 191                   frame_type <= Const.SAME_LOCALS_1_STACK_ITEM_FRAME_MAX) {
 192             buf.append("SAME_LOCALS_1_STACK");
 193         } else if (frame_type == Const.SAME_LOCALS_1_STACK_ITEM_FRAME_EXTENDED) {
 194             buf.append("SAME_LOCALS_1_STACK_EXTENDED");
 195         } else if (frame_type >= Const.CHOP_FRAME && frame_type <= Const.CHOP_FRAME_MAX) {
 196             buf.append("CHOP ").append(String.valueOf(251-frame_type));
 197         } else if (frame_type == Const.SAME_FRAME_EXTENDED) {
 198             buf.append("SAME_EXTENDED");
 199         } else if (frame_type >= Const.APPEND_FRAME && frame_type <= Const.APPEND_FRAME_MAX) {
 200             buf.append("APPEND ").append(String.valueOf(frame_type-251));
 201         } else if (frame_type == Const.FULL_FRAME) {
 202             buf.append("FULL");
 203         } else {
 204             buf.append("UNKNOWN (").append(frame_type).append(")");
 205         }


 409         return e;
 410     }
 411 
 412 
 413     /**
 414      * Called by objects that are traversing the nodes of the tree implicitely
 415      * defined by the contents of a Java class. I.e., the hierarchy of methods,
 416      * fields, attributes, etc. spawns a tree of objects.
 417      *
 418      * @param v Visitor object
 419      */
 420     @Override
 421     public void accept( final Visitor v ) {
 422         v.visitStackMapEntry(this);
 423     }
 424 
 425 
 426     /**
 427      * @return Constant pool used by this object.
 428      */
 429     public final ConstantPool getConstantPool() {
 430         return constant_pool;
 431     }
 432 
 433 
 434     /**
 435      * @param constant_pool Constant pool to be used for this object.
 436      */
 437     public final void setConstantPool( final ConstantPool constant_pool ) {
 438         this.constant_pool = constant_pool;
 439     }
 440 }


  14  *
  15  * Unless required by applicable law or agreed to in writing, software
  16  * distributed under the License is distributed on an "AS IS" BASIS,
  17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  18  * See the License for the specific language governing permissions and
  19  * limitations under the License.
  20  */
  21 
  22 package com.sun.org.apache.bcel.internal.classfile;
  23 
  24 import java.io.DataInput;
  25 import java.io.DataOutputStream;
  26 import java.io.IOException;
  27 import com.sun.org.apache.bcel.internal.Const;
  28 
  29 /**
  30  * This class represents a stack map entry recording the types of
  31  * local variables and the the of stack items at a given byte code offset.
  32  * See CLDC specification 5.3.1.2
  33  *

  34  * @see     StackMap
  35  * @see     StackMapType
  36  */
  37 public final class StackMapEntry implements Node, Cloneable
  38 {
  39 
  40     private int frame_type;
  41     private int byte_code_offset;
  42     private StackMapType[] types_of_locals;
  43     private StackMapType[] types_of_stack_items;
  44     private ConstantPool constant_pool;
  45 
  46 
  47     /**
  48      * Construct object from input stream.
  49      *
  50      * @param input Input stream
  51      * @throws IOException
  52      */
  53     StackMapEntry(final DataInput input, final ConstantPool constantPool) throws IOException {


 124      * @param typesOfStackItems array ot {@link StackMapType}s of stack items
 125      * @param constantPool the constant pool
 126      */
 127     public StackMapEntry(final int tag, final int byteCodeOffset,
 128             final StackMapType[] typesOfLocals,
 129             final StackMapType[] typesOfStackItems, final ConstantPool constantPool) {
 130         this.frame_type = tag;
 131         this.byte_code_offset = byteCodeOffset;
 132         this.types_of_locals = typesOfLocals != null ? typesOfLocals : new StackMapType[0];
 133         this.types_of_stack_items = typesOfStackItems != null ? typesOfStackItems : new StackMapType[0];
 134         this.constant_pool = constantPool;
 135     }
 136 
 137 
 138     /**
 139      * Dump stack map entry
 140      *
 141      * @param file Output file stream
 142      * @throws IOException
 143      */
 144     public void dump( final DataOutputStream file ) throws IOException {
 145         file.write(frame_type);
 146         if (frame_type >= Const.SAME_FRAME && frame_type <= Const.SAME_FRAME_MAX) {
 147             // nothing to be done
 148         } else if (frame_type >= Const.SAME_LOCALS_1_STACK_ITEM_FRAME &&
 149                    frame_type <= Const.SAME_LOCALS_1_STACK_ITEM_FRAME_MAX) {
 150             types_of_stack_items[0].dump(file);
 151         } else if (frame_type == Const.SAME_LOCALS_1_STACK_ITEM_FRAME_EXTENDED) {
 152             file.writeShort(byte_code_offset);
 153             types_of_stack_items[0].dump(file);
 154         } else if (frame_type >= Const.CHOP_FRAME && frame_type <= Const.CHOP_FRAME_MAX) {
 155             file.writeShort(byte_code_offset);
 156         } else if (frame_type == Const.SAME_FRAME_EXTENDED) {
 157             file.writeShort(byte_code_offset);
 158         } else if (frame_type >= Const.APPEND_FRAME && frame_type <= Const.APPEND_FRAME_MAX) {
 159             file.writeShort(byte_code_offset);
 160             for (final StackMapType type : types_of_locals) {
 161                 type.dump(file);
 162             }
 163         } else if (frame_type == Const.FULL_FRAME) {
 164             file.writeShort(byte_code_offset);
 165             file.writeShort(types_of_locals.length);
 166             for (final StackMapType type : types_of_locals) {
 167                 type.dump(file);
 168             }
 169             file.writeShort(types_of_stack_items.length);
 170             for (final StackMapType type : types_of_stack_items) {
 171                 type.dump(file);
 172             }
 173         } else {
 174             /* Can't happen */
 175             throw new ClassFormatException ("Invalid Stack map table tag: " + frame_type);
 176         }
 177     }
 178 
 179 
 180     /**
 181      * @return String representation.
 182      */
 183     @Override
 184     public String toString() {
 185         final StringBuilder buf = new StringBuilder(64);
 186         buf.append("(");
 187         if (frame_type >= Const.SAME_FRAME && frame_type <= Const.SAME_FRAME_MAX) {
 188             buf.append("SAME");
 189         } else if (frame_type >= Const.SAME_LOCALS_1_STACK_ITEM_FRAME &&
 190                   frame_type <= Const.SAME_LOCALS_1_STACK_ITEM_FRAME_MAX) {
 191             buf.append("SAME_LOCALS_1_STACK");
 192         } else if (frame_type == Const.SAME_LOCALS_1_STACK_ITEM_FRAME_EXTENDED) {
 193             buf.append("SAME_LOCALS_1_STACK_EXTENDED");
 194         } else if (frame_type >= Const.CHOP_FRAME && frame_type <= Const.CHOP_FRAME_MAX) {
 195             buf.append("CHOP ").append(String.valueOf(251-frame_type));
 196         } else if (frame_type == Const.SAME_FRAME_EXTENDED) {
 197             buf.append("SAME_EXTENDED");
 198         } else if (frame_type >= Const.APPEND_FRAME && frame_type <= Const.APPEND_FRAME_MAX) {
 199             buf.append("APPEND ").append(String.valueOf(frame_type-251));
 200         } else if (frame_type == Const.FULL_FRAME) {
 201             buf.append("FULL");
 202         } else {
 203             buf.append("UNKNOWN (").append(frame_type).append(")");
 204         }


 408         return e;
 409     }
 410 
 411 
 412     /**
 413      * Called by objects that are traversing the nodes of the tree implicitely
 414      * defined by the contents of a Java class. I.e., the hierarchy of methods,
 415      * fields, attributes, etc. spawns a tree of objects.
 416      *
 417      * @param v Visitor object
 418      */
 419     @Override
 420     public void accept( final Visitor v ) {
 421         v.visitStackMapEntry(this);
 422     }
 423 
 424 
 425     /**
 426      * @return Constant pool used by this object.
 427      */
 428     public ConstantPool getConstantPool() {
 429         return constant_pool;
 430     }
 431 
 432 
 433     /**
 434      * @param constant_pool Constant pool to be used for this object.
 435      */
 436     public void setConstantPool( final ConstantPool constant_pool ) {
 437         this.constant_pool = constant_pool;
 438     }
 439 }
< prev index next >