mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/jpexs-decompiler.git
synced 2026-09-25 10:20:52 +00:00
Issue #225 AS object literal broken with ternar operator
This commit is contained in:
@@ -18,6 +18,7 @@ package com.jpexs.decompiler.flash.abc.avm2.treemodel;
|
||||
|
||||
import com.jpexs.decompiler.flash.abc.avm2.ConstantPool;
|
||||
import com.jpexs.decompiler.flash.graph.GraphTargetItem;
|
||||
import com.jpexs.decompiler.flash.graph.TernarOpItem;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
@@ -34,6 +35,10 @@ public class NameValuePair extends TreeItem {
|
||||
|
||||
@Override
|
||||
public String toString(ConstantPool constants, HashMap<Integer, String> localRegNames, List<String> fullyQualifiedNames) {
|
||||
return name.toString(constants, localRegNames, fullyQualifiedNames) + ":" + value.toString(constants, localRegNames, fullyQualifiedNames);
|
||||
String valueStr = value.toString(constants, localRegNames, fullyQualifiedNames);
|
||||
if (value instanceof TernarOpItem) { //Ternar operator contains ":"
|
||||
valueStr = "(" + valueStr + ")";
|
||||
}
|
||||
return name.toString(constants, localRegNames, fullyQualifiedNames) + ":" + valueStr;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,43 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2010-2013 JPEXS
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.jpexs.decompiler.flash.abc.avm2.treemodel.clauses;
|
||||
|
||||
import com.jpexs.decompiler.flash.abc.avm2.ConstantPool;
|
||||
import com.jpexs.decompiler.flash.abc.avm2.instructions.AVM2Instruction;
|
||||
import com.jpexs.decompiler.flash.abc.avm2.treemodel.TreeItem;
|
||||
import com.jpexs.decompiler.flash.graph.GraphTargetItem;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
public class TernarOpTreeItem extends TreeItem {
|
||||
|
||||
public GraphTargetItem expression;
|
||||
public GraphTargetItem onTrue;
|
||||
public GraphTargetItem onFalse;
|
||||
|
||||
public TernarOpTreeItem(AVM2Instruction instruction, GraphTargetItem expression, GraphTargetItem onTrue, GraphTargetItem onFalse) {
|
||||
super(instruction, PRECEDENCE_CONDITIONAL);
|
||||
this.expression = expression;
|
||||
this.onTrue = onTrue;
|
||||
this.onFalse = onFalse;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(ConstantPool constants, HashMap<Integer, String> localRegNames, List<String> fullyQualifiedNames) {
|
||||
return expression.toString(constants, localRegNames, fullyQualifiedNames) + hilight("?") + onTrue.toString(constants, localRegNames, fullyQualifiedNames) + hilight(":") + onFalse.toString(constants, localRegNames, fullyQualifiedNames);
|
||||
}
|
||||
}
|
||||
@@ -18,6 +18,7 @@ package com.jpexs.decompiler.flash.action.treemodel;
|
||||
|
||||
import com.jpexs.decompiler.flash.graph.GraphSourceItem;
|
||||
import com.jpexs.decompiler.flash.graph.GraphTargetItem;
|
||||
import com.jpexs.decompiler.flash.graph.TernarOpItem;
|
||||
import java.util.List;
|
||||
|
||||
public class InitObjectTreeItem extends TreeItem {
|
||||
@@ -38,7 +39,11 @@ public class InitObjectTreeItem extends TreeItem {
|
||||
if (i > 0) {
|
||||
objStr += hilight(",");
|
||||
}
|
||||
objStr += names.get(i).toString(constants) + hilight(":") + values.get(i).toString(constants);
|
||||
String valueStr = values.get(i).toString(constants);
|
||||
if (values.get(i) instanceof TernarOpItem) { //Ternar operator contains ":"
|
||||
valueStr = "(" + valueStr + ")";
|
||||
}
|
||||
objStr += names.get(i).toString(constants) + hilight(":") + valueStr;
|
||||
}
|
||||
return hilight("{") + objStr + hilight("}");
|
||||
}
|
||||
|
||||
@@ -1,40 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2010-2013 JPEXS
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.jpexs.decompiler.flash.action.treemodel.clauses;
|
||||
|
||||
import com.jpexs.decompiler.flash.action.Action;
|
||||
import com.jpexs.decompiler.flash.action.treemodel.ConstantPool;
|
||||
import com.jpexs.decompiler.flash.action.treemodel.TreeItem;
|
||||
|
||||
public class TernarOpTreeItem extends TreeItem {
|
||||
|
||||
public TreeItem expression;
|
||||
public TreeItem onTrue;
|
||||
public TreeItem onFalse;
|
||||
|
||||
public TernarOpTreeItem(Action instruction, TreeItem expression, TreeItem onTrue, TreeItem onFalse) {
|
||||
super(instruction, PRECEDENCE_CONDITIONAL);
|
||||
this.expression = expression;
|
||||
this.onTrue = onTrue;
|
||||
this.onFalse = onFalse;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(ConstantPool constants) {
|
||||
return expression.toString(constants) + hilight("?") + onTrue.toString(constants) + hilight(":") + onFalse.toString(constants);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user