@@ -63,34 +63,34 @@ bool FileRemapper::initFromDisk(StringRef outputDir, Diagnostic &Diag,
63
63
llvm::OwningPtr<llvm::MemoryBuffer> fileBuf;
64
64
if (llvm::error_code ec = llvm::MemoryBuffer::getFile (infoFile.c_str (),
65
65
fileBuf))
66
- return report (std::string ( " Error opening file: " ) + infoFile, Diag);
66
+ return report (" Error opening file: " + infoFile, Diag);
67
67
68
68
SmallVector<StringRef, 64 > lines;
69
69
fileBuf->getBuffer ().split (lines, " \n " );
70
70
71
71
for (unsigned idx = 0 ; idx+3 <= lines.size (); idx += 3 ) {
72
- std::string fromFilename = lines[idx];
72
+ StringRef fromFilename = lines[idx];
73
73
unsigned long long timeModified;
74
74
lines[idx+1 ].getAsInteger (10 , timeModified);
75
- std::string toFilename = lines[idx+2 ];
75
+ StringRef toFilename = lines[idx+2 ];
76
76
77
77
const FileEntry *origFE = FileMgr->getFile (fromFilename);
78
78
if (!origFE) {
79
79
if (ignoreIfFilesChanged)
80
80
continue ;
81
- return report (std::string ( " File does not exist: " ) + fromFilename, Diag);
81
+ return report (" File does not exist: " + fromFilename, Diag);
82
82
}
83
83
const FileEntry *newFE = FileMgr->getFile (toFilename);
84
84
if (!newFE) {
85
85
if (ignoreIfFilesChanged)
86
86
continue ;
87
- return report (std::string ( " File does not exist: " ) + toFilename, Diag);
87
+ return report (" File does not exist: " + toFilename, Diag);
88
88
}
89
89
90
90
if ((uint64_t )origFE->getModificationTime () != timeModified) {
91
91
if (ignoreIfFilesChanged)
92
92
continue ;
93
- return report (std::string ( " File was modified: " ) + fromFilename, Diag);
93
+ return report (" File was modified: " + fromFilename, Diag);
94
94
}
95
95
96
96
pairs.push_back (std::make_pair (origFE, newFE));
@@ -107,8 +107,7 @@ bool FileRemapper::flushToDisk(StringRef outputDir, Diagnostic &Diag) {
107
107
108
108
bool existed;
109
109
if (fs::create_directory (outputDir, existed) != llvm::errc::success)
110
- return report (std::string (" Could not create directory: " ) + outputDir.str (),
111
- Diag);
110
+ return report (" Could not create directory: " + outputDir, Diag);
112
111
113
112
std::string errMsg;
114
113
std::string infoFile = getRemapInfoFile (outputDir);
@@ -138,8 +137,7 @@ bool FileRemapper::flushToDisk(StringRef outputDir, Diagnostic &Diag) {
138
137
tempPath += path::extension (origFE->getName ());
139
138
int fd;
140
139
if (fs::unique_file (tempPath.str (), fd, tempPath) != llvm::errc::success)
141
- return report (std::string (" Could not create file: " ) + tempPath.c_str (),
142
- Diag);
140
+ return report (" Could not create file: " + tempPath.str (), Diag);
143
141
144
142
llvm::raw_fd_ostream newOut (fd, /* shouldClose=*/ true );
145
143
llvm::MemoryBuffer *mem = I->second .get <llvm::MemoryBuffer *>();
@@ -165,20 +163,15 @@ bool FileRemapper::overwriteOriginal(Diagnostic &Diag,
165
163
const FileEntry *origFE = I->first ;
166
164
if (const FileEntry *newFE = I->second .dyn_cast <const FileEntry *>()) {
167
165
if (fs::copy_file (newFE->getName (), origFE->getName (),
168
- fs::copy_option::overwrite_if_exists) != llvm::errc::success) {
169
- std::string err = " Could not copy file '" ;
170
- llvm::raw_string_ostream os (err);
171
- os << " Could not copy file '" << newFE->getName () << " ' to file '"
172
- << origFE->getName () << " '" ;
173
- os.flush ();
174
- return report (err, Diag);
175
- }
166
+ fs::copy_option::overwrite_if_exists) != llvm::errc::success)
167
+ return report (StringRef (" Could not copy file '" ) + newFE->getName () +
168
+ " ' to file '" + origFE->getName () + " '" , Diag);
176
169
} else {
177
170
178
171
bool fileExists = false ;
179
172
fs::exists (origFE->getName (), fileExists);
180
173
if (!fileExists)
181
- return report (std::string (" File does not exist: " ) + origFE->getName (),
174
+ return report (StringRef (" File does not exist: " ) + origFE->getName (),
182
175
Diag);
183
176
184
177
std::string errMsg;
@@ -283,9 +276,10 @@ void FileRemapper::resetTarget(Target &targ) {
283
276
}
284
277
}
285
278
286
- bool FileRemapper::report (const std::string &err, Diagnostic &Diag) {
279
+ bool FileRemapper::report (const Twine &err, Diagnostic &Diag) {
280
+ llvm::SmallString<128 > buf;
287
281
unsigned ID = Diag.getDiagnosticIDs ()->getCustomDiagID (DiagnosticIDs::Error,
288
- err);
282
+ err. toStringRef (buf) );
289
283
Diag.Report (ID);
290
284
return true ;
291
285
}
0 commit comments