Action getResult fixes

This commit is contained in:
honfika@gmail.com
2015-09-22 12:40:11 +02:00
parent a3fef3d306
commit f14fb16793
26 changed files with 509 additions and 96 deletions

View File

@@ -55,6 +55,7 @@ import com.jpexs.decompiler.flash.action.swf5.ActionEquals2;
import com.jpexs.decompiler.flash.action.swf7.ActionDefineFunction2;
import com.jpexs.decompiler.flash.configuration.Configuration;
import com.jpexs.decompiler.flash.ecma.Null;
import com.jpexs.decompiler.flash.ecma.Undefined;
import com.jpexs.decompiler.flash.exporters.modes.ScriptExportMode;
import com.jpexs.decompiler.flash.helpers.CodeFormatting;
import com.jpexs.decompiler.flash.helpers.GraphTextWriter;
@@ -925,34 +926,9 @@ public abstract class Action implements GraphSourceItem {
this.ignored = ignored;
}
private static class Loop {
public long loopContinue;
public long loopBreak;
public int continueCount = 0;
public int breakCount = 0;
public Loop(long loopContinue, long loopBreak) {
this.loopContinue = loopContinue;
this.loopBreak = loopBreak;
}
@Override
public String toString() {
return "[Loop continue:" + loopContinue + ", break:" + loopBreak + "]";
}
}
private static void log(String s) {
logger.fine(s);
}
public static List<GraphTargetItem> actionsPartToTree(HashMap<Integer, String> registerNames, HashMap<String, GraphTargetItem> variables, HashMap<String, GraphTargetItem> functions, TranslateStack stack, List<Action> actions, int start, int end, int version, int staticOperation, String path) throws InterruptedException {
if (start < actions.size() && (end > 0) && (start > 0)) {
log("Entering " + start + "-" + end + (actions.size() > 0 ? (" (" + actions.get(start).toString() + " - " + actions.get(end == actions.size() ? end - 1 : end) + ")") : ""));
logger.log(Level.FINE, "Entering {0}-{1}{2}", new Object[]{start, end, actions.size() > 0 ? (" (" + actions.get(start).toString() + " - " + actions.get(end == actions.size() ? end - 1 : end) + ")") : ""});
}
ActionLocalData localData = new ActionLocalData(registerNames, variables, functions);
List<GraphTargetItem> output = new ArrayList<>();
@@ -1136,7 +1112,7 @@ public abstract class Action implements GraphSourceItem {
ip++;
}
//output = checkClass(output);
log("Leaving " + start + "-" + end);
logger.log(Level.FINE, "Leaving {0}-{1}", new Object[]{start, end});
return output;
}
@@ -1357,11 +1333,20 @@ public abstract class Action implements GraphSourceItem {
if (o instanceof Long) {
return (Long) o;
}
if (o instanceof Null) {
return Double.NaN;
}
if (o instanceof Undefined) {
return Double.NaN;
}
if (o instanceof Boolean) {
return (Boolean) o ? 1.0 : 0.0;
}
if (o instanceof String) {
try {
return Double.parseDouble((String) o);
} catch (NumberFormatException nfe) {
return 0;
return Double.NaN;
}
}
return 0;

View File

@@ -79,6 +79,10 @@ public class ActionList extends ArrayList<Action> {
ActionListReader.addAction(this, index, action, SWF.DEFAULT_VERSION, false, false);
}
public void addActions(int index, List<Action> actions) {
ActionListReader.addActions(this, index, actions, SWF.DEFAULT_VERSION);
}
public void fixActionList() {
ActionListReader.fixActionList(this, null, SWF.DEFAULT_VERSION);
}

View File

@@ -730,6 +730,52 @@ public class ActionListReader {
return true;
}
/**
* Adds an action to the action list to the specified location, and updates
* all references
*
* @param actions
* @param index
* @param newActions
* @param version
* @return
*/
public static boolean addActions(ActionList actions, int index, List<Action> newActions, int version) {
if (index < 0 || actions.size() < index) {
return false;
}
long startIp = actions.get(0).getAddress();
Action lastAction = actions.get(actions.size() - 1);
if (!(lastAction instanceof ActionEnd)) {
Action aEnd = new ActionEnd();
aEnd.setAddress(lastAction.getAddress() + lastAction.getTotalActionLength());
actions.add(aEnd);
lastAction = aEnd;
}
long endAddress = lastAction.getAddress();
Map<Action, List<Action>> containerLastActions = new HashMap<>();
getContainerLastActions(actions, containerLastActions);
Map<Action, Action> jumps = new HashMap<>();
List<Action> tempActions = new ArrayList<>(actions);
tempActions.addAll(newActions);
getJumps(tempActions, jumps);
actions.addAll(index, newActions);
updateActionLengths(actions, version);
updateAddresses(actions, startIp);
updateJumps(actions, jumps, containerLastActions, endAddress);
updateActionStores(actions, jumps);
updateContainerSizes(actions, containerLastActions);
return true;
}
private static Action readActionListAtPos(List<DisassemblyListener> listeners, ConstantPool cpool,
SWFInputStream sis, Map<Long, Action> actions, Map<Long, Long> nextOffsets,
long ip, long startIp, long endIp, String path, boolean indeterminate, List<Long> visitedContainers) throws IOException {

View File

@@ -18,6 +18,7 @@ package com.jpexs.decompiler.flash.action.model;
import com.jpexs.decompiler.flash.SourceGeneratorLocalData;
import com.jpexs.decompiler.flash.action.swf4.ActionAsciiToChar;
import com.jpexs.decompiler.flash.ecma.EcmaScript;
import com.jpexs.decompiler.flash.helpers.GraphTextWriter;
import com.jpexs.decompiler.graph.CompilationException;
import com.jpexs.decompiler.graph.GraphSourceItem;
@@ -49,6 +50,16 @@ public class AsciiToCharActionItem extends ActionItem {
return ret;
}
@Override
public Object getResult() {
Double res = EcmaScript.toNumber(value.getResult());
if (Double.isNaN(res) || Double.compare(res, 0) == 0) {
return "";
}
return ((Character) (char) res.intValue()).toString();
}
@Override
public List<GraphSourceItem> toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException {
return toSourceMerge(localData, generator, value, new ActionAsciiToChar());

View File

@@ -80,13 +80,12 @@ public class DirectValueActionItem extends ActionItem implements SimpleValue {
if (value instanceof Float) {
return (double) (Float) value;
}
if (value instanceof Long) {
return (double) (Long) value;
if (value instanceof Long || value instanceof Integer || value instanceof Short || value instanceof Byte) {
return ((Number) value).doubleValue();
}
if (value instanceof Boolean) {
return value;
}
if (value instanceof String) {
return value;
}

View File

@@ -18,6 +18,7 @@ package com.jpexs.decompiler.flash.action.model;
import com.jpexs.decompiler.flash.SourceGeneratorLocalData;
import com.jpexs.decompiler.flash.action.swf4.ActionMBAsciiToChar;
import com.jpexs.decompiler.flash.ecma.EcmaScript;
import com.jpexs.decompiler.flash.helpers.GraphTextWriter;
import com.jpexs.decompiler.graph.CompilationException;
import com.jpexs.decompiler.graph.GraphSourceItem;
@@ -49,6 +50,16 @@ public class MBAsciiToCharActionItem extends ActionItem {
return ret;
}
@Override
public Object getResult() {
Double res = EcmaScript.toNumber(value.getResult());
if (Double.isNaN(res) || Double.compare(res, 0) == 0) {
return "";
}
return ((Character) (char) res.intValue()).toString();
}
@Override
public List<GraphSourceItem> toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException {
return toSourceMerge(localData, generator, value, new ActionMBAsciiToChar());

View File

@@ -18,6 +18,7 @@ package com.jpexs.decompiler.flash.action.model;
import com.jpexs.decompiler.flash.SourceGeneratorLocalData;
import com.jpexs.decompiler.flash.action.swf4.ActionMBStringLength;
import com.jpexs.decompiler.flash.ecma.EcmaScript;
import com.jpexs.decompiler.flash.helpers.GraphTextWriter;
import com.jpexs.decompiler.graph.CompilationException;
import com.jpexs.decompiler.graph.GraphSourceItem;
@@ -56,6 +57,11 @@ public class MBStringLengthActionItem extends ActionItem {
return ret;
}
@Override
public Object getResult() {
return EcmaScript.toNumber(EcmaScript.toString(value.getResult()).length());
}
@Override
public List<GraphSourceItem> toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException {
return toSourceMerge(localData, generator, value, new ActionMBStringLength());

View File

@@ -18,6 +18,7 @@ package com.jpexs.decompiler.flash.action.model;
import com.jpexs.decompiler.flash.SourceGeneratorLocalData;
import com.jpexs.decompiler.flash.action.swf4.ActionStringLength;
import com.jpexs.decompiler.flash.ecma.EcmaScript;
import com.jpexs.decompiler.flash.helpers.GraphTextWriter;
import com.jpexs.decompiler.graph.CompilationException;
import com.jpexs.decompiler.graph.GraphSourceItem;
@@ -48,6 +49,11 @@ public class StringLengthActionItem extends ActionItem {
return false;
}
@Override
public Object getResult() {
return EcmaScript.toNumber(EcmaScript.toString(value.getResult()).length());
}
@Override
public List<GraphSourceItem> toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException {
return toSourceMerge(localData, generator, value, new ActionStringLength());

View File

@@ -18,6 +18,7 @@ package com.jpexs.decompiler.flash.action.model;
import com.jpexs.decompiler.flash.SourceGeneratorLocalData;
import com.jpexs.decompiler.flash.action.swf4.ActionToInteger;
import com.jpexs.decompiler.flash.ecma.EcmaScript;
import com.jpexs.decompiler.flash.helpers.GraphTextWriter;
import com.jpexs.decompiler.graph.CompilationException;
import com.jpexs.decompiler.graph.GraphSourceItem;
@@ -49,6 +50,11 @@ public class ToIntegerActionItem extends ActionItem {
return ret;
}
@Override
public Object getResult() {
return Math.round(EcmaScript.toNumber(value.getResult()));
}
@Override
public List<GraphSourceItem> toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException {
return toSourceMerge(localData, generator, value, new ActionToInteger());

View File

@@ -18,6 +18,7 @@ package com.jpexs.decompiler.flash.action.model;
import com.jpexs.decompiler.flash.SourceGeneratorLocalData;
import com.jpexs.decompiler.flash.action.swf5.ActionToNumber;
import com.jpexs.decompiler.flash.ecma.EcmaScript;
import com.jpexs.decompiler.flash.helpers.GraphTextWriter;
import com.jpexs.decompiler.graph.CompilationException;
import com.jpexs.decompiler.graph.GraphSourceItem;
@@ -49,6 +50,11 @@ public class ToNumberActionItem extends ActionItem {
return ret;
}
@Override
public Object getResult() {
return EcmaScript.toNumber(value.getResult());
}
@Override
public List<GraphSourceItem> toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException {
return toSourceMerge(localData, generator, value, new ActionToNumber());

View File

@@ -18,6 +18,7 @@ package com.jpexs.decompiler.flash.action.model;
import com.jpexs.decompiler.flash.SourceGeneratorLocalData;
import com.jpexs.decompiler.flash.action.swf5.ActionToString;
import com.jpexs.decompiler.flash.ecma.EcmaScript;
import com.jpexs.decompiler.flash.helpers.GraphTextWriter;
import com.jpexs.decompiler.graph.CompilationException;
import com.jpexs.decompiler.graph.GraphSourceItem;
@@ -49,6 +50,11 @@ public class ToStringActionItem extends ActionItem {
return ret;
}
@Override
public Object getResult() {
return EcmaScript.toString(value.getResult());
}
@Override
public List<GraphSourceItem> toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException {
return toSourceMerge(localData, generator, value, new ActionToString());

View File

@@ -67,7 +67,7 @@ public class AddActionItem extends BinaryOpItem {
Object leftResult = leftSide.getResult();
Object rightResult = rightSide.getResult();
if (EcmaScript.type(leftResult) == EcmaType.STRING || EcmaScript.type(rightResult) == EcmaType.STRING) {
return "" + leftResult + rightResult;
return EcmaScript.toString(leftResult) + EcmaScript.toString(rightResult);
}
return EcmaScript.toNumber(leftResult) + EcmaScript.toNumber(rightResult);
} else {

View File

@@ -35,11 +35,13 @@ public class DivideActionItem extends BinaryOpItem {
@Override
public Object getResult() {
Object rightResult = rightSide.getResult();
if (Double.compare(EcmaScript.toNumber(rightResult), 0) == 0) {
return Double.NaN;
Double leftResult = EcmaScript.toNumber(leftSide.getResult());
Double rightResult = EcmaScript.toNumber(rightSide.getResult());
if (Double.compare(rightResult, 0) == 0) {
return leftResult < 0 ? Double.NEGATIVE_INFINITY
: leftResult > 0 ? Double.POSITIVE_INFINITY : Double.NaN;
}
return (EcmaScript.toNumber(leftSide.getResult())) / (EcmaScript.toNumber(rightResult));
return leftResult / rightResult;
}
@Override

View File

@@ -35,11 +35,11 @@ public class ModuloActionItem extends BinaryOpItem {
@Override
public Object getResult() {
Object rightResult = rightSide.getResult();
if (Double.compare(EcmaScript.toNumber(rightResult), 0) == 0) {
Double rightResult = EcmaScript.toNumber(rightSide.getResult());
if (Double.isNaN(rightResult) || Double.compare(rightResult, 0) == 0) {
return Double.NaN;
}
return ((long) (double) EcmaScript.toNumber(leftSide.getResult())) % ((long) (double) EcmaScript.toNumber(rightResult));
return ((long) (double) EcmaScript.toNumber(leftSide.getResult())) % ((long) (double) rightResult);
}
@Override

View File

@@ -1,18 +1,19 @@
/*
* Copyright (C) 2010-2015 JPEXS, All rights reserved.
*
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3.0 of the License, or (at your option) any later version.
*
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library.
* License along with this library.
*/
package com.jpexs.decompiler.flash.action.model.operations;
import com.jpexs.decompiler.flash.SourceGeneratorLocalData;
@@ -34,7 +35,8 @@ public class RShiftActionItem extends BinaryOpItem {
@Override
public Object getResult() {
public Object getResult() {
long rightResult = ((long) (double) EcmaScript.toNumber(rightSide.getResult())) & 0x1f;
return ((long) (double) EcmaScript.toNumber(leftSide.getResult())) >> rightResult;
}
@Override

View File

@@ -1,22 +1,24 @@
/*
* Copyright (C) 2010-2015 JPEXS, All rights reserved.
*
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3.0 of the License, or (at your option) any later version.
*
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library.
* License along with this library.
*/
package com.jpexs.decompiler.flash.action.model.operations;
import com.jpexs.decompiler.flash.SourceGeneratorLocalData;
import com.jpexs.decompiler.flash.action.swf4.ActionStringAdd;
import com.jpexs.decompiler.flash.ecma.EcmaScript;
import com.jpexs.decompiler.graph.CompilationException;
import com.jpexs.decompiler.graph.GraphSourceItem;
import com.jpexs.decompiler.graph.GraphTargetItem;
@@ -37,6 +39,11 @@ public class StringAddActionItem extends BinaryOpItem {
return false;
}
@Override
public Object getResult() {
return EcmaScript.toString(leftSide.getResult()) + EcmaScript.toString(rightSide.getResult());
}
@Override
public List<GraphSourceItem> toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException {
return toSourceMerge(localData, generator, leftSide, rightSide, new ActionStringAdd());

View File

@@ -18,6 +18,7 @@ package com.jpexs.decompiler.flash.action.model.operations;
import com.jpexs.decompiler.flash.SourceGeneratorLocalData;
import com.jpexs.decompiler.flash.action.swf4.ActionStringEquals;
import com.jpexs.decompiler.flash.ecma.EcmaScript;
import com.jpexs.decompiler.graph.CompilationException;
import com.jpexs.decompiler.graph.GraphSourceItem;
import com.jpexs.decompiler.graph.GraphTargetItem;
@@ -38,6 +39,11 @@ public class StringEqActionItem extends BinaryOpItem implements Inverted {
return false;
}
@Override
public Object getResult() {
return EcmaScript.toString(leftSide.getResult()).equals(EcmaScript.toString(rightSide.getResult()));
}
@Override
public List<GraphSourceItem> toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException {
return toSourceMerge(localData, generator, leftSide, rightSide, new ActionStringEquals());

View File

@@ -19,6 +19,7 @@ package com.jpexs.decompiler.flash.action.model.operations;
import com.jpexs.decompiler.flash.SourceGeneratorLocalData;
import com.jpexs.decompiler.flash.action.swf4.ActionNot;
import com.jpexs.decompiler.flash.action.swf4.ActionStringLess;
import com.jpexs.decompiler.flash.ecma.EcmaScript;
import com.jpexs.decompiler.graph.CompilationException;
import com.jpexs.decompiler.graph.GraphSourceItem;
import com.jpexs.decompiler.graph.GraphTargetItem;
@@ -39,6 +40,11 @@ public class StringGeActionItem extends BinaryOpItem implements Inverted {
return false;
}
@Override
public Object getResult() {
return EcmaScript.toString(leftSide.getResult()).compareTo(EcmaScript.toString(rightSide.getResult())) >= 0;
}
@Override
public List<GraphSourceItem> toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException {
return toSourceMerge(localData, generator, leftSide, rightSide, new ActionStringLess(), new ActionNot());

View File

@@ -20,6 +20,7 @@ import com.jpexs.decompiler.flash.SourceGeneratorLocalData;
import com.jpexs.decompiler.flash.action.parser.script.ActionSourceGenerator;
import com.jpexs.decompiler.flash.action.swf4.ActionStringLess;
import com.jpexs.decompiler.flash.action.swf6.ActionStringGreater;
import com.jpexs.decompiler.flash.ecma.EcmaScript;
import com.jpexs.decompiler.graph.CompilationException;
import com.jpexs.decompiler.graph.GraphSourceItem;
import com.jpexs.decompiler.graph.GraphTargetItem;
@@ -40,6 +41,11 @@ public class StringGtActionItem extends BinaryOpItem implements Inverted {
return false;
}
@Override
public Object getResult() {
return EcmaScript.toString(leftSide.getResult()).compareTo(EcmaScript.toString(rightSide.getResult())) > 0;
}
@Override
public List<GraphSourceItem> toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException {
ActionSourceGenerator g = (ActionSourceGenerator) generator;

View File

@@ -21,6 +21,7 @@ import com.jpexs.decompiler.flash.action.parser.script.ActionSourceGenerator;
import com.jpexs.decompiler.flash.action.swf4.ActionNot;
import com.jpexs.decompiler.flash.action.swf4.ActionStringLess;
import com.jpexs.decompiler.flash.action.swf6.ActionStringGreater;
import com.jpexs.decompiler.flash.ecma.EcmaScript;
import com.jpexs.decompiler.graph.CompilationException;
import com.jpexs.decompiler.graph.GraphSourceItem;
import com.jpexs.decompiler.graph.GraphTargetItem;
@@ -41,6 +42,11 @@ public class StringLeActionItem extends BinaryOpItem implements Inverted {
return false;
}
@Override
public Object getResult() {
return EcmaScript.toString(leftSide.getResult()).compareTo(EcmaScript.toString(rightSide.getResult())) <= 0;
}
@Override
public List<GraphSourceItem> toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException {

View File

@@ -18,6 +18,7 @@ package com.jpexs.decompiler.flash.action.model.operations;
import com.jpexs.decompiler.flash.SourceGeneratorLocalData;
import com.jpexs.decompiler.flash.action.swf4.ActionStringLess;
import com.jpexs.decompiler.flash.ecma.EcmaScript;
import com.jpexs.decompiler.graph.CompilationException;
import com.jpexs.decompiler.graph.GraphSourceItem;
import com.jpexs.decompiler.graph.GraphTargetItem;
@@ -38,6 +39,11 @@ public class StringLtActionItem extends BinaryOpItem implements Inverted {
return false;
}
@Override
public Object getResult() {
return EcmaScript.toString(leftSide.getResult()).compareTo(EcmaScript.toString(rightSide.getResult())) < 0;
}
@Override
public List<GraphSourceItem> toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException {
return toSourceMerge(localData, generator, leftSide, rightSide, new ActionStringLess());

View File

@@ -1,18 +1,19 @@
/*
* Copyright (C) 2010-2015 JPEXS, All rights reserved.
*
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3.0 of the License, or (at your option) any later version.
*
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library.
* License along with this library.
*/
package com.jpexs.decompiler.flash.action.model.operations;
import com.jpexs.decompiler.flash.SourceGeneratorLocalData;
@@ -34,7 +35,9 @@ public class URShiftActionItem extends BinaryOpItem {
@Override
public Object getResult() {
public Object getResult() {
long leftResult = ((long) (double) EcmaScript.toNumber(leftSide.getResult())) & 0xffffffffL;
long rightResult = ((long) (double) EcmaScript.toNumber(rightSide.getResult())) & 0x1f;
return leftResult >>> rightResult;
}
@Override

View File

@@ -154,19 +154,19 @@ public class ActionPush extends Action {
} else if (o instanceof Boolean) {
sos.writeUI8(5);
sos.writeUI8((Boolean) o ? 1 : 0);
} else if (o instanceof Double || o instanceof Long) {
} else if (o instanceof Number) {
if (o instanceof Long) {
long l = (Long) o;
if (l < -0x80000000 || l > 0x7fffffff) {
o = (double) l;
}
}
if (o instanceof Double) {
if (o instanceof Double || o instanceof Float) {
sos.writeUI8(6);
sos.writeDOUBLE((Double) o);
} else if (o instanceof Long) {
sos.writeDOUBLE(((Number) o).doubleValue());
} else if (o instanceof Long || o instanceof Integer || o instanceof Short || o instanceof Byte) {
sos.writeUI8(7);
sos.writeSI32((Long) o);
sos.writeSI32(((Number) o).longValue());
}
} else if (o instanceof ConstantIndex) {
int cIndex = ((ConstantIndex) o).index;
@@ -202,16 +202,16 @@ public class ActionPush extends Action {
res += 2;
} else if (o instanceof Boolean) {
res += 2;
} else if (o instanceof Double || o instanceof Long) {
} else if (o instanceof Number) {
if (o instanceof Long) {
long l = (Long) o;
if (l < -0x80000000 || l > 0x7fffffff) {
o = (double) l;
}
}
if (o instanceof Double) {
if (o instanceof Double || o instanceof Float) {
res += 9;
} else if (o instanceof Long) {
} else if (o instanceof Long || o instanceof Integer || o instanceof Short || o instanceof Byte) {
res += 5;
}
} else if (o instanceof ConstantIndex) {

View File

@@ -13,8 +13,9 @@
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library.
*/
/*
*
* ----------------- Original copyright --------------------------
*
* Copyright 1996-2004 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
@@ -134,8 +135,7 @@ public class EcmaFloatingDecimal {
* count number of bits from high-order 1 bit to low-order 1 bit,
* inclusive.
*/
private static int
countBits(long v) {
private static int countBits(long v) {
//
// the strategy is to shift until we get a non-zero sign bit
// then shift until we have no bits left, counting the difference.
@@ -213,8 +213,7 @@ public class EcmaFloatingDecimal {
//
// a common operation
//
private static FDBigInt
multPow52(FDBigInt v, int p5, int p2) {
private static FDBigInt multPow52(FDBigInt v, int p5, int p2) {
if (p5 != 0) {
if (p5 < small5pow.length) {
v = v.mult(small5pow[p5]);
@@ -249,8 +248,7 @@ public class EcmaFloatingDecimal {
* bigIntExp and bigIntNBits
*
*/
private FDBigInt
doubleToBigInt(double dval) {
private FDBigInt doubleToBigInt(double dval) {
long lbits = Double.doubleToLongBits(dval) & ~signMask;
int binexp = (int) (lbits >>> expShift);
lbits &= fractMask;
@@ -926,6 +924,17 @@ public class EcmaFloatingDecimal {
roundup();
}
}
if (nDigits > 15) {
nDigits = 15;
if (digits[15] >= '5') {
roundup();
}
while (nDigits > 0 && digits[nDigits - 1] == '0') {
nDigits--;
}
}
}
public String toString() {
@@ -954,7 +963,7 @@ public class EcmaFloatingDecimal {
private int getChars(char[] result) {
assert nDigits <= 19 : nDigits; // generous bound on size of nDigits
int i = 0;
if (isNegative) {
if (isNegative && (decExponent != 0 || digits != zero)) {
result[0] = '-';
i = 1;
}
@@ -1253,8 +1262,7 @@ class FDBigInt {
* Left shift by c bits.
* Shifts this in place.
*/
public void
lshiftMe(int c) throws IllegalArgumentException {
public void lshiftMe(int c) throws IllegalArgumentException {
if (c <= 0) {
if (c == 0) {
return; // silly.
@@ -1307,8 +1315,7 @@ class FDBigInt {
* the dividend not span up into another word of precision.
* (This needs to be explained more clearly!)
*/
public int
normalizeMe() throws IllegalArgumentException {
public int normalizeMe() throws IllegalArgumentException {
int src;
int wordcount = 0;
int bitcount = 0;
@@ -1359,8 +1366,7 @@ class FDBigInt {
* Multiply a FDBigInt by an int.
* Result is a new FDBigInt.
*/
public FDBigInt
mult(int iv) {
public FDBigInt mult(int iv) {
long v = iv;
int r[];
long p;
@@ -1386,8 +1392,7 @@ class FDBigInt {
* Result is computed in place.
* Hope it fits!
*/
public void
multaddMe(int iv, int addend) {
public void multaddMe(int iv, int addend) {
long v = iv;
long p;
@@ -1410,8 +1415,7 @@ class FDBigInt {
* Multiply a FDBigInt by another FDBigInt.
* Result is a new FDBigInt.
*/
public FDBigInt
mult(FDBigInt other) {
public FDBigInt mult(FDBigInt other) {
// crudely guess adequate size for r
int r[] = new int[nWords + other.nWords];
int i;
@@ -1440,8 +1444,7 @@ class FDBigInt {
/*
* Add one FDBigInt to another. Return a FDBigInt
*/
public FDBigInt
add(FDBigInt other) {
public FDBigInt add(FDBigInt other) {
int i;
int a[], b[];
int n, m;
@@ -1482,8 +1485,7 @@ class FDBigInt {
* Subtract one FDBigInt from another. Return a FDBigInt
* Assert that the result is positive.
*/
public FDBigInt
sub(FDBigInt other) {
public FDBigInt sub(FDBigInt other) {
int r[] = new int[this.nWords];
int i;
int n = this.nWords;
@@ -1522,8 +1524,7 @@ class FDBigInt {
* 0: this == other
* <0: this < other
*/
public int
cmp(FDBigInt other) {
public int cmp(FDBigInt other) {
int i;
if (this.nWords > other.nWords) {
// if any of my high-order words is non-zero,
@@ -1584,8 +1585,7 @@ class FDBigInt {
* Also assume, of course, that the result, q, can be expressed
* as an integer, 0 <= q < 10.
*/
public int
quoRemIteration(FDBigInt S) throws IllegalArgumentException {
public int quoRemIteration(FDBigInt S) throws IllegalArgumentException {
// ensure that this and S have the same number of
// digits. If S is properly normalized and q < 10 then
// this must be so.
@@ -1641,8 +1641,7 @@ class FDBigInt {
return (int) q;
}
public long
longValue() {
public long longValue() {
// if this can be represented as a long, return the value
assert this.nWords > 0 : this.nWords; // longValue confused
@@ -1655,8 +1654,7 @@ class FDBigInt {
return ((long) (data[1]) << 32) | ((long) data[0] & 0xffffffffL);
}
public String
toString() {
public String toString() {
StringBuffer r = new StringBuffer(30);
r.append('[');
int i = Math.min(nWords - 1, data.length - 1);

View File

@@ -30,7 +30,7 @@ public class EcmaScript {
return Double.NaN;
}
if (o instanceof Null) {
return 0.0;
return Double.NaN;
}
if (o instanceof Boolean) {
return (Boolean) o ? 1.0 : 0.0;