Example #1
1
  /** 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;
  }
Example #2
1
  /** 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);
    }
  }
Example #3
0
  /** 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);
    }
  }
Example #4
0
  /**
   * 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);
    }
  }