Issue #1134 compiling §§ instructions back while direct editation

(§§goto is still missing)
This commit is contained in:
Jindra Petřík
2016-01-16 19:51:11 +01:00
parent 7c1146618c
commit 95b4402390
14 changed files with 229 additions and 41 deletions
@@ -16,10 +16,15 @@
*/
package com.jpexs.decompiler.flash.action.model;
import com.jpexs.decompiler.flash.SourceGeneratorLocalData;
import com.jpexs.decompiler.flash.action.swf5.ActionEnumerate;
import com.jpexs.decompiler.flash.action.swf6.ActionEnumerate2;
import com.jpexs.decompiler.flash.helpers.GraphTextWriter;
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.model.LocalData;
import java.util.ArrayList;
import java.util.List;
@@ -58,8 +63,16 @@ public class EnumerateActionItem extends ActionItem {
return ret;
}
@Override
public List<GraphSourceItem> toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException {
if ((object instanceof DirectValueActionItem) && (((DirectValueActionItem) object).isString())) {
return toSourceMerge(localData, generator, value, new ActionEnumerate());
}
return toSourceMerge(localData, generator, value, new ActionEnumerate2());
}
@Override
public boolean hasReturnValue() {
return true;
return false;
}
}
@@ -28,6 +28,7 @@ import com.jpexs.decompiler.flash.action.model.CloneSpriteActionItem;
import com.jpexs.decompiler.flash.action.model.DefineLocalActionItem;
import com.jpexs.decompiler.flash.action.model.DeleteActionItem;
import com.jpexs.decompiler.flash.action.model.DirectValueActionItem;
import com.jpexs.decompiler.flash.action.model.EnumerateActionItem;
import com.jpexs.decompiler.flash.action.model.EvalActionItem;
import com.jpexs.decompiler.flash.action.model.FSCommandActionItem;
import com.jpexs.decompiler.flash.action.model.FunctionActionItem;
@@ -135,12 +136,15 @@ import com.jpexs.decompiler.graph.model.BreakItem;
import com.jpexs.decompiler.graph.model.CommaExpressionItem;
import com.jpexs.decompiler.graph.model.ContinueItem;
import com.jpexs.decompiler.graph.model.DoWhileItem;
import com.jpexs.decompiler.graph.model.DuplicateItem;
import com.jpexs.decompiler.graph.model.ForItem;
import com.jpexs.decompiler.graph.model.IfItem;
import com.jpexs.decompiler.graph.model.LocalData;
import com.jpexs.decompiler.graph.model.NotItem;
import com.jpexs.decompiler.graph.model.OrItem;
import com.jpexs.decompiler.graph.model.ParenthesisItem;
import com.jpexs.decompiler.graph.model.PopItem;
import com.jpexs.decompiler.graph.model.PushItem;
import com.jpexs.decompiler.graph.model.SwitchItem;
import com.jpexs.decompiler.graph.model.TernarOpItem;
import com.jpexs.decompiler.graph.model.WhileItem;
@@ -367,17 +371,15 @@ public class ActionScript2Parser {
String fname = s.value.toString();
if (fname.equals(classNameStr)) { //constructor
constr = (function(!isInterface, "", true, variables));
} else {
if (!isInterface) {
if (isStatic) {
FunctionActionItem ft = function(!isInterface, "", true, variables);
ft.calculatedFunctionName = pushConst(fname);
staticFunctions.add(ft);
} else {
FunctionActionItem ft = function(!isInterface, "", true, variables);
ft.calculatedFunctionName = pushConst(fname);
functions.add(ft);
}
} else if (!isInterface) {
if (isStatic) {
FunctionActionItem ft = function(!isInterface, "", true, variables);
ft.calculatedFunctionName = pushConst(fname);
staticFunctions.add(ft);
} else {
FunctionActionItem ft = function(!isInterface, "", true, variables);
ft.calculatedFunctionName = pushConst(fname);
functions.add(ft);
}
}
break;
@@ -1553,10 +1555,8 @@ public class ActionScript2Parser {
lexer.pushback(s);
if (cmd == null) {
expr.add(expression(inFunction, inMethod, true, variables));
} else {
if (!cmd.hasReturnValue()) {
throw new ActionParseException("Expression expected", lexer.yyline());
}
} else if (!cmd.hasReturnValue()) {
throw new ActionParseException("Expression expected", lexer.yyline());
}
return new CommaExpressionItem(null, null, expr);
}
@@ -1570,6 +1570,31 @@ public class ActionScript2Parser {
ParsedSymbol s = lex();
switch (s.type) {
case PREPROCESSOR:
expectedType(SymbolType.PARENT_OPEN);
switch ("" + s.value) {
//AS 1/2:
case "enumerate":
ret = new EnumerateActionItem(null, null, expression(inFunction, inMethod, allowRemainder, variables));
break;
//Both ASs
case "dup":
ret = new DuplicateItem(null, null, expression(inFunction, inMethod, allowRemainder, variables));
break;
case "push":
ret = new PushItem(expression(inFunction, inMethod, allowRemainder, variables));
break;
case "pop":
ret = new PopItem(null, null);
break;
case "goto": //TODO
throw new ActionParseException("Compiling §§" + s.value + " is not available, sorry", lexer.yyline());
default:
throw new ActionParseException("Unknown preprocessor instruction: §§" + s.value, lexer.yyline());
}
expectedType(SymbolType.PARENT_CLOSE);
break;
case NEGATE:
versionRequired(s, 5);
ret = expressionPrimary(false, inFunction, inMethod, false, variables);
@@ -1837,12 +1862,10 @@ public class ActionScript2Parser {
GraphTargetItem stored = v.getStoreValue();
if (v.isDefinition()) {
v.setBoxedValue(new DefineLocalActionItem(null, null, pushConst(varName), stored));
} else if (stored != null) {
v.setBoxedValue(new SetVariableActionItem(null, null, pushConst(varName), stored));
} else {
if (stored != null) {
v.setBoxedValue(new SetVariableActionItem(null, null, pushConst(varName), stored));
} else {
v.setBoxedValue(new GetVariableActionItem(null, null, pushConst(varName)));
}
v.setBoxedValue(new GetVariableActionItem(null, null, pushConst(varName)));
}
}
if (lexer.lex().type != SymbolType.EOF) {
@@ -61,6 +61,8 @@ import com.jpexs.decompiler.graph.model.ForItem;
import com.jpexs.decompiler.graph.model.IfItem;
import com.jpexs.decompiler.graph.model.NotItem;
import com.jpexs.decompiler.graph.model.OrItem;
import com.jpexs.decompiler.graph.model.PopItem;
import com.jpexs.decompiler.graph.model.PushItem;
import com.jpexs.decompiler.graph.model.SwitchItem;
import com.jpexs.decompiler.graph.model.TernarOpItem;
import com.jpexs.decompiler.graph.model.TrueItem;
@@ -803,4 +805,16 @@ public class ActionSourceGenerator implements SourceGenerator {
ret.add(new ActionPop());
return ret;
}
@Override
public List<GraphSourceItem> generate(SourceGeneratorLocalData localData, PushItem item) throws CompilationException {
return item.value.toSource(localData, this);
}
@Override
public List<GraphSourceItem> generate(SourceGeneratorLocalData localData, PopItem item) throws CompilationException {
List<GraphSourceItem> ret = new ArrayList<>();
return ret;
}
}