r216785 - unique_ptrify some parameters to PTHManager::PTHManager
David Blaikie
dblaikie at gmail.com
Fri Aug 29 15:04:40 PDT 2014
Author: dblaikie
Date: Fri Aug 29 17:04:40 2014
New Revision: 216785
URL: http://llvm.org/viewvc/llvm-project?rev=216785&view=rev
Log:
unique_ptrify some parameters to PTHManager::PTHManager
A couple of these arguments were passed by void* as a rather extreme
example of pimpling. Adjusting this to a more classic form of the idiom
(involving forward declarations) makes this more legible and allows
explicit passing of ownership via std::unique_ptr.
Modified:
cfe/trunk/include/clang/Lex/PTHManager.h
cfe/trunk/lib/Lex/PTHLexer.cpp
Modified: cfe/trunk/include/clang/Lex/PTHManager.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/PTHManager.h?rev=216785&r1=216784&r2=216785&view=diff
==============================================================================
--- cfe/trunk/include/clang/Lex/PTHManager.h (original)
+++ cfe/trunk/include/clang/Lex/PTHManager.h Fri Aug 29 17:04:40 2014
@@ -20,6 +20,7 @@
#include "clang/Lex/PTHLexer.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/Support/Allocator.h"
+#include "llvm/Support/OnDiskHashTable.h"
#include <string>
namespace llvm {
@@ -36,8 +37,15 @@ class FileSystemStatCache;
class PTHManager : public IdentifierInfoLookup {
friend class PTHLexer;
+ friend class PTHStatCache;
+
+ class PTHStringLookupTrait;
+ class PTHFileLookupTrait;
+ typedef llvm::OnDiskChainedHashTable<PTHStringLookupTrait> PTHStringIdLookup;
+ typedef llvm::OnDiskChainedHashTable<PTHFileLookupTrait> PTHFileLookup;
+
/// The memory mapped PTH file.
- const llvm::MemoryBuffer* Buf;
+ std::unique_ptr<const llvm::MemoryBuffer> Buf;
/// Alloc - Allocator used for IdentifierInfo objects.
llvm::BumpPtrAllocator Alloc;
@@ -48,7 +56,7 @@ class PTHManager : public IdentifierInfo
/// FileLookup - Abstract data structure used for mapping between files
/// and token data in the PTH file.
- void* FileLookup;
+ std::unique_ptr<PTHFileLookup> FileLookup;
/// IdDataTable - Array representing the mapping from persistent IDs to the
/// data offset within the PTH file containing the information to
@@ -57,7 +65,7 @@ class PTHManager : public IdentifierInfo
/// SortedIdTable - Abstract data structure mapping from strings to
/// persistent IDs. This is used by get().
- void* StringIdLookup;
+ std::unique_ptr<PTHStringIdLookup> StringIdLookup;
/// NumIds - The number of identifiers in the PTH file.
const unsigned NumIds;
@@ -76,10 +84,11 @@ class PTHManager : public IdentifierInfo
/// This constructor is intended to only be called by the static 'Create'
/// method.
- PTHManager(const llvm::MemoryBuffer* buf, void* fileLookup,
- const unsigned char* idDataTable, IdentifierInfo** perIDCache,
- void* stringIdLookup, unsigned numIds,
- const unsigned char* spellingBase, const char *originalSourceFile);
+ PTHManager(std::unique_ptr<const llvm::MemoryBuffer> buf,
+ std::unique_ptr<PTHFileLookup> fileLookup,
+ const unsigned char *idDataTable, IdentifierInfo **perIDCache,
+ std::unique_ptr<PTHStringIdLookup> stringIdLookup, unsigned numIds,
+ const unsigned char *spellingBase, const char *originalSourceFile);
PTHManager(const PTHManager &) LLVM_DELETED_FUNCTION;
void operator=(const PTHManager &) LLVM_DELETED_FUNCTION;
Modified: cfe/trunk/lib/Lex/PTHLexer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PTHLexer.cpp?rev=216785&r1=216784&r2=216785&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/PTHLexer.cpp (original)
+++ cfe/trunk/lib/Lex/PTHLexer.cpp Fri Aug 29 17:04:40 2014
@@ -24,7 +24,6 @@
#include "llvm/ADT/StringMap.h"
#include "llvm/Support/EndianStream.h"
#include "llvm/Support/MemoryBuffer.h"
-#include "llvm/Support/OnDiskHashTable.h"
#include <memory>
#include <system_error>
using namespace clang;
@@ -342,7 +341,9 @@ public:
}
};
-class PTHFileLookupTrait : public PTHFileLookupCommonTrait {
+} // end anonymous namespace
+
+class PTHManager::PTHFileLookupTrait : public PTHFileLookupCommonTrait {
public:
typedef const FileEntry* external_key_type;
typedef PTHFileData data_type;
@@ -365,7 +366,7 @@ public:
}
};
-class PTHStringLookupTrait {
+class PTHManager::PTHStringLookupTrait {
public:
typedef uint32_t data_type;
typedef const std::pair<const char*, unsigned> external_key_type;
@@ -408,30 +409,23 @@ public:
}
};
-} // end anonymous namespace
-
-typedef llvm::OnDiskChainedHashTable<PTHFileLookupTrait> PTHFileLookup;
-typedef llvm::OnDiskChainedHashTable<PTHStringLookupTrait> PTHStringIdLookup;
-
//===----------------------------------------------------------------------===//
// PTHManager methods.
//===----------------------------------------------------------------------===//
-PTHManager::PTHManager(const llvm::MemoryBuffer* buf, void* fileLookup,
- const unsigned char* idDataTable,
- IdentifierInfo** perIDCache,
- void* stringIdLookup, unsigned numIds,
- const unsigned char* spellingBase,
- const char* originalSourceFile)
-: Buf(buf), PerIDCache(perIDCache), FileLookup(fileLookup),
- IdDataTable(idDataTable), StringIdLookup(stringIdLookup),
- NumIds(numIds), PP(nullptr), SpellingBase(spellingBase),
- OriginalSourceFile(originalSourceFile) {}
+PTHManager::PTHManager(std::unique_ptr<const llvm::MemoryBuffer> buf,
+ std::unique_ptr<PTHFileLookup> fileLookup,
+ const unsigned char *idDataTable,
+ IdentifierInfo **perIDCache,
+ std::unique_ptr<PTHStringIdLookup> stringIdLookup,
+ unsigned numIds, const unsigned char *spellingBase,
+ const char *originalSourceFile)
+ : Buf(std::move(buf)), PerIDCache(perIDCache),
+ FileLookup(std::move(fileLookup)), IdDataTable(idDataTable),
+ StringIdLookup(std::move(stringIdLookup)), NumIds(numIds), PP(nullptr),
+ SpellingBase(spellingBase), OriginalSourceFile(originalSourceFile) {}
PTHManager::~PTHManager() {
- delete Buf;
- delete (PTHFileLookup*) FileLookup;
- delete (PTHStringIdLookup*) StringIdLookup;
free(PerIDCache);
}
@@ -560,8 +554,8 @@ PTHManager *PTHManager::Create(const std
if (!len) originalSourceBase = nullptr;
// Create the new PTHManager.
- return new PTHManager(File.release(), FL.release(), IData, PerIDCache,
- SL.release(), NumIds, spellingBase,
+ return new PTHManager(std::move(File), std::move(FL), IData, PerIDCache,
+ std::move(SL), NumIds, spellingBase,
(const char *)originalSourceBase);
}
@@ -589,12 +583,11 @@ IdentifierInfo* PTHManager::LazilyCreate
}
IdentifierInfo* PTHManager::get(StringRef Name) {
- PTHStringIdLookup& SL = *((PTHStringIdLookup*)StringIdLookup);
// Double check our assumption that the last character isn't '\0'.
assert(Name.empty() || Name.back() != '\0');
- PTHStringIdLookup::iterator I = SL.find(std::make_pair(Name.data(),
- Name.size()));
- if (I == SL.end()) // No identifier found?
+ PTHStringIdLookup::iterator I =
+ StringIdLookup->find(std::make_pair(Name.data(), Name.size()));
+ if (I == StringIdLookup->end()) // No identifier found?
return nullptr;
// Match found. Return the identifier!
@@ -612,10 +605,9 @@ PTHLexer *PTHManager::CreateLexer(FileID
// Lookup the FileEntry object in our file lookup data structure. It will
// return a variant that indicates whether or not there is an offset within
// the PTH file that contains cached tokens.
- PTHFileLookup& PFL = *((PTHFileLookup*)FileLookup);
- PTHFileLookup::iterator I = PFL.find(FE);
+ PTHFileLookup::iterator I = FileLookup->find(FE);
- if (I == PFL.end()) // No tokens available?
+ if (I == FileLookup->end()) // No tokens available?
return nullptr;
const PTHFileData& FileData = *I;
@@ -694,15 +686,17 @@ public:
return data_type();
}
};
+} // end anonymous namespace
+namespace clang {
class PTHStatCache : public FileSystemStatCache {
typedef llvm::OnDiskChainedHashTable<PTHStatLookupTrait> CacheTy;
CacheTy Cache;
public:
- PTHStatCache(PTHFileLookup &FL) :
- Cache(FL.getNumBuckets(), FL.getNumEntries(), FL.getBuckets(),
- FL.getBase()) {}
+ PTHStatCache(PTHManager::PTHFileLookup &FL)
+ : Cache(FL.getNumBuckets(), FL.getNumEntries(), FL.getBuckets(),
+ FL.getBase()) {}
LookupResult getStat(const char *Path, FileData &Data, bool isFile,
std::unique_ptr<vfs::File> *F,
@@ -730,8 +724,8 @@ public:
return CacheExists;
}
};
-} // end anonymous namespace
+}
std::unique_ptr<FileSystemStatCache> PTHManager::createStatCache() {
- return llvm::make_unique<PTHStatCache>(*((PTHFileLookup *)FileLookup));
+ return llvm::make_unique<PTHStatCache>(*FileLookup);
}
More information about the cfe-commits
mailing list