better AS 1/2 unresolved const handling

This commit is contained in:
Jindra Petřík
2018-05-24 19:42:44 +02:00
parent 51cc222964
commit a9733926cf
6 changed files with 180 additions and 3 deletions

View File

@@ -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;
import com.jpexs.decompiler.flash.abc.RenameType;

View File

@@ -0,0 +1,164 @@
/*
* Copyright (C) 2010-2018 JPEXS, All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3.0 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. */
package com.jpexs.decompiler.flash.action.model;
import com.jpexs.decompiler.flash.SourceGeneratorLocalData;
import com.jpexs.decompiler.flash.action.swf4.ActionPush;
import com.jpexs.decompiler.flash.action.swf4.ConstantIndex;
import com.jpexs.decompiler.flash.ecma.Undefined;
import com.jpexs.decompiler.flash.helpers.GraphTextWriter;
import com.jpexs.decompiler.graph.CompilationException;
import com.jpexs.decompiler.graph.GraphSourceItem;
import com.jpexs.decompiler.graph.GraphTargetItem;
import com.jpexs.decompiler.graph.SimpleValue;
import com.jpexs.decompiler.graph.SourceGenerator;
import com.jpexs.decompiler.graph.model.LocalData;
import java.util.List;
import java.util.Objects;
import java.util.Set;
/**
*
* @author JPEXS
*/
public class UnresolvedConstantActionItem extends ActionItem implements SimpleValue {
public GraphTargetItem computedRegValue;
public final int pos;
private int index;
public UnresolvedConstantActionItem(int index) {
this(null, null, 0, index);
}
public UnresolvedConstantActionItem(GraphSourceItem instruction, GraphSourceItem lineStartIns, int instructionPos, int index) {
super(instruction, lineStartIns, PRECEDENCE_PRIMARY);
this.index = index;
this.pos = instructionPos;
}
@Override
protected int getPos() {
return pos;
}
@Override
public boolean isVariableComputed() {
return (computedRegValue != null);
}
@Override
public Object getResult() {
return Undefined.INSTANCE;
}
@Override
public boolean isSimpleValue() {
return false;
}
@Override
public String toStringNoQuotes(LocalData localData) {
return "\u00A7\u00A7constant(" + index + ")";
}
public int getIndex() {
return index;
}
@Override
public GraphTextWriter appendToNoQuotes(GraphTextWriter writer, LocalData localData) {
return writer.append("\u00A7\u00A7constant(" + index + ")");
}
public String toStringNoH(ConstantPool constants) {
return "\u00A7\u00A7constant(" + index + ")";
}
@Override
public GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) {
return writer.append("\u00A7\u00A7constant(" + index + ")");
}
@Override
public boolean isCompileTime(Set<GraphTargetItem> dependencies) {
return true;
}
@Override
public int hashCode() {
return index;
}
@Override
public boolean valueEquals(GraphTargetItem obj) {
if (obj == null) {
return false;
}
if (!(obj instanceof UnresolvedConstantActionItem)) {
return false;
}
final UnresolvedConstantActionItem other = (UnresolvedConstantActionItem) obj;
if (!Objects.equals(index, other.index)) {
return false;
}
return true;
}
@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final UnresolvedConstantActionItem other = (UnresolvedConstantActionItem) obj;
if (!Objects.equals(this.index, other.index)) {
return false;
}
return true;
}
@Override
public List<GraphSourceItem> toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException {
return toSourceMerge(localData, generator, new ActionPush(new ConstantIndex(index)));
}
@Override
public boolean hasReturnValue() {
return true;
}
public boolean isString() {
return true;
}
public String getAsString() {
if (!isString()) {
return null;
}
return (String) getResult();
}
@Override
public String toString() {
return "" + getResult();
}
}

View File

@@ -80,6 +80,7 @@ import com.jpexs.decompiler.flash.action.model.TraceActionItem;
import com.jpexs.decompiler.flash.action.model.TypeOfActionItem;
import com.jpexs.decompiler.flash.action.model.UnLoadMovieActionItem;
import com.jpexs.decompiler.flash.action.model.UnLoadMovieNumActionItem;
import com.jpexs.decompiler.flash.action.model.UnresolvedConstantActionItem;
import com.jpexs.decompiler.flash.action.model.clauses.ClassActionItem;
import com.jpexs.decompiler.flash.action.model.clauses.ForInActionItem;
import com.jpexs.decompiler.flash.action.model.clauses.IfFrameLoadedActionItem;
@@ -1583,6 +1584,12 @@ public class ActionScript2Parser {
expectedType(SymbolType.PARENT_OPEN);
switch ("" + s.value) {
//AS 1/2:
//AS2:
case "constant":
s = lexer.lex();
expected(s, lexer.yyline(), SymbolType.INTEGER);
ret = new UnresolvedConstantActionItem((int) (long) (Long) s.value);
break;
case "enumerate":
ret = new EnumerateActionItem(null, null, expression(inFunction, inMethod, allowRemainder, variables, functions));
break;

View File

@@ -25,6 +25,7 @@ import com.jpexs.decompiler.flash.action.ActionList;
import com.jpexs.decompiler.flash.action.LocalDataArea;
import com.jpexs.decompiler.flash.action.model.DirectValueActionItem;
import com.jpexs.decompiler.flash.action.model.TemporaryRegister;
import com.jpexs.decompiler.flash.action.model.UnresolvedConstantActionItem;
import com.jpexs.decompiler.flash.action.parser.ActionParseException;
import com.jpexs.decompiler.flash.action.parser.pcode.ASMParsedSymbol;
import com.jpexs.decompiler.flash.action.parser.pcode.FlasmLexer;
@@ -394,7 +395,8 @@ public class ActionPush extends Action {
for (Object o : values) {
if (o instanceof ConstantIndex) {
if ((constantPool == null) || (((ConstantIndex) o).index >= constantPool.size())) {
o = "\u00A7\u00A7constant" + ((ConstantIndex) o).index;
stack.push(new UnresolvedConstantActionItem(((ConstantIndex) o).index));
continue;
} else {
o = constantPool.get(((ConstantIndex) o).index);
}

View File

@@ -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.swf4;
import com.jpexs.helpers.Helper;