clang 23.0.0git
ModelStringConversions.h
Go to the documentation of this file.
1//===- ModelStringConversions.h -------------------------------------------===//
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 CLANG_LIB_ANALYSIS_SCALABLE_MODELSTRINGCONVERSIONS_H
17#define CLANG_LIB_ANALYSIS_SCALABLE_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";
39 }
40 llvm_unreachable("Unhandled BuildNamespaceKind variant");
41}
42
43/// Parses a string produced by buildNamespaceKindToString(). Returns
44/// std::nullopt if \p Str does not match any known BuildNamespaceKind value.
45inline std::optional<BuildNamespaceKind>
46buildNamespaceKindFromString(llvm::StringRef Str) {
47 if (Str == "CompilationUnit")
49 if (Str == "LinkUnit")
51 return std::nullopt;
52}
53
54//===----------------------------------------------------------------------===//
55// EntityLinkageType
56//===----------------------------------------------------------------------===//
57
58/// Returns the canonical string representation of \p LT used for
59/// serialization and display (e.g. "None", "Internal", "External").
60inline llvm::StringRef entityLinkageTypeToString(EntityLinkageType LT) {
61 switch (LT) {
63 return "None";
65 return "Internal";
67 return "External";
68 }
69 llvm_unreachable("Unhandled EntityLinkageType variant");
70}
71
72/// Parses a string produced by entityLinkageTypeToString(). Returns
73/// std::nullopt if \p Str does not match any known EntityLinkageType value.
74inline std::optional<EntityLinkageType>
75entityLinkageTypeFromString(llvm::StringRef Str) {
76 if (Str == "None")
78 if (Str == "Internal")
80 if (Str == "External")
82 return std::nullopt;
83}
84
85} // namespace clang::ssaf
86
87#endif // CLANG_LIB_ANALYSIS_SCALABLE_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().
@ None
local variables, function parameters
@ Internal
static functions/variables, anonymous namespace
@ External
globally visible across translation units
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....