Skip to content

Commit d3fd9e6

Browse files
committed
chore: refactor reporting call sites
1 parent 4d12651 commit d3fd9e6

34 files changed

+93
-192
lines changed

include/mrdox/Support/Error.hpp

-62
Original file line numberDiff line numberDiff line change
@@ -891,66 +891,6 @@ fatal(
891891

892892
//------------------------------------------------
893893

894-
/** Report an error to the console.
895-
896-
@param text The message contents. A newline
897-
will be added automatically to the output.
898-
*/
899-
MRDOX_DECL
900-
void
901-
reportError(
902-
std::string_view text);
903-
904-
/** Format an error to the console.
905-
906-
@param fs The operation format string.
907-
908-
@param arg0,args The arguments to use
909-
with the format string.
910-
*/
911-
template<class Arg0, class... Args>
912-
void
913-
reportError(
914-
fmt::format_string<Arg0, Args...> fs,
915-
Arg0&& arg0, Args&&... args)
916-
{
917-
reportError(fmt::format(fs,
918-
std::forward<Arg0>(arg0),
919-
std::forward<Args>(args)...));
920-
}
921-
922-
/** Format an error to the console.
923-
924-
This function formats an error message
925-
to the console, of the form:
926-
@code
927-
"Could not {1} because {2}."
928-
@endcode
929-
Where 1 is the operation which failed,
930-
specified by the format arguments, and
931-
2 is the reason for the failure.
932-
933-
@param err The error which occurred.
934-
935-
@param fs The operation format string.
936-
937-
@param arg0,args The arguments to use
938-
with the format string.
939-
*/
940-
template<class... Args>
941-
void
942-
reportError(
943-
Error const& err,
944-
fmt::format_string<Args...> fs,
945-
Args&&... args)
946-
{
947-
MRDOX_ASSERT(err.failed());
948-
reportError(fmt::format(
949-
"Could not {} because {}",
950-
fmt::format(fs, std::forward<Args>(args)...),
951-
err.message()));
952-
}
953-
954894
/** Report an unhandled exception
955895
*/
956896
MRDOX_DECL
@@ -959,8 +899,6 @@ void
959899
reportUnhandledException(
960900
std::exception const& ex);
961901

962-
//------------------------------------------------
963-
964902
} // mrdox
965903
} // clang
966904

lib/-XML/XMLWriter.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
#include "CXXTags.hpp"
1414
#include "XMLWriter.hpp"
15-
#include "Tool/ConfigImpl.hpp"
15+
#include "Lib/ConfigImpl.hpp"
1616
#include "Support/Yaml.hpp"
1717
#include "Support/Radix.hpp"
1818
#include "Support/SafeNames.hpp"

lib/-adoc/AdocGenerator.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ buildOne(
108108
return Error(errors);
109109

110110
ex->async(
111-
[ &os](Builder& builder)
111+
[&os](Builder& builder)
112112
{
113113
auto pageText = builder.renderSinglePageFooter().value();
114114
os.write(pageText.data(), pageText.size());

lib/-adoc/Options.cpp

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

1212
#include "Options.hpp"
1313
#include "Support/Yaml.hpp"
14-
#include "Tool/ConfigImpl.hpp" // VFALCO This is a problem
14+
#include "Lib/ConfigImpl.hpp" // VFALCO This is a problem
1515
#include <mrdox/Corpus.hpp>
1616
#include <mrdox/Support/Path.hpp>
1717
#include <llvm/Support/YAMLParser.h>

lib/-bitcode/BitcodeGenerator.cpp

+5-9
Original file line numberDiff line numberDiff line change
@@ -65,17 +65,13 @@ class MultiFileBuilder
6565
std::error_code ec;
6666
llvm::raw_fd_ostream os(filePath, ec, fs::CD_CreateAlways);
6767
if(ec)
68-
{
69-
reportError(Error(ec), "open \"{}\"", filePath);
70-
return;
71-
}
68+
Error(ec).Throw();
7269
auto bc = writeBitcode(I);
73-
if(auto ec = os.error())
74-
{
75-
reportError(Error(ec), "write \"{}\"", filePath);
76-
return;
77-
}
70+
if((ec = os.error()))
71+
Error(ec).Throw();
7872
os.write(bc.data.data(), bc.data.size());
73+
if((ec = os.error()))
74+
Error(ec).Throw();
7975
});
8076

8177
if constexpr(T::isRecord())

lib/AST/ASTVisitor.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#include "ParseJavadoc.hpp"
1717
#include "Support/Path.hpp"
1818
#include "Support/Debug.hpp"
19-
#include "Tool/Diagnostics.hpp"
19+
#include "Lib/Diagnostics.hpp"
2020
#include <mrdox/Metadata.hpp>
2121
#include <clang/AST/Attr.h>
2222
#include <clang/AST/Decl.h>

lib/AST/ASTVisitor.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
#ifndef MRDOX_TOOL_AST_ASTVISITOR_HPP
1414
#define MRDOX_TOOL_AST_ASTVISITOR_HPP
1515

16-
#include "Tool/ConfigImpl.hpp"
17-
#include "Tool/ExecutionContext.hpp"
16+
#include "Lib/ConfigImpl.hpp"
17+
#include "Lib/ExecutionContext.hpp"
1818
#include <mrdox/Platform.hpp>
1919
#include <clang/Tooling/Execution.h>
2020
#include <clang/Tooling/Tooling.h>

lib/AST/ParseJavadoc.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ visitHTMLStartTagComment(
271271
if(end_ - it_ < 3)
272272
{
273273
// error
274-
reportError(
274+
report::error(
275275
"warning: invalid HTML <a> tag at {}({})",
276276
files::makePosixStyle(loc.getFilename()),
277277
loc.getLine());

lib/Tool/AbsoluteCompilationDatabase.cpp renamed to lib/Lib/AbsoluteCompilationDatabase.cpp

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

1212
#include "Support/Debug.hpp"
1313
#include "Support/Path.hpp"
14-
#include "Tool/ConfigImpl.hpp"
15-
#include "Tool/AbsoluteCompilationDatabase.hpp"
14+
#include "Lib/ConfigImpl.hpp"
15+
#include "Lib/AbsoluteCompilationDatabase.hpp"
1616
#include <fmt/format.h>
1717
#include <clang/Basic/LangStandard.h>
1818
#include <clang/Driver/Driver.h>

lib/Tool/Config.cpp renamed to lib/Lib/Config.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// Official repository: https://github.com/cppalliance/mrdox
1010
//
1111

12-
#include "Tool/ConfigImpl.hpp"
12+
#include "Lib/ConfigImpl.hpp"
1313
#include "Support/Path.hpp"
1414
#include <mrdox/Support/Error.hpp>
1515
#include <llvm/Config/llvm-config.h>

lib/Tool/ConfigImpl.cpp renamed to lib/Lib/ConfigImpl.cpp

+7-5
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// Official repository: https://github.com/cppalliance/mrdox
1010
//
1111

12-
#include "Tool/ConfigImpl.hpp"
12+
#include "Lib/ConfigImpl.hpp"
1313
#include "Support/Debug.hpp"
1414
#include "Support/Error.hpp"
1515
#include "Support/Path.hpp"
@@ -83,10 +83,12 @@ ConfigImpl(
8383
formatError("working path \"{}\" is not absolute", workingDir_).Throw();
8484
settings_.workingDir = files::makeDirsy(files::normalizePath(workingDir_));
8585

86-
if(auto err = files::requireDirectory(addonsDir_))
87-
formatError("addons path \"{}\" is not absolute", addonsDir_).Throw();
88-
MRDOX_ASSERT(files::isDirsy(addonsDir_));
89-
settings_.addonsDir = addonsDir_;
86+
// Addons directory
87+
{
88+
settings_.addonsDir = files::makeAbsolute(addonsDir_).value();
89+
files::requireDirectory(settings_.addonsDir).maybeThrow();
90+
MRDOX_ASSERT(files::isDirsy(settings_.addonsDir));
91+
}
9092

9193
settings_.configYaml = configYaml_;
9294
settings_.extraYaml = extraYaml_;

lib/Tool/ConfigImpl.hpp renamed to lib/Lib/ConfigImpl.hpp

+15-9
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,11 @@ class ConfigImpl
166166
for calculating filenames from relative
167167
paths.
168168
169-
@param addonsDir A valid directory to determine
170-
the location of the addons/ folder.
171-
This must be an absolute path.
169+
@param addonsDir An optional, valid directory
170+
to determine the location of the addons/ folder.
171+
If the path is not absolute, it will be resolved
172+
relative to the current working directory of
173+
the process.
172174
173175
@param configYaml A string containing valid
174176
YAML which will be parsed and applied to create
@@ -210,9 +212,11 @@ createConfigFromYAML(
210212
directory of the process. POSIX or Windows style
211213
path separators are accepted.
212214
213-
@param addonsDir A valid directory to determine
214-
the location of the addons/ folder.
215-
This must be an absolute path.
215+
@param addonsDir An optional, valid directory
216+
to determine the location of the addons/ folder.
217+
If the path is not absolute, it will be resolved
218+
relative to the current working directory of
219+
the process.
216220
217221
@param extraYaml An optional string containing
218222
additional valid YAML which will be parsed and
@@ -247,9 +251,11 @@ loadConfigFile(
247251
calculating filenames from relative paths.
248252
This must be an absolute path.
249253
250-
@param addonsDir A valid directory to determine
251-
the location of the addons/ folder.
252-
This must be an absolute path.
254+
@param addonsDir An optional, valid directory
255+
to determine the location of the addons/ folder.
256+
If the path is not absolute, it will be resolved
257+
relative to the current working directory of
258+
the process.
253259
254260
@param configYaml A string containing valid
255261
YAML which will be parsed and applied to create

lib/Tool/Corpus.cpp renamed to lib/Lib/Corpus.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// Official repository: https://github.com/cppalliance/mrdox
1010
//
1111

12-
#include "Tool/ConfigImpl.hpp"
12+
#include "Lib/ConfigImpl.hpp"
1313
#include <mrdox/Corpus.hpp>
1414
#include <mrdox/Metadata.hpp>
1515
#include <mrdox/Support/Error.hpp>

lib/Tool/CorpusImpl.cpp renamed to lib/Lib/CorpusImpl.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ build(
152152
auto infos = readBitcode(bitcode);
153153
if(! infos)
154154
{
155-
reportError(infos.error(), "read bitcode");
155+
report::error("{}: reading bitcode", infos.error());
156156
GotFailure = true;
157157
return;
158158
}
@@ -165,7 +165,7 @@ build(
165165
auto merged = mergeInfos(Infos);
166166
if(! merged)
167167
{
168-
reportError(toError(merged.takeError()), "merge metadata");
168+
report::error("{}: merging metadata", toError(merged.takeError()));
169169
GotFailure = true;
170170
return;
171171
}

lib/Tool/CorpusImpl.hpp renamed to lib/Lib/CorpusImpl.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
#ifndef MRDOX_TOOL_CORPUSIMPL_HPP
1212
#define MRDOX_TOOL_CORPUSIMPL_HPP
1313

14-
#include "Tool/ConfigImpl.hpp"
15-
#include "Tool/ToolExecutor.hpp"
14+
#include "Lib/ConfigImpl.hpp"
15+
#include "Lib/ToolExecutor.hpp"
1616
#include "Support/Debug.hpp"
1717
#include <mrdox/Corpus.hpp>
1818
#include <mrdox/Metadata.hpp>

lib/Tool/Diagnostics.hpp renamed to lib/Lib/Diagnostics.hpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,15 @@ class Diagnostics
2727
std::unordered_map<std::string, bool> messages_;
2828

2929
public:
30-
void reportError(std::string s)
30+
void error(std::string s)
3131
{
3232
auto result =
3333
messages_.emplace(std::move(s), true);
3434
if(result.second)
3535
++errorCount_;
3636
}
3737

38-
void reportWarning(std::string s)
38+
void warn(std::string s)
3939
{
4040
messages_.emplace(std::move(s), false);
4141
}
@@ -66,7 +66,7 @@ class Diagnostics
6666
{
6767
os << "No errors or warnings.\n";
6868
}
69-
report::print_impl(level, s, nullptr);
69+
report::print_impl(level, s);
7070
}
7171

7272
void
File renamed without changes.
File renamed without changes.
File renamed without changes.

lib/Tool/ToolExecutor.cpp renamed to lib/Lib/ToolExecutor.cpp

+1-7
Original file line numberDiff line numberDiff line change
@@ -110,12 +110,6 @@ execute(
110110
ErrorMsg += Err.str();
111111
};
112112

113-
auto Log = [&](llvm::Twine Msg)
114-
{
115-
std::unique_lock<std::mutex> LockGuard(TUMutex);
116-
llvm::errs() << Msg.str() << "\n";
117-
};
118-
119113
// Get a copy of the filename strings
120114
std::vector<std::string> Files = Compilations.getAllFiles();
121115

@@ -187,7 +181,7 @@ execute(
187181
Context.reportEnd(reportLevel_);
188182

189183
if(! errors.empty())
190-
reportError(errors, "Could not run the tool executor");
184+
return makeError(Error(errors).message());
191185

192186
if (!ErrorMsg.empty())
193187
return makeError(ErrorMsg);
File renamed without changes.

lib/Support/Error.cpp

-8
Original file line numberDiff line numberDiff line change
@@ -226,14 +226,6 @@ call_impl(
226226

227227
//------------------------------------------------
228228

229-
void
230-
reportError(
231-
std::string_view text)
232-
{
233-
std::lock_guard<llvm::sys::Mutex> lock(reportMutex_);
234-
llvm::errs() << text << '\n';
235-
}
236-
237229
void
238230
reportUnhandledException(
239231
std::exception const& ex)

test/TestArgs.cpp

-14
Original file line numberDiff line numberDiff line change
@@ -30,29 +30,16 @@ R"(MrDox Test Program
3030

3131
, extraHelp(
3232
R"(
33-
ADDONS:
34-
The location of the addons directory is determined in this order:
35-
36-
1. The --addons command line argument if present, or
37-
2. The directory containing the mrdox tool executable, otherwise
38-
3. The environment variable MRDOX_ADDONS_DIR if set.
39-
4033
EXAMPLES:
4134
mrdox-test .. ( compile-commands )
4235
mrdox-test .. --action ( "test" | "create" | "update" ) ( dir | file )...
4336
mrdox-test --action test friend.cpp
44-
mrdox-test --format adoc compile_commands.json
4537
)")
4638

4739
//
4840
// Common options
4941
//
5042

51-
, addonsDir(
52-
"addons",
53-
llvm::cl::desc("The path to the addons directory."),
54-
llvm::cl::cat(commonCat))
55-
5643
, reportLevel(
5744
"report",
5845
llvm::cl::desc("The minimum reporting level (0 to 4)."),
@@ -101,7 +88,6 @@ hideForeignOptions()
10188

10289
std::vector<llvm::cl::Option const*> ours({
10390
&action,
104-
&addonsDir,
10591
std::addressof(inputPaths),
10692
&badOption,
10793
&unitOption

test/TestArgs.hpp

-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ class TestArgs
3939
llvm::cl::extrahelp extraHelp;
4040

4141
// Common options
42-
llvm::cl::opt<std::string> addonsDir;
4342
llvm::cl::opt<unsigned> reportLevel;
4443

4544
// Test options

0 commit comments

Comments
 (0)