Please use GitHub pull requests for new patches. Avoid migrating existing patches. Phabricator shutdown timeline
Changeset View
Changeset View
Standalone View
Standalone View
clang/include/clang/Basic/JsonSupport.h
//===- JsonSupport.h - JSON Output Utilities --------------------*- C++ -*-===// | //===- JsonSupport.h - JSON Output Utilities --------------------*- C++ -*-===// | ||||
// | // | ||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||||
// See https://llvm.org/LICENSE.txt for license information. | // See https://llvm.org/LICENSE.txt for license information. | ||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||||
// | // | ||||
//===----------------------------------------------------------------------===// | //===----------------------------------------------------------------------===// | ||||
#ifndef LLVM_CLANG_BASIC_JSONSUPPORT_H | #ifndef LLVM_CLANG_BASIC_JSONSUPPORT_H | ||||
#define LLVM_CLANG_BASIC_JSONSUPPORT_H | #define LLVM_CLANG_BASIC_JSONSUPPORT_H | ||||
#include "clang/Basic/LLVM.h" | #include "clang/Basic/LLVM.h" | ||||
#include "clang/Basic/SourceManager.h" | #include "clang/Basic/SourceManager.h" | ||||
#include "llvm/ADT/StringRef.h" | #include "llvm/ADT/StringRef.h" | ||||
#include "llvm/Support/Path.h" | |||||
#include "llvm/Support/raw_ostream.h" | #include "llvm/Support/raw_ostream.h" | ||||
#include <iterator> | #include <iterator> | ||||
namespace clang { | namespace clang { | ||||
inline raw_ostream &Indent(raw_ostream &Out, const unsigned int Space, | inline raw_ostream &Indent(raw_ostream &Out, const unsigned int Space, | ||||
bool IsDot) { | bool IsDot) { | ||||
for (unsigned int I = 0; I < Space * 2; ++I) | for (unsigned int I = 0; I < Space * 2; ++I) | ||||
▲ Show 20 Lines • Show All 70 Lines • ▼ Show 20 Lines | if (Loc.isFileID()) { | ||||
if (PLoc.isInvalid()) { | if (PLoc.isInvalid()) { | ||||
Out << "null"; | Out << "null"; | ||||
return; | return; | ||||
} | } | ||||
// The macro expansion and spelling pos is identical for file locs. | // The macro expansion and spelling pos is identical for file locs. | ||||
if (AddBraces) | if (AddBraces) | ||||
Out << "{ "; | Out << "{ "; | ||||
std::string filename(PLoc.getFilename()); | std::string filename(PLoc.getFilename()); | ||||
#ifdef _WIN32 | if (is_style_windows(llvm::sys::path::Style::native)) { | ||||
// Remove forbidden Windows path characters | // Remove forbidden Windows path characters | ||||
auto RemoveIt = | auto RemoveIt = | ||||
std::remove_if(filename.begin(), filename.end(), [](auto Char) { | std::remove_if(filename.begin(), filename.end(), [](auto Char) { | ||||
static const char ForbiddenChars[] = "<>*?\"|"; | static const char ForbiddenChars[] = "<>*?\"|"; | ||||
return std::find(std::begin(ForbiddenChars), std::end(ForbiddenChars), | return std::find(std::begin(ForbiddenChars), | ||||
std::end(ForbiddenChars), | |||||
Char) != std::end(ForbiddenChars); | Char) != std::end(ForbiddenChars); | ||||
}); | }); | ||||
filename.erase(RemoveIt, filename.end()); | filename.erase(RemoveIt, filename.end()); | ||||
// Handle windows-specific path delimiters. | // Handle windows-specific path delimiters. | ||||
std::replace(filename.begin(), filename.end(), '\\', '/'); | std::replace(filename.begin(), filename.end(), '\\', '/'); | ||||
#endif | } | ||||
Out << "\"line\": " << PLoc.getLine() | Out << "\"line\": " << PLoc.getLine() | ||||
<< ", \"column\": " << PLoc.getColumn() | << ", \"column\": " << PLoc.getColumn() | ||||
<< ", \"file\": \"" << filename << "\""; | << ", \"file\": \"" << filename << "\""; | ||||
if (AddBraces) | if (AddBraces) | ||||
Out << " }"; | Out << " }"; | ||||
return; | return; | ||||
} | } | ||||
Show All 12 Lines |