File tree Expand file tree Collapse file tree 7 files changed +22
-26
lines changed Expand file tree Collapse file tree 7 files changed +22
-26
lines changed Original file line number Diff line number Diff line change 33
33
#include " clang/Tooling/Tooling.h"
34
34
#include " llvm/LineEditor/LineEditor.h"
35
35
#include " llvm/Support/CommandLine.h"
36
+ #include " llvm/Support/Error.h"
36
37
#include " llvm/Support/MemoryBuffer.h"
37
38
#include " llvm/Support/Signals.h"
38
39
#include " llvm/Support/WithColor.h"
39
- #include < fstream>
40
40
#include < string>
41
41
42
42
using namespace clang ;
@@ -73,16 +73,15 @@ static cl::opt<std::string> PreloadFile(
73
73
74
74
bool runCommandsInFile (const char *ExeName, std::string const &FileName,
75
75
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 ;
80
81
}
81
82
82
- std::string FileContent ((std::istreambuf_iterator<char >(Input)),
83
- std::istreambuf_iterator<char >());
83
+ StringRef FileContentRef (Buffer.get ()->getBuffer ());
84
84
85
- StringRef FileContentRef (FileContent);
86
85
while (!FileContentRef.empty ()) {
87
86
QueryRef Q = QueryParser::parse (FileContentRef, QS);
88
87
if (!Q->run (llvm::outs (), QS))
Original file line number Diff line number Diff line change 11
11
#include " clang/AST/RecordLayout.h"
12
12
#include " clang/ASTMatchers/ASTMatchFinder.h"
13
13
#include < math.h>
14
- #include < sstream>
15
14
16
15
using namespace clang ::ast_matchers;
17
16
@@ -109,15 +108,13 @@ void StructPackAlignCheck::check(const MatchFinder::MatchResult &Result) {
109
108
AlignedAttr *Attribute = Struct->getAttr <AlignedAttr>();
110
109
std::string NewAlignQuantity = std::to_string ((int )NewAlign.getQuantity ());
111
110
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 ());
116
114
} 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 ());
121
118
}
122
119
123
120
// And suggest the minimum power-of-two alignment for the struct as a whole
Original file line number Diff line number Diff line change 12
12
13
13
#include < algorithm>
14
14
#include < functional>
15
- #include < sstream>
16
15
17
16
using namespace clang ::ast_matchers;
18
17
Original file line number Diff line number Diff line change 13
13
#include " llvm/ADT/StringRef.h"
14
14
#include " llvm/Support/Path.h"
15
15
#include " llvm/Support/Regex.h"
16
- #include < fstream>
17
- #include < streambuf>
18
16
#include < string>
19
17
20
18
const char *IndexFilename;
@@ -34,9 +32,15 @@ std::unique_ptr<SymbolIndex> buildDex() {
34
32
35
33
// Reads JSON array of serialized FuzzyFindRequest's from user-provided file.
36
34
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 ();
40
44
41
45
std::vector<FuzzyFindRequest> Requests;
42
46
auto JSONArray = llvm::json::parse (Log);
Original file line number Diff line number Diff line change 16
16
#include " ClangdServer.h"
17
17
#include " support/ThreadsafeFS.h"
18
18
#include < cstdio>
19
- #include < sstream>
20
19
21
20
using namespace clang ::clangd;
22
21
Original file line number Diff line number Diff line change 39
39
#include " llvm/Support/raw_ostream.h"
40
40
#include < chrono>
41
41
#include < cstdlib>
42
- #include < iostream>
43
42
#include < memory>
44
43
#include < mutex>
45
44
#include < string>
Original file line number Diff line number Diff line change 247
247
#include " llvm/Support/MemoryBuffer.h"
248
248
#include " llvm/Support/Path.h"
249
249
#include < algorithm>
250
- #include < fstream>
251
250
#include < iterator>
252
251
#include < string>
253
252
#include < vector>
You can’t perform that action at this time.
0 commit comments