/// <summary> /// Start asynchronous continuous compilation in background threads /// </summary> public void StartContinuousBackgroundCompilation(int scannerPeriodMillisecond, int preprocessorPeriodMillisecond, int codeElementsParserPeriodMillisecond, int programClassParserPeriodMillisecond) { // Protect against concurrent updates lock (timersSyncObject) { // Already started, nothing to do if (scannerTimer != null) { return; } // Check that periods for sucessive steps are consistent if (preprocessorPeriodMillisecond <= scannerPeriodMillisecond || codeElementsParserPeriodMillisecond <= preprocessorPeriodMillisecond || programClassParserPeriodMillisecond <= codeElementsParserPeriodMillisecond) { throw new ArgumentException("Compiler step execution periods should be set with increasing values : any other setup would waste CPU resources"); } // Initialize timers if (CompilationResultsForCopy != null) { scannerTimer = new Timer(state => CompilationResultsForCopy.RefreshTokensDocumentSnapshot(), null, 0, scannerPeriodMillisecond); preprocessorTimer = new Timer(state => CompilationResultsForCopy.RefreshProcessedTokensDocumentSnapshot(), null, preprocessorPeriodMillisecond, preprocessorPeriodMillisecond); } else { scannerTimer = new Timer(state => CompilationResultsForProgram.RefreshTokensDocumentSnapshot(), null, 0, scannerPeriodMillisecond); preprocessorTimer = new Timer(state => CompilationResultsForProgram.RefreshProcessedTokensDocumentSnapshot(), null, preprocessorPeriodMillisecond, preprocessorPeriodMillisecond); codeElementsParserTimer = new Timer(state => CompilationResultsForProgram.RefreshCodeElementsDocumentSnapshot(), null, codeElementsParserPeriodMillisecond, codeElementsParserPeriodMillisecond); programClassParserTimer = new Timer(state => CompilationResultsForProgram.RefreshProgramClassDocumentSnapshot(), null, programClassParserPeriodMillisecond, programClassParserPeriodMillisecond); } } }
/// <summary> /// Synchronous one-time compilation of the current file /// </summary> public void CompileOnce() { if (CompilerOptions.ExecToStep == null) { CompilerOptions.ExecToStep = ExecutionStep.SemanticCheck; } if (CompilationResultsForCopy != null) { CompilationResultsForCopy.UpdateTokensLines(); //Scanner if (!(CompilerOptions.ExecToStep > ExecutionStep.Scanner)) { return; } CompilationResultsForCopy.RefreshTokensDocumentSnapshot(); CompilationResultsForCopy.RefreshProcessedTokensDocumentSnapshot(); //Preprocessor } else { AnalyticsWrapper.Telemetry.TrackEvent("[Phase] Scanner Step"); CompilationResultsForProgram.UpdateTokensLines(); //Scanner if (!(CompilerOptions.ExecToStep > ExecutionStep.Scanner)) { return; } AnalyticsWrapper.Telemetry.TrackEvent("[Phase] Preprocessor Step"); CompilationResultsForProgram.RefreshTokensDocumentSnapshot(); CompilationResultsForProgram.RefreshProcessedTokensDocumentSnapshot(); //Preprocessor if (!(CompilerOptions.ExecToStep > ExecutionStep.Preprocessor)) { return; } if (CompilerOptions.HaltOnMissingCopy && CompilationResultsForProgram.MissingCopies.Count > 0) { return; //If the Option is set to true and there is at least one missing copy, we don't have to run the semantic phase } AnalyticsWrapper.Telemetry.TrackEvent("[Phase] Syntaxic Step"); CompilationResultsForProgram.RefreshCodeElementsDocumentSnapshot(); //SyntaxCheck if (!(CompilerOptions.ExecToStep > ExecutionStep.SyntaxCheck)) { return; } AnalyticsWrapper.Telemetry.TrackEvent("[Phase] Semantic Step"); CompilationResultsForProgram.RefreshProgramClassDocumentSnapshot(); //SemanticCheck } }
/// <summary> /// Perform a cmpilation based on an execution step. /// </summary> /// <param name="exec2Step">The execution step</param> /// <param name="haltOnMissingCopy">For preprocessing step, halt on missing copy options</param> /// <param name="useAntlrProgramParsing">Shall Antlr be used to parse the program</param> public void CompileOnce(ExecutionStep?exec2Step, bool haltOnMissingCopy, bool useAntlrProgramParsing) { if (exec2Step == null) { exec2Step = ExecutionStep.CrossCheck; } if (CompilationResultsForCopy != null) { CompilationResultsForCopy.UpdateTokensLines(); //Scanner if (!(exec2Step > ExecutionStep.Scanner)) { return; } CompilationResultsForCopy.RefreshTokensDocumentSnapshot(); CompilationResultsForCopy.RefreshProcessedTokensDocumentSnapshot(); //Preprocessor } else { CompilationResultsForProgram.UpdateTokensLines(); //Scanner CompilationResultsForProgram.RefreshTokensDocumentSnapshot(); ExecutionStepEventHandler?.Invoke(this, new ExecutionStepEventArgs() { ExecutionStep = ExecutionStep.Scanner }); if (!(exec2Step > ExecutionStep.Scanner)) { return; } CompilationResultsForProgram.RefreshProcessedTokensDocumentSnapshot(); //Preprocessor ExecutionStepEventHandler?.Invoke(this, new ExecutionStepEventArgs() { ExecutionStep = ExecutionStep.Preprocessor }); if (!(exec2Step > ExecutionStep.Preprocessor)) { return; } if (haltOnMissingCopy && CompilationResultsForProgram.MissingCopies.Count > 0) { return; //If the Option is set to true and there is at least one missing copy, we don't have to run the semantic phase } CompilationResultsForProgram.RefreshCodeElementsDocumentSnapshot(); //SyntaxCheck ExecutionStepEventHandler?.Invoke(this, new ExecutionStepEventArgs() { ExecutionStep = ExecutionStep.SyntaxCheck }); if (!(exec2Step > ExecutionStep.SyntaxCheck)) { return; } CompilationResultsForProgram.ProduceTemporarySemanticDocument(); //SemanticCheck ExecutionStepEventHandler?.Invoke(this, new ExecutionStepEventArgs() { ExecutionStep = ExecutionStep.SemanticCheck }); if (!(exec2Step > ExecutionStep.SemanticCheck)) { return; } CompilationResultsForProgram.RefreshProgramClassDocumentSnapshot(); //Cross Check step ExecutionStepEventHandler?.Invoke(this, new ExecutionStepEventArgs() { ExecutionStep = ExecutionStep.CrossCheck }); } }