@@ -1052,8 +1052,8 @@ static void printASTValidationError(
1052
1052
}
1053
1053
1054
1054
void SwiftASTContext::DiagnoseWarnings (Process &process, Module &module ) const {
1055
- for ( const std::string &message : m_module_import_warnings )
1056
- process.PrintWarningCantLoadSwiftModule (module , message );
1055
+ if ( HasErrors () || HasClangImporterErrors () )
1056
+ process.PrintWarningCantLoadSwiftModule (module , GetAllErrors (). AsCString () );
1057
1057
}
1058
1058
1059
1059
// / Locate the swift-plugin-server for a plugin library,
@@ -1690,7 +1690,7 @@ SwiftASTContext::CreateInstance(lldb::LanguageType language, Module &module,
1690
1690
m_description, errs, got_serialized_options,
1691
1691
found_swift_modules)) {
1692
1692
// Validation errors are not fatal for the context.
1693
- swift_ast_sp->m_module_import_warnings . push_back ( std::string (error ));
1693
+ swift_ast_sp->AddDiagnostic (eDiagnosticSeverityWarning, errs. str ( ));
1694
1694
}
1695
1695
1696
1696
llvm::StringRef serialized_triple =
@@ -2973,7 +2973,6 @@ class StoringDiagnosticConsumer : public swift::DiagnosticConsumer {
2973
2973
return old;
2974
2974
}
2975
2975
2976
- // / This is only used by ReconstructTypes.
2977
2976
void AddDiagnostic (std::unique_ptr<Diagnostic> diagnostic) {
2978
2977
if (diagnostic)
2979
2978
m_diagnostics.push_back (std::move (diagnostic));
@@ -3062,19 +3061,16 @@ swift::ASTContext *SwiftASTContext::GetASTContext() {
3062
3061
3063
3062
// Handle any errors.
3064
3063
if (!clang_importer_ap || HasErrors ()) {
3065
- std::string message;
3066
- if (!HasErrors ()) {
3067
- message = " failed to create ClangImporter." ;
3068
- m_module_import_warnings.push_back (message);
3069
- } else {
3064
+ AddDiagnostic (eDiagnosticSeverityWarning,
3065
+ " failed to create ClangImporter" );
3066
+ if (GetLog (LLDBLog::Types)) {
3070
3067
DiagnosticManager diagnostic_manager;
3071
3068
PrintDiagnostics (diagnostic_manager, true );
3072
3069
std::string underlying_error = diagnostic_manager.GetString ();
3073
- message = " failed to initialize ClangImporter: " ;
3074
- message += underlying_error;
3075
- m_module_import_warnings. push_back (underlying_error );
3070
+ LOG_PRINTF ( GetLog (LLDBLog::Types),
3071
+ " failed to initialize ClangImporter: %s " ,
3072
+ underlying_error. c_str () );
3076
3073
}
3077
- LOG_PRINTF (GetLog (LLDBLog::Types), " %s" , message.c_str ());
3078
3074
}
3079
3075
if (clang_importer_ap)
3080
3076
moduleCachePath = swift::getModuleCachePathFromClang (
@@ -4127,10 +4123,9 @@ swift::TypeBase *
4127
4123
SwiftASTContext::ReconstructType (ConstString mangled_typename) {
4128
4124
Status error;
4129
4125
4130
- auto reconstructed_type = this ->ReconstructType (mangled_typename, error);
4131
- if (!error.Success ()) {
4132
- this ->AddErrorStatusAsGenericDiagnostic (error);
4133
- }
4126
+ auto reconstructed_type = ReconstructType (mangled_typename, error);
4127
+ if (!error.Success ())
4128
+ AddDiagnostic (eDiagnosticSeverityWarning, error.AsCString ());
4134
4129
return reconstructed_type;
4135
4130
}
4136
4131
@@ -4761,19 +4756,32 @@ uint32_t SwiftASTContext::GetPointerByteSize() {
4761
4756
return m_pointer_byte_size;
4762
4757
}
4763
4758
4764
- bool SwiftASTContext::HasErrors () {
4765
- if (m_diagnostic_consumer_ap. get () )
4766
- return (
4767
- static_cast <StoringDiagnosticConsumer *>(m_diagnostic_consumer_ap. get ())
4768
- -> NumErrors () != 0 );
4769
- return false ;
4759
+ bool SwiftASTContext::HasErrors () const {
4760
+ if (! m_diagnostic_consumer_ap)
4761
+ return false ;
4762
+ return (
4763
+ static_cast <StoringDiagnosticConsumer *>(m_diagnostic_consumer_ap. get ())
4764
+ -> NumErrors () != 0 ) ;
4770
4765
}
4771
- bool SwiftASTContext::HasClangImporterErrors () {
4772
- if (m_diagnostic_consumer_ap.get ())
4773
- return (
4774
- static_cast <StoringDiagnosticConsumer *>(m_diagnostic_consumer_ap.get ())
4775
- ->NumClangErrors () != 0 );
4776
- return false ;
4766
+ bool SwiftASTContext::HasClangImporterErrors () const {
4767
+ if (!m_diagnostic_consumer_ap)
4768
+ return false ;
4769
+ return (
4770
+ static_cast <StoringDiagnosticConsumer *>(m_diagnostic_consumer_ap.get ())
4771
+ ->NumClangErrors () != 0 );
4772
+ }
4773
+
4774
+ void SwiftASTContext::AddDiagnostic (DiagnosticSeverity severity,
4775
+ llvm::StringRef message) {
4776
+ assert (m_diagnostic_consumer_ap.get ());
4777
+ HEALTH_LOG_PRINTF (" %s" , message.str ().c_str ());
4778
+ if (!m_diagnostic_consumer_ap.get ())
4779
+ return ;
4780
+
4781
+ auto diagnostic = std::make_unique<Diagnostic>(
4782
+ message, severity, eDiagnosticOriginLLDB, LLDB_INVALID_COMPILER_ID);
4783
+ static_cast <StoringDiagnosticConsumer *>(m_diagnostic_consumer_ap.get ())
4784
+ ->AddDiagnostic (std::move (diagnostic));
4777
4785
}
4778
4786
4779
4787
bool SwiftASTContext::HasFatalErrors (swift::ASTContext *ast_context) {
@@ -4795,17 +4803,6 @@ bool SwiftASTContext::SetColorizeDiagnostics(bool b) {
4795
4803
return false ;
4796
4804
}
4797
4805
4798
- void SwiftASTContext::AddErrorStatusAsGenericDiagnostic (Status error) {
4799
- assert (!error.Success () && " status should be in an error state" );
4800
-
4801
- auto diagnostic = std::make_unique<Diagnostic>(
4802
- error.AsCString (), eDiagnosticSeverityError, eDiagnosticOriginLLDB,
4803
- LLDB_INVALID_COMPILER_ID);
4804
- if (m_diagnostic_consumer_ap.get ())
4805
- static_cast <StoringDiagnosticConsumer *>(m_diagnostic_consumer_ap.get ())
4806
- ->AddDiagnostic (std::move (diagnostic));
4807
- }
4808
-
4809
4806
void SwiftASTContext::PrintDiagnostics (DiagnosticManager &diagnostic_manager,
4810
4807
uint32_t bufferID, uint32_t first_line,
4811
4808
uint32_t last_line) const {
0 commit comments