outerValues reworked, they may shrink now and you can register a listener

for this event.
analyzation passes totally reworked:
	analyze()
	analyzeInnerClasses()
	makeDeclaration()


git-svn-id: https://svn.code.sf.net/p/jode/code/trunk@880 379699f6-c40d-0410-875b-85095c16579e
stable
jochen 26 years ago
parent d2511d224f
commit 00369e6284
  1. 138
      jode/jode/decompiler/ClassAnalyzer.java

@ -29,13 +29,18 @@ import jode.expr.Expression;
import jode.expr.ThisOperator; import jode.expr.ThisOperator;
import jode.expr.ConstructorOperator; import jode.expr.ConstructorOperator;
import jode.flow.TransformConstructors; import jode.flow.TransformConstructors;
import java.util.NoSuchElementException; import java.util.NoSuchElementException;
import java.util.Vector;
import java.util.Enumeration;
import java.lang.reflect.Modifier; import java.lang.reflect.Modifier;
public class ClassAnalyzer implements Analyzer, Scope, Declarable { public class ClassAnalyzer
implements Analyzer, Scope, Declarable, ClassDeclarer
{
ImportHandler imports; ImportHandler imports;
ClassInfo clazz; ClassInfo clazz;
Object parent; ClassDeclarer parent;
String name; String name;
FieldAnalyzer[] fields; FieldAnalyzer[] fields;
@ -43,14 +48,16 @@ public class ClassAnalyzer implements Analyzer, Scope, Declarable {
ClassAnalyzer[] inners; ClassAnalyzer[] inners;
int modifiers; int modifiers;
TransformConstructors constrAna;
MethodAnalyzer staticConstructor; MethodAnalyzer staticConstructor;
MethodAnalyzer[] constructors; MethodAnalyzer[] constructors;
Expression[] outerValues; Expression[] outerValues;
boolean constructorAnalyzed = false;
boolean jikesAnonymousInner = false; boolean jikesAnonymousInner = false;
public ClassAnalyzer(Object parent, Vector ovListeners;
public ClassAnalyzer(ClassDeclarer parent,
ClassInfo clazz, ImportHandler imports, ClassInfo clazz, ImportHandler imports,
Expression[] outerValues) Expression[] outerValues)
{ {
@ -88,7 +95,7 @@ public class ClassAnalyzer implements Analyzer, Scope, Declarable {
} }
} }
public ClassAnalyzer(Object parent, public ClassAnalyzer(ClassDeclarer parent,
ClassInfo clazz, ImportHandler imports) ClassInfo clazz, ImportHandler imports)
{ {
this(parent, clazz, imports, null); this(parent, clazz, imports, null);
@ -122,24 +129,49 @@ public class ClassAnalyzer implements Analyzer, Scope, Declarable {
return null; return null;
} }
public Object getParent() { public ClassDeclarer getParent() {
return parent; return parent;
} }
public void setParent(ClassDeclarer newParent) {
this.parent = newParent;
}
public ClassInfo getClazz() { public ClassInfo getClazz() {
return clazz; return clazz;
} }
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Expression[] getOuterValues() { public Expression[] getOuterValues() {
return outerValues; return outerValues;
} }
public void setOuterValues(Expression[] outerValues) { public void addOuterValueListener(OuterValueListener l) {
this.outerValues = outerValues; if (ovListeners == null)
ovListeners = new Vector();
ovListeners.addElement(l);
} }
public boolean isConstructorAnalyzed() { public void shrinkOuterValues(int newCount) {
return constructorAnalyzed; if (newCount >= outerValues.length)
return;
Expression[] newOuter = new Expression[newCount];
System.arraycopy(outerValues, 0, newOuter, 0, newCount);
outerValues = newOuter;
if (ovListeners != null) {
for (Enumeration enum = ovListeners.elements();
enum.hasMoreElements();)
((OuterValueListener) enum.nextElement()
).shrinkingOuterValues(this, newCount);
}
} }
/** /**
@ -161,6 +193,13 @@ public class ClassAnalyzer implements Analyzer, Scope, Declarable {
} }
public void analyze() { public void analyze() {
imports.useClass(clazz);
if (clazz.getSuperclass() != null)
imports.useClass(clazz.getSuperclass());
ClassInfo[] interfaces = clazz.getInterfaces();
for (int j=0; j< interfaces.length; j++)
imports.useClass(interfaces[j]);
FieldInfo[] finfos = clazz.getFields(); FieldInfo[] finfos = clazz.getFields();
MethodInfo[] minfos = clazz.getMethods(); MethodInfo[] minfos = clazz.getMethods();
InnerClassInfo[] innerInfos = clazz.getInnerClasses(); InnerClassInfo[] innerInfos = clazz.getInnerClasses();
@ -211,22 +250,16 @@ public class ClassAnalyzer implements Analyzer, Scope, Declarable {
for (int j=0; j < fields.length; j++) for (int j=0; j < fields.length; j++)
fields[j].analyze(); fields[j].analyze();
// now analyze constructors: // now analyze constructors and synthetic fields:
constrAna = null;
constructors = new MethodAnalyzer[constrVector.size()]; constructors = new MethodAnalyzer[constrVector.size()];
if (constructors.length > 0) { if (constructors.length > 0) {
constrVector.copyInto(constructors); constrVector.copyInto(constructors);
for (int j=0; j< constructors.length; j++) for (int j=0; j< constructors.length; j++)
constructors[j].analyze(); constructors[j].analyze();
constrAna = new TransformConstructors(this, false, constructors);
new TransformConstructors(this, false, constructors).transform(); constrAna.initSyntheticFields();
} }
if (staticConstructor != null) {
staticConstructor.analyze();
new TransformConstructors
(this, true, new MethodAnalyzer[] { staticConstructor })
.transform();
}
constructorAnalyzed = true;
// Now analyze remaining methods. // Now analyze remaining methods.
for (int j=0; j < methods.length; j++) { for (int j=0; j < methods.length; j++) {
@ -234,28 +267,37 @@ public class ClassAnalyzer implements Analyzer, Scope, Declarable {
&& !methods[j].isJikesConstructor) && !methods[j].isJikesConstructor)
methods[j].analyze(); methods[j].analyze();
} }
}
public void analyzeInnerClasses() {
// Now analyze the inner classes. // Now analyze the inner classes.
for (int j=0; j < inners.length; j++) for (int j=0; j < inners.length; j++) {
inners[j].analyze(); inners[j].analyze();
inners[j].analyzeInnerClasses();
}
// Now analyze the method scoped classes. // Now analyze the method scoped classes.
for (int j=0; j < methods.length; j++) for (int j=0; j < methods.length; j++)
methods[j].analyzeAnonymousClasses(); methods[j].analyzeInnerClasses();
imports.useClass(clazz);
if (clazz.getSuperclass() != null)
imports.useClass(clazz.getSuperclass());
ClassInfo[] interfaces = clazz.getInterfaces();
for (int j=0; j< interfaces.length; j++)
imports.useClass(interfaces[j]);
} }
public String getName() { public void makeDeclaration() {
return name; // Finally anlyze the remaining field initializers.
} if (constrAna != null)
constrAna.transform();
public void setName(String name) { if (staticConstructor != null) {
this.name = name; staticConstructor.analyze();
new TransformConstructors
(this, true, new MethodAnalyzer[] { staticConstructor })
.transform();
}
for (int j=0; j < fields.length; j++)
fields[j].makeDeclaration();
for (int j=0; j < inners.length; j++)
inners[j].makeDeclaration();
for (int j=0; j < methods.length; j++)
methods[j].makeDeclaration();
} }
public void dumpDeclaration(TabbedPrintWriter writer) public void dumpDeclaration(TabbedPrintWriter writer)
@ -302,7 +344,7 @@ public class ClassAnalyzer implements Analyzer, Scope, Declarable {
int modifiedModifiers = modifiers & ~Modifier.SYNCHRONIZED; int modifiedModifiers = modifiers & ~Modifier.SYNCHRONIZED;
if (clazz.isInterface()) if (clazz.isInterface())
modifiedModifiers &= ~Modifier.ABSTRACT; modifiedModifiers &= ~Modifier.ABSTRACT;
if (parent instanceof CodeAnalyzer) { if (parent instanceof MethodAnalyzer) {
/* method scope classes are implicitly private */ /* method scope classes are implicitly private */
modifiedModifiers &= ~Modifier.PRIVATE; modifiedModifiers &= ~Modifier.PRIVATE;
/* anonymous classes are implicitly final */ /* anonymous classes are implicitly final */
@ -340,7 +382,7 @@ public class ClassAnalyzer implements Analyzer, Scope, Declarable {
writer.tab(); writer.tab();
dumpBlock(writer); dumpBlock(writer);
writer.untab(); writer.untab();
if (parent instanceof CodeAnalyzer) { if (parent instanceof MethodAnalyzer) {
/* This is a method scope class */ /* This is a method scope class */
writer.closeBraceNoSpace(); writer.closeBraceNoSpace();
} else } else
@ -353,6 +395,8 @@ public class ClassAnalyzer implements Analyzer, Scope, Declarable {
imports.init(clazz.getName()); imports.init(clazz.getName());
LocalInfo.init(); LocalInfo.init();
analyze(); analyze();
analyzeInnerClasses();
makeDeclaration();
imports.dumpHeader(writer); imports.dumpHeader(writer);
dumpSource(writer); dumpSource(writer);
@ -398,4 +442,26 @@ public class ClassAnalyzer implements Analyzer, Scope, Declarable {
} }
return false; return false;
} }
/**
* Get the class analyzer for the given class info. This searches
* the method scoped/anonymous classes in this method and all
* outer methods and the outer classes for the class analyzer.
* @param cinfo the classinfo for which the analyzer is searched.
* @return the class analyzer, or null if there is not an outer
* class that equals cinfo, and not a method scope/inner class in
* an outer method.
*/
public ClassAnalyzer getClassAnalyzer(ClassInfo cinfo) {
if (cinfo == getClazz())
return this;
if (parent == null)
return null;
return getParent().getClassAnalyzer(cinfo);
}
public void addClassAnalyzer(ClassAnalyzer clazzAna) {
if (parent != null)
parent.addClassAnalyzer(clazzAna);
}
} }

Loading…
Cancel
Save