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