14
14
#include " ClangDoc.h"
15
15
#include " Serialize.h"
16
16
#include < mrdox/Corpus.hpp>
17
+ #include < mrdox/Error.hpp>
17
18
#include < clang/Tooling/AllTUsExecution.h>
18
19
#include < clang/Tooling/CommonOptionsParser.h>
19
20
#include < llvm/Support/Mutex.h>
@@ -35,57 +36,45 @@ struct Corpus::Temps
35
36
//
36
37
// ------------------------------------------------
37
38
38
- std::unique_ptr<Corpus>
39
+ llvm::Expected< std::unique_ptr<Corpus> >
39
40
Corpus::
40
41
build (
41
42
tooling::ToolExecutor& ex,
42
43
Config const & config,
43
44
Reporter& R)
44
45
{
45
- auto up = std::unique_ptr<Corpus>(new Corpus (config));
46
- Corpus& corpus = *up;
46
+ std::unique_ptr<Corpus> corpus (new Corpus (config));
47
47
48
48
// Traverse the AST for all translation units
49
49
// and emit serializd bitcode into tool results.
50
50
// This operation happens ona thread pool.
51
-
52
51
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 (
55
54
makeToolFactory (*ex.getExecutionContext (), config, R),
56
- config.ArgAdjuster );
57
- if (err)
55
+ config.ArgAdjuster ))
58
56
{
59
57
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)));
70
60
}
71
61
72
62
// Collect the symbols. Each symbol will have
73
63
// a vector of one or more bitcodes. These will
74
64
// be merged later.
75
-
76
65
if (config.verbose ())
77
- llvm::outs () << " Collecting symbols\n " ;
66
+ R. print ( " Collecting symbols" ) ;
78
67
llvm::StringMap<std::vector<StringRef>> USRToBitcode;
79
68
ex.getToolResults ()->forEachResult (
80
69
[&](StringRef Key, StringRef Value)
81
70
{
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);
84
73
});
85
74
86
75
// First reducing phase (reduce all decls into one info per decl).
87
76
if (config.verbose ())
88
- llvm::outs () << " Reducing " << USRToBitcode.size () << " declarations\n " ;
77
+ R. print ( " Reducing " , USRToBitcode.size (), " declarations" ) ;
89
78
std::atomic<bool > GotFailure;
90
79
GotFailure = false ;
91
80
// VFALCO Should this concurrency be a command line option?
@@ -102,43 +91,38 @@ build(
102
91
{
103
92
llvm::BitstreamCursor Stream (Bitcode);
104
93
ClangDocBitcodeReader Reader (Stream);
105
- auto ReadInfos = Reader.readBitcode ();
106
- if (! ReadInfos )
94
+ auto infos = Reader.readBitcode ();
95
+ if (R. error (infos, " read bitcode " ) )
107
96
{
108
- R.failed (ReadInfos.takeError (), " read bitcode" );
109
97
GotFailure = true ;
110
98
return ;
111
99
}
112
100
std::move (
113
- ReadInfos ->begin (),
114
- ReadInfos ->end (),
101
+ infos ->begin (),
102
+ infos ->end (),
115
103
std::back_inserter (Infos));
116
104
}
117
105
118
- auto mergeResult = mergeInfos (Infos);
119
- if (R.error (mergeResult , " merge metadata" ))
106
+ auto merged = mergeInfos (Infos);
107
+ if (R.error (merged , " merge metadata" ))
120
108
{
121
- // VFALCO What about GotFailure?
109
+ GotFailure = true ;
122
110
return ;
123
111
}
124
112
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 ));
128
116
});
129
117
}
130
118
131
119
Pool.wait ();
132
120
133
121
if (config.verbose ())
134
- llvm::outs () << " Collected " <<
135
- corpus.InfoMap .size () << " symbols.\n " ;
122
+ R.print (" Collected " , corpus->InfoMap .size (), " symbols.\n " );
136
123
137
124
if (GotFailure)
138
- {
139
- R.print (" Failed building Corpus" );
140
- return nullptr ;
141
- }
125
+ return makeErrorString (" one or more errors occurred" );
142
126
143
127
//
144
128
// Finish up
@@ -148,17 +132,17 @@ build(
148
132
{
149
133
std::string temp[2 ];
150
134
llvm::sort (
151
- corpus. allSymbols ,
135
+ corpus-> allSymbols ,
152
136
[&](SymbolID const & id0,
153
137
SymbolID const & id1) noexcept
154
138
{
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 ]);
157
141
return symbolCompare (s0, s1);
158
142
});
159
143
}
160
144
161
- return up ;
145
+ return corpus ;
162
146
}
163
147
164
148
bool
@@ -201,14 +185,6 @@ reportResult(
201
185
//
202
186
// ------------------------------------------------
203
187
204
- static
205
- constexpr
206
- char
207
- isalpha (char c) noexcept
208
- {
209
- return ((unsigned int )(c | 32 ) - 97 ) < 26U ;
210
- }
211
-
212
188
static
213
189
constexpr
214
190
unsigned char
@@ -220,17 +196,6 @@ tolower(char c) noexcept
220
196
return uc;
221
197
}
222
198
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
-
234
199
bool
235
200
Corpus::
236
201
symbolCompare (
0 commit comments