コード例 #1
0
  public void toAsm(JarOutputStream jos) {
    ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES);
    //        ClassWriter cw = new ClassWriter(0);
    CheckClassAdapter cca = new CheckClassAdapter(cw);

    cca.visit(version, access, name, sig, superName, interfaces);
    Iterator it = fieldVisitors.entrySet().iterator();

    while (it.hasNext()) {
      Map.Entry pairs = (Map.Entry) it.next();
      ByteCodeFieldVisitor fv = (ByteCodeFieldVisitor) pairs.getValue();
      fv.toAsm(cca);
    }

    it = methodVisitors.entrySet().iterator();
    while (it.hasNext()) {
      Map.Entry pairs = (Map.Entry) it.next();
      ByteCodeMethodVisitor mv = (ByteCodeMethodVisitor) pairs.getValue();
      mv.toAsm(cca);
    }

    byte[] bytes = cw.toByteArray();
    if (ProjectProperties.getBoolean("fortress.bytecode.verify", false)) {
      PrintWriter pw = new PrintWriter(System.out);
      CheckClassAdapter.verify(new ClassReader(bytes), true, pw);
    }
    System.out.println("About to write " + name);
    ByteCodeWriter.writeJarredClass(jos, name, bytes);
  }
コード例 #2
0
ファイル: Shell.java プロジェクト: dbremner/fortress
 private static int parse(String file, Option<String> out) throws UserError, IOException {
   int return_code = 0;
   try {
     CompilationUnit unit = Parser.parseFileConvertExn(new File(file));
     System.out.println("Ok");
     if (out.isSome()) {
       try {
         ASTIO.writeJavaAst(unit, out.unwrap());
         System.out.println("Dumped parse tree to " + out.unwrap());
       } catch (IOException e) {
         throw new IOException("IOException " + e + "while writing " + out.unwrap());
       }
     }
   } catch (ParserError e) {
     if (Debug.stackTraceOn()) {
       System.err.println(e.getMessage());
       e.printStackTrace();
     } else {
       System.err.println(turnOnDebugMessage);
     }
     return_code = 1;
   } catch (ProgramError e) {
     failureBoilerplate(e);
     return_code = 1;
   } catch (CompilerBug e) {
     failureBoilerplate(e);
     return_code = 1;
   } catch (InterpreterBug e) {
     failureBoilerplate(e);
     return_code = 1;
   } catch (FileNotFoundException f) {
     throw new UserError(file + " not found");
   } finally {
     try {
       Files.rm(ProjectProperties.preparserErrorLog(file));
     } catch (IOException e) {
     }
   }
   return return_code;
 }
コード例 #3
0
ファイル: Shell.java プロジェクト: dbremner/fortress
  /**
   * @param tokens
   * @return
   * @throws InterruptedException
   * @throws Throwable
   */
  public static int subMain(String[] tokens) throws InterruptedException, Throwable {
    int return_code = 0;

    // Now match the assembled string.
    try {
      String what = tokens[0];
      List<String> args = Arrays.asList(tokens).subList(1, tokens.length);
      if (what.equals("compile")) {
        useCompilerLibraries();
        setTypeChecking(true);
        setPhaseOrder(PhaseOrder.compilerPhaseOrder);
        return_code = compilerPhases(args, Option.<String>none(), what);
      } else if (what.equals("junit")) {
        return_code = junit(args);
      } else if (what.equals("link")) {
        useCompilerLibraries();
        setTypeChecking(true);
        setPhaseOrder(PhaseOrder.compilerPhaseOrder);
        return_code = link(args);
      } else if (what.equals("build")) {
        useCompilerLibraries();
        setTypeChecking(true);
        setPhaseOrder(PhaseOrder.compilerPhaseOrder);
        return_code = link(args);
      } else if (what.equals("walk")) {
        useInterpreterLibraries();
        setScala(false);
        setPhaseOrder(PhaseOrder.interpreterPhaseOrder);
        walk(args);
      } else if (what.equals("api")) {
        useCompilerLibraries();
        api(args, Option.<String>none(), Option.<String>none());
      } else if (what.equals("compare")) {
        useCompilerLibraries();
        compare(args);
      } else if (what.equals("parse")) {
        useCompilerLibraries();
        return_code = parse(args, Option.<String>none());
      } else if (what.equals("unparse")) {
        useCompilerLibraries();
        unparse(args, Option.<String>none(), false, false);
      } else if (what.equals("disambiguate")) {
        useCompilerLibraries();
        setPhaseOrder(PhaseOrder.disambiguatePhaseOrder);
        return_code = compilerPhases(args, Option.<String>none(), what);
      } else if (what.equals("desugar")) {
        useCompilerLibraries();
        setTypeChecking(true);
        setObjExprDesugaring(true);
        setPhaseOrder(PhaseOrder.desugarPhaseOrder);

        return_code = compilerPhases(args, Option.<String>none(), what);
      } else if (what.equals("grammar")) {
        useCompilerLibraries();
        setPhaseOrder(PhaseOrder.grammarPhaseOrder);

        return_code = compilerPhases(args, Option.<String>none(), what);
      } else if (what.equals("typecheck")) {
        useCompilerLibraries();
        setTypeChecking(true);
        setPhaseOrder(PhaseOrder.typecheckPhaseOrder);

        return_code = compilerPhases(args, Option.<String>none(), what);
      } else if (what.equals("test-coercion")) {
        useCompilerLibraries();
        setTypeChecking(true);
        setPhaseOrder(PhaseOrder.typecheckPhaseOrder);

        return_code = compilerPhases(args, Option.<String>none(), what);
      } else if (what.equals("typecheck-old")) {
        useInterpreterLibraries();
        setScala(false);
        /* TODO: remove the next line once type checking is permanently turned on */
        setTypeChecking(true);
        setPhaseOrder(PhaseOrder.typecheckPhaseOrder);

        return_code = compilerPhases(args, Option.<String>none(), what);
      } else if (what.equals("test")) {
        useInterpreterLibraries();
        setScala(false);
        setPhaseOrder(PhaseOrder.interpreterPhaseOrder);
        walkTests(args, false);
      } else if (what.contains(ProjectProperties.COMP_SOURCE_SUFFIX)
          || (what.startsWith("-") && tokens.length > 1)) {
        useInterpreterLibraries();
        setScala(false);
        setPhaseOrder(PhaseOrder.interpreterPhaseOrder);
        walk(Arrays.asList(tokens));
      } else if (what.equals("help")) {
        useCompilerLibraries();
        printHelpMessage();
      } else if (what.equals("expand") && tokens.length == 2) {
        System.out.println(ProjectProperties.get(tokens[1], ""));
      } else {
        useCompilerLibraries();
        printUsageMessage();
      }
    } catch (StaticError e) {
      System.err.println(e);
      if (Debug.stackTraceOn()) {
        e.printStackTrace();
      }
      return_code = -1;
    } catch (UserError error) {
      System.err.println(error.getMessage());
      return_code = -1;
    } catch (IOException error) {
      System.err.println(error.getMessage());
      return_code = -2;
    } catch (CompilerBug error) {
      System.err.println(error.getMessage());
      if (Debug.stackTraceOn()) {
        error.printStackTrace();
      }
      return_code = -3;
    }

    Init.allowForLeakChecks();
    return return_code;
  }
コード例 #4
0
ファイル: Shell.java プロジェクト: dbremner/fortress
 /** The fields of this class serve as temporary switches used for testing. */
 private static class CompileProperties {
   boolean macro =
       ProjectProperties.getBoolean(
           "fortress.compile.macro", true); // run syntax abstraction or not
   boolean type_check =
       ProjectProperties.getBoolean(
           "fortress.compile.typecheck", false); // run type checker or not
   boolean objExpr_desugar =
       ProjectProperties.getBoolean(
           "fortress.compile.desugar.objexpr", false); // run obj expression desugaring or not
   boolean getter_setter_desugar =
       ProjectProperties.getBoolean(
           "fortress.compile.desugar.getset", true); // run getter/setter desugaring or not
   boolean use_scala =
       ProjectProperties.getBoolean(
           "fortress.compile.usescala", true); // use the scala typechecker
   boolean test_coercion =
       ProjectProperties.getBoolean("fortress.compile.testcoercion", false); // test coercion
   boolean assignment_desugar =
       ProjectProperties.getBoolean(
           "fortress.compile.desugar.assignment", true); // run assignment desugaring or not
   boolean assignment_pre_desugar =
       ProjectProperties.getBoolean(
           "fortress.compile.predesugar.assignment",
           false); // run predisambiguation assignment desugaring or not
   boolean extendsObject_pre_desugar =
       ProjectProperties.getBoolean(
           "fortress.compile.predesugar.extendsobject",
           false); // run predisambiguation extendsObject desugaring or not
   boolean coercion_desugar =
       ProjectProperties.getBoolean(
           "fortress.compile.desugar.coercion", true); // run coercion desugaring or not
   boolean chainexpr_desugar =
       ProjectProperties.getBoolean(
           "fortress.compile.desugar.chainexpr", true); // run chain expr desugaring or not
   boolean compiled_expr_desugarer = true;
 }