| 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 | |
| 13 | namespace clang::ssaf { |
| 14 | |
| 15 | llvm::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 | |
| 25 | std::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 | |
| 33 | BuildNamespace |
| 34 | BuildNamespace::makeCompilationUnit(llvm::StringRef CompilationId) { |
| 35 | return BuildNamespace{BuildNamespaceKind::CompilationUnit, |
| 36 | CompilationId.str()}; |
| 37 | } |
| 38 | |
| 39 | bool BuildNamespace::operator==(const BuildNamespace &Other) const { |
| 40 | return asTuple() == Other.asTuple(); |
| 41 | } |
| 42 | |
| 43 | bool BuildNamespace::operator!=(const BuildNamespace &Other) const { |
| 44 | return !(*this == Other); |
| 45 | } |
| 46 | |
| 47 | bool BuildNamespace::operator<(const BuildNamespace &Other) const { |
| 48 | return asTuple() < Other.asTuple(); |
| 49 | } |
| 50 | |
| 51 | NestedBuildNamespace |
| 52 | NestedBuildNamespace::makeCompilationUnit(llvm::StringRef CompilationId) { |
| 53 | NestedBuildNamespace Result; |
| 54 | Result.Namespaces.push_back( |
| 55 | x: BuildNamespace::makeCompilationUnit(CompilationId)); |
| 56 | return Result; |
| 57 | } |
| 58 | |
| 59 | bool NestedBuildNamespace::empty() const { return Namespaces.empty(); } |
| 60 | |
| 61 | bool NestedBuildNamespace::operator==(const NestedBuildNamespace &Other) const { |
| 62 | return Namespaces == Other.Namespaces; |
| 63 | } |
| 64 | |
| 65 | bool NestedBuildNamespace::operator!=(const NestedBuildNamespace &Other) const { |
| 66 | return !(*this == Other); |
| 67 | } |
| 68 | |
| 69 | bool NestedBuildNamespace::operator<(const NestedBuildNamespace &Other) const { |
| 70 | return Namespaces < Other.Namespaces; |
| 71 | } |
| 72 | |
| 73 | } // namespace clang::ssaf |
| 74 |