private boolean tryJavaInvocation(FunctionCall node) throws IOException { if (!(node.getTarget() instanceof PropertyGet)) { return false; } PropertyGet propertyGet = (PropertyGet) node.getTarget(); String callMethod = getJavaMethod(propertyGet.getTarget()); if (callMethod == null || !propertyGet.getProperty().getIdentifier().equals("invoke")) { return false; } MethodReference method = MethodReference.parseIfPossible(callMethod); if (method == null) { return false; } writer.appendMethodBody(method).append('('); printList(node.getArguments()); writer.append(')'); return true; }
consumeToken(); checkCallRequiresActivation(pn); FunctionCall f = new FunctionCall(pos); f.setTarget(pn); f.setLineno(lineno); f.setLp(ts.tokenBeg - pos); List<AstNode> args = argumentList(); if (args != null && args.size() > ARGC_LIMIT) reportError("msg.too.many.function.args"); f.setArguments(args); f.setRp(ts.tokenBeg - pos); f.setLength(ts.tokenEnd - pos); pn = f; break;
private Node transformFunctionCall(FunctionCall node) { Node call = createCallOrNew(Token.CALL, transform(node.getTarget())); call.setLineno(node.getLineno()); decompiler.addToken(Token.LP); List<AstNode> args = node.getArguments(); for (int i = 0; i < args.size(); i++) { AstNode arg = args.get(i); call.addChildToBack(transform(arg)); if (i < args.size() - 1) { decompiler.addToken(Token.COMMA); } } decompiler.addToken(Token.RP); return call; }
public int getNumArguments() { return node.getArguments().size(); }
private static Node getCallTarget(FunctionCall n) { return n.getTarget(); } /**
@Override public String toSource(int depth) { StringBuilder sb = new StringBuilder(); sb.append(makeIndent(depth)); sb.append(target.toSource(0)); sb.append("("); if (arguments != null) { printList(arguments, sb); } sb.append(")"); return sb.toString(); }
/** * Sets node evaluating to the function to call, and sets * its parent to this node. * @param target node evaluating to the function to call. * @throws IllegalArgumentException} if target is {@code null} */ public void setTarget(AstNode target) { assertNotNull(target); this.target = target; target.setParent(this); }
/** * Sets function argument list * @param arguments function argument list. Can be {@code null}, * in which case any existing args are removed. */ public void setArguments(List<AstNode> arguments) { if (arguments == null) { this.arguments = null; } else { if (this.arguments != null) this.arguments.clear(); for (AstNode arg : arguments) { addArgument(arg); } } }
consumeToken(); checkCallRequiresActivation(pn); FunctionCall f = new FunctionCall(pos); f.setTarget(pn); f.setLineno(lineno); f.setLp(ts.tokenBeg - pos); List<AstNode> args = argumentList(); if (args != null && args.size() > ARGC_LIMIT) reportError("msg.too.many.function.args"); f.setArguments(args); f.setRp(ts.tokenBeg - pos); f.setLength(ts.tokenEnd - pos); pn = f; break;
private Node transformFunctionCall(FunctionCall node) { Node call = createCallOrNew(Token.CALL, transform(node.getTarget())); call.setLineno(node.getLineno()); decompiler.addToken(Token.LP); List<AstNode> args = node.getArguments(); for (int i = 0; i < args.size(); i++) { AstNode arg = args.get(i); call.addChildToBack(transform(arg)); if (i < args.size() - 1) { decompiler.addToken(Token.COMMA); } } decompiler.addToken(Token.RP); return call; }
private CAstNode[] gatherCallArguments(Node call, WalkContext context) { List<AstNode> nodes = ((FunctionCall)call).getArguments(); CAstNode[] args = new CAstNode[ nodes.size() ]; for(int i = 0; i < nodes.size(); i++) { args[i] = visit(nodes.get(i), context); } return args; }
public boolean visit(AstNode node) { if (node instanceof FunctionCall) { FunctionCall call = (FunctionCall) node; node = call.getTarget(); if (node instanceof Name) { Name name = (Name) node; if (funcName.equals(name.toSource())) { target.set(call); return false; } } } return true; } });
@Override public String toSource(int depth) { StringBuilder sb = new StringBuilder(); sb.append(makeIndent(depth)); sb.append(target.toSource(0)); sb.append("("); if (arguments != null) { printList(arguments, sb); } sb.append(")"); return sb.toString(); }
/** * Sets node evaluating to the function to call, and sets * its parent to this node. * @param target node evaluating to the function to call. * @throws IllegalArgumentException} if target is {@code null} */ public void setTarget(AstNode target) { assertNotNull(target); this.target = target; target.setParent(this); }
/** * Sets function argument list * @param arguments function argument list. Can be {@code null}, * in which case any existing args are removed. */ public void setArguments(List<AstNode> arguments) { if (arguments == null) { this.arguments = null; } else { if (this.arguments != null) this.arguments.clear(); for (AstNode arg : arguments) { addArgument(arg); } } }
private void print(FunctionCall node, int precedence) throws IOException { if (tryJavaInvocation(node)) { return; } if (precedence < PRECEDENCE_FUNCTION) { writer.append('('); } int innerPrecedence = node instanceof NewExpression ? PRECEDENCE_FUNCTION - 1 : PRECEDENCE_FUNCTION; if (node instanceof NewExpression) { writer.append("new "); } print(node.getTarget(), innerPrecedence); writer.append('('); printList(node.getArguments()); writer.append(')'); if (node instanceof NewExpression) { NewExpression newExpr = (NewExpression) node; if (newExpr.getInitializer() != null) { writer.ws(); print(newExpr.getInitializer()); } } if (precedence < PRECEDENCE_FUNCTION) { writer.append(')'); } }
consumeToken(); checkCallRequiresActivation(pn); FunctionCall f = new FunctionCall(pos); f.setTarget(pn); f.setLineno(lineno); f.setLp(ts.tokenBeg - pos); List<AstNode> args = argumentList(); if (args != null && args.size() > ARGC_LIMIT) reportError("msg.too.many.function.args"); f.setArguments(args); f.setRp(ts.tokenBeg - pos); f.setLength(ts.tokenEnd - pos); pn = f; break;
private Node transformFunctionCall(FunctionCall node) { Node call = createCallOrNew(Token.CALL, transform(node.getTarget())); call.setLineno(node.getLineno()); decompiler.addToken(Token.LP); List<AstNode> args = node.getArguments(); for (int i = 0; i < args.size(); i++) { AstNode arg = args.get(i); call.addChildToBack(transform(arg)); if (i < args.size() - 1) { decompiler.addToken(Token.COMMA); } } decompiler.addToken(Token.RP); return call; }
/** * Get all nodes within AstNode and add to an ArrayList * * @param node */ private void collectAllNodes(AstNode node) { if (node.getType() == Token.CALL) { // collect all argument nodes FunctionCall call = (FunctionCall) node; Iterator<AstNode> args = call.getArguments().iterator(); while (args.hasNext()) { AstNode arg = args.next(); VisitorAll all = new VisitorAll(); arg.visit(all); paramNodes.addAll(all.getAllNodes()); } } }
@Override public CAstNode visitFunctionCall(FunctionCall n, WalkContext context) { if (!isPrimitiveCall(context, n)) { AstNode callee = n.getTarget(); int thisBaseVarNum = ++tempVarNum; WalkContext child = new MemberDestructuringContext(context, callee, thisBaseVarNum);