diff options
Diffstat (limited to 'lib/Basic/SourceManager.cpp')
| -rw-r--r-- | lib/Basic/SourceManager.cpp | 64 | 
1 files changed, 32 insertions, 32 deletions
diff --git a/lib/Basic/SourceManager.cpp b/lib/Basic/SourceManager.cpp index ae76817826e1..efa6ad2493b2 100644 --- a/lib/Basic/SourceManager.cpp +++ b/lib/Basic/SourceManager.cpp @@ -105,9 +105,9 @@ llvm::MemoryBuffer *ContentCache::getBuffer(DiagnosticsEngine &Diag,    if (Buffer.getPointer() || !ContentsEntry) {      if (Invalid)        *Invalid = isBufferInvalid(); -     +      return Buffer.getPointer(); -  }     +  }    bool isVolatile = SM.userFilesAreVolatile() && !IsSystemFile;    auto BufferOrError = @@ -141,7 +141,7 @@ llvm::MemoryBuffer *ContentCache::getBuffer(DiagnosticsEngine &Diag,            << ContentsEntry->getName() << BufferOrError.getError().message();      Buffer.setInt(Buffer.getInt() | InvalidFlag); -     +      if (Invalid) *Invalid = true;      return Buffer.getPointer();    } @@ -187,10 +187,10 @@ llvm::MemoryBuffer *ContentCache::getBuffer(DiagnosticsEngine &Diag,        << InvalidBOM << ContentsEntry->getName();      Buffer.setInt(Buffer.getInt() | InvalidFlag);    } -   +    if (Invalid)      *Invalid = isBufferInvalid(); -   +    return Buffer.getPointer();  } @@ -672,7 +672,7 @@ StringRef SourceManager::getBufferData(FileID FID, bool *Invalid) const {    bool MyInvalid = false;    const SLocEntry &SLoc = getSLocEntry(FID, &MyInvalid);    if (!SLoc.isFile() || MyInvalid) { -    if (Invalid)  +    if (Invalid)        *Invalid = true;      return "<<<<<INVALID SOURCE LOCATION>>>>>";    } @@ -684,7 +684,7 @@ StringRef SourceManager::getBufferData(FileID FID, bool *Invalid) const {    if (MyInvalid)      return "<<<<<INVALID SOURCE LOCATION>>>>>"; -   +    return Buf->getBuffer();  } @@ -770,7 +770,7 @@ FileID SourceManager::getFileIDLocal(unsigned SLocOffset) const {      unsigned MidOffset = getLocalSLocEntry(MiddleIndex, &Invalid).getOffset();      if (Invalid)        return FileID::get(0); -     +      ++NumProbes;      // If the offset of the midpoint is too large, chop the high side of the @@ -1104,7 +1104,7 @@ const char *SourceManager::getCharacterData(SourceLocation SL,    if (CharDataInvalid || !Entry.isFile()) {      if (Invalid)        *Invalid = true; -     +      return "<<<<INVALID BUFFER>>>>";    }    llvm::MemoryBuffer *Buffer = Entry.getFile().getContentCache()->getBuffer( @@ -1289,7 +1289,7 @@ FoundSpecialChar:  /// for the position indicated.  This requires building and caching a table of  /// line offsets for the MemoryBuffer, so this is not cheap: use only when  /// about to emit a diagnostic. -unsigned SourceManager::getLineNumber(FileID FID, unsigned FilePos,  +unsigned SourceManager::getLineNumber(FileID FID, unsigned FilePos,                                        bool *Invalid) const {    if (FID.isInvalid()) {      if (Invalid) @@ -1308,10 +1308,10 @@ unsigned SourceManager::getLineNumber(FileID FID, unsigned FilePos,          *Invalid = true;        return 1;      } -     +      Content = const_cast<ContentCache*>(Entry.getFile().getContentCache());    } -   +    // If this is the first use of line information for this buffer, compute the    /// SourceLineCache for it on demand.    if (!Content->SourceLineCache) { @@ -1383,7 +1383,7 @@ unsigned SourceManager::getLineNumber(FileID FID, unsigned FilePos,    return LineNo;  } -unsigned SourceManager::getSpellingLineNumber(SourceLocation Loc,  +unsigned SourceManager::getSpellingLineNumber(SourceLocation Loc,                                                bool *Invalid) const {    if (isInvalid(Loc, Invalid)) return 0;    std::pair<FileID, unsigned> LocInfo = getDecomposedSpellingLoc(Loc); @@ -1418,7 +1418,7 @@ SourceManager::getFileCharacteristic(SourceLocation Loc) const {    const SLocEntry &SEntry = getSLocEntry(LocInfo.first, &Invalid);    if (Invalid || !SEntry.isFile())      return C_User; -   +    const SrcMgr::FileInfo &FI = SEntry.getFile();    // If there are no #line directives in this file, just return the whole-file @@ -1466,7 +1466,7 @@ PresumedLoc SourceManager::getPresumedLoc(SourceLocation Loc,    const SLocEntry &Entry = getSLocEntry(LocInfo.first, &Invalid);    if (Invalid || !Entry.isFile())      return PresumedLoc(); -   +    const SrcMgr::FileInfo &FI = Entry.getFile();    const SrcMgr::ContentCache *C = FI.getContentCache(); @@ -1485,7 +1485,7 @@ PresumedLoc SourceManager::getPresumedLoc(SourceLocation Loc,    unsigned ColNo  = getColumnNumber(LocInfo.first, LocInfo.second, &Invalid);    if (Invalid)      return PresumedLoc(); -   +    SourceLocation IncludeLoc = FI.getIncludeLoc();    // If we have #line directives in this file, update and overwrite the physical @@ -1621,7 +1621,7 @@ FileID SourceManager::translateFile(const FileEntry *SourceFile) const {      const SLocEntry &MainSLoc = getSLocEntry(MainFileID, &Invalid);      if (Invalid)        return FileID(); -     +      if (MainSLoc.isFile()) {        const ContentCache *MainContentCache          = MainSLoc.getFile().getContentCache(); @@ -1658,8 +1658,8 @@ FileID SourceManager::translateFile(const FileEntry *SourceFile) const {        const SLocEntry &SLoc = getLocalSLocEntry(I, &Invalid);        if (Invalid)          return FileID(); -       -      if (SLoc.isFile() &&  + +      if (SLoc.isFile() &&            SLoc.getFile().getContentCache() &&            SLoc.getFile().getContentCache()->OrigEntry == SourceFile) {          FirstFID = FileID::get(I); @@ -1670,7 +1670,7 @@ FileID SourceManager::translateFile(const FileEntry *SourceFile) const {      if (FirstFID.isInvalid()) {        for (unsigned I = 0, N = loaded_sloc_entry_size(); I != N; ++I) {          const SLocEntry &SLoc = getLoadedSLocEntry(I); -        if (SLoc.isFile() &&  +        if (SLoc.isFile() &&              SLoc.getFile().getContentCache() &&              SLoc.getFile().getContentCache()->OrigEntry == SourceFile) {            FirstFID = FileID::get(-int(I) - 2); @@ -1681,7 +1681,7 @@ FileID SourceManager::translateFile(const FileEntry *SourceFile) const {    }    // If we haven't found what we want yet, try again, but this time stat() -  // each of the files in case the files have changed since we originally  +  // each of the files in case the files have changed since we originally    // parsed the file.    if (FirstFID.isInvalid() &&        (SourceFileName || @@ -1694,13 +1694,13 @@ FileID SourceManager::translateFile(const FileEntry *SourceFile) const {        const SLocEntry &SLoc = getSLocEntry(IFileID, &Invalid);        if (Invalid)          return FileID(); -       -      if (SLoc.isFile()) {  -        const ContentCache *FileContentCache  + +      if (SLoc.isFile()) { +        const ContentCache *FileContentCache            = SLoc.getFile().getContentCache();          const FileEntry *Entry = FileContentCache ? FileContentCache->OrigEntry                                                    : nullptr; -        if (Entry &&  +        if (Entry &&              *SourceFileName == llvm::sys::path::filename(Entry->getName())) {            if (Optional<llvm::sys::fs::UniqueID> EntryUID =                    getActualFileUID(Entry)) { @@ -1712,9 +1712,9 @@ FileID SourceManager::translateFile(const FileEntry *SourceFile) const {            }          }        } -    }       +    }    } -   +    (void) SourceFile;    return FirstFID;  } @@ -1948,7 +1948,7 @@ SourceManager::getMacroArgExpandedLocation(SourceLocation Loc) const {    assert(!MacroArgsCache->empty());    MacroArgsMap::iterator I = MacroArgsCache->upper_bound(Offset);    --I; -   +    unsigned MacroArgBeginOffs = I->first;    SourceLocation MacroArgExpandedLoc = I->second;    if (MacroArgExpandedLoc.isValid()) @@ -2151,7 +2151,7 @@ void SourceManager::PrintStats() const {                 << " loaded SLocEntries allocated, "                 << MaxLoadedOffset - CurrentLoadedOffset                 << "B of Sloc address space used.\n"; -   +    unsigned NumLineNumsComputed = 0;    unsigned NumFileBytesMapped = 0;    for (fileinfo_iterator I = fileinfo_begin(), E = fileinfo_end(); I != E; ++I){ @@ -2231,7 +2231,7 @@ ExternalSLocEntrySource::~ExternalSLocEntrySource() = default;  SourceManager::MemoryBufferSizes SourceManager::getMemoryBufferSizes() const {    size_t malloc_bytes = 0;    size_t mmap_bytes = 0; -   +    for (unsigned i = 0, e = MemBufferInfos.size(); i != e; ++i)      if (size_t sized_mapped = MemBufferInfos[i]->getSizeBytesMapped())        switch (MemBufferInfos[i]->getMemoryBufferKind()) { @@ -2242,7 +2242,7 @@ SourceManager::MemoryBufferSizes SourceManager::getMemoryBufferSizes() const {            malloc_bytes += sized_mapped;            break;        } -   +    return MemoryBufferSizes(malloc_bytes, mmap_bytes);  } @@ -2252,7 +2252,7 @@ size_t SourceManager::getDataStructureSizes() const {      + llvm::capacity_in_bytes(LoadedSLocEntryTable)      + llvm::capacity_in_bytes(SLocEntryLoaded)      + llvm::capacity_in_bytes(FileInfos); -   +    if (OverriddenFilesInfo)      size += llvm::capacity_in_bytes(OverriddenFilesInfo->OverriddenFiles);  | 
