clang 23.0.0git
ModelStringConversions.h
Go to the documentation of this file.
1//===- ModelStringConversions.h ---------------------------------*- 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// Internal string conversion utilities for SSAF model types.
10//
11// These functions are shared by the model .cpp files (for operator<<) and
12// JSONFormat.cpp (for serialization). They are not part of the public API.
13//
14//===----------------------------------------------------------------------===//
15
16#ifndef LLVM_CLANG_LIB_ScalableStaticAnalysis_CORE_MODELSTRINGCONVERSIONS_H
17#define LLVM_CLANG_LIB_ScalableStaticAnalysis_CORE_MODELSTRINGCONVERSIONS_H
18
21#include "llvm/ADT/StringRef.h"
22#include "llvm/Support/ErrorHandling.h"
23#include <optional>
24
25namespace clang::ssaf {
26
27//===----------------------------------------------------------------------===//
28// BuildNamespaceKind
29//===----------------------------------------------------------------------===//
30
31/// Returns the canonical string representation of \p BNK used for
32/// serialization and display (e.g. "CompilationUnit", "LinkUnit").
34 switch (BNK) {
36 return "CompilationUnit";
38 return "LinkUnit";
40 return "StaticLibrary";
42 return "MultiArchStaticLibrary";
43 }
44 llvm_unreachable("Unhandled BuildNamespaceKind variant");
45}
46
47/// Parses a string produced by buildNamespaceKindToString(). Returns
48/// std::nullopt if \p Str does not match any known BuildNamespaceKind value.
49inline std::optional<BuildNamespaceKind>
50buildNamespaceKindFromString(llvm::StringRef Str) {
51 if (Str == "CompilationUnit")
53 if (Str == "LinkUnit")
55 if (Str == "StaticLibrary")
57 if (Str == "MultiArchStaticLibrary")
59 return std::nullopt;
60}
61
62//===----------------------------------------------------------------------===//
63// EntityLinkageType
64//===----------------------------------------------------------------------===//
65
66/// Returns the canonical string representation of \p LT used for
67/// serialization and display (e.g. "None", "Internal", "External").
68inline llvm::StringRef entityLinkageTypeToString(EntityLinkageType LT) {
69 switch (LT) {
71 return "None";
73 return "Internal";
75 return "External";
76 }
77 llvm_unreachable("Unhandled EntityLinkageType variant");
78}
79
80/// Parses a string produced by entityLinkageTypeToString(). Returns
81/// std::nullopt if \p Str does not match any known EntityLinkageType value.
82inline std::optional<EntityLinkageType>
83entityLinkageTypeFromString(llvm::StringRef Str) {
84 if (Str == "None")
86 if (Str == "Internal")
88 if (Str == "External")
90 return std::nullopt;
91}
92
93} // namespace clang::ssaf
94
95#endif // LLVM_CLANG_LIB_ScalableStaticAnalysis_CORE_MODELSTRINGCONVERSIONS_H
std::optional< EntityLinkageType > entityLinkageTypeFromString(llvm::StringRef Str)
Parses a string produced by entityLinkageTypeToString().
std::optional< BuildNamespaceKind > buildNamespaceKindFromString(llvm::StringRef Str)
Parses a string produced by buildNamespaceKindToString().
@ Internal
static functions/variables, anonymous namespace
@ External
globally visible across translation units (including parameters of functions with external linkage)
llvm::StringRef buildNamespaceKindToString(BuildNamespaceKind BNK)
Returns the canonical string representation of BNK used for serialization and display (e....
llvm::StringRef entityLinkageTypeToString(EntityLinkageType LT)
Returns the canonical string representation of LT used for serialization and display (e....