Fixed AS 1/2 use DefineLocal in function instead of registers when eval, set is used

This commit is contained in:
Jindra Petřík
2021-11-20 14:25:34 +01:00
parent f24ad2dde1
commit 0613b9009a
5 changed files with 151 additions and 136 deletions
@@ -63,6 +63,8 @@ public class FunctionActionItem extends ActionItem implements BranchStackResista
public GraphTargetItem calculatedFunctionName;
public boolean hasEval = false;
private int regStart;
private List<VariableActionItem> variables;
@@ -89,7 +91,7 @@ public class FunctionActionItem extends ActionItem implements BranchStackResista
super(null, null, PRECEDENCE_PRIMARY);
}
public FunctionActionItem(GraphSourceItem instruction, GraphSourceItem lineStartIns, String functionName, List<String> paramNames, Map<Integer, String> regNames, List<GraphTargetItem> actions, List<String> constants, int regStart, List<VariableActionItem> variables, List<FunctionActionItem> innerFunctions) {
public FunctionActionItem(GraphSourceItem instruction, GraphSourceItem lineStartIns, String functionName, List<String> paramNames, Map<Integer, String> regNames, List<GraphTargetItem> actions, List<String> constants, int regStart, List<VariableActionItem> variables, List<FunctionActionItem> innerFunctions, boolean hasEval) {
super(instruction, lineStartIns, PRECEDENCE_PRIMARY);
this.actions = actions;
this.constants = constants;
@@ -99,6 +101,7 @@ public class FunctionActionItem extends ActionItem implements BranchStackResista
this.regStart = regStart;
this.variables = variables;
this.innerFunctions = innerFunctions;
this.hasEval = hasEval;
}
@Override
@@ -344,7 +347,8 @@ public class FunctionActionItem extends ActionItem implements BranchStackResista
String varName = v.getVariableName();
GraphTargetItem stored = v.getStoreValue();
if (needsFun2) {
if (v.isDefinition() && !registerNames.contains(varName) && !deeplyUsedVariableNames.contains(varName)) {
if (v.isDefinition() && !registerNames.contains(varName) && !deeplyUsedVariableNames.contains(varName)
&& !hasEval) {
registerNames.add(varName);
}
}
@@ -162,6 +162,7 @@ import com.jpexs.decompiler.graph.model.SwitchItem;
import com.jpexs.decompiler.graph.model.TernarOpItem;
import com.jpexs.decompiler.graph.model.TrueItem;
import com.jpexs.decompiler.graph.model.WhileItem;
import com.jpexs.helpers.Reference;
import java.io.IOException;
import java.io.StringReader;
import java.util.ArrayList;
@@ -261,13 +262,13 @@ public class ActionScript2Parser {
return "" + uniqLast;
}
private List<GraphTargetItem> commands(boolean inFunction, boolean inMethod, int forinlevel, boolean inTellTarget, List<VariableActionItem> variables, List<FunctionActionItem> functions) throws IOException, ActionParseException {
private List<GraphTargetItem> commands(boolean inFunction, boolean inMethod, int forinlevel, boolean inTellTarget, List<VariableActionItem> variables, List<FunctionActionItem> functions, Reference<Boolean> hasEval) throws IOException, ActionParseException {
List<GraphTargetItem> ret = new ArrayList<>();
if (debugMode) {
System.out.println("commands:");
}
GraphTargetItem cmd;
while ((cmd = command(inFunction, inMethod, forinlevel, inTellTarget, true, variables, functions)) != null) {
while ((cmd = command(inFunction, inMethod, forinlevel, inTellTarget, true, variables, functions, hasEval)) != null) {
ret.add(cmd);
}
if (debugMode) {
@@ -341,7 +342,7 @@ public class ActionScript2Parser {
return ret;
}
private List<GraphTargetItem> call(boolean inFunction, boolean inMethod, boolean inTellTarget, List<VariableActionItem> variables, List<FunctionActionItem> functions) throws IOException, ActionParseException {
private List<GraphTargetItem> call(boolean inFunction, boolean inMethod, boolean inTellTarget, List<VariableActionItem> variables, List<FunctionActionItem> functions, Reference<Boolean> hasEval) throws IOException, ActionParseException {
List<GraphTargetItem> ret = new ArrayList<>();
//expected(SymbolType.PARENT_OPEN); //MUST BE HANDLED BY CALLER
ParsedSymbol s = lex();
@@ -349,14 +350,14 @@ public class ActionScript2Parser {
if (s.type != SymbolType.COMMA) {
lexer.pushback(s);
}
ret.add(expression(inFunction, inMethod, inTellTarget, true, variables, functions, false));
ret.add(expression(inFunction, inMethod, inTellTarget, true, variables, functions, false, hasEval));
s = lex();
expected(s, lexer.yyline(), SymbolType.COMMA, SymbolType.PARENT_CLOSE);
}
return ret;
}
private FunctionActionItem function(boolean withBody, String functionName, boolean isMethod, List<VariableActionItem> variables, List<FunctionActionItem> functions, boolean inTellTarget) throws IOException, ActionParseException {
private FunctionActionItem function(boolean withBody, String functionName, boolean isMethod, List<VariableActionItem> variables, List<FunctionActionItem> functions, boolean inTellTarget, Reference<Boolean> hasEval) throws IOException, ActionParseException {
GraphTargetItem ret = null;
ParsedSymbol s;
expectedType(SymbolType.PARENT_OPEN);
@@ -383,19 +384,23 @@ public class ActionScript2Parser {
List<GraphTargetItem> body = null;
List<VariableActionItem> subvariables = new ArrayList<>();
List<FunctionActionItem> subfunctions = new ArrayList<>();
Reference<Boolean> subHasEval = new Reference<>(false);
if (withBody) {
expectedType(SymbolType.CURLY_OPEN);
body = commands(true, isMethod, 0, inTellTarget, subvariables, subfunctions);
body = commands(true, isMethod, 0, inTellTarget, subvariables, subfunctions, subHasEval);
expectedType(SymbolType.CURLY_CLOSE);
}
FunctionActionItem retf = new FunctionActionItem(null, null, functionName, paramNames, new HashMap<>() /*?*/, body, constantPool, -1, subvariables, subfunctions);
if (subHasEval.getVal()) {
hasEval.setVal(true);
}
FunctionActionItem retf = new FunctionActionItem(null, null, functionName, paramNames, new HashMap<>() /*?*/, body, constantPool, -1, subvariables, subfunctions, subHasEval.getVal());
functions.add(retf);
return retf;
}
private GraphTargetItem traits(boolean isInterface, GraphTargetItem nameStr, GraphTargetItem extendsStr, List<GraphTargetItem> implementsStr, List<VariableActionItem> variables, List<FunctionActionItem> functions, boolean inTellTarget) throws IOException, ActionParseException {
private GraphTargetItem traits(boolean isInterface, GraphTargetItem nameStr, GraphTargetItem extendsStr, List<GraphTargetItem> implementsStr, List<VariableActionItem> variables, List<FunctionActionItem> functions, boolean inTellTarget, Reference<Boolean> hasEval) throws IOException, ActionParseException {
GraphTargetItem ret = null;
/*for (int i = 0; i < nameStr.size() - 1; i++) {
@@ -459,13 +464,13 @@ public class ActionScript2Parser {
}
if (!isInterface) {
if (isStatic) {
FunctionActionItem ft = function(!isInterface, "", true, variables, functions, inTellTarget);
FunctionActionItem ft = function(!isInterface, "", true, variables, functions, inTellTarget, hasEval);
ft.calculatedFunctionName = pushConst(fname);
//staticFunctions.add(ft);
traits.add(new MyEntry<>(ft.calculatedFunctionName, ft));
traitsStatic.add(true);
} else {
FunctionActionItem ft = function(!isInterface, "", true, variables, functions, inTellTarget);
FunctionActionItem ft = function(!isInterface, "", true, variables, functions, inTellTarget, hasEval);
ft.calculatedFunctionName = pushConst(fname);
//instanceFunctions.add(ft);
traits.add(new MyEntry<>(ft.calculatedFunctionName, ft));
@@ -483,7 +488,7 @@ public class ActionScript2Parser {
s = lex();
}
if (s.type == SymbolType.ASSIGN) {
traits.add(new MyEntry<>(pushConst(ident), expression(false, false, false, true, variables, functions, false)));
traits.add(new MyEntry<>(pushConst(ident), expression(false, false, false, true, variables, functions, false, hasEval)));
traitsStatic.add(isStatic);
s = lex();
}
@@ -505,7 +510,7 @@ public class ActionScript2Parser {
}
}
private GraphTargetItem expressionCommands(ParsedSymbol s, boolean inFunction, boolean inMethod, boolean inTellTarget, int forinlevel, List<VariableActionItem> variables, List<FunctionActionItem> functions) throws IOException, ActionParseException {
private GraphTargetItem expressionCommands(ParsedSymbol s, boolean inFunction, boolean inMethod, boolean inTellTarget, int forinlevel, List<VariableActionItem> variables, List<FunctionActionItem> functions, Reference<Boolean> hasEval) throws IOException, ActionParseException {
if (debugMode) {
System.out.println("expressionCommands:");
}
@@ -518,52 +523,52 @@ public class ActionScript2Parser {
break;
case MBORD:
expectedType(SymbolType.PARENT_OPEN);
ret = new MBCharToAsciiActionItem(null, null, expression(inFunction, inMethod, inTellTarget, true, variables, functions, false));
ret = new MBCharToAsciiActionItem(null, null, expression(inFunction, inMethod, inTellTarget, true, variables, functions, false, hasEval));
expectedType(SymbolType.PARENT_CLOSE);
break;
case MBCHR:
expectedType(SymbolType.PARENT_OPEN);
ret = new MBAsciiToCharActionItem(null, null, expression(inFunction, inMethod, inTellTarget, true, variables, functions, false));
ret = new MBAsciiToCharActionItem(null, null, expression(inFunction, inMethod, inTellTarget, true, variables, functions, false, hasEval));
expectedType(SymbolType.PARENT_CLOSE);
break;
case MBLENGTH:
expectedType(SymbolType.PARENT_OPEN);
ret = new MBStringLengthActionItem(null, null, expression(inFunction, inMethod, inTellTarget, true, variables, functions, false));
ret = new MBStringLengthActionItem(null, null, expression(inFunction, inMethod, inTellTarget, true, variables, functions, false, hasEval));
expectedType(SymbolType.PARENT_CLOSE);
break;
case MBSUBSTRING:
expectedType(SymbolType.PARENT_OPEN);
GraphTargetItem val1 = (expression(inFunction, inMethod, inTellTarget, true, variables, functions, false));
GraphTargetItem val1 = (expression(inFunction, inMethod, inTellTarget, true, variables, functions, false, hasEval));
expectedType(SymbolType.COMMA);
GraphTargetItem index1 = (expression(inFunction, inMethod, inTellTarget, true, variables, functions, false));
GraphTargetItem index1 = (expression(inFunction, inMethod, inTellTarget, true, variables, functions, false, hasEval));
expectedType(SymbolType.COMMA);
GraphTargetItem len1 = (expression(inFunction, inMethod, inTellTarget, true, variables, functions, false));
GraphTargetItem len1 = (expression(inFunction, inMethod, inTellTarget, true, variables, functions, false, hasEval));
expectedType(SymbolType.PARENT_CLOSE);
ret = new MBStringExtractActionItem(null, null, val1, index1, len1);
break;
case SUBSTR:
expectedType(SymbolType.PARENT_OPEN);
GraphTargetItem val2 = (expression(inFunction, inMethod, inTellTarget, true, variables, functions, false));
GraphTargetItem val2 = (expression(inFunction, inMethod, inTellTarget, true, variables, functions, false, hasEval));
expectedType(SymbolType.COMMA);
GraphTargetItem index2 = (expression(inFunction, inMethod, inTellTarget, true, variables, functions, false));
GraphTargetItem index2 = (expression(inFunction, inMethod, inTellTarget, true, variables, functions, false, hasEval));
expectedType(SymbolType.COMMA);
GraphTargetItem len2 = (expression(inFunction, inMethod, inTellTarget, true, variables, functions, false));
GraphTargetItem len2 = (expression(inFunction, inMethod, inTellTarget, true, variables, functions, false, hasEval));
expectedType(SymbolType.PARENT_CLOSE);
ret = new StringExtractActionItem(null, null, val2, index2, len2);
break;
case LENGTH:
expectedType(SymbolType.PARENT_OPEN);
ret = new StringLengthActionItem(null, null, expression(inFunction, inMethod, inTellTarget, true, variables, functions, false));
ret = new StringLengthActionItem(null, null, expression(inFunction, inMethod, inTellTarget, true, variables, functions, false, hasEval));
expectedType(SymbolType.PARENT_CLOSE);
break;
case RANDOM:
expectedType(SymbolType.PARENT_OPEN);
ret = new RandomNumberActionItem(null, null, expression(inFunction, inMethod, inTellTarget, true, variables, functions, false));
ret = new RandomNumberActionItem(null, null, expression(inFunction, inMethod, inTellTarget, true, variables, functions, false, hasEval));
expectedType(SymbolType.PARENT_CLOSE);
break;
case INT:
expectedType(SymbolType.PARENT_OPEN);
ret = new ToIntegerActionItem(null, null, expression(inFunction, inMethod, inTellTarget, true, variables, functions, false));
ret = new ToIntegerActionItem(null, null, expression(inFunction, inMethod, inTellTarget, true, variables, functions, false, hasEval));
expectedType(SymbolType.PARENT_CLOSE);
break;
case NUMBER_OP:
@@ -576,7 +581,7 @@ public class ActionScript2Parser {
ret = vi; //memberOrCall(vi, inFunction, inMethod, variables, functions);
} else {
expected(s, lexer.yyline(), SymbolType.PARENT_OPEN);
ret = new ToNumberActionItem(null, null, expression(inFunction, inMethod, inTellTarget, true, variables, functions, false));
ret = new ToNumberActionItem(null, null, expression(inFunction, inMethod, inTellTarget, true, variables, functions, false, hasEval));
expectedType(SymbolType.PARENT_CLOSE);
}
break;
@@ -590,28 +595,28 @@ public class ActionScript2Parser {
ret = vi2; //memberOrCall(vi2, inFunction, inMethod, variables, functions);
} else {
expected(s, lexer.yyline(), SymbolType.PARENT_OPEN);
ret = new ToStringActionItem(null, null, expression(inFunction, inMethod, inTellTarget, true, variables, functions, false));
ret = new ToStringActionItem(null, null, expression(inFunction, inMethod, inTellTarget, true, variables, functions, false, hasEval));
expectedType(SymbolType.PARENT_CLOSE);
//ret = memberOrCall(ret, inFunction, inMethod, variables, functions);
}
break;
case ORD:
expectedType(SymbolType.PARENT_OPEN);
ret = new CharToAsciiActionItem(null, null, expression(inFunction, inMethod, inTellTarget, true, variables, functions, false));
ret = new CharToAsciiActionItem(null, null, expression(inFunction, inMethod, inTellTarget, true, variables, functions, false, hasEval));
expectedType(SymbolType.PARENT_CLOSE);
break;
case CHR:
expectedType(SymbolType.PARENT_OPEN);
ret = new AsciiToCharActionItem(null, null, expression(inFunction, inMethod, inTellTarget, true, variables, functions, false));
ret = new AsciiToCharActionItem(null, null, expression(inFunction, inMethod, inTellTarget, true, variables, functions, false, hasEval));
expectedType(SymbolType.PARENT_CLOSE);
break;
case DUPLICATEMOVIECLIP:
expectedType(SymbolType.PARENT_OPEN);
GraphTargetItem src3 = (expression(inFunction, inMethod, inTellTarget, true, variables, functions, false));
GraphTargetItem src3 = (expression(inFunction, inMethod, inTellTarget, true, variables, functions, false, hasEval));
expectedType(SymbolType.COMMA);
GraphTargetItem tar3 = (expression(inFunction, inMethod, inTellTarget, true, variables, functions, false));
GraphTargetItem tar3 = (expression(inFunction, inMethod, inTellTarget, true, variables, functions, false, hasEval));
expectedType(SymbolType.COMMA);
GraphTargetItem dep3 = (expression(inFunction, inMethod, inTellTarget, true, variables, functions, false));
GraphTargetItem dep3 = (expression(inFunction, inMethod, inTellTarget, true, variables, functions, false, hasEval));
expectedType(SymbolType.PARENT_CLOSE);
ret = new CloneSpriteActionItem(null, null, src3, tar3, dep3);
break;
@@ -622,7 +627,7 @@ public class ActionScript2Parser {
break;
case TARGETPATH:
expectedType(SymbolType.PARENT_OPEN);
ret = new TargetPathActionItem(null, null, (expression(inFunction, inMethod, inTellTarget, true, variables, functions, false)));
ret = new TargetPathActionItem(null, null, (expression(inFunction, inMethod, inTellTarget, true, variables, functions, false, hasEval)));
expectedType(SymbolType.PARENT_CLOSE);
break;
default:
@@ -634,7 +639,7 @@ public class ActionScript2Parser {
return ret;
}
private GraphTargetItem command(boolean inFunction, boolean inMethod, int forinlevel, boolean inTellTarget, boolean mustBeCommand, List<VariableActionItem> variables, List<FunctionActionItem> functions) throws IOException, ActionParseException {
private GraphTargetItem command(boolean inFunction, boolean inMethod, int forinlevel, boolean inTellTarget, boolean mustBeCommand, List<VariableActionItem> variables, List<FunctionActionItem> functions, Reference<Boolean> hasEval) throws IOException, ActionParseException {
LexBufferer buf = new LexBufferer();
lexer.addListener(buf);
GraphTargetItem ret = null;
@@ -648,43 +653,44 @@ public class ActionScript2Parser {
switch (s.type) {
case FSCOMMAND:
expectedType(SymbolType.PARENT_OPEN);
ret = new FSCommandActionItem(null, null, expression(inFunction, inMethod, inTellTarget, true, variables, functions, false));
ret = new FSCommandActionItem(null, null, expression(inFunction, inMethod, inTellTarget, true, variables, functions, false, hasEval));
expectedType(SymbolType.PARENT_CLOSE);
break;
case CALL:
expectedType(SymbolType.PARENT_OPEN);
ret = new CallActionItem(null, null, (expression(inFunction, inMethod, inTellTarget, true, variables, functions, false)));
ret = new CallActionItem(null, null, (expression(inFunction, inMethod, inTellTarget, true, variables, functions, false, hasEval)));
expectedType(SymbolType.PARENT_CLOSE);
break;
case LENGTH:
expectedType(SymbolType.PARENT_OPEN);
ret = new StringLengthActionItem(null, null, (expression(inFunction, inMethod, inTellTarget, true, variables, functions, false)));
ret = new StringLengthActionItem(null, null, (expression(inFunction, inMethod, inTellTarget, true, variables, functions, false, hasEval)));
expectedType(SymbolType.PARENT_CLOSE);
break;
case MBLENGTH:
expectedType(SymbolType.PARENT_OPEN);
ret = new MBStringLengthActionItem(null, null, (expression(inFunction, inMethod, inTellTarget, true, variables, functions, false)));
ret = new MBStringLengthActionItem(null, null, (expression(inFunction, inMethod, inTellTarget, true, variables, functions, false, hasEval)));
expectedType(SymbolType.PARENT_CLOSE);
break;
case SET:
expectedType(SymbolType.PARENT_OPEN);
GraphTargetItem name1 = (expression(inFunction, inMethod, inTellTarget, true, variables, functions, false));
GraphTargetItem name1 = (expression(inFunction, inMethod, inTellTarget, true, variables, functions, false, hasEval));
expectedType(SymbolType.COMMA);
GraphTargetItem value1 = (expression(inFunction, inMethod, inTellTarget, true, variables, functions, false));
GraphTargetItem value1 = (expression(inFunction, inMethod, inTellTarget, true, variables, functions, false, hasEval));
expectedType(SymbolType.PARENT_CLOSE);
ret = new SetVariableActionItem(null, null, name1, value1);
hasEval.setVal(true); //FlashPro does this (using definelocal for funcs) only for eval func, but we will also use set since it is generated by obfuscated identifiers
break;
case WITH:
expectedType(SymbolType.PARENT_OPEN);
GraphTargetItem wvar = expression(inFunction, inMethod, inTellTarget, false, variables, functions, false);//(variable(inFunction, inMethod, variables, functions));
GraphTargetItem wvar = expression(inFunction, inMethod, inTellTarget, false, variables, functions, false, hasEval);//(variable(inFunction, inMethod, variables, functions));
expectedType(SymbolType.PARENT_CLOSE);
expectedType(SymbolType.CURLY_OPEN);
List<GraphTargetItem> wcmd = commands(inFunction, inMethod, forinlevel, inTellTarget, variables, functions);
List<GraphTargetItem> wcmd = commands(inFunction, inMethod, forinlevel, inTellTarget, variables, functions, hasEval);
expectedType(SymbolType.CURLY_CLOSE);
ret = new WithActionItem(null, null, wvar, wcmd);
break;
case DELETE:
GraphTargetItem varDel = expression(inFunction, inMethod, inTellTarget, false, variables, functions, false);//variable(inFunction, inMethod, variables, functions);
GraphTargetItem varDel = expression(inFunction, inMethod, inTellTarget, false, variables, functions, false, hasEval);//variable(inFunction, inMethod, variables, functions);
if (varDel instanceof GetMemberActionItem) {
GetMemberActionItem gm = (GetMemberActionItem) varDel;
ret = new DeleteActionItem(null, null, gm.object, gm.memberName);
@@ -699,19 +705,19 @@ public class ActionScript2Parser {
break;
case TRACE:
expectedType(SymbolType.PARENT_OPEN);
ret = new TraceActionItem(null, null, (expression(inFunction, inMethod, inTellTarget, true, variables, functions, false)));
ret = new TraceActionItem(null, null, (expression(inFunction, inMethod, inTellTarget, true, variables, functions, false, hasEval)));
expectedType(SymbolType.PARENT_CLOSE);
break;
case GETURL:
expectedType(SymbolType.PARENT_OPEN);
GraphTargetItem url = (expression(inFunction, inMethod, inTellTarget, true, variables, functions, false));
GraphTargetItem url = (expression(inFunction, inMethod, inTellTarget, true, variables, functions, false, hasEval));
s = lex();
expected(s, lexer.yyline(), SymbolType.PARENT_CLOSE, SymbolType.COMMA);
int getuMethod = 0;
GraphTargetItem target;
if (s.type == SymbolType.COMMA) {
target = (expression(inFunction, inMethod, inTellTarget, true, variables, functions, false));
target = (expression(inFunction, inMethod, inTellTarget, true, variables, functions, false, hasEval));
s = lex();
if (s.type == SymbolType.COMMA) {
s = lex();
@@ -735,11 +741,11 @@ public class ActionScript2Parser {
break;
case GOTOANDSTOP:
expectedType(SymbolType.PARENT_OPEN);
GraphTargetItem gtsFrame = expression(inFunction, inMethod, inTellTarget, true, variables, functions, false);
GraphTargetItem gtsFrame = expression(inFunction, inMethod, inTellTarget, true, variables, functions, false, hasEval);
s = lex();
if (s.type == SymbolType.COMMA) { //Handle scene?
lex();
gtsFrame = expression(inFunction, inMethod, inTellTarget, true, variables, functions, false);
gtsFrame = expression(inFunction, inMethod, inTellTarget, true, variables, functions, false, hasEval);
} else {
lexer.pushback(s);
}
@@ -763,10 +769,10 @@ public class ActionScript2Parser {
break;
case TELLTARGET:
expectedType(SymbolType.PARENT_OPEN);
GraphTargetItem tellTarget = expression(inFunction, inMethod, inTellTarget, true, variables, functions, false);
GraphTargetItem tellTarget = expression(inFunction, inMethod, inTellTarget, true, variables, functions, false, hasEval);
expectedType(SymbolType.PARENT_CLOSE);
expectedType(SymbolType.CURLY_OPEN);
List<GraphTargetItem> tellcmds = commands(inFunction, inMethod, forinlevel, true, variables, functions);
List<GraphTargetItem> tellcmds = commands(inFunction, inMethod, forinlevel, true, variables, functions, hasEval);
expectedType(SymbolType.CURLY_CLOSE);
TellTargetActionItem tt = new TellTargetActionItem(null, null, tellTarget, tellcmds);
if (inTellTarget) {
@@ -800,7 +806,7 @@ public class ActionScript2Parser {
case UNLOADMOVIENUM:
SymbolType unloadType = s.type;
expectedType(SymbolType.PARENT_OPEN);
GraphTargetItem unTargetOrNum = expression(inFunction, inMethod, inTellTarget, true, variables, functions, false);
GraphTargetItem unTargetOrNum = expression(inFunction, inMethod, inTellTarget, true, variables, functions, false, hasEval);
expectedType(SymbolType.PARENT_CLOSE);
if (unloadType == SymbolType.UNLOADMOVIE) {
ret = new UnLoadMovieActionItem(null, null, unTargetOrNum);
@@ -815,9 +821,9 @@ public class ActionScript2Parser {
case PRINTNUM:
SymbolType printType = s.type;
expectedType(SymbolType.PARENT_OPEN);
GraphTargetItem printTarget = (expression(inFunction, inMethod, inTellTarget, true, variables, functions, false));
GraphTargetItem printTarget = (expression(inFunction, inMethod, inTellTarget, true, variables, functions, false, hasEval));
expectedType(SymbolType.COMMA);
GraphTargetItem printBBox = (expression(inFunction, inMethod, inTellTarget, true, variables, functions, false));
GraphTargetItem printBBox = (expression(inFunction, inMethod, inTellTarget, true, variables, functions, false, hasEval));
expectedType(SymbolType.PARENT_CLOSE);
switch (printType) {
@@ -841,9 +847,9 @@ public class ActionScript2Parser {
case LOADMOVIENUM:
SymbolType loadType = s.type;
expectedType(SymbolType.PARENT_OPEN);
GraphTargetItem url2 = (expression(inFunction, inMethod, inTellTarget, true, variables, functions, false));
GraphTargetItem url2 = (expression(inFunction, inMethod, inTellTarget, true, variables, functions, false, hasEval));
expectedType(SymbolType.COMMA);
GraphTargetItem targetOrNum = (expression(inFunction, inMethod, inTellTarget, true, variables, functions, false));
GraphTargetItem targetOrNum = (expression(inFunction, inMethod, inTellTarget, true, variables, functions, false, hasEval));
s = lex();
expected(s, lexer.yyline(), SymbolType.PARENT_CLOSE, SymbolType.COMMA);
@@ -879,11 +885,11 @@ public class ActionScript2Parser {
break;
case GOTOANDPLAY:
expectedType(SymbolType.PARENT_OPEN);
GraphTargetItem gtpFrame = expression(inFunction, inMethod, inTellTarget, true, variables, functions, false);
GraphTargetItem gtpFrame = expression(inFunction, inMethod, inTellTarget, true, variables, functions, false, hasEval);
s = lex();
if (s.type == SymbolType.COMMA) { //Handle scene?
lex();
gtpFrame = expression(inFunction, inMethod, inTellTarget, true, variables, functions, false);
gtpFrame = expression(inFunction, inMethod, inTellTarget, true, variables, functions, false, hasEval);
} else {
lexer.pushback(s);
}
@@ -893,12 +899,12 @@ public class ActionScript2Parser {
case REMOVEMOVIECLIP:
expectedType(SymbolType.PARENT_OPEN);
ret = new RemoveSpriteActionItem(null, null, (expression(inFunction, inMethod, inTellTarget, true, variables, functions, false)));
ret = new RemoveSpriteActionItem(null, null, (expression(inFunction, inMethod, inTellTarget, true, variables, functions, false, hasEval)));
expectedType(SymbolType.PARENT_CLOSE);
break;
case STARTDRAG:
expectedType(SymbolType.PARENT_OPEN);
GraphTargetItem dragTarget = (expression(inFunction, inMethod, inTellTarget, true, variables, functions, false));
GraphTargetItem dragTarget = (expression(inFunction, inMethod, inTellTarget, true, variables, functions, false, hasEval));
GraphTargetItem lockCenter;
GraphTargetItem constrain;
GraphTargetItem x1 = null;
@@ -907,20 +913,20 @@ public class ActionScript2Parser {
GraphTargetItem y2 = null;
s = lex();
if (s.type == SymbolType.COMMA) {
lockCenter = (expression(inFunction, inMethod, inTellTarget, true, variables, functions, false));
lockCenter = (expression(inFunction, inMethod, inTellTarget, true, variables, functions, false, hasEval));
s = lex();
if (s.type == SymbolType.COMMA) {
constrain = new DirectValueActionItem(null, null, 0, 1L, new ArrayList<>());
x1 = (expression(inFunction, inMethod, inTellTarget, true, variables, functions, false));
x1 = (expression(inFunction, inMethod, inTellTarget, true, variables, functions, false, hasEval));
s = lex();
if (s.type == SymbolType.COMMA) {
y1 = (expression(inFunction, inMethod, inTellTarget, true, variables, functions, false));
y1 = (expression(inFunction, inMethod, inTellTarget, true, variables, functions, false, hasEval));
s = lex();
if (s.type == SymbolType.COMMA) {
x2 = (expression(inFunction, inMethod, inTellTarget, true, variables, functions, false));
x2 = (expression(inFunction, inMethod, inTellTarget, true, variables, functions, false, hasEval));
s = lex();
if (s.type == SymbolType.COMMA) {
y2 = (expression(inFunction, inMethod, inTellTarget, true, variables, functions, false));
y2 = (expression(inFunction, inMethod, inTellTarget, true, variables, functions, false, hasEval));
} else {
lexer.pushback(s);
y2 = new DirectValueActionItem(null, null, 0, 0L, new ArrayList<>());
@@ -953,10 +959,10 @@ public class ActionScript2Parser {
case IFFRAMELOADED:
expectedType(SymbolType.PARENT_OPEN);
GraphTargetItem iflExpr = (expression(inFunction, inMethod, inTellTarget, true, variables, functions, false));
GraphTargetItem iflExpr = (expression(inFunction, inMethod, inTellTarget, true, variables, functions, false, hasEval));
expectedType(SymbolType.PARENT_CLOSE);
expectedType(SymbolType.CURLY_OPEN);
List<GraphTargetItem> iflComs = commands(inFunction, inMethod, forinlevel, inTellTarget, variables, functions);
List<GraphTargetItem> iflComs = commands(inFunction, inMethod, forinlevel, inTellTarget, variables, functions, hasEval);
expectedType(SymbolType.CURLY_CLOSE);
ret = new IfFrameLoadedActionItem(iflExpr, iflComs, null, null);
break;
@@ -977,7 +983,7 @@ public class ActionScript2Parser {
} while (s.type == SymbolType.COMMA);
}
expected(s, lexer.yyline(), SymbolType.CURLY_OPEN);
ret = (traits(false, classTypeStr, extendsTypeStr, implementsTypeStrs, variables, functions, inTellTarget));
ret = (traits(false, classTypeStr, extendsTypeStr, implementsTypeStrs, variables, functions, inTellTarget, hasEval));
expectedType(SymbolType.CURLY_CLOSE);
break;
case INTERFACE:
@@ -993,13 +999,13 @@ public class ActionScript2Parser {
} while (s.type == SymbolType.COMMA);
}
expected(s, lexer.yyline(), SymbolType.CURLY_OPEN);
ret = (traits(true, interfaceTypeStr, null, intExtendsTypeStrs, variables, functions, inTellTarget));
ret = (traits(true, interfaceTypeStr, null, intExtendsTypeStrs, variables, functions, inTellTarget, hasEval));
expectedType(SymbolType.CURLY_CLOSE);
break;
case FUNCTION:
s = lexer.lex();
expected(s, lexer.yyline(), SymbolType.IDENTIFIER, SymbolGroup.GLOBALFUNC);
ret = (function(true, s.value.toString(), false, variables, functions, inTellTarget));
ret = (function(true, s.value.toString(), false, variables, functions, inTellTarget, hasEval));
break;
case VAR:
s = lex();
@@ -1016,7 +1022,7 @@ public class ActionScript2Parser {
}
if (s.type == SymbolType.ASSIGN) {
GraphTargetItem varval = (expression(inFunction, inMethod, inTellTarget, true, variables, functions, false));
GraphTargetItem varval = (expression(inFunction, inMethod, inTellTarget, true, variables, functions, false, hasEval));
ret = new VariableActionItem(varIdentifier, varval, true);
variables.add((VariableActionItem) ret);
} else {
@@ -1026,12 +1032,12 @@ public class ActionScript2Parser {
}
break;
case CURLY_OPEN:
ret = new BlockItem(null, null, commands(inFunction, inMethod, forinlevel, inTellTarget, variables, functions));
ret = new BlockItem(null, null, commands(inFunction, inMethod, forinlevel, inTellTarget, variables, functions, hasEval));
expectedType(SymbolType.CURLY_CLOSE);
break;
case INCREMENT: //preincrement
case DECREMENT: //predecrement
GraphTargetItem varincdec = expression(inFunction, inMethod, inTellTarget, false, variables, functions, false);
GraphTargetItem varincdec = expression(inFunction, inMethod, inTellTarget, false, variables, functions, false, hasEval);
if (s.type == SymbolType.INCREMENT) {
ret = new PreIncrementActionItem(null, null, varincdec);
} else if (s.type == SymbolType.DECREMENT) {
@@ -1041,7 +1047,7 @@ public class ActionScript2Parser {
case SUPER: //constructor call
ParsedSymbol ss2 = lex();
if (ss2.type == SymbolType.PARENT_OPEN) {
List<GraphTargetItem> args = call(inFunction, inMethod, inTellTarget, variables, functions);
List<GraphTargetItem> args = call(inFunction, inMethod, inTellTarget, variables, functions, hasEval);
VariableActionItem supItem = new VariableActionItem(s.value.toString(), null, false);
variables.add(supItem);
ret = new CallMethodActionItem(null, null, supItem, new DirectValueActionItem(null, null, 0, Undefined.INSTANCE, constantPool), args);
@@ -1052,16 +1058,16 @@ public class ActionScript2Parser {
break;
case IF:
expectedType(SymbolType.PARENT_OPEN);
GraphTargetItem ifExpr = (expression(inFunction, inMethod, inTellTarget, true, variables, functions, false));
GraphTargetItem ifExpr = (expression(inFunction, inMethod, inTellTarget, true, variables, functions, false, hasEval));
expectedType(SymbolType.PARENT_CLOSE);
GraphTargetItem onTrue = command(inFunction, inMethod, forinlevel, inTellTarget, true, variables, functions);
GraphTargetItem onTrue = command(inFunction, inMethod, forinlevel, inTellTarget, true, variables, functions, hasEval);
List<GraphTargetItem> onTrueList = new ArrayList<>();
onTrueList.add(onTrue);
s = lex();
List<GraphTargetItem> onFalseList = null;
if (s.type == SymbolType.ELSE) {
onFalseList = new ArrayList<>();
onFalseList.add(command(inFunction, inMethod, forinlevel, inTellTarget, true, variables, functions));
onFalseList.add(command(inFunction, inMethod, forinlevel, inTellTarget, true, variables, functions, hasEval));
} else {
lexer.pushback(s);
}
@@ -1070,19 +1076,19 @@ public class ActionScript2Parser {
case WHILE:
expectedType(SymbolType.PARENT_OPEN);
List<GraphTargetItem> whileExpr = new ArrayList<>();
whileExpr.add(expression(inFunction, inMethod, inTellTarget, true, variables, functions, true));
whileExpr.add(expression(inFunction, inMethod, inTellTarget, true, variables, functions, true, hasEval));
expectedType(SymbolType.PARENT_CLOSE);
List<GraphTargetItem> whileBody = new ArrayList<>();
whileBody.add(command(inFunction, inMethod, forinlevel, inTellTarget, true, variables, functions));
whileBody.add(command(inFunction, inMethod, forinlevel, inTellTarget, true, variables, functions, hasEval));
ret = new WhileItem(null, null, null, whileExpr, whileBody);
break;
case DO:
List<GraphTargetItem> doBody = new ArrayList<>();
doBody.add(command(inFunction, inMethod, forinlevel, inTellTarget, true, variables, functions));
doBody.add(command(inFunction, inMethod, forinlevel, inTellTarget, true, variables, functions, hasEval));
expectedType(SymbolType.WHILE);
expectedType(SymbolType.PARENT_OPEN);
List<GraphTargetItem> doExpr = new ArrayList<>();
doExpr.add(expression(inFunction, inMethod, inTellTarget, true, variables, functions, true));
doExpr.add(expression(inFunction, inMethod, inTellTarget, true, variables, functions, true, hasEval));
expectedType(SymbolType.PARENT_CLOSE);
ret = new DoWhileItem(null, null, null, doBody, doExpr);
break;
@@ -1143,7 +1149,7 @@ public class ActionScript2Parser {
variables.add(item);
collection = expression(inFunction, inMethod, inTellTarget, true, variables, functions, false);
collection = expression(inFunction, inMethod, inTellTarget, true, variables, functions, false, hasEval);
forin = true;
} else {
lexer.pushback(s3);
@@ -1165,23 +1171,23 @@ public class ActionScript2Parser {
GraphTargetItem forExpr = null;
List<GraphTargetItem> forFirstCommands = new ArrayList<>();
if (!forin) {
GraphTargetItem fc = command(inFunction, inMethod, forinlevel, inTellTarget, true, variables, functions);
GraphTargetItem fc = command(inFunction, inMethod, forinlevel, inTellTarget, true, variables, functions, hasEval);
if (fc != null) { //can be empty command
forFirstCommands.add(fc);
}
forExpr = expression(inFunction, inMethod, inTellTarget, true, variables, functions, false);
forExpr = expression(inFunction, inMethod, inTellTarget, true, variables, functions, false, hasEval);
if (forExpr == null) {
forExpr = new TrueItem(null, null);
}
expectedType(SymbolType.SEMICOLON);
GraphTargetItem fcom = command(inFunction, inMethod, forinlevel, inTellTarget, true, variables, functions);
GraphTargetItem fcom = command(inFunction, inMethod, forinlevel, inTellTarget, true, variables, functions, hasEval);
if (fcom != null) {
forFinalCommands.add(fcom);
}
}
expectedType(SymbolType.PARENT_CLOSE);
List<GraphTargetItem> forBody = new ArrayList<>();
forBody.add(command(inFunction, inMethod, forin ? forinlevel + 1 : forinlevel, inTellTarget, true, variables, functions));
forBody.add(command(inFunction, inMethod, forin ? forinlevel + 1 : forinlevel, inTellTarget, true, variables, functions, hasEval));
if (forin) {
ret = new ForInActionItem(null, null, null, item, collection, forBody);
} else {
@@ -1190,7 +1196,7 @@ public class ActionScript2Parser {
break;
case SWITCH:
expectedType(SymbolType.PARENT_OPEN);
GraphTargetItem switchExpr = expression(inFunction, inMethod, inTellTarget, true, variables, functions, false);
GraphTargetItem switchExpr = expression(inFunction, inMethod, inTellTarget, true, variables, functions, false, hasEval);
expectedType(SymbolType.PARENT_CLOSE);
expectedType(SymbolType.CURLY_OPEN);
s = lex();
@@ -1211,7 +1217,7 @@ public class ActionScript2Parser {
while (s.type == SymbolType.CASE || s.type == SymbolType.DEFAULT) {
//List<GraphTargetItem> caseExprs; = new ArrayList<>();
while (s.type == SymbolType.CASE || s.type == SymbolType.DEFAULT) {
GraphTargetItem curCaseExpr = s.type == SymbolType.DEFAULT ? new DefaultItem() : expression(inFunction, inMethod, inTellTarget, true, variables, functions, false);
GraphTargetItem curCaseExpr = s.type == SymbolType.DEFAULT ? new DefaultItem() : expression(inFunction, inMethod, inTellTarget, true, variables, functions, false, hasEval);
//caseExprs.add(curCaseExpr);
expectedType(SymbolType.COLON);
s = lex();
@@ -1220,7 +1226,7 @@ public class ActionScript2Parser {
}
pos++;
lexer.pushback(s);
List<GraphTargetItem> caseCmd = commands(inFunction, inMethod, forinlevel, inTellTarget, variables, functions);
List<GraphTargetItem> caseCmd = commands(inFunction, inMethod, forinlevel, inTellTarget, variables, functions, hasEval);
caseCmds.add(caseCmd);
s = lex();
}
@@ -1234,7 +1240,7 @@ public class ActionScript2Parser {
ret = new ContinueItem(null, null, 0); //? There is no more than 1 level continue/break in AS1/2
break;
case RETURN:
GraphTargetItem retexpr = expression(inFunction, inMethod, inTellTarget, true, variables, functions, false);
GraphTargetItem retexpr = expression(inFunction, inMethod, inTellTarget, true, variables, functions, false, hasEval);
if (retexpr == null) {
retexpr = new DirectValueActionItem(null, null, 0, Undefined.INSTANCE, new ArrayList<>());
}
@@ -1242,7 +1248,7 @@ public class ActionScript2Parser {
break;
case TRY:
List<GraphTargetItem> tryCommands = new ArrayList<>();
tryCommands.add(command(inFunction, inMethod, forinlevel, inTellTarget, true, variables, functions));
tryCommands.add(command(inFunction, inMethod, forinlevel, inTellTarget, true, variables, functions, hasEval));
s = lex();
boolean found = false;
List<List<GraphTargetItem>> catchCommands = null;
@@ -1266,7 +1272,7 @@ public class ActionScript2Parser {
catchCommands = new ArrayList<>();
}
List<GraphTargetItem> cc = new ArrayList<>();
cc.add(command(inFunction, inMethod, forinlevel, inTellTarget, true, variables, functions));
cc.add(command(inFunction, inMethod, forinlevel, inTellTarget, true, variables, functions, hasEval));
catchCommands.add(cc);
s = lex();
found = true;
@@ -1274,7 +1280,7 @@ public class ActionScript2Parser {
List<GraphTargetItem> finallyCommands = null;
if (s.type == SymbolType.FINALLY) {
finallyCommands = new ArrayList<>();
finallyCommands.add(command(inFunction, inMethod, forinlevel, inTellTarget, true, variables, functions));
finallyCommands.add(command(inFunction, inMethod, forinlevel, inTellTarget, true, variables, functions, hasEval));
found = true;
s = lex();
}
@@ -1285,7 +1291,7 @@ public class ActionScript2Parser {
ret = new TryActionItem(tryCommands, catchExceptionNames, catchExceptionTypes, catchCommands, finallyCommands);
break;
case THROW:
ret = new ThrowActionItem(null, null, expression(inFunction, inMethod, inTellTarget, true, variables, functions, false));
ret = new ThrowActionItem(null, null, expression(inFunction, inMethod, inTellTarget, true, variables, functions, false, hasEval));
break;
case SEMICOLON: //empty command
if (debugMode) {
@@ -1293,13 +1299,13 @@ public class ActionScript2Parser {
}
return new EmptyCommand();
default:
GraphTargetItem valcmd = expressionCommands(s, inFunction, inMethod, inTellTarget, forinlevel, variables, functions);
GraphTargetItem valcmd = expressionCommands(s, inFunction, inMethod, inTellTarget, forinlevel, variables, functions, hasEval);
if (valcmd != null) {
ret = valcmd;
break;
}
lexer.pushback(s);
ret = expression(inFunction, inMethod, inTellTarget, true, variables, functions, true);
ret = expression(inFunction, inMethod, inTellTarget, true, variables, functions, true, hasEval);
}
if (debugMode) {
System.out.println("/command");
@@ -1307,7 +1313,7 @@ public class ActionScript2Parser {
lexer.removeListener(buf);
if (ret == null) { //can be popped expression
buf.pushAllBack(lexer);
ret = expression(inFunction, inMethod, inTellTarget, true, variables, functions, false);
ret = expression(inFunction, inMethod, inTellTarget, true, variables, functions, false, hasEval);
}
s = lex();
if ((s != null) && (s.type != SymbolType.SEMICOLON)) {
@@ -1318,18 +1324,18 @@ public class ActionScript2Parser {
}
private GraphTargetItem expression(boolean inFunction, boolean inMethod, boolean inTellTarget, boolean allowRemainder, List<VariableActionItem> variables, List<FunctionActionItem> functions, boolean allowComma) throws IOException, ActionParseException {
private GraphTargetItem expression(boolean inFunction, boolean inMethod, boolean inTellTarget, boolean allowRemainder, List<VariableActionItem> variables, List<FunctionActionItem> functions, boolean allowComma, Reference<Boolean> hasEval) throws IOException, ActionParseException {
if (debugMode) {
System.out.println("expression:");
}
List<GraphTargetItem> commaItems = new ArrayList<>();
ParsedSymbol symb;
do {
GraphTargetItem prim = expressionPrimary(false, inFunction, inMethod, inTellTarget, allowRemainder, variables, functions, true);
GraphTargetItem prim = expressionPrimary(false, inFunction, inMethod, inTellTarget, allowRemainder, variables, functions, true, hasEval);
if (prim == null) {
return null;
}
GraphTargetItem expr = expression1(prim, GraphTargetItem.NOPRECEDENCE, inFunction, inMethod, inTellTarget, allowRemainder, variables, functions);
GraphTargetItem expr = expression1(prim, GraphTargetItem.NOPRECEDENCE, inFunction, inMethod, inTellTarget, allowRemainder, variables, functions, hasEval);
commaItems.add(expr);
symb = lex();
} while (allowComma && symb != null && symb.type == SymbolType.COMMA);
@@ -1378,7 +1384,7 @@ public class ActionScript2Parser {
return s.type.getPrecedence();
}
private GraphTargetItem expression1(GraphTargetItem lhs, int min_precedence, boolean inFunction, boolean inMethod, boolean inTellTarget, boolean allowRemainder, List<VariableActionItem> variables, List<FunctionActionItem> functions) throws IOException, ActionParseException {
private GraphTargetItem expression1(GraphTargetItem lhs, int min_precedence, boolean inFunction, boolean inMethod, boolean inTellTarget, boolean allowRemainder, List<VariableActionItem> variables, List<FunctionActionItem> functions, Reference<Boolean> hasEval) throws IOException, ActionParseException {
ParsedSymbol op;
GraphTargetItem rhs;
GraphTargetItem mhs = null;
@@ -1398,14 +1404,14 @@ public class ActionScript2Parser {
if (debugMode) {
System.out.println("ternar-middle:");
}
mhs = expression(inFunction, inMethod, inTellTarget, allowRemainder, variables, functions, false);
mhs = expression(inFunction, inMethod, inTellTarget, allowRemainder, variables, functions, false, hasEval);
expectedType(SymbolType.COLON);
if (debugMode) {
System.out.println("/ternar-middle");
}
}
rhs = expressionPrimary(allowRemainder, inFunction, inMethod, inTellTarget, allowRemainder, variables, functions, true);
rhs = expressionPrimary(allowRemainder, inFunction, inMethod, inTellTarget, allowRemainder, variables, functions, true, hasEval);
if (rhs == null) {
lexer.pushback(op);
break;
@@ -1414,7 +1420,7 @@ public class ActionScript2Parser {
lookahead = peekLex();
while ((isBinaryOperator(lookahead) && getSymbPrecedence(lookahead) < /* > on wiki */ getSymbPrecedence(op))
|| (lookahead.type.isRightAssociative() && getSymbPrecedence(lookahead) == getSymbPrecedence(op))) {
rhs = expression1(rhs, getSymbPrecedence(lookahead), inFunction, inMethod, inTellTarget, allowRemainder, variables, functions);
rhs = expression1(rhs, getSymbPrecedence(lookahead), inFunction, inMethod, inTellTarget, allowRemainder, variables, functions, hasEval);
lookahead = peekLex();
}
@@ -1620,7 +1626,7 @@ public class ActionScript2Parser {
return (item instanceof VariableActionItem);
}
private int brackets(List<GraphTargetItem> ret, boolean inFunction, boolean inMethod, boolean inTellTarget, List<VariableActionItem> variables, List<FunctionActionItem> functions) throws IOException, ActionParseException {
private int brackets(List<GraphTargetItem> ret, boolean inFunction, boolean inMethod, boolean inTellTarget, List<VariableActionItem> variables, List<FunctionActionItem> functions, Reference<Boolean> hasEval) throws IOException, ActionParseException {
ParsedSymbol s = lex();
int arrCnt = 0;
if (s.type == SymbolType.BRACKET_OPEN) {
@@ -1631,7 +1637,7 @@ public class ActionScript2Parser {
lexer.pushback(s);
}
arrCnt++;
ret.add(expression(inFunction, inMethod, inTellTarget, true, variables, functions, false));
ret.add(expression(inFunction, inMethod, inTellTarget, true, variables, functions, false, hasEval));
s = lex();
if (!s.isType(SymbolType.COMMA, SymbolType.BRACKET_CLOSE)) {
expected(s, lexer.yyline(), SymbolType.COMMA, SymbolType.BRACKET_CLOSE);
@@ -1644,7 +1650,7 @@ public class ActionScript2Parser {
return arrCnt;
}
private GraphTargetItem expressionPrimary(boolean allowEmpty, boolean inFunction, boolean inMethod, boolean inTellTarget, boolean allowRemainder, List<VariableActionItem> variables, List<FunctionActionItem> functions, boolean allowCall) throws IOException, ActionParseException {
private GraphTargetItem expressionPrimary(boolean allowEmpty, boolean inFunction, boolean inMethod, boolean inTellTarget, boolean allowRemainder, List<VariableActionItem> variables, List<FunctionActionItem> functions, boolean allowCall, Reference<Boolean> hasEval) throws IOException, ActionParseException {
if (debugMode) {
System.out.println("primary:");
}
@@ -1664,14 +1670,14 @@ public class ActionScript2Parser {
ret = new UnresolvedConstantActionItem((int) (long) (Long) s.value);
break;
case "enumerate":
ret = new EnumerateActionItem(null, null, expression(inFunction, inMethod, inTellTarget, allowRemainder, variables, functions, false));
ret = new EnumerateActionItem(null, null, expression(inFunction, inMethod, inTellTarget, allowRemainder, variables, functions, false, hasEval));
break;
//Both ASs
case "dup":
ret = new DuplicateItem(null, null, expression(inFunction, inMethod, inTellTarget, allowRemainder, variables, functions, false));
ret = new DuplicateItem(null, null, expression(inFunction, inMethod, inTellTarget, allowRemainder, variables, functions, false, hasEval));
break;
case "push":
ret = new PushItem(expression(inFunction, inMethod, inTellTarget, allowRemainder, variables, functions, false));
ret = new PushItem(expression(inFunction, inMethod, inTellTarget, allowRemainder, variables, functions, false, hasEval));
break;
case "pop":
ret = new PopItem(null, null);
@@ -1686,7 +1692,7 @@ public class ActionScript2Parser {
break;
case NEGATE:
versionRequired(s, 5);
ret = expressionPrimary(false, inFunction, inMethod, inTellTarget, false, variables, functions, true);
ret = expressionPrimary(false, inFunction, inMethod, inTellTarget, false, variables, functions, true, hasEval);
ret = new BitXorActionItem(null, null, ret, new DirectValueActionItem(4.294967295E9));
break;
@@ -1700,7 +1706,7 @@ public class ActionScript2Parser {
} else {
lexer.pushback(s);
GraphTargetItem num = expressionPrimary(false, inFunction, inMethod, inTellTarget, true, variables, functions, true);
GraphTargetItem num = expressionPrimary(false, inFunction, inMethod, inTellTarget, true, variables, functions, true, hasEval);
if ((num instanceof DirectValueActionItem)
&& (((DirectValueActionItem) num).value instanceof Long)) {
((DirectValueActionItem) num).value = -(Long) ((DirectValueActionItem) num).value;
@@ -1724,7 +1730,7 @@ public class ActionScript2Parser {
}
break;
case TYPEOF:
ret = new TypeOfActionItem(null, null, expressionPrimary(false, inFunction, inMethod, inTellTarget, false, variables, functions, true));
ret = new TypeOfActionItem(null, null, expressionPrimary(false, inFunction, inMethod, inTellTarget, false, variables, functions, true, hasEval));
allowMemberOrCall = true;
break;
case TRUE:
@@ -1754,7 +1760,7 @@ public class ActionScript2Parser {
expected(s, lexer.yyline(), SymbolType.IDENTIFIER);
objectNames.add(0, pushConst((String) s.value));
expectedType(SymbolType.COLON);
objectValues.add(0, expression(inFunction, inMethod, inTellTarget, true, variables, functions, false));
objectValues.add(0, expression(inFunction, inMethod, inTellTarget, true, variables, functions, false, hasEval));
s = lex();
if (!s.isType(SymbolType.COMMA, SymbolType.CURLY_CLOSE)) {
expected(s, lexer.yyline(), SymbolType.COMMA, SymbolType.CURLY_CLOSE);
@@ -1766,7 +1772,7 @@ public class ActionScript2Parser {
case BRACKET_OPEN: //Array literal or just brackets
lexer.pushback(s);
List<GraphTargetItem> inBrackets = new ArrayList<>();
int arrCnt = brackets(inBrackets, inFunction, inMethod, inTellTarget, variables, functions);
int arrCnt = brackets(inBrackets, inFunction, inMethod, inTellTarget, variables, functions, hasEval);
ret = new InitArrayActionItem(null, null, inBrackets);
allowMemberOrCall = true;
break;
@@ -1778,7 +1784,7 @@ public class ActionScript2Parser {
} else {
lexer.pushback(s);
}
ret = function(true, fname, false, variables, functions, inTellTarget);
ret = function(true, fname, false, variables, functions, inTellTarget, hasEval);
allowMemberOrCall = true;
break;
case STRING:
@@ -1803,7 +1809,7 @@ public class ActionScript2Parser {
break;
case DELETE:
GraphTargetItem varDel = expressionPrimary(false, inFunction, inMethod, inTellTarget, false, variables, functions, true);
GraphTargetItem varDel = expressionPrimary(false, inFunction, inMethod, inTellTarget, false, variables, functions, true, hasEval);
if (varDel instanceof GetMemberActionItem) {
GetMemberActionItem gm = (GetMemberActionItem) varDel;
ret = new DeleteActionItem(null, null, gm.object, gm.memberName);
@@ -1813,7 +1819,7 @@ public class ActionScript2Parser {
break;
case INCREMENT:
case DECREMENT: //preincrement
GraphTargetItem prevar = expressionPrimary(false, inFunction, inMethod, inTellTarget, false, variables, functions, true);//variable(inFunction, inMethod, variables, functions);
GraphTargetItem prevar = expressionPrimary(false, inFunction, inMethod, inTellTarget, false, variables, functions, true, hasEval);//variable(inFunction, inMethod, variables, functions);
if (s.type == SymbolType.INCREMENT) {
ret = new PreIncrementActionItem(null, null, prevar);
}
@@ -1823,17 +1829,17 @@ public class ActionScript2Parser {
break;
case NOT:
ret = new NotItem(null, null, expressionPrimary(false, inFunction, inMethod, inTellTarget, false, variables, functions, true));
ret = new NotItem(null, null, expressionPrimary(false, inFunction, inMethod, inTellTarget, false, variables, functions, true, hasEval));
break;
case PARENT_OPEN:
ret = new ParenthesisItem(null, null, expression(inFunction, inMethod, inTellTarget, true, variables, functions, true));
ret = new ParenthesisItem(null, null, expression(inFunction, inMethod, inTellTarget, true, variables, functions, true, hasEval));
expectedType(SymbolType.PARENT_CLOSE);
//ret = memberOrCall(ret, inFunction, inMethod, variables, functions);
allowMemberOrCall = true;
break;
case NEW:
GraphTargetItem newvar = expressionPrimary(false, inFunction, inMethod, inTellTarget, false, variables, functions, false);//variable(inFunction, inMethod, variables, functions);
GraphTargetItem newvar = expressionPrimary(false, inFunction, inMethod, inTellTarget, false, variables, functions, false, hasEval);//variable(inFunction, inMethod, variables, functions);
if (newvar instanceof ToNumberActionItem) {
List<GraphTargetItem> args = new ArrayList<>();
if (((ToNumberActionItem) newvar).value != null) {
@@ -1850,12 +1856,12 @@ public class ActionScript2Parser {
GetMemberActionItem ca = (GetMemberActionItem) newvar;
expectedType(SymbolType.PARENT_OPEN);
List<GraphTargetItem> args = call(inFunction, inMethod, inTellTarget, variables, functions);
List<GraphTargetItem> args = call(inFunction, inMethod, inTellTarget, variables, functions, hasEval);
ret = new NewMethodActionItem(null, null, ca.object, ca.memberName, args);
} else if (newvar instanceof VariableActionItem) {
VariableActionItem cf = (VariableActionItem) newvar;
expectedType(SymbolType.PARENT_OPEN);
List<GraphTargetItem> args = call(inFunction, inMethod, inTellTarget, variables, functions);
List<GraphTargetItem> args = call(inFunction, inMethod, inTellTarget, variables, functions, hasEval);
ret = new NewObjectActionItem(null, null, pushConst(cf.getVariableName()), args);
} else {
throw new ActionParseException("Invalid new item", lexer.yyline());
@@ -1865,8 +1871,9 @@ public class ActionScript2Parser {
break;
case EVAL:
expectedType(SymbolType.PARENT_OPEN);
GraphTargetItem evar = new EvalActionItem(null, null, expression(inFunction, inMethod, inTellTarget, true, variables, functions, false));
GraphTargetItem evar = new EvalActionItem(null, null, expression(inFunction, inMethod, inTellTarget, true, variables, functions, false, hasEval));
expectedType(SymbolType.PARENT_CLOSE);
hasEval.setVal(true);
//evar = memberOrCall(evar, inFunction, inMethod, variables, functions);
ret = evar;
allowMemberOrCall = true;
@@ -1877,7 +1884,7 @@ public class ActionScript2Parser {
case SUPER:
case PATH:
if (s.value.equals("not")) {
ret = new NotItem(null, null, expressionPrimary(false, inFunction, inMethod, inTellTarget, false, variables, functions, true));
ret = new NotItem(null, null, expressionPrimary(false, inFunction, inMethod, inTellTarget, false, variables, functions, true, hasEval));
} else {
String varName = s.value.toString();
ParsedSymbol s2 = lex();
@@ -1896,7 +1903,7 @@ public class ActionScript2Parser {
break;
default:
GraphTargetItem excmd = expressionCommands(s, inFunction, inMethod, inTellTarget, -1, variables, functions);
GraphTargetItem excmd = expressionCommands(s, inFunction, inMethod, inTellTarget, -1, variables, functions, hasEval);
if (excmd != null) {
//?
ret = excmd;
@@ -1907,7 +1914,7 @@ public class ActionScript2Parser {
}
if (allowMemberOrCall && ret != null) {
ret = memberOrCall(ret, inFunction, inMethod, inTellTarget, variables, functions, allowCall);
ret = memberOrCall(ret, inFunction, inMethod, inTellTarget, variables, functions, allowCall, hasEval);
}
if (debugMode) {
System.out.println("/primary");
@@ -1943,14 +1950,14 @@ public class ActionScript2Parser {
return false;
}
private GraphTargetItem memberOrCall(GraphTargetItem ret, boolean inFunction, boolean inMethod, boolean inTellTarget, List<VariableActionItem> variables, List<FunctionActionItem> functions, boolean allowCall) throws IOException, ActionParseException {
private GraphTargetItem memberOrCall(GraphTargetItem ret, boolean inFunction, boolean inMethod, boolean inTellTarget, List<VariableActionItem> variables, List<FunctionActionItem> functions, boolean allowCall, Reference<Boolean> hasEval) throws IOException, ActionParseException {
ParsedSymbol op = lex();
while (op.isType(SymbolType.PARENT_OPEN, SymbolType.BRACKET_OPEN, SymbolType.DOT)) {
if (op.type == SymbolType.PARENT_OPEN) {
if (!allowCall) {
break;
}
List<GraphTargetItem> args = call(inFunction, inMethod, inTellTarget, variables, functions);
List<GraphTargetItem> args = call(inFunction, inMethod, inTellTarget, variables, functions, hasEval);
if (isCastOp(ret) && args.size() == 1) {
ret = new CastOpActionItem(null, null, ret, args.get(0));
} else if (ret instanceof GetMemberActionItem) {
@@ -1964,7 +1971,7 @@ public class ActionScript2Parser {
}
}
if (op.type == SymbolType.BRACKET_OPEN) {
GraphTargetItem rhs = expression(inFunction, inMethod, inTellTarget, false, variables, functions, false);
GraphTargetItem rhs = expression(inFunction, inMethod, inTellTarget, false, variables, functions, false, hasEval);
ret = new GetMemberActionItem(null, null, ret, rhs);
expectedType(SymbolType.BRACKET_CLOSE);
}
@@ -2174,7 +2181,8 @@ public class ActionScript2Parser {
List<VariableActionItem> vars = new ArrayList<>();
List<FunctionActionItem> functions = new ArrayList<>();
retTree.addAll(commands(false, false, 0, false, vars, functions));
Reference<Boolean> hasEval = new Reference<>(false);
retTree.addAll(commands(false, false, 0, false, vars, functions, hasEval));
for (VariableActionItem v : vars) {
String varName = v.getVariableName();
GraphTargetItem stored = v.getStoreValue();
@@ -12,7 +12,8 @@
* 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.swf5;
import com.jpexs.decompiler.flash.SWFInputStream;
@@ -176,7 +177,7 @@ public class ActionDefineFunction extends Action implements GraphSourceItemConta
funcList.add((FunctionActionItem) val);
}
}
FunctionActionItem fti = new FunctionActionItem(this, lineStartItem, functionName, paramNames, getRegNames(), content.get(0), constantPool, 1, new ArrayList<>(), funcList);
FunctionActionItem fti = new FunctionActionItem(this, lineStartItem, functionName, paramNames, getRegNames(), content.get(0), constantPool, 1, new ArrayList<>(), funcList, false /*actually unknown*/);
//ActionGraph.translateViaGraph(regNames, variables, functions, code, version)
stack.push(fti);
functions.put(functionName, fti);
@@ -12,7 +12,8 @@
* 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.swf7;
import com.jpexs.decompiler.flash.SWFInputStream;
@@ -316,7 +317,7 @@ public class ActionDefineFunction2 extends Action implements GraphSourceItemCont
funcList.add((FunctionActionItem) val);
}
}
FunctionActionItem fti = new FunctionActionItem(this, lineStartItem, functionName, paramNames, getRegNames(), content.get(0), constantPool, getFirstRegister(), new ArrayList<>(), funcList);
FunctionActionItem fti = new FunctionActionItem(this, lineStartItem, functionName, paramNames, getRegNames(), content.get(0), constantPool, getFirstRegister(), new ArrayList<>(), funcList, false /*actually unknown*/);
functions.put(functionName, fti);
stack.push(fti);
}