Skip to content

Commit 79cfba1

Browse files
committed
Twinify.
llvm-svn: 138689
1 parent e89397a commit 79cfba1

File tree

2 files changed

+16
-22
lines changed

2 files changed

+16
-22
lines changed

clang/include/clang/ARCMigrate/FileRemapper.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class FileRemapper {
6565
const FileEntry *getOriginalFile(StringRef filePath);
6666
void resetTarget(Target &targ);
6767

68-
bool report(const std::string &err, Diagnostic &Diag);
68+
bool report(const Twine &err, Diagnostic &Diag);
6969

7070
std::string getRemapInfoFile(StringRef outputDir);
7171
};

clang/lib/ARCMigrate/FileRemapper.cpp

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -63,34 +63,34 @@ bool FileRemapper::initFromDisk(StringRef outputDir, Diagnostic &Diag,
6363
llvm::OwningPtr<llvm::MemoryBuffer> fileBuf;
6464
if (llvm::error_code ec = llvm::MemoryBuffer::getFile(infoFile.c_str(),
6565
fileBuf))
66-
return report(std::string("Error opening file: ") + infoFile, Diag);
66+
return report("Error opening file: " + infoFile, Diag);
6767

6868
SmallVector<StringRef, 64> lines;
6969
fileBuf->getBuffer().split(lines, "\n");
7070

7171
for (unsigned idx = 0; idx+3 <= lines.size(); idx += 3) {
72-
std::string fromFilename = lines[idx];
72+
StringRef fromFilename = lines[idx];
7373
unsigned long long timeModified;
7474
lines[idx+1].getAsInteger(10, timeModified);
75-
std::string toFilename = lines[idx+2];
75+
StringRef toFilename = lines[idx+2];
7676

7777
const FileEntry *origFE = FileMgr->getFile(fromFilename);
7878
if (!origFE) {
7979
if (ignoreIfFilesChanged)
8080
continue;
81-
return report(std::string("File does not exist: ") + fromFilename, Diag);
81+
return report("File does not exist: " + fromFilename, Diag);
8282
}
8383
const FileEntry *newFE = FileMgr->getFile(toFilename);
8484
if (!newFE) {
8585
if (ignoreIfFilesChanged)
8686
continue;
87-
return report(std::string("File does not exist: ") + toFilename, Diag);
87+
return report("File does not exist: " + toFilename, Diag);
8888
}
8989

9090
if ((uint64_t)origFE->getModificationTime() != timeModified) {
9191
if (ignoreIfFilesChanged)
9292
continue;
93-
return report(std::string("File was modified: ") + fromFilename, Diag);
93+
return report("File was modified: " + fromFilename, Diag);
9494
}
9595

9696
pairs.push_back(std::make_pair(origFE, newFE));
@@ -107,8 +107,7 @@ bool FileRemapper::flushToDisk(StringRef outputDir, Diagnostic &Diag) {
107107

108108
bool existed;
109109
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);
112111

113112
std::string errMsg;
114113
std::string infoFile = getRemapInfoFile(outputDir);
@@ -138,8 +137,7 @@ bool FileRemapper::flushToDisk(StringRef outputDir, Diagnostic &Diag) {
138137
tempPath += path::extension(origFE->getName());
139138
int fd;
140139
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);
143141

144142
llvm::raw_fd_ostream newOut(fd, /*shouldClose=*/true);
145143
llvm::MemoryBuffer *mem = I->second.get<llvm::MemoryBuffer *>();
@@ -165,20 +163,15 @@ bool FileRemapper::overwriteOriginal(Diagnostic &Diag,
165163
const FileEntry *origFE = I->first;
166164
if (const FileEntry *newFE = I->second.dyn_cast<const FileEntry *>()) {
167165
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);
176169
} else {
177170

178171
bool fileExists = false;
179172
fs::exists(origFE->getName(), fileExists);
180173
if (!fileExists)
181-
return report(std::string("File does not exist: ") + origFE->getName(),
174+
return report(StringRef("File does not exist: ") + origFE->getName(),
182175
Diag);
183176

184177
std::string errMsg;
@@ -283,9 +276,10 @@ void FileRemapper::resetTarget(Target &targ) {
283276
}
284277
}
285278

286-
bool FileRemapper::report(const std::string &err, Diagnostic &Diag) {
279+
bool FileRemapper::report(const Twine &err, Diagnostic &Diag) {
280+
llvm::SmallString<128> buf;
287281
unsigned ID = Diag.getDiagnosticIDs()->getCustomDiagID(DiagnosticIDs::Error,
288-
err);
282+
err.toStringRef(buf));
289283
Diag.Report(ID);
290284
return true;
291285
}

0 commit comments

Comments
 (0)