clang 23.0.0git
JSONFormatImpl.h
Go to the documentation of this file.
1//===- JSONFormatImpl.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 implementation header shared by all translation units in the
10// JSONFormat subdirectory. Not part of the public API.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_CLANG_LIB_SCALABLESTATICANALYSISFRAMEWORK_CORE_SERIALIZATION_JSONFORMAT_JSONFORMATIMPL_H
15#define LLVM_CLANG_LIB_SCALABLESTATICANALYSISFRAMEWORK_CORE_SERIALIZATION_JSONFORMAT_JSONFORMATIMPL_H
16
24#include "llvm/ADT/STLExtras.h"
25#include "llvm/ADT/StringExtras.h"
26#include "llvm/Support/ErrorHandling.h"
27#include "llvm/Support/FileSystem.h"
28#include "llvm/Support/FormatVariadic.h"
29#include "llvm/Support/JSON.h"
30#include "llvm/Support/MemoryBuffer.h"
31#include "llvm/Support/Path.h"
32#include "llvm/Support/Registry.h"
33
34namespace clang::ssaf {
35
36using Array = llvm::json::Array;
37using Object = llvm::json::Object;
38using Value = llvm::json::Value;
39
40//----------------------------------------------------------------------------
41// File Format Constant
42//----------------------------------------------------------------------------
43
44inline constexpr const char *JSONFormatFileExtension = ".json";
45
46//----------------------------------------------------------------------------
47// Error Message Constants
48//----------------------------------------------------------------------------
49
50namespace ErrorMessages {
51
52inline constexpr const char *FailedToReadFile =
53 "failed to read file '{0}': {1}";
54inline constexpr const char *FailedToWriteFile =
55 "failed to write file '{0}': {1}";
56inline constexpr const char *FileNotFound = "file does not exist";
57inline constexpr const char *FileIsDirectory =
58 "path is a directory, not a file";
59inline constexpr const char *FileIsNotJSON =
60 "file does not end with '{0}' extension";
61inline constexpr const char *FileExists = "file already exists";
62inline constexpr const char *ParentDirectoryNotFound =
63 "parent directory does not exist";
64
65inline constexpr const char *ReadingFromField = "reading {0} from field '{1}'";
66inline constexpr const char *WritingToField = "writing {0} to field '{1}'";
67inline constexpr const char *ReadingFromIndex = "reading {0} from index '{1}'";
68inline constexpr const char *WritingToIndex = "writing {0} to index '{1}'";
69inline constexpr const char *ReadingFromFile = "reading {0} from file '{1}'";
70inline constexpr const char *WritingToFile = "writing {0} to file '{1}'";
71
72inline constexpr const char *FailedInsertionOnDuplication =
73 "failed to insert {0} at index '{1}': encountered duplicate '{2}'";
74
75inline constexpr const char *FailedToReadObject =
76 "failed to read {0}: expected JSON {1}";
77inline constexpr const char *FailedToReadObjectAtField =
78 "failed to read {0} from field '{1}': expected JSON {2}";
79inline constexpr const char *FailedToReadObjectAtIndex =
80 "failed to read {0} from index '{1}': expected JSON {2}";
81
83 "failed to deserialize EntitySummary: no FormatInfo registered for '{0}'";
84inline constexpr const char *FailedToSerializeEntitySummaryNoFormatInfo =
85 "failed to serialize EntitySummary: no FormatInfo registered for '{0}'";
86
87inline constexpr const char *FailedToDeserializeEntitySummaryMissingData =
88 "failed to deserialize EntitySummary: null EntitySummary data for '{0}'";
89inline constexpr const char *FailedToSerializeEntitySummaryMissingData =
90 "JSONFormat - null EntitySummary data for '{0}'";
91
92inline constexpr const char
94 "failed to deserialize EntitySummary: EntitySummary data for '{0}' "
95 "reports mismatched '{1}'";
96inline constexpr const char
98 "JSONFormat - EntitySummary data for '{0}' reports mismatched '{1}'";
99
100inline constexpr const char *InvalidBuildNamespaceKind =
101 "invalid BuildNamespaceKind value '{0}' for field 'kind'";
102
103inline constexpr const char *InvalidEntityLinkageType =
104 "invalid EntityLinkageType value '{0}' for field 'type'";
105
106inline constexpr const char *FailedToDeserializeLinkageTableExtraId =
107 "failed to deserialize LinkageTable: extra '{0}' not present in IdTable";
108
109inline constexpr const char *FailedToDeserializeLinkageTableMissingId =
110 "failed to deserialize LinkageTable: missing '{0}' present in IdTable";
111
112inline constexpr const char *FailedToReadEntityIdObject =
113 "failed to read EntityId: expected JSON object with a single '{0}' key "
114 "mapped to a number (unsigned 64-bit integer)";
115
116inline constexpr const char *FailedToPatchEntityIdNotInTable =
117 "failed to patch EntityId: '{0}' not found in entity resolution table";
118
119} // namespace ErrorMessages
120
121//----------------------------------------------------------------------------
122// Entity Id JSON Representation
123//----------------------------------------------------------------------------
124
125/// An entity ID is encoded as the single-key object {"@": <index>}.
126inline constexpr const char *JSONEntityIdKey = "@";
127
128//----------------------------------------------------------------------------
129// JSON Reader and Writer
130//----------------------------------------------------------------------------
131
132llvm::Expected<Value> readJSON(llvm::StringRef Path);
133llvm::Error writeJSON(Value &&V, llvm::StringRef Path);
134
135//----------------------------------------------------------------------------
136// SummaryName helpers (free functions, anonymous-namespace in .cpp)
137//----------------------------------------------------------------------------
138
139SummaryName summaryNameFromJSON(llvm::StringRef SummaryNameStr);
140llvm::StringRef summaryNameToJSON(const SummaryName &SN);
141
142//----------------------------------------------------------------------------
143// BuildNamespaceKind helpers
144//----------------------------------------------------------------------------
145
147buildNamespaceKindFromJSON(llvm::StringRef BuildNamespaceKindStr);
148
149// Provided for consistency with respect to rest of the codebase.
151
152//----------------------------------------------------------------------------
153// EntityLinkageType helpers
154//----------------------------------------------------------------------------
155
157entityLinkageTypeFromJSON(llvm::StringRef EntityLinkageTypeStr);
158
159// Provided for consistency with respect to rest of the codebase.
161
162} // namespace clang::ssaf
163
164#endif // LLVM_CLANG_LIB_SCALABLESTATICANALYSISFRAMEWORK_CORE_SERIALIZATION_JSONFORMAT_JSONFORMATIMPL_H
#define V(N, I)
Uniquely identifies an analysis summary.
Definition SummaryName.h:22
constexpr const char * FailedToSerializeEntitySummaryMismatchedSummaryName
constexpr const char * FailedToPatchEntityIdNotInTable
constexpr const char * InvalidBuildNamespaceKind
constexpr const char * ReadingFromFile
constexpr const char * ReadingFromField
constexpr const char * FailedToReadObjectAtIndex
constexpr const char * FailedToDeserializeEntitySummaryNoFormatInfo
constexpr const char * InvalidEntityLinkageType
constexpr const char * FileIsDirectory
constexpr const char * FailedToDeserializeEntitySummaryMismatchedSummaryName
constexpr const char * FileNotFound
constexpr const char * FailedToReadObjectAtField
constexpr const char * FileExists
constexpr const char * FailedToReadEntityIdObject
constexpr const char * WritingToFile
constexpr const char * ReadingFromIndex
constexpr const char * WritingToField
constexpr const char * FailedInsertionOnDuplication
constexpr const char * FailedToDeserializeLinkageTableExtraId
constexpr const char * FailedToSerializeEntitySummaryMissingData
constexpr const char * FailedToDeserializeEntitySummaryMissingData
constexpr const char * FailedToWriteFile
constexpr const char * FailedToDeserializeLinkageTableMissingId
constexpr const char * FileIsNotJSON
constexpr const char * FailedToReadFile
constexpr const char * FailedToReadObject
constexpr const char * ParentDirectoryNotFound
constexpr const char * FailedToSerializeEntitySummaryNoFormatInfo
constexpr const char * WritingToIndex
SummaryName summaryNameFromJSON(llvm::StringRef SummaryNameStr)
llvm::StringRef summaryNameToJSON(const SummaryName &SN)
llvm::json::Array Array
llvm::Expected< EntityLinkageType > entityLinkageTypeFromJSON(llvm::StringRef EntityLinkageTypeStr)
constexpr const char * JSONEntityIdKey
An entity ID is encoded as the single-key object {"@": <index>}.
llvm::json::Value Value
llvm::Expected< BuildNamespaceKind > buildNamespaceKindFromJSON(llvm::StringRef BuildNamespaceKindStr)
llvm::json::Object Object
llvm::Expected< Value > readJSON(llvm::StringRef Path)
constexpr const char * JSONFormatFileExtension
llvm::StringRef buildNamespaceKindToJSON(BuildNamespaceKind BNK)
llvm::StringRef entityLinkageTypeToJSON(EntityLinkageType LT)
llvm::Error writeJSON(Value &&V, llvm::StringRef Path)