clang 23.0.0git
LUSummaryConsumer.cpp
Go to the documentation of this file.
1//===- LUSummaryConsumer.cpp ----------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
12
13using namespace clang;
14using namespace ssaf;
15
17LUSummaryConsumer::build(LUDataIterator LUIt) {
18 const SummaryName SN = LUIt->first;
20 if (!Builder) {
21 return ErrorBuilder::create(std::errc::invalid_argument,
22 "no builder registered for analysis '{0}'",
23 SN.str())
24 .build();
25 }
26
27 for (auto &[Id, Summary] : LUIt->second) {
28 Builder->addSummary(Id, std::move(Summary));
29 }
30 Builder->finalize();
31 LU->Data.erase(LUIt);
32
33 return std::move(*Builder).getData();
34}
35
36llvm::Expected<std::unique_ptr<SummaryData>>
37LUSummaryConsumer::build(const SummaryName &SN) {
38 auto LUIt = LU->Data.find(SN);
39 if (LUIt == LU->Data.end()) {
40 return ErrorBuilder::create(std::errc::invalid_argument,
41 "no data for analysis '{0}' in LUSummary",
42 SN.str())
43 .build();
44 }
45 return build(LUIt);
46}
47
48llvm::Expected<SummaryDataStore>
50 SummaryDataStore Store;
51 for (const auto &SN : Names) {
52 auto Result = build(SN);
53 if (!Result) {
54 return Result.takeError();
55 }
56 Store.Data.emplace(SN, std::move(*Result));
57 }
58 return Store;
59}
60
62 SummaryDataStore Store;
63 // Advance the iterator before calling build(): build() erases the current
64 // element on success, but std::map only invalidates iterators to the erased
65 // element, so the pre-advanced iterator remains valid in all cases.
66 auto It = LU->Data.begin();
67 while (It != LU->Data.end()) {
68 auto Current = It++; // Read the comment above!
69 SummaryName SN = Current->first; // copy before build() potentially erases
70 auto Result = build(Current);
71 if (!Result) {
72 llvm::consumeError(Result.takeError());
73 continue;
74 }
75 Store.Data.emplace(std::move(SN), std::move(*Result));
76 }
77 return Store;
78}
static ErrorBuilder create(std::error_code EC, const char *Fmt, Args &&...ArgVals)
Create an ErrorBuilder with an error code and formatted message.
llvm::Error build() const
Build and return the final error.
llvm::Expected< SummaryDataStore > run()
Processes analyses for each of the given types and returns the results.
static std::unique_ptr< SummaryDataBuilderBase > instantiate(llvm::StringRef Name)
Instantiates the builder registered under Name, or returns nullptr if no such builder is registered.
Owns a collection of SummaryData objects keyed by SummaryName.
Uniquely identifies an analysis summary.
Definition SummaryName.h:22
llvm::StringRef str() const
Explicit conversion to the underlying string representation.
Definition SummaryName.h:31
The JSON file list parser is used to communicate input to InstallAPI.
@ Result
The result type of a method or function.
Definition TypeBase.h:905