List of usage examples for jdk.nashorn.internal.ir.debug ASTWriter ASTWriter
public ASTWriter(final Node root)
From source file:edu.brown.cs.bubbles.nobase.NobaseNashorn.java
License:Open Source License
/********************************************************************************/ @Override/* w w w . j ava 2s. c o m*/ public ISemanticData parse(NobaseProject proj, NobaseFile fd, boolean lib) { Source src = new Source(fd.getFileName(), fd.getContents()); Options opts = new Options("nashorn"); PrintWriter pw = new PrintWriter(new StringWriter()); ScriptEnvironment env = new ScriptEnvironment(opts, pw, pw); DeferredErrorManager em = new DeferredErrorManager(fd); if (fd.getFileName().endsWith(".json")) { JSONParser jsonparse = new JSONParser(src, em); Node nd = jsonparse.parse(); if (do_debug) { System.err.println("WORKING ON " + fd.getFileName()); try { ASTWriter pv = new ASTWriter(nd); System.err.println("PARSE: " + pv.toString()); } catch (Throwable t) { } } return null; } Parser parser = new Parser(env, src, em); FunctionNode fn = parser.parse(); if (fn == null) { NobaseMain.logE("Problem parsing " + fd.getFileName()); return null; } if (do_debug) { System.err.println("WORKING ON " + fd.getFileName()); try { ASTWriter pv = new ASTWriter(fn); System.err.println("PARSE: " + pv.toString()); } catch (Throwable t) { } } ParseData rslt = new ParseData(proj, fd, em, fn.getBody(), lib); if (do_debug) { System.err.println("RESULT: " + rslt.getRootNode().dumpTree(fd)); } return rslt; }
From source file:org.kihara.util.JavascriptEngine.java
License:Open Source License
/** * Compiles the given script files in the command line * * @param context the nashorn context//w w w. j a va 2 s . c o m * @param global the global scope * @param files the list of script files to compile * * @return error code * @throws IOException when any script file read results in I/O error */ private static int compileScripts(final Context context, final ScriptObject global, final List<String> files) throws IOException { final ScriptObject oldGlobal = Context.getGlobal(); final boolean globalChanged = (oldGlobal != global); final ScriptEnvironment env = context.getEnv(); try { if (globalChanged) { Context.setGlobal(global); } final ErrorManager errors = context.getErrorManager(); // For each file on the command line. for (final String fileName : files) { final FunctionNode functionNode = new Parser(env, Source.sourceFor(fileName, new File(fileName)), errors, env._strict, 0, context.getLogger(Parser.class)).parse(); if (errors.getNumberOfErrors() != 0) { return COMPILATION_ERROR; } new Compiler(context, env, null, //null - pass no code installer - this is compile only functionNode.getSource(), context.getErrorManager(), env._strict | functionNode.isStrict()) .compile(functionNode, Compiler.CompilationPhases.COMPILE_ALL_NO_INSTALL); //*/ /* Compiler.forNoInstallerCompilation(context, functionNode.getSource(), env._strict | functionNode.isStrict()). compile(functionNode, Compiler.CompilationPhases.COMPILE_ALL_NO_INSTALL); //*/ if (env._print_ast) { context.getErr().println(new ASTWriter(functionNode)); } if (env._print_parse) { context.getErr().println(new PrintVisitor(functionNode)); } if (errors.getNumberOfErrors() != 0) { return COMPILATION_ERROR; } } } finally { env.getOut().flush(); env.getErr().flush(); if (globalChanged) { Context.setGlobal(oldGlobal); } } return SUCCESS; }