From 0a66fa892531a8f35dd2a9e08c857cf88a513a06 Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Wed, 28 May 2014 19:42:51 +0400 Subject: option to pass numeric literals undecoded --- src/de/fernflower/main/DecompilerContext.java | 2 +- .../main/extern/IFernflowerPreferences.java | 3 +- .../modules/decompiler/exps/ConstExprent.java | 39 ++++++++++++++++++---- 3 files changed, 35 insertions(+), 9 deletions(-) (limited to 'src/de') diff --git a/src/de/fernflower/main/DecompilerContext.java b/src/de/fernflower/main/DecompilerContext.java index 99001a0..213898a 100644 --- a/src/de/fernflower/main/DecompilerContext.java +++ b/src/de/fernflower/main/DecompilerContext.java @@ -76,7 +76,7 @@ public class DecompilerContext { mapDefault.put(IFernflowerPreferences.DECOMPILE_ENUM, "1"); mapDefault.put(IFernflowerPreferences.FINALLY_DEINLINE, "1"); mapDefault.put(IFernflowerPreferences.REMOVE_GETCLASS_NEW, "1"); - + mapDefault.put(IFernflowerPreferences.LITERALS_AS_IS, "0"); mapDefault.put(IFernflowerPreferences.BOOLEAN_TRUE_ONE, "1"); mapDefault.put(IFernflowerPreferences.SYNTHETIC_NOT_SET, "1"); mapDefault.put(IFernflowerPreferences.UNDEFINED_PARAM_TYPE_OBJECT, "1"); diff --git a/src/de/fernflower/main/extern/IFernflowerPreferences.java b/src/de/fernflower/main/extern/IFernflowerPreferences.java index 35b17de..5037107 100644 --- a/src/de/fernflower/main/extern/IFernflowerPreferences.java +++ b/src/de/fernflower/main/extern/IFernflowerPreferences.java @@ -28,7 +28,8 @@ public interface IFernflowerPreferences { public static final String NO_EXCEPTIONS_RETURN = "ner"; public static final String DECOMPILE_ENUM = "den"; public static final String REMOVE_GETCLASS_NEW = "rgn"; - public static final String BOOLEAN_TRUE_ONE = "bto"; + public static final String LITERALS_AS_IS = "bto"; + public static final String BOOLEAN_TRUE_ONE = "bto"; public static final String SYNTHETIC_NOT_SET = "nns"; public static final String UNDEFINED_PARAM_TYPE_OBJECT = "uto"; public static final String USE_DEBUG_VARNAMES = "udv"; diff --git a/src/de/fernflower/modules/decompiler/exps/ConstExprent.java b/src/de/fernflower/modules/decompiler/exps/ConstExprent.java index 2187c49..26d7355 100644 --- a/src/de/fernflower/modules/decompiler/exps/ConstExprent.java +++ b/src/de/fernflower/modules/decompiler/exps/ConstExprent.java @@ -101,7 +101,8 @@ public class ConstExprent extends Exprent { } public String toJava(int indent) { - + boolean literal = DecompilerContext.getOption(IFernflowerPreferences.LITERALS_AS_IS); + if(consttype.type != CodeConstants.TYPE_NULL && value == null) { return ExprProcessor.getCastTypeName(consttype); } else { @@ -112,7 +113,7 @@ public class ConstExprent extends Exprent { Integer val = (Integer)value; String ret = escapes.get(val); if(ret == null) { - if(val.intValue() >= 32 && val.intValue() < 127) { + if(literal || val.intValue() >= 32 && val.intValue() < 127) { ret = String.valueOf((char)val.intValue()); } else { ret = InterpreterUtil.charToUnicodeLiteral(val); @@ -126,8 +127,10 @@ public class ConstExprent extends Exprent { case CodeConstants.TYPE_INT: int ival = ((Integer)value).intValue(); - String intfield; - if(ival == Integer.MAX_VALUE) { + String intfield; + if(literal) { + return value.toString(); + } else if(ival == Integer.MAX_VALUE) { intfield = "MAX_VALUE"; } else if(ival == Integer.MIN_VALUE) { intfield = "MIN_VALUE"; @@ -139,7 +142,9 @@ public class ConstExprent extends Exprent { long lval = ((Long)value).longValue(); String longfield; - if(lval == Long.MAX_VALUE) { + if(literal) { + return value.toString()+"L"; + } else if(lval == Long.MAX_VALUE) { longfield = "MAX_VALUE"; } else if(lval == Long.MIN_VALUE) { longfield = "MIN_VALUE"; @@ -151,7 +156,17 @@ public class ConstExprent extends Exprent { double dval = ((Double)value).doubleValue(); String doublefield; - if(Double.isNaN(dval)) { + if(literal) { + if(Double.isNaN(dval)) { + return "0.0D / 0.0"; + } else if(dval == Double.POSITIVE_INFINITY) { + return "1.0D / 0.0"; + } else if(dval == Double.NEGATIVE_INFINITY) { + return "-1.0D / 0.0"; + } else { + return value.toString() + "D"; + } + } else if(Double.isNaN(dval)) { doublefield = "NaN"; } else if(dval == Double.POSITIVE_INFINITY) { doublefield = "POSITIVE_INFINITY"; @@ -169,7 +184,17 @@ public class ConstExprent extends Exprent { float fval = ((Float)value).floatValue(); String floatfield; - if(Float.isNaN(fval)) { + if(literal) { + if(Double.isNaN(fval)) { + return "0.0F / 0.0"; + } else if(fval == Double.POSITIVE_INFINITY) { + return "1.0F / 0.0"; + } else if(fval == Double.NEGATIVE_INFINITY) { + return "-1.0F / 0.0"; + } else { + return value.toString() + "F"; + } + } else if(Float.isNaN(fval)) { floatfield = "NaN"; } else if(fval == Float.POSITIVE_INFINITY) { floatfield = "POSITIVE_INFINITY"; -- cgit v1.2.3