c2c/Clang/SourceManager.cpp
/// getPresumedLoc - This method returns the "presumed" location of a
/// SourceLocation specifies.  A "presumed location" can be modified by \#line
/// or GNU line marker directives.  This provides a view on the data that a
/// user should see in diagnostics, for example.
///
/// Note that a presumed location is always given as the expansion point of an
/// expansion location, not at the spelling location.
This method returns the "presumed" location of a
SourceLocation specifies.  A "presumed location" can be modified by \#line
or GNU line marker directives.  This provides a view on the data that a
user should see in diagnostics, for example.

Note that a presumed location is always given as the expansion point of an
expansion location, not at the spelling location.
This method returns the " presumed " location of a SourceLocation specifies . A " presumed location " can be modified by \ #line or GNU line marker directives . This provides a view on the data that a user should see in diagnostics for example . Note that a presumed location is always given as the expansion point of an expansion location not at the spelling location .
PresumedLoc SourceManager::getPresumedLoc(SourceLocation Loc,
                                          bool UseLineDirectives) const {
  if (Loc.isInvalid()) return PresumedLoc();
  std::pair<FileID, unsigned> LocInfo = getDecomposedExpansionLoc(Loc);
  bool Invalid = false;
  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();
  StringRef Filename;
  if (C->OrigEntry)
    Filename = C->OrigEntry->getName();
  else
    Filename = C->getBuffer(Diag, *this)->getBufferIdentifier();
  unsigned LineNo = getLineNumber(LocInfo.first, LocInfo.second, &Invalid);
  if (Invalid)
    return PresumedLoc();
  unsigned ColNo  = getColumnNumber(LocInfo.first, LocInfo.second, &Invalid);
  if (Invalid)
    return PresumedLoc();
  SourceLocation IncludeLoc = FI.getIncludeLoc();
  if (UseLineDirectives && FI.hasLineDirectives()) {
    assert(LineTable && "Can't have linetable entries without a LineTable!");
    if (const LineEntry *Entry =
          LineTable->FindNearestLineEntry(LocInfo.first, LocInfo.second)) {
      if (Entry->FilenameID != -1)
        Filename = LineTable->getFilename(Entry->FilenameID);
      unsigned MarkerLineNo = getLineNumber(LocInfo.first, Entry->FileOffset);
      LineNo = Entry->LineNo + (LineNo-MarkerLineNo-1);
      if (Entry->IncludeOffset) {
        IncludeLoc = getLocForStartOfFile(LocInfo.first);
        IncludeLoc = IncludeLoc.getLocWithOffset(Entry->IncludeOffset);
      }
    }
  }
  return PresumedLoc(Filename.data(), LineNo, ColNo, IncludeLoc);
}
PresumedLoc SourceManager :: getPresumedLoc ( SourceLocation Loc , bool UseLineDirectives ) const { if ( Loc . isInvalid ( ) ) return PresumedLoc ( ) ; std :: pair < FileID , unsigned > LocInfo = getDecomposedExpansionLoc ( Loc ) ; bool Invalid = false ; 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 ( ) ; StringRef Filename ; if ( C -> OrigEntry ) Filename = C -> OrigEntry -> getName ( ) ; else Filename = C -> getBuffer ( Diag , * this ) -> getBufferIdentifier ( ) ; unsigned LineNo = getLineNumber ( LocInfo . first , LocInfo . second , & Invalid ) ; if ( Invalid ) return PresumedLoc ( ) ; unsigned ColNo = getColumnNumber ( LocInfo . first , LocInfo . second , & Invalid ) ; if ( Invalid ) return PresumedLoc ( ) ; SourceLocation IncludeLoc = FI . getIncludeLoc ( ) ; if ( UseLineDirectives && FI . hasLineDirectives ( ) ) { assert ( LineTable && " " ) ; if ( const LineEntry * Entry = LineTable -> FindNearestLineEntry ( LocInfo . first , LocInfo . second ) ) { if ( Entry -> FilenameID != -1 ) Filename = LineTable -> getFilename ( Entry -> FilenameID ) ; unsigned MarkerLineNo = getLineNumber ( LocInfo . first , Entry -> FileOffset ) ; LineNo = Entry -> LineNo + ( LineNo - MarkerLineNo - 1 ) ; if ( Entry -> IncludeOffset ) { IncludeLoc = getLocForStartOfFile ( LocInfo . first ) ; IncludeLoc = IncludeLoc . getLocWithOffset ( Entry -> IncludeOffset ) ; } } } return PresumedLoc ( Filename . data ( ) , LineNo , ColNo , IncludeLoc ) ; }
getPresumedLoc - This method returns the "presumed" location of a
SourceLocation specifies.
getPresumedLoc - This method returns the " presumed " location of a SourceLocation specifies .
// Presumed locations are always for expansion points. // To get the source name, first consult the FileEntry (if one exists) // before the MemBuffer as this will avoid unnecessarily paging in the // MemBuffer. // If we have #line directives in this file, update and overwrite the physical // location info if appropriate. // See if there is a #line directive before this.  If so, get it. // If the LineEntry indicates a filename, use it. // Use the line number specified by the LineEntry.  This line number may // be multiple lines down from the line entry.  Add the difference in // physical line numbers from the query point and the line marker to the // total. // Note that column numbers are not molested by line markers. // Handle virtual #include manipulation.