Skip to content

Commit ce70be6

Browse files
committed
source file refactor
1 parent 12fc21a commit ce70be6

File tree

6 files changed

+87
-129
lines changed

6 files changed

+87
-129
lines changed

include/mrdox/Error.hpp

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
#ifndef MRDOX_ERROR_HPP
1313
#define MRDOX_ERROR_HPP
1414

15-
#include <mrdox/detail/nice.hpp>
1615
#include <llvm/Support/Error.h>
1716
#include <llvm/Support/raw_ostream.h>
1817
#include <source_location>
@@ -21,6 +20,47 @@
2120
namespace clang {
2221
namespace mrdox {
2322

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+
2464
/** Return an Error with descriptive information.
2565
2666
@param reason A phrase describing the cause of the failure.
@@ -45,7 +85,6 @@ struct makeError : llvm::Error
4585
: llvm::Error(
4686
[&]
4787
{
48-
using detail::nice;
4988
std::string temp;
5089
llvm::raw_string_ostream os(temp);
5190
os << nice(std::forward<Arg0>(arg0));

include/mrdox/Reporter.hpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#ifndef MRDOX_REPORTER_HPP
1313
#define MRDOX_REPORTER_HPP
1414

15-
#include <mrdox/detail/nice.hpp>
15+
#include <mrdox/Error.hpp>
1616
#include <llvm/Support/Error.h>
1717
#include <llvm/Support/Mutex.h>
1818
#include <llvm/Support/raw_ostream.h>
@@ -164,7 +164,6 @@ print(
164164
Arg0&& arg,
165165
Args&&... args)
166166
{
167-
using detail::nice;
168167
auto& temp = temp_string();
169168
temp.clear();
170169
{
@@ -184,7 +183,6 @@ failed(
184183
Arg0&& arg,
185184
Args&&... args)
186185
{
187-
using detail::nice;
188186
auto& temp = temp_string();
189187
temp.clear();
190188
{
@@ -208,7 +206,6 @@ error(
208206
Arg0&& arg0,
209207
Args&&... args)
210208
{
211-
using detail::nice;
212209
if(! isFailure(std::forward<E>(e)))
213210
return false;
214211
auto& temp = temp_string();

include/mrdox/detail/nice.hpp

Lines changed: 0 additions & 58 deletions
This file was deleted.

source/lib/Error.cpp

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,54 @@
1111

1212
#include <mrdox/Error.hpp>
1313
#include <mrdox/Reporter.hpp>
14+
#include <llvm/Support/Path.h>
1415
#include <utility>
1516

1617
namespace clang {
1718
namespace mrdox {
1819

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+
1962
namespace {
2063

2164
class ErrorInfoPlus
@@ -39,7 +82,7 @@ class ErrorInfoPlus
3982
log(
4083
llvm::raw_ostream &os) const override
4184
{
42-
os << action_ << " at " << detail::nice(loc_);
85+
os << action_ << " at " << nice(loc_);
4386
}
4487

4588
std::error_code

source/lib/_adoc/PagesBuilder.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
//
1010

1111
#include "PagesBuilder.hpp"
12-
#include "format/radix.hpp"
12+
#include "radix.hpp"
1313
#include <mrdox/Metadata.hpp>
1414
#include <llvm/ADT/STLExtras.h>
1515
#include <llvm/Support/FileSystem.h>

source/lib/detail/nice.cpp

Lines changed: 0 additions & 63 deletions
This file was deleted.

0 commit comments

Comments
 (0)