diff --git a/ets2panda/aot/main.cpp b/ets2panda/aot/main.cpp index 411df8364a29cccacefe03a517ccd368f2658b63..b8f59a420fea54dce7a69cf402702fc0455fa874 100644 --- a/ets2panda/aot/main.cpp +++ b/ets2panda/aot/main.cpp @@ -165,6 +165,7 @@ static int Run(Span args) auto diagnosticEngine = util::DiagnosticEngine(); auto options = std::make_unique(args[0], diagnosticEngine); if (!options->Parse(args)) { + diagnosticEngine.FlushDiagnostic(); return 1; } diagnosticEngine.SetWError(options->IsEtsWarningsWerror()); @@ -175,6 +176,7 @@ static int Run(Span args) auto pluginsOpt = InitializePlugins(options->GetPlugins(), diagnosticEngine); if (!pluginsOpt.has_value()) { + diagnosticEngine.FlushDiagnostic(); return 1; } @@ -182,10 +184,12 @@ static int Run(Span args) if (options->IsListPhases()) { std::cerr << "Available phases:" << std::endl; std::cerr << compiler.GetPhasesList(); + diagnosticEngine.FlushDiagnostic(); return 1; } if (options->GetCompilationMode() == CompilationMode::PROJECT) { + diagnosticEngine.FlushDiagnostic(); return CompileFromConfig(compiler, options.get(), diagnosticEngine); } @@ -200,7 +204,9 @@ static int Run(Span args) parserInput = std::string_view(buf, size); } es2panda::SourceFile input(sourceFile, parserInput, options->IsModule(), options->GetOutput()); - return CompileFromSource(compiler, input, *options.get(), diagnosticEngine); + auto res = CompileFromSource(compiler, input, *options.get(), diagnosticEngine); + diagnosticEngine.FlushDiagnostic(); + return res; } } // namespace ark::es2panda::aot diff --git a/ets2panda/public/es2panda_lib.cpp b/ets2panda/public/es2panda_lib.cpp index 68c404993fe37dbe0d4d8bd25d9457fb5ad5ad9e..f10f45292b41daf85503efd64b6639be9eb2841d 100644 --- a/ets2panda/public/es2panda_lib.cpp +++ b/ets2panda/public/es2panda_lib.cpp @@ -273,6 +273,7 @@ extern "C" void DestroyConfig(es2panda_Config *config) } delete cfg->options; + cfg->diagnosticEngine->FlushDiagnostic(); delete cfg->diagnosticEngine; delete cfg; } diff --git a/ets2panda/util/diagnosticEngine.cpp b/ets2panda/util/diagnosticEngine.cpp index 131ca76cf853ad72d7bea3b41d85bb1e7e4c47fe..84a00213a7ef61312b5ddcbdcd045e30a281d6fb 100644 --- a/ets2panda/util/diagnosticEngine.cpp +++ b/ets2panda/util/diagnosticEngine.cpp @@ -68,6 +68,9 @@ void DiagnosticEngine::FlushDiagnostic() for (auto it = log.begin(); it != last; it++) { printer_->Print(**it); } + for (auto &vec : diagnostics_) { + vec.clear(); + } } #ifndef FUZZING_EXIT_ON_FAILED_ASSERT static void SigSegvHandler([[maybe_unused]] int sig) diff --git a/ets2panda/util/diagnosticEngine.h b/ets2panda/util/diagnosticEngine.h index 0562a1cb453f1188dd5d0c7973e034f99b1ae7d5..a10f4e2aeac62f74edfa6db053353d774cd68157 100644 --- a/ets2panda/util/diagnosticEngine.h +++ b/ets2panda/util/diagnosticEngine.h @@ -58,7 +58,6 @@ public: NO_MOVE_SEMANTIC(DiagnosticEngine); ~DiagnosticEngine() { - FlushDiagnostic(); g_diagnosticEngine = nullptr; }