Skip to content

Commit 564de79

Browse files
committed
tidy up errors and warnings
1 parent 5a5de47 commit 564de79

File tree

8 files changed

+65
-93
lines changed

8 files changed

+65
-93
lines changed

CMakeLists.txt

+14-10
Original file line numberDiff line numberDiff line change
@@ -124,12 +124,16 @@ if (MRDOX_CLANG)
124124
target_compile_options(
125125
mrdox_lib
126126
PUBLIC
127-
-Wno-unused-private-field)
127+
-Wno-unused-private-field
128+
-Wno-unused-value
129+
PRIVATE
130+
-Wno-covered-switch-default
131+
)
128132
endif ()
129133

130-
source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} PREFIX "" FILES CMakeLists.txt)
131-
source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR}/include/mrdox PREFIX "include" FILES ${LIB_INCLUDES})
132-
source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR}/source/lib PREFIX "source" FILES ${LIB_SOURCES})
134+
source_group(TREE ${PROJECT_SOURCE_DIR} PREFIX "" FILES CMakeLists.txt)
135+
source_group(TREE ${PROJECT_SOURCE_DIR}/include/mrdox PREFIX "include" FILES ${LIB_INCLUDES})
136+
source_group(TREE ${PROJECT_SOURCE_DIR}/source/lib PREFIX "source" FILES ${LIB_SOURCES})
133137

134138
#-------------------------------------------------
135139
#
@@ -142,8 +146,8 @@ add_executable(mrdox ${TOOL_SOURCES})
142146
target_link_libraries(mrdox PRIVATE mrdox_lib)
143147
target_include_directories(mrdox PRIVATE source/tool)
144148

145-
source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} PREFIX "" FILES CMakeLists.txt)
146-
source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR}/source/tool PREFIX "source" FILES ${TOOL_SOURCES})
149+
source_group(TREE ${PROJECT_SOURCE_DIR} PREFIX "" FILES CMakeLists.txt)
150+
source_group(TREE ${PROJECT_SOURCE_DIR}/source/tool PREFIX "source" FILES ${TOOL_SOURCES})
147151

148152
#-------------------------------------------------
149153
#
@@ -157,10 +161,10 @@ if (MRDOX_BUILD_TESTS)
157161
add_executable(mrdox_tests ${TEST_SOURCES})
158162
target_link_libraries(mrdox_tests PRIVATE mrdox_lib ${llvm_libs})
159163
target_include_directories(mrdox_tests PRIVATE ${PROJECT_SOURCE_DIR}/source/tests)
160-
add_test(NAME mrdox_tests COMMAND mrdox_tests "${CMAKE_CURRENT_SOURCE_DIR}/testfiles")
161-
add_test(NAME mrdox_tests_bare COMMAND mrdox_tests "${CMAKE_CURRENT_SOURCE_DIR}/testfiles/bare")
162-
source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} PREFIX "" FILES CMakeLists.txt)
163-
source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR}/source/tests PREFIX "source" FILES ${TEST_SOURCES})
164+
add_test(NAME mrdox_tests COMMAND mrdox_tests "${PROJECT_SOURCE_DIR}/testfiles")
165+
#add_test(NAME mrdox_tests_bare COMMAND mrdox_tests "${PROJECT_SOURCE_DIR}/testfiles/bare")
166+
source_group(TREE ${PROJECT_SOURCE_DIR} PREFIX "" FILES CMakeLists.txt)
167+
source_group(TREE ${PROJECT_SOURCE_DIR}/source/tests PREFIX "source" FILES ${TEST_SOURCES})
164168
endif()
165169

166170
#-------------------------------------------------

include/mrdox/Corpus.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ class Corpus
7575
*/
7676
[[nodiscard]]
7777
static
78-
std::unique_ptr<Corpus>
78+
llvm::Expected<std::unique_ptr<Corpus>>
7979
build(
8080
tooling::ToolExecutor& ex,
8181
Config const& config,

include/mrdox/Error.hpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ struct makeError : llvm::Error
4949
std::string temp;
5050
llvm::raw_string_ostream os(temp);
5151
os << nice(std::forward<Arg0>(arg0));
52-
(os << ... << nice(std::forward<Args>(args)));
52+
if constexpr(sizeof...(args) > 0)
53+
(os << ... << nice(std::forward<Args>(args)));
5354
os << ' ' << nice(loc);
5455
return makeErrorString(std::move(temp), loc);
5556
}())

include/mrdox/Reporter.hpp

+6-3
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,8 @@ print(
181181
{
182182
llvm::raw_string_ostream os(temp);
183183
os << nice(std::forward<Arg0>(arg));
184-
(os << ... << nice(std::forward<Args>(args)));
184+
if constexpr(sizeof...(args) > 0)
185+
(os << ... << nice(std::forward<Args>(args)));
185186
}
186187
threadSafePrint(llvm::outs(), temp, nullptr);
187188
}
@@ -201,7 +202,8 @@ failed(
201202
llvm::raw_string_ostream os(temp);
202203
os << "error: Couldn't ";
203204
os << nice(std::forward<Arg0>(arg));
204-
(os << ... << nice(std::forward<Args>(args)));
205+
if constexpr(sizeof...(args) > 0)
206+
(os << ... << nice(std::forward<Args>(args)));
205207
os << ".";
206208
}
207209
threadSafePrint(llvm::errs(), temp, &errorCount_);
@@ -226,7 +228,8 @@ error(
226228
llvm::raw_string_ostream os(temp);
227229
os << "error: Couldn't ";
228230
os << nice(std::forward<Arg0>(arg0));
229-
(os << ... << nice(std::forward<Args>(args)));
231+
if constexpr(sizeof...(args) > 0)
232+
(os << ... << nice(std::forward<Args>(args)));
230233
os << " because " << nice(std::forward<E>(e)) << '.';
231234
}
232235
threadSafePrint(llvm::errs(), temp, &errorCount_);

source/lib/Corpus.cpp

+28-63
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "ClangDoc.h"
1515
#include "Serialize.h"
1616
#include <mrdox/Corpus.hpp>
17+
#include <mrdox/Error.hpp>
1718
#include <clang/Tooling/AllTUsExecution.h>
1819
#include <clang/Tooling/CommonOptionsParser.h>
1920
#include <llvm/Support/Mutex.h>
@@ -35,57 +36,45 @@ struct Corpus::Temps
3536
//
3637
//------------------------------------------------
3738

38-
std::unique_ptr<Corpus>
39+
llvm::Expected<std::unique_ptr<Corpus>>
3940
Corpus::
4041
build(
4142
tooling::ToolExecutor& ex,
4243
Config const& config,
4344
Reporter& R)
4445
{
45-
auto up = std::unique_ptr<Corpus>(new Corpus(config));
46-
Corpus& corpus = *up;
46+
std::unique_ptr<Corpus> corpus(new Corpus(config));
4747

4848
// Traverse the AST for all translation units
4949
// and emit serializd bitcode into tool results.
5050
// This operation happens ona thread pool.
51-
5251
if(config.verbose())
53-
llvm::outs() << "Mapping declarations\n";
54-
llvm::Error err = ex.execute(
52+
R.print("Mapping declarations");
53+
if(auto err = ex.execute(
5554
makeToolFactory(*ex.getExecutionContext(), config, R),
56-
config.ArgAdjuster);
57-
if(err)
55+
config.ArgAdjuster))
5856
{
5957
if(! config.IgnoreMappingFailures)
60-
{
61-
llvm::errs() <<
62-
"Mapping failure: " << toString(std::move(err)) << "\n";
63-
return nullptr;
64-
}
65-
66-
llvm::errs() <<
67-
"Error mapping decls in files. "
68-
"MrDox will ignore these files and continue:\n" <<
69-
toString(std::move(err)) << "\n";
58+
return err;
59+
R.print("warning: mapping failed because ", toString(std::move(err)));
7060
}
7161

7262
// Collect the symbols. Each symbol will have
7363
// a vector of one or more bitcodes. These will
7464
// be merged later.
75-
7665
if(config.verbose())
77-
llvm::outs() << "Collecting symbols\n";
66+
R.print("Collecting symbols");
7867
llvm::StringMap<std::vector<StringRef>> USRToBitcode;
7968
ex.getToolResults()->forEachResult(
8069
[&](StringRef Key, StringRef Value)
8170
{
82-
auto R = USRToBitcode.try_emplace(Key, std::vector<StringRef>());
83-
R.first->second.emplace_back(Value);
71+
auto result = USRToBitcode.try_emplace(Key, std::vector<StringRef>());
72+
result.first->second.emplace_back(Value);
8473
});
8574

8675
// First reducing phase (reduce all decls into one info per decl).
8776
if(config.verbose())
88-
llvm::outs() << "Reducing " << USRToBitcode.size() << " declarations\n";
77+
R.print("Reducing ", USRToBitcode.size(), " declarations");
8978
std::atomic<bool> GotFailure;
9079
GotFailure = false;
9180
// VFALCO Should this concurrency be a command line option?
@@ -102,43 +91,38 @@ build(
10291
{
10392
llvm::BitstreamCursor Stream(Bitcode);
10493
ClangDocBitcodeReader Reader(Stream);
105-
auto ReadInfos = Reader.readBitcode();
106-
if(! ReadInfos)
94+
auto infos = Reader.readBitcode();
95+
if(R.error(infos, "read bitcode"))
10796
{
108-
R.failed(ReadInfos.takeError(), "read bitcode");
10997
GotFailure = true;
11098
return;
11199
}
112100
std::move(
113-
ReadInfos->begin(),
114-
ReadInfos->end(),
101+
infos->begin(),
102+
infos->end(),
115103
std::back_inserter(Infos));
116104
}
117105

118-
auto mergeResult = mergeInfos(Infos);
119-
if(R.error(mergeResult, "merge metadata"))
106+
auto merged = mergeInfos(Infos);
107+
if(R.error(merged, "merge metadata"))
120108
{
121-
// VFALCO What about GotFailure?
109+
GotFailure = true;
122110
return;
123111
}
124112

125-
std::unique_ptr<Info> Ip(mergeResult.get().release());
126-
assert(Group.getKey() == llvm::toStringRef(Ip->USR));
127-
corpus.insert(std::move(Ip));
113+
std::unique_ptr<Info> I(merged.get().release());
114+
assert(Group.getKey() == llvm::toStringRef(I->USR));
115+
corpus->insert(std::move(I));
128116
});
129117
}
130118

131119
Pool.wait();
132120

133121
if(config.verbose())
134-
llvm::outs() << "Collected " <<
135-
corpus.InfoMap.size() << " symbols.\n";
122+
R.print("Collected ", corpus->InfoMap.size(), " symbols.\n");
136123

137124
if(GotFailure)
138-
{
139-
R.print("Failed building Corpus");
140-
return nullptr;
141-
}
125+
return makeErrorString("one or more errors occurred");
142126

143127
//
144128
// Finish up
@@ -148,17 +132,17 @@ build(
148132
{
149133
std::string temp[2];
150134
llvm::sort(
151-
corpus.allSymbols,
135+
corpus->allSymbols,
152136
[&](SymbolID const& id0,
153137
SymbolID const& id1) noexcept
154138
{
155-
auto s0 = corpus.get<Info>(id0).getFullyQualifiedName(temp[0]);
156-
auto s1 = corpus.get<Info>(id1).getFullyQualifiedName(temp[1]);
139+
auto s0 = corpus->get<Info>(id0).getFullyQualifiedName(temp[0]);
140+
auto s1 = corpus->get<Info>(id1).getFullyQualifiedName(temp[1]);
157141
return symbolCompare(s0, s1);
158142
});
159143
}
160144

161-
return up;
145+
return corpus;
162146
}
163147

164148
bool
@@ -201,14 +185,6 @@ reportResult(
201185
//
202186
//------------------------------------------------
203187

204-
static
205-
constexpr
206-
char
207-
isalpha(char c) noexcept
208-
{
209-
return ((unsigned int)(c | 32) - 97) < 26U;
210-
}
211-
212188
static
213189
constexpr
214190
unsigned char
@@ -220,17 +196,6 @@ tolower(char c) noexcept
220196
return uc;
221197
}
222198

223-
static
224-
constexpr
225-
unsigned char
226-
toupper(char c) noexcept
227-
{
228-
auto uc = static_cast<unsigned char>(c);
229-
if(uc >= 'a' && uc <= 'z')
230-
return uc - 32;
231-
return uc;
232-
}
233-
234199
bool
235200
Corpus::
236201
symbolCompare(

source/lib/OverloadSet.cpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,10 @@ makeOverloadSet(
4848
if( it == list.end() ||
4949
(*it)->Name != (*it0)->Name)
5050
{
51-
result.emplace_back((*it0)->Name,
52-
std::vector<FunctionInfo const*>(
53-
it0, it));
51+
result.emplace_back(
52+
OverloadSet{
53+
(*it0)->Name,
54+
std::vector<FunctionInfo const*>(it0, it)});
5455
it0 = it;
5556
}
5657
}

source/tests/Tester.cpp

+7-9
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,10 @@ checkDirRecursively(
3535
namespace fs = llvm::sys::fs;
3636
namespace path = llvm::sys::path;
3737

38+
std::error_code ec;
3839
llvm::SmallString<32> outputPath;
3940
path::remove_dots(dirPath, true);
4041
fs::directory_iterator const end{};
41-
42-
std::error_code ec;
4342
fs::directory_iterator iter(dirPath, ec, false);
4443
if(R_.error(ec, "iterate the directory '", dirPath, '.'))
4544
return false;
@@ -48,8 +47,7 @@ checkDirRecursively(
4847
{
4948
if(iter->type() == fs::file_type::directory_file)
5049
{
51-
if(! checkDirRecursively(llvm::StringRef(iter->path()), threadPool))
52-
return false;
50+
checkDirRecursively(llvm::StringRef(iter->path()), threadPool);
5351
}
5452
else if(
5553
iter->type() == fs::file_type::regular_file &&
@@ -66,8 +64,8 @@ checkDirRecursively(
6664
SingleFile db(dirPath, inputPath, outputPath);
6765
tooling::StandaloneToolExecutor ex(db, { std::string(inputPath) });
6866
auto corpus = Corpus::build(ex, config_, R_);
69-
if(corpus)
70-
checkOneFile(*corpus, inputPath, outputPath);
67+
if(! R_.error(corpus, "build corpus for '", inputPath, "'"))
68+
checkOneFile(**corpus, inputPath, outputPath);
7169
});
7270
}
7371
else
@@ -117,13 +115,13 @@ checkOneFile(
117115
auto bufferResult = llvm::MemoryBuffer::getFile(outputPath, false);
118116
if(R_.error(bufferResult, "read the file '", outputPath, "'"))
119117
return;
120-
std::string_view got(bufferResult->get()->getBuffer());
121-
if(xmlString != bufferResult->get()->getBuffer())
118+
std::string_view good(bufferResult->get()->getBuffer());
119+
if(xmlString != good)
122120
{
123121
R_.print(
124122
"File: \"", inputPath, "\" failed.\n",
125123
"Expected:\n",
126-
bufferResult->get()->getBuffer(), "\n",
124+
good, "\n",
127125
"Got:\n", xmlString, "\n");
128126
R_.testFailed();
129127
}

source/tool/ToolMain.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -134,13 +134,13 @@ toolMain(
134134
}
135135

136136
// Run the tool, this can take a while
137-
auto rv = Corpus::build(*ex, **config, R);
138-
if(! rv)
137+
auto corpus = Corpus::build(*ex, **config, R);
138+
if(R.error(corpus, "build the documentation corpus"))
139139
return;
140140

141141
// Run the generator.
142142
llvm::outs() << "Generating docs...\n";
143-
if(! gen->build((*config)->OutDirectory, *rv, **config, R))
143+
if(! gen->build((*config)->OutDirectory, **corpus, **config, R))
144144
return;
145145
}
146146

0 commit comments

Comments
 (0)