================
@@ -0,0 +1,189 @@
+//===- EntityLinker.cpp ----------------------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "clang/Analysis/Scalable/EntityLinker/EntityLinker.h"
+#include "clang/Analysis/Scalable/EntityLinker/EntitySummaryEncoding.h"
+#include "clang/Analysis/Scalable/EntityLinker/TUSummaryEncoding.h"
+#include "clang/Analysis/Scalable/Model/EntityLinkage.h"
+#include "clang/Analysis/Scalable/Model/EntityName.h"
+#include "clang/Analysis/Scalable/Support/ErrorBuilder.h"
+#include "clang/Analysis/Scalable/Support/FormatProviders.h"
+#include <cassert>
+
+using namespace clang::ssaf;
+
+//===----------------------------------------------------------------------===//
+// Error Message Constants
+//===----------------------------------------------------------------------===//
+
+namespace ErrorMessages {
+
+static constexpr const char *EntityLinkerFatalErrorPrefix =
+    "EntityLinker: Corrupted TUSummary or logic bug";
+
+static constexpr const char *EntityAlreadyExistsInLinkageTable =
+    "{0} - {1} with {2} already exists in LUSummary";
+
+static constexpr const char *MissingLinkageInformation =
+    "{0} - {1} missing linkage information in TUSummary";
+
+static constexpr const char *DuplicateEntityIdInTUSummary =
+    "{0} - Duplicate {1} in EntityResolutionTable";
+
+static constexpr const char *EntityNotFoundInResolutionTable =
+    "{0} - {1} not found in EntityResolutionTable";
+
+static constexpr const char *FailedToInsertEntityIntoOutputSummary =
+    "{0} - Failed to insert data for {1} with {2} against {3} to LUSummary";
+
+static constexpr const char *DuplicateTUNamespace =
+    "failed to link TU summary: duplicate {0}";
+
+} // namespace ErrorMessages
+
+static NestedBuildNamespace
+resolveNamespace(const NestedBuildNamespace &LUNamespace,
+                 const NestedBuildNamespace &EntityNamespace,
+                 EntityLinkage::LinkageType Linkage) {
+  switch (Linkage) {
+  case EntityLinkage::LinkageType::None:
+  case EntityLinkage::LinkageType::Internal:
+    return EntityNamespace.makeQualified(LUNamespace);
+  case EntityLinkage::LinkageType::External:
+    return NestedBuildNamespace(LUNamespace);
+  }
+
+  llvm_unreachable("Unhandled EntityLinkage::LinkageType variant");
+}
+
+EntityId EntityLinker::resolveEntity(const EntityName &OldName,
+                                     const EntityLinkage &Linkage) {
+  NestedBuildNamespace NewNamespace = resolveNamespace(
+      Output.LUNamespace, OldName.Namespace, Linkage.getLinkage());
+
+  EntityName NewName(OldName.USR, OldName.Suffix, NewNamespace);
+
+  // NewId construction will always return a fresh id for `None` and `Internal`
+  // linkage entities since their namespaces will be different even if their
+  // names clash. For `External` linkage entities with clashing names this
----------------
aviralg wrote:

Fixed.

https://github.com/llvm/llvm-project/pull/181765
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to