| 1 | //===- TUSummaryBuilder.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 | |
| 9 | #include "clang/ScalableStaticAnalysis/Core/TUSummary/TUSummaryBuilder.h" |
| 10 | #include "clang/ScalableStaticAnalysis/Core/Model/EntityId.h" |
| 11 | #include "clang/ScalableStaticAnalysis/Core/Model/EntityLinkage.h" |
| 12 | #include "clang/ScalableStaticAnalysis/Core/TUSummary/EntitySummary.h" |
| 13 | #include "clang/ScalableStaticAnalysis/Core/TUSummary/TUSummary.h" |
| 14 | #include <memory> |
| 15 | #include <utility> |
| 16 | |
| 17 | using namespace clang; |
| 18 | using namespace ssaf; |
| 19 | |
| 20 | EntityId TUSummaryBuilder::addEntity(const EntityName &EN, |
| 21 | EntityLinkageType Linkage) { |
| 22 | EntityId Id = Summary.IdTable.getId(Name: EN); |
| 23 | [[maybe_unused]] EntityLinkageType Link = |
| 24 | Summary.LinkageTable.try_emplace(k: Id, args&: Linkage).first->second.getLinkage(); |
| 25 | // Even if we had in the past a linkage, that must bee the same as we set now. |
| 26 | assert(Link == Linkage); |
| 27 | return Id; |
| 28 | } |
| 29 | |
| 30 | std::pair<EntitySummary *, bool> |
| 31 | TUSummaryBuilder::addSummaryImpl(EntityId Entity, |
| 32 | std::unique_ptr<EntitySummary> &&Data) { |
| 33 | auto &EntitySummaries = Summary.Data[Data->getSummaryName()]; |
| 34 | auto [It, Inserted] = EntitySummaries.try_emplace(k: Entity, args: std::move(Data)); |
| 35 | return {It->second.get(), Inserted}; |
| 36 | } |
| 37 |