public:
/// This attempts to load the specified file as a header map. If it doesn't
/// look like a HeaderMap, it gives up and returns null.
- static const HeaderMap *Create(const FileEntry *FE, FileManager &FM);
+ static std::unique_ptr<HeaderMap> Create(const FileEntry *FE,
+ FileManager &FM);
/// Check to see if the specified relative filename is located in this
/// HeaderMap. If so, open it and return its FileEntry. If RawPath is not
#include "clang/Basic/SourceLocation.h"
#include "clang/Basic/SourceManager.h"
#include "clang/Lex/DirectoryLookup.h"
+#include "clang/Lex/HeaderMap.h"
#include "clang/Lex/ModuleMap.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/DenseMap.h"
class ExternalPreprocessorSource;
class FileEntry;
class FileManager;
-class HeaderMap;
class HeaderSearchOptions;
class IdentifierInfo;
class LangOptions;
llvm::StringMap<std::string, llvm::BumpPtrAllocator>;
std::unique_ptr<IncludeAliasMap> IncludeAliases;
- /// This is a mapping from FileEntry -> HeaderMap, uniquing
- /// headermaps. This vector owns the headermap.
- std::vector<std::pair<const FileEntry *, const HeaderMap *>> HeaderMaps;
+ /// This is a mapping from FileEntry -> HeaderMap, uniquing headermaps.
+ std::vector<std::pair<const FileEntry *, std::unique_ptr<HeaderMap>>> HeaderMaps;
/// The mapping between modules and headers.
mutable ModuleMap ModMap;
const LangOptions &LangOpts, const TargetInfo *Target);
HeaderSearch(const HeaderSearch &) = delete;
HeaderSearch &operator=(const HeaderSearch &) = delete;
- ~HeaderSearch();
/// Retrieve the header-search options with which this header search
/// was initialized.
/// map. If it doesn't look like a HeaderMap, it gives up and returns null.
/// If it looks like a HeaderMap but is obviously corrupted, it puts a reason
/// into the string error argument and returns null.
-const HeaderMap *HeaderMap::Create(const FileEntry *FE, FileManager &FM) {
+std::unique_ptr<HeaderMap> HeaderMap::Create(const FileEntry *FE,
+ FileManager &FM) {
// If the file is too small to be a header map, ignore it.
unsigned FileSize = FE->getSize();
if (FileSize <= sizeof(HMapHeader)) return nullptr;
bool NeedsByteSwap;
if (!checkHeader(**FileBuffer, NeedsByteSwap))
return nullptr;
- return new HeaderMap(std::move(*FileBuffer), NeedsByteSwap);
+ return std::unique_ptr<HeaderMap>(new HeaderMap(std::move(*FileBuffer), NeedsByteSwap));
}
bool HeaderMapImpl::checkHeader(const llvm::MemoryBuffer &File,
FileMgr(SourceMgr.getFileManager()), FrameworkMap(64),
ModMap(SourceMgr, Diags, LangOpts, Target, *this) {}
-HeaderSearch::~HeaderSearch() {
- // Delete headermaps.
- for (unsigned i = 0, e = HeaderMaps.size(); i != e; ++i)
- delete HeaderMaps[i].second;
-}
-
void HeaderSearch::PrintStats() {
fprintf(stderr, "\n*** HeaderSearch Stats:\n");
fprintf(stderr, "%d files tracked.\n", (int)FileInfo.size());
// Pointer equality comparison of FileEntries works because they are
// already uniqued by inode.
if (HeaderMaps[i].first == FE)
- return HeaderMaps[i].second;
+ return HeaderMaps[i].second.get();
}
- if (const HeaderMap *HM = HeaderMap::Create(FE, FileMgr)) {
- HeaderMaps.push_back(std::make_pair(FE, HM));
- return HM;
+ if (std::unique_ptr<HeaderMap> HM = HeaderMap::Create(FE, FileMgr)) {
+ HeaderMaps.emplace_back(FE, std::move(HM));
+ return HeaderMaps.back().second.get();
}
return nullptr;