9 #ifndef LLVM_CLANG_BASIC_JSONSUPPORT_H 10 #define LLVM_CLANG_BASIC_JSONSUPPORT_H 14 #include "llvm/ADT/StringRef.h" 15 #include "llvm/Support/raw_ostream.h" 20 inline raw_ostream &
Indent(raw_ostream &Out,
const unsigned int Space,
22 for (
unsigned int I = 0; I < Space * 2; ++I)
23 Out << (IsDot ?
" " :
" ");
27 inline std::string
JsonFormat(StringRef RawSR,
bool AddQuotes) {
32 std::string Str = RawSR.trim().str();
37 Pos = Str.find(
'\\', Pos);
38 if (Pos == std::string::npos)
42 size_t TempPos = (Pos != 0) ? Pos - 1 : 0;
45 if (TempPos != Str.find(
"\\\\", Pos)) {
46 Str.insert(Pos,
"\\");
56 Pos = Str.find(
'\"', Pos);
57 if (Pos == std::string::npos)
61 size_t TempPos = (Pos != 0) ? Pos - 1 : 0;
64 if (TempPos != Str.find(
"\\\"", Pos)) {
65 Str.insert(Pos,
"\\");
73 Str.erase(
std::remove(Str.begin(), Str.end(),
'\n'), Str.end());
78 return '\"' + Str +
'\"';
83 bool AddBraces =
true) {
100 Out <<
"\"line\": " << PLoc.
getLine()
113 Out <<
", \"spelling\": ";
119 #endif // LLVM_CLANG_BASIC_JSONSUPPORT_H Defines the SourceManager interface.
std::string JsonFormat(StringRef RawSR, bool AddQuotes)
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified...
SourceLocation getExpansionLoc(SourceLocation Loc) const
Given a SourceLocation object Loc, return the expansion location referenced by the ID...
SourceLocation getSpellingLoc(SourceLocation Loc) const
Given a SourceLocation object, return the spelling location referenced by the ID. ...
bool isInvalid() const
Return true if this object is invalid or uninitialized.
unsigned getLine() const
Return the presumed line number of this location.
Represents an unpacked "presumed" location which can be presented to the user.
const char * getFilename() const
Return the presumed filename of this location.
unsigned getColumn() const
Return the presumed column number of this location.
Encodes a location in the source.
void printSourceLocationAsJson(raw_ostream &Out, SourceLocation Loc, const SourceManager &SM, bool AddBraces=true)
Dataflow Directional Tag Classes.
bool isValid() const
Return true if this is a valid SourceLocation object.
PresumedLoc getPresumedLoc(SourceLocation Loc, bool UseLineDirectives=true) const
Returns the "presumed" location of a SourceLocation specifies.
raw_ostream & Indent(raw_ostream &Out, const unsigned int Space, bool IsDot)
This class handles loading and caching of source files into memory.