Author: sammccall Date: Wed Dec 20 02:26:53 2017 New Revision: 321161 URL: http://llvm.org/viewvc/llvm-project?rev=321161&view=rev Log: [clangd] Add debug printers for basic protocol types. NFC
Modified: clang-tools-extra/trunk/clangd/Protocol.cpp clang-tools-extra/trunk/clangd/Protocol.h clang-tools-extra/trunk/unittests/clangd/SourceCodeTests.cpp Modified: clang-tools-extra/trunk/clangd/Protocol.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/Protocol.cpp?rev=321161&r1=321160&r2=321161&view=diff ============================================================================== --- clang-tools-extra/trunk/clangd/Protocol.cpp (original) +++ clang-tools-extra/trunk/clangd/Protocol.cpp Wed Dec 20 02:26:53 2017 @@ -59,6 +59,10 @@ bool fromJSON(const json::Expr &E, URI & json::Expr toJSON(const URI &U) { return U.uri; } +llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const URI &U) { + return OS << U.uri; +} + bool fromJSON(const json::Expr &Params, TextDocumentIdentifier &R) { json::ObjectMapper O(Params); return O && O.map("uri", R.uri); @@ -76,6 +80,10 @@ json::Expr toJSON(const Position &P) { }; } +llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const Position &P) { + return OS << P.line << ':' << P.character; +} + bool fromJSON(const json::Expr &Params, Range &R) { json::ObjectMapper O(Params); return O && O.map("start", R.start) && O.map("end", R.end); @@ -88,6 +96,10 @@ json::Expr toJSON(const Range &P) { }; } +llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const Range &R) { + return OS << R.start << '-' << R.end; +} + json::Expr toJSON(const Location &P) { return json::obj{ {"uri", P.uri}, @@ -95,6 +107,10 @@ json::Expr toJSON(const Location &P) { }; } +llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const Location &L) { + return OS << L.range << '@' << L.uri; +} + bool fromJSON(const json::Expr &Params, TextDocumentItem &R) { json::ObjectMapper O(Params); return O && O.map("uri", R.uri) && O.map("languageId", R.languageId) && Modified: clang-tools-extra/trunk/clangd/Protocol.h URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/Protocol.h?rev=321161&r1=321160&r2=321161&view=diff ============================================================================== --- clang-tools-extra/trunk/clangd/Protocol.h (original) +++ clang-tools-extra/trunk/clangd/Protocol.h Wed Dec 20 02:26:53 2017 @@ -16,6 +16,9 @@ // Each struct has a toJSON and fromJSON function, that converts between // the struct and a JSON representation. (See JSONExpr.h) // +// Some structs also have operator<< serialization. This is for debugging and +// tests, and is not generally machine-readable. +// //===----------------------------------------------------------------------===// #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_PROTOCOL_H @@ -65,6 +68,7 @@ struct URI { }; json::Expr toJSON(const URI &U); bool fromJSON(const json::Expr &, URI &); +llvm::raw_ostream &operator<<(llvm::raw_ostream &, const URI &); struct TextDocumentIdentifier { /// The text document's URI. @@ -90,6 +94,7 @@ struct Position { }; bool fromJSON(const json::Expr &, Position &); json::Expr toJSON(const Position &); +llvm::raw_ostream &operator<<(llvm::raw_ostream &, const Position &); struct Range { /// The range's start position. @@ -107,6 +112,7 @@ struct Range { }; bool fromJSON(const json::Expr &, Range &); json::Expr toJSON(const Range &); +llvm::raw_ostream &operator<<(llvm::raw_ostream &, const Range &); struct Location { /// The text document's URI. @@ -126,6 +132,7 @@ struct Location { } }; json::Expr toJSON(const Location &); +llvm::raw_ostream &operator<<(llvm::raw_ostream &, const Location &); struct Metadata { std::vector<std::string> extraFlags; Modified: clang-tools-extra/trunk/unittests/clangd/SourceCodeTests.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/SourceCodeTests.cpp?rev=321161&r1=321160&r2=321161&view=diff ============================================================================== --- clang-tools-extra/trunk/unittests/clangd/SourceCodeTests.cpp (original) +++ clang-tools-extra/trunk/unittests/clangd/SourceCodeTests.cpp Wed Dec 20 02:26:53 2017 @@ -13,10 +13,6 @@ namespace clang{ namespace clangd { -void PrintTo(const Position &P, std::ostream *O) { - llvm::raw_os_ostream OS(*O); - OS << toJSON(P); -} namespace { MATCHER_P2(Pos, Line, Col, "") { _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits