1//===- BuildNamespace.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/Model/BuildNamespace.h"
10#include "../ModelStringConversions.h"
11#include "llvm/ADT/STLExtras.h"
12#include "llvm/Support/ErrorHandling.h"
13#include <tuple>
14
15namespace clang::ssaf {
16
17BuildNamespace
18BuildNamespace::makeCompilationUnit(llvm::StringRef CompilationId) {
19 return BuildNamespace{BuildNamespaceKind::CompilationUnit,
20 CompilationId.str()};
21}
22
23BuildNamespace BuildNamespace::withKind(BuildNamespaceKind Kind) const {
24 return BuildNamespace{Kind, Name};
25}
26
27bool BuildNamespace::operator==(const BuildNamespace &Other) const {
28 return asTuple() == Other.asTuple();
29}
30
31bool BuildNamespace::operator!=(const BuildNamespace &Other) const {
32 return !(*this == Other);
33}
34
35bool BuildNamespace::operator<(const BuildNamespace &Other) const {
36 return asTuple() < Other.asTuple();
37}
38
39NestedBuildNamespace
40NestedBuildNamespace::makeCompilationUnit(llvm::StringRef CompilationId) {
41 NestedBuildNamespace Result;
42 Result.Namespaces.push_back(
43 x: BuildNamespace::makeCompilationUnit(CompilationId));
44 return Result;
45}
46
47NestedBuildNamespace
48NestedBuildNamespace::makeLinkUnit(llvm::StringRef LinkUnitId) {
49 NestedBuildNamespace Result;
50 Result.Namespaces.push_back(
51 x: BuildNamespace(BuildNamespaceKind::LinkUnit, LinkUnitId));
52 return Result;
53}
54
55bool NestedBuildNamespace::empty() const { return Namespaces.empty(); }
56
57bool NestedBuildNamespace::operator==(const NestedBuildNamespace &Other) const {
58 return Namespaces == Other.Namespaces;
59}
60
61bool NestedBuildNamespace::operator!=(const NestedBuildNamespace &Other) const {
62 return !(*this == Other);
63}
64
65bool NestedBuildNamespace::operator<(const NestedBuildNamespace &Other) const {
66 return Namespaces < Other.Namespaces;
67}
68
69llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, BuildNamespaceKind BNK) {
70 return OS << buildNamespaceKindToString(BNK);
71}
72
73llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const BuildNamespace &BN) {
74 return OS << "BuildNamespace(" << BN.Kind << ", " << BN.Name << ")";
75}
76
77llvm::raw_ostream &operator<<(llvm::raw_ostream &OS,
78 const NestedBuildNamespace &NBN) {
79 OS << "NestedBuildNamespace([";
80 llvm::interleaveComma(c: NBN.Namespaces, os&: OS);
81 OS << "])";
82 return OS;
83}
84
85} // namespace clang::ssaf
86