| 7 | import unluac.decompile.Walker; |
| 8 | |
| 9 | public class FunctionCall extends Expression { |
| 10 | |
| 11 | private final Expression function; |
| 12 | private final Expression[] arguments; |
| 13 | private final boolean multiple; |
| 14 | |
| 15 | public FunctionCall(Expression function, Expression[] arguments, boolean multiple) { |
| 16 | super(PRECEDENCE_ATOMIC); |
| 17 | this.function = function; |
| 18 | this.arguments = arguments; |
| 19 | this.multiple = multiple; |
| 20 | } |
| 21 | |
| 22 | @Override |
| 23 | public void walk(Walker w) { |
| 24 | w.visitExpression(this); |
| 25 | function.walk(w); |
| 26 | for(Expression expression : arguments) { |
| 27 | expression.walk(w); |
| 28 | } |
| 29 | } |
| 30 | |
| 31 | @Override |
| 32 | public int getConstantIndex() { |
| 33 | int index = function.getConstantIndex(); |
| 34 | for(Expression argument : arguments) { |
| 35 | index = Math.max(argument.getConstantIndex(), index); |
| 36 | } |
| 37 | return index; |
| 38 | } |
| 39 | |
| 40 | @Override |
| 41 | public boolean isMultiple() { |
| 42 | return multiple; |
| 43 | } |
| 44 | |
| 45 | @Override |
| 46 | public void printMultiple(Decompiler d, Output out) { |
| 47 | if(!multiple) { |
| 48 | out.print("("); |
| 49 | } |
| 50 | print(d, out); |
| 51 | if(!multiple) { |
| 52 | out.print(")"); |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | private boolean isMethodCall() { |
| 57 | return function.isMemberAccess() && arguments.length > 0 && function.getTable() == arguments[0]; |
| 58 | } |
| 59 | |
| 60 | @Override |
| 61 | public boolean beginsWithParen() { |
| 62 | if(isMethodCall()) { |
| 63 | Expression obj = function.getTable(); |
| 64 | return obj.isUngrouped() || obj.beginsWithParen(); |
| 65 | } else { |
| 66 | return function.isUngrouped() || function.beginsWithParen(); |
nothing calls this directly
no outgoing calls
no test coverage detected