Skip to content

Commit 00c7d66

Browse files
committed
[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
1 parent a7cad66 commit 00c7d66

File tree

7 files changed

+22
-26
lines changed

7 files changed

+22
-26
lines changed

clang-tools-extra/clang-query/tool/ClangQuery.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@
3333
#include "clang/Tooling/Tooling.h"
3434
#include "llvm/LineEditor/LineEditor.h"
3535
#include "llvm/Support/CommandLine.h"
36+
#include "llvm/Support/Error.h"
3637
#include "llvm/Support/MemoryBuffer.h"
3738
#include "llvm/Support/Signals.h"
3839
#include "llvm/Support/WithColor.h"
39-
#include <fstream>
4040
#include <string>
4141

4242
using namespace clang;
@@ -73,16 +73,15 @@ static cl::opt<std::string> PreloadFile(
7373

7474
bool runCommandsInFile(const char *ExeName, std::string const &FileName,
7575
QuerySession &QS) {
76-
std::ifstream Input(FileName.c_str());
77-
if (!Input.is_open()) {
78-
llvm::errs() << ExeName << ": cannot open " << FileName << "\n";
79-
return 1;
76+
auto Buffer = llvm::MemoryBuffer::getFile(FileName);
77+
if (!Buffer) {
78+
llvm::errs() << ExeName << ": cannot open " << FileName << ": "
79+
<< Buffer.getError().message() << "\n";
80+
return true;
8081
}
8182

82-
std::string FileContent((std::istreambuf_iterator<char>(Input)),
83-
std::istreambuf_iterator<char>());
83+
StringRef FileContentRef(Buffer.get()->getBuffer());
8484

85-
StringRef FileContentRef(FileContent);
8685
while (!FileContentRef.empty()) {
8786
QueryRef Q = QueryParser::parse(FileContentRef, QS);
8887
if (!Q->run(llvm::outs(), QS))

clang-tools-extra/clang-tidy/altera/StructPackAlignCheck.cpp

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
#include "clang/AST/RecordLayout.h"
1212
#include "clang/ASTMatchers/ASTMatchFinder.h"
1313
#include <math.h>
14-
#include <sstream>
1514

1615
using namespace clang::ast_matchers;
1716

@@ -109,15 +108,13 @@ void StructPackAlignCheck::check(const MatchFinder::MatchResult &Result) {
109108
AlignedAttr *Attribute = Struct->getAttr<AlignedAttr>();
110109
std::string NewAlignQuantity = std::to_string((int)NewAlign.getQuantity());
111110
if (Attribute) {
112-
std::ostringstream FixItString;
113-
FixItString << "aligned(" << NewAlignQuantity << ")";
114-
FixIt =
115-
FixItHint::CreateReplacement(Attribute->getRange(), FixItString.str());
111+
FixIt = FixItHint::CreateReplacement(
112+
Attribute->getRange(),
113+
(Twine("aligned(") + NewAlignQuantity + ")").str());
116114
} else {
117-
std::ostringstream FixItString;
118-
FixItString << " __attribute__((aligned(" << NewAlignQuantity << ")))";
119-
FixIt = FixItHint::CreateInsertion(Struct->getEndLoc().getLocWithOffset(1),
120-
FixItString.str());
115+
FixIt = FixItHint::CreateInsertion(
116+
Struct->getEndLoc().getLocWithOffset(1),
117+
(Twine(" __attribute__((aligned(") + NewAlignQuantity + ")))").str());
121118
}
122119

123120
// And suggest the minimum power-of-two alignment for the struct as a whole

clang-tools-extra/clang-tidy/readability/InconsistentDeclarationParameterNameCheck.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212

1313
#include <algorithm>
1414
#include <functional>
15-
#include <sstream>
1615

1716
using namespace clang::ast_matchers;
1817

clang-tools-extra/clangd/benchmarks/IndexBenchmark.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313
#include "llvm/ADT/StringRef.h"
1414
#include "llvm/Support/Path.h"
1515
#include "llvm/Support/Regex.h"
16-
#include <fstream>
17-
#include <streambuf>
1816
#include <string>
1917

2018
const char *IndexFilename;
@@ -34,9 +32,15 @@ std::unique_ptr<SymbolIndex> buildDex() {
3432

3533
// Reads JSON array of serialized FuzzyFindRequest's from user-provided file.
3634
std::vector<FuzzyFindRequest> extractQueriesFromLogs() {
37-
std::ifstream InputStream(RequestsFilename);
38-
std::string Log((std::istreambuf_iterator<char>(InputStream)),
39-
std::istreambuf_iterator<char>());
35+
36+
auto Buffer = llvm::MemoryBuffer::getFile(RequestsFilename);
37+
if (!Buffer) {
38+
llvm::errs() << "Error cannot open JSON request file:" << RequestsFilename
39+
<< ": " << Buffer.getError().message() << "\n";
40+
exit(1);
41+
}
42+
43+
StringRef Log = Buffer.get()->getBuffer();
4044

4145
std::vector<FuzzyFindRequest> Requests;
4246
auto JSONArray = llvm::json::parse(Log);

clang-tools-extra/clangd/fuzzer/clangd-fuzzer.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
#include "ClangdServer.h"
1717
#include "support/ThreadsafeFS.h"
1818
#include <cstdio>
19-
#include <sstream>
2019

2120
using namespace clang::clangd;
2221

clang-tools-extra/clangd/tool/ClangdMain.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
#include "llvm/Support/raw_ostream.h"
4040
#include <chrono>
4141
#include <cstdlib>
42-
#include <iostream>
4342
#include <memory>
4443
#include <mutex>
4544
#include <string>

clang-tools-extra/modularize/Modularize.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,6 @@
247247
#include "llvm/Support/MemoryBuffer.h"
248248
#include "llvm/Support/Path.h"
249249
#include <algorithm>
250-
#include <fstream>
251250
#include <iterator>
252251
#include <string>
253252
#include <vector>

0 commit comments

Comments
 (0)