Refine search
private void print(FunctionNode node) throws IOException { if (!node.isMethod()) { writer.append("function"); } if (node.getFunctionName() != null) { writer.append(' '); print(node.getFunctionName()); } writer.append('('); printList(node.getParams()); writer.append(')').ws(); if (node.isExpressionClosure()) { if (node.getBody().getLastChild() instanceof ReturnStatement) { print(((ReturnStatement) node.getBody().getLastChild()).getReturnValue()); if (node.getFunctionType() == FunctionNode.FUNCTION_STATEMENT) { writer.append(";"); } } } else { print(node.getBody()); } }
public ASTFunctionNode(FunctionNode functionNode) { super(functionNode); super.setImage(functionNode.getName()); }
if (compilerEnv.isAllowMemberExprAsFunctionName()) { && name != null && name.length() > 0) { FunctionNode fnNode = new FunctionNode(functionSourceStart, name); fnNode.setFunctionType(type); if (lpPos != -1) fnNode.setLp(lpPos - functionSourceStart); fnNode.setJsDocNode(getAndResetJsDoc()); fnNode.setBody(parseFunctionBody()); fnNode.setEncodedSourceBounds(functionSourceStart, ts.tokenEnd); fnNode.setLength(ts.tokenEnd - functionSourceStart); if (compilerEnv.isStrictMode() && !fnNode.getBody().hasConsistentReturnUsage()) { String msg = (name != null && name.length() > 0) ? "msg.no.return.value" fnNode.setMemberExprNode(memberExprNode); // rewrite later fnNode.setSourceName(sourceURI); fnNode.setBaseLineno(baseLineno); fnNode.setEndLineno(ts.lineno); if (compilerEnv.isIdeMode()) { fnNode.setParentScope(currentScope);
private Node initFunction(FunctionNode fnNode, int functionIndex, Node statements, int functionType) { fnNode.setFunctionType(functionType); fnNode.addChildToBack(statements); int functionCount = fnNode.getFunctionCount(); if (functionCount != 0) { fnNode.setRequiresActivation(); Name name = fnNode.getFunctionName(); if (name != null && name.length() != 0 && fnNode.getSymbol(name.getIdentifier()) == null) { fnNode.putSymbol(new Symbol(Token.FUNCTION, name.getIdentifier())); Node setFn = new Node(Token.EXPR_VOID, new Node(Token.SETNAME, Node result = Node.newString(Token.FUNCTION, fnNode.getName()); result.putIntProp(Node.FUNCTION_PROP, functionIndex); return result;
private Node transformGenExpr(GeneratorExpression node) { Node pn; FunctionNode fn = new FunctionNode(); fn.setSourceName(currentScriptOrFn.getNextTempName()); fn.setIsGenerator(); fn.setFunctionType(FunctionNode.FUNCTION_EXPRESSION); fn.setRequiresActivation(); int functionType = fn.getFunctionType(); int start = decompiler.markFunctionStart(functionType); Node mexpr = decompileFunctionHeader(fn); Node destructuring = (Node)fn.getProp(Node.DESTRUCTURING_PARAMS); fn.removeProp(Node.DESTRUCTURING_PARAMS); if (!fn.isExpressionClosure()) { decompiler.addToken(Token.RC); fn.setEncodedSourceBounds(start, decompiler.markFunctionEnd(start)); if (functionType != FunctionNode.FUNCTION_EXPRESSION && !fn.isExpressionClosure()) { int syntheticType = fn.getFunctionType(); pn = initFunction(fn, index, body, syntheticType); if (mexpr != null) { pn = createAssignment(Token.ASSIGN, mexpr, pn); if (syntheticType != FunctionNode.FUNCTION_EXPRESSION) { pn = createExprStatementNoReturn(pn, fn.getLineno());
private void generateFunctionICode() { itsInFunctionFlag = true; FunctionNode theFunction = (FunctionNode)scriptOrFn; itsData.itsFunctionType = theFunction.getFunctionType(); itsData.itsNeedsActivation = theFunction.requiresActivation(); if (theFunction.getFunctionName() != null) { itsData.itsName = theFunction.getName(); } if (theFunction.isGenerator()) { addIcode(Icode_GENERATOR); addUint16(theFunction.getBaseLineno() & 0xFFFF); } generateICodeFromTree(theFunction.getLastChild()); }
private Node transformFunction(FunctionNode fn) { int functionType = fn.getFunctionType(); int start = decompiler.markFunctionStart(functionType); Node mexpr = decompileFunctionHeader(fn); Node destructuring = (Node)fn.getProp(Node.DESTRUCTURING_PARAMS); fn.removeProp(Node.DESTRUCTURING_PARAMS); int lineno = fn.getBody().getLineno(); Node body = transform(fn.getBody()); if (!fn.isExpressionClosure()) { decompiler.addToken(Token.RC); fn.setEncodedSourceBounds(start, decompiler.markFunctionEnd(start)); if (functionType != FunctionNode.FUNCTION_EXPRESSION && !fn.isExpressionClosure()) { int syntheticType = fn.getFunctionType(); Node pn = initFunction(fn, index, body, syntheticType); if (mexpr != null) { pn = createAssignment(Token.ASSIGN, mexpr, pn); if (syntheticType != FunctionNode.FUNCTION_EXPRESSION) { pn = createExprStatementNoReturn(pn, fn.getLineno());
Node decompileFunctionHeader(FunctionNode fn) { Node mexpr = null; if (fn.getFunctionName() != null) { decompiler.addName(fn.getName()); } else if (fn.getMemberExprNode() != null) { mexpr = transform(fn.getMemberExprNode()); } decompiler.addToken(Token.LP); List<AstNode> params = fn.getParams(); for (int i = 0; i < params.size(); i++) { decompile(params.get(i)); if (i < params.size() - 1) { decompiler.addToken(Token.COMMA); } } decompiler.addToken(Token.RP); if (!fn.isExpressionClosure()) { decompiler.addEOL(Token.LC); } return mexpr; }
List<Node> targets = ((FunctionNode)scriptOrFn).getResumptionPoints(); if (targets != null) { if (compilerEnv.isGenerateObserverCount()) saveCurrentCodeOffset(); int paramCount = fnCurrent.fnode.getParamCount(); int varCount = fnCurrent.fnode.getParamAndVarCount(); boolean [] constDeclarations = fnCurrent.fnode.getParamAndVarConst(); if (compilerEnv.isGenerateDebugInfo()) { String name = fnCurrent.fnode.getParamOrVarName(i); String type = fnCurrent.isNumberVar(i) ? "D" : "Ljava/lang/Object;"; if (compilerEnv.isGenerateDebugInfo()) { cfw.addVariableDescriptor(debugVariableName, "Lorg/mozilla/javascript/Scriptable;",
CompilerEnvirons env = new CompilerEnvirons(); env.setRecoverFromErrors(true); env.setLanguageVersion(Context.VERSION_1_8); env.setIdeMode(true); JSParser parser = new JSParser(env, errorReporter); throw new RuntimeException("IO Error occurred", e); AstNode body = ((FunctionNode) rootNode.getFirstChild()).getBody();
@Override public String toSource(int depth) { StringBuilder sb = new StringBuilder(); if (!isMethod()) { sb.append(makeIndent(depth)); sb.append("function"); sb.append(functionName.toSource(0)); } else { sb.append("("); printList(params, sb); sb.append(") "); AstNode body = getBody(); if (body.getLastChild() instanceof ReturnStatement) { sb.append(getBody().toSource(depth).trim()); if (functionType == FUNCTION_STATEMENT || isMethod()) { sb.append("\n");
Set<Completion> set, String entered, int offset) { FunctionNode fn = (FunctionNode) child; String jsdoc = fn.getJsDoc(); TypeDeclaration returnType = getFunctionType(fn); JavaScriptInScriptFunctionCompletion fc = new JavaScriptInScriptFunctionCompletion( provider, fn.getName(), returnType); fc.setShortDescription(jsdoc); offset = fn.getAbsolutePosition() + fn.getLength(); if (fn.getParamCount() > 0) { List<AstNode> fnParams = fn.getParams(); List<Parameter> params = new ArrayList<Parameter>(); for (int i = 0; i < fn.getParamCount(); i++) { String paramName = null; AstNode node = fnParams.get(i); switch (node.getType()) { case Token.NAME: paramName = ((Name) node).getIdentifier(); break; default: addCodeBlock(fn.getBody(), set, entered, block, offset);
/** * Gets a Java-compatible "informative" name for the the ScriptOrFnNode */ String cleanName(final ScriptNode n) { String result = ""; if (n instanceof FunctionNode) { Name name = ((FunctionNode) n).getFunctionName(); if (name == null) { result = "anonymous"; } else { result = name.getIdentifier(); } } else { result = "script"; } return result; }
/** * Visits this node, the function name node if supplied, * the parameters, and the body. If there is a member-expr node, * it is visited last. */ @Override public void visit(NodeVisitor v) { if (v.visit(this)) { if (functionName != null) { functionName.visit(v); } for (AstNode param : getParams()) { param.visit(v); } getBody().visit(v); if (!isExpressionClosure) { if (memberExprNode != null) { memberExprNode.visit(v); } } } } }
WalkContext child = new FunctionContext(context, fn); List<CAstNode> body = new ArrayList<>(); body.add(visit(fn.getBody(), child)); Name x = fn.getFunctionName(); if (x == null || x.getIdentifier() == null || x.getIdentifier().isEmpty()) { name = scriptName + '@' + fn.getAbsolutePosition(); String label = getParentName(fn); if (label != null) { name = fn.getFunctionName().getIdentifier(); System.err.println(fne.getName()); if (fn.getFunctionType() == FunctionNode.FUNCTION_EXPRESSION) { CAstNode fun = Ast.makeNode(CAstNode.FUNCTION_EXPR, Ast.makeConstant(fne));
int optLevel = compilerEnv.getOptimizationLevel(); for (int i = 0; i != functionCount; ++i) { OptFunctionNode ofn = OptFunctionNode.get(tree, i); if (ofn.fnode.getFunctionType() == FunctionNode.FUNCTION_STATEMENT) String name = ofn.fnode.getName(); if (name.length() != 0) { if (possibleDirectCalls == null) {
cfw.addPush(compilerEnv.getLanguageVersion()); cfw.add(ByteCode.IRETURN); cfw.addPush(""); } else { String name = ((FunctionNode)n).getName(); cfw.addPush(name);
namePosition = makePosition(f.getFunctionName()); f.flattenSymbolTable(false); int i = 0; arguments = new String[f.getParamCount() + 2]; arguments[i++] = name; arguments[i++] = "this"; for (int j = 0; j < f.getParamCount(); j++) { arguments[i++] = f.getParamOrVarName(j); List<AstNode> params = f.getParams(); paramPositions = new Position[ params.size() ]; for(int pi = 0; pi < params.size(); pi++) {
int paramCount = fn.getParamCount(); if (paramCount>0) { List<AstNode> fnParams = fn.getParams(); for (int i=0; i<paramCount; i++) { String paramName = null; switch (paramNode.getType()) { case Token.NAME: paramName = ((Name)paramNode).getIdentifier(); break; default:
/** * Visits a function AST node. This will create a tree node for the * function, and also visit the AST nodes in the function's body, to * identify local variables, nested functions, etc. * * @param fn The function node. * @return <code>false</code> always, as this method manually visits * the function AST node's child nodes. */ private boolean visitFunction(FunctionNode fn) { Name funcName = fn.getFunctionName(); // Happens with certain syntax errors, such as // "function function foo() {". if (funcName!=null) { String text = fn.getName() + RhinoUtil.getFunctionArgsString(fn); JavaScriptTreeNode tn = createTreeNode(funcName); tn.setText(text); tn.setIcon(IconFactory.getIcon(IconFactory.DEFAULT_FUNCTION_ICON)); tn.setSortPriority(JavaScriptOutlineTree.PRIORITY_FUNCTION); curScopeTreeNode.add(tn); curScopeTreeNode = tn; fn.getBody().visit(this); curScopeTreeNode = (JavaScriptTreeNode)curScopeTreeNode.getParent(); } // Never visit children; we do this manually so we know when scope ends return false; }