Store FileEntry::Filename as a StringRef instead of raw pointer (NFC)
llvm-svn: 283815
This commit is contained in:
parent
0da86301ad
commit
004b9c7aae
|
@ -51,7 +51,7 @@ public:
|
|||
/// If the 'File' member is valid, then this FileEntry has an open file
|
||||
/// descriptor for the file.
|
||||
class FileEntry {
|
||||
const char *Name; // Name of the file.
|
||||
StringRef Name; // Name of the file.
|
||||
std::string RealPathName; // Real path to the file; could be empty.
|
||||
off_t Size; // File size in bytes.
|
||||
time_t ModTime; // Modification time of file.
|
||||
|
@ -82,7 +82,7 @@ public:
|
|||
assert(!isValid() && "Cannot copy an initialized FileEntry");
|
||||
}
|
||||
|
||||
const char *getName() const { return Name; }
|
||||
StringRef getName() const { return Name; }
|
||||
StringRef tryGetRealPathName() const { return RealPathName; }
|
||||
bool isValid() const { return IsValid; }
|
||||
off_t getSize() const { return Size; }
|
||||
|
|
|
@ -423,7 +423,7 @@ FileManager::getBufferForFile(const FileEntry *Entry, bool isVolatile,
|
|||
if (isVolatile)
|
||||
FileSize = -1;
|
||||
|
||||
const char *Filename = Entry->getName();
|
||||
StringRef Filename = Entry->getName();
|
||||
// If the file is already open, use the open file descriptor.
|
||||
if (Entry->File) {
|
||||
auto Result =
|
||||
|
|
|
@ -2582,7 +2582,7 @@ llvm::Function *CGObjCGNU::ModuleInitFunction() {
|
|||
SourceManager &SM = CGM.getContext().getSourceManager();
|
||||
const FileEntry *mainFile = SM.getFileEntryForID(SM.getMainFileID());
|
||||
std::string path =
|
||||
std::string(mainFile->getDir()->getName()) + '/' + mainFile->getName();
|
||||
(Twine(mainFile->getDir()->getName()) + "/" + mainFile->getName()).str();
|
||||
Elements.push_back(MakeConstantString(path, ".objc_source_file_name"));
|
||||
Elements.push_back(SymTab);
|
||||
|
||||
|
|
|
@ -847,17 +847,19 @@ LookupSubframeworkHeader(StringRef Filename,
|
|||
if (SlashPos == StringRef::npos) return nullptr;
|
||||
|
||||
// Look up the base framework name of the ContextFileEnt.
|
||||
const char *ContextName = ContextFileEnt->getName();
|
||||
StringRef ContextName = ContextFileEnt->getName();
|
||||
|
||||
// If the context info wasn't a framework, couldn't be a subframework.
|
||||
const unsigned DotFrameworkLen = 10;
|
||||
const char *FrameworkPos = strstr(ContextName, ".framework");
|
||||
if (FrameworkPos == nullptr ||
|
||||
(FrameworkPos[DotFrameworkLen] != '/' &&
|
||||
FrameworkPos[DotFrameworkLen] != '\\'))
|
||||
auto FrameworkPos = ContextName.find(".framework");
|
||||
if (FrameworkPos == StringRef::npos ||
|
||||
(ContextName[FrameworkPos + DotFrameworkLen] != '/' &&
|
||||
ContextName[FrameworkPos + DotFrameworkLen] != '\\'))
|
||||
return nullptr;
|
||||
|
||||
SmallString<1024> FrameworkName(ContextName, FrameworkPos+DotFrameworkLen+1);
|
||||
SmallString<1024> FrameworkName(ContextName.data(), ContextName.data() +
|
||||
FrameworkPos +
|
||||
DotFrameworkLen + 1);
|
||||
|
||||
// Append Frameworks/HIToolbox.framework/
|
||||
FrameworkName += "Frameworks/";
|
||||
|
@ -1449,7 +1451,7 @@ std::string HeaderSearch::suggestPathToFileForDiagnostics(const FileEntry *File,
|
|||
// FIXME: We assume that the path name currently cached in the FileEntry is
|
||||
// the most appropriate one for this analysis (and that it's spelled the same
|
||||
// way as the corresponding header search path).
|
||||
const char *Name = File->getName();
|
||||
StringRef Name = File->getName();
|
||||
|
||||
unsigned BestPrefixLength = 0;
|
||||
unsigned BestSearchDir;
|
||||
|
@ -1492,5 +1494,5 @@ std::string HeaderSearch::suggestPathToFileForDiagnostics(const FileEntry *File,
|
|||
|
||||
if (IsSystem)
|
||||
*IsSystem = BestPrefixLength ? BestSearchDir >= SystemDirIdx : false;
|
||||
return Name + BestPrefixLength;
|
||||
return Name.drop_front(BestPrefixLength);
|
||||
}
|
||||
|
|
|
@ -317,7 +317,7 @@ public:
|
|||
|
||||
class PTHFileLookupCommonTrait {
|
||||
public:
|
||||
typedef std::pair<unsigned char, const char*> internal_key_type;
|
||||
typedef std::pair<unsigned char, StringRef> internal_key_type;
|
||||
typedef unsigned hash_value_type;
|
||||
typedef unsigned offset_type;
|
||||
|
||||
|
@ -352,7 +352,7 @@ public:
|
|||
}
|
||||
|
||||
static bool EqualKey(internal_key_type a, internal_key_type b) {
|
||||
return a.first == b.first && strcmp(a.second, b.second) == 0;
|
||||
return a.first == b.first && a.second == b.second;
|
||||
}
|
||||
|
||||
static PTHFileData ReadData(const internal_key_type& k,
|
||||
|
@ -655,7 +655,7 @@ public:
|
|||
static bool EqualKey(internal_key_type a, internal_key_type b) {
|
||||
// When doing 'stat' lookups we don't care about the kind of 'a' and 'b',
|
||||
// just the paths.
|
||||
return strcmp(a.second, b.second) == 0;
|
||||
return a.second == b.second;
|
||||
}
|
||||
|
||||
static data_type ReadData(const internal_key_type& k, const unsigned char* d,
|
||||
|
|
|
@ -1600,8 +1600,7 @@ bool HeaderFileInfoTrait::EqualKey(internal_key_ref a, internal_key_ref b) {
|
|||
if (a.Size != b.Size || (a.ModTime && b.ModTime && a.ModTime != b.ModTime))
|
||||
return false;
|
||||
|
||||
if (llvm::sys::path::is_absolute(a.Filename) &&
|
||||
strcmp(a.Filename, b.Filename) == 0)
|
||||
if (llvm::sys::path::is_absolute(a.Filename) && a.Filename == b.Filename)
|
||||
return true;
|
||||
|
||||
// Determine whether the actual files are equivalent.
|
||||
|
|
|
@ -257,7 +257,7 @@ public:
|
|||
struct internal_key_type {
|
||||
off_t Size;
|
||||
time_t ModTime;
|
||||
const char *Filename;
|
||||
StringRef Filename;
|
||||
bool Imported;
|
||||
};
|
||||
typedef const internal_key_type &internal_key_ref;
|
||||
|
|
|
@ -1808,7 +1808,7 @@ namespace {
|
|||
|
||||
struct key_type {
|
||||
const FileEntry *FE;
|
||||
const char *Filename;
|
||||
StringRef Filename;
|
||||
};
|
||||
typedef const key_type &key_type_ref;
|
||||
|
||||
|
@ -1829,7 +1829,7 @@ namespace {
|
|||
EmitKeyDataLength(raw_ostream& Out, key_type_ref key, data_type_ref Data) {
|
||||
using namespace llvm::support;
|
||||
endian::Writer<little> LE(Out);
|
||||
unsigned KeyLen = strlen(key.Filename) + 1 + 8 + 8;
|
||||
unsigned KeyLen = key.Filename.size() + 1 + 8 + 8;
|
||||
LE.write<uint16_t>(KeyLen);
|
||||
unsigned DataLen = 1 + 2 + 4 + 4;
|
||||
for (auto ModInfo : HS.getModuleMap().findAllModulesForHeader(key.FE))
|
||||
|
@ -1846,7 +1846,7 @@ namespace {
|
|||
KeyLen -= 8;
|
||||
LE.write<uint64_t>(Writer.getTimestampForOutput(key.FE));
|
||||
KeyLen -= 8;
|
||||
Out.write(key.Filename, KeyLen);
|
||||
Out.write(key.Filename.data(), KeyLen);
|
||||
}
|
||||
|
||||
void EmitData(raw_ostream &Out, key_type_ref key,
|
||||
|
@ -1935,13 +1935,13 @@ void ASTWriter::WriteHeaderSearch(const HeaderSearch &HS) {
|
|||
continue;
|
||||
|
||||
// Massage the file path into an appropriate form.
|
||||
const char *Filename = File->getName();
|
||||
StringRef Filename = File->getName();
|
||||
SmallString<128> FilenameTmp(Filename);
|
||||
if (PreparePathForOutput(FilenameTmp)) {
|
||||
// If we performed any translation on the file name at all, we need to
|
||||
// save this string, since the generator will refer to it later.
|
||||
Filename = strdup(FilenameTmp.c_str());
|
||||
SavedStrings.push_back(Filename);
|
||||
Filename = StringRef(strdup(FilenameTmp.c_str()));
|
||||
SavedStrings.push_back(Filename.data());
|
||||
}
|
||||
|
||||
HeaderFileInfoTrait::key_type key = { File, Filename };
|
||||
|
|
|
@ -139,16 +139,17 @@ CXSourceLocation clang_getLocation(CXTranslationUnit TU,
|
|||
if (SLoc.isInvalid()) {
|
||||
if (Log)
|
||||
*Log << llvm::format("(\"%s\", %d, %d) = invalid",
|
||||
File->getName(), line, column);
|
||||
File->getName().str().c_str(), line, column);
|
||||
return clang_getNullLocation();
|
||||
}
|
||||
|
||||
CXSourceLocation CXLoc =
|
||||
cxloc::translateSourceLocation(CXXUnit->getASTContext(), SLoc);
|
||||
if (Log)
|
||||
*Log << llvm::format("(\"%s\", %d, %d) = ", File->getName(), line, column)
|
||||
*Log << llvm::format("(\"%s\", %d, %d) = ", File->getName().str().c_str(),
|
||||
line, column)
|
||||
<< CXLoc;
|
||||
|
||||
|
||||
return CXLoc;
|
||||
}
|
||||
|
||||
|
|
|
@ -140,7 +140,7 @@ TEST_F(FileManagerTest, getFileReturnsValidFileEntryForExistingRealFile) {
|
|||
|
||||
const FileEntry *file = manager.getFile("/tmp/test");
|
||||
ASSERT_TRUE(file != nullptr);
|
||||
EXPECT_STREQ("/tmp/test", file->getName());
|
||||
EXPECT_EQ("/tmp/test", file->getName());
|
||||
|
||||
const DirectoryEntry *dir = file->getDir();
|
||||
ASSERT_TRUE(dir != nullptr);
|
||||
|
@ -164,7 +164,7 @@ TEST_F(FileManagerTest, getFileReturnsValidFileEntryForExistingVirtualFile) {
|
|||
manager.getVirtualFile("virtual/dir/bar.h", 100, 0);
|
||||
const FileEntry *file = manager.getFile("virtual/dir/bar.h");
|
||||
ASSERT_TRUE(file != nullptr);
|
||||
EXPECT_STREQ("virtual/dir/bar.h", file->getName());
|
||||
EXPECT_EQ("virtual/dir/bar.h", file->getName());
|
||||
|
||||
const DirectoryEntry *dir = file->getDir();
|
||||
ASSERT_TRUE(dir != nullptr);
|
||||
|
|
Loading…
Reference in New Issue