/** UnParse a file. If you want a dump then give -out somefile. */ private static void unparse( List<String> args, Option<String> out, boolean _unqualified, boolean _unmangle) throws UserError, InterruptedException, IOException { if (args.size() == 0) { throw new UserError("The unparse command needs a file to unparse."); } String s = args.get(0); List<String> rest = args.subList(1, args.size()); boolean unqualified = _unqualified; boolean unmangle = _unmangle; if (s.startsWith("-")) { if (s.equals("-unqualified")) { unqualified = true; } else if (s.equals("-unmangle")) { unmangle = true; } else if (s.equals("-debug")) { rest = Debug.parseOptions(rest); } else if (s.equals("-out") && !rest.isEmpty()) { out = Option.<String>some(rest.get(0)); rest = rest.subList(1, rest.size()); } else invalidFlag(s, "unparse"); unparse(rest, out, unqualified, unmangle); } else { unparse(s, out, unqualified, unmangle); } }
/** Compile a file. If you want a dump then give -out somefile. */ public static int compilerPhases(List<String> args, Option<String> out, String phase) throws UserError, InterruptedException, IOException, RepositoryError { int return_code = 0; if (args.size() == 0) { throw new UserError("The " + phase + " command must be given a file."); } String s = args.get(0); List<String> rest = args.subList(1, args.size()); if (s.startsWith("-")) { if (s.equals("-debug")) { rest = Debug.parseOptions(rest); } else if (s.equals("-out") && !rest.isEmpty()) { out = Option.<String>some(rest.get(0)); rest = rest.subList(1, rest.size()); } else if (s.equals("-compiler-lib")) { WellKnownNames.useCompilerLibraries(); Types.useCompilerLibraries(); } else if (s.equals("-typecheck-java")) { setScala(false); } else if (s.equals("-coercion")) { setTestCoercion(true); } else invalidFlag(s, phase); return_code = compilerPhases(rest, out, phase); } else { return_code = compileWithErrorHandling(s, out, false); } return return_code; }
private static void walkTests(List<String> args, boolean verbose) throws UserError, IOException, Throwable { boolean _verbose = verbose; if (args.size() == 0) { throw new UserError("Need a file to run through the Fortress interpreter."); } String s = args.get(0); List<String> rest = args.subList(1, args.size()); if (s.startsWith("-")) { if (s.equals("-debug")) { rest = Debug.parseOptions(rest); } else if (s.equals("-verbose")) { _verbose = true; } else invalidFlag(s, "test"); walkTests(rest, _verbose); } else { for (String file : args) { try { Iterable<? extends StaticError> errors = IterUtil.empty(); try { if (!isComponent(file)) throw new UserError(file + " is not a component file."); APIName name = NodeUtil.apiName(file); Path path = sourcePath(file, name); GraphRepository bcr = specificInterpreterRepository(path); ComponentIndex cu = bcr.getLinkedComponent(name); Driver.runTests(bcr, cu, _verbose); } catch (Throwable th) { // TODO FIXME what is the proper treatment of errors/exceptions etc.? if (th instanceof FortressException) { FortressException pe = (FortressException) th; if (pe.getStaticErrors() != null) errors = pe.getStaticErrors(); } if (th instanceof RuntimeException) throw (RuntimeException) th; if (th instanceof Error) throw (Error) th; throw new WrappedException(th, Debug.stackTraceOn()); } for (StaticError error : errors) { System.err.println(error); } // If there are no errors, // all components will have been written to disk // by the CacheBasedRepository. } catch (StaticError e) { System.err.println(e); if (Debug.stackTraceOn()) { e.printStackTrace(); } } catch (RepositoryError e) { System.err.println(e.getMessage()); } catch (FortressException e) { failureBoilerplate(e); System.exit(1); } } } }
/** Link compiled components implementing APIs imported by the given component. */ private static int junit(List<String> args) throws UserError, IOException { if (args.size() == 0) { throw new UserError("Need a file to run junit tests."); } String s = args.get(0); List<String> rest = args.subList(1, args.size()); if (s.startsWith("-")) { if (s.equals("-debug")) { rest = Debug.parseOptions(rest); } else invalidFlag(s, "junit"); return junit(rest); } junit.textui.TestRunner.run(FileTests.suiteFromListOfFiles(args, "", "", "", false, false)); return 0; }
/** Compare results of two components. */ private static void compare(List<String> args) throws UserError, InterruptedException, IOException, Throwable { if (args.size() == 0) { throw new UserError("Need files to compare the results."); } String s = args.get(0); List<String> rest = args.subList(1, args.size()); if (s.startsWith("-")) { if (s.equals("-debug")) { rest = Debug.parseOptions(rest); } else invalidFlag(s, "compare"); compare(rest); } else { if (args.size() == 1) throw new UserError("Need one more file to compare the results."); compare(s, args.get(1)); } }
/** Run a file through the Fortress interpreter. */ private static void walk(List<String> args) throws UserError, IOException, Throwable { if (args.size() == 0) { throw new UserError("Need a file to run through the Fortress interpreter."); } String s = args.get(0); List<String> rest = args.subList(1, args.size()); if (s.startsWith("-")) { if (s.equals("-debug")) { rest = Debug.parseOptions(rest); } else if (s.equals("-compiler-lib")) { WellKnownNames.useCompilerLibraries(); Types.useCompilerLibraries(); } else invalidFlag(s, "walk"); walk(rest); } else { walk(s, rest); } }
/** Link compiled components implementing APIs imported by the given component. */ private static int link(List<String> args) throws UserError, IOException { if (args.size() == 0) { throw new UserError("Need a file to link."); } String s = args.get(0); List<String> rest = args.subList(1, args.size()); if (s.startsWith("-")) { if (s.equals("-debug")) { rest = Debug.parseOptions(rest); } else invalidFlag(s, "link"); return link(rest); } else { if (!s.endsWith(".fss")) { s = s + ".fss"; } return compileWithErrorHandling(s, Option.<String>none(), true); } }
/** * Parse a file. If the file parses ok it will say "Ok". If you want a dump then give -out * somefile. */ private static int parse(List<String> args, Option<String> out) throws UserError, InterruptedException, IOException { if (args.size() == 0) { throw new UserError("Need a file to parse"); } String s = args.get(0); List<String> rest = args.subList(1, args.size()); if (s.startsWith("-")) { if (s.equals("-debug")) { rest = Debug.parseOptions(rest); } else if (s.equals("-out") && !rest.isEmpty()) { out = Option.<String>some(rest.get(0)); rest = rest.subList(1, rest.size()); } else invalidFlag(s, "parse"); return parse(rest, out); } else { return parse(s, out); } }
/** Automatically generate an API from a component. */ private static void api(List<String> args, Option<String> out, Option<String> prepend) throws UserError, InterruptedException, IOException { if (args.size() == 0) { throw new UserError("Need a file to generate an API."); } String s = args.get(0); List<String> rest = args.subList(1, args.size()); if (s.startsWith("-")) { if (s.equals("-debug")) { rest = Debug.parseOptions(rest); } else if (s.equals("-out") && !rest.isEmpty()) { out = Option.<String>some(rest.get(0)); rest = rest.subList(1, rest.size()); } else if (s.equals("-prepend") && !rest.isEmpty()) { prepend = Option.<String>some(rest.get(0)); rest = rest.subList(1, rest.size()); } else invalidFlag(s, "api"); api(rest, out, prepend); } else { api(s, out, prepend); } }