Author: Nathan James Date: 2021-03-02T21:57:16Z New Revision: 00c7d6699a3937cd1fe34921f1fbc0c4fc09cebd
URL: https://github.com/llvm/llvm-project/commit/00c7d6699a3937cd1fe34921f1fbc0c4fc09cebd DIFF: https://github.com/llvm/llvm-project/commit/00c7d6699a3937cd1fe34921f1fbc0c4fc09cebd.diff LOG: [cte][NFC] Remove all references to stdlib stream headers. Inclusion of iostream is frobidden and using other stream classes from standard library is discouraged as per https://llvm.org/docs/CodingStandards.html#include-iostream-is-forbidden Reviewed By: sammccall Differential Revision: https://reviews.llvm.org/D97771 Added: Modified: clang-tools-extra/clang-query/tool/ClangQuery.cpp clang-tools-extra/clang-tidy/altera/StructPackAlignCheck.cpp clang-tools-extra/clang-tidy/readability/InconsistentDeclarationParameterNameCheck.cpp clang-tools-extra/clangd/benchmarks/IndexBenchmark.cpp clang-tools-extra/clangd/fuzzer/clangd-fuzzer.cpp clang-tools-extra/clangd/tool/ClangdMain.cpp clang-tools-extra/modularize/Modularize.cpp Removed: ################################################################################ diff --git a/clang-tools-extra/clang-query/tool/ClangQuery.cpp b/clang-tools-extra/clang-query/tool/ClangQuery.cpp index 45a355073945..2bdb36192f35 100644 --- a/clang-tools-extra/clang-query/tool/ClangQuery.cpp +++ b/clang-tools-extra/clang-query/tool/ClangQuery.cpp @@ -33,10 +33,10 @@ #include "clang/Tooling/Tooling.h" #include "llvm/LineEditor/LineEditor.h" #include "llvm/Support/CommandLine.h" +#include "llvm/Support/Error.h" #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/Signals.h" #include "llvm/Support/WithColor.h" -#include <fstream> #include <string> using namespace clang; @@ -73,16 +73,15 @@ static cl::opt<std::string> PreloadFile( bool runCommandsInFile(const char *ExeName, std::string const &FileName, QuerySession &QS) { - std::ifstream Input(FileName.c_str()); - if (!Input.is_open()) { - llvm::errs() << ExeName << ": cannot open " << FileName << "\n"; - return 1; + auto Buffer = llvm::MemoryBuffer::getFile(FileName); + if (!Buffer) { + llvm::errs() << ExeName << ": cannot open " << FileName << ": " + << Buffer.getError().message() << "\n"; + return true; } - std::string FileContent((std::istreambuf_iterator<char>(Input)), - std::istreambuf_iterator<char>()); + StringRef FileContentRef(Buffer.get()->getBuffer()); - StringRef FileContentRef(FileContent); while (!FileContentRef.empty()) { QueryRef Q = QueryParser::parse(FileContentRef, QS); if (!Q->run(llvm::outs(), QS)) diff --git a/clang-tools-extra/clang-tidy/altera/StructPackAlignCheck.cpp b/clang-tools-extra/clang-tidy/altera/StructPackAlignCheck.cpp index 9f28a22a9d03..a2178befa9df 100644 --- a/clang-tools-extra/clang-tidy/altera/StructPackAlignCheck.cpp +++ b/clang-tools-extra/clang-tidy/altera/StructPackAlignCheck.cpp @@ -11,7 +11,6 @@ #include "clang/AST/RecordLayout.h" #include "clang/ASTMatchers/ASTMatchFinder.h" #include <math.h> -#include <sstream> using namespace clang::ast_matchers; @@ -109,15 +108,13 @@ void StructPackAlignCheck::check(const MatchFinder::MatchResult &Result) { AlignedAttr *Attribute = Struct->getAttr<AlignedAttr>(); std::string NewAlignQuantity = std::to_string((int)NewAlign.getQuantity()); if (Attribute) { - std::ostringstream FixItString; - FixItString << "aligned(" << NewAlignQuantity << ")"; - FixIt = - FixItHint::CreateReplacement(Attribute->getRange(), FixItString.str()); + FixIt = FixItHint::CreateReplacement( + Attribute->getRange(), + (Twine("aligned(") + NewAlignQuantity + ")").str()); } else { - std::ostringstream FixItString; - FixItString << " __attribute__((aligned(" << NewAlignQuantity << ")))"; - FixIt = FixItHint::CreateInsertion(Struct->getEndLoc().getLocWithOffset(1), - FixItString.str()); + FixIt = FixItHint::CreateInsertion( + Struct->getEndLoc().getLocWithOffset(1), + (Twine(" __attribute__((aligned(") + NewAlignQuantity + ")))").str()); } // And suggest the minimum power-of-two alignment for the struct as a whole diff --git a/clang-tools-extra/clang-tidy/readability/InconsistentDeclarationParameterNameCheck.cpp b/clang-tools-extra/clang-tidy/readability/InconsistentDeclarationParameterNameCheck.cpp index 43d2f6a69cd1..c28424b11f27 100644 --- a/clang-tools-extra/clang-tidy/readability/InconsistentDeclarationParameterNameCheck.cpp +++ b/clang-tools-extra/clang-tidy/readability/InconsistentDeclarationParameterNameCheck.cpp @@ -12,7 +12,6 @@ #include <algorithm> #include <functional> -#include <sstream> using namespace clang::ast_matchers; diff --git a/clang-tools-extra/clangd/benchmarks/IndexBenchmark.cpp b/clang-tools-extra/clangd/benchmarks/IndexBenchmark.cpp index 237655dcc9bc..deeb07b4cb64 100644 --- a/clang-tools-extra/clangd/benchmarks/IndexBenchmark.cpp +++ b/clang-tools-extra/clangd/benchmarks/IndexBenchmark.cpp @@ -13,8 +13,6 @@ #include "llvm/ADT/StringRef.h" #include "llvm/Support/Path.h" #include "llvm/Support/Regex.h" -#include <fstream> -#include <streambuf> #include <string> const char *IndexFilename; @@ -34,9 +32,15 @@ std::unique_ptr<SymbolIndex> buildDex() { // Reads JSON array of serialized FuzzyFindRequest's from user-provided file. std::vector<FuzzyFindRequest> extractQueriesFromLogs() { - std::ifstream InputStream(RequestsFilename); - std::string Log((std::istreambuf_iterator<char>(InputStream)), - std::istreambuf_iterator<char>()); + + auto Buffer = llvm::MemoryBuffer::getFile(RequestsFilename); + if (!Buffer) { + llvm::errs() << "Error cannot open JSON request file:" << RequestsFilename + << ": " << Buffer.getError().message() << "\n"; + exit(1); + } + + StringRef Log = Buffer.get()->getBuffer(); std::vector<FuzzyFindRequest> Requests; auto JSONArray = llvm::json::parse(Log); diff --git a/clang-tools-extra/clangd/fuzzer/clangd-fuzzer.cpp b/clang-tools-extra/clangd/fuzzer/clangd-fuzzer.cpp index 41c603b5fd21..1c1ac5bf0c77 100644 --- a/clang-tools-extra/clangd/fuzzer/clangd-fuzzer.cpp +++ b/clang-tools-extra/clangd/fuzzer/clangd-fuzzer.cpp @@ -16,7 +16,6 @@ #include "ClangdServer.h" #include "support/ThreadsafeFS.h" #include <cstdio> -#include <sstream> using namespace clang::clangd; diff --git a/clang-tools-extra/clangd/tool/ClangdMain.cpp b/clang-tools-extra/clangd/tool/ClangdMain.cpp index 51280b73afac..3afcd5f08333 100644 --- a/clang-tools-extra/clangd/tool/ClangdMain.cpp +++ b/clang-tools-extra/clangd/tool/ClangdMain.cpp @@ -39,7 +39,6 @@ #include "llvm/Support/raw_ostream.h" #include <chrono> #include <cstdlib> -#include <iostream> #include <memory> #include <mutex> #include <string> diff --git a/clang-tools-extra/modularize/Modularize.cpp b/clang-tools-extra/modularize/Modularize.cpp index 73c78cff14b2..7f73749f5b54 100644 --- a/clang-tools-extra/modularize/Modularize.cpp +++ b/clang-tools-extra/modularize/Modularize.cpp @@ -247,7 +247,6 @@ #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/Path.h" #include <algorithm> -#include <fstream> #include <iterator> #include <string> #include <vector> _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits