1//===- BuildNamespace.cpp ---------------------------------------*- C++ -*-===//
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/Analysis/Scalable/Model/BuildNamespace.h"
10#include "llvm/Support/ErrorHandling.h"
11#include <tuple>
12
13namespace clang::ssaf {
14
15llvm::StringRef toString(BuildNamespaceKind BNK) {
16 switch (BNK) {
17 case BuildNamespaceKind::CompilationUnit:
18 return "compilation_unit";
19 case BuildNamespaceKind::LinkUnit:
20 return "link_unit";
21 }
22 llvm_unreachable("Unknown BuildNamespaceKind");
23}
24
25std::optional<BuildNamespaceKind> parseBuildNamespaceKind(llvm::StringRef Str) {
26 if (Str == "compilation_unit")
27 return BuildNamespaceKind::CompilationUnit;
28 if (Str == "link_unit")
29 return BuildNamespaceKind::LinkUnit;
30 return std::nullopt;
31}
32
33BuildNamespace
34BuildNamespace::makeCompilationUnit(llvm::StringRef CompilationId) {
35 return BuildNamespace{BuildNamespaceKind::CompilationUnit,
36 CompilationId.str()};
37}
38
39bool BuildNamespace::operator==(const BuildNamespace &Other) const {
40 return asTuple() == Other.asTuple();
41}
42
43bool BuildNamespace::operator!=(const BuildNamespace &Other) const {
44 return !(*this == Other);
45}
46
47bool BuildNamespace::operator<(const BuildNamespace &Other) const {
48 return asTuple() < Other.asTuple();
49}
50
51NestedBuildNamespace
52NestedBuildNamespace::makeCompilationUnit(llvm::StringRef CompilationId) {
53 NestedBuildNamespace Result;
54 Result.Namespaces.push_back(
55 x: BuildNamespace::makeCompilationUnit(CompilationId));
56 return Result;
57}
58
59bool NestedBuildNamespace::empty() const { return Namespaces.empty(); }
60
61bool NestedBuildNamespace::operator==(const NestedBuildNamespace &Other) const {
62 return Namespaces == Other.Namespaces;
63}
64
65bool NestedBuildNamespace::operator!=(const NestedBuildNamespace &Other) const {
66 return !(*this == Other);
67}
68
69bool NestedBuildNamespace::operator<(const NestedBuildNamespace &Other) const {
70 return Namespaces < Other.Namespaces;
71}
72
73} // namespace clang::ssaf
74