@@ -191,11 +191,10 @@ swift::Type TypeSystemSwiftTypeRef::GetSwiftType(CompilerType compiler_type) {
191
191
if (!ts)
192
192
return {};
193
193
194
- Status error;
195
194
// FIXME: Suboptimal performance, because the ConstString is looked up again.
196
195
ConstString mangled_name (
197
196
reinterpret_cast <const char *>(compiler_type.GetOpaqueQualType ()));
198
- return ts->m_swift_ast_context ->ReconstructType (mangled_name, error );
197
+ return ts->m_swift_ast_context ->ReconstructType (mangled_name);
199
198
}
200
199
201
200
swift::Type SwiftASTContext::GetSwiftType (CompilerType compiler_type) {
@@ -2853,8 +2852,8 @@ class ANSIColorStringStream : public llvm::raw_string_ostream {
2853
2852
class StoringDiagnosticConsumer : public swift ::DiagnosticConsumer {
2854
2853
public:
2855
2854
StoringDiagnosticConsumer (SwiftASTContext &ast_context)
2856
- : m_ast_context(ast_context), m_diagnostics (), m_num_errors( 0 ),
2857
- m_colorize (false ) {
2855
+ : m_ast_context(ast_context), m_raw_diagnostics (), m_diagnostics( ),
2856
+ m_num_errors ( 0 ), m_colorize(false ) {
2858
2857
m_ast_context.GetDiagnosticEngine ().resetHadAnyError ();
2859
2858
m_ast_context.GetDiagnosticEngine ().addConsumer (*this );
2860
2859
}
@@ -2926,19 +2925,19 @@ class StoringDiagnosticConsumer : public swift::DiagnosticConsumer {
2926
2925
std::string &message_ref = os.str ();
2927
2926
2928
2927
if (message_ref.empty ())
2929
- m_diagnostics .push_back (RawDiagnostic (
2928
+ m_raw_diagnostics .push_back (RawDiagnostic (
2930
2929
text.str (), info.Kind , bufferName, bufferID, line_col.first ,
2931
2930
line_col.second ,
2932
2931
use_fixits ? info.FixIts
2933
2932
: llvm::ArrayRef<swift::Diagnostic::FixIt>()));
2934
2933
else
2935
- m_diagnostics .push_back (RawDiagnostic (
2934
+ m_raw_diagnostics .push_back (RawDiagnostic (
2936
2935
message_ref, info.Kind , bufferName, bufferID, line_col.first ,
2937
2936
line_col.second ,
2938
2937
use_fixits ? info.FixIts
2939
2938
: llvm::ArrayRef<swift::Diagnostic::FixIt>()));
2940
2939
} else {
2941
- m_diagnostics .push_back (RawDiagnostic (
2940
+ m_raw_diagnostics .push_back (RawDiagnostic (
2942
2941
text.str (), info.Kind , bufferName, bufferID, line_col.first ,
2943
2942
line_col.second , llvm::ArrayRef<swift::Diagnostic::FixIt>()));
2944
2943
}
@@ -2949,6 +2948,7 @@ class StoringDiagnosticConsumer : public swift::DiagnosticConsumer {
2949
2948
2950
2949
void Clear () {
2951
2950
m_ast_context.GetDiagnosticEngine ().resetHadAnyError ();
2951
+ m_raw_diagnostics.clear ();
2952
2952
m_diagnostics.clear ();
2953
2953
m_num_errors = 0 ;
2954
2954
}
@@ -2980,8 +2980,13 @@ class StoringDiagnosticConsumer : public swift::DiagnosticConsumer {
2980
2980
void PrintDiagnostics (DiagnosticManager &diagnostic_manager,
2981
2981
uint32_t bufferID = UINT32_MAX, uint32_t first_line = 0 ,
2982
2982
uint32_t last_line = UINT32_MAX) {
2983
- bool added_one_diagnostic = false ;
2984
- for (const RawDiagnostic &diagnostic : m_diagnostics) {
2983
+ bool added_one_diagnostic = !m_diagnostics.empty ();
2984
+
2985
+ for (std::unique_ptr<Diagnostic> &diagnostic : m_diagnostics) {
2986
+ diagnostic_manager.AddDiagnostic (std::move (diagnostic));
2987
+ }
2988
+
2989
+ for (const RawDiagnostic &diagnostic : m_raw_diagnostics) {
2985
2990
// We often make expressions and wrap them in some code. When
2986
2991
// we see errors we want the line numbers to be correct so we
2987
2992
// correct them below. LLVM stores in SourceLoc objects as
@@ -3053,7 +3058,7 @@ class StoringDiagnosticConsumer : public swift::DiagnosticConsumer {
3053
3058
// This will report diagnostic errors from outside the
3054
3059
// expression's source range. Those are not interesting to
3055
3060
// users, so we only emit them in debug builds.
3056
- for (const RawDiagnostic &diagnostic : m_diagnostics ) {
3061
+ for (const RawDiagnostic &diagnostic : m_raw_diagnostics ) {
3057
3062
const DiagnosticSeverity severity = SeverityForKind (diagnostic.kind );
3058
3063
const DiagnosticOrigin origin = eDiagnosticOriginSwift;
3059
3064
diagnostic_manager.AddDiagnostic (diagnostic.description .c_str (),
@@ -3070,6 +3075,10 @@ class StoringDiagnosticConsumer : public swift::DiagnosticConsumer {
3070
3075
return old;
3071
3076
}
3072
3077
3078
+ void AddDiagnostic (std::unique_ptr<Diagnostic> diagnostic) {
3079
+ m_diagnostics.push_back (std::move (diagnostic));
3080
+ }
3081
+
3073
3082
private:
3074
3083
// We don't currently use lldb_private::Diagostic or any of the lldb
3075
3084
// DiagnosticManager machinery to store diagnostics as they
@@ -3095,9 +3104,12 @@ class StoringDiagnosticConsumer : public swift::DiagnosticConsumer {
3095
3104
std::vector<swift::DiagnosticInfo::FixIt> fixits;
3096
3105
};
3097
3106
typedef std::vector<RawDiagnostic> RawDiagnosticBuffer;
3107
+ typedef std::vector<std::unique_ptr<Diagnostic>> DiagnosticList;
3098
3108
3099
3109
SwiftASTContext &m_ast_context;
3100
- RawDiagnosticBuffer m_diagnostics;
3110
+ RawDiagnosticBuffer m_raw_diagnostics;
3111
+ DiagnosticList m_diagnostics;
3112
+
3101
3113
unsigned m_num_errors = 0 ;
3102
3114
bool m_colorize;
3103
3115
};
@@ -4360,9 +4372,8 @@ swift::Type convertSILFunctionTypesToASTFunctionTypes(swift::Type t) {
4360
4372
4361
4373
CompilerType
4362
4374
SwiftASTContext::GetTypeFromMangledTypename (ConstString mangled_typename) {
4363
- Status error;
4364
4375
if (llvm::isa<SwiftASTContextForExpressions>(this ))
4365
- return GetCompilerType (ReconstructType (mangled_typename, error ));
4376
+ return GetCompilerType (ReconstructType (mangled_typename));
4366
4377
return GetCompilerType (mangled_typename);
4367
4378
}
4368
4379
@@ -4410,6 +4421,17 @@ CompilerType SwiftASTContext::GetAsClangType(ConstString mangled_name) {
4410
4421
return clang_type;
4411
4422
}
4412
4423
4424
+ swift::TypeBase *SwiftASTContext::ReconstructType (ConstString mangled_typename) {
4425
+ Status error;
4426
+
4427
+ auto reconstructed_type =
4428
+ this ->ReconstructType (mangled_typename, error);
4429
+ if (!error.Success ()) {
4430
+ this ->AddErrorStatusAsGenericDiagnostic (error);
4431
+ }
4432
+ return reconstructed_type;
4433
+ }
4434
+
4413
4435
swift::TypeBase *SwiftASTContext::ReconstructType (ConstString mangled_typename,
4414
4436
Status &error) {
4415
4437
VALID_OR_RETURN (nullptr );
@@ -5001,6 +5023,17 @@ bool SwiftASTContext::SetColorizeDiagnostics(bool b) {
5001
5023
return false ;
5002
5024
}
5003
5025
5026
+ void SwiftASTContext::AddErrorStatusAsGenericDiagnostic (Status error) {
5027
+ assert (!error.Success () && " status should be in an error state" );
5028
+
5029
+ auto diagnostic = std::make_unique<Diagnostic>(
5030
+ error.AsCString (), eDiagnosticSeverityError, eDiagnosticOriginLLDB,
5031
+ LLDB_INVALID_COMPILER_ID);
5032
+ if (m_diagnostic_consumer_ap.get ())
5033
+ static_cast <StoringDiagnosticConsumer *>(m_diagnostic_consumer_ap.get ())
5034
+ ->AddDiagnostic (std::move (diagnostic));
5035
+ }
5036
+
5004
5037
void SwiftASTContext::PrintDiagnostics (DiagnosticManager &diagnostic_manager,
5005
5038
uint32_t bufferID, uint32_t first_line,
5006
5039
uint32_t last_line) {
0 commit comments