Author: tcurdt Date: Sat Feb 2 11:50:53 2008 New Revision: 617873 URL: http://svn.apache.org/viewvc?rev=617873&view=rev Log: forgot to add
Added: jakarta/bcel/trunk/src/main/java/org/apache/bcel/classfile/StackMapTable.java (with props) jakarta/bcel/trunk/src/main/java/org/apache/bcel/classfile/StackMapTableEntry.java (with props) Added: jakarta/bcel/trunk/src/main/java/org/apache/bcel/classfile/StackMapTable.java URL: http://svn.apache.org/viewvc/jakarta/bcel/trunk/src/main/java/org/apache/bcel/classfile/StackMapTable.java?rev=617873&view=auto ============================================================================== --- jakarta/bcel/trunk/src/main/java/org/apache/bcel/classfile/StackMapTable.java (added) +++ jakarta/bcel/trunk/src/main/java/org/apache/bcel/classfile/StackMapTable.java Sat Feb 2 11:50:53 2008 @@ -0,0 +1,153 @@ +/* + * Copyright 2000-2004 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +package org.apache.bcel.classfile; + +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.IOException; +import org.apache.bcel.Constants; + +/** + * This class represents a stack map attribute used for + * preverification of Java classes for the <a + * href="http://java.sun.com/j2me/"> Java 2 Micro Edition</a> + * (J2ME). This attribute is used by the <a + * href="http://java.sun.com/products/cldc/">KVM</a> and contained + * within the Code attribute of a method. See CLDC specification + * À?5.3.1.2 + * + * @version $Id$ + * @author <A HREF="mailto:[EMAIL PROTECTED]">M. Dahm</A> + * @see Code + * @see StackMapEntry + * @see StackMapType + */ +public final class StackMapTable extends Attribute implements Node { + + private int map_length; + private StackMapTableEntry[] map; // Table of stack map entries + + + /* + * @param name_index Index of name + * @param length Content length in bytes + * @param map Table of stack map entries + * @param constant_pool Array of constants + */ + public StackMapTable(int name_index, int length, StackMapTableEntry[] map, ConstantPool constant_pool) { + super(Constants.ATTR_STACK_MAP_TABLE, name_index, length, constant_pool); + setStackMapTable(map); + } + + + /** + * Construct object from file stream. + * @param name_index Index of name + * @param length Content length in bytes + * @param file Input stream + * @param constant_pool Array of constants + * @throws IOException + */ + StackMapTable(int name_index, int length, DataInputStream file, ConstantPool constant_pool) + throws IOException { + this(name_index, length, (StackMapTableEntry[]) null, constant_pool); + map_length = file.readUnsignedShort(); + map = new StackMapTableEntry[map_length]; + for (int i = 0; i < map_length; i++) { + map[i] = new StackMapTableEntry(file, constant_pool); + } + } + + + /** + * Dump line number table attribute to file stream in binary format. + * + * @param file Output file stream + * @throws IOException + */ + public final void dump( DataOutputStream file ) throws IOException { + super.dump(file); + file.writeShort(map_length); + for (int i = 0; i < map_length; i++) { + map[i].dump(file); + } + } + + + /** + * @return Array of stack map entries + */ + public final StackMapTableEntry[] getStackMapTable() { + return map; + } + + + /** + * @param map Array of stack map entries + */ + public final void setStackMapTable( StackMapTableEntry[] map ) { + this.map = map; + map_length = (map == null) ? 0 : map.length; + } + + + /** + * @return String representation. + */ + public final String toString() { + StringBuffer buf = new StringBuffer("StackMapTable("); + for (int i = 0; i < map_length; i++) { + buf.append(map[i].toString()); + if (i < map_length - 1) { + buf.append(", "); + } + } + buf.append(')'); + return buf.toString(); + } + + + /** + * @return deep copy of this attribute + */ + public Attribute copy( ConstantPool _constant_pool ) { + StackMapTable c = (StackMapTable) clone(); + c.map = new StackMapTableEntry[map_length]; + for (int i = 0; i < map_length; i++) { + c.map[i] = map[i].copy(); + } + c.constant_pool = _constant_pool; + return c; + } + + + /** + * Called by objects that are traversing the nodes of the tree implicitely + * defined by the contents of a Java class. I.e., the hierarchy of methods, + * fields, attributes, etc. spawns a tree of objects. + * + * @param v Visitor object + */ + public void accept( Visitor v ) { + v.visitStackMapTable(this); + } + + + public final int getMapLength() { + return map_length; + } +} Propchange: jakarta/bcel/trunk/src/main/java/org/apache/bcel/classfile/StackMapTable.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: jakarta/bcel/trunk/src/main/java/org/apache/bcel/classfile/StackMapTable.java ------------------------------------------------------------------------------ svn:keywords = Date Revision Author HeadURL Id Propchange: jakarta/bcel/trunk/src/main/java/org/apache/bcel/classfile/StackMapTable.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: jakarta/bcel/trunk/src/main/java/org/apache/bcel/classfile/StackMapTableEntry.java URL: http://svn.apache.org/viewvc/jakarta/bcel/trunk/src/main/java/org/apache/bcel/classfile/StackMapTableEntry.java?rev=617873&view=auto ============================================================================== --- jakarta/bcel/trunk/src/main/java/org/apache/bcel/classfile/StackMapTableEntry.java (added) +++ jakarta/bcel/trunk/src/main/java/org/apache/bcel/classfile/StackMapTableEntry.java Sat Feb 2 11:50:53 2008 @@ -0,0 +1,285 @@ +/* + * Copyright 2000-2004 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +package org.apache.bcel.classfile; + +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.IOException; + +import org.apache.bcel.Constants; + +/** + * This class represents a stack map entry recording the types of + * local variables and the the of stack items at a given byte code offset. + * See CLDC specification À?5.3.1.2 + * + * @version $Id$ + * @author <A HREF="mailto:[EMAIL PROTECTED]">M. Dahm</A> + * @see StackMap + * @see StackMapType + */ +public final class StackMapTableEntry implements Cloneable { + + private int frame_type; + private int byte_code_offset_delta; + private int number_of_locals; + private StackMapType[] types_of_locals; + private int number_of_stack_items; + private StackMapType[] types_of_stack_items; + private ConstantPool constant_pool; + + + /** + * Construct object from file stream. + * @param file Input stream + * @throws IOException + */ + StackMapTableEntry(DataInputStream file, ConstantPool constant_pool) throws IOException { + this(file.read(), -1, -1, null, -1, null, constant_pool); + + if (frame_type >= Constants.SAME_FRAME && frame_type <= Constants.SAME_FRAME_MAX) { + byte_code_offset_delta = frame_type - Constants.SAME_FRAME; + } else if (frame_type >= Constants.SAME_LOCALS_1_STACK_ITEM_FRAME && frame_type <= Constants.SAME_LOCALS_1_STACK_ITEM_FRAME_MAX) { + byte_code_offset_delta = frame_type - Constants.SAME_LOCALS_1_STACK_ITEM_FRAME; + number_of_stack_items = 1; + types_of_stack_items = new StackMapType[1]; + types_of_stack_items[0] = new StackMapType(file, constant_pool); + } else if (frame_type == Constants.SAME_LOCALS_1_STACK_ITEM_FRAME_EXTENDED) { + byte_code_offset_delta = file.readShort(); + number_of_stack_items = 1; + types_of_stack_items = new StackMapType[1]; + types_of_stack_items[0] = new StackMapType(file, constant_pool); + } else if (frame_type >= Constants.CHOP_FRAME && frame_type <= Constants.CHOP_FRAME_MAX) { + byte_code_offset_delta = file.readShort(); + } else if (frame_type == Constants.SAME_FRAME_EXTENDED) { + byte_code_offset_delta = file.readShort(); + } else if (frame_type >= Constants.APPEND_FRAME && frame_type <= Constants.APPEND_FRAME_MAX) { + byte_code_offset_delta = file.readShort(); + number_of_locals = frame_type - 251; + types_of_locals = new StackMapType[number_of_locals]; + for (int i = 0; i < number_of_locals; i++) { + types_of_locals[i] = new StackMapType(file, constant_pool); + } + } else if (frame_type == Constants.FULL_FRAME) { + byte_code_offset_delta = file.readShort(); + number_of_locals = file.readShort(); + types_of_locals = new StackMapType[number_of_locals]; + for (int i = 0; i < number_of_locals; i++) { + types_of_locals[i] = new StackMapType(file, constant_pool); + } + number_of_stack_items = file.readShort(); + types_of_stack_items = new StackMapType[number_of_stack_items]; + for (int i = 0; i < number_of_stack_items; i++) { + types_of_stack_items[i] = new StackMapType(file, constant_pool); + } + } else { + /* Can't happen */ + throw new ClassFormatException ("Illegal Tag"); + } + } + + + public StackMapTableEntry(int tag, int byte_code_offset_delta, int number_of_locals, + StackMapType[] types_of_locals, int number_of_stack_items, + StackMapType[] types_of_stack_items, ConstantPool constant_pool) { + this.frame_type = tag; + this.byte_code_offset_delta = byte_code_offset_delta; + this.number_of_locals = number_of_locals; + this.types_of_locals = types_of_locals; + this.number_of_stack_items = number_of_stack_items; + this.types_of_stack_items = types_of_stack_items; + this.constant_pool = constant_pool; + } + + + /** + * Dump stack map entry + * + * @param file Output file stream + * @throws IOException + */ + public final void dump( DataOutputStream file ) throws IOException { + file.write(frame_type); + if (frame_type >= Constants.SAME_LOCALS_1_STACK_ITEM_FRAME && frame_type <= Constants.SAME_LOCALS_1_STACK_ITEM_FRAME_MAX) { + types_of_stack_items[0].dump(file); + } else if (frame_type == Constants.SAME_LOCALS_1_STACK_ITEM_FRAME_EXTENDED) { + file.write(byte_code_offset_delta); + types_of_stack_items[0].dump(file); + } else if (frame_type >= Constants.CHOP_FRAME && frame_type <= Constants.CHOP_FRAME_MAX) { + file.write(byte_code_offset_delta); + } else if (frame_type == Constants.SAME_FRAME_EXTENDED) { + file.write(byte_code_offset_delta); + } else if (frame_type >= Constants.APPEND_FRAME && frame_type <= Constants.APPEND_FRAME_MAX) { + file.write(byte_code_offset_delta); + for (int i = 0; i < number_of_locals; i++) { + types_of_locals[i].dump(file); + } + } else if (frame_type == Constants.FULL_FRAME) { + file.writeShort(byte_code_offset_delta); + file.writeShort(number_of_locals); + for (int i = 0; i < number_of_locals; i++) { + types_of_locals[i].dump(file); + } + file.writeShort(number_of_stack_items); + for (int i = 0; i < number_of_stack_items; i++) { + types_of_stack_items[i].dump(file); + } + } else { + /* Can't happen */ + throw new ClassFormatException ("Illegal Tag"); + } + } + + + /** + * @return String representation. + */ + public final String toString() { + StringBuffer buf = new StringBuffer(64); + buf.append("("); + if (frame_type >= Constants.SAME_FRAME && frame_type <= Constants.SAME_FRAME_MAX) { + buf.append("SAME"); + } else if (frame_type >= Constants.SAME_LOCALS_1_STACK_ITEM_FRAME && frame_type <= Constants.SAME_LOCALS_1_STACK_ITEM_FRAME_MAX) { + buf.append("SAME_LOCALS_1_STACK"); + } else if (frame_type == Constants.SAME_LOCALS_1_STACK_ITEM_FRAME_EXTENDED) { + buf.append("SAME_LOCALS_1_STACK_EXTENDED"); + } else if (frame_type >= Constants.CHOP_FRAME && frame_type <= Constants.CHOP_FRAME_MAX) { + buf.append("CHOP "+(251-frame_type)); + } else if (frame_type == Constants.SAME_FRAME_EXTENDED) { + buf.append("SAME_EXTENDED"); + } else if (frame_type >= Constants.APPEND_FRAME && frame_type <= Constants.APPEND_FRAME_MAX) { + buf.append("APPEND "+(frame_type-251)); + } else if (frame_type == Constants.FULL_FRAME) { + buf.append("FULL"); + } else { + buf.append("UNKNOWN"); + } + buf.append(", offset delta=").append(byte_code_offset_delta); + if (number_of_locals > 0) { + buf.append(", locals={"); + for (int i = 0; i < number_of_locals; i++) { + buf.append(types_of_locals[i]); + if (i < number_of_locals - 1) { + buf.append(", "); + } + } + buf.append("}"); + } + if (number_of_stack_items > 0) { + buf.append(", stack items={"); + for (int i = 0; i < number_of_stack_items; i++) { + buf.append(types_of_stack_items[i]); + if (i < number_of_stack_items - 1) { + buf.append(", "); + } + } + buf.append("}"); + } + buf.append(")"); + return buf.toString(); + } + + + public void setByteCodeOffsetDelta( int b ) { + byte_code_offset_delta = b; + } + + + public int getByteCodeOffsetDelta() { + return byte_code_offset_delta; + } + + + public void setNumberOfLocals( int n ) { + number_of_locals = n; + } + + + public int getNumberOfLocals() { + return number_of_locals; + } + + + public void setTypesOfLocals( StackMapType[] t ) { + types_of_locals = t; + } + + + public StackMapType[] getTypesOfLocals() { + return types_of_locals; + } + + + public void setNumberOfStackItems( int n ) { + number_of_stack_items = n; + } + + + public int getNumberOfStackItems() { + return number_of_stack_items; + } + + + public void setTypesOfStackItems( StackMapType[] t ) { + types_of_stack_items = t; + } + + + public StackMapType[] getTypesOfStackItems() { + return types_of_stack_items; + } + + + /** + * @return deep copy of this object + */ + public StackMapTableEntry copy() { + try { + return (StackMapTableEntry) clone(); + } catch (CloneNotSupportedException e) { + } + return null; + } + + + /** + * Called by objects that are traversing the nodes of the tree implicitely + * defined by the contents of a Java class. I.e., the hierarchy of methods, + * fields, attributes, etc. spawns a tree of objects. + * + * @param v Visitor object + */ + public void accept( Visitor v ) { + v.visitStackMapTableEntry(this); + } + + + /** + * @return Constant pool used by this object. + */ + public final ConstantPool getConstantPool() { + return constant_pool; + } + + + /** + * @param constant_pool Constant pool to be used for this object. + */ + public final void setConstantPool( ConstantPool constant_pool ) { + this.constant_pool = constant_pool; + } +} Propchange: jakarta/bcel/trunk/src/main/java/org/apache/bcel/classfile/StackMapTableEntry.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: jakarta/bcel/trunk/src/main/java/org/apache/bcel/classfile/StackMapTableEntry.java ------------------------------------------------------------------------------ svn:keywords = Date Revision Author HeadURL Id Propchange: jakarta/bcel/trunk/src/main/java/org/apache/bcel/classfile/StackMapTableEntry.java ------------------------------------------------------------------------------ svn:mime-type = text/plain --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]