Skip to content

Commit f276538

Browse files
Fix escaping bugs that currently affect the JSON formatting test on
Windows. Other escaping bugs may remain; #620 is to fix all of them. Fixes #619.
1 parent a929d23 commit f276538

File tree

3 files changed

+14
-11
lines changed

3 files changed

+14
-11
lines changed

clang/include/clang/3C/PersistentSourceLoc.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,13 @@ class PersistentSourceLoc {
5656
return FileName < O.FileName;
5757
}
5858

59-
void print(llvm::raw_ostream &O) const {
60-
O << FileName << ":" << LineNo << ":" << ColNoS << ":" << ColNoE;
59+
std::string toString() const {
60+
return FileName + ":" + std::to_string(LineNo) + ":" +
61+
std::to_string(ColNoS) + ":" + std::to_string(ColNoE);
6162
}
6263

64+
void print(llvm::raw_ostream &O) const { O << toString(); }
65+
6366
void dump() const { print(llvm::errs()); }
6467

6568
static PersistentSourceLoc mkPSL(const clang::Decl *D,

clang/lib/3C/3CInteractiveData.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
//===----------------------------------------------------------------------===//
1212

1313
#include "clang/3C/3CInteractiveData.h"
14+
#include "llvm/Support/JSON.h"
1415

1516
void ConstraintsInfo::clear() {
1617
RootWildAtomsWithReason.clear();
@@ -116,11 +117,9 @@ void ConstraintsInfo::printConstraintStats(llvm::raw_ostream &O,
116117
O << "\"InSrc\":" << (InSrcWildAtoms.find(Cause) != InSrcWildAtoms.end()) << ", ";
117118
O << "\"Location\":";
118119
const PersistentSourceLoc &PSL = PtrInfo.getLocation();
119-
if (PSL.valid()) {
120-
O << "\"";
121-
PSL.print(O);
122-
O << "\"";
123-
} else
120+
if (PSL.valid())
121+
O << llvm::json::Value(PSL.toString());
122+
else
124123
O << "null";
125124
O << ", ";
126125

clang/lib/3C/ProgramInfo.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "clang/3C/ConstraintsGraph.h"
1414
#include "clang/3C/MappingVisitor.h"
1515
#include "clang/3C/Utils.h"
16+
#include "llvm/Support/JSON.h"
1617
#include <sstream>
1718

1819
using namespace clang;
@@ -113,9 +114,9 @@ void ProgramInfo::dumpJson(llvm::raw_ostream &O) const {
113114
}
114115
PersistentSourceLoc L = I.first;
115116

116-
O << "{\"line\":\"";
117-
L.print(O);
118-
O << "\",\"Variables\":[";
117+
O << "{\"line\":";
118+
O << llvm::json::Value(L.toString());
119+
O << ",\"Variables\":[";
119120
I.second->dumpJson(O);
120121
O << "]}";
121122
AddComma = true;
@@ -315,7 +316,7 @@ void ProgramInfo::printStats(const std::set<std::string> &F, raw_ostream &O,
315316
if (AddComma) {
316317
O << ",\n";
317318
}
318-
O << "{\"" << I.first << "\":{";
319+
O << "{" << llvm::json::Value(I.first) << ":{";
319320
O << "\"constraints\":" << V << ",";
320321
O << "\"ptr\":" << P << ",";
321322
O << "\"ntarr\":" << Nt << ",";

0 commit comments

Comments
 (0)