Skip to content

Commit

Permalink
Merge branch 'LVTProcessing'
Browse files Browse the repository at this point in the history
  • Loading branch information
cpw committed Oct 17, 2015
2 parents 635b7b9 + 36ea9a3 commit dd118af
Show file tree
Hide file tree
Showing 87 changed files with 3,413 additions and 464 deletions.
Empty file modified gradlew
100644 → 100755
Empty file.
15 changes: 15 additions & 0 deletions src/org/jetbrains/java/decompiler/code/cfg/BasicBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -262,4 +262,19 @@ public List<BasicBlock> getPredExceptions() {
public void setPredExceptions(List<BasicBlock> predExceptions) {
this.predExceptions = predExceptions;
}

public int getStartInstruction() {
if (seq.isEmpty()) {
return 0;
}
return instrOldOffsets.get(0);
}

public int getEndInstruction() {
if (seq.isEmpty()) {
return 0;
}
int end = seq.getLastInstr().length();
return end + instrOldOffsets.get(size() -1);
}
}
156 changes: 51 additions & 105 deletions src/org/jetbrains/java/decompiler/main/ClassWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -342,13 +342,7 @@ else if (isInterface) {
buffer.append("class ");
}

GenericClassDescriptor descriptor = null;
if (DecompilerContext.getOption(IFernflowerPreferences.DECOMPILE_GENERIC_SIGNATURES)) {
StructGenericSignatureAttribute attr = (StructGenericSignatureAttribute)cl.getAttributes().getWithKey("Signature");
if (attr != null) {
descriptor = GenericMain.parseClassSignature(attr.getSignature());
}
}
GenericClassDescriptor descriptor = cl.getSignature();

buffer.append(node.simpleName);

Expand All @@ -362,12 +356,7 @@ else if (isInterface) {
VarType supertype = new VarType(cl.superClass.getString(), true);
if (!VarType.VARTYPE_OBJECT.equals(supertype)) {
buffer.append("extends ");
if (descriptor != null) {
buffer.append(GenericMain.getGenericCastTypeName(descriptor.superclass));
}
else {
buffer.append(ExprProcessor.getCastTypeName(supertype));
}
buffer.append(ExprProcessor.getCastTypeName(descriptor == null ? supertype : descriptor.superclass));
buffer.append(' ');
}
}
Expand All @@ -380,12 +369,8 @@ else if (isInterface) {
if (i > 0) {
buffer.append(", ");
}
if (descriptor != null) {
buffer.append(GenericMain.getGenericCastTypeName(descriptor.superinterfaces.get(i)));
}
else {
buffer.append(ExprProcessor.getCastTypeName(new VarType(cl.getInterface(i), true)));
}
VarType iface = descriptor == null ? new VarType(cl.getInterface(i), true) : descriptor.superinterfaces.get(i);
buffer.append(ExprProcessor.getCastTypeName(iface));
}
buffer.append(' ');
}
Expand Down Expand Up @@ -423,21 +408,10 @@ private void fieldToJava(ClassWrapper wrapper, StructClass cl, StructField fd, T

VarType fieldType = new VarType(fd.getDescriptor(), false);

GenericFieldDescriptor descriptor = null;
if (DecompilerContext.getOption(IFernflowerPreferences.DECOMPILE_GENERIC_SIGNATURES)) {
StructGenericSignatureAttribute attr = (StructGenericSignatureAttribute)fd.getAttributes().getWithKey("Signature");
if (attr != null) {
descriptor = GenericMain.parseFieldSignature(attr.getSignature());
}
}
GenericFieldDescriptor descriptor = fd.getSignature();

if (!isEnum) {
if (descriptor != null) {
buffer.append(GenericMain.getGenericCastTypeName(descriptor.type));
}
else {
buffer.append(ExprProcessor.getCastTypeName(fieldType));
}
buffer.append(ExprProcessor.getCastTypeName(descriptor == null ? fieldType : descriptor.type));
buffer.append(' ');
}

Expand All @@ -461,6 +435,7 @@ private void fieldToJava(ClassWrapper wrapper, StructClass cl, StructField fd, T
else {
buffer.append(" = ");
// FIXME: special case field initializer. Can map to more than one method (constructor) and bytecode intruction.
initializer.getInferredExprType(descriptor == null? fieldType : descriptor.type);
buffer.append(initializer.toJava(indent, tracer));
}
}
Expand Down Expand Up @@ -607,6 +582,7 @@ private boolean methodToJava(ClassNode node, StructMethod mt, TextBuffer buffer,
boolean clinit = false, init = false, dinit = false;

MethodDescriptor md = MethodDescriptor.parseDescriptor(mt.getDescriptor());
DecompilerContext.setProperty(DecompilerContext.CURRENT_METHOD_DESCRIPTOR, md);

int flags = mt.getAccessFlags();
if ((flags & CodeConstants.ACC_NATIVE) != 0) {
Expand Down Expand Up @@ -661,32 +637,26 @@ else if (CodeConstants.CLINIT_NAME.equals(name)) {
clinit = true;
}

GenericMethodDescriptor descriptor = null;
if (DecompilerContext.getOption(IFernflowerPreferences.DECOMPILE_GENERIC_SIGNATURES)) {
StructGenericSignatureAttribute attr = (StructGenericSignatureAttribute)mt.getAttributes().getWithKey("Signature");
if (attr != null) {
descriptor = GenericMain.parseMethodSignature(attr.getSignature());
if (descriptor != null) {
int actualParams = md.params.length;
List<VarVersionPair> sigFields = methodWrapper.signatureFields;
if (sigFields != null) {
actualParams = 0;
for (VarVersionPair field : methodWrapper.signatureFields) {
if (field == null) {
actualParams++;
}
}
}
else if (isEnum && init) actualParams -= 2;
if (actualParams != descriptor.params.size()) {
String message = "Inconsistent generic signature in method " + mt.getName() + " " + mt.getDescriptor() + " in " + cl.qualifiedName;
DecompilerContext.getLogger().writeMessage(message, IFernflowerLogger.Severity.WARN);
descriptor = null;
GenericMethodDescriptor descriptor = mt.getSignature();
if (descriptor != null) {
int actualParams = md.params.length;
List<VarVersionPair> sigFields = methodWrapper.signatureFields;
if (sigFields != null) {
actualParams = 0;
for (VarVersionPair field : methodWrapper.signatureFields) {
if (field == null) {
actualParams++;
}
}
}
else if (isEnum && init) actualParams -= 2;
if (actualParams != descriptor.params.size()) {
String message = "Inconsistent generic signature in method " + mt.getName() + " " + mt.getDescriptor() + " in " + cl.qualifiedName;
DecompilerContext.getLogger().writeMessage(message, IFernflowerLogger.Severity.WARN);
descriptor = null;
}
md.addGenericDescriptor(descriptor);
}

boolean throwsExceptions = false;
int paramCount = 0;

Expand All @@ -699,12 +669,7 @@ else if (CodeConstants.CLINIT_NAME.equals(name)) {
}

if (!init) {
if (descriptor != null) {
buffer.append(GenericMain.getGenericCastTypeName(descriptor.ret));
}
else {
buffer.append(ExprProcessor.getCastTypeName(md.ret));
}
buffer.append(ExprProcessor.getCastTypeName(descriptor == null ? md.ret : descriptor.ret));
buffer.append(' ');
}

Expand All @@ -725,6 +690,12 @@ else if (CodeConstants.CLINIT_NAME.equals(name)) {
int index = isEnum && init ? 3 : thisVar ? 1 : 0;
boolean hasDescriptor = descriptor != null;
int start = isEnum && init && !hasDescriptor ? 2 : 0;

if (init && hasDescriptor && !isEnum &&
((node.access & CodeConstants.ACC_STATIC) == 0) && node.type == ClassNode.CLASS_MEMBER) {
index++; //Enclosing class
}

int params = hasDescriptor ? descriptor.params.size() : md.params.length;
for (int i = start; i < params; i++) {
if (hasDescriptor || (signFields == null || signFields.get(i) == null)) {
Expand All @@ -738,45 +709,23 @@ else if (CodeConstants.CLINIT_NAME.equals(name)) {
buffer.append("final ");
}

if (descriptor != null) {
GenericType parameterType = descriptor.params.get(i);

boolean isVarArg = (i == lastVisibleParameterIndex && mt.hasModifier(CodeConstants.ACC_VARARGS) && parameterType.arrayDim > 0);
if (isVarArg) {
parameterType = parameterType.decreaseArrayDim();
}

String typeName = GenericMain.getGenericCastTypeName(parameterType);
if (ExprProcessor.UNDEFINED_TYPE_STRING.equals(typeName) &&
DecompilerContext.getOption(IFernflowerPreferences.UNDEFINED_PARAM_TYPE_OBJECT)) {
typeName = ExprProcessor.getCastTypeName(VarType.VARTYPE_OBJECT);
}
VarType parameterType = descriptor == null ? md.params[i] : descriptor.params.get(i);

buffer.append(typeName);

if (isVarArg) {
buffer.append("...");
}
boolean isVarArg = (i == lastVisibleParameterIndex && mt.hasModifier(CodeConstants.ACC_VARARGS) && parameterType.arrayDim > 0);
if (isVarArg) {
parameterType = parameterType.decreaseArrayDim();
}
else {
VarType parameterType = md.params[i];

boolean isVarArg = (i == lastVisibleParameterIndex && mt.hasModifier(CodeConstants.ACC_VARARGS) && parameterType.arrayDim > 0);
if (isVarArg) {
parameterType = parameterType.decreaseArrayDim();
}

String typeName = ExprProcessor.getCastTypeName(parameterType);
if (ExprProcessor.UNDEFINED_TYPE_STRING.equals(typeName) &&
DecompilerContext.getOption(IFernflowerPreferences.UNDEFINED_PARAM_TYPE_OBJECT)) {
typeName = ExprProcessor.getCastTypeName(VarType.VARTYPE_OBJECT);
}
String typeName = ExprProcessor.getCastTypeName(parameterType);
if (ExprProcessor.UNDEFINED_TYPE_STRING.equals(typeName) &&
DecompilerContext.getOption(IFernflowerPreferences.UNDEFINED_PARAM_TYPE_OBJECT)) {
typeName = ExprProcessor.getCastTypeName(VarType.VARTYPE_OBJECT);
}

buffer.append(typeName);
buffer.append(typeName);

if (isVarArg) {
buffer.append("...");
}
if (isVarArg) {
buffer.append("...");
}

buffer.append(' ');
Expand All @@ -787,7 +736,7 @@ else if (CodeConstants.CLINIT_NAME.equals(name)) {
paramCount++;
}

index += md.params[i].stackSize;
index += hasDescriptor ? descriptor.params.get(i).stackSize : md.params[i].stackSize;
}

buffer.append(')');
Expand All @@ -801,14 +750,11 @@ else if (CodeConstants.CLINIT_NAME.equals(name)) {
if (i > 0) {
buffer.append(", ");
}
VarType type = new VarType(attr.getExcClassname(i, cl.getPool()), true);
if (descriptor != null && !descriptor.exceptions.isEmpty()) {
GenericType type = descriptor.exceptions.get(i);
buffer.append(GenericMain.getGenericCastTypeName(type));
}
else {
VarType type = new VarType(attr.getExcClassname(i, cl.getPool()), true);
buffer.append(ExprProcessor.getCastTypeName(type));
type = descriptor.exceptions.get(i);
}
buffer.append(ExprProcessor.getCastTypeName(type));
}
}
}
Expand Down Expand Up @@ -1071,7 +1017,7 @@ private static void appendModifiers(TextBuffer buffer, int flags, int allowed, b
}
}

private static void appendTypeParameters(TextBuffer buffer, List<String> parameters, List<List<GenericType>> bounds) {
private static void appendTypeParameters(TextBuffer buffer, List<String> parameters, List<List<VarType>> bounds) {
buffer.append('<');

for (int i = 0; i < parameters.size(); i++) {
Expand All @@ -1081,13 +1027,13 @@ private static void appendTypeParameters(TextBuffer buffer, List<String> paramet

buffer.append(parameters.get(i));

List<GenericType> parameterBounds = bounds.get(i);
List<VarType> parameterBounds = bounds.get(i);
if (parameterBounds.size() > 1 || !"java/lang/Object".equals(parameterBounds.get(0).value)) {
buffer.append(" extends ");
buffer.append(GenericMain.getGenericCastTypeName(parameterBounds.get(0)));
buffer.append(ExprProcessor.getCastTypeName(parameterBounds.get(0)));
for (int j = 1; j < parameterBounds.size(); j++) {
buffer.append(" & ");
buffer.append(GenericMain.getGenericCastTypeName(parameterBounds.get(j)));
buffer.append(ExprProcessor.getCastTypeName(parameterBounds.get(j)));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import org.jetbrains.java.decompiler.struct.StructContext;
import org.jetbrains.java.decompiler.struct.StructMethod;
import org.jetbrains.java.decompiler.struct.attr.StructEnclosingMethodAttribute;
import org.jetbrains.java.decompiler.struct.attr.StructGeneralAttribute;
import org.jetbrains.java.decompiler.struct.attr.StructInnerClassesAttribute;
import org.jetbrains.java.decompiler.struct.attr.StructInnerClassesAttribute.InnerClassInfo;
import org.jetbrains.java.decompiler.struct.gen.VarType;
Expand Down
4 changes: 3 additions & 1 deletion src/org/jetbrains/java/decompiler/main/EnumProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ else if (CodeConstants.INIT_NAME.equals(name)) {

// FIXME: move to a util class (see also InitializerProcessor)
private static Statement findFirstData(Statement stat) {

if (stat == null) {
return null;
}
if (stat.getExprents() != null) {
return stat;
}
Expand Down
30 changes: 30 additions & 0 deletions src/org/jetbrains/java/decompiler/main/Fernflower.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.jetbrains.java.decompiler.main.collectors.CounterContainer;
import org.jetbrains.java.decompiler.main.extern.IBytecodeProvider;
import org.jetbrains.java.decompiler.main.extern.IFernflowerLogger;
import org.jetbrains.java.decompiler.main.extern.IFernflowerLogger.Severity;
import org.jetbrains.java.decompiler.main.extern.IResultSaver;
import org.jetbrains.java.decompiler.main.extern.IFernflowerPreferences;
import org.jetbrains.java.decompiler.modules.renamer.IdentifierConverter;
Expand All @@ -27,7 +28,10 @@
import org.jetbrains.java.decompiler.struct.StructContext;
import org.jetbrains.java.decompiler.struct.lazy.LazyLoader;

import java.io.File;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

public class Fernflower implements IDecompiledData {

Expand All @@ -39,6 +43,10 @@ public Fernflower(IBytecodeProvider provider, IResultSaver saver, Map<String, Ob
DecompilerContext.initContext(options);
DecompilerContext.setCounterContainer(new CounterContainer());
DecompilerContext.setLogger(logger);

if (DecompilerContext.getOption(IFernflowerPreferences.INCLUDE_ENTIRE_CLASSPATH)) {
addAllClasspath();
}
}

public void decompileContext() {
Expand Down Expand Up @@ -92,4 +100,26 @@ public String getClassContent(StructClass cl) {
return null;
}
}

private void addAllClasspath() {
Set<String> found = new HashSet<String>();
String[] props = { System.getProperty("java.class.path"), System.getProperty("sun.boot.class.path") };
for (String prop : props) {
if (prop == null)
continue;

for (final String path : prop.split(File.pathSeparator)) {
File file = new File(path);
if (found.contains(file.getAbsolutePath()))
continue;

// only add .class files from classpath
if (file.exists() && (file.getName().endsWith(".class") || file.getName().endsWith(".jar"))) {
DecompilerContext.getLogger().writeMessage("Adding File to context from classpath: " + file, Severity.INFO);
structContext.addSpace(file, false);
found.add(file.getAbsolutePath());
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ public interface IFernflowerPreferences {
String LINE_SEPARATOR_WIN = "\r\n";
String LINE_SEPARATOR_LIN = "\n";

String INCLUDE_ENTIRE_CLASSPATH = "iec";

Map<String, Object> DEFAULTS = Collections.unmodifiableMap(new HashMap<String, Object>() {{
put(REMOVE_BRIDGE, "1");
put(REMOVE_SYNTHETIC, "0");
Expand Down Expand Up @@ -93,5 +95,6 @@ public interface IFernflowerPreferences {
put(BANNER, "");
put(UNIT_TEST_MODE, "0");
put(DUMP_ORIGINAL_LINES, "0");
put(INCLUDE_ENTIRE_CLASSPATH, "0");
}});
}
Loading

0 comments on commit dd118af

Please sign in to comment.