| 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 | |
| 15 | namespace clang::ssaf { |
| 16 | |
| 17 | BuildNamespace |
| 18 | BuildNamespace::makeCompilationUnit(llvm::StringRef CompilationId) { |
| 19 | return BuildNamespace{BuildNamespaceKind::CompilationUnit, |
| 20 | CompilationId.str()}; |
| 21 | } |
| 22 | |
| 23 | BuildNamespace BuildNamespace::withKind(BuildNamespaceKind Kind) const { |
| 24 | return BuildNamespace{Kind, Name}; |
| 25 | } |
| 26 | |
| 27 | bool BuildNamespace::operator==(const BuildNamespace &Other) const { |
| 28 | return asTuple() == Other.asTuple(); |
| 29 | } |
| 30 | |
| 31 | bool BuildNamespace::operator!=(const BuildNamespace &Other) const { |
| 32 | return !(*this == Other); |
| 33 | } |
| 34 | |
| 35 | bool BuildNamespace::operator<(const BuildNamespace &Other) const { |
| 36 | return asTuple() < Other.asTuple(); |
| 37 | } |
| 38 | |
| 39 | NestedBuildNamespace |
| 40 | NestedBuildNamespace::makeCompilationUnit(llvm::StringRef CompilationId) { |
| 41 | NestedBuildNamespace Result; |
| 42 | Result.Namespaces.push_back( |
| 43 | x: BuildNamespace::makeCompilationUnit(CompilationId)); |
| 44 | return Result; |
| 45 | } |
| 46 | |
| 47 | NestedBuildNamespace |
| 48 | NestedBuildNamespace::makeLinkUnit(llvm::StringRef LinkUnitId) { |
| 49 | NestedBuildNamespace Result; |
| 50 | Result.Namespaces.push_back( |
| 51 | x: BuildNamespace(BuildNamespaceKind::LinkUnit, LinkUnitId)); |
| 52 | return Result; |
| 53 | } |
| 54 | |
| 55 | bool NestedBuildNamespace::empty() const { return Namespaces.empty(); } |
| 56 | |
| 57 | bool NestedBuildNamespace::operator==(const NestedBuildNamespace &Other) const { |
| 58 | return Namespaces == Other.Namespaces; |
| 59 | } |
| 60 | |
| 61 | bool NestedBuildNamespace::operator!=(const NestedBuildNamespace &Other) const { |
| 62 | return !(*this == Other); |
| 63 | } |
| 64 | |
| 65 | bool NestedBuildNamespace::operator<(const NestedBuildNamespace &Other) const { |
| 66 | return Namespaces < Other.Namespaces; |
| 67 | } |
| 68 | |
| 69 | llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, BuildNamespaceKind BNK) { |
| 70 | return OS << buildNamespaceKindToString(BNK); |
| 71 | } |
| 72 | |
| 73 | llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const BuildNamespace &BN) { |
| 74 | return OS << "BuildNamespace("<< BN.Kind << ", "<< BN.Name << ")"; |
| 75 | } |
| 76 | |
| 77 | llvm::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 |