Skip to content

Commit 1eda403

Browse files
committed
chore: reporting is in Error.hpp
close #363, fix #365
1 parent 22ea97a commit 1eda403

17 files changed

+213
-230
lines changed

include/mrdox/Support/Error.hpp

+144
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,11 @@
2727
namespace clang {
2828
namespace mrdox {
2929

30+
//------------------------------------------------
3031
//
3132
// Error
3233
//
34+
//------------------------------------------------
3335

3436
class Exception;
3537

@@ -339,6 +341,10 @@ class [[nodiscard]]
339341
}
340342
};
341343

344+
//------------------------------------------------
345+
//
346+
// SourceLocation
347+
//
342348
//------------------------------------------------
343349

344350
/** A source location with filename prettification.
@@ -376,6 +382,10 @@ class MRDOX_DECL
376382
}
377383
};
378384

385+
//------------------------------------------------
386+
//
387+
// Implementation
388+
//
379389
//------------------------------------------------
380390

381391
inline
@@ -657,6 +667,140 @@ swap(Expected& rhs) noexcept
657667
swap(has_error_, rhs.has_error_);
658668
}
659669

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+
660804
//------------------------------------------------
661805

662806
} // mrdox

include/mrdox/Support/Report.hpp

-153
This file was deleted.

source/-adoc/AdocGenerator.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
#include "SinglePageVisitor.hpp"
1717
#include "Support/SafeNames.hpp"
1818
#include <mrdox/Metadata/DomMetadata.hpp>
19+
#include <mrdox/Support/Error.hpp>
1920
#include <mrdox/Support/Path.hpp>
20-
#include <mrdox/Support/Report.hpp>
2121
#include <optional>
2222
#include <vector>
2323

source/-bitcode/BitcodeGenerator.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
#include "Support/Error.hpp"
1414
#include "Support/SafeNames.hpp"
1515
#include "AST/Bitcode.hpp"
16-
#include <mrdox/Support/Report.hpp>
1716
#include <mrdox/Support/ThreadPool.hpp>
1817
#include <mrdox/Metadata.hpp>
1918

source/AST/ParseJavadoc.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111

1212
#include "ParseJavadoc.hpp"
1313
#include <mrdox/Metadata/Javadoc.hpp>
14+
#include <mrdox/Support/Error.hpp>
1415
#include <mrdox/Support/Path.hpp>
15-
#include <mrdox/Support/Report.hpp>
1616
#include <mrdox/Support/String.hpp>
1717
#include <clang/AST/CommentCommandTraits.h>
1818
#include <clang/AST/ASTContext.h>

0 commit comments

Comments
 (0)