*** empty log message ***

git-svn-id: https://svn.code.sf.net/p/jode/code/trunk@113 379699f6-c40d-0410-875b-85095c16579e
stable
jochen 26 years ago
parent b3aee060b3
commit e40a33feca
  1. 1
      jode/jode/bytecode/Opcodes.java
  2. 10
      jode/jode/expr/InvokeOperator.java
  3. 268
      jode/jode/flow/VariableSet.java
  4. 4
      jode/jode/type/Type.java
  5. 16
      jode/jode/util/SimpleDictionary.java

@ -355,6 +355,7 @@ public abstract class Opcodes {
} }
} }
case opc_ret: case opc_ret:
stream.skip(1);
return new int[] { 2 }; return new int[] { 2 };
case opc_jsr_w: case opc_jsr_w:

@ -91,8 +91,8 @@ public final class InvokeOperator extends Operator {
public String toString(String[] operands) { public String toString(String[] operands) {
String object = null; String object = null;
if (specialFlag) { if (specialFlag) {
Class clazz = codeAnalyzer.method.classAnalyzer.clazz;
if (operands[0].equals("this")) { if (operands[0].equals("this")) {
Class clazz = codeAnalyzer.method.classAnalyzer.clazz;
object = ""; object = "";
while (clazz != null while (clazz != null
&& !classType.equals(Type.tType(clazz))) { && !classType.equals(Type.tType(clazz))) {
@ -101,9 +101,11 @@ public final class InvokeOperator extends Operator {
} }
if (clazz == null) if (clazz == null)
object = "ERROR-SPECIAL"; object = "SPECIAL";
} else } else if (classType.equals(Type.tType(clazz)))
object = "ERROR-SPECIAL"; object = operands[0];
else
object = "SPECIAL "+operands[0];
} }
object = (object != null) ? object object = (object != null) ? object

@ -29,20 +29,98 @@ import jode.LocalInfo;
* Note that a variable set can contain LocalInfos that use the same * Note that a variable set can contain LocalInfos that use the same
* slot, but are different. * slot, but are different.
*/ */
public class VariableSet extends java.util.Vector { public class VariableSet implements Cloneable {
LocalInfo[] locals;
int count;
/** /**
* Creates a new empty variable set * Creates a new empty variable set
*/ */
public VariableSet() { public VariableSet() {
super(0, 0); locals = null;
count = 0;
} }
/** /**
* Adds a local variable to the variable set. * Creates a new pre initialized variable set
* @param li The local variable of type LocalInfo. */
public VariableSet(LocalInfo[] locals) {
count = locals.length;
this.locals = locals;
}
public final void grow(int size) {
if (locals != null) {
size += count;
if (size > locals.length) {
int nextSize = locals.length * 2;
// System.err.println("wanted: "+size+" next: "+nextSize);
LocalInfo[] newLocals
= new LocalInfo[nextSize > size ? nextSize : size];
System.arraycopy(locals, 0, newLocals, 0, count);
locals = newLocals;
}
} else if (size > 0)
locals = new LocalInfo[size];
}
/**
* Adds a local info to this variable set. It doesn't check for
* duplicates.
*/ */
public void addElement(LocalInfo li) { public void addElement(LocalInfo li) {
super.addElement((Object)li); grow(1);
locals[count++] = li;
}
/**
* Checks if the variable set contains the given local info.
*/
public boolean contains(LocalInfo li) {
li = li.getLocalInfo();
for (int i=0; i<count;i++)
if (locals[i].getLocalInfo() == li)
return true;
return false;
}
/**
* Removes a local info from this variable set.
*/
public void removeElement(LocalInfo li) {
li = li.getLocalInfo();
for (int i=0; i<count;i++)
if (locals[i].getLocalInfo() == li)
locals[i] = locals[--count];
}
/**
* Removes everything from this variable set.
*/
public void removeAllElements() {
locals = null;
count = 0;
}
public java.util.Enumeration elements() {
return new ArrayEnum(count, locals);
}
public boolean isEmpty() {
return count == 0;
}
public Object clone() {
try {
VariableSet other = (VariableSet) super.clone();
if (count > 0) {
other.locals = new LocalInfo[count];
System.arraycopy(locals, 0, other.locals, 0, count);
}
return other;
} catch (CloneNotSupportedException ex) {
throw new jode.AssertError("Clone?");
}
} }
/** /**
@ -50,22 +128,30 @@ public class VariableSet extends java.util.Vector {
* in both variable sets, all corresponding LocalInfos are merged. * in both variable sets, all corresponding LocalInfos are merged.
* The variable sets are not changed (use union for this). * The variable sets are not changed (use union for this).
* @return The merged variables. * @return The merged variables.
* @param vs the other variable set. * @param vs the other variable set. */
*/
public VariableSet merge(VariableSet vs) { public VariableSet merge(VariableSet vs) {
VariableSet merged = new VariableSet(); VariableSet merged = new VariableSet();
for (int i=0; i<elementCount; i++) { merged.grow(Math.min(count,vs.count));
LocalInfo li1 = ((LocalInfo) elementData[i]).getLocalInfo(); big_loop:
for (int i=0; i<count; i++) {
LocalInfo li1 = locals[i];
int slot = li1.getSlot();
boolean didMerge = false; boolean didMerge = false;
for (int j=0; j<vs.elementCount; j++) { for (int k=0; k< merged.count; k++) {
LocalInfo li2 = ((LocalInfo) vs.elementData[j]).getLocalInfo(); if (slot == merged.locals[k].getSlot()) {
if (li1.getSlot() == li2.getSlot()) { /* This slot was already merged. */
li1.combineWith(li2); li1.combineWith(merged.locals[k]);
continue big_loop;
}
}
for (int j=0; j<vs.count; j++) {
if (li1.getSlot() == vs.locals[j].getSlot()) {
li1.combineWith(vs.locals[j]);
didMerge = true; didMerge = true;
} }
} }
if (didMerge) if (didMerge)
merged.addElement(li1); merged.locals[merged.count++] = li1;
} }
return merged; return merged;
} }
@ -77,15 +163,20 @@ public class VariableSet extends java.util.Vector {
*/ */
public VariableSet intersect(VariableSet vs) { public VariableSet intersect(VariableSet vs) {
VariableSet intersection = new VariableSet(); VariableSet intersection = new VariableSet();
for (int i=0; i<elementCount; i++) { intersection.grow(Math.min(count, vs.count));
LocalInfo li1 = ((LocalInfo) elementData[i]).getLocalInfo(); big_loop:
for (int j=0; j<vs.elementCount; j++) { for (int i=0; i<count; i++) {
LocalInfo li2 = ((LocalInfo) vs.elementData[j]).getLocalInfo(); LocalInfo li = locals[i];
if (li1.getSlot() == li2.getSlot()) { int slot = li.getSlot();
if (!intersection.contains(li1)) for (int j=0; j<vs.count; j++) {
intersection.addElement(li1); if (slot == vs.locals[j].getSlot()) {
if (!intersection.contains(li2)) for (int k=0; k<intersection.count; k++) {
intersection.addElement(li2); if (slot == intersection.locals[k].getSlot())
continue big_loop;
}
intersection.locals[intersection.count++]
= li.getLocalInfo();
continue big_loop;
} }
} }
} }
@ -99,15 +190,15 @@ public class VariableSet extends java.util.Vector {
*/ */
public VariableSet intersectExact(VariableSet vs) { public VariableSet intersectExact(VariableSet vs) {
VariableSet intersection = new VariableSet(); VariableSet intersection = new VariableSet();
for (int i=0; i<elementCount; i++) { intersection.grow(Math.min(count, vs.count));
LocalInfo li1 = ((LocalInfo) elementData[i]).getLocalInfo(); big_loop:
for (int j=0; j<vs.elementCount; j++) { for (int i=0; i<count; i++) {
LocalInfo li2 = ((LocalInfo) vs.elementData[j]).getLocalInfo(); LocalInfo li1 = locals[i].getLocalInfo();
if (li1.getLocalInfo() == li2.getLocalInfo()) { for (int j=0; j<vs.count; j++) {
if (li1 == vs.locals[j].getLocalInfo()) {
if (!intersection.contains(li1)) if (!intersection.contains(li1))
intersection.addElement(li1); intersection.locals[intersection.count++] = li1;
if (!intersection.contains(li2)) continue big_loop;
intersection.addElement(li2);
} }
} }
} }
@ -118,18 +209,18 @@ public class VariableSet extends java.util.Vector {
* Union the other variable set to the current. * Union the other variable set to the current.
*/ */
public void unionExact(VariableSet vs) { public void unionExact(VariableSet vs) {
int oldSize = elementCount; grow(vs.count);
iloop: big_loop:
for (int i=0; i< vs.elementCount; i++) { for (int i=0; i< vs.count; i++) {
LocalInfo li2 = ((LocalInfo) vs.elementData[i]).getLocalInfo(); LocalInfo li2 = (vs.locals[i]).getLocalInfo();
/* check if this particular local info was already in the set */ /* check if this particular local info is already in the set */
for (int j=0; j< oldSize; j++) { for (int j=0; j< count; j++) {
LocalInfo li1 = ((LocalInfo) elementData[j]).getLocalInfo(); LocalInfo li1 = (locals[j]).getLocalInfo();
if (li1 == li2) if (li1 == li2)
/* Yes it was, take next variable */ /* Yes it is, take next variable */
continue iloop; continue big_loop;
} }
addElement(li2); locals[count++] = li2;
} }
} }
@ -138,18 +229,18 @@ public class VariableSet extends java.util.Vector {
* is already in the current set. * is already in the current set.
*/ */
public void add(VariableSet vs) { public void add(VariableSet vs) {
int oldSize = elementCount; grow(vs.count);
iloop: big_loop:
for (int i=0; i< vs.elementCount; i++) { for (int i=0; i< vs.count; i++) {
LocalInfo li2 = (LocalInfo) vs.elementData[i]; LocalInfo li2 = vs.locals[i];
/* check if this slot was already overwritten by this block */ int slot2 = li2.getSlot();
for (int j=0; j< oldSize; j++) { /* check if this slot is already in the current set */
LocalInfo li1 = (LocalInfo) elementData[j]; for (int j=0; j< count; j++) {
if (li1.getSlot() == li2.getSlot()) if (locals[j].getSlot() == slot2)
/* Yes it was, take next variable */ /* Yes it is, take next variable */
continue iloop; continue big_loop;
} }
addElement(li2.getLocalInfo()); locals[count++] = li2.getLocalInfo();
} }
} }
@ -160,17 +251,19 @@ public class VariableSet extends java.util.Vector {
* @param kill The kill set. * @param kill The kill set.
*/ */
public void mergeGenKill(VariableSet gen, VariableSet kill) { public void mergeGenKill(VariableSet gen, VariableSet kill) {
iloop: grow(gen.count);
for (int i=0; i< gen.elementCount; i++) { big_loop:
LocalInfo li2 = ((LocalInfo) gen.elementData[i]).getLocalInfo(); for (int i=0; i< gen.count; i++) {
/* check if this slot was already overwritten (kill set) */ LocalInfo li2 = gen.locals[i];
for (int j=0; j< kill.elementCount; j++) { int slot = li2.getSlot();
LocalInfo li1 = (LocalInfo) kill.elementData[j]; /* check if this slot is in the kill set) */
if (li2.getSlot() == li1.getSlot()) for (int j=0; j< kill.count; j++) {
/* Yes it was, take next variable */ LocalInfo li1 = kill.locals[j];
continue iloop; if (slot == kill.locals[j].getSlot())
/* Yes it is, take next variable */
continue big_loop;
} }
addElement(li2); locals[count++] = li2.getLocalInfo();
} }
} }
@ -181,25 +274,19 @@ public class VariableSet extends java.util.Vector {
* @param vs The other variable set. * @param vs The other variable set.
*/ */
public void subtract(VariableSet vs) { public void subtract(VariableSet vs) {
/* We count from top to bottom to have easier reorganization. big_loop:
* Note, that the variables have not to be in any particular for (int i=0; i < count;) {
* order. */ LocalInfo li1 = locals[i];
int newCount = elementCount; int slot = li1.getSlot();
for (int i=newCount-1; i>=0; i--) { for (int j=0; j<vs.count; j++) {
LocalInfo li1 = (LocalInfo) elementData[i]; if (slot == vs.locals[j].getSlot()) {
for (int j=0; j<vs.elementCount; j++) {
LocalInfo li2 = (LocalInfo) vs.elementData[j];
if (li1.getSlot() == li2.getSlot()) {
/* remove the element from this variable list. */ /* remove the element from this variable list. */
newCount--; locals[i] = locals[--count].getLocalInfo();
elementData[i] = elementData[newCount]; continue big_loop;
/* break the j-loop */
break;
} }
} }
i++;
} }
/* Now set the new size */
setSize(newCount);
} }
/** /**
@ -209,28 +296,17 @@ public class VariableSet extends java.util.Vector {
* @param vs The other variable set. * @param vs The other variable set.
*/ */
public void subtractExact(VariableSet vs) { public void subtractExact(VariableSet vs) {
/* We count from top to bottom to have easier reorganization. big_loop:
* Note, that the variables have not to be in any particular for (int i=0; i < count;) {
* order. */ LocalInfo li1 = locals[i].getLocalInfo();
int newCount = elementCount; for (int j=0; j<vs.count; j++) {
for (int i=newCount-1; i>=0; i--) { if (li1 == vs.locals[j].getLocalInfo()) {
LocalInfo li1 = (LocalInfo) elementData[i];
for (int j=0; j<vs.elementCount; j++) {
LocalInfo li2 = (LocalInfo) vs.elementData[j];
if (li1.getLocalInfo() == li2.getLocalInfo()) {
/* remove the element from this variable list. */ /* remove the element from this variable list. */
newCount--; locals[i] = locals[--count].getLocalInfo();
elementData[i] = elementData[newCount]; continue big_loop;
/* break the j-loop */
break;
} }
} }
i++;
} }
/* Now set the new size */
setSize(newCount);
} }
} }

@ -158,7 +158,7 @@ public class Type {
: clazz == Void.TYPE ? tVoid : clazz == Void.TYPE ? tVoid
: tError; : tError;
} }
return tClass(clazz.getName()); return new ClassInterfacesType(clazz);
} }
public static final Type tClass(String clazzname) { public static final Type tClass(String clazzname) {
@ -234,7 +234,7 @@ public class Type {
/** /**
* @return the type code of the type. * @return the type code of the type.
*/ */
public int getTypeCode() { public final int getTypeCode() {
return typecode; return typecode;
} }

@ -33,24 +33,12 @@ public class SimpleDictionary extends Dictionary {
return count == 0; return count == 0;
} }
public Enumeration getArrayEnum(final Object[] array, final int size) {
return new Enumeration() {
int index = 0;
public boolean hasMoreElements() {
return index < size;
}
public Object nextElement() {
return array[index++];
}
};
}
public Enumeration keys() { public Enumeration keys() {
return getArrayEnum(keyObjects, count); return new ArrayEnum(count, keyObjects);
} }
public Enumeration elements() { public Enumeration elements() {
return getArrayEnum(elementObjects, count); return new ArrayEnum(count, elementObjects);
} }
public Object get(Object key) { public Object get(Object key) {

Loading…
Cancel
Save