AS3 parser: delete property

This commit is contained in:
Jindra Petk
2014-04-13 12:12:17 +02:00
parent a435c21774
commit 8fd9b28ebd
3 changed files with 23 additions and 9 deletions

View File

@@ -21,6 +21,8 @@ import com.jpexs.decompiler.flash.abc.avm2.instructions.AVM2Instruction;
import com.jpexs.decompiler.flash.abc.avm2.instructions.other.DeletePropertyIns;
import com.jpexs.decompiler.flash.abc.avm2.model.AVM2Item;
import com.jpexs.decompiler.flash.abc.avm2.parser.script.AVM2SourceGenerator;
import com.jpexs.decompiler.flash.abc.avm2.parser.script.PropertyAVM2Item;
import com.jpexs.decompiler.flash.abc.avm2.parser.script.UnresolvedAVM2Item;
import com.jpexs.decompiler.flash.helpers.GraphTextWriter;
import com.jpexs.decompiler.graph.CompilationException;
import com.jpexs.decompiler.graph.GraphSourceItem;
@@ -35,6 +37,14 @@ public class DeletePropertyAVM2Item extends AVM2Item {
public GraphTargetItem object;
public GraphTargetItem propertyName;
private int line;
//Constructor for compiler
public DeletePropertyAVM2Item(GraphTargetItem property, int line) {
this(null, property, null);
this.line = line;
}
public DeletePropertyAVM2Item(AVM2Instruction instruction, GraphTargetItem object, GraphTargetItem propertyName) {
super(instruction, PRECEDENCE_UNARY);
this.object = object;
@@ -52,8 +62,18 @@ public class DeletePropertyAVM2Item extends AVM2Item {
@Override
public List<GraphSourceItem> toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException {
return toSourceMerge(localData, generator, object,
new AVM2Instruction(0, new DeletePropertyIns(), new int[]{((AVM2SourceGenerator) generator).propertyName(propertyName)}, new byte[0])
GraphTargetItem p = object;
if (p instanceof UnresolvedAVM2Item) {
p = ((UnresolvedAVM2Item) p).resolved;
}
if (!(p instanceof PropertyAVM2Item)) {
throw new CompilationException("Not a property", line); //TODO: handle line better way
}
PropertyAVM2Item prop = (PropertyAVM2Item) p;
return toSourceMerge(localData, generator, prop.object,
ins(new DeletePropertyIns(), prop.resolveProperty(localData))
);
}

View File

@@ -1723,12 +1723,7 @@ public class ActionScriptParser {
if (!isNameOrProp(varDel)) {
throw new ParseException("Not a property or name", lexer.yyline());
}
if (varDel instanceof GetPropertyAVM2Item) {
GetPropertyAVM2Item gm = (GetPropertyAVM2Item) varDel;
ret = new DeletePropertyAVM2Item(null, gm.object, gm.propertyName);
} else {
throw new ParseException("Not a property", lexer.yyline());
}
ret = new DeletePropertyAVM2Item(varDel, lexer.yyline());
break;
case INCREMENT:
case DECREMENT: //preincrement

View File

@@ -3,6 +3,5 @@ TODO List for AS3 parser/compiler:
- E4X (XML)
- typenames (Vectors)
- inner function names
- delete property
- default xml namespace
- custom namespace modifiers