File tree Expand file tree Collapse file tree 6 files changed +87
-129
lines changed Expand file tree Collapse file tree 6 files changed +87
-129
lines changed Original file line number Diff line number Diff line change 12
12
#ifndef MRDOX_ERROR_HPP
13
13
#define MRDOX_ERROR_HPP
14
14
15
- #include < mrdox/detail/nice.hpp>
16
15
#include < llvm/Support/Error.h>
17
16
#include < llvm/Support/raw_ostream.h>
18
17
#include < source_location>
21
20
namespace clang {
22
21
namespace mrdox {
23
22
23
+ // ------------------------------------------------
24
+ /*
25
+ nice output for variadic error functions
26
+
27
+ These are used to convert arguments to
28
+ strings in makeError and Reporter members.
29
+ */
30
+
31
+ template <class T >
32
+ T& nice (T& t)
33
+ {
34
+ return t;
35
+ }
36
+
37
+ template <class T >
38
+ T&& nice(T&& t)
39
+ {
40
+ return std::forward<T>(t);
41
+ }
42
+
43
+ template <class T >
44
+ auto nice (llvm::Expected<T>&& e)
45
+ {
46
+ return nice (e.takeError ());
47
+ }
48
+
49
+ inline auto nice (std::error_code ec)
50
+ {
51
+ return ec.message ();
52
+ }
53
+
54
+ template <class T >
55
+ auto nice (llvm::ErrorOr<T>&& e)
56
+ {
57
+ return nice (e.getError ());
58
+ }
59
+
60
+ llvm::StringRef nice (std::source_location loc);
61
+
62
+ // ------------------------------------------------
63
+
24
64
/* * Return an Error with descriptive information.
25
65
26
66
@param reason A phrase describing the cause of the failure.
@@ -45,7 +85,6 @@ struct makeError : llvm::Error
45
85
: llvm::Error(
46
86
[&]
47
87
{
48
- using detail::nice;
49
88
std::string temp;
50
89
llvm::raw_string_ostream os (temp);
51
90
os << nice (std::forward<Arg0>(arg0));
Original file line number Diff line number Diff line change 12
12
#ifndef MRDOX_REPORTER_HPP
13
13
#define MRDOX_REPORTER_HPP
14
14
15
- #include < mrdox/detail/nice .hpp>
15
+ #include < mrdox/Error .hpp>
16
16
#include < llvm/Support/Error.h>
17
17
#include < llvm/Support/Mutex.h>
18
18
#include < llvm/Support/raw_ostream.h>
@@ -164,7 +164,6 @@ print(
164
164
Arg0&& arg,
165
165
Args&&... args)
166
166
{
167
- using detail::nice;
168
167
auto & temp = temp_string ();
169
168
temp.clear ();
170
169
{
@@ -184,7 +183,6 @@ failed(
184
183
Arg0&& arg,
185
184
Args&&... args)
186
185
{
187
- using detail::nice;
188
186
auto & temp = temp_string ();
189
187
temp.clear ();
190
188
{
@@ -208,7 +206,6 @@ error(
208
206
Arg0&& arg0,
209
207
Args&&... args)
210
208
{
211
- using detail::nice;
212
209
if (! isFailure (std::forward<E>(e)))
213
210
return false ;
214
211
auto & temp = temp_string ();
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 11
11
12
12
#include < mrdox/Error.hpp>
13
13
#include < mrdox/Reporter.hpp>
14
+ #include < llvm/Support/Path.h>
14
15
#include < utility>
15
16
16
17
namespace clang {
17
18
namespace mrdox {
18
19
20
+ llvm::StringRef
21
+ nice (
22
+ std::source_location loc)
23
+ {
24
+ namespace path = llvm::sys::path;
25
+
26
+ static thread_local llvm::SmallString<0 > temp;
27
+
28
+ llvm::StringRef fileName (loc.file_name ());
29
+ auto it = path::rbegin (fileName);
30
+ auto const end = path::rend (fileName);
31
+ if (it == end)
32
+ {
33
+ temp.clear ();
34
+ return {};
35
+ }
36
+ for (;;)
37
+ {
38
+ // VFALCO This assumes the directory
39
+ // layout of the source files.
40
+ if ( *it == " source" ||
41
+ *it == " include" )
42
+ {
43
+ temp.assign (
44
+ it->data (),
45
+ fileName.end ());
46
+ break ;
47
+ }
48
+ ++it;
49
+ if (it == end)
50
+ {
51
+ temp = fileName;
52
+ break ;
53
+ }
54
+ }
55
+ path::remove_dots (temp, true );
56
+ temp.push_back (' (' );
57
+ temp.append (std::to_string (loc.line ()));
58
+ temp.push_back (' )' );
59
+ return temp;
60
+ }
61
+
19
62
namespace {
20
63
21
64
class ErrorInfoPlus
@@ -39,7 +82,7 @@ class ErrorInfoPlus
39
82
log (
40
83
llvm::raw_ostream &os) const override
41
84
{
42
- os << action_ << " at " << detail:: nice (loc_);
85
+ os << action_ << " at " << nice (loc_);
43
86
}
44
87
45
88
std::error_code
Original file line number Diff line number Diff line change 9
9
//
10
10
11
11
#include " PagesBuilder.hpp"
12
- #include " format/ radix.hpp"
12
+ #include " radix.hpp"
13
13
#include < mrdox/Metadata.hpp>
14
14
#include < llvm/ADT/STLExtras.h>
15
15
#include < llvm/Support/FileSystem.h>
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments