@@ -359,20 +359,13 @@ class OverrideError : public llvm::ErrorInfo<OverrideError,
359
359
}
360
360
};
361
361
362
- class TypeError : public llvm ::ErrorInfo<TypeError, DeclDeserializationError> {
363
- friend ErrorInfo;
364
- static const char ID;
365
- void anchor () override ;
362
+ // Service class for errors with an underlying cause.
363
+ class ErrorWithUnderlyingReason {
364
+ std::unique_ptr<llvm::ErrorInfoBase> underlyingReason;
366
365
367
- std::unique_ptr<ErrorInfoBase> underlyingReason;
368
366
public:
369
- explicit TypeError (DeclName name, std::unique_ptr<ErrorInfoBase> reason,
370
- Flags flags={}, unsigned numVTableEntries=0 )
371
- : underlyingReason(std::move(reason)) {
372
- this ->name = name;
373
- this ->flags = flags;
374
- this ->numVTableEntries = numVTableEntries;
375
- }
367
+ explicit ErrorWithUnderlyingReason (std::unique_ptr<llvm::ErrorInfoBase> reason) :
368
+ underlyingReason(std::move(reason)) {}
376
369
377
370
template <typename UnderlyingErrorT>
378
371
bool underlyingReasonIsA () const {
@@ -381,60 +374,74 @@ class TypeError : public llvm::ErrorInfo<TypeError, DeclDeserializationError> {
381
374
return underlyingReason->isA <UnderlyingErrorT>();
382
375
}
383
376
384
- void log (raw_ostream &OS) const override {
385
- OS << " Could not deserialize type for '" << name << " '" ;
377
+ void log (raw_ostream &OS) const {
386
378
if (underlyingReason) {
387
379
OS << " \n Caused by: " ;
388
380
underlyingReason->log (OS);
389
381
}
390
382
}
391
383
384
+ };
385
+
386
+ class TypeError : public llvm ::ErrorInfo<TypeError, DeclDeserializationError>,
387
+ public ErrorWithUnderlyingReason {
388
+ friend ErrorInfo;
389
+ static const char ID;
390
+ void anchor () override ;
391
+
392
+ public:
393
+ explicit TypeError (DeclName name, std::unique_ptr<ErrorInfoBase> reason,
394
+ Flags flags={}, unsigned numVTableEntries=0 )
395
+ : ErrorWithUnderlyingReason(std::move(reason)) {
396
+ this ->name = name;
397
+ this ->flags = flags;
398
+ this ->numVTableEntries = numVTableEntries;
399
+ }
400
+
401
+ void log (raw_ostream &OS) const override {
402
+ OS << " Could not deserialize type for '" << name << " '" ;
403
+ ErrorWithUnderlyingReason::log (OS);
404
+ }
405
+
392
406
std::error_code convertToErrorCode () const override {
393
407
return llvm::inconvertibleErrorCode ();
394
408
}
395
409
};
396
410
397
- class ExtensionError : public llvm ::ErrorInfo<ExtensionError> {
411
+ class ExtensionError : public llvm ::ErrorInfo<ExtensionError>,
412
+ public ErrorWithUnderlyingReason {
398
413
friend ErrorInfo;
399
414
static const char ID;
400
415
void anchor () override ;
401
416
402
- std::unique_ptr<ErrorInfoBase> underlyingReason;
403
-
404
417
public:
405
418
explicit ExtensionError (std::unique_ptr<ErrorInfoBase> reason)
406
- : underlyingReason (std::move(reason)) {}
419
+ : ErrorWithUnderlyingReason (std::move(reason)) {}
407
420
408
421
void log (raw_ostream &OS) const override {
409
422
OS << " could not deserialize extension" ;
410
- if (underlyingReason) {
411
- OS << " : " ;
412
- underlyingReason->log (OS);
413
- }
423
+ ErrorWithUnderlyingReason::log (OS);
414
424
}
415
425
416
426
std::error_code convertToErrorCode () const override {
417
427
return llvm::inconvertibleErrorCode ();
418
428
}
419
429
};
420
430
421
- class SILEntityError : public llvm ::ErrorInfo<SILEntityError> {
431
+ class SILEntityError : public llvm ::ErrorInfo<SILEntityError>,
432
+ public ErrorWithUnderlyingReason {
422
433
friend ErrorInfo;
423
434
static const char ID;
424
435
void anchor () override ;
425
436
426
- std::unique_ptr<ErrorInfoBase> underlyingReason;
427
437
StringRef name;
428
438
public:
429
439
SILEntityError (StringRef name, std::unique_ptr<ErrorInfoBase> reason)
430
- : underlyingReason (std::move(reason)), name(name) {}
440
+ : ErrorWithUnderlyingReason (std::move(reason)), name(name) {}
431
441
432
442
void log (raw_ostream &OS) const override {
433
443
OS << " could not deserialize SIL entity '" << name << " '" ;
434
- if (underlyingReason) {
435
- OS << " : " ;
436
- underlyingReason->log (OS);
437
- }
444
+ ErrorWithUnderlyingReason::log (OS);
438
445
}
439
446
440
447
std::error_code convertToErrorCode () const override {
0 commit comments