From c008af646620f6718384c2cd95f58a7311fe10fb Mon Sep 17 00:00:00 2001 From: Sam McCall Date: Sat, 20 Oct 2018 15:30:37 +0000 Subject: [clangd] Namespace style cleanup in cpp files. NFC. Standardize on the most common namespace setup in our *.cpp files: using namespace llvm; namespace clang { namespace clangd { void foo(StringRef) { ... } And remove redundant llvm:: qualifiers. (Except for cases like make_unique where this causes problems with std:: and ADL). This choice is pretty arbitrary, but some broad consistency is nice. This is going to conflict with everything. Sorry :-/ Squash the other configurations: A) using namespace llvm; using namespace clang; using namespace clangd; void clangd::foo(StringRef); This is in some of the older files. (It prevents accidentally defining a new function instead of one in the header file, for what that's worth). B) namespace clang { namespace clangd { void foo(llvm::StringRef) { ... } This is fine, but in practice the using directive often gets added over time. C) namespace clang { namespace clangd { using namespace llvm; // inside the namespace This was pretty common, but is a bit misleading: name lookup preferrs clang::clangd::foo > clang::foo > llvm:: foo (no matter where the using directive is). llvm-svn: 344850 --- clang-tools-extra/clangd/Protocol.cpp | 38 ++++++++++++++++------------------- 1 file changed, 17 insertions(+), 21 deletions(-) (limited to 'clang-tools-extra/clangd/Protocol.cpp') diff --git a/clang-tools-extra/clangd/Protocol.cpp b/clang-tools-extra/clangd/Protocol.cpp index 805225a2434..3622a43c18e 100644 --- a/clang-tools-extra/clangd/Protocol.cpp +++ b/clang-tools-extra/clangd/Protocol.cpp @@ -21,14 +21,14 @@ #include "llvm/Support/Path.h" #include "llvm/Support/raw_ostream.h" +using namespace llvm; namespace clang { namespace clangd { -using namespace llvm; char LSPError::ID; URIForFile::URIForFile(std::string AbsPath) { - assert(llvm::sys::path::is_absolute(AbsPath) && "the path is relative"); + assert(sys::path::is_absolute(AbsPath) && "the path is relative"); File = std::move(AbsPath); } @@ -57,7 +57,7 @@ bool fromJSON(const json::Value &E, URIForFile &R) { json::Value toJSON(const URIForFile &U) { return U.uri(); } -llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const URIForFile &U) { +raw_ostream &operator<<(raw_ostream &OS, const URIForFile &U) { return OS << U.uri(); } @@ -82,7 +82,7 @@ json::Value toJSON(const Position &P) { }; } -llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const Position &P) { +raw_ostream &operator<<(raw_ostream &OS, const Position &P) { return OS << P.line << ':' << P.character; } @@ -98,7 +98,7 @@ json::Value toJSON(const Range &P) { }; } -llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const Range &R) { +raw_ostream &operator<<(raw_ostream &OS, const Range &R) { return OS << R.start << '-' << R.end; } @@ -109,7 +109,7 @@ json::Value toJSON(const Location &P) { }; } -llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const Location &L) { +raw_ostream &operator<<(raw_ostream &OS, const Location &L) { return OS << L.range << '@' << L.uri; } @@ -139,7 +139,7 @@ json::Value toJSON(const TextEdit &P) { }; } -llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const TextEdit &TE) { +raw_ostream &operator<<(raw_ostream &OS, const TextEdit &TE) { OS << TE.range << " => \""; printEscapedString(TE.newText, OS); return OS << '"'; @@ -342,7 +342,7 @@ bool fromJSON(const json::Value &Params, DocumentSymbolParams &R) { return O && O.map("textDocument", R.textDocument); } -llvm::json::Value toJSON(const Diagnostic &D) { +json::Value toJSON(const Diagnostic &D) { json::Object Diag{ {"range", D.range}, {"severity", D.severity}, @@ -366,7 +366,7 @@ bool fromJSON(const json::Value &Params, CodeActionContext &R) { return O && O.map("diagnostics", R.diagnostics); } -llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const Diagnostic &D) { +raw_ostream &operator<<(raw_ostream &OS, const Diagnostic &D) { OS << D.range << " ["; switch (D.severity) { case 1: @@ -399,7 +399,7 @@ bool fromJSON(const json::Value &Params, WorkspaceEdit &R) { return O && O.map("changes", R.changes); } -const llvm::StringLiteral ExecuteCommandParams::CLANGD_APPLY_FIX_COMMAND = +const StringLiteral ExecuteCommandParams::CLANGD_APPLY_FIX_COMMAND = "clangd.applyFix"; bool fromJSON(const json::Value &Params, ExecuteCommandParams &R) { json::ObjectMapper O(Params); @@ -423,8 +423,7 @@ json::Value toJSON(const SymbolInformation &P) { }; } -llvm::raw_ostream &operator<<(llvm::raw_ostream &O, - const SymbolInformation &SI) { +raw_ostream &operator<<(raw_ostream &O, const SymbolInformation &SI) { O << SI.containerName << "::" << SI.name << " - " << toJSON(SI); return O; } @@ -441,9 +440,9 @@ json::Value toJSON(const Command &C) { return std::move(Cmd); } -const llvm::StringLiteral CodeAction::QUICKFIX_KIND = "quickfix"; +const StringLiteral CodeAction::QUICKFIX_KIND = "quickfix"; -llvm::json::Value toJSON(const CodeAction &CA) { +json::Value toJSON(const CodeAction &CA) { auto CodeAction = json::Object{{"title", CA.title}}; if (CA.kind) CodeAction["kind"] = *CA.kind; @@ -575,7 +574,7 @@ json::Value toJSON(const CompletionItem &CI) { return std::move(Result); } -llvm::raw_ostream &operator<<(llvm::raw_ostream &O, const CompletionItem &I) { +raw_ostream &operator<<(raw_ostream &O, const CompletionItem &I) { O << I.label << " - " << toJSON(I); return O; } @@ -611,8 +610,7 @@ json::Value toJSON(const SignatureInformation &SI) { return std::move(Result); } -llvm::raw_ostream &operator<<(llvm::raw_ostream &O, - const SignatureInformation &I) { +raw_ostream &operator<<(raw_ostream &O, const SignatureInformation &I) { O << I.label << " - " << toJSON(I); return O; } @@ -642,8 +640,7 @@ json::Value toJSON(const DocumentHighlight &DH) { }; } -llvm::raw_ostream &operator<<(llvm::raw_ostream &O, - const DocumentHighlight &V) { +raw_ostream &operator<<(raw_ostream &O, const DocumentHighlight &V) { O << V.range; if (V.kind == DocumentHighlightKind::Read) O << "(r)"; @@ -657,8 +654,7 @@ bool fromJSON(const json::Value &Params, DidChangeConfigurationParams &CCP) { return O && O.map("settings", CCP.settings); } -bool fromJSON(const llvm::json::Value &Params, - ClangdCompileCommand &CDbUpdate) { +bool fromJSON(const json::Value &Params, ClangdCompileCommand &CDbUpdate) { json::ObjectMapper O(Params); return O && O.map("workingDirectory", CDbUpdate.workingDirectory) && O.map("compilationCommand", CDbUpdate.compilationCommand); -- cgit v1.2.3