|
27 | 27 | namespace clang {
|
28 | 28 | namespace mrdox {
|
29 | 29 |
|
| 30 | +//------------------------------------------------ |
30 | 31 | //
|
31 | 32 | // Error
|
32 | 33 | //
|
| 34 | +//------------------------------------------------ |
33 | 35 |
|
34 | 36 | class Exception;
|
35 | 37 |
|
@@ -339,6 +341,10 @@ class [[nodiscard]]
|
339 | 341 | }
|
340 | 342 | };
|
341 | 343 |
|
| 344 | +//------------------------------------------------ |
| 345 | +// |
| 346 | +// SourceLocation |
| 347 | +// |
342 | 348 | //------------------------------------------------
|
343 | 349 |
|
344 | 350 | /** A source location with filename prettification.
|
@@ -376,6 +382,10 @@ class MRDOX_DECL
|
376 | 382 | }
|
377 | 383 | };
|
378 | 384 |
|
| 385 | +//------------------------------------------------ |
| 386 | +// |
| 387 | +// Implementation |
| 388 | +// |
379 | 389 | //------------------------------------------------
|
380 | 390 |
|
381 | 391 | inline
|
@@ -657,6 +667,140 @@ swap(Expected& rhs) noexcept
|
657 | 667 | swap(has_error_, rhs.has_error_);
|
658 | 668 | }
|
659 | 669 |
|
| 670 | +//------------------------------------------------ |
| 671 | +// |
| 672 | +// Reporting |
| 673 | +// |
| 674 | +//------------------------------------------------ |
| 675 | + |
| 676 | +/** Report an error to the console. |
| 677 | +
|
| 678 | + @param text The message contents. A newline |
| 679 | + will be added automatically to the output. |
| 680 | +*/ |
| 681 | +MRDOX_DECL |
| 682 | +void |
| 683 | +reportError( |
| 684 | + std::string_view text); |
| 685 | + |
| 686 | +/** Format an error to the console. |
| 687 | +
|
| 688 | + @param fs The operation format string. |
| 689 | +
|
| 690 | + @param arg0,args The arguments to use |
| 691 | + with the format string. |
| 692 | +*/ |
| 693 | +template<class Arg0, class... Args> |
| 694 | +void |
| 695 | +reportError( |
| 696 | + fmt::format_string<Arg0, Args...> fs, |
| 697 | + Arg0&& arg0, Args&&... args) |
| 698 | +{ |
| 699 | + reportError(fmt::format(fs, |
| 700 | + std::forward<Arg0>(arg0), |
| 701 | + std::forward<Args>(args)...)); |
| 702 | +} |
| 703 | + |
| 704 | +/** Format an error to the console. |
| 705 | +
|
| 706 | + This function formats an error message |
| 707 | + to the console, of the form: |
| 708 | + @code |
| 709 | + "Could not {1} because {2}." |
| 710 | + @endcode |
| 711 | + Where 1 is the operation which failed, |
| 712 | + specified by the format arguments, and |
| 713 | + 2 is the reason for the failure. |
| 714 | +
|
| 715 | + @param err The error which occurred. |
| 716 | +
|
| 717 | + @param fs The operation format string. |
| 718 | +
|
| 719 | + @param arg0,args The arguments to use |
| 720 | + with the format string. |
| 721 | +*/ |
| 722 | +template<class... Args> |
| 723 | +void |
| 724 | +reportError( |
| 725 | + Error const& err, |
| 726 | + fmt::format_string<Args...> fs, |
| 727 | + Args&&... args) |
| 728 | +{ |
| 729 | + MRDOX_ASSERT(err.failed()); |
| 730 | + reportError(fmt::format( |
| 731 | + "Could not {} because {}", |
| 732 | + fmt::format(fs, std::forward<Args>(args)...), |
| 733 | + err.message())); |
| 734 | +} |
| 735 | + |
| 736 | +/** Report a warning to the console. |
| 737 | +
|
| 738 | + @param text The message contents. A newline |
| 739 | + will be added automatically to the output. |
| 740 | +*/ |
| 741 | +MRDOX_DECL |
| 742 | +void |
| 743 | +reportWarning( |
| 744 | + std::string_view text); |
| 745 | + |
| 746 | +/** Format a warning to the console. |
| 747 | +
|
| 748 | + @param fs The message format string. |
| 749 | + A newline will be added automatically |
| 750 | + to the output. |
| 751 | +
|
| 752 | + @param arg0,args The arguments to use |
| 753 | + with the format string. |
| 754 | +*/ |
| 755 | +template<class Arg0, class... Args> |
| 756 | +void |
| 757 | +reportWarning( |
| 758 | + fmt::format_string<Arg0, Args...> fs, |
| 759 | + Arg0&& arg0, Args&&... args) |
| 760 | +{ |
| 761 | + reportWarning(fmt::format(fs, |
| 762 | + std::forward<Arg0>(arg0), |
| 763 | + std::forward<Args>(args)...)); |
| 764 | +} |
| 765 | + |
| 766 | +/** Report information to the console. |
| 767 | +
|
| 768 | + @param text The message contents. A newline |
| 769 | + will be added automatically to the output. |
| 770 | +*/ |
| 771 | +MRDOX_DECL |
| 772 | +void |
| 773 | +reportInfo( |
| 774 | + std::string_view text); |
| 775 | + |
| 776 | +/** Format information to the console. |
| 777 | +
|
| 778 | + @param fs The message format string. |
| 779 | + A newline will be added automatically |
| 780 | + to the output. |
| 781 | +
|
| 782 | + @param arg0,args The arguments to use |
| 783 | + with the format string. |
| 784 | +*/ |
| 785 | +template<class Arg0, class... Args> |
| 786 | +void |
| 787 | +reportInfo( |
| 788 | + fmt::format_string<Arg0, Args...> fs, |
| 789 | + Arg0&& arg0, Args&&... args) |
| 790 | +{ |
| 791 | + reportInfo(fmt::format(fs, |
| 792 | + std::forward<Arg0>(arg0), |
| 793 | + std::forward<Args>(args)...)); |
| 794 | +} |
| 795 | + |
| 796 | +/** Report an unhandled exception |
| 797 | +*/ |
| 798 | +MRDOX_DECL |
| 799 | +[[noreturn]] |
| 800 | +void |
| 801 | +reportUnhandledException( |
| 802 | + std::exception const& ex); |
| 803 | + |
660 | 804 | //------------------------------------------------
|
661 | 805 |
|
662 | 806 | } // mrdox
|
|
0 commit comments