================
@@ -9,10 +9,47 @@
#ifndef LLVM_CLANG_ANALYSIS_SCALABLE_TUSUMMARY_TUSUMMARYBUILDER_H
#define LLVM_CLANG_ANALYSIS_SCALABLE_TUSUMMARY_TUSUMMARYBUILDER_H
+#include "clang/Analysis/Scalable/Model/EntityId.h"
+#include "clang/Analysis/Scalable/TUSummary/EntitySummary.h"
+#include <memory>
+#include <utility>
+
namespace clang::ssaf {
+class EntityName;
+class TUSummary;
+
class TUSummaryBuilder {
- // Empty for now.
+public:
+ explicit TUSummaryBuilder(TUSummary &Summary) : Summary(Summary) {}
+
+ /// Add an entity to the summary and return its EntityId.
+ /// If the entity already exists, returns the existing ID (idempotent).
+ EntityId addEntity(const EntityName &E);
+
+ /// Associate the \p Data EntitySummary with the \p Entity.
+ /// This consumes the \p Data only if \p Entity wasn't associated yet with
the
+ /// same kind of EntitySummary.
+ /// \returns a pointer to the EntitySummary and whether it inserted or not.
+ template <typename ConcreteEntitySummary,
+ DerivesFromEntitySummary<ConcreteEntitySummary> * = nullptr>
+ std::pair<EntitySummary *, bool>
+ addSummary(EntityId Entity, std::unique_ptr<ConcreteEntitySummary> &&Data) {
+ std::unique_ptr<EntitySummary> TypeErasedData = std::move(Data);
+ auto [It, Inserted] = addSummaryImpl(Entity, std::move(TypeErasedData));
+ // Move it back on failue to keep the `Data` unconsumed.
+ if (!Inserted) {
+ Data = std::unique_ptr<ConcreteEntitySummary>(
+ static_cast<ConcreteEntitySummary *>(TypeErasedData.release()));
+ }
+ return {It, Inserted};
+ }
----------------
aviralg wrote:
When the client adds a conflicting summary, the function moves the data back to
keep it unconsumed. That way, the argument to the `Data` parameter remains
valid on the client side.
https://github.com/llvm/llvm-project/pull/181220
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits