public void Test_LoadingAssembly(ICirData cirData, string assemblyToLoad, bool verify, bool verbose) { AssemblyDefinition assemblyDefinition = CecilUtils.getAssembly(assemblyToLoad); if (assemblyDefinition == null) { return; } var loadTimer = new O2Timer("Assembly " + Path.GetFileName(assemblyToLoad) + " Loaded in"); if (verbose) { loadTimer.start(); } cirFactory.processAssemblyDefinition(cirData, assemblyDefinition, assemblyToLoad); if (verbose) { loadTimer.stop(); } if (verify) { var checkTimer = new O2Timer(" functions checked in "); if (verbose) { checkTimer.start(); } checkThatAllFunctionsMatch(cirData, assemblyDefinition); if (verbose) { checkTimer.stop(); } } }
public void setCompilerEnvironment() { var o2Timer = new O2Timer("Code Compiled in"); this.csharpCompiler = new CSharp_FastCompiler(); //csharpCompiler.field("forceAstBuildDelay",250); // try to prevent the problem with missing the compilation of the last char this.csharpCompiler.beforeSnippetAst = () => { this.csharpCompiler.InvocationParameters = this.InvocationParameters; }; this.csharpCompiler.onAstFail = () => { //"AST creation failed".error(); // this.sourceCodeViewer.enabled(false); executeButton.enabled(false); result_RichTextBox.textColor(Color.Red).set_Text("Ast Parsing Errors:\r\n\r\n"); //.append_Text(csharpCompiler.AstErrors); commandsToExecute.updateCodeComplete(csharpCompiler); sourceCodeViewer.setDocumentContents(csharpCompiler.SourceCode); OnAstFail.invoke(); }; this.csharpCompiler.onAstOK = () => { o2Timer.start(); commandsToExecute.editor().refresh(); sourceCodeViewer.enabled(true); commandsToExecute.invokeOnThread(() => commandsToExecute.Refresh()); GeneratedCode = csharpCompiler.SourceCode; commandsToExecute.updateCodeComplete(csharpCompiler); sourceCodeViewer.setDocumentContents(csharpCompiler.SourceCode); OnAstOK.invoke(); }; csharpCompiler.onCompileFail = () => { //"AST OK, but compilation failed".error(); executeButton.enabled(false); var codeOffset = csharpCompiler.getGeneratedSourceCodeMethodLineOffset(); csharpCompiler.CompilationErrors.runForEachCompilationError( (row, col) => { sourceCodeViewer.editor().setSelectedText(row, col, true, false); commandsToExecute.editor().setSelectedText( row - codeOffset.Line, col - codeOffset.Column, true, /*showAsError*/ false, /*showAsBookMark*/ false); /*decrementLineAndColumn*/ }); result_RichTextBox.textColor(Color.Red) .set_Text("Compilation Errors:\r\n\r\n") .append_Text(csharpCompiler.CompilationErrors); onCompileFail.invoke(); }; csharpCompiler.onCompileOK = () => { o2Timer.stop(); "Compilation OK".debug(); commandsToExecute.editor().refresh(); sourceCodeViewer.editor().refresh(); result_RichTextBox.set_Text("Compilation OK:\r\n\r\n") .textColor(Color.Green); executeButton.enabled(true); if (AutoSaveOnCompileSuccess && Code != defaultCode) { AutoSaveDir.createDir(); // make sure it exits var targetFile = AutoSaveDir.pathCombine(Files.getFileSaveDateTime_Now().trim() + ".cs"); targetFile.fileWrite(Code); } onCompileOK.invoke(); // once all is done update the codeComplete information if (commandsToExecute.editor().o2CodeCompletion.notNull()) { commandsToExecute.editor().o2CodeCompletion.addReferences(csharpCompiler.ReferencedAssemblies); } //add_ExtraMethodsFile(); // restore previous mappings here //register cacheAssmbly var codeMd5 = previousCompiledCodeText.md5Hash(); CompileEngine.CachedCompiledAssemblies.add(codeMd5, this.csharpCompiler.CompiledAssembly.Location); executeButton.enabled(true); if (ExecuteOnCompile) { execute(); } }; }