public CompilerResults compileFromFiles(CompilerParameters parameters, File[] files) { var results = new CompilerResults(); this.context = new CompilerContext(parameters, results); this.statementValidator = new StatementValidator(this.context); this.expressionValidator = new ExpressionValidator(this.context); this.statementValidator.ExpressionValidator = this.expressionValidator; this.expressionValidator.StatementValidator = this.statementValidator; this.reachabilityChecker = new ReachabilityChecker(context); this.assignmentChecker = new AssignmentChecker(context); this.bytecodeGenerator = new BytecodeGenerator(context); bool tragicError = false; var buffer = new char[4096]; var sb = new StringBuilder(); var parser = new Parser(); foreach (var file in files) { sb.setLength(0); InputStreamReader reader = null; try { reader = new InputStreamReader(new FileInputStream(file), Charset.forName("UTF-8")); int read; while ((read = reader.read(buffer)) != -1) { sb.append(buffer, 0, read); } var text = new char[sb.length()]; sb.getChars(0, sizeof(text), text, 0); if (sizeof(text) > 0) { if (text[sizeof(text) - 1] == '\u001a') { text[sizeof(text) - 1] = ' '; } } var preprocessor = new Preprocessor(results.codeErrorManager, text); preprocessor.Filename = file.getAbsolutePath(); preprocessor.Symbols.addAll(parameters.Symbols); var scanner = new PreprocessedTextScanner(results.codeErrorManager, preprocessor.preprocess()); scanner.Filename = file.getAbsolutePath(); var compilationUnit = parser.parseCompilationUnit(scanner); if (compilationUnit != null) { compilationUnit.Symbols = preprocessor.Symbols; context.CompilationUnits.add(compilationUnit); } } catch (CodeErrorException) { } catch (Exception e) { e.printStackTrace(); tragicError = true; break; } finally { if (reader != null) { try { reader.close(); } catch (IOException) { } } } } if (!tragicError) { if (!context.HasErrors) { if (parameters.ProgressTracker != null) { parameters.ProgressTracker.compilationStageFinished(CompilationStage.Parsing); } doCompile(); } } this.context = null; this.statementValidator = null; this.expressionValidator = null; this.reachabilityChecker = null; this.assignmentChecker = null; this.queryTranslator = null; this.documentationBuilder = null; if (parameters.ProgressTracker != null) { parameters.ProgressTracker.compilationFinished(); } return results; }
private char[] getText(IFile file) { char[] text; if (parameters.AllFiles.getProjectRelativeName(file).equals(parameters.EditedFileName)) { text = parameters.EditedFileText; } else { using (var reader = new InputStreamReader(file.getContents(), file.getCharset())) { var sb = new StringBuilder(); int read; while ((read = reader.read(buffer)) != -1) { sb.append(buffer, 0, read); } text = new char[sb.length()]; sb.getChars(0, sizeof(text), text, 0); } } if (sizeof(text) > 0) { if (text[sizeof(text) - 1] == '\u001a') { text[sizeof(text) - 1] = ' '; } } return text; }