diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/ActionScriptParser.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/ActionScriptParser.java index a2a901416..a3717dab7 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/ActionScriptParser.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/ActionScriptParser.java @@ -344,8 +344,8 @@ public class ActionScriptParser { } } - if (k == -1) { - throw new ParseException("Cannot find variable or type:" + Helper.joinStrings(parts,"."), lexer.yyline()); + if (k == -1) { + throw new ParseException("Cannot find variable or type:" + Helper.joinStrings(parts, "."), lexer.yyline()); } GraphTargetItem ret = new TypeItem("".equals(pkg) ? name : pkg + "." + name); for (int i = 1; i < parts.size(); i++) { @@ -409,32 +409,32 @@ public class ActionScriptParser { private MethodAVM2Item method(boolean override, boolean isFinal, GraphTargetItem thisType, List openedNamespaces, List openedNamespacesKinds, boolean isStatic, int namespaceKind, boolean withBody, String functionName, boolean isMethod, List variables) throws IOException, ParseException { FunctionAVM2Item f = function(thisType, openedNamespaces, openedNamespacesKinds, withBody, functionName, isMethod, variables); - return new MethodAVM2Item(f.hasRest,f.line,override, isFinal, isStatic, namespaceKind, functionName, f.paramTypes, f.paramNames, f.paramValues, f.body, f.subvariables, f.retType); + return new MethodAVM2Item(f.hasRest, f.line, override, isFinal, isStatic, namespaceKind, functionName, f.paramTypes, f.paramNames, f.paramValues, f.body, f.subvariables, f.retType); } private FunctionAVM2Item function(GraphTargetItem thisType, List openedNamespaces, List openedNamespacesKinds, boolean withBody, String functionName, boolean isMethod, List variables) throws IOException, ParseException { - int line=lexer.yyline(); + int line = lexer.yyline(); ParsedSymbol s; expectedType(SymbolType.PARENT_OPEN); s = lex(); List paramNames = new ArrayList<>(); List paramTypes = new ArrayList<>(); List paramValues = new ArrayList<>(); - boolean hasRest = false; + boolean hasRest = false; while (s.type != SymbolType.PARENT_CLOSE) { if (s.type != SymbolType.COMMA) { lexer.pushback(s); - } - s = lex(); - if(s.type == SymbolType.REST){ + } + s = lex(); + if (s.type == SymbolType.REST) { hasRest = true; s = lex(); } expected(s, lexer.yyline(), SymbolType.IDENTIFIER); - + paramNames.add(s.value.toString()); s = lex(); - if(!hasRest){ + if (!hasRest) { if (s.type == SymbolType.COLON) { paramTypes.add(type(openedNamespaces, openedNamespacesKinds, variables)); s = lex(); @@ -449,12 +449,11 @@ public class ActionScriptParser { } } } - if (!s.isType(SymbolType.COMMA, SymbolType.PARENT_CLOSE)) { expected(s, lexer.yyline(), SymbolType.COMMA, SymbolType.PARENT_CLOSE); } - if(hasRest){ + if (hasRest) { expected(s, lexer.yyline(), SymbolType.PARENT_CLOSE); } } @@ -484,7 +483,7 @@ public class ActionScriptParser { for (int i = 0; i < parCnt; i++) { subvariables.remove(0); } - return new FunctionAVM2Item(hasRest,line,functionName, paramTypes, paramNames, paramValues, body, subvariables, retType); + return new FunctionAVM2Item(hasRest, line, functionName, paramTypes, paramNames, paramValues, body, subvariables, retType); } private GraphTargetItem traits(List openedNamespaces, List openedNamespacesKinds, String packageName, String classNameStr, boolean isInterface, List traits) throws ParseException, IOException { @@ -511,7 +510,7 @@ public class ActionScriptParser { } isFinal = true; } - if(s.type == SymbolType.DYNAMIC){ + if (s.type == SymbolType.DYNAMIC) { if (isDynamic) { throw new ParseException("Only one dynamic keyword allowed", lexer.yyline()); } @@ -586,7 +585,7 @@ public class ActionScriptParser { } while (s.type == SymbolType.COMMA); } expected(s, lexer.yyline(), SymbolType.CURLY_OPEN); - traits.add((classTraits(isDynamic,isFinal,openedNamespaces, openedNamespacesKinds, packageName, nsKind, false, classTypeStr, extendsTypeStr, implementsTypeStrs, variables))); + traits.add((classTraits(isDynamic, isFinal, openedNamespaces, openedNamespacesKinds, packageName, nsKind, false, classTypeStr, extendsTypeStr, implementsTypeStrs, variables))); expectedType(SymbolType.CURLY_CLOSE); break; case INTERFACE: @@ -599,7 +598,7 @@ public class ActionScriptParser { if (isFinal) { throw new ParseException("Final flag not allowed for interfaces", lexer.yyline()); } - if(isDynamic){ + if (isDynamic) { throw new ParseException("Dynamic flag not allowed for interfaces", lexer.yyline()); } //GraphTargetItem interfaceTypeStr = type(openedNamespaces, openedNamespacesKinds, variables); @@ -617,20 +616,20 @@ public class ActionScriptParser { } while (s.type == SymbolType.COMMA); } expected(s, lexer.yyline(), SymbolType.CURLY_OPEN); - traits.add((classTraits(false,isFinal,openedNamespaces, openedNamespacesKinds, packageName, nsKind, true, intTypeStr, null, intExtendsTypeStrs, variables))); + traits.add((classTraits(false, isFinal, openedNamespaces, openedNamespacesKinds, packageName, nsKind, true, intTypeStr, null, intExtendsTypeStrs, variables))); expectedType(SymbolType.CURLY_CLOSE); break; case FUNCTION: - - if(isDynamic){ + + if (isDynamic) { throw new ParseException("Dynamic flag not allowed for methods", lexer.yyline()); } s = lex(); if (s.type == SymbolType.GET) { if (classNameStr == null) { throw new ParseException("No get keyword allowed here", lexer.yyline()); - } + } isGetter = true; s = lex(); } else if (s.type == SymbolType.SET) { @@ -669,16 +668,16 @@ public class ActionScriptParser { MethodAVM2Item ft = method(isOverride, isFinal, thisType, openedNamespaces, openedNamespacesKinds, isStatic, nsKind, !isInterface, fname, true, variables); GraphTargetItem t; if (isGetter) { - if(!ft.paramTypes.isEmpty()){ + if (!ft.paramTypes.isEmpty()) { throw new ParseException("Getter can't have any parameters", lexer.yyline()); } - GetterAVM2Item g = new GetterAVM2Item(ft.hasRest,ft.line,ft.isOverride(), ft.isFinal(), isStatic, ft.namespaceKind, ft.functionName, ft.paramTypes, ft.paramNames, ft.paramValues, ft.body, ft.subvariables, ft.retType); + GetterAVM2Item g = new GetterAVM2Item(ft.hasRest, ft.line, ft.isOverride(), ft.isFinal(), isStatic, ft.namespaceKind, ft.functionName, ft.paramTypes, ft.paramNames, ft.paramValues, ft.body, ft.subvariables, ft.retType); t = g; } else if (isSetter) { - if(ft.paramTypes.size()!=1){ + if (ft.paramTypes.size() != 1) { throw new ParseException("Getter must have exactly one parameter", lexer.yyline()); } - SetterAVM2Item st = new SetterAVM2Item(ft.hasRest, ft.line,ft.isOverride(), ft.isFinal(), isStatic, ft.namespaceKind, ft.functionName, ft.paramTypes, ft.paramNames, ft.paramValues, ft.body, ft.subvariables, ft.retType); + SetterAVM2Item st = new SetterAVM2Item(ft.hasRest, ft.line, ft.isOverride(), ft.isFinal(), isStatic, ft.namespaceKind, ft.functionName, ft.paramTypes, ft.paramNames, ft.paramValues, ft.body, ft.subvariables, ft.retType); t = st; } else { t = ft; @@ -699,8 +698,8 @@ public class ActionScriptParser { if (isFinal) { throw new ParseException("Final flag not allowed for " + (isConst ? "consts" : "vars"), lexer.yyline()); } - if(isDynamic){ - throw new ParseException("Dynamic flag not allowed for "+(isConst ? "consts":"vars"), lexer.yyline()); + if (isDynamic) { + throw new ParseException("Dynamic flag not allowed for " + (isConst ? "consts" : "vars"), lexer.yyline()); } s = lex(); @@ -735,7 +734,7 @@ public class ActionScriptParser { return constr; } - private GraphTargetItem classTraits(boolean isDynamic,boolean isFinal,List openedNamespaces, List openedNamespacesKinds, String packageName, int namespaceKind, boolean isInterface, String nameStr, GraphTargetItem extendsStr, List implementsStr, List variables) throws IOException, ParseException { + private GraphTargetItem classTraits(boolean isDynamic, boolean isFinal, List openedNamespaces, List openedNamespacesKinds, String packageName, int namespaceKind, boolean isInterface, String nameStr, GraphTargetItem extendsStr, List implementsStr, List variables) throws IOException, ParseException { GraphTargetItem ret = null; @@ -781,9 +780,9 @@ public class ActionScriptParser { GraphTargetItem constr = traits(openedNamespaces, openedNamespacesKinds, packageName, classNameStr, isInterface, traits); if (isInterface) { - return new InterfaceAVM2Item(isFinal,namespaceKind, classNameStr, implementsStr, traits); + return new InterfaceAVM2Item(isFinal, namespaceKind, classNameStr, implementsStr, traits); } else { - return new ClassAVM2Item(isDynamic,isFinal,namespaceKind, classNameStr, extendsStr, implementsStr, constr, traits); + return new ClassAVM2Item(isDynamic, isFinal, namespaceKind, classNameStr, extendsStr, implementsStr, constr, traits); } } @@ -1407,15 +1406,16 @@ public class ActionScriptParser { assigned = new BitXorAVM2Item(null, expr, assigned); break; } - if (expr instanceof NameAVM2Item) { - ((NameAVM2Item) expr).setStoreValue(assigned); - ((NameAVM2Item) expr).setDefinition(false); - ret = expr; - } else if (expr instanceof PropertyAVM2Item) { - ((PropertyAVM2Item) expr).setStoreValue(assigned); - } else { + + if (!(expr instanceof AssignableAVM2Item)) { throw new ParseException("Invalid assignment", lexer.yyline()); } + ((AssignableAVM2Item) expr).setAssignedValue(assigned); + if (expr instanceof NameAVM2Item) { + ((NameAVM2Item) expr).setDefinition(false); + ret = expr; + } + ret = expr; break; case INCREMENT: //postincrement if (!(expr instanceof NameAVM2Item) && !(expr instanceof GetPropertyAVM2Item)) { @@ -1797,7 +1797,7 @@ public class ActionScriptParser { } public static void main(String[] args) { - if(args.length<2){ + if (args.length < 2) { return; } Main.initLogging(false); diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/AssignableAVM2Item.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/AssignableAVM2Item.java new file mode 100644 index 000000000..4c9a93bc4 --- /dev/null +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/AssignableAVM2Item.java @@ -0,0 +1,55 @@ +/* + * Copyright (C) 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 . + */ + +package com.jpexs.decompiler.flash.abc.avm2.parser.script; + +import com.jpexs.decompiler.flash.SourceGeneratorLocalData; +import com.jpexs.decompiler.flash.abc.avm2.model.AVM2Item; +import com.jpexs.decompiler.graph.GraphSourceItem; +import com.jpexs.decompiler.graph.GraphTargetItem; +import com.jpexs.decompiler.graph.SourceGenerator; +import java.util.ArrayList; +import java.util.List; + +/** + * + * @author JPEXS + */ +public abstract class AssignableAVM2Item extends AVM2Item{ + + protected GraphTargetItem assignedValue; + + public AssignableAVM2Item() { + this(null); + } + + public AssignableAVM2Item(GraphTargetItem storeValue) { + super(null, PRECEDENCE_PRIMARY); + this.assignedValue = storeValue; + } + public abstract List toSourcePreChange(SourceGeneratorLocalData localData, SourceGenerator generator, List change); + public abstract List toSourcePostChange(SourceGeneratorLocalData localData, SourceGenerator generator, List change); + + public GraphTargetItem getAssignedValue(){ + return assignedValue; + } + + public void setAssignedValue(GraphTargetItem storeValue) { + this.assignedValue = storeValue; + } + +} diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/NameAVM2Item.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/NameAVM2Item.java index 330d0194c..354d9d586 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/NameAVM2Item.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/NameAVM2Item.java @@ -36,10 +36,10 @@ import java.util.List; * * @author JPEXS */ -public class NameAVM2Item extends AVM2Item { +public class NameAVM2Item extends AssignableAVM2Item { private String variableName; - private GraphTargetItem storeValue; + private boolean definition; private GraphTargetItem index; private int nsKind = -1; @@ -92,8 +92,8 @@ public class NameAVM2Item extends AVM2Item { return nsKind; } - public void setStoreValue(GraphTargetItem storeValue) { - this.storeValue = storeValue; + public void setAssignedValue(GraphTargetItem storeValue) { + this.assignedValue = storeValue; } public String getVariableName() { @@ -101,9 +101,9 @@ public class NameAVM2Item extends AVM2Item { } public NameAVM2Item(GraphTargetItem type, int line, String variableName, GraphTargetItem storeValue, boolean definition, List openedNamespaces, List openedNamespacesKind) { - super(null, PRECEDENCE_PRIMARY); + super(storeValue); this.variableName = variableName; - this.storeValue = storeValue; + this.assignedValue = storeValue; this.definition = definition; this.line = line; this.type = type; @@ -114,7 +114,7 @@ public class NameAVM2Item extends AVM2Item { } public GraphTargetItem getStoreValue() { - return storeValue; + return assignedValue; } @Override @@ -127,13 +127,19 @@ public class NameAVM2Item extends AVM2Item { if (regNumber == -1) { throw new RuntimeException("No register set for " + variableName); } - if (definition && storeValue == null) { + if (definition && assignedValue == null) { return new ArrayList<>(); } - if (storeValue == null) { + AVM2SourceGenerator g=(AVM2SourceGenerator)generator; + + if(index!=null){ + //g.abc.constants.getmu + } + + if (assignedValue == null) { return toSourceMerge(localData, generator, new LocalRegAVM2Item(null, regNumber, null)); } else { - return toSourceMerge(localData, generator, new SetLocalAVM2Item(null, regNumber, new CoerceAVM2Item(null, storeValue, type.toString()))); + return toSourceMerge(localData, generator, new SetLocalAVM2Item(null, regNumber, new CoerceAVM2Item(null, assignedValue, type.toString()))); } } @@ -143,14 +149,14 @@ public class NameAVM2Item extends AVM2Item { if (regNumber == -1) { throw new RuntimeException("No register set for " + variableName); } - if (definition && storeValue == null) { + if (definition && assignedValue == null) { return new ArrayList<>(); } - if (storeValue == null) { + if (assignedValue == null) { return toSourceMerge(localData, generator, new LocalRegAVM2Item(null, regNumber, null), new AVM2Instruction(0, new PopIns(), new int[]{}, new byte[0])); } else { - return toSourceMerge(localData, generator, new SetLocalAVM2Item(null, regNumber, new CoerceAVM2Item(null, storeValue, type.toString())).toSourceIgnoreReturnValue(localData, generator)); + return toSourceMerge(localData, generator, new SetLocalAVM2Item(null, regNumber, new CoerceAVM2Item(null, assignedValue, type.toString())).toSourceIgnoreReturnValue(localData, generator)); } } @@ -183,4 +189,14 @@ public class NameAVM2Item extends AVM2Item { return type; } + @Override + public List toSourcePreChange(SourceGeneratorLocalData localData, SourceGenerator generator, List change) { + return null;//TODO + } + + @Override + public List toSourcePostChange(SourceGeneratorLocalData localData, SourceGenerator generator, List change) { + return null;//TODO + } + } diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/PropertyAVM2Item.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/PropertyAVM2Item.java index d0aed245c..719552ff6 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/PropertyAVM2Item.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/PropertyAVM2Item.java @@ -52,29 +52,23 @@ import java.util.List; * * @author JPEXS */ -public class PropertyAVM2Item extends AVM2Item { +public class PropertyAVM2Item extends AssignableAVM2Item { public String propertyName; public GraphTargetItem object; public List abcs; public GraphTargetItem index; - private GraphTargetItem storeValue; private List openedNamespaces; private List openedNamespacesKind; - public PropertyAVM2Item(GraphTargetItem object, String propertyName, GraphTargetItem index, List abcs, List openedNamespaces, List openedNamespacesKind) { - super(null, PRECEDENCE_PRIMARY); + public PropertyAVM2Item(GraphTargetItem object, String propertyName, GraphTargetItem index, List abcs, List openedNamespaces, List openedNamespacesKind) { this.propertyName = propertyName; this.object = object; this.abcs = abcs; this.index = index; this.openedNamespaces = openedNamespaces; this.openedNamespacesKind = openedNamespacesKind; - } - - public void setStoreValue(GraphTargetItem storeValue) { - this.storeValue = storeValue; - } + } @Override public GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) throws InterruptedException { @@ -268,13 +262,13 @@ public class PropertyAVM2Item extends AVM2Item { if (obj == null) { obj = new AVM2Instruction(0, new FindPropertyStrictIns(), new int[]{propertyId}, new byte[0]); } - if (storeValue != null) { + if (assignedValue != null) { int temp_reg = g.getFreeRegister(localData); String targetType = resolvePropertyType().toString(); - String srcType = storeValue.returnType().toString(); - GraphTargetItem st=storeValue; + String srcType = assignedValue.returnType().toString(); + GraphTargetItem st=assignedValue; if(!targetType.equals(srcType)){ - st = new CoerceAVM2Item(null, storeValue, targetType); + st = new CoerceAVM2Item(null, assignedValue, targetType); } List ret = toSourceMerge(localData, generator, obj, index,st , new AVM2Instruction(0, new DupIns(), new int[]{}, new byte[0]), @@ -301,12 +295,12 @@ public class PropertyAVM2Item extends AVM2Item { if (obj == null) { obj = new AVM2Instruction(0, new FindPropertyStrictIns(), new int[]{propertyId}, new byte[0]); } - if (storeValue != null) { + if (assignedValue != null) { String targetType = resolvePropertyType().toString(); - String srcType = storeValue.returnType().toString(); - GraphTargetItem st=storeValue; + String srcType = assignedValue.returnType().toString(); + GraphTargetItem st=assignedValue; if(!targetType.equals(srcType)){ - st = new CoerceAVM2Item(null, storeValue, targetType); + st = new CoerceAVM2Item(null, assignedValue, targetType); } return toSourceMerge(localData, generator, obj, index, st, new AVM2Instruction(0, new SetPropertyIns(), new int[]{propertyId}, new byte[0]) @@ -324,4 +318,14 @@ public class PropertyAVM2Item extends AVM2Item { return true; } + @Override + public List toSourcePreChange(SourceGeneratorLocalData localData, SourceGenerator generator, List change) { + return null; //TODO + } + + @Override + public List toSourcePostChange(SourceGeneratorLocalData localData, SourceGenerator generator, List change) { + return null; //TODO + } + } diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/todo.txt b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/todo.txt index a3d8038f9..9d5bdfefc 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/todo.txt +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/todo.txt @@ -10,4 +10,5 @@ TODO List for AS3 parser/compiler: - pre/post in/decrements - with - delete property -- default xml namespace \ No newline at end of file +- default xml namespace +- method body correct code stats \ No newline at end of file