AS1: Old string operators support, and/or, <> operator (editation)

This commit is contained in:
Jindra Petřík
2014-05-12 19:51:07 +02:00
parent d4887af707
commit f8aac56d82
13 changed files with 1405 additions and 1123 deletions

View File

@@ -30,7 +30,7 @@ import java.util.List;
public class AndActionItem extends BinaryOpItem {
public AndActionItem(GraphSourceItem instruction, GraphTargetItem leftSide, GraphTargetItem rightSide) {
super(instruction, PRECEDENCE_LOGICALAND, leftSide, rightSide, "&&");
super(instruction, PRECEDENCE_LOGICALAND, leftSide, rightSide, "and");
}
@Override

View File

@@ -30,7 +30,7 @@ import java.util.List;
public class OrActionItem extends BinaryOpItem {
public OrActionItem(GraphSourceItem instruction, GraphTargetItem leftSide, GraphTargetItem rightSide) {
super(instruction, PRECEDENCE_LOGICALOR, leftSide, rightSide, "||");
super(instruction, PRECEDENCE_LOGICALOR, leftSide, rightSide, "or");
}
@Override

View File

@@ -30,7 +30,7 @@ import java.util.Set;
public class StringAddActionItem extends BinaryOpItem {
public StringAddActionItem(GraphSourceItem instruction, GraphTargetItem leftSide, GraphTargetItem rightSide) {
super(instruction, PRECEDENCE_ADDITIVE, leftSide, rightSide, "+");
super(instruction, PRECEDENCE_ADDITIVE, leftSide, rightSide, "add");
}
@Override

View File

@@ -27,10 +27,10 @@ import com.jpexs.decompiler.graph.model.BinaryOpItem;
import java.util.List;
import java.util.Set;
public class StringEqActionItem extends BinaryOpItem {
public class StringEqActionItem extends BinaryOpItem implements Inverted {
public StringEqActionItem(GraphSourceItem instruction, GraphTargetItem leftSide, GraphTargetItem rightSide) {
super(instruction, PRECEDENCE_EQUALITY, leftSide, rightSide, "==");
super(instruction, PRECEDENCE_EQUALITY, leftSide, rightSide, "eq");
}
@Override
@@ -47,4 +47,9 @@ public class StringEqActionItem extends BinaryOpItem {
public GraphTargetItem returnType() {
return TypeItem.BOOLEAN;
}
@Override
public GraphTargetItem invert() {
return new StringNeActionItem(src, leftSide, rightSide);
}
}

View File

@@ -0,0 +1,57 @@
/*
* Copyright (C) 2010-2014 JPEXS
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.jpexs.decompiler.flash.action.model.operations;
import com.jpexs.decompiler.flash.SourceGeneratorLocalData;
import com.jpexs.decompiler.flash.action.special.ActionNop;
import com.jpexs.decompiler.flash.action.swf4.ActionNot;
import com.jpexs.decompiler.flash.action.swf4.ActionStringLess;
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 com.jpexs.decompiler.graph.model.BinaryOpItem;
import java.util.List;
import java.util.Set;
public class StringGeActionItem extends BinaryOpItem implements Inverted{
public StringGeActionItem(GraphSourceItem instruction, GraphTargetItem leftSide, GraphTargetItem rightSide) {
super(instruction, PRECEDENCE_RELATIONAL, leftSide, rightSide, "ge");
}
@Override
public boolean isCompileTime(Set<GraphTargetItem> dependencies) {
return false;
}
@Override
public List<GraphSourceItem> toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException {
return toSourceMerge(localData, generator, leftSide, rightSide, new ActionStringLess(), new ActionNot());
}
@Override
public GraphTargetItem returnType() {
return TypeItem.BOOLEAN;
}
@Override
public GraphTargetItem invert() {
return new StringLtActionItem(src, leftSide, rightSide);
}
}

View File

@@ -0,0 +1,55 @@
/*
* Copyright (C) 2010-2014 JPEXS
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.jpexs.decompiler.flash.action.model.operations;
import com.jpexs.decompiler.flash.SourceGeneratorLocalData;
import com.jpexs.decompiler.flash.action.swf4.ActionStringLess;
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 com.jpexs.decompiler.graph.model.BinaryOpItem;
import java.util.List;
import java.util.Set;
public class StringGtActionItem extends BinaryOpItem implements Inverted {
public StringGtActionItem(GraphSourceItem instruction, GraphTargetItem leftSide, GraphTargetItem rightSide) {
super(instruction, PRECEDENCE_RELATIONAL, leftSide, rightSide, "gt");
}
@Override
public boolean isCompileTime(Set<GraphTargetItem> dependencies) {
return false;
}
@Override
public List<GraphSourceItem> toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException {
return toSourceMerge(localData, generator, rightSide, leftSide, new ActionStringLess());
}
@Override
public GraphTargetItem returnType() {
return TypeItem.BOOLEAN;
}
@Override
public GraphTargetItem invert() {
return new StringLeActionItem(src, leftSide, rightSide);
}
}

View File

@@ -0,0 +1,56 @@
/*
* Copyright (C) 2010-2014 JPEXS
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.jpexs.decompiler.flash.action.model.operations;
import com.jpexs.decompiler.flash.SourceGeneratorLocalData;
import com.jpexs.decompiler.flash.action.swf4.ActionNot;
import com.jpexs.decompiler.flash.action.swf4.ActionStringLess;
import com.jpexs.decompiler.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 com.jpexs.decompiler.graph.model.BinaryOpItem;
import java.util.List;
import java.util.Set;
public class StringLeActionItem extends BinaryOpItem implements Inverted{
public StringLeActionItem(GraphSourceItem instruction, GraphTargetItem leftSide, GraphTargetItem rightSide) {
super(instruction, PRECEDENCE_RELATIONAL, leftSide, rightSide, "le");
}
@Override
public boolean isCompileTime(Set<GraphTargetItem> dependencies) {
return false;
}
@Override
public List<GraphSourceItem> toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException {
return toSourceMerge(localData, generator, rightSide, leftSide, new ActionStringLess(), new ActionNot());
}
@Override
public GraphTargetItem returnType() {
return TypeItem.BOOLEAN;
}
@Override
public GraphTargetItem invert() {
return new StringGtActionItem(src, leftSide, rightSide);
}
}

View File

@@ -27,10 +27,10 @@ import com.jpexs.decompiler.graph.model.BinaryOpItem;
import java.util.List;
import java.util.Set;
public class StringLtActionItem extends BinaryOpItem {
public class StringLtActionItem extends BinaryOpItem implements Inverted{
public StringLtActionItem(GraphSourceItem instruction, GraphTargetItem leftSide, GraphTargetItem rightSide) {
super(instruction, PRECEDENCE_RELATIONAL, leftSide, rightSide, "<");
super(instruction, PRECEDENCE_RELATIONAL, leftSide, rightSide, "lt");
}
@Override
@@ -47,4 +47,9 @@ public class StringLtActionItem extends BinaryOpItem {
public GraphTargetItem returnType() {
return TypeItem.BOOLEAN;
}
@Override
public GraphTargetItem invert() {
return new StringGeActionItem(src, leftSide, rightSide);
}
}

View File

@@ -0,0 +1,56 @@
/*
* Copyright (C) 2010-2014 JPEXS
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.jpexs.decompiler.flash.action.model.operations;
import com.jpexs.decompiler.flash.SourceGeneratorLocalData;
import com.jpexs.decompiler.flash.action.swf4.ActionNot;
import com.jpexs.decompiler.flash.action.swf4.ActionStringEquals;
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 com.jpexs.decompiler.graph.model.BinaryOpItem;
import java.util.List;
import java.util.Set;
public class StringNeActionItem extends BinaryOpItem implements Inverted {
public StringNeActionItem(GraphSourceItem instruction, GraphTargetItem leftSide, GraphTargetItem rightSide) {
super(instruction, PRECEDENCE_EQUALITY, leftSide, rightSide, "ne");
}
@Override
public boolean isCompileTime(Set<GraphTargetItem> dependencies) {
return false;
}
@Override
public List<GraphSourceItem> toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException {
return toSourceMerge(localData, generator, leftSide, rightSide, new ActionStringEquals(), new ActionNot());
}
@Override
public GraphTargetItem returnType() {
return TypeItem.BOOLEAN;
}
@Override
public GraphTargetItem invert() {
return new StringEqActionItem(src, leftSide, rightSide);
}
}

View File

@@ -107,6 +107,13 @@ import com.jpexs.decompiler.flash.action.model.operations.PreIncrementActionItem
import com.jpexs.decompiler.flash.action.model.operations.RShiftActionItem;
import com.jpexs.decompiler.flash.action.model.operations.StrictEqActionItem;
import com.jpexs.decompiler.flash.action.model.operations.StrictNeqActionItem;
import com.jpexs.decompiler.flash.action.model.operations.StringAddActionItem;
import com.jpexs.decompiler.flash.action.model.operations.StringEqActionItem;
import com.jpexs.decompiler.flash.action.model.operations.StringGeActionItem;
import com.jpexs.decompiler.flash.action.model.operations.StringGtActionItem;
import com.jpexs.decompiler.flash.action.model.operations.StringLeActionItem;
import com.jpexs.decompiler.flash.action.model.operations.StringLtActionItem;
import com.jpexs.decompiler.flash.action.model.operations.StringNeActionItem;
import com.jpexs.decompiler.flash.action.model.operations.SubtractActionItem;
import com.jpexs.decompiler.flash.action.model.operations.URShiftActionItem;
import com.jpexs.decompiler.flash.action.parser.ParseException;
@@ -1396,19 +1403,48 @@ public class ActionScriptParser {
lexer.pushback(s);
ret = memberOrCall(expr, registerVars, inFunction, inMethod, variables);
break;
default:
lexer.pushback(s);
if (expr instanceof ParenthesisItem) {
if (isType(((ParenthesisItem) expr).value)) {
GraphTargetItem expr2 = expression(false, registerVars, inFunction, inMethod, true, variables);
if (expr2 != null) {
ret = new CastOpActionItem(null, ((ParenthesisItem) expr).value, expr2);
}
case IDENTIFIER:
switch(s.value.toString()){
case "add":
ret = new StringAddActionItem(null, expr, expression(registerVars, inFunction, inMethod, allowRemainder, variables));
break;
case "eq":
ret = new StringEqActionItem(null, expr, expression(registerVars, inFunction, inMethod, allowRemainder, variables));
break;
case "ne":
ret = new StringNeActionItem(null, expr, expression(registerVars, inFunction, inMethod, allowRemainder, variables));
break;
case "lt":
ret = new StringLtActionItem(null, expr, expression(registerVars, inFunction, inMethod, allowRemainder, variables));
break;
case "ge":
ret = new StringGeActionItem(null, expr, expression(registerVars, inFunction, inMethod, allowRemainder, variables));
break;
case "gt":
ret = new StringGtActionItem(null, expr, expression(registerVars, inFunction, inMethod, allowRemainder, variables));
break;
case "le":
ret = new StringLeActionItem(null, expr, expression(registerVars, inFunction, inMethod, allowRemainder, variables));
break;
default:
lexer.pushback(s);
}
break;
default:
lexer.pushback(s);
}
if(ret == null){
if (expr instanceof ParenthesisItem) {
if (isType(((ParenthesisItem) expr).value)) {
GraphTargetItem expr2 = expression(false, registerVars, inFunction, inMethod, true, variables);
if (expr2 != null) {
ret = new CastOpActionItem(null, ((ParenthesisItem) expr).value, expr2);
}
}
}
}
ret = fixPrecedence(ret);
return ret;
}
@@ -1639,22 +1675,20 @@ public class ActionScriptParser {
}
existsRemainder = true;
break;
case EVAL:
expectedType(SymbolType.PARENT_OPEN);
GraphTargetItem evar = new EvalActionItem(null, expression(registerVars, inFunction, inMethod, true, variables));
expectedType(SymbolType.PARENT_CLOSE);
evar = memberOrCall(evar, registerVars, inFunction, inMethod, variables);
ret = evar;
existsRemainder = true;
break;
case IDENTIFIER:
case THIS:
case SUPER:
case EVAL:
GraphTargetItem var;
if (s.type == SymbolType.EVAL) {
expectedType(SymbolType.PARENT_OPEN);
var = new EvalActionItem(null, expression(registerVars, inFunction, inMethod, true, variables));
expectedType(SymbolType.PARENT_CLOSE);
var = memberOrCall(var, registerVars, inFunction, inMethod, variables);
} else {
lexer.pushback(s);
var = variable(registerVars, inFunction, inMethod, variables);
var = memberOrCall(var, registerVars, inFunction, inMethod, variables);
}
case SUPER:
lexer.pushback(s);
GraphTargetItem var = variable(registerVars, inFunction, inMethod, variables);
var = memberOrCall(var, registerVars, inFunction, inMethod, variables);
ret = var;
existsRemainder = true;
break;

View File

@@ -92,6 +92,8 @@ public enum SymbolType {
STRICT_NOT_EQUAL,
AND,
OR,
FULLAND,
FULLOR,
INCREMENT,
DECREMENT,
PLUS,

View File

@@ -259,7 +259,7 @@ SingleCharacter = [^\r\n\'\\]
"<=" { return new ParsedSymbol(SymbolGroup.OPERATOR,SymbolType.LOWER_EQUAL,yytext()); }
">=" { return new ParsedSymbol(SymbolGroup.OPERATOR,SymbolType.GREATER_EQUAL,yytext()); }
"!==" { return new ParsedSymbol(SymbolGroup.OPERATOR,SymbolType.STRICT_NOT_EQUAL,yytext()); }
"!=" { return new ParsedSymbol(SymbolGroup.OPERATOR,SymbolType.NOT_EQUAL,yytext()); }
"!=" | "<>" { return new ParsedSymbol(SymbolGroup.OPERATOR,SymbolType.NOT_EQUAL,yytext()); }
"&&" { return new ParsedSymbol(SymbolGroup.OPERATOR,SymbolType.AND,yytext()); }
"||" { return new ParsedSymbol(SymbolGroup.OPERATOR,SymbolType.OR,yytext()); }
"++" { return new ParsedSymbol(SymbolGroup.OPERATOR,SymbolType.INCREMENT,yytext()); }
@@ -295,6 +295,8 @@ SingleCharacter = [^\r\n\'\\]
"typeof" { return new ParsedSymbol(SymbolGroup.OPERATOR,SymbolType.TYPEOF,yytext()); }
"void" { return new ParsedSymbol(SymbolGroup.OPERATOR,SymbolType.VOID,yytext()); }
"@" { return new ParsedSymbol(SymbolGroup.OPERATOR,SymbolType.ATTRIBUTE,yytext()); }
"and" { return new ParsedSymbol(SymbolGroup.OPERATOR,SymbolType.FULLAND,yytext()); }
"or" { return new ParsedSymbol(SymbolGroup.OPERATOR,SymbolType.FULLOR,yytext()); }
/* string literal */
\" {