Separated FFDec core library and the rest (GUI).

FFDec Library is now LGPLv3, others stay GPLv3.
Version changed to 3.0.0 for FFDec, 1.0.0 for FFDec Library.
This commit is contained in:
Jindra Petřík
2014-08-24 17:55:42 +02:00
parent 2479c59b03
commit 04922aaf69
1323 changed files with 53605 additions and 52175 deletions
@@ -0,0 +1,57 @@
/*
* Copyright (C) 2010-2014 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.␍ */
package com.jpexs.decompiler.graph.model;
import com.jpexs.decompiler.flash.SourceGeneratorLocalData;
import com.jpexs.decompiler.graph.CompilationException;
import com.jpexs.decompiler.graph.GraphSourceItem;
import com.jpexs.decompiler.graph.GraphSourceItemPos;
import com.jpexs.decompiler.graph.GraphTargetItem;
import com.jpexs.decompiler.graph.SourceGenerator;
import com.jpexs.decompiler.graph.TypeItem;
import java.util.List;
public class AndItem extends BinaryOpItem {
@Override
public List<GraphSourceItemPos> getNeededSources() {
List<GraphSourceItemPos> ret = super.getNeededSources();
ret.addAll(leftSide.getNeededSources());
ret.addAll(rightSide.getNeededSources());
return ret;
}
public AndItem(GraphSourceItem src, GraphTargetItem leftSide, GraphTargetItem rightSide) {
super(src, PRECEDENCE_LOGICALAND, leftSide, rightSide, "&&");
this.leftSide = leftSide;
this.rightSide = rightSide;
}
@Override
public boolean hasReturnValue() {
return true;
}
@Override
public List<GraphSourceItem> toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException {
return generator.generate(localData, this);
}
@Override
public GraphTargetItem returnType() {
return TypeItem.BOOLEAN;
}
}
@@ -0,0 +1,38 @@
/*
* Copyright (C) 2010-2014 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.␍ */
package com.jpexs.decompiler.graph.model;
import com.jpexs.decompiler.graph.GraphTargetItem;
import java.util.List;
/**
*
* @author JPEXS
*/
public interface BinaryOp {
public GraphTargetItem getLeftSide();
public GraphTargetItem getRightSide();
public void setLeftSide(GraphTargetItem value);
public void setRightSide(GraphTargetItem value);
public int getPrecedence();
public List<GraphTargetItem> getAllSubItems();
}
@@ -0,0 +1,198 @@
/*
* Copyright (C) 2010-2014 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.␍ */
package com.jpexs.decompiler.graph.model;
import com.jpexs.decompiler.flash.helpers.GraphTextWriter;
import com.jpexs.decompiler.graph.GraphPart;
import com.jpexs.decompiler.graph.GraphSourceItem;
import com.jpexs.decompiler.graph.GraphSourceItemPos;
import com.jpexs.decompiler.graph.GraphTargetItem;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
public abstract class BinaryOpItem extends GraphTargetItem implements BinaryOp {
public GraphTargetItem leftSide;
public GraphTargetItem rightSide;
protected String operator = "";
@Override
public GraphPart getFirstPart() {
GraphPart fp = leftSide.getFirstPart();
if (fp == null) {
return super.getFirstPart();
}
return fp;
}
public BinaryOpItem(GraphSourceItem instruction, int precedence, GraphTargetItem leftSide, GraphTargetItem rightSide, String operator) {
super(instruction, precedence);
this.leftSide = leftSide;
this.rightSide = rightSide;
this.operator = operator;
}
@Override
public GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) throws InterruptedException {
if (leftSide.getPrecedence() > precedence) {
writer.append("(");
leftSide.toString(writer, localData);
writer.append(")");
} else {
leftSide.toString(writer, localData);
}
writer.append(" ");
writer.append(operator);
writer.append(" ");
if (rightSide.getPrecedence() > precedence) {
writer.append("(");
rightSide.toString(writer, localData);
writer.append(")");
} else {
rightSide.toString(writer, localData);
}
return writer;
}
@Override
public List<GraphSourceItemPos> getNeededSources() {
List<GraphSourceItemPos> ret = super.getNeededSources();
ret.addAll(leftSide.getNeededSources());
ret.addAll(rightSide.getNeededSources());
return ret;
}
@Override
public boolean isCompileTime(Set<GraphTargetItem> dependencies) {
if (dependencies.contains(leftSide)) {
return false;
}
dependencies.add(leftSide);
if (leftSide != rightSide && dependencies.contains(rightSide)) {
return false;
}
dependencies.add(rightSide);
return leftSide.isCompileTime(dependencies) && rightSide.isCompileTime(dependencies);
}
@Override
public boolean isVariableComputed() {
return leftSide.isVariableComputed() || rightSide.isVariableComputed();
}
@Override
public boolean hasSideEffect() {
return leftSide.hasSideEffect() || rightSide.hasSideEffect();
}
@Override
public int hashCode() {
int hash = 7;
hash = 71 * hash + (this.leftSide != null ? this.leftSide.hashCode() : 0);
hash = 71 * hash + (this.rightSide != null ? this.rightSide.hashCode() : 0);
hash = 71 * hash + (this.operator != null ? this.operator.hashCode() : 0);
return hash;
}
public GraphTargetItem getLeftMostItem(GraphTargetItem item) {
GraphTargetItem ret = item;
if (ret instanceof BinaryOpItem) {
ret = ((BinaryOpItem) ret).getLeftMostItem();
}
return ret;
}
public GraphTargetItem getLeftMostItem() {
GraphTargetItem ret = leftSide;
if (ret instanceof BinaryOpItem) {
ret = ((BinaryOpItem) ret).getLeftMostItem();
}
return ret;
}
@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final BinaryOpItem other = (BinaryOpItem) obj;
if (this.leftSide != other.leftSide && (this.leftSide == null || !this.leftSide.equals(other.leftSide))) {
return false;
}
if (this.rightSide != other.rightSide && (this.rightSide == null || !this.rightSide.equals(other.rightSide))) {
return false;
}
if ((this.operator == null) ? (other.operator != null) : !this.operator.equals(other.operator)) {
return false;
}
return true;
}
/*@Override
public boolean toBoolean() {
double val=toNumber();
if(Double.isNaN(val)){
return false;
}
if(Double.compare(val, 0)==0){
return false;
}
return true;
}*/
@Override
public GraphTargetItem getLeftSide() {
return leftSide;
}
@Override
public GraphTargetItem getRightSide() {
return rightSide;
}
@Override
public void setLeftSide(GraphTargetItem value) {
leftSide = value;
}
@Override
public void setRightSide(GraphTargetItem value) {
rightSide = value;
}
@Override
public int getPrecedence() {
return precedence;
}
@Override
public boolean hasReturnValue() {
return true;
}
@Override
public List<GraphTargetItem> getAllSubItems() {
List<GraphTargetItem> ret = new ArrayList<>();
ret.add(getLeftSide());
ret.add(getRightSide());
return ret;
}
}
@@ -0,0 +1,62 @@
/*
* Copyright (C) 2010-2014 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.␍ */
package com.jpexs.decompiler.graph.model;
import com.jpexs.decompiler.flash.SourceGeneratorLocalData;
import com.jpexs.decompiler.flash.helpers.GraphTextWriter;
import com.jpexs.decompiler.graph.CompilationException;
import com.jpexs.decompiler.graph.Graph;
import com.jpexs.decompiler.graph.GraphSourceItem;
import com.jpexs.decompiler.graph.GraphTargetItem;
import com.jpexs.decompiler.graph.SourceGenerator;
import com.jpexs.decompiler.graph.TypeItem;
import java.util.List;
/**
*
* @author JPEXS
*/
public class BlockItem extends GraphTargetItem {
List<GraphTargetItem> commands;
public BlockItem(GraphSourceItem src, List<GraphTargetItem> commands) {
super(src, PRECEDENCE_PRIMARY);
this.commands = commands;
}
@Override
public GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) throws InterruptedException {
writer.startBlock();
Graph.graphToString(commands, writer, localData);
return writer.endBlock();
}
@Override
public List<GraphSourceItem> toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException {
return generator.generate(localData, commands);
}
@Override
public boolean hasReturnValue() {
return false;
}
@Override
public GraphTargetItem returnType() {
return TypeItem.UNBOUNDED;
}
}
@@ -0,0 +1,72 @@
/*
* Copyright (C) 2010-2014 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.␍ */
package com.jpexs.decompiler.graph.model;
import com.jpexs.decompiler.flash.SourceGeneratorLocalData;
import com.jpexs.decompiler.flash.helpers.GraphTextWriter;
import com.jpexs.decompiler.flash.helpers.NulWriter;
import com.jpexs.decompiler.graph.CompilationException;
import com.jpexs.decompiler.graph.GraphSourceItem;
import com.jpexs.decompiler.graph.GraphTargetItem;
import com.jpexs.decompiler.graph.SourceGenerator;
import com.jpexs.decompiler.graph.TypeItem;
import java.util.List;
/**
*
* @author JPEXS
*/
public class BreakItem extends GraphTargetItem {
public long loopId;
private boolean labelRequired;
public BreakItem(GraphSourceItem src, long loopId) {
super(src, NOPRECEDENCE);
this.loopId = loopId;
}
@Override
public GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) {
writer.append("break");
if (writer instanceof NulWriter) {
NulWriter nulWriter = (NulWriter) writer;
labelRequired = loopId != nulWriter.getLoop();
if (labelRequired) {
nulWriter.setLoopUsed(loopId);
}
}
if (labelRequired) {
writer.append(" loop" + loopId);
}
return writer;
}
@Override
public List<GraphSourceItem> toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException {
return generator.generate(localData, this);
}
@Override
public boolean hasReturnValue() {
return false;
}
@Override
public GraphTargetItem returnType() {
return TypeItem.UNBOUNDED;
}
}
@@ -0,0 +1,67 @@
/*
* Copyright (C) 2010-2014 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.␍ */
package com.jpexs.decompiler.graph.model;
import com.jpexs.decompiler.flash.SourceGeneratorLocalData;
import com.jpexs.decompiler.flash.helpers.GraphTextWriter;
import com.jpexs.decompiler.graph.CompilationException;
import com.jpexs.decompiler.graph.GraphSourceItem;
import com.jpexs.decompiler.graph.GraphTargetItem;
import com.jpexs.decompiler.graph.SourceGenerator;
import com.jpexs.decompiler.graph.TypeItem;
import java.util.List;
/**
*
* @author JPEXS
*/
public class CommaExpressionItem extends GraphTargetItem {
public List<GraphTargetItem> commands;
public CommaExpressionItem(GraphSourceItem src, List<GraphTargetItem> commands) {
super(src, PRECEDENCE_PRIMARY);
this.commands = commands;
}
@Override
public GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) throws InterruptedException {
boolean first = true;
for (GraphTargetItem t : commands) {
if (!first) {
writer.append(", ");
}
t.toString(writer, localData);
first = false;
}
return writer;
}
@Override
public List<GraphSourceItem> toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException {
return generator.generate(localData, this);
}
@Override
public boolean hasReturnValue() {
return false;
}
@Override
public GraphTargetItem returnType() {
return commands.isEmpty() ? TypeItem.UNBOUNDED : commands.get(commands.size() - 1).returnType();
}
}
@@ -0,0 +1,75 @@
/*
* Copyright (C) 2010-2014 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.␍ */
package com.jpexs.decompiler.graph.model;
import com.jpexs.decompiler.flash.helpers.GraphTextWriter;
import com.jpexs.decompiler.graph.GraphTargetItem;
import com.jpexs.decompiler.graph.TypeItem;
/**
*
* @author JPEXS
*/
public class CommentItem extends GraphTargetItem {
private final String[] commentLines;
public CommentItem(String comment) {
super(null, NOPRECEDENCE);
this.commentLines = new String[]{comment};
}
public CommentItem(String[] commentLines) {
super(null, NOPRECEDENCE);
this.commentLines = commentLines;
}
@Override
public GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) {
writer.append("/* ");
for (int i = 0; i < commentLines.length; i++) {
writer.append(commentLines[i]);
if (i != commentLines.length - 1) {
writer.newLine();
}
}
return writer.append(" */");
}
public String[] getCommentLines() {
return commentLines;
}
@Override
public boolean isEmpty() {
return false;
}
@Override
public boolean needsSemicolon() {
return false;
}
@Override
public boolean hasReturnValue() {
return false;
}
@Override
public GraphTargetItem returnType() {
return TypeItem.UNBOUNDED;
}
}
@@ -0,0 +1,72 @@
/*
* Copyright (C) 2010-2014 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.␍ */
package com.jpexs.decompiler.graph.model;
import com.jpexs.decompiler.flash.SourceGeneratorLocalData;
import com.jpexs.decompiler.flash.helpers.GraphTextWriter;
import com.jpexs.decompiler.flash.helpers.NulWriter;
import com.jpexs.decompiler.graph.CompilationException;
import com.jpexs.decompiler.graph.GraphSourceItem;
import com.jpexs.decompiler.graph.GraphTargetItem;
import com.jpexs.decompiler.graph.SourceGenerator;
import com.jpexs.decompiler.graph.TypeItem;
import java.util.List;
/**
*
* @author JPEXS
*/
public class ContinueItem extends GraphTargetItem {
public long loopId;
private boolean labelRequired;
public ContinueItem(GraphSourceItem src, long loopId) {
super(src, NOPRECEDENCE);
this.loopId = loopId;
}
@Override
public GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) {
writer.append("continue");
if (writer instanceof NulWriter) {
NulWriter nulWriter = (NulWriter) writer;
labelRequired = loopId != nulWriter.getNonSwitchLoop();
if (labelRequired) {
nulWriter.setLoopUsed(loopId);
}
}
if (labelRequired) {
writer.append(" loop" + loopId);
}
return writer;
}
@Override
public List<GraphSourceItem> toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException {
return generator.generate(localData, this);
}
@Override
public boolean hasReturnValue() {
return false;
}
@Override
public GraphTargetItem returnType() {
return TypeItem.UNBOUNDED;
}
}
@@ -0,0 +1,126 @@
/*
* Copyright (C) 2010-2014 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.␍ */
package com.jpexs.decompiler.graph.model;
import com.jpexs.decompiler.flash.SourceGeneratorLocalData;
import com.jpexs.decompiler.flash.helpers.GraphTextWriter;
import com.jpexs.decompiler.flash.helpers.LoopWithType;
import com.jpexs.decompiler.flash.helpers.NulWriter;
import com.jpexs.decompiler.graph.Block;
import com.jpexs.decompiler.graph.CompilationException;
import com.jpexs.decompiler.graph.GraphSourceItem;
import com.jpexs.decompiler.graph.GraphTargetItem;
import com.jpexs.decompiler.graph.Loop;
import com.jpexs.decompiler.graph.SourceGenerator;
import com.jpexs.decompiler.graph.TypeItem;
import java.util.ArrayList;
import java.util.List;
public class DoWhileItem extends LoopItem implements Block {
public List<GraphTargetItem> commands;
public List<GraphTargetItem> expression;
private boolean labelUsed;
@Override
public boolean needsSemicolon() {
return false;
}
@Override
public List<List<GraphTargetItem>> getSubs() {
List<List<GraphTargetItem>> ret = new ArrayList<>();
if (commands != null) {
ret.add(commands);
}
return ret;
}
public DoWhileItem(GraphSourceItem src, Loop loop, List<GraphTargetItem> commands, List<GraphTargetItem> expression) {
super(src, loop);
this.expression = expression;
this.commands = commands;
}
@Override
public GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) throws InterruptedException {
if (writer instanceof NulWriter) {
((NulWriter) writer).startLoop(loop.id, LoopWithType.LOOP_TYPE_LOOP);
}
if (labelUsed) {
writer.append("loop" + loop.id + ":").newLine();
}
writer.append("do");
writer.startBlock();
for (GraphTargetItem ti : commands) {
if (!ti.isEmpty()) {
ti.toStringSemicoloned(writer, localData).newLine();
}
}
writer.endBlock().newLine();
writer.append("while");
if (writer.getFormatting().spaceBeforeParenthesesWhileParentheses) {
writer.append(" ");
}
writer.append("(");
for (int i = 0; i < expression.size(); i++) {
if (expression.get(i).isEmpty()) {
continue;
}
if (i != 0) {
writer.append(", ");
}
expression.get(i).toString(writer, localData);
}
writer.append(");").newLine();
if (writer instanceof NulWriter) {
LoopWithType loopOjb = ((NulWriter) writer).endLoop(loop.id);
labelUsed = loopOjb.used;
}
return writer;
}
@Override
public List<ContinueItem> getContinues() {
List<ContinueItem> ret = new ArrayList<>();
for (GraphTargetItem ti : commands) {
if (ti instanceof ContinueItem) {
ret.add((ContinueItem) ti);
}
if (ti instanceof Block) {
ret.addAll(((Block) ti).getContinues());
}
}
return ret;
}
@Override
public List<GraphSourceItem> toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException {
return generator.generate(localData, this);
}
@Override
public boolean hasReturnValue() {
return false;
}
@Override
public GraphTargetItem returnType() {
return TypeItem.UNBOUNDED;
}
}
@@ -0,0 +1,92 @@
/*
* Copyright (C) 2010-2014 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.␍ */
package com.jpexs.decompiler.graph.model;
import com.jpexs.decompiler.flash.SourceGeneratorLocalData;
import com.jpexs.decompiler.flash.helpers.GraphTextWriter;
import com.jpexs.decompiler.graph.CompilationException;
import com.jpexs.decompiler.graph.GraphSourceItem;
import com.jpexs.decompiler.graph.GraphTargetItem;
import com.jpexs.decompiler.graph.SourceGenerator;
import com.jpexs.decompiler.graph.TypeItem;
import java.util.List;
import java.util.Set;
/**
*
* @author JPEXS
*/
public class DuplicateItem extends GraphTargetItem {
public DuplicateItem(GraphSourceItem src, GraphTargetItem value) {
super(src, value.getPrecedence());
this.value = value;
}
@Override
public Object getResult() {
return value.getResult();
}
@Override
public GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) throws InterruptedException {
return value.toString(writer, localData);
}
@Override
public GraphTargetItem getNotCoerced() {
return value.getNotCoerced();
}
@Override
public GraphTargetItem getThroughRegister() {
return value.getThroughRegister();
}
@Override
public GraphTargetItem getThroughDuplicate() {
return value.getThroughDuplicate();
}
@Override
public boolean isCompileTime(Set<GraphTargetItem> dependencies) {
if (dependencies.contains(value)) {
return false;
}
dependencies.add(value);
return value.isCompileTime(dependencies);
}
@Override
public boolean isVariableComputed() {
return value.isVariableComputed();
}
@Override
public List<GraphSourceItem> toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException {
return generator.generate(localData, this);
}
@Override
public boolean hasReturnValue() {
return true;
}
@Override
public GraphTargetItem returnType() {
return TypeItem.UNBOUNDED;
}
}
@@ -0,0 +1,23 @@
/*
* Copyright (C) 2010-2014 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.␍ */
package com.jpexs.decompiler.graph.model;
/**
*
* @author JPEXS
*/
public interface ExitItem {
}
@@ -0,0 +1,149 @@
/*
* Copyright (C) 2010-2014 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.␍ */
package com.jpexs.decompiler.graph.model;
import com.jpexs.decompiler.flash.SourceGeneratorLocalData;
import com.jpexs.decompiler.flash.helpers.GraphTextWriter;
import com.jpexs.decompiler.flash.helpers.LoopWithType;
import com.jpexs.decompiler.flash.helpers.NulWriter;
import com.jpexs.decompiler.graph.Block;
import com.jpexs.decompiler.graph.CompilationException;
import com.jpexs.decompiler.graph.GraphSourceItem;
import com.jpexs.decompiler.graph.GraphTargetItem;
import com.jpexs.decompiler.graph.Loop;
import com.jpexs.decompiler.graph.SourceGenerator;
import com.jpexs.decompiler.graph.TypeItem;
import java.util.ArrayList;
import java.util.List;
public class ForItem extends LoopItem implements Block {
public List<GraphTargetItem> firstCommands;
public GraphTargetItem expression;
public List<GraphTargetItem> finalCommands;
public List<GraphTargetItem> commands;
private boolean labelUsed;
@Override
public List<List<GraphTargetItem>> getSubs() {
List<List<GraphTargetItem>> ret = new ArrayList<>();
if (firstCommands != null) {
ret.add(firstCommands);
}
if (commands != null) {
ret.add(commands);
}
if (finalCommands != null) {
ret.add(finalCommands);
}
return ret;
}
public ForItem(GraphSourceItem src, Loop loop, List<GraphTargetItem> firstCommands, GraphTargetItem expression, List<GraphTargetItem> finalCommands, List<GraphTargetItem> commands) {
super(src, loop);
this.firstCommands = firstCommands;
this.expression = expression;
this.finalCommands = finalCommands;
this.commands = commands;
}
@Override
public GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) throws InterruptedException {
if (writer instanceof NulWriter) {
((NulWriter) writer).startLoop(loop.id, LoopWithType.LOOP_TYPE_LOOP);
}
if (labelUsed) {
writer.append("loop" + loop.id + ":").newLine();
}
writer.append("for");
if (writer.getFormatting().spaceBeforeParenthesesForParentheses) {
writer.append(" ");
}
writer.append("(");
int p = 0;
for (int i = 0; i < firstCommands.size(); i++) {
if (firstCommands.get(i).isEmpty()) {
continue;
}
if (p > 0) {
writer.append(",");
}
firstCommands.get(i).toString(writer, localData);
p++;
}
writer.append(";");
expression.toString(writer, localData);
writer.append(";");
p = 0;
for (int i = 0; i < finalCommands.size(); i++) {
if (finalCommands.get(i).isEmpty()) {
continue;
}
if (p > 0) {
writer.append(",");
}
finalCommands.get(i).toString(writer, localData);
p++;
}
writer.append(")").startBlock();
for (GraphTargetItem ti : commands) {
if (!ti.isEmpty()) {
ti.toStringSemicoloned(writer, localData).newLine();
}
}
writer.endBlock();
if (writer instanceof NulWriter) {
LoopWithType loopOjb = ((NulWriter) writer).endLoop(loop.id);
labelUsed = loopOjb.used;
}
return writer;
}
@Override
public boolean needsSemicolon() {
return false;
}
@Override
public List<ContinueItem> getContinues() {
List<ContinueItem> ret = new ArrayList<>();
for (GraphTargetItem ti : commands) {
if (ti instanceof ContinueItem) {
ret.add((ContinueItem) ti);
}
if (ti instanceof Block) {
ret.addAll(((Block) ti).getContinues());
}
}
return ret;
}
@Override
public List<GraphSourceItem> toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException {
return generator.generate(localData, this);
}
@Override
public boolean hasReturnValue() {
return false;
}
@Override
public GraphTargetItem returnType() {
return TypeItem.UNBOUNDED;
}
}
@@ -0,0 +1,163 @@
/*
* Copyright (C) 2010-2014 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.␍ */
package com.jpexs.decompiler.graph.model;
import com.jpexs.decompiler.flash.SourceGeneratorLocalData;
import com.jpexs.decompiler.flash.helpers.GraphTextWriter;
import com.jpexs.decompiler.graph.Block;
import com.jpexs.decompiler.graph.CompilationException;
import com.jpexs.decompiler.graph.GraphSourceItem;
import com.jpexs.decompiler.graph.GraphTargetItem;
import com.jpexs.decompiler.graph.SourceGenerator;
import com.jpexs.decompiler.graph.TypeItem;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
public class IfItem extends GraphTargetItem implements Block {
public GraphTargetItem expression;
public List<GraphTargetItem> onTrue;
public List<GraphTargetItem> onFalse;
@Override
public boolean isCompileTime(Set<GraphTargetItem> dependencies) {
if (dependencies.contains(expression)) {
return false;
}
dependencies.add(expression);
return expression.isCompileTime(dependencies);
}
@Override
public List<List<GraphTargetItem>> getSubs() {
List<List<GraphTargetItem>> ret = new ArrayList<>();
if (onTrue != null) {
ret.add(onTrue);
}
if (onFalse != null) {
ret.add(onFalse);
}
return ret;
}
public IfItem(GraphSourceItem src, GraphTargetItem expression, List<GraphTargetItem> onTrue, List<GraphTargetItem> onFalse) {
super(src, NOPRECEDENCE);
this.expression = expression;
this.onTrue = onTrue;
this.onFalse = onFalse;
}
@Override
public GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) throws InterruptedException {
GraphTargetItem expr = expression;
List<GraphTargetItem> ifBranch = onTrue;
List<GraphTargetItem> elseBranch = onFalse;
if (onTrue.isEmpty()) {
if (onFalse.isEmpty()) {
if (expr instanceof NotItem) {
expr = ((NotItem) expr).getOriginal();
}
} else {
if (expr instanceof LogicalOpItem) {
expr = ((LogicalOpItem) expr).invert();
} else {
expr = new NotItem(null, expr);
}
ifBranch = onFalse;
elseBranch = onTrue;
}
}
writer.append("if");
if (writer.getFormatting().spaceBeforeParenthesesIfParentheses) {
writer.append(" ");
}
writer.append("(");
expr.toString(writer, localData);
writer.append(")").startBlock();
for (GraphTargetItem ti : ifBranch) {
if (!ti.isEmpty()) {
ti.toStringSemicoloned(writer, localData).newLine();
}
}
writer.endBlock();
if (elseBranch.size() > 0) {
boolean elseIf = elseBranch.size() == 1 && (elseBranch.get(0) instanceof IfItem);
if (writer.getFormatting().beginBlockOnNewLine) {
writer.newLine();
} else {
writer.append(" ");
}
writer.append("else");
if (!elseIf) {
writer.startBlock();
} else {
writer.append(" ");
}
for (GraphTargetItem ti : elseBranch) {
if (!ti.isEmpty()) {
ti.toStringSemicoloned(writer, localData).newLine();
}
}
if (!elseIf) {
writer.endBlock();
}
}
return writer;
}
@Override
public boolean needsSemicolon() {
return false;
}
@Override
public List<ContinueItem> getContinues() {
List<ContinueItem> ret = new ArrayList<>();
for (GraphTargetItem ti : onTrue) {
if (ti instanceof ContinueItem) {
ret.add((ContinueItem) ti);
}
if (ti instanceof Block) {
ret.addAll(((Block) ti).getContinues());
}
}
for (GraphTargetItem ti : onFalse) {
if (ti instanceof ContinueItem) {
ret.add((ContinueItem) ti);
}
if (ti instanceof Block) {
ret.addAll(((Block) ti).getContinues());
}
}
return ret;
}
@Override
public List<GraphSourceItem> toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException {
return generator.generate(localData, this);
}
@Override
public boolean hasReturnValue() {
return false;
}
@Override
public GraphTargetItem returnType() {
return TypeItem.UNBOUNDED;
}
}
@@ -0,0 +1,61 @@
/*
* Copyright (C) 2010-2014 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.␍ */
package com.jpexs.decompiler.graph.model;
import com.jpexs.decompiler.flash.helpers.GraphTextWriter;
import com.jpexs.decompiler.graph.GraphSourceItem;
import com.jpexs.decompiler.graph.GraphTargetItem;
import com.jpexs.decompiler.graph.TypeItem;
import java.util.Set;
/**
*
* @author JPEXS
*/
public class IntegerValueItem extends GraphTargetItem {
private final int intValue;
public IntegerValueItem(GraphSourceItem src, int value) {
super(src, PRECEDENCE_PRIMARY);
this.intValue = value;
}
@Override
public GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) {
return writer.append("" + intValue);
}
@Override
public boolean isCompileTime(Set<GraphTargetItem> dependencies) {
return true;
}
@Override
public Object getResult() {
return Double.valueOf(intValue);
}
@Override
public boolean hasReturnValue() {
return true;
}
@Override
public GraphTargetItem returnType() {
return TypeItem.UNBOUNDED;
}
}
@@ -0,0 +1,47 @@
/*
* Copyright (C) 2010-2014 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.␍ */
package com.jpexs.decompiler.graph.model;
import com.jpexs.decompiler.flash.action.model.ConstantPool;
import java.util.HashMap;
import java.util.List;
/**
*
* @author JPEXS
*/
public class LocalData {
public static LocalData empty = new LocalData();
public ConstantPool constants;
public com.jpexs.decompiler.flash.abc.avm2.ConstantPool constantsAvm2;
public HashMap<Integer, String> localRegNames;
public List<String> fullyQualifiedNames;
public static LocalData create(ConstantPool constants) {
LocalData localData = new LocalData();
localData.constants = constants;
return localData;
}
public static LocalData create(com.jpexs.decompiler.flash.abc.avm2.ConstantPool constants, HashMap<Integer, String> localRegNames, List<String> fullyQualifiedNames) {
LocalData localData = new LocalData();
localData.constantsAvm2 = constants;
localData.localRegNames = localRegNames;
localData.fullyQualifiedNames = fullyQualifiedNames;
return localData;
}
}
@@ -0,0 +1,27 @@
/*
* Copyright (C) 2010-2014 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.␍ */
package com.jpexs.decompiler.graph.model;
import com.jpexs.decompiler.graph.GraphTargetItem;
/**
*
* @author JPEXS
*/
public interface LogicalOpItem {
public GraphTargetItem invert();
}
@@ -0,0 +1,30 @@
/*
* Copyright (C) 2010-2014 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.␍ */
package com.jpexs.decompiler.graph.model;
import com.jpexs.decompiler.graph.GraphSourceItem;
import com.jpexs.decompiler.graph.GraphTargetItem;
import com.jpexs.decompiler.graph.Loop;
public abstract class LoopItem extends GraphTargetItem {
public Loop loop;
public LoopItem(GraphSourceItem src, Loop loop) {
super(src, NOPRECEDENCE);
this.loop = loop;
}
}
@@ -0,0 +1,83 @@
/*
* Copyright (C) 2010-2014 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.␍ */
package com.jpexs.decompiler.graph.model;
import com.jpexs.decompiler.flash.SourceGeneratorLocalData;
import com.jpexs.decompiler.flash.action.model.operations.Inverted;
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;
import com.jpexs.decompiler.graph.SourceGenerator;
import com.jpexs.decompiler.graph.TypeItem;
import java.util.List;
import java.util.Set;
/**
*
* @author JPEXS
*/
public class NotItem extends UnaryOpItem implements LogicalOpItem, Inverted {
public NotItem(GraphSourceItem instruction, GraphTargetItem value) {
super(instruction, PRECEDENCE_UNARY, value, "!");
}
@Override
public Object getResult() {
Object ret = EcmaScript.toBoolean(value.getResult());
if (ret == Boolean.TRUE) {
return Boolean.FALSE;
}
if (ret == Boolean.FALSE) {
return Boolean.TRUE;
}
return ret;
}
@Override
public boolean isCompileTime(Set<GraphTargetItem> dependencies) {
if (dependencies.contains(value)) {
return false;
}
dependencies.add(value);
return value.isCompileTime(dependencies);
}
@Override
public GraphTargetItem invert() {
return value;
}
public GraphTargetItem getOriginal() {
return value;
}
@Override
public List<GraphSourceItem> toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException {
return generator.generate(localData, this);
}
@Override
public boolean hasReturnValue() {
return true;
}
@Override
public GraphTargetItem returnType() {
return TypeItem.BOOLEAN;
}
}
@@ -0,0 +1,57 @@
/*
* Copyright (C) 2010-2014 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.␍ */
package com.jpexs.decompiler.graph.model;
import com.jpexs.decompiler.flash.SourceGeneratorLocalData;
import com.jpexs.decompiler.graph.CompilationException;
import com.jpexs.decompiler.graph.GraphSourceItem;
import com.jpexs.decompiler.graph.GraphSourceItemPos;
import com.jpexs.decompiler.graph.GraphTargetItem;
import com.jpexs.decompiler.graph.SourceGenerator;
import com.jpexs.decompiler.graph.TypeItem;
import java.util.List;
public class OrItem extends BinaryOpItem {
public OrItem(GraphSourceItem src, GraphTargetItem leftSide, GraphTargetItem rightSide) {
super(src, PRECEDENCE_LOGICALOR, leftSide, rightSide, "||");
this.leftSide = leftSide;
this.rightSide = rightSide;
}
@Override
public List<GraphSourceItemPos> getNeededSources() {
List<GraphSourceItemPos> ret = super.getNeededSources();
ret.addAll(leftSide.getNeededSources());
ret.addAll(rightSide.getNeededSources());
return ret;
}
@Override
public List<GraphSourceItem> toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException {
return generator.generate(localData, this);
}
@Override
public boolean hasReturnValue() {
return true;
}
@Override
public GraphTargetItem returnType() {
return TypeItem.BOOLEAN;
}
}
@@ -0,0 +1,58 @@
/*
* Copyright (C) 2010-2014 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.␍ */
package com.jpexs.decompiler.graph.model;
import com.jpexs.decompiler.flash.SourceGeneratorLocalData;
import com.jpexs.decompiler.flash.helpers.GraphTextWriter;
import com.jpexs.decompiler.graph.CompilationException;
import com.jpexs.decompiler.graph.GraphSourceItem;
import com.jpexs.decompiler.graph.GraphTargetItem;
import com.jpexs.decompiler.graph.SourceGenerator;
import java.util.List;
/**
*
* @author JPEXS
*/
public class ParenthesisItem extends GraphTargetItem {
public ParenthesisItem(GraphSourceItem src, GraphTargetItem value) {
super(src, PRECEDENCE_PRIMARY);
this.value = value;
}
@Override
public GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) throws InterruptedException {
writer.append("(");
value.toString(writer, localData);
return writer.append(")");
}
@Override
public List<GraphSourceItem> toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException {
return value.toSource(localData, generator);
}
@Override
public boolean hasReturnValue() {
return value.hasReturnValue();
}
@Override
public GraphTargetItem returnType() {
return value.returnType();
}
}
@@ -0,0 +1,56 @@
/*
* Copyright (C) 2010-2014 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.␍ */
package com.jpexs.decompiler.graph.model;
import com.jpexs.decompiler.flash.helpers.GraphTextWriter;
import com.jpexs.decompiler.graph.GraphTargetItem;
import com.jpexs.decompiler.graph.TypeItem;
/**
*
* @author JPEXS
*/
public class ScriptEndItem extends GraphTargetItem implements ExitItem {
public ScriptEndItem() {
super(null, NOPRECEDENCE);
}
@Override
public GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) {
return writer;
}
@Override
public boolean needsSemicolon() {
return false;
}
@Override
public boolean isEmpty() {
return true;
}
@Override
public boolean hasReturnValue() {
return false;
}
@Override
public GraphTargetItem returnType() {
return TypeItem.UNBOUNDED;
}
}
@@ -0,0 +1,158 @@
/*
* Copyright (C) 2010-2014 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.␍ */
package com.jpexs.decompiler.graph.model;
import com.jpexs.decompiler.flash.SourceGeneratorLocalData;
import com.jpexs.decompiler.flash.helpers.GraphTextWriter;
import com.jpexs.decompiler.flash.helpers.LoopWithType;
import com.jpexs.decompiler.flash.helpers.NulWriter;
import com.jpexs.decompiler.graph.Block;
import com.jpexs.decompiler.graph.CompilationException;
import com.jpexs.decompiler.graph.GraphSourceItem;
import com.jpexs.decompiler.graph.GraphTargetItem;
import com.jpexs.decompiler.graph.Loop;
import com.jpexs.decompiler.graph.SourceGenerator;
import com.jpexs.decompiler.graph.TypeItem;
import java.util.ArrayList;
import java.util.List;
public class SwitchItem extends LoopItem implements Block {
public GraphTargetItem switchedObject;
public List<GraphTargetItem> caseValues;
public List<List<GraphTargetItem>> caseCommands;
public List<GraphTargetItem> defaultCommands;
public List<Integer> valuesMapping;
private boolean labelUsed;
@Override
public List<List<GraphTargetItem>> getSubs() {
List<List<GraphTargetItem>> ret = new ArrayList<>();
ret.addAll(caseCommands);
if (defaultCommands != null) {
ret.add(defaultCommands);
}
return ret;
}
public SwitchItem(GraphSourceItem instruction, Loop loop, GraphTargetItem switchedObject, List<GraphTargetItem> caseValues, List<List<GraphTargetItem>> caseCommands, List<GraphTargetItem> defaultCommands, List<Integer> valuesMapping) {
super(instruction, loop);
this.switchedObject = switchedObject;
this.caseValues = caseValues;
this.caseCommands = caseCommands;
this.defaultCommands = defaultCommands;
this.valuesMapping = valuesMapping;
}
@Override
public boolean needsSemicolon() {
return false;
}
@Override
public GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) throws InterruptedException {
if (writer instanceof NulWriter) {
((NulWriter) writer).startLoop(loop.id, LoopWithType.LOOP_TYPE_SWITCH);
}
if (labelUsed) {
writer.append("loop" + loop.id + ":").newLine();
}
writer.append("switch");
if (writer.getFormatting().spaceBeforeParenthesesSwitchParentheses) {
writer.append(" ");
}
writer.append("(");
switchedObject.toString(writer, localData);
writer.append(")").startBlock();
for (int i = 0; i < caseCommands.size(); i++) {
for (int k = 0; k < valuesMapping.size(); k++) {
if (valuesMapping.get(k) == i) {
writer.append("case ");
caseValues.get(k).toString(writer, localData);
writer.append(":").newLine();
}
}
writer.indent();
for (int j = 0; j < caseCommands.get(i).size(); j++) {
if (!caseCommands.get(i).get(j).isEmpty()) {
caseCommands.get(i).get(j).toStringSemicoloned(writer, localData).newLine();
}
}
writer.unindent();
}
if (defaultCommands != null) {
if (defaultCommands.size() > 0) {
writer.append("default");
writer.append(":").newLine();
writer.indent();
for (int j = 0; j < defaultCommands.size(); j++) {
if (!defaultCommands.get(j).isEmpty()) {
defaultCommands.get(j).toStringSemicoloned(writer, localData).newLine();
}
}
writer.unindent();
}
}
writer.endBlock();
if (writer instanceof NulWriter) {
LoopWithType loopOjb = ((NulWriter) writer).endLoop(loop.id);
labelUsed = loopOjb.used;
}
return writer;
}
@Override
public List<ContinueItem> getContinues() {
List<ContinueItem> ret = new ArrayList<>();
for (List<GraphTargetItem> onecase : caseCommands) {
for (GraphTargetItem ti : onecase) {
if (ti instanceof ContinueItem) {
ret.add((ContinueItem) ti);
}
if (ti instanceof Block) {
ret.addAll(((Block) ti).getContinues());
}
}
}
if (defaultCommands != null) {
for (GraphTargetItem ti : defaultCommands) {
if (ti instanceof ContinueItem) {
ret.add((ContinueItem) ti);
}
if (ti instanceof Block) {
ret.addAll(((Block) ti).getContinues());
}
}
}
return ret;
}
@Override
public List<GraphSourceItem> toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException {
return generator.generate(localData, this);
}
@Override
public boolean hasReturnValue() {
return false;
}
@Override
public GraphTargetItem returnType() {
return TypeItem.UNBOUNDED;
}
}
@@ -0,0 +1,63 @@
/*
* Copyright (C) 2010-2014 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.␍ */
package com.jpexs.decompiler.graph.model;
import com.jpexs.decompiler.flash.SourceGeneratorLocalData;
import com.jpexs.decompiler.flash.helpers.GraphTextWriter;
import com.jpexs.decompiler.graph.CompilationException;
import com.jpexs.decompiler.graph.GraphSourceItem;
import com.jpexs.decompiler.graph.GraphTargetItem;
import com.jpexs.decompiler.graph.SourceGenerator;
import java.util.List;
public class TernarOpItem extends GraphTargetItem {
public GraphTargetItem expression;
public GraphTargetItem onTrue;
public GraphTargetItem onFalse;
public TernarOpItem(GraphSourceItem src, GraphTargetItem expression, GraphTargetItem onTrue, GraphTargetItem onFalse) {
super(src, PRECEDENCE_CONDITIONAL);
this.expression = expression;
this.onTrue = onTrue;
this.onFalse = onFalse;
}
@Override
public GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) throws InterruptedException {
expression.toString(writer, localData);
writer.append("?");
onTrue.toString(writer, localData);
writer.append(":");
onFalse.toString(writer, localData);
return writer;
}
@Override
public List<GraphSourceItem> toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException {
return generator.generate(localData, this);
}
@Override
public boolean hasReturnValue() {
return true;
}
@Override
public GraphTargetItem returnType() {
return onTrue.returnType();
}
}
@@ -0,0 +1,47 @@
/*
* Copyright (C) 2010-2014 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.␍ */
package com.jpexs.decompiler.graph.model;
import com.jpexs.decompiler.flash.helpers.GraphTextWriter;
import com.jpexs.decompiler.graph.GraphSourceItem;
import com.jpexs.decompiler.graph.GraphTargetItem;
import com.jpexs.decompiler.graph.TypeItem;
/**
*
* @author JPEXS
*/
public class TrueItem extends GraphTargetItem {
public TrueItem(GraphSourceItem src) {
super(src, PRECEDENCE_PRIMARY);
}
@Override
public GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) {
return writer.append("true");
}
@Override
public boolean hasReturnValue() {
return true;
}
@Override
public GraphTargetItem returnType() {
return TypeItem.BOOLEAN;
}
}
@@ -0,0 +1,29 @@
/*
* Copyright (C) 2010-2014 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.␍ */
package com.jpexs.decompiler.graph.model;
import com.jpexs.decompiler.graph.GraphTargetItem;
/**
*
* @author JPEXS
*/
public interface UnaryOp {
public GraphTargetItem getValue();
public int getPrecedence();
}
@@ -0,0 +1,93 @@
/*
* Copyright (C) 2010-2014 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.␍ */
package com.jpexs.decompiler.graph.model;
import com.jpexs.decompiler.flash.helpers.GraphTextWriter;
import com.jpexs.decompiler.graph.GraphSourceItem;
import com.jpexs.decompiler.graph.GraphSourceItemPos;
import com.jpexs.decompiler.graph.GraphTargetItem;
import java.util.List;
import java.util.Set;
public abstract class UnaryOpItem extends GraphTargetItem implements UnaryOp {
public GraphTargetItem value;
public String operator;
public UnaryOpItem(GraphSourceItem instruction, int precedence, GraphTargetItem value, String operator) {
super(instruction, precedence);
this.value = value;
this.operator = operator;
}
@Override
public GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) throws InterruptedException {
writer.append(operator);
if (value != null) {
if (value.getPrecedence() > precedence) {
writer.append("(");
value.toString(writer, localData);
writer.append(")");
} else {
value.toString(writer, localData);
}
} else {
writer.append("null");
}
return writer;
}
@Override
public boolean isCompileTime(Set<GraphTargetItem> dependencies) {
if (dependencies.contains(value)) {
return false;
}
dependencies.add(value);
return value.isCompileTime(dependencies);
}
@Override
public boolean isVariableComputed() {
return value.isVariableComputed();
}
@Override
public List<GraphSourceItemPos> getNeededSources() {
List<GraphSourceItemPos> ret = super.getNeededSources();
ret.addAll(value.getNeededSources());
return ret;
}
@Override
public boolean hasSideEffect() {
return value.hasSideEffect();
}
@Override
public int getPrecedence() {
return precedence;
}
@Override
public GraphTargetItem getValue() {
return value;
}
@Override
public boolean hasReturnValue() {
return true;
}
}
@@ -0,0 +1,52 @@
/*
* Copyright (C) 2014 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.␍ */
package com.jpexs.decompiler.graph.model;
import com.jpexs.decompiler.flash.abc.avm2.model.AVM2Item;
import com.jpexs.decompiler.flash.helpers.GraphTextWriter;
import com.jpexs.decompiler.graph.GraphTargetItem;
/**
*
* @author JPEXS
*/
public class UnboundedTypeItem extends AVM2Item {
public UnboundedTypeItem() {
super(null, NOPRECEDENCE);
}
@Override
public GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) throws InterruptedException {
writer.append("*");
return writer;
}
@Override
public GraphTargetItem returnType() {
return this;
}
@Override
public String toString() {
return "*";
}
@Override
public boolean hasReturnValue() {
return true;
}
}
@@ -0,0 +1,105 @@
/*
* Copyright (C) 2010-2014 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.␍ */
package com.jpexs.decompiler.graph.model;
import com.jpexs.decompiler.flash.helpers.GraphTextWriter;
import com.jpexs.decompiler.flash.helpers.LoopWithType;
import com.jpexs.decompiler.flash.helpers.NulWriter;
import com.jpexs.decompiler.graph.Block;
import com.jpexs.decompiler.graph.GraphSourceItem;
import com.jpexs.decompiler.graph.GraphTargetItem;
import com.jpexs.decompiler.graph.Loop;
import com.jpexs.decompiler.graph.TypeItem;
import java.util.ArrayList;
import java.util.List;
/**
*
* @author JPEXS
*/
public class UniversalLoopItem extends LoopItem implements Block {
public List<GraphTargetItem> commands;
private boolean labelUsed;
public UniversalLoopItem(GraphSourceItem src, Loop loop) {
super(src, loop);
}
@Override
public boolean needsSemicolon() {
return false;
}
@Override
public GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) throws InterruptedException {
if (writer instanceof NulWriter) {
((NulWriter) writer).startLoop(loop.id, LoopWithType.LOOP_TYPE_LOOP);
}
if (labelUsed) {
writer.append("loop" + loop.id + ":").newLine();
}
writer.append("while");
if (writer.getFormatting().spaceBeforeParenthesesWhileParentheses) {
writer.append(" ");
}
writer.append("(true)").startBlock();
for (GraphTargetItem ti : commands) {
if (!ti.isEmpty()) {
ti.toStringSemicoloned(writer, localData).newLine();
}
}
writer.endBlock();
if (writer instanceof NulWriter) {
LoopWithType loopOjb = ((NulWriter) writer).endLoop(loop.id);
labelUsed = loopOjb.used;
}
return writer;
}
@Override
public List<ContinueItem> getContinues() {
List<ContinueItem> ret = new ArrayList<>();
for (GraphTargetItem ti : commands) {
if (ti instanceof ContinueItem) {
ret.add((ContinueItem) ti);
}
if (ti instanceof Block) {
ret.addAll(((Block) ti).getContinues());
}
}
return ret;
}
@Override
public List<List<GraphTargetItem>> getSubs() {
List<List<GraphTargetItem>> ret = new ArrayList<>();
if (commands != null) {
ret.add(commands);
}
return ret;
}
@Override
public boolean hasReturnValue() {
return false;
}
@Override
public GraphTargetItem returnType() {
return TypeItem.UNBOUNDED;
}
}
@@ -0,0 +1,123 @@
/*
* Copyright (C) 2010-2014 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.␍ */
package com.jpexs.decompiler.graph.model;
import com.jpexs.decompiler.flash.SourceGeneratorLocalData;
import com.jpexs.decompiler.flash.helpers.GraphTextWriter;
import com.jpexs.decompiler.flash.helpers.LoopWithType;
import com.jpexs.decompiler.flash.helpers.NulWriter;
import com.jpexs.decompiler.graph.Block;
import com.jpexs.decompiler.graph.CompilationException;
import com.jpexs.decompiler.graph.GraphSourceItem;
import com.jpexs.decompiler.graph.GraphTargetItem;
import com.jpexs.decompiler.graph.Loop;
import com.jpexs.decompiler.graph.SourceGenerator;
import com.jpexs.decompiler.graph.TypeItem;
import java.util.ArrayList;
import java.util.List;
public class WhileItem extends LoopItem implements Block {
public List<GraphTargetItem> expression;
public List<GraphTargetItem> commands;
private boolean labelUsed;
@Override
public List<List<GraphTargetItem>> getSubs() {
List<List<GraphTargetItem>> ret = new ArrayList<>();
if (commands != null) {
ret.add(commands);
}
return ret;
}
public WhileItem(GraphSourceItem src, Loop loop, List<GraphTargetItem> expression, List<GraphTargetItem> commands) {
super(src, loop);
this.expression = expression;
this.commands = commands;
}
@Override
public GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) throws InterruptedException {
if (writer instanceof NulWriter) {
((NulWriter) writer).startLoop(loop.id, LoopWithType.LOOP_TYPE_LOOP);
}
if (labelUsed) {
writer.append("loop" + loop.id + ":").newLine();
}
writer.append("while");
if (writer.getFormatting().spaceBeforeParenthesesWhileParentheses) {
writer.append(" ");
}
writer.append("(");
for (int i = 0; i < expression.size(); i++) {
if (expression.get(i).isEmpty()) {
continue;
}
if (i != 0) {
writer.append(", ");
}
expression.get(i).toString(writer, localData);
}
writer.append(")");
writer.startBlock();
for (GraphTargetItem ti : commands) {
if (!ti.isEmpty()) {
ti.toStringSemicoloned(writer, localData).newLine();
}
}
writer.endBlock();
if (writer instanceof NulWriter) {
LoopWithType loopOjb = ((NulWriter) writer).endLoop(loop.id);
labelUsed = loopOjb.used;
}
return writer;
}
@Override
public List<ContinueItem> getContinues() {
List<ContinueItem> ret = new ArrayList<>();
for (GraphTargetItem ti : commands) {
if (ti instanceof ContinueItem) {
ret.add((ContinueItem) ti);
}
if (ti instanceof Block) {
ret.addAll(((Block) ti).getContinues());
}
}
return ret;
}
@Override
public boolean needsSemicolon() {
return false;
}
@Override
public List<GraphSourceItem> toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException {
return generator.generate(localData, this);
}
@Override
public boolean hasReturnValue() {
return false;
}
@Override
public GraphTargetItem returnType() {
return TypeItem.UNBOUNDED;
}
}