clang-tools 8.0.0

Conversion.cpp
Go to the documentation of this file.
1 //===--- Conversion.cpp - LSP data (de-)serialization through XPC - C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #include "xpc/Conversion.h"
11 #include "Logger.h"
12 #include "llvm/ADT/StringRef.h"
13 #include "llvm/Support/ScopedPrinter.h"
14 #include <string>
15 #include <vector>
16
17 using namespace llvm;
18 namespace clang {
19 namespace clangd {
20
21 xpc_object_t jsonToXpc(const json::Value &JSON) {
22 const char *const Key = "LSP";
23 xpc_object_t PayloadObj = xpc_string_create(llvm::to_string(JSON).c_str());
24 return xpc_dictionary_create(&Key, &PayloadObj, 1);
25 }
26
27 json::Value xpcToJson(const xpc_object_t &XPCObject) {
28 if (xpc_get_type(XPCObject) == XPC_TYPE_DICTIONARY) {
29 const char *const LSP = xpc_dictionary_get_string(XPCObject, "LSP");
30 auto Json = json::parse(llvm::StringRef(LSP));
31 if (Json)
32 return *Json;
33 else
34 elog("JSON parse error: {0}", toString(Json.takeError()));
35 }
36 return json::Value(nullptr);
37 }
38
39 } // namespace clangd
40 } // namespace clang
llvm
Some operations such as code completion produce a set of candidates.
Definition: YAMLGenerator.cpp:28
clang::tidy::cppcoreguidelines::toString
static llvm::StringRef toString(SpecialMemberFunctionsCheck::SpecialMemberFunctionKind K)
Definition: SpecialMemberFunctionsCheck.cpp:59
clang::clangd::Key
Values in a Context are indexed by typed keys.
Definition: Context.h:41
Conversion.h
clang::clangd::elog
void elog(const char *Fmt, Ts &&... Vals)
Definition: Logger.h:57
clang::clangd::xpcToJson
json::Value xpcToJson(const xpc_object_t &XPCObject)
Definition: Conversion.cpp:27
Logger.h
clang
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
Definition: ChangeNamespace.cpp:18
clang::clangd::jsonToXpc
xpc_object_t jsonToXpc(const json::Value &JSON)
Definition: Conversion.cpp:21