From 078c10c595b04fbf62f5fb4b437b0baf40768290 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jindra=20Pet=F8=EDk?= Date: Mon, 21 Apr 2014 08:02:49 +0200 Subject: [PATCH] AS3 direct editation - const/var primitive initialization fix, preincrement fix, type calling fix, unbounded attribute fix --- .../parser/script/AVM2SourceGenerator.java | 9 +++++--- .../parser/script/ActionScriptParser.java | 6 +++-- .../abc/avm2/parser/script/CallAVM2Item.java | 22 +++++++++++++------ .../abc/avm2/parser/script/IndexAVM2Item.java | 2 +- .../abc/avm2/parser/script/NameAVM2Item.java | 2 +- .../avm2/parser/script/PropertyAVM2Item.java | 2 +- 6 files changed, 28 insertions(+), 15 deletions(-) diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/AVM2SourceGenerator.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/AVM2SourceGenerator.java index 9c00fa713..e4d89b991 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/AVM2SourceGenerator.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/AVM2SourceGenerator.java @@ -1196,9 +1196,12 @@ public class AVM2SourceGenerator implements SourceGenerator { sinitcode.add(ins(new InitPropertyIns(), traitName(si.getNamespace(), si.var))); } if (!si.isStatic() && si.value!=null) { - initcode.add(ins(new GetLocal0Ins())); - initcode.addAll(toInsList(si.value.toSource(localData, this))); - initcode.add(ins(new InitPropertyIns(), traitName(si.getNamespace(), si.var))); + //do not init basic values, that can be stored in trait + if(!(si.value instanceof IntegerValueAVM2Item) && !(si.value instanceof StringAVM2Item) && !(si.value instanceof BooleanAVM2Item) && !(si.value instanceof NullAVM2Item) && !(si.value instanceof UndefinedAVM2Item)){ + initcode.add(ins(new GetLocal0Ins())); + initcode.addAll(toInsList(si.value.toSource(localData, this))); + initcode.add(ins(new InitPropertyIns(), traitName(si.getNamespace(), si.var))); + } } } } 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 eb9cb0dc6..9a8b39c84 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 @@ -738,6 +738,8 @@ public class ActionScriptParser { if (s.type == SymbolType.COLON) { type = type(new Reference(false), importedClasses, openedNamespaces, new ArrayList()); s = lex(); + }else{ + type = TypeItem.UNBOUNDED; } GraphTargetItem value = null; @@ -1870,10 +1872,10 @@ public class ActionScriptParser { case MINUS: s = lex(); if (s.isType(SymbolType.DOUBLE)) { - ret = new FloatValueAVM2Item(null, (Double) s.value); + ret = new FloatValueAVM2Item(null, -(Double) s.value); existsRemainder = true; } else if (s.isType(SymbolType.INTEGER)) { - ret = new IntegerValueAVM2Item(null, (Long) s.value); + ret = new IntegerValueAVM2Item(null, -(Long) s.value); existsRemainder = true; } else { lexer.pushback(s); diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/CallAVM2Item.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/CallAVM2Item.java index dccce26b4..98da3d870 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/CallAVM2Item.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/CallAVM2Item.java @@ -97,14 +97,17 @@ public class CallAVM2Item extends AVM2Item { callable = p; } + + int propIndex = -1; if(callable instanceof TypeItem){ TypeItem t=(TypeItem)callable; - callable = new PropertyAVM2Item(null, t.fullTypeName, g.abc, g.allABCs, new ArrayList(), new ArrayList()); + propIndex = AVM2SourceGenerator.resolveType(t, ((AVM2SourceGenerator)generator).abc); } + Object obj = null; if (callable instanceof PropertyAVM2Item) { PropertyAVM2Item prop = (PropertyAVM2Item) callable; - Object obj = prop.object; + obj = prop.object; if (obj == null) { List allAbcs = new ArrayList<>(); @@ -127,16 +130,21 @@ public class CallAVM2Item extends AVM2Item { NameAVM2Item nobj = new NameAVM2Item(new TypeItem(localData.currentClass), 0, "this", null, false, new ArrayList()); nobj.setRegNumber(0); obj = nobj; - } else { - obj = new AVM2Instruction(0, new FindPropertyStrictIns(), new int[]{prop.resolveProperty(localData)}, new byte[0]); } + propIndex = prop.resolveProperty(localData); + } + } + + if(propIndex!=-1){ + if(obj == null){ + obj = new AVM2Instruction(0, new FindPropertyStrictIns(), new int[]{propIndex}, new byte[0]); } return toSourceMerge(localData, generator, obj, arguments, - new AVM2Instruction(0, new CallPropertyIns(), new int[]{prop.resolveProperty(localData), arguments.size()}, new byte[0]) + ins(new CallPropertyIns(),propIndex,arguments.size()) ); } - throw new CompilationException("Cannot call a type", line); - //return new ArrayList<>(); + + throw new CompilationException("Not a callable", line); } @Override diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/IndexAVM2Item.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/IndexAVM2Item.java index e9c600f5c..c3f7c8b57 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/IndexAVM2Item.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/IndexAVM2Item.java @@ -106,7 +106,7 @@ public class IndexAVM2Item extends AssignableAVM2Item { object,dupSetTemp(localData, generator, obj_temp), index,dupSetTemp(localData, generator, index_temp), ins(new GetPropertyIns(),indexPropIndex), - ins(new ConvertDIns()), + post?ins(new ConvertDIns()):null, (!post)?(decrement?ins(new DecrementIns()):ins(new IncrementIns())):null, needsReturn?ins(new DupIns()):null, post?(decrement?ins(new DecrementIns()):ins(new IncrementIns())):null, 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 bb3a0efed..5008da5b5 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 @@ -356,7 +356,7 @@ public class NameAVM2Item extends AssignableAVM2Item { //Start get original //generateGetLoc(regNumber), getTemp(localData, generator, index_temp), ins(new GetPropertyIns(), g.abc.constants.getMultinameId(new Multiname(Multiname.MULTINAMEL, 0, 0, allNsSet(g.abc), 0, new ArrayList()), true)), - !isInteger ? ins(new ConvertDIns()) : null, + (!isInteger && post) ? ins(new ConvertDIns()) : null, //End get original (!post) ? (decrement ? ins(isInteger ? new DecrementIIns() : new DecrementIns()) : ins(isInteger ? new IncrementIIns() : new IncrementIns())) : null, needsReturn ? ins(new DupIns()) : null, 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 7ec4cb2b7..211349e34 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 @@ -605,7 +605,7 @@ public class PropertyAVM2Item extends AssignableAVM2Item { //getTemp(localData, generator, obj_temp), //index!=null?getTemp(localData, generator, index_temp):null, ins(new GetPropertyIns(), propertyId), - !isInteger ? ins(new ConvertDIns()) : null, + (!isInteger && post) ? ins(new ConvertDIns()) : null, //End get original (!post) ? (decrement ? ins(isInteger ? new DecrementIIns() : new DecrementIns()) : ins(isInteger ? new IncrementIIns() : new IncrementIns())) : null, needsReturn ? ins(new DupIns()) : null,