9#ifndef LLVM_CLANG_BASIC_JSONSUPPORT_H
10#define LLVM_CLANG_BASIC_JSONSUPPORT_H
14#include "llvm/ADT/StringRef.h"
15#include "llvm/Support/Path.h"
16#include "llvm/Support/raw_ostream.h"
21inline raw_ostream &Indent(raw_ostream &Out,
const unsigned int Space,
23 for (
unsigned int I = 0; I < Space * 2; ++I)
24 Out << (IsDot ?
" " :
" ");
28inline std::string
JsonFormat(StringRef RawSR,
bool AddQuotes) {
33 std::string Str = RawSR.trim().str();
38 Pos = Str.find(
'\\', Pos);
39 if (Pos == std::string::npos)
43 size_t TempPos = (Pos != 0) ? Pos - 1 : 0;
46 if (TempPos != Str.find(
"\\\\", Pos)) {
47 Str.insert(Pos,
"\\");
57 Pos = Str.find(
'\"', Pos);
58 if (Pos == std::string::npos)
62 size_t TempPos = (Pos != 0) ? Pos - 1 : 0;
65 if (TempPos != Str.find(
"\\\"", Pos)) {
66 Str.insert(Pos,
"\\");
74 llvm::erase(Str,
'\n');
79 return '\"' + Str +
'\"';
84 bool AddBraces =
true) {
102 if (is_style_windows(llvm::sys::path::Style::native)) {
104 llvm::erase_if(filename, [](
auto Char) {
105 static const char ForbiddenChars[] =
"<>*?\"|";
106 return llvm::is_contained(ForbiddenChars, Char);
109 std::replace(filename.begin(), filename.end(),
'\\',
'/');
111 Out <<
"\"line\": " << PLoc.
getLine()
113 <<
", \"file\": \"" << filename <<
"\"";
124 Out <<
", \"spelling\": ";
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.
Defines the SourceManager interface.
Represents an unpacked "presumed" location which can be presented to the user.
unsigned getColumn() const
Return the presumed column number of this location.
const char * getFilename() const
Return the presumed filename of this location.
unsigned getLine() const
Return the presumed line number of this location.
bool isInvalid() const
Return true if this object is invalid or uninitialized.
Encodes a location in the source.
bool isValid() const
Return true if this is a valid SourceLocation object.
This class handles loading and caching of source files into memory.
The JSON file list parser is used to communicate input to InstallAPI.
void printSourceLocationAsJson(raw_ostream &Out, SourceLocation Loc, const SourceManager &SM, bool AddBraces=true)
std::string JsonFormat(StringRef RawSR, bool AddQuotes)