|
9 | 9 | // Official repository: https://github.com/cppalliance/mrdox
|
10 | 10 | //
|
11 | 11 |
|
12 |
| -#include "CorpusImpl.hpp" |
13 | 12 | #include "ConfigImpl.hpp"
|
14 |
| -#include "AST/Bitcode.hpp" |
15 |
| -#include "AST/FrontendAction.hpp" |
16 |
| -#include "Metadata/Reduce.hpp" |
17 |
| -#include "Support/Error.hpp" |
| 13 | +#include <mrdox/Corpus.hpp> |
18 | 14 | #include <mrdox/Support/Report.hpp>
|
19 | 15 | #include <mrdox/Metadata.hpp>
|
20 |
| -#include <clang/Tooling/ArgumentsAdjusters.h> |
21 |
| -#include <clang/Tooling/CommonOptionsParser.h> |
22 |
| -#include <llvm/Bitstream/BitstreamReader.h> |
23 |
| -#include <llvm/Support/Mutex.h> |
24 | 16 | #include <cassert>
|
25 | 17 |
|
26 | 18 | namespace clang {
|
27 | 19 | namespace mrdox {
|
28 | 20 |
|
29 |
| -// A standalone function to call to merge a vector of infos into one. |
30 |
| -// This assumes that all infos in the vector are of the same type, and will fail |
31 |
| -// if they are different. |
32 |
| -// Dispatch function. |
33 |
| -llvm::Expected<std::unique_ptr<Info>> |
34 |
| -mergeInfos(std::vector<std::unique_ptr<Info>>& Values) |
35 |
| -{ |
36 |
| - if (Values.empty() || !Values[0]) |
37 |
| - return llvm::createStringError(llvm::inconvertibleErrorCode(), |
38 |
| - "no info values to merge"); |
39 |
| - |
40 |
| - switch (Values[0]->Kind) { |
41 |
| - case InfoKind::Namespace: |
42 |
| - return reduce<NamespaceInfo>(Values); |
43 |
| - case InfoKind::Record: |
44 |
| - return reduce<RecordInfo>(Values); |
45 |
| - case InfoKind::Enum: |
46 |
| - return reduce<EnumInfo>(Values); |
47 |
| - case InfoKind::Function: |
48 |
| - return reduce<FunctionInfo>(Values); |
49 |
| - case InfoKind::Typedef: |
50 |
| - return reduce<TypedefInfo>(Values); |
51 |
| - case InfoKind::Variable: |
52 |
| - return reduce<VarInfo>(Values); |
53 |
| - case InfoKind::Field: |
54 |
| - return reduce<FieldInfo>(Values); |
55 |
| - default: |
56 |
| - return llvm::createStringError(llvm::inconvertibleErrorCode(), |
57 |
| - "unexpected info type"); |
58 |
| - } |
59 |
| -} |
60 |
| - |
61 | 21 | //------------------------------------------------
|
62 | 22 |
|
63 | 23 | Corpus::~Corpus() noexcept = default;
|
@@ -285,113 +245,6 @@ traverse(
|
285 | 245 | //
|
286 | 246 | //------------------------------------------------
|
287 | 247 |
|
288 |
| -Expected<std::unique_ptr<Corpus>> |
289 |
| -Corpus:: |
290 |
| -build( |
291 |
| - tooling::ToolExecutor& ex, |
292 |
| - std::shared_ptr<Config const> config_) |
293 |
| -{ |
294 |
| - auto config = std::dynamic_pointer_cast<ConfigImpl const>(config_); |
295 |
| - auto corpus = std::make_unique<CorpusImpl>(config); |
296 |
| - |
297 |
| - // Build arguments adjuster |
298 |
| - tooling::ArgumentsAdjuster ArgAdjuster; |
299 |
| - { |
300 |
| - for(auto const& define : config->additionalDefines_) |
301 |
| - { |
302 |
| - std::string s; |
303 |
| - llvm::raw_string_ostream os(s); |
304 |
| - os << "-D" << define; |
305 |
| - ArgAdjuster = tooling::combineAdjusters( |
306 |
| - tooling::getInsertArgumentAdjuster( |
307 |
| - s.c_str(), tooling::ArgumentInsertPosition::END), |
308 |
| - ArgAdjuster); |
309 |
| - } |
310 |
| - } |
311 |
| - |
312 |
| - // Traverse the AST for all translation units |
313 |
| - // and emit serializd bitcode into tool results. |
314 |
| - // This operation happens ona thread pool. |
315 |
| - if(corpus->config.verboseOutput) |
316 |
| - reportInfo("Mapping declarations"); |
317 |
| - if(auto err = ex.execute( |
318 |
| - makeFrontendActionFactory( |
319 |
| - *ex.getExecutionContext(), *config), ArgAdjuster)) |
320 |
| - { |
321 |
| - if(! corpus->config.ignoreFailures) |
322 |
| - return toError(std::move(err)); |
323 |
| - reportWarning("warning: mapping failed because ", toString(std::move(err))); |
324 |
| - } |
325 |
| - |
326 |
| - // Inject the global namespace |
327 |
| - { |
328 |
| - // default-constructed NamespaceInfo |
329 |
| - // describes the global namespace |
330 |
| - NamespaceInfo I; |
331 |
| - insertBitcode( |
332 |
| - *ex.getExecutionContext(), |
333 |
| - writeBitcode(I)); |
334 |
| - } |
335 |
| - |
336 |
| - // Collect the symbols. Each symbol will have |
337 |
| - // a vector of one or more bitcodes. These will |
338 |
| - // be merged later. |
339 |
| - if(corpus->config.verboseOutput) |
340 |
| - reportInfo("Collecting symbols"); |
341 |
| - auto bitcodes = collectBitcodes(ex); |
342 |
| - |
343 |
| - // First reducing phase (reduce all decls into one info per decl). |
344 |
| - if(corpus->config.verboseOutput) |
345 |
| - reportInfo("Reducing {} declarations", bitcodes.size()); |
346 |
| - std::atomic<bool> GotFailure; |
347 |
| - GotFailure = false; |
348 |
| - corpus->config.parallelForEach( |
349 |
| - bitcodes, |
350 |
| - [&](auto& Group) |
351 |
| - { |
352 |
| - // One or more Info for the same symbol ID |
353 |
| - std::vector<std::unique_ptr<Info>> Infos; |
354 |
| - |
355 |
| - // Each Bitcode can have multiple Infos |
356 |
| - for (auto& bitcode : Group.getValue()) |
357 |
| - { |
358 |
| - auto infos = readBitcode(bitcode); |
359 |
| - if(! infos) |
360 |
| - { |
361 |
| - reportError(infos.getError(), "read bitcode"); |
362 |
| - GotFailure = true; |
363 |
| - return; |
364 |
| - } |
365 |
| - std::move( |
366 |
| - infos->begin(), |
367 |
| - infos->end(), |
368 |
| - std::back_inserter(Infos)); |
369 |
| - } |
370 |
| - |
371 |
| - auto merged = mergeInfos(Infos); |
372 |
| - if(! merged) |
373 |
| - { |
374 |
| - reportError(toError(merged.takeError()), "merge metadata"); |
375 |
| - GotFailure = true; |
376 |
| - return; |
377 |
| - } |
378 |
| - |
379 |
| - std::unique_ptr<Info> I(merged.get().release()); |
380 |
| - Assert(Group.getKey() == I->id); |
381 |
| - corpus->insert(std::move(I)); |
382 |
| - }); |
383 |
| - |
384 |
| - if(corpus->config.verboseOutput) |
385 |
| - llvm::outs() << "Collected " << corpus->InfoMap.size() << " symbols.\n"; |
386 |
| - |
387 |
| - if(GotFailure) |
388 |
| - return Error("multiple errors occurred"); |
389 |
| - |
390 |
| - corpus->canonicalize(); |
391 |
| - |
392 |
| - return corpus; |
393 |
| -} |
394 |
| - |
395 | 248 | // KRYSTIAN NOTE: temporary
|
396 | 249 | std::string&
|
397 | 250 | Corpus::
|
|
0 commit comments