mirror of
https://github.com/intel/llvm.git
synced 2026-02-07 16:11:27 +08:00
Associate the macro arguments location map with a FileID instead
of a ContentCache, since multiple FileIDs can have the same ContentCache but the expanded macro arguments locations will be different. llvm-svn: 140521
This commit is contained in:
@@ -104,11 +104,6 @@ namespace SrcMgr {
|
||||
/// if SourceLineCache is non-null.
|
||||
unsigned NumLines;
|
||||
|
||||
/// \brief Lazily computed map of macro argument chunks to their expanded
|
||||
/// source location.
|
||||
typedef std::map<unsigned, SourceLocation> MacroArgsMap;
|
||||
MacroArgsMap *MacroArgsCache;
|
||||
|
||||
/// getBuffer - Returns the memory buffer for the associated content.
|
||||
///
|
||||
/// \param Diag Object through which diagnostics will be emitted if the
|
||||
@@ -166,11 +161,11 @@ namespace SrcMgr {
|
||||
|
||||
ContentCache(const FileEntry *Ent = 0)
|
||||
: Buffer(0, false), OrigEntry(Ent), ContentsEntry(Ent),
|
||||
SourceLineCache(0), NumLines(0), MacroArgsCache(0) {}
|
||||
SourceLineCache(0), NumLines(0) {}
|
||||
|
||||
ContentCache(const FileEntry *Ent, const FileEntry *contentEnt)
|
||||
: Buffer(0, false), OrigEntry(Ent), ContentsEntry(contentEnt),
|
||||
SourceLineCache(0), NumLines(0), MacroArgsCache(0) {}
|
||||
SourceLineCache(0), NumLines(0) {}
|
||||
|
||||
~ContentCache();
|
||||
|
||||
@@ -178,14 +173,13 @@ namespace SrcMgr {
|
||||
/// a non-NULL Buffer or SourceLineCache. Ownership of allocated memory
|
||||
/// is not transferred, so this is a logical error.
|
||||
ContentCache(const ContentCache &RHS)
|
||||
: Buffer(0, false), SourceLineCache(0), MacroArgsCache(0)
|
||||
: Buffer(0, false), SourceLineCache(0)
|
||||
{
|
||||
OrigEntry = RHS.OrigEntry;
|
||||
ContentsEntry = RHS.ContentsEntry;
|
||||
|
||||
assert (RHS.Buffer.getPointer() == 0 && RHS.SourceLineCache == 0 &&
|
||||
RHS.MacroArgsCache == 0
|
||||
&& "Passed ContentCache object cannot own a buffer.");
|
||||
"Passed ContentCache object cannot own a buffer.");
|
||||
|
||||
NumLines = RHS.NumLines;
|
||||
}
|
||||
@@ -571,6 +565,12 @@ class SourceManager : public llvm::RefCountedBase<SourceManager> {
|
||||
// Cache for the "fake" buffer used for error-recovery purposes.
|
||||
mutable llvm::MemoryBuffer *FakeBufferForRecovery;
|
||||
|
||||
/// \brief Lazily computed map of macro argument chunks to their expanded
|
||||
/// source location.
|
||||
typedef std::map<unsigned, SourceLocation> MacroArgsMap;
|
||||
|
||||
mutable llvm::DenseMap<FileID, MacroArgsMap *> MacroArgsCacheMap;
|
||||
|
||||
// SourceManager doesn't support copy construction.
|
||||
explicit SourceManager(const SourceManager&);
|
||||
void operator=(const SourceManager&);
|
||||
@@ -1301,7 +1301,7 @@ private:
|
||||
std::pair<FileID, unsigned>
|
||||
getDecomposedSpellingLocSlowCase(const SrcMgr::SLocEntry *E,
|
||||
unsigned Offset) const;
|
||||
void computeMacroArgsCache(SrcMgr::ContentCache *Content, FileID FID) const;
|
||||
void computeMacroArgsCache(MacroArgsMap *&MacroArgsCache, FileID FID) const;
|
||||
|
||||
friend class ASTReader;
|
||||
friend class ASTWriter;
|
||||
|
||||
@@ -39,7 +39,6 @@ using llvm::MemoryBuffer;
|
||||
ContentCache::~ContentCache() {
|
||||
if (shouldFreeBuffer())
|
||||
delete Buffer.getPointer();
|
||||
delete MacroArgsCache;
|
||||
}
|
||||
|
||||
/// getSizeBytesMapped - Returns the number of bytes actually mapped for this
|
||||
@@ -389,6 +388,11 @@ SourceManager::~SourceManager() {
|
||||
}
|
||||
|
||||
delete FakeBufferForRecovery;
|
||||
|
||||
for (llvm::DenseMap<FileID, MacroArgsMap *>::iterator
|
||||
I = MacroArgsCacheMap.begin(),E = MacroArgsCacheMap.end(); I!=E; ++I) {
|
||||
delete I->second;
|
||||
}
|
||||
}
|
||||
|
||||
void SourceManager::clearIDTables() {
|
||||
@@ -1503,13 +1507,13 @@ SourceLocation SourceManager::translateLineCol(FileID FID,
|
||||
/// 0 -> SourceLocation()
|
||||
/// 100 -> Expanded macro arg location
|
||||
/// 110 -> SourceLocation()
|
||||
void SourceManager::computeMacroArgsCache(ContentCache *Content,
|
||||
void SourceManager::computeMacroArgsCache(MacroArgsMap *&CachePtr,
|
||||
FileID FID) const {
|
||||
assert(!Content->MacroArgsCache);
|
||||
assert(!FID.isInvalid());
|
||||
assert(!CachePtr);
|
||||
|
||||
Content->MacroArgsCache = new ContentCache::MacroArgsMap();
|
||||
ContentCache::MacroArgsMap &MacroArgsCache = *Content->MacroArgsCache;
|
||||
CachePtr = new MacroArgsMap();
|
||||
MacroArgsMap &MacroArgsCache = *CachePtr;
|
||||
// Initially no macro argument chunk is present.
|
||||
MacroArgsCache.insert(std::make_pair(0, SourceLocation()));
|
||||
|
||||
@@ -1566,7 +1570,7 @@ void SourceManager::computeMacroArgsCache(ContentCache *Content,
|
||||
// previous chunks, we only need to find where the ending of the new macro
|
||||
// chunk is mapped to and update the map with new begin/end mappings.
|
||||
|
||||
ContentCache::MacroArgsMap::iterator I= MacroArgsCache.upper_bound(EndOffs);
|
||||
MacroArgsMap::iterator I = MacroArgsCache.upper_bound(EndOffs);
|
||||
--I;
|
||||
SourceLocation EndOffsMappedLoc = I->second;
|
||||
MacroArgsCache[BeginOffs] = SourceLocation::getMacroLoc(Entry.getOffset());
|
||||
@@ -1594,15 +1598,12 @@ SourceManager::getMacroArgExpandedLocation(SourceLocation Loc) const {
|
||||
if (FID.isInvalid())
|
||||
return Loc;
|
||||
|
||||
ContentCache *Content
|
||||
= const_cast<ContentCache *>(getSLocEntry(FID).getFile().getContentCache());
|
||||
if (!Content->MacroArgsCache)
|
||||
computeMacroArgsCache(Content, FID);
|
||||
MacroArgsMap *&MacroArgsCache = MacroArgsCacheMap[FID];
|
||||
if (!MacroArgsCache)
|
||||
computeMacroArgsCache(MacroArgsCache, FID);
|
||||
|
||||
assert(Content->MacroArgsCache);
|
||||
assert(!Content->MacroArgsCache->empty());
|
||||
ContentCache::MacroArgsMap::iterator
|
||||
I = Content->MacroArgsCache->upper_bound(Offset);
|
||||
assert(!MacroArgsCache->empty());
|
||||
MacroArgsMap::iterator I = MacroArgsCache->upper_bound(Offset);
|
||||
--I;
|
||||
|
||||
unsigned MacroArgBeginOffs = I->first;
|
||||
@@ -1720,13 +1721,12 @@ void SourceManager::PrintStats() const {
|
||||
<< "B of Sloc address space used.\n";
|
||||
|
||||
unsigned NumLineNumsComputed = 0;
|
||||
unsigned NumMacroArgsComputed = 0;
|
||||
unsigned NumFileBytesMapped = 0;
|
||||
for (fileinfo_iterator I = fileinfo_begin(), E = fileinfo_end(); I != E; ++I){
|
||||
NumLineNumsComputed += I->second->SourceLineCache != 0;
|
||||
NumMacroArgsComputed += I->second->MacroArgsCache != 0;
|
||||
NumFileBytesMapped += I->second->getSizeBytesMapped();
|
||||
}
|
||||
unsigned NumMacroArgsComputed = MacroArgsCacheMap.size();
|
||||
|
||||
llvm::errs() << NumFileBytesMapped << " bytes of files mapped, "
|
||||
<< NumLineNumsComputed << " files with line #'s computed, "
|
||||
|
||||
Reference in New Issue
Block a user