You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openjpa.apache.org by pc...@apache.org on 2006/07/01 00:37:29 UTC
svn commit: r418401 [27/32] - in /incubator/openjpa/trunk: openjpa-lib/
openjpa-lib/src/main/java/org/apache/openjpa/lib/ant/
openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/
openjpa-lib/src/main/java/org/apache/openjpa/lib/jdbc/ openjpa-lib/src/...
Modified: incubator/openjpa/trunk/serp/src/main/java/serp/bytecode/LoadInstruction.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/serp/src/main/java/serp/bytecode/LoadInstruction.java?rev=418401&r1=418400&r2=418401&view=diff
==============================================================================
--- incubator/openjpa/trunk/serp/src/main/java/serp/bytecode/LoadInstruction.java (original)
+++ incubator/openjpa/trunk/serp/src/main/java/serp/bytecode/LoadInstruction.java Fri Jun 30 15:37:18 2006
@@ -1,13 +1,10 @@
/*
* Copyright 2006 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
+ * 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
+ * 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
@@ -15,24 +12,20 @@
*/
package serp.bytecode;
-import serp.bytecode.visitor.*;
-
import java.io.*;
-
+import serp.bytecode.visitor.*;
/**
- * <p>Loads a value from the locals table to the stack.</p>
- *
- * @author Abe White
+ * Loads a value from the locals table to the stack.
+ *
+ * @author Abe White
*/
public class LoadInstruction extends LocalVariableInstruction {
private static final Class[][] _mappings = new Class[][] {
- { byte.class, int.class },
- { boolean.class, int.class },
- { char.class, int.class },
- { short.class, int.class },
- { void.class, int.class },
- };
+ { byte.class, int.class }, { boolean.class, int.class },
+ { char.class, int.class }, { short.class, int.class },
+ { void.class, int.class }, };
+
String _type = null;
LoadInstruction(Code owner) {
@@ -51,7 +44,6 @@
case Constants.DLOAD:
case Constants.ALOAD:
return super.getLength() + 1;
-
default:
return super.getLength();
}
@@ -70,10 +62,8 @@
case Constants.DLOAD2:
case Constants.DLOAD3:
return 2;
-
case Constants.NOP:
return 0;
-
default:
return 1;
}
@@ -83,7 +73,6 @@
switch (getOpcode()) {
case Constants.NOP:
return 0;
-
default:
return 1;
}
@@ -97,35 +86,30 @@
case Constants.ILOAD2:
case Constants.ILOAD3:
return int.class.getName();
-
case Constants.LLOAD:
case Constants.LLOAD0:
case Constants.LLOAD1:
case Constants.LLOAD2:
case Constants.LLOAD3:
return long.class.getName();
-
case Constants.FLOAD:
case Constants.FLOAD0:
case Constants.FLOAD1:
case Constants.FLOAD2:
case Constants.FLOAD3:
return float.class.getName();
-
case Constants.DLOAD:
case Constants.DLOAD0:
case Constants.DLOAD1:
case Constants.DLOAD2:
case Constants.DLOAD3:
return double.class.getName();
-
case Constants.ALOAD:
case Constants.ALOAD0:
case Constants.ALOAD1:
case Constants.ALOAD2:
case Constants.ALOAD3:
return Object.class.getName();
-
default:
return _type;
}
@@ -133,14 +117,12 @@
public TypedInstruction setType(String type) {
type = mapType(type, _mappings, true);
-
int local = getLocal();
// if an invalid type or local, revert to nop
- if ((type == null) || (local < 0)) {
+ if (type == null || local < 0) {
_type = type;
-
- return (TypedInstruction) setOpcode(Constants.NOP);
+ return(TypedInstruction) setOpcode(Constants.NOP);
}
// valid opcode, unset saved type
@@ -148,68 +130,56 @@
switch (type.charAt(0)) {
case 'i':
- return (TypedInstruction) setOpcode((local > 3) ? Constants.ILOAD
- : (Constants.ILOAD0 +
- local));
-
+ return(TypedInstruction) setOpcode((local > 3) ? Constants.ILOAD
+ : Constants.ILOAD0 + local);
case 'l':
- return (TypedInstruction) setOpcode((local > 3) ? Constants.LLOAD
- : (Constants.LLOAD0 +
- local));
-
+ return(TypedInstruction) setOpcode((local > 3) ? Constants.LLOAD
+ : Constants.LLOAD0 + local);
case 'f':
- return (TypedInstruction) setOpcode((local > 3) ? Constants.FLOAD
- : (Constants.FLOAD0 +
- local));
-
+ return(TypedInstruction) setOpcode((local > 3) ? Constants.FLOAD
+ : Constants.FLOAD0 + local);
case 'd':
- return (TypedInstruction) setOpcode((local > 3) ? Constants.DLOAD
- : (Constants.DLOAD0 +
- local));
-
+ return(TypedInstruction) setOpcode((local > 3) ? Constants.DLOAD
+ : Constants.DLOAD0 + local);
default:
- return (TypedInstruction) setOpcode((local > 3) ? Constants.ALOAD
- : (Constants.ALOAD0 +
- local));
+ return(TypedInstruction) setOpcode((local > 3) ? Constants.ALOAD
+ : Constants.ALOAD0 + local);
}
}
/**
- * Equivalent to <code>setLocal (0).setType (Object.class)</code>; the
- * <code>this</code> ptr is always passed in local variable 0.
- *
- * @return this instruction, for method chaining
+ * Equivalent to <code>setLocal(0).setType(Object.class)</code>; the
+ * <code>this</code> ptr is always passed in local variable 0.
+ *
+ * @return this instruction, for method chaining
*/
public LoadInstruction setThis() {
- return (LoadInstruction) setLocal(0).setType(Object.class);
+ return(LoadInstruction) setLocal(0).setType(Object.class);
}
/**
- * Equivalent to <code>getLocal () == 0 && getType () ==
- * Object.class</code>; the <code>this</code> ptr
- * is always passed in local variable 0.
+ * Equivalent to <code>getLocal() == 0 && getType() ==
+ * Object.class</code>; the <code>this</code> ptr
+ * is always passed in local variable 0.
*/
public boolean isThis() {
- return (getLocal() == 0) && (getType() == Object.class);
+ return getLocal() == 0 && getType() == Object.class;
}
/**
- * LoadInstructions are equal if the type they reference the same
- * type and locals index or if either is unset.
+ * LoadInstructions are equal if the type they reference the same
+ * type and locals index or if either is unset.
*/
public boolean equalsInstruction(Instruction other) {
- if (other == this) {
+ if (other == this)
return true;
- }
-
- if (!super.equalsInstruction(other)) {
+ if (!super.equalsInstruction(other))
return false;
- }
String type = getTypeName();
String otherType = ((LoadInstruction) other).getTypeName();
- return (type == null) || (otherType == null) || type.equals(otherType);
+ return type == null || otherType == null || type.equals(otherType);
}
public void acceptVisit(BCVisitor visit) {
@@ -234,7 +204,6 @@
case Constants.DLOAD:
case Constants.ALOAD:
setLocal(in.readUnsignedByte());
-
break;
}
}
@@ -265,34 +234,27 @@
case Constants.DLOAD0:
case Constants.ALOAD0:
setLocal(0);
-
break;
-
case Constants.ILOAD1:
case Constants.LLOAD1:
case Constants.FLOAD1:
case Constants.DLOAD1:
case Constants.ALOAD1:
setLocal(1);
-
break;
-
case Constants.ILOAD2:
case Constants.LLOAD2:
case Constants.FLOAD2:
case Constants.DLOAD2:
case Constants.ALOAD2:
setLocal(2);
-
break;
-
case Constants.ILOAD3:
case Constants.LLOAD3:
case Constants.FLOAD3:
case Constants.DLOAD3:
case Constants.ALOAD3:
setLocal(3);
-
break;
}
}
Modified: incubator/openjpa/trunk/serp/src/main/java/serp/bytecode/Local.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/serp/src/main/java/serp/bytecode/Local.java?rev=418401&r1=418400&r2=418401&view=diff
==============================================================================
--- incubator/openjpa/trunk/serp/src/main/java/serp/bytecode/Local.java (original)
+++ incubator/openjpa/trunk/serp/src/main/java/serp/bytecode/Local.java Fri Jun 30 15:37:18 2006
@@ -1,13 +1,10 @@
/*
* Copyright 2006 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
+ * 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
+ * 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
@@ -15,25 +12,21 @@
*/
package serp.bytecode;
+import java.io.*;
+import java.util.*;
import serp.bytecode.lowlevel.*;
-
import serp.bytecode.visitor.*;
-
import serp.util.*;
-import java.io.*;
-
-import java.util.*;
-
-
/**
- * <p>A local variable or local variable type.</p>
- *
- * @author Abe White
+ * A local variable or local variable type.
+ *
+ * @author Abe White
*/
public abstract class Local implements BCEntity, InstructionPtr {
private LocalTable _owner = null;
private InstructionPtrStrategy _target = new InstructionPtrStrategy(this);
+
private int _length = 0;
private int _nameIndex = 0;
private int _descriptorIndex = 0;
@@ -44,7 +37,7 @@
}
/**
- * The owning table.
+ * The owning table.
*/
public LocalTable getTable() {
return _owner;
@@ -59,35 +52,35 @@
//////////////////////////
/**
- * Get the local variable index of the current frame for this local.
+ * Get the local variable index of the current frame for this local.
*/
public int getLocal() {
return _index;
}
/**
- * Set the local variable index of the current frame for this local.
+ * Set the local variable index of the current frame for this local.
*/
public void setLocal(int index) {
_index = index;
}
/**
- * Return the parameter that this local corresponds to, or -1 if none.
+ * Return the parameter that this local corresponds to, or -1 if none.
*/
public int getParam() {
return getCode().getParamsIndex(getLocal());
}
/**
- * Set the method parameter that this local corresponds to.
+ * Set the method parameter that this local corresponds to.
*/
public void setParam(int param) {
setLocal(_owner.getCode().getLocalsIndex(param));
}
/**
- * Return the index into the code byte array at which this local starts.
+ * Return the index into the code byte array at which this local starts.
*/
public int getStartPc() {
return _target.getByteIndex();
@@ -98,23 +91,23 @@
////////////////////////////
/**
- * Return the instruction marking the beginning of this local.
+ * Return the instruction marking the beginning of this local.
*/
public Instruction getStart() {
return _target.getTargetInstruction();
}
/**
- * Set the index into the code byte array at which this local starts.
+ * Set the index into the code byte array at which this local starts.
*/
public void setStartPc(int startPc) {
_target.setByteIndex(startPc);
}
/**
- * Set the {@link Instruction} marking the beginning this local.
- * The instruction must already be a part of the method.
- * WARNING: if this instruction is deleted, the results are undefined.
+ * Set the {@link Instruction} marking the beginning this local.
+ * The instruction must already be a part of the method.
+ * WARNING: if this instruction is deleted, the results are undefined.
*/
public void setStart(Instruction instruction) {
_target.setTargetInstruction(instruction);
@@ -129,16 +122,16 @@
}
/**
- * Get the number of bytes for which this local has a value in
- * the code byte array.
+ * Get the number of bytes for which this local has a value in
+ * the code byte array.
*/
public int getLength() {
return _length;
}
/**
- * Set the number of bytes for which this local has a value in
- * the code byte array.
+ * Set the number of bytes for which this local has a value in
+ * the code byte array.
*/
public void setLength(int length) {
_length = length;
@@ -149,80 +142,75 @@
/////////////////////////
/**
- * Return the {@link ConstantPool} index of the {@link UTF8Entry} that
- * describes the name of this local. Defaults to 0.
+ * Return the {@link ConstantPool} index of the {@link UTF8Entry} that
+ * describes the name of this local. Defaults to 0.
*/
public int getNameIndex() {
return _nameIndex;
}
/**
- * Set the {@link ConstantPool} index of the {@link UTF8Entry} that
- * describes the name of this local.
+ * Set the {@link ConstantPool} index of the {@link UTF8Entry} that
+ * describes the name of this local.
*/
public void setNameIndex(int nameIndex) {
_nameIndex = nameIndex;
}
/**
- * Return the name of this local, or null if unset.
+ * Return the name of this local, or null if unset.
*/
public String getName() {
- if (getNameIndex() == 0) {
+ if (getNameIndex() == 0)
return null;
- }
-
- return ((UTF8Entry) getPool().getEntry(getNameIndex())).getValue();
+ return((UTF8Entry) getPool().getEntry(getNameIndex())).getValue();
}
/**
- * Set the name of this inner local.
+ * Set the name of this inner local.
*/
public void setName(String name) {
- if (name == null) {
+ if (name == null)
setNameIndex(0);
- } else {
+ else
setNameIndex(getPool().findUTF8Entry(name, true));
- }
}
/**
- * Return the {@link ConstantPool} index of the {@link UTF8Entry} that
- * describes this local. Defaults to 0.
+ * Return the {@link ConstantPool} index of the {@link UTF8Entry} that
+ * describes this local. Defaults to 0.
*/
public int getTypeIndex() {
return _descriptorIndex;
}
/**
- * Set the {@link ConstantPool} index of the {@link UTF8Entry} that
- * describes this local.
+ * Set the {@link ConstantPool} index of the {@link UTF8Entry} that
+ * describes this local.
*/
public void setTypeIndex(int index) {
_descriptorIndex = index;
}
/**
- * Return the full name of the local's type, or null if unset.
+ * Return the full name of the local's type, or null if unset.
*/
public String getTypeName() {
- if (getTypeIndex() == 0) {
+ if (getTypeIndex() == 0)
return null;
- }
UTF8Entry entry = (UTF8Entry) getPool().getEntry(getTypeIndex());
-
- return getProject().getNameCache()
- .getExternalForm(entry.getValue(), false);
+ return getProject().getNameCache().getExternalForm
+ (entry.getValue(), false);
}
/**
- * Set the type of this local.
+ * Set the type of this local.
*/
public void setType(String type) {
- if (type == null) {
+ if (type == null)
setTypeIndex(0);
- } else {
+ else {
type = getProject().getNameCache().getInternalForm(type, true);
setTypeIndex(getPool().findUTF8Entry(type, true));
}
@@ -231,6 +219,7 @@
///////////////////////////
// BCEntity implementation
///////////////////////////
+
public Project getProject() {
return _owner.getProject();
}
@@ -250,6 +239,7 @@
//////////////////
// I/O operations
//////////////////
+
void read(DataInput in) throws IOException {
setStartPc(in.readUnsignedShort());
setLength(in.readUnsignedShort());
Modified: incubator/openjpa/trunk/serp/src/main/java/serp/bytecode/LocalTable.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/serp/src/main/java/serp/bytecode/LocalTable.java?rev=418401&r1=418400&r2=418401&view=diff
==============================================================================
--- incubator/openjpa/trunk/serp/src/main/java/serp/bytecode/LocalTable.java (original)
+++ incubator/openjpa/trunk/serp/src/main/java/serp/bytecode/LocalTable.java Fri Jun 30 15:37:18 2006
@@ -1,13 +1,10 @@
/*
* Copyright 2006 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
+ * 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
+ * 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
@@ -15,18 +12,15 @@
*/
package serp.bytecode;
-import serp.bytecode.visitor.*;
-
import java.io.*;
-
import java.util.*;
-
+import serp.bytecode.visitor.*;
/**
- * <p>Code blocks compiled from source have local tables mapping
- * locals used in opcodes to their names and descriptions.</p>
- *
- * @author Abe White
+ * Code blocks compiled from source have local tables mapping
+ * locals used in opcodes to their names and descriptions.
+ *
+ * @author Abe White
*/
public abstract class LocalTable extends Attribute implements InstructionPtr {
private List _locals = new ArrayList();
@@ -36,161 +30,143 @@
}
/**
- * Return all the locals of this method.
+ * Return all the locals of this method.
*/
public Local[] getLocals() {
- return (Local[]) _locals.toArray(newLocalArray(_locals.size()));
+ return(Local[]) _locals.toArray(newLocalArray(_locals.size()));
}
/**
- * Return the local with the given locals index, or null if none.
+ * Return the local with the given locals index, or null if none.
*/
public Local getLocal(int local) {
for (int i = 0; i < _locals.size(); i++)
- if (((Local) _locals.get(i)).getLocal() == local) {
- return (Local) _locals.get(i);
- }
-
+ if (((Local) _locals.get(i)).getLocal() == local)
+ return(Local) _locals.get(i);
return null;
}
/**
- * Return the local with the given name, or null if none. If multiple
- * locals have the given name, which is returned is undefined.
+ * Return the local with the given name, or null if none. If multiple
+ * locals have the given name, which is returned is undefined.
*/
public Local getLocal(String name) {
String loc;
-
for (int i = 0; i < _locals.size(); i++) {
loc = ((Local) _locals.get(i)).getName();
-
- if (((loc == null) && (name == null)) ||
- ((loc != null) && loc.equals(name))) {
- return (Local) _locals.get(i);
- }
+ if ((loc == null && name == null)
+ || (loc != null && loc.equals(name)))
+ return(Local) _locals.get(i);
}
-
return null;
}
/**
- * Return all locals with the given name, or empty array if none.
+ * Return all locals with the given name, or empty array if none.
*/
public Local[] getLocals(String name) {
List matches = new LinkedList();
String loc;
-
for (int i = 0; i < _locals.size(); i++) {
loc = ((Local) _locals.get(i)).getName();
-
- if (((loc == null) && (name == null)) ||
- ((loc != null) && loc.equals(name))) {
+ if ((loc == null && name == null)
+ || (loc != null && loc.equals(name)))
matches.add(_locals.get(i));
- }
}
-
- return (Local[]) matches.toArray(newLocalArray(matches.size()));
+ return(Local[]) matches.toArray(newLocalArray(matches.size()));
}
/**
- * Set the locals of this table. This method is useful when
- * importing locals from another method.
+ * Set the locals of this table. This method is useful when
+ * importing locals from another method.
*/
public void setLocals(Local[] locals) {
clear();
-
- if (locals != null) {
+ if (locals != null)
for (int i = 0; i < locals.length; i++)
addLocal(locals[i]);
- }
}
/**
- * Import a local from another method/class. Note that
- * the program counter and length from the given local is copied
- * directly, and thus will be incorrect unless this method is the same
- * as the one the local is copied from, or the pc and length are reset.
+ * Import a local from another method/class. Note that
+ * the program counter and length from the given local is copied
+ * directly, and thus will be incorrect unless this method is the same
+ * as the one the local is copied from, or the pc and length are reset.
*/
public Local addLocal(Local local) {
Local newLocal = addLocal(local.getName(), local.getTypeName());
newLocal.setStartPc(local.getStartPc());
newLocal.setLength(local.getLength());
-
return newLocal;
}
/**
- * Add a local to this table.
+ * Add a local to this table.
*/
public Local addLocal() {
Local local = newLocal();
_locals.add(local);
-
return local;
}
/**
- * Create a new element of this table.
+ * Create a new element of this table.
*/
protected abstract Local newLocal();
/**
- * Create a new array.
+ * Create a new array.
*/
protected abstract Local[] newLocalArray(int size);
/**
- * Add a local to this table.
+ * Add a local to this table.
*/
public Local addLocal(String name, String type) {
Local local = addLocal();
local.setName(name);
local.setType(type);
-
return local;
}
/**
- * Clear all locals from this table.
+ * Clear all locals from this table.
*/
public void clear() {
for (int i = 0; i < _locals.size(); i++)
((Local) _locals.get(i)).invalidate();
-
_locals.clear();
}
/**
- * Removes the local with the given locals index from the table.
- *
- * @return true if a local was removed, false otherwise
+ * Removes the local with the given locals index from the table.
+ *
+ * @return true if a local was removed, false otherwise
*/
public boolean removeLocal(int local) {
return removeLocal(getLocal(local));
}
/**
- * Removes the local with the given name from this method.
- *
- * @return true if a local was removed, false otherwise
+ * Removes the local with the given name from this method.
+ *
+ * @return true if a local was removed, false otherwise
*/
public boolean removeLocal(String name) {
return removeLocal(getLocal(name));
}
/**
- * Removes a local from this method. After this method, the local
- * will be invalid, and the result of any operations on it is undefined.
- *
- * @return true if a local was removed, false otherwise
+ * Removes a local from this method. After this method, the local
+ * will be invalid, and the result of any operations on it is undefined.
+ *
+ * @return true if a local was removed, false otherwise
*/
public boolean removeLocal(Local local) {
- if ((local == null) || !_locals.remove(local)) {
+ if (local == null || !_locals.remove(local))
return false;
- }
local.invalidate();
-
return true;
}
@@ -205,11 +181,11 @@
}
public Code getCode() {
- return (Code) getOwner();
+ return(Code) getOwner();
}
int getLength() {
- return 2 + (10 * _locals.size());
+ return 2 + 10 * _locals.size();
}
void read(Attribute other) {
@@ -218,11 +194,9 @@
void read(DataInput in, int length) throws IOException {
clear();
-
int numLocals = in.readUnsignedShort();
Local Local;
-
for (int i = 0; i < numLocals; i++) {
Local = addLocal();
Local.read(in);
@@ -231,7 +205,6 @@
void write(DataOutput out, int length) throws IOException {
out.writeShort(_locals.size());
-
for (int i = 0; i < _locals.size(); i++)
((Local) _locals.get(i)).write(out);
}
Modified: incubator/openjpa/trunk/serp/src/main/java/serp/bytecode/LocalVariable.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/serp/src/main/java/serp/bytecode/LocalVariable.java?rev=418401&r1=418400&r2=418401&view=diff
==============================================================================
--- incubator/openjpa/trunk/serp/src/main/java/serp/bytecode/LocalVariable.java (original)
+++ incubator/openjpa/trunk/serp/src/main/java/serp/bytecode/LocalVariable.java Fri Jun 30 15:37:18 2006
@@ -1,13 +1,10 @@
/*
* Copyright 2006 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
+ * 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
+ * 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
@@ -16,15 +13,13 @@
package serp.bytecode;
import serp.bytecode.visitor.*;
-
import serp.util.*;
-
/**
- * <p>A local variable contains the name, description, index and scope
- * of a local used in opcodes.</p>
- *
- * @author Abe White
+ * A local variable contains the name, description, index and scope
+ * of a local used in opcodes.
+ *
+ * @author Abe White
*/
public class LocalVariable extends Local {
LocalVariable(LocalVariableTable owner) {
@@ -32,60 +27,52 @@
}
/**
- * The owning table.
+ * The owning table.
*/
public LocalVariableTable getLocalVariableTable() {
- return (LocalVariableTable) getTable();
+ return(LocalVariableTable) getTable();
}
/**
- * Return the type of this local.
- * If the type has not been set, this method will return null.
+ * Return the type of this local.
+ * If the type has not been set, this method will return null.
*/
public Class getType() {
String type = getTypeName();
-
- if (type == null) {
+ if (type == null)
return null;
- }
-
return Strings.toClass(type, getClassLoader());
}
/**
- * Return the type of this local.
- * If the type has not been set, this method will return null.
+ * Return the type of this local.
+ * If the type has not been set, this method will return null.
*/
public BCClass getTypeBC() {
String type = getTypeName();
-
- if (type == null) {
+ if (type == null)
return null;
- }
-
return getProject().loadClass(type, getClassLoader());
}
/**
- * Set the type of this local.
+ * Set the type of this local.
*/
public void setType(Class type) {
- if (type == null) {
+ if (type == null)
setType((String) null);
- } else {
+ else
setType(type.getName());
- }
}
/**
- * Set the type of this local.
+ * Set the type of this local.
*/
public void setType(BCClass type) {
- if (type == null) {
+ if (type == null)
setType((String) null);
- } else {
+ else
setType(type.getName());
- }
}
public void acceptVisit(BCVisitor visit) {
Modified: incubator/openjpa/trunk/serp/src/main/java/serp/bytecode/LocalVariableInstruction.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/serp/src/main/java/serp/bytecode/LocalVariableInstruction.java?rev=418401&r1=418400&r2=418401&view=diff
==============================================================================
--- incubator/openjpa/trunk/serp/src/main/java/serp/bytecode/LocalVariableInstruction.java (original)
+++ incubator/openjpa/trunk/serp/src/main/java/serp/bytecode/LocalVariableInstruction.java Fri Jun 30 15:37:18 2006
@@ -1,13 +1,10 @@
/*
* Copyright 2006 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
+ * 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
+ * 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
@@ -17,22 +14,18 @@
import serp.bytecode.visitor.*;
-
/**
- * <p>An instruction that has an argument of an index into the
- * local variable table of the current frame. This includes most of the
- * <code>load</code> and <code>store</code> instructions.</p>
- *
- * <p>The local variable table size is fixed by the <code>maxLocals</code>
- * property of the code block. Long and double types take up 2 local variable
- * indexes.</p>
- *
- * <p>Parameter values to methods are loaded into the local variable table
- * prior to the execution of the first instruction. The 0 index of the
- * table is set to the instance of the class the method is being invoked
- * on.</p>
- *
- * @author Abe White
+ * An instruction that has an argument of an index into the
+ * local variable table of the current frame. This includes most of the
+ * <code>load</code> and <code>store</code> instructions.
+ * The local variable table size is fixed by the <code>maxLocals</code>
+ * property of the code block. Long and double types take up 2 local variable
+ * indexes.
+ * Parameter values to methods are loaded into the local variable table
+ * prior to the execution of the first instruction. The 0 index of the
+ * table is set to the instance of the class the method is being invoked on.
+ *
+ * @author Abe White
*/
public abstract class LocalVariableInstruction extends TypedInstruction {
private int _index = -1;
@@ -55,18 +48,16 @@
}
/**
- * Return the index of the local variable that this instruction
- * operates on.
+ * Return the index of the local variable that this instruction operates on.
*/
public int getLocal() {
return _index;
}
/**
- * Set the index of the local variable that this instruction
- * operates on.
- *
- * @return this instruction, for method chaining
+ * Set the index of the local variable that this instruction operates on.
+ *
+ * @return this instruction, for method chaining
*/
public LocalVariableInstruction setLocal(int index) {
_index = index;
@@ -76,83 +67,71 @@
}
/**
- * Return the parameter that this instruction operates on, or -1 if none.
+ * Return the parameter that this instruction operates on, or -1 if none.
*/
public int getParam() {
return getCode().getParamsIndex(getLocal());
}
/**
- * Set the method parameter that this instruction operates on. This
- * will set both the local index and the type of the instruction based
- * on the current method parameters.
+ * Set the method parameter that this instruction operates on. This
+ * will set both the local index and the type of the instruction based
+ * on the current method parameters.
*/
public LocalVariableInstruction setParam(int param) {
int local = getCode().getLocalsIndex(param);
-
if (local != -1) {
BCMethod method = getCode().getMethod();
setType(method.getParamNames()[param]);
}
-
return setLocal(local);
}
/**
- * Return the local variable object this instruction
- * operates on, or null if none.
- *
- * @see LocalVariableTable#getLocalVariable(int)
+ * Return the local variable object this instruction
+ * operates on, or null if none.
+ *
+ * @see LocalVariableTable#getLocalVariable(int)
*/
public LocalVariable getLocalVariable() {
LocalVariableTable table = getCode().getLocalVariableTable(false);
-
- if (table == null) {
+ if (table == null)
return null;
- }
-
return table.getLocalVariable(getLocal());
}
/**
- * Set the local variable object this instruction
- * operates on. This method will set both the type and local index
- * of this instruction from the given local variable.
- *
- * @return this instruction, for method chaining
+ * Set the local variable object this instruction
+ * operates on. This method will set both the type and local index
+ * of this instruction from the given local variable.
+ *
+ * @return this instruction, for method chaining
*/
public LocalVariableInstruction setLocalVariable(LocalVariable local) {
- if (local == null) {
+ if (local == null)
return setLocal(-1);
- } else {
+ else {
String type = local.getTypeName();
-
- if (type != null) {
+ if (type != null)
setType(type);
- }
-
return setLocal(local.getLocal());
}
}
/**
- * Two local variable instructions are equal if the local index they
- * reference is equal or if either index is 0/unset.
+ * Two local variable instructions are equal if the local index they
+ * reference is equal or if either index is 0/unset.
*/
public boolean equalsInstruction(Instruction other) {
- if (this == other) {
+ if (this == other)
return true;
- }
-
- if (!getClass().equals(other.getClass())) {
+ if (!getClass().equals(other.getClass()))
return false;
- }
LocalVariableInstruction ins = (LocalVariableInstruction) other;
int index = getLocal();
int insIndex = ins.getLocal();
-
- return (index == -1) || (insIndex == -1) || (index == insIndex);
+ return index == -1 || insIndex == -1 || index == insIndex;
}
void read(Instruction orig) {
@@ -161,16 +140,15 @@
}
/**
- * Subclasses with variable opcodes can use this method to be
- * notified that information possibly affecting the opcode has been
- * changed.
+ * Subclasses with variable opcodes can use this method to be
+ * notified that information possibly affecting the opcode has been changed.
*/
void calculateOpcode() {
}
/**
- * Subclasses can use this method to calculate
- * the locals index based on their opcode.
+ * Subclasses can use this method to calculate
+ * the locals index based on their opcode.
*/
void calculateLocal() {
}
Modified: incubator/openjpa/trunk/serp/src/main/java/serp/bytecode/LocalVariableTable.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/serp/src/main/java/serp/bytecode/LocalVariableTable.java?rev=418401&r1=418400&r2=418401&view=diff
==============================================================================
--- incubator/openjpa/trunk/serp/src/main/java/serp/bytecode/LocalVariableTable.java (original)
+++ incubator/openjpa/trunk/serp/src/main/java/serp/bytecode/LocalVariableTable.java Fri Jun 30 15:37:18 2006
@@ -1,13 +1,10 @@
/*
* Copyright 2006 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
+ * 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
+ * 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
@@ -17,12 +14,11 @@
import serp.bytecode.visitor.*;
-
/**
- * <p>Code blocks compiled from source have local variable tables mapping
- * locals used in opcodes to their names and descriptions.</p>
- *
- * @author Abe White
+ * Code blocks compiled from source have local variable tables mapping
+ * locals used in opcodes to their names and descriptions.
+ *
+ * @author Abe White
*/
public class LocalVariableTable extends LocalTable {
LocalVariableTable(int nameIndex, Attributes owner) {
@@ -30,73 +26,71 @@
}
/**
- * Return all the locals of this method.
+ * Return all the locals of this method.
*/
public LocalVariable[] getLocalVariables() {
- return (LocalVariable[]) getLocals();
+ return(LocalVariable[]) getLocals();
}
/**
- * Return the local with the given locals index, or null if none.
+ * Return the local with the given locals index, or null if none.
*/
public LocalVariable getLocalVariable(int local) {
- return (LocalVariable) getLocal(local);
+ return(LocalVariable) getLocal(local);
}
/**
- * Return the local with the given name, or null if none. If multiple
- * locals have the given name, which is returned is undefined.
+ * Return the local with the given name, or null if none. If multiple
+ * locals have the given name, which is returned is undefined.
*/
public LocalVariable getLocalVariable(String name) {
- return (LocalVariable) getLocal(name);
+ return(LocalVariable) getLocal(name);
}
/**
- * Return all locals with the given name, or empty array if none.
+ * Return all locals with the given name, or empty array if none.
*/
public LocalVariable[] getLocalVariables(String name) {
- return (LocalVariable[]) getLocals(name);
+ return(LocalVariable[]) getLocals(name);
}
/**
- * Import a local from another method/class. Note that
- * the program counter and length from the given local is copied
- * directly, and thus will be incorrect unless this method is the same
- * as the one the local is copied from, or the pc and length are reset.
+ * Import a local from another method/class. Note that
+ * the program counter and length from the given local is copied
+ * directly, and thus will be incorrect unless this method is the same
+ * as the one the local is copied from, or the pc and length are reset.
*/
public LocalVariable addLocalVariable(LocalVariable local) {
- return (LocalVariable) addLocal(local);
+ return(LocalVariable) addLocal(local);
}
/**
- * Add a local to this table.
+ * Add a local to this table.
*/
public LocalVariable addLocalVariable() {
- return (LocalVariable) addLocal();
+ return(LocalVariable) addLocal();
}
/**
- * Add a local to this table.
+ * Add a local to this table.
*/
public LocalVariable addLocalVariable(String name, String type) {
- return (LocalVariable) addLocal(name, type);
+ return(LocalVariable) addLocal(name, type);
}
/**
- * Add a local to this table.
+ * Add a local to this table.
*/
public LocalVariable addLocalVariable(String name, Class type) {
String typeName = (type == null) ? null : type.getName();
-
return addLocalVariable(name, typeName);
}
/**
- * Add a local to this table.
+ * Add a local to this table.
*/
public LocalVariable addLocalVariable(String name, BCClass type) {
String typeName = (type == null) ? null : type.getName();
-
return addLocalVariable(name, typeName);
}
@@ -104,7 +98,6 @@
visit.enterLocalVariableTable(this);
LocalVariable[] locals = (LocalVariable[]) getLocals();
-
for (int i = 0; i < locals.length; i++)
locals[i].acceptVisit(visit);
Modified: incubator/openjpa/trunk/serp/src/main/java/serp/bytecode/LocalVariableType.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/serp/src/main/java/serp/bytecode/LocalVariableType.java?rev=418401&r1=418400&r2=418401&view=diff
==============================================================================
--- incubator/openjpa/trunk/serp/src/main/java/serp/bytecode/LocalVariableType.java (original)
+++ incubator/openjpa/trunk/serp/src/main/java/serp/bytecode/LocalVariableType.java Fri Jun 30 15:37:18 2006
@@ -1,13 +1,10 @@
/*
* Copyright 2006 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
+ * 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
+ * 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
@@ -17,12 +14,11 @@
import serp.bytecode.visitor.*;
-
/**
- * <p>A local variable type contains the name, signature, index and scope
- * of a generics-using local used in opcodes.</p>
- *
- * @author Abe White
+ * A local variable type contains the name, signature, index and scope
+ * of a generics-using local used in opcodes.
+ *
+ * @author Abe White
*/
public class LocalVariableType extends Local {
LocalVariableType(LocalVariableTypeTable owner) {
@@ -30,10 +26,10 @@
}
/**
- * The owning table.
+ * The owning table.
*/
public LocalVariableTypeTable getLocalVariableTypeTable() {
- return (LocalVariableTypeTable) getTable();
+ return(LocalVariableTypeTable) getTable();
}
public void acceptVisit(BCVisitor visit) {
Modified: incubator/openjpa/trunk/serp/src/main/java/serp/bytecode/LocalVariableTypeTable.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/serp/src/main/java/serp/bytecode/LocalVariableTypeTable.java?rev=418401&r1=418400&r2=418401&view=diff
==============================================================================
--- incubator/openjpa/trunk/serp/src/main/java/serp/bytecode/LocalVariableTypeTable.java (original)
+++ incubator/openjpa/trunk/serp/src/main/java/serp/bytecode/LocalVariableTypeTable.java Fri Jun 30 15:37:18 2006
@@ -1,13 +1,10 @@
/*
* Copyright 2006 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
+ * 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
+ * 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
@@ -17,12 +14,11 @@
import serp.bytecode.visitor.*;
-
/**
- * <p>Code blocks compiled from source have local variable type tables mapping
- * generics-using locals used in opcodes to their names and signatures.</p>
- *
- * @author Abe White
+ * Code blocks compiled from source have local variable type tables mapping
+ * generics-using locals used in opcodes to their names and signatures.
+ *
+ * @author Abe White
*/
public class LocalVariableTypeTable extends LocalTable {
LocalVariableTypeTable(int nameIndex, Attributes owner) {
@@ -30,63 +26,62 @@
}
/**
- * Return all the locals of this method.
+ * Return all the locals of this method.
*/
public LocalVariableType[] getLocalVariableTypes() {
- return (LocalVariableType[]) getLocals();
+ return(LocalVariableType[]) getLocals();
}
/**
- * Return the local with the given locals index, or null if none.
+ * Return the local with the given locals index, or null if none.
*/
public LocalVariableType getLocalVariableType(int local) {
- return (LocalVariableType) getLocal(local);
+ return(LocalVariableType) getLocal(local);
}
/**
- * Return the local with the given name, or null if none. If multiple
- * locals have the given name, which is returned is undefined.
+ * Return the local with the given name, or null if none. If multiple
+ * locals have the given name, which is returned is undefined.
*/
public LocalVariableType getLocalVariableType(String name) {
- return (LocalVariableType) getLocal(name);
+ return(LocalVariableType) getLocal(name);
}
/**
- * Return all locals with the given name, or empty array if none.
+ * Return all locals with the given name, or empty array if none.
*/
public LocalVariableType[] getLocalVariableTypes(String name) {
- return (LocalVariableType[]) getLocals(name);
+ return(LocalVariableType[]) getLocals(name);
}
/**
- * Import a local from another method/class. Note that
- * the program counter and length from the given local is copied
- * directly, and thus will be incorrect unless this method is the same
- * as the one the local is copied from, or the pc and length are reset.
+ * Import a local from another method/class. Note that
+ * the program counter and length from the given local is copied
+ * directly, and thus will be incorrect unless this method is the same
+ * as the one the local is copied from, or the pc and length are reset.
*/
public LocalVariableType addLocalVariableType(LocalVariableType local) {
- return (LocalVariableType) addLocal(local);
+ return(LocalVariableType) addLocal(local);
}
/**
- * Add a local to this table.
+ * Add a local to this table.
*/
public LocalVariableType addLocalVariableType() {
- return (LocalVariableType) addLocal();
+ return(LocalVariableType) addLocal();
}
/**
- * Add a local to this table.
+ * Add a local to this table.
*/
public LocalVariableType addLocalVariableType(String name, String type) {
- return (LocalVariableType) addLocal(name, type);
+ return(LocalVariableType) addLocal(name, type);
}
public void acceptVisit(BCVisitor visit) {
visit.enterLocalVariableTypeTable(this);
LocalVariableType[] locals = (LocalVariableType[]) getLocals();
-
for (int i = 0; i < locals.length; i++)
locals[i].acceptVisit(visit);
Modified: incubator/openjpa/trunk/serp/src/main/java/serp/bytecode/LookupSwitchInstruction.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/serp/src/main/java/serp/bytecode/LookupSwitchInstruction.java?rev=418401&r1=418400&r2=418401&view=diff
==============================================================================
--- incubator/openjpa/trunk/serp/src/main/java/serp/bytecode/LookupSwitchInstruction.java (original)
+++ incubator/openjpa/trunk/serp/src/main/java/serp/bytecode/LookupSwitchInstruction.java Fri Jun 30 15:37:18 2006
@@ -1,13 +1,10 @@
/*
* Copyright 2006 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
+ * 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
+ * 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
@@ -15,24 +12,20 @@
*/
package serp.bytecode;
-import serp.bytecode.visitor.*;
-
-import serp.util.*;
-
import java.io.*;
-
import java.util.*;
-
+import serp.bytecode.visitor.*;
+import serp.util.*;
/**
- * <p>The <code>lookupswitch</code> instruction.</p>
- *
- * @author Abe White
+ * The <code>lookupswitch</code> instruction.
+ *
+ * @author Abe White
*/
public class LookupSwitchInstruction extends JumpInstruction {
// case info
private List _matches = new LinkedList();
- private List _cases = new LinkedList();
+ private List _cases = new LinkedList();
LookupSwitchInstruction(Code owner) {
super(owner, Constants.LOOKUPSWITCH);
@@ -46,15 +39,13 @@
// make the first byte of the 'default' a multiple of 4 from the
// start of the method
int byteIndex = getByteIndex() + 1;
-
- for (; (byteIndex % 4) != 0; byteIndex++, length++)
- ;
+ for (; byteIndex % 4 != 0; byteIndex++, length++);
// default, npairs
length += 8;
// pairs
- length += (8 * _matches.size());
+ length += 8 * _matches.size();
return length;
}
@@ -68,50 +59,50 @@
}
/**
- * Synonymous with {@link #getTarget}.
+ * Synonymous with {@link #getTarget}.
*/
public Instruction getDefaultTarget() {
return getTarget();
}
/**
- * Synonymous with {@link #setTarget}.
+ * Synonymous with {@link #setTarget}.
*/
public LookupSwitchInstruction setDefaultTarget(Instruction ins) {
- return (LookupSwitchInstruction) setTarget(ins);
+ return(LookupSwitchInstruction) setTarget(ins);
}
/**
- * Synonymous with {@link #getOffset}.
+ * Synonymous with {@link #getOffset}.
*/
public int getDefaultOffset() {
return getOffset();
}
/**
- * Synonymous with {@link #setOffset}.
+ * Synonymous with {@link #setOffset}.
*/
public LookupSwitchInstruction setDefaultOffset(int offset) {
setOffset(offset);
-
return this;
}
/**
- * Set the match-jumppt pairs for this switch.
- *
- * @return this instruction, for method chaining
+ * Set the match-jumppt pairs for this switch.
+ *
+ * @return this instruction, for method chaining
*/
- public LookupSwitchInstruction setCases(int[] matches, Instruction[] targets) {
+ public LookupSwitchInstruction setCases(int[] matches,
+ Instruction[] targets) {
_matches.clear();
_cases.clear();
for (int i = 0; i < matches.length; i++)
- _matches.add(Numbers.valueOf(matches[i]));
+ _matches.add(Numbers.valueOf(matches [i]));
for (int i = 0; i < targets.length; i++) {
InstructionPtrStrategy next = new InstructionPtrStrategy(this);
- next.setTargetInstruction(targets[i]);
+ next.setTargetInstruction(targets [i]);
_cases.add(next);
}
@@ -120,79 +111,67 @@
public int[] getOffsets() {
int bi = getByteIndex();
- int[] offsets = new int[_cases.size()];
-
- for (int i = 0; i < offsets.length; i++)
- offsets[i] = ((InstructionPtrStrategy) _cases.get(i)).getByteIndex() -
- bi;
-
+ int[] offsets = new int [_cases.size()];
+ for (int i=0; i < offsets.length; i++)
+ offsets [i] = ((InstructionPtrStrategy) _cases.get(i)).
+ getByteIndex() - bi;
return offsets;
}
/**
- * Return the values of the case statements for this switch.
+ * Return the values of the case statements for this switch.
*/
public int[] getMatches() {
int[] matches = new int[_matches.size()];
Iterator itr = _matches.iterator();
-
for (int i = 0; i < matches.length; i++)
matches[i] = ((Integer) itr.next()).intValue();
-
return matches;
}
/**
- * Return the targets of the case statements for this switch.
+ * Return the targets of the case statements for this switch.
*/
public Instruction[] getTargets() {
Instruction[] result = new Instruction[_cases.size()];
-
- for (int i = 0; i < result.length; i++)
- result[i] = ((InstructionPtrStrategy) _cases.get(i)).getTargetInstruction();
-
+ for (int i=0; i < result.length; i++)
+ result [i] = ((InstructionPtrStrategy) _cases.get(i)).
+ getTargetInstruction();
return result;
}
/**
- * Add a case to this switch.
- *
- * @return this instruction, for method chaining
+ * Add a case to this switch.
+ *
+ * @return this instruction, for method chaining
*/
public LookupSwitchInstruction addCase(int match, Instruction target) {
_matches.add(Numbers.valueOf(match));
_cases.add(new InstructionPtrStrategy(this, target));
-
return this;
}
private Instruction findJumpPoint(int jumpByteIndex, List inss) {
Instruction ins;
-
for (Iterator itr = inss.iterator(); itr.hasNext();) {
ins = (Instruction) itr.next();
-
- if (ins.getByteIndex() == jumpByteIndex) {
+ if (ins.getByteIndex() == jumpByteIndex)
return ins;
- }
}
-
return null;
}
public void updateTargets() {
super.updateTargets();
-
for (Iterator itr = _cases.iterator(); itr.hasNext();)
((InstructionPtrStrategy) itr.next()).updateTargets();
}
public void replaceTarget(Instruction oldTarget, Instruction newTarget) {
super.replaceTarget(oldTarget, newTarget);
-
for (Iterator itr = _cases.iterator(); itr.hasNext();)
- ((InstructionPtrStrategy) itr.next()).replaceTarget(oldTarget,
- newTarget);
+ ((InstructionPtrStrategy) itr.next()).replaceTarget
+ (oldTarget, newTarget);
}
public void acceptVisit(BCVisitor visit) {
@@ -206,9 +185,9 @@
LookupSwitchInstruction ins = (LookupSwitchInstruction) orig;
_matches = new LinkedList(ins._matches);
_cases.clear();
-
- for (Iterator itr = ins._cases.iterator(); itr.hasNext();) {
- InstructionPtrStrategy origPtr = (InstructionPtrStrategy) itr.next();
+ for (Iterator itr=ins._cases.iterator(); itr.hasNext();) {
+ InstructionPtrStrategy origPtr = (InstructionPtrStrategy)
+ itr.next();
InstructionPtrStrategy newPtr = new InstructionPtrStrategy(this);
newPtr.setByteIndex(origPtr.getByteIndex());
_cases.add(newPtr);
@@ -218,18 +197,15 @@
void read(DataInput in) throws IOException {
// don't call super
int bi = getByteIndex();
-
- for (int byteIndex = bi + 1; (byteIndex % 4) != 0; byteIndex++)
+ for (int byteIndex = bi + 1; byteIndex % 4 != 0; byteIndex++)
in.readByte();
setOffset(in.readInt());
_matches.clear();
_cases.clear();
-
for (int i = 0, pairCount = in.readInt(); i < pairCount; i++) {
_matches.add(Numbers.valueOf(in.readInt()));
-
InstructionPtrStrategy next = new InstructionPtrStrategy(this);
next.setByteIndex(bi + in.readInt());
_cases.add(next);
@@ -238,9 +214,9 @@
void write(DataOutput out) throws IOException {
// don't call super
- int bi = getByteIndex();
- for (int byteIndex = bi + 1; (byteIndex % 4) != 0; byteIndex++)
+ int bi = getByteIndex();
+ for (int byteIndex = bi + 1; byteIndex % 4 != 0; byteIndex++)
out.writeByte(0);
out.writeInt(getOffset());
@@ -248,8 +224,8 @@
for (int i = 0; i < _matches.size(); i++) {
out.writeInt(((Integer) _matches.get(i)).intValue());
- out.writeInt(((InstructionPtrStrategy) _cases.get(i)).getByteIndex() -
- bi);
+ out.writeInt(((InstructionPtrStrategy) _cases.get(i)).
+ getByteIndex() - bi);
}
}
}
Modified: incubator/openjpa/trunk/serp/src/main/java/serp/bytecode/MathInstruction.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/serp/src/main/java/serp/bytecode/MathInstruction.java?rev=418401&r1=418400&r2=418401&view=diff
==============================================================================
--- incubator/openjpa/trunk/serp/src/main/java/serp/bytecode/MathInstruction.java (original)
+++ incubator/openjpa/trunk/serp/src/main/java/serp/bytecode/MathInstruction.java Fri Jun 30 15:37:18 2006
@@ -1,13 +1,10 @@
/*
* Copyright 2006 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
+ * 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
+ * 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
@@ -15,27 +12,22 @@
*/
package serp.bytecode;
-import serp.bytecode.visitor.*;
-
import java.util.*;
-
+import serp.bytecode.visitor.*;
/**
- * <p>One of the math operations defined in the {@link Constants} interface.
- * Changing the type or operation of the instruction will automatically
- * update the underlying opcode.</p>
- *
- * @author Abe White
+ * One of the math operations defined in the {@link Constants} interface.
+ * Changing the type or operation of the instruction will automatically
+ * update the underlying opcode.
+ *
+ * @author Abe White
*/
public class MathInstruction extends TypedInstruction {
private static final Class[][] _mappings = new Class[][] {
- { byte.class, int.class },
- { boolean.class, int.class },
- { char.class, int.class },
- { short.class, int.class },
- { void.class, int.class },
- { Object.class, int.class },
- };
+ { byte.class, int.class }, { boolean.class, int.class },
+ { char.class, int.class }, { short.class, int.class },
+ { void.class, int.class }, { Object.class, int.class }, };
+
private int _op = -1;
private String _type = null;
@@ -50,36 +42,28 @@
public int getStackChange() {
int op = getOperation();
-
- if ((op == Constants.MATH_NEG) || (getOpcode() == Constants.NOP)) {
+ if (op == Constants.MATH_NEG || getOpcode() == Constants.NOP)
return 0;
- }
String type = getTypeName();
-
- if (long.class.getName().equals(type) ||
- double.class.getName().equals(type)) {
+ if (long.class.getName().equals(type)
+ || double.class.getName().equals(type)) {
switch (getOpcode()) {
- case (Constants.LSHL):
- case (Constants.LSHR):
- case (Constants.LUSHR):
- return -1;
-
- default:
- return -2;
+ case(Constants.LSHL):
+ case(Constants.LSHR):
+ case(Constants.LUSHR):
+ return -1;
+ default:
+ return -2;
}
}
-
return -1;
}
public int getLogicalStackChange() {
int op = getOperation();
-
- if ((op == Constants.MATH_NEG) || (getOpcode() == Constants.NOP)) {
+ if (op == Constants.MATH_NEG || getOpcode() == Constants.NOP)
return 0;
- }
-
return -1;
}
@@ -98,7 +82,6 @@
case Constants.IOR:
case Constants.IXOR:
return int.class.getName();
-
case Constants.LADD:
case Constants.LSUB:
case Constants.LMUL:
@@ -112,7 +95,6 @@
case Constants.LOR:
case Constants.LXOR:
return long.class.getName();
-
case Constants.FADD:
case Constants.FSUB:
case Constants.FMUL:
@@ -120,7 +102,6 @@
case Constants.FREM:
case Constants.FNEG:
return float.class.getName();
-
case Constants.DADD:
case Constants.DSUB:
case Constants.DMUL:
@@ -128,7 +109,6 @@
case Constants.DREM:
case Constants.DNEG:
return double.class.getName();
-
default:
return _type;
}
@@ -138,10 +118,9 @@
type = mapType(type, _mappings, true);
// if an invalid type or op, revert to nop
- if ((type == null) || (_op < 0)) {
+ if (type == null || _op < 0) {
_type = type;
-
- return (TypedInstruction) setOpcode(Constants.NOP);
+ return(TypedInstruction) setOpcode(Constants.NOP);
}
// valid opcode, unset saved type
@@ -149,41 +128,35 @@
switch (type.charAt(0)) {
case 'i':
- return (TypedInstruction) setOpcode(_op);
-
+ return(TypedInstruction) setOpcode(_op);
case 'l':
- return (TypedInstruction) setOpcode(_op + 1);
-
+ return(TypedInstruction) setOpcode(_op + 1);
case 'f':
- return (TypedInstruction) setOpcode(_op + 2);
-
+ return(TypedInstruction) setOpcode(_op + 2);
case 'd':
- return (TypedInstruction) setOpcode(_op + 3);
-
+ return(TypedInstruction) setOpcode(_op + 3);
default:
throw new IllegalStateException();
}
}
/**
- * Set the math operation to be performed. This should be one of the
- * math constant defined in {@link Constants}.
- *
- * @return this instruction, for method chaining
+ * Set the math operation to be performed. This should be one of the
+ * math constant defined in {@link Constants}.
+ *
+ * @return this instruction, for method chaining
*/
public MathInstruction setOperation(int operation) {
_op = operation;
// this calculates the opcode
setType(getTypeName());
-
return this;
}
/**
- * Return the operation for this math instruction; will be one of the
- * math constant defined in {@link Constants}, or -1 if
- * unset.
+ * Return the operation for this math instruction; will be one of the
+ * math constant defined in {@link Constants}, or -1 if unset.
*/
public int getOperation() {
switch (getOpcode()) {
@@ -192,89 +165,74 @@
case Constants.FADD:
case Constants.DADD:
return Constants.MATH_ADD;
-
case Constants.ISUB:
case Constants.LSUB:
case Constants.FSUB:
case Constants.DSUB:
return Constants.MATH_SUB;
-
case Constants.IMUL:
case Constants.LMUL:
case Constants.FMUL:
case Constants.DMUL:
return Constants.MATH_MUL;
-
case Constants.IDIV:
case Constants.LDIV:
case Constants.FDIV:
case Constants.DDIV:
return Constants.MATH_DIV;
-
case Constants.IREM:
case Constants.LREM:
case Constants.FREM:
case Constants.DREM:
return Constants.MATH_REM;
-
case Constants.INEG:
case Constants.LNEG:
case Constants.FNEG:
case Constants.DNEG:
return Constants.MATH_NEG;
-
case Constants.ISHL:
case Constants.LSHL:
return Constants.MATH_SHL;
-
case Constants.ISHR:
case Constants.LSHR:
return Constants.MATH_SHR;
-
case Constants.IUSHR:
case Constants.LUSHR:
return Constants.MATH_USHR;
-
case Constants.IAND:
case Constants.LAND:
return Constants.MATH_AND;
-
case Constants.IOR:
case Constants.LOR:
return Constants.MATH_OR;
-
case Constants.IXOR:
case Constants.LXOR:
return Constants.MATH_XOR;
-
default:
return _op;
}
}
/**
- * MathInstructions are equal if they have the same operation and type,
- * or the operation and type of either is unset.
+ * MathInstructions are equal if they have the same operation and type,
+ * or the operation and type of either is unset.
*/
public boolean equalsInstruction(Instruction other) {
- if (this == other) {
+ if (this == other)
return true;
- }
-
- if (!(other instanceof MathInstruction)) {
+ if (!(other instanceof MathInstruction))
return false;
- }
MathInstruction ins = (MathInstruction) other;
int op = getOperation();
int otherOp = ins.getOperation();
- boolean opEq = (op == -1) || (otherOp == -1) || (op == otherOp);
+ boolean opEq = op == -1 || otherOp == -1 || op == otherOp;
String type = getTypeName();
String otherType = ins.getTypeName();
- boolean typeEq = (type == null) || (otherType == null) ||
- type.equals(otherType);
+ boolean typeEq = type == null || otherType == null
+ || type.equals(otherType);
return opEq && typeEq;
}
@@ -286,7 +244,6 @@
void read(Instruction orig) {
super.read(orig);
-
MathInstruction ins = (MathInstruction) orig;
_type = ins._type;
_op = ins._op;