diff --git a/src/org/rascalmpl/interpreter/Evaluator.java b/src/org/rascalmpl/interpreter/Evaluator.java index 99836be3f70..a5f3b47e213 100755 --- a/src/org/rascalmpl/interpreter/Evaluator.java +++ b/src/org/rascalmpl/interpreter/Evaluator.java @@ -1373,14 +1373,14 @@ private char[] getResourceContent(ISourceLocation location) throws IOException{ * effect of declaring non-terminal types in the given environment. */ @Override - public ITree parseModuleAndFragments(IRascalMonitor monitor, ISourceLocation location) throws IOException{ - return parseModuleAndFragments(monitor, getResourceContent(location), location); + public ITree parseModuleAndFragments(IRascalMonitor monitor, ISourceLocation location, String jobName) throws IOException{ + return parseModuleAndFragments(monitor, jobName, getResourceContent(location), location); } - public ITree parseModuleAndFragments(IRascalMonitor monitor, char[] data, ISourceLocation location){ + public ITree parseModuleAndFragments(IRascalMonitor monitor, String jobName, char[] data, ISourceLocation location){ IRascalMonitor old = setMonitor(monitor); try { - return org.rascalmpl.semantics.dynamic.Import.parseModuleAndFragments(data, location, this); + return org.rascalmpl.semantics.dynamic.Import.parseModuleAndFragments(data, location, jobName, this); } finally{ setMonitor(old); diff --git a/src/org/rascalmpl/interpreter/IEvaluator.java b/src/org/rascalmpl/interpreter/IEvaluator.java index fea8f7a17f0..e8a1dde6abf 100644 --- a/src/org/rascalmpl/interpreter/IEvaluator.java +++ b/src/org/rascalmpl/interpreter/IEvaluator.java @@ -118,7 +118,7 @@ public interface IEvaluator extends IEvaluatorContext { public ITree parseCommand(IRascalMonitor monitor, String command, ISourceLocation location); - public ITree parseModuleAndFragments(IRascalMonitor monitor, ISourceLocation location) throws IOException; + public ITree parseModuleAndFragments(IRascalMonitor monitor, ISourceLocation location, String jobName) throws IOException; public void registerConstructorDeclaredListener(IConstructorDeclared iml); diff --git a/src/org/rascalmpl/repl/TerminalProgressBarMonitor.java b/src/org/rascalmpl/repl/TerminalProgressBarMonitor.java index 5c120d06f25..f771d6a516e 100644 --- a/src/org/rascalmpl/repl/TerminalProgressBarMonitor.java +++ b/src/org/rascalmpl/repl/TerminalProgressBarMonitor.java @@ -104,6 +104,7 @@ void update() { write(); writer.write(ANSI.moveDown(bars.size() - bars.indexOf(this))); writer.write(ANSI.showCursor()); + writer.flush(); } } @@ -297,7 +298,7 @@ public synchronized void jobStep(String name, String message, int workShare) { public synchronized int jobEnd(String name, boolean succeeded) { var pb = findBarByName(name); - if (pb != null && --pb.nesting == 0) { + if (pb != null && --pb.nesting == -1) { eraseBars(); // write it one last time into the scrollback buffer (on top) pb.done(); @@ -307,6 +308,10 @@ public synchronized int jobEnd(String name, boolean succeeded) { printBars(); return pb.current; } + else if (pb != null) { + pb.done(); + pb.update(); + } return -1; } diff --git a/src/org/rascalmpl/semantics/dynamic/Import.java b/src/org/rascalmpl/semantics/dynamic/Import.java index 0e741910482..15e91f8fae6 100644 --- a/src/org/rascalmpl/semantics/dynamic/Import.java +++ b/src/org/rascalmpl/semantics/dynamic/Import.java @@ -293,64 +293,64 @@ else if (eval.getCurrentEnvt() == eval.__getRootScope()) { public static ModuleEnvironment loadModule(ISourceLocation x, String name, IEvaluator> eval) { GlobalEnvironment heap = eval.getHeap(); - - ModuleEnvironment env = heap.getModule(name); - if (env == null) { - env = new ModuleEnvironment(name, heap); - heap.addModule(env); + ModuleEnvironment m = heap.getModule(name); + if (m == null) { + m = new ModuleEnvironment(name, heap); + heap.addModule(m); } + final ModuleEnvironment env = m; ISourceLocation uri = eval.getRascalResolver().resolveModule(name); - try { - eval.getMonitor().jobStart("loading", 1); + eval.job("loading " + name, 1, (jobName) -> { + try { + if (uri == null) { + throw new ModuleImport(name, "can not find in search path", x); + } + Module module = buildModule(uri, env, eval, jobName); - if (uri == null) { - throw new ModuleImport(name, "can not find in search path", x); - } - Module module = buildModule(uri, env, eval); + if (isDeprecated(module)) { + eval.getErrorPrinter().println("WARNING: deprecated module " + name + ":" + getDeprecatedMessage(module)); + } - if (isDeprecated(module)) { - eval.getErrorPrinter().println("WARNING: deprecated module " + name + ":" + getDeprecatedMessage(module)); - } + if (module != null) { + String internalName = org.rascalmpl.semantics.dynamic.Module.getModuleName(module); + if (!internalName.equals(name)) { + throw new ModuleNameMismatch(internalName, name, x); + } + heap.setModuleURI(name, module.getLocation().getURI()); - if (module != null) { - String internalName = org.rascalmpl.semantics.dynamic.Module.getModuleName(module); - if (!internalName.equals(name)) { - throw new ModuleNameMismatch(internalName, name, x); - } - heap.setModuleURI(name, module.getLocation().getURI()); + module.interpret(eval); - module.interpret(eval); + eval.jobStep(jobName, "loaded " + URIUtil.getLocationName(uri), 1); + } - eval.jobStep("loading", "loaded " + URIUtil.getLocationName(uri), 1); - return env; - } - } - catch (SyntaxError e) { - handleLoadError(heap, env, eval, name, e.getMessage(), e.getLocation(), x); - throw e; - } - catch (StaticError e) { - handleLoadError(heap, env, eval, name, e.getMessage(), e.getLocation(), x); - throw e; - } - catch (Throw e) { - handleLoadError(heap, env, eval, name, e.getMessage(), e.getLocation(), x); - throw e; - } - catch (Throwable e) { - handleLoadError(heap, env, eval, name, e.getMessage(), x, x); - e.printStackTrace(); - throw new ModuleImport(name, e.getMessage(), x); - } - finally { - eval.jobEnd("loading", true); - } + return true; + } + catch (SyntaxError e) { + handleLoadError(heap, env, eval, name, e.getMessage(), e.getLocation(), x); + throw e; + } + catch (StaticError e) { + handleLoadError(heap, env, eval, name, e.getMessage(), e.getLocation(), x); + throw e; + } + catch (Throw e) { + handleLoadError(heap, env, eval, name, e.getMessage(), e.getLocation(), x); + throw e; + } + catch (Throwable e) { + handleLoadError(heap, env, eval, name, e.getMessage(), x, x); + e.printStackTrace(); + throw new ModuleImport(name, e.getMessage(), x); + } + finally { + eval.jobStep(jobName, name); + } + }); - heap.removeModule(env); - throw new ImplementationError("Unexpected error while parsing module " + name + " and building an AST for it ", x); + return env; } private static void handleLoadError(GlobalEnvironment heap, ModuleEnvironment env, IEvaluator> eval, @@ -379,8 +379,8 @@ private static String getDeprecatedMessage(Module preModule){ return ""; } - private static Module buildModule(ISourceLocation uri, ModuleEnvironment env, IEvaluator> eval) throws IOException { - ITree tree = eval.parseModuleAndFragments(eval, uri); + private static Module buildModule(ISourceLocation uri, ModuleEnvironment env, IEvaluator> eval, String jobName) throws IOException { + ITree tree = eval.parseModuleAndFragments(eval, uri, jobName); return getBuilder().buildModule(tree); } @@ -399,12 +399,12 @@ private static void addImportToCurrentModule(ISourceLocation src, String name, I current.setSyntaxDefined(current.definesSyntax() || module.definesSyntax()); } - public static ITree parseModuleAndFragments(char[] data, ISourceLocation location, IEvaluator> eval) { + public static ITree parseModuleAndFragments(char[] data, ISourceLocation location, String jobName, IEvaluator> eval) { eval.__setInterrupt(false); IActionExecutor actions = new NoActionExecutor(); ITree tree; - eval.jobTodo("loading", 1); + eval.jobTodo(jobName, 1); try { tree = new RascalParser().parse(Parser.START_MODULE, location.getURI(), data, actions, new DefaultNodeFlattener(), new UPTRNodeFactory(true)); @@ -412,8 +412,9 @@ public static ITree parseModuleAndFragments(char[] data, ISourceLocation locatio catch (ParseError e) { throw new SyntaxError("module", IRascalValueFactory.getInstance().sourceLocation(location, e.getOffset(), e.getLength(), e.getBeginLine(), e.getEndLine(), e.getBeginColumn(), e.getEndColumn())); } - - eval.jobStep("loading", "parsed " + URIUtil.getLocationName(location), 1); + finally { + eval.jobStep(jobName, "parsed " + URIUtil.getLocationName(location), 1); + } if (TreeAdapter.isAmb(tree)) { // Ambiguity is dealt with elsewhere @@ -446,28 +447,28 @@ public static ITree parseModuleAndFragments(char[] data, ISourceLocation locatio ISet rules = Modules.getSyntax(top); for (IValue rule : rules) { evalImport(eval, (IConstructor) rule); - eval.getMonitor().jobStep("loading", "defining syntax", 1); + eval.getMonitor().jobStep(jobName, "defining syntax", 1); } ISet imports = Modules.getImports(top); - eval.getMonitor().jobTodo("loading", imports.size()); + eval.getMonitor().jobTodo(jobName, imports.size()); for (IValue mod : imports) { evalImport(eval, (IConstructor) mod); - eval.getMonitor().jobStep("loading", "importing", 1); + eval.getMonitor().jobStep(jobName, "importing", 1); } ISet extend = Modules.getExtends(top); - eval.getMonitor().jobTodo("loading", extend.size()); + eval.getMonitor().jobTodo(jobName, extend.size()); for (IValue mod : extend) { evalImport(eval, (IConstructor) mod); - eval.getMonitor().jobStep("loading", "extending", 1); + eval.getMonitor().jobStep(jobName, "extending", 1); } ISet externals = Modules.getExternals(top); - eval.getMonitor().jobTodo("loading", externals.size()); + eval.getMonitor().jobTodo(jobName, externals.size()); for (IValue mod : externals) { evalImport(eval, (IConstructor) mod); - eval.getMonitor().jobStep("loading", "external importing", 1); + eval.getMonitor().jobStep(jobName, "external importing", 1); } } finally { @@ -481,7 +482,7 @@ public static ITree parseModuleAndFragments(char[] data, ISourceLocation locatio RascalFunctionValueFactory vf = eval.getFunctionValueFactory(); URIResolverRegistry reg = URIResolverRegistry.getInstance(); ISourceLocation parserCacheFile = URIUtil.changeExtension(location, "parsers"); - eval.jobStep("loading", "parsing concrete fragment in " + name); + eval.jobStep(jobName, "parsing concrete fragment in " + name); IFunction parsers = null; @@ -502,17 +503,14 @@ else if (reg.exists(parserCacheFile)) { parsers = vf.parsers(reifiedType, vf.bool(false), vf.bool(false), vf.bool(false), vf.set()); } - eval.getMonitor().jobTodo("loading", 1); + eval.getMonitor().jobTodo(jobName, 1); result = parseFragments(vf, eval.getMonitor(), parsers, tree, location, env); - eval.getMonitor().jobStep("loading", "parsed concrete fragments", 1); + eval.getMonitor().jobStep(jobName, "parsed concrete fragments", 1); } } catch (URISyntaxException | ClassNotFoundException | IOException e) { eval.warning("reusing parsers failed during module import: " + e.getMessage(), env.getLocation()); } - finally { - eval.jobEnd("loading", true); - } return result; } diff --git a/src/org/rascalmpl/test/infrastructure/TestFramework.java b/src/org/rascalmpl/test/infrastructure/TestFramework.java index 888cc019cb1..2c351bcb985 100644 --- a/src/org/rascalmpl/test/infrastructure/TestFramework.java +++ b/src/org/rascalmpl/test/infrastructure/TestFramework.java @@ -94,9 +94,7 @@ private void reset() { catch (IOException e) { } } - generatedModules.clear(); - - + generatedModules.clear(); evaluator.getAccumulators().clear(); } @@ -138,7 +136,6 @@ public TestFramework prepare(String command) { try { reset(); execute(command); - } catch (StaticError e) { throw e;