mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/jpexs-decompiler.git
synced 2026-07-11 15:18:38 +00:00
@@ -1465,7 +1465,7 @@ public class AVM2SourceGenerator implements SourceGenerator {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<GraphSourceItem> generate(SourceGeneratorLocalData localData, CommaExpressionItem item) throws CompilationException {
|
||||
public List<GraphSourceItem> generate(SourceGeneratorLocalData localData, CommaExpressionItem item, boolean withReturnValue) throws CompilationException {
|
||||
if (item.commands.isEmpty()) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
@@ -1475,7 +1475,7 @@ public class AVM2SourceGenerator implements SourceGenerator {
|
||||
GraphTargetItem lastExpr = cmds.remove(cmds.size() - 1);
|
||||
List<GraphSourceItem> ret = new ArrayList<>();
|
||||
ret.addAll(generate(localData, cmds));
|
||||
ret.addAll(lastExpr.toSource(localData, this));
|
||||
ret.addAll(withReturnValue ? lastExpr.toSource(localData, this) : lastExpr.toSourceIgnoreReturnValue(localData, this));
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
@@ -1512,7 +1512,7 @@ public class ActionScript3Parser {
|
||||
case WHILE:
|
||||
expectedType(SymbolType.PARENT_OPEN);
|
||||
List<GraphTargetItem> whileExpr = new ArrayList<>();
|
||||
whileExpr.add(commaExpression(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, loops, loopLabels, registerVars, inFunction, inMethod, forinlevel, variables));
|
||||
whileExpr.add(expression(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, true, variables));
|
||||
expectedType(SymbolType.PARENT_CLOSE);
|
||||
List<GraphTargetItem> whileBody = new ArrayList<>();
|
||||
Loop wloop = new Loop(uniqId(), null, null);
|
||||
@@ -1534,7 +1534,7 @@ public class ActionScript3Parser {
|
||||
expectedType(SymbolType.WHILE);
|
||||
expectedType(SymbolType.PARENT_OPEN);
|
||||
List<GraphTargetItem> doExpr = new ArrayList<>();
|
||||
doExpr.add(commaExpression(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, loops, loopLabels, registerVars, inFunction, inMethod, forinlevel, variables));
|
||||
doExpr.add(expression(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, true, variables));
|
||||
expectedType(SymbolType.PARENT_CLOSE);
|
||||
ret = new DoWhileItem(null, null, dloop, doBody, doExpr);
|
||||
break;
|
||||
@@ -1892,32 +1892,26 @@ public class ActionScript3Parser {
|
||||
return arrCnt;
|
||||
}
|
||||
|
||||
private GraphTargetItem commaExpression(List<List<NamespaceItem>> allOpenedNamespaces, TypeItem thisType, NamespaceItem pkg, Reference<Boolean> needsActivation, List<DottedChain> importedClasses, List<NamespaceItem> openedNamespaces, Stack<Loop> loops, Map<Loop, String> loopLabels, HashMap<String, Integer> registerVars, boolean inFunction, boolean inMethod, int forInLevel, List<AssignableAVM2Item> variables) throws IOException, AVM2ParseException {
|
||||
GraphTargetItem cmd = null;
|
||||
List<GraphTargetItem> expr = new ArrayList<>();
|
||||
ParsedSymbol s;
|
||||
do {
|
||||
cmd = command(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, loops, loopLabels, registerVars, inFunction, inMethod, forInLevel, false, variables);
|
||||
if (cmd != null) {
|
||||
expr.add(cmd);
|
||||
}
|
||||
s = lex();
|
||||
} while (s.type == SymbolType.COMMA && cmd != null);
|
||||
lexer.pushback(s);
|
||||
if (cmd == null) {
|
||||
expr.add(expression(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, true, variables));
|
||||
} else if (!cmd.hasReturnValue()) {
|
||||
throw new AVM2ParseException("Expression expected", lexer.yyline());
|
||||
}
|
||||
return new CommaExpressionItem(null, null, expr);
|
||||
}
|
||||
|
||||
private GraphTargetItem expression(List<List<NamespaceItem>> allOpenedNamespaces, TypeItem thisType, NamespaceItem pkg, Reference<Boolean> needsActivation, List<DottedChain> importedClasses, List<NamespaceItem> openedNamespaces, boolean allowEmpty, HashMap<String, Integer> registerVars, boolean inFunction, boolean inMethod, boolean allowRemainder, List<AssignableAVM2Item> variables) throws IOException, AVM2ParseException {
|
||||
GraphTargetItem prim = expressionPrimary(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, allowEmpty, registerVars, inFunction, inMethod, allowRemainder, variables);
|
||||
if (prim == null) {
|
||||
return null;
|
||||
|
||||
List<GraphTargetItem> commaItems = new ArrayList<>();
|
||||
ParsedSymbol symb;
|
||||
do {
|
||||
GraphTargetItem prim = expressionPrimary(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, allowEmpty, registerVars, inFunction, inMethod, allowRemainder, variables);
|
||||
if (prim == null) {
|
||||
return null;
|
||||
}
|
||||
GraphTargetItem item = expression1(allOpenedNamespaces, prim, GraphTargetItem.NOPRECEDENCE, thisType, pkg, needsActivation, importedClasses, openedNamespaces, allowEmpty, registerVars, inFunction, inMethod, allowRemainder, variables);
|
||||
commaItems.add(item);
|
||||
symb = lex();
|
||||
} while (symb != null && symb.type == SymbolType.COMMA);
|
||||
if (symb != null) {
|
||||
lexer.pushback(symb);
|
||||
}
|
||||
return expression1(allOpenedNamespaces, prim, GraphTargetItem.NOPRECEDENCE, thisType, pkg, needsActivation, importedClasses, openedNamespaces, allowEmpty, registerVars, inFunction, inMethod, allowRemainder, variables);
|
||||
if (commaItems.size() == 1) {
|
||||
return commaItems.get(0);
|
||||
}
|
||||
return new CommaExpressionItem(null, null, commaItems);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1065,7 +1065,7 @@ public class ActionScript2Parser {
|
||||
case WHILE:
|
||||
expectedType(SymbolType.PARENT_OPEN);
|
||||
List<GraphTargetItem> whileExpr = new ArrayList<>();
|
||||
whileExpr.add(commaExpression(inFunction, inMethod, forinlevel, variables, functions));
|
||||
whileExpr.add(expression(inFunction, inMethod, true, variables, functions));
|
||||
expectedType(SymbolType.PARENT_CLOSE);
|
||||
List<GraphTargetItem> whileBody = new ArrayList<>();
|
||||
whileBody.add(command(inFunction, inMethod, forinlevel, true, variables, functions));
|
||||
@@ -1077,7 +1077,7 @@ public class ActionScript2Parser {
|
||||
expectedType(SymbolType.WHILE);
|
||||
expectedType(SymbolType.PARENT_OPEN);
|
||||
List<GraphTargetItem> doExpr = new ArrayList<>();
|
||||
doExpr.add(commaExpression(inFunction, inMethod, forinlevel, variables, functions));
|
||||
doExpr.add(expression(inFunction, inMethod, true, variables, functions));
|
||||
expectedType(SymbolType.PARENT_CLOSE);
|
||||
ret = new DoWhileItem(null, null, null, doBody, doExpr);
|
||||
break;
|
||||
@@ -1314,15 +1314,27 @@ public class ActionScript2Parser {
|
||||
if (debugMode) {
|
||||
System.out.println("expression:");
|
||||
}
|
||||
GraphTargetItem prim = expressionPrimary(false, inFunction, inMethod, allowRemainder, variables, functions);
|
||||
if (prim == null) {
|
||||
return null;
|
||||
List<GraphTargetItem> commaItems = new ArrayList<>();
|
||||
ParsedSymbol symb;
|
||||
do {
|
||||
GraphTargetItem prim = expressionPrimary(false, inFunction, inMethod, allowRemainder, variables, functions);
|
||||
if (prim == null) {
|
||||
return null;
|
||||
}
|
||||
GraphTargetItem expr = expression1(prim, GraphTargetItem.NOPRECEDENCE, inFunction, inMethod, allowRemainder, variables, functions);
|
||||
commaItems.add(expr);
|
||||
symb = lex();
|
||||
} while (symb != null && symb.type == SymbolType.COMMA);
|
||||
if (symb != null) {
|
||||
lexer.pushback(symb);
|
||||
}
|
||||
GraphTargetItem ret = expression1(prim, GraphTargetItem.NOPRECEDENCE, inFunction, inMethod, allowRemainder, variables, functions);
|
||||
if (debugMode) {
|
||||
System.out.println("/expression");
|
||||
}
|
||||
return ret;
|
||||
if (commaItems.size() == 1) {
|
||||
return commaItems.get(0);
|
||||
}
|
||||
return new CommaExpressionItem(null, null, commaItems);
|
||||
}
|
||||
|
||||
private ParsedSymbol peekLex() throws IOException, ActionParseException {
|
||||
@@ -1627,26 +1639,6 @@ public class ActionScript2Parser {
|
||||
return arrCnt;
|
||||
}
|
||||
|
||||
private GraphTargetItem commaExpression(boolean inFunction, boolean inMethod, int forInLevel, List<VariableActionItem> variables, List<FunctionActionItem> functions) throws IOException, ActionParseException {
|
||||
GraphTargetItem cmd = null;
|
||||
List<GraphTargetItem> expr = new ArrayList<>();
|
||||
ParsedSymbol s;
|
||||
do {
|
||||
cmd = command(inFunction, inMethod, forInLevel, false, variables, functions);
|
||||
if (cmd != null) {
|
||||
expr.add(cmd);
|
||||
}
|
||||
s = lex();
|
||||
} while (s.type == SymbolType.COMMA && cmd != null);
|
||||
lexer.pushback(s);
|
||||
if (cmd == null) {
|
||||
expr.add(expression(inFunction, inMethod, true, variables, functions));
|
||||
} else if (!cmd.hasReturnValue()) {
|
||||
throw new ActionParseException("Expression expected", lexer.yyline());
|
||||
}
|
||||
return new CommaExpressionItem(null, null, expr);
|
||||
}
|
||||
|
||||
private GraphTargetItem expressionPrimary(boolean allowEmpty, boolean inFunction, boolean inMethod, boolean allowRemainder, List<VariableActionItem> variables, List<FunctionActionItem> functions) throws IOException, ActionParseException {
|
||||
if (debugMode) {
|
||||
System.out.println("primary:");
|
||||
|
||||
@@ -792,7 +792,7 @@ public class ActionSourceGenerator implements SourceGenerator {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<GraphSourceItem> generate(SourceGeneratorLocalData localData, CommaExpressionItem item) throws CompilationException {
|
||||
public List<GraphSourceItem> generate(SourceGeneratorLocalData localData, CommaExpressionItem item, boolean withReturnValue) throws CompilationException {
|
||||
if (item.commands.isEmpty()) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
@@ -802,7 +802,7 @@ public class ActionSourceGenerator implements SourceGenerator {
|
||||
GraphTargetItem lastExpr = cmds.remove(cmds.size() - 1);
|
||||
List<GraphSourceItem> ret = new ArrayList<>();
|
||||
ret.addAll(generate(localData, cmds));
|
||||
ret.addAll(lastExpr.toSource(localData, this));
|
||||
ret.addAll(withReturnValue ? lastExpr.toSource(localData, this) : lastExpr.toSourceIgnoreReturnValue(localData, this));
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
@@ -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.graph;
|
||||
|
||||
import com.jpexs.decompiler.flash.SourceGeneratorLocalData;
|
||||
@@ -75,7 +76,7 @@ public interface SourceGenerator {
|
||||
|
||||
public List<GraphSourceItem> generate(SourceGeneratorLocalData localData, List<GraphTargetItem> commands) throws CompilationException;
|
||||
|
||||
|
||||
public List<GraphSourceItem> generate(SourceGeneratorLocalData localData, CommaExpressionItem item, boolean withReturnValue) throws CompilationException;
|
||||
|
||||
public List<GraphSourceItem> generate(SourceGeneratorLocalData localData, TypeItem item) throws CompilationException;
|
||||
|
||||
|
||||
@@ -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.graph.model;
|
||||
|
||||
import com.jpexs.decompiler.flash.SourceGeneratorLocalData;
|
||||
@@ -58,9 +59,15 @@ public class CommaExpressionItem extends GraphTargetItem {
|
||||
|
||||
@Override
|
||||
public List<GraphSourceItem> toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException {
|
||||
public List<GraphSourceItem> toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException {
|
||||
return generator.generate(localData, this, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<GraphSourceItem> toSourceIgnoreReturnValue(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException {
|
||||
return generator.generate(localData, this, false);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean hasReturnValue() {
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user