18 #include "llvm/ADT/StringRef.h" 19 #include "llvm/Support/Compiler.h" 20 #include "llvm/Support/MemoryBuffer.h" 21 #include "llvm/Support/raw_ostream.h" 26 using namespace clang;
37 OS << Message <<
'\n';
46 OS <<
"<invalid loc>";
70 LLVM_DUMP_METHOD std::string 71 SourceLocation::printToString(const SourceManager &SM) const { 73 llvm::raw_string_ostream OS(S); 78 LLVM_DUMP_METHOD void SourceLocation::dump(const SourceManager &SM) const { 79 print(llvm::errs(), SM); 83 LLVM_DUMP_METHOD void SourceRange::dump(const SourceManager &SM) const { 84 print(llvm::errs(), SM); 88 static PresumedLoc PrintDifference(raw_ostream &OS, const SourceManager &SM, 89 SourceLocation Loc, PresumedLoc Previous) { 92 PresumedLoc PLoc = SM.getPresumedLoc(Loc); 94 if (PLoc.isInvalid()) { 95 OS << "<invalid sloc>"; 99 if (Previous.isInvalid() || 100 strcmp(PLoc.getFilename(), Previous.getFilename()) != 0) { 101 OS << PLoc.getFilename() << ':
' << PLoc.getLine() << ':
' 103 } else if (Previous.isInvalid() || PLoc.getLine() != Previous.getLine()) { 104 OS << "line" << ':
' << PLoc.getLine() << ':
' << PLoc.getColumn(); 106 OS << "col" << ':
' << PLoc.getColumn(); 110 auto PrintedLoc = PrintDifference(OS, SM, SM.getExpansionLoc(Loc), Previous); 113 PrintedLoc = PrintDifference(OS, SM, SM.getSpellingLoc(Loc), PrintedLoc); 118 void SourceRange::print(raw_ostream &OS, const SourceManager &SM) const { 121 auto PrintedLoc = PrintDifference(OS, SM, B, {}); 124 PrintDifference(OS, SM, E, PrintedLoc); 129 LLVM_DUMP_METHOD std::string 130 SourceRange::printToString(const SourceManager &SM) const { 132 llvm::raw_string_ostream OS(S); 137 //===----------------------------------------------------------------------===// 139 //===----------------------------------------------------------------------===// 141 FileID FullSourceLoc::getFileID() const { 143 return SrcMgr->getFileID(*this); 146 FullSourceLoc FullSourceLoc::getExpansionLoc() const { 148 return FullSourceLoc(SrcMgr->getExpansionLoc(*this), *SrcMgr); 151 FullSourceLoc FullSourceLoc::getSpellingLoc() const { 153 return FullSourceLoc(SrcMgr->getSpellingLoc(*this), *SrcMgr); 156 FullSourceLoc FullSourceLoc::getFileLoc() const { 158 return FullSourceLoc(SrcMgr->getFileLoc(*this), *SrcMgr); 161 PresumedLoc FullSourceLoc::getPresumedLoc(bool UseLineDirectives) const { 163 return PresumedLoc(); 165 return SrcMgr->getPresumedLoc(*this, UseLineDirectives); 168 bool FullSourceLoc::isMacroArgExpansion(FullSourceLoc *StartLoc) const { 170 return SrcMgr->isMacroArgExpansion(*this, StartLoc); 173 FullSourceLoc FullSourceLoc::getImmediateMacroCallerLoc() const { 175 return FullSourceLoc(SrcMgr->getImmediateMacroCallerLoc(*this), *SrcMgr); 178 std::pair<FullSourceLoc, StringRef> FullSourceLoc::getModuleImportLoc() const { 180 return std::make_pair(FullSourceLoc(), StringRef()); 182 std::pair<SourceLocation, StringRef> ImportLoc = 183 SrcMgr->getModuleImportLoc(*this); 184 return std::make_pair(FullSourceLoc(ImportLoc.first, *SrcMgr), 188 unsigned FullSourceLoc::getFileOffset() const { 190 return SrcMgr->getFileOffset(*this); 193 unsigned FullSourceLoc::getLineNumber(bool *Invalid) const { 195 return SrcMgr->getLineNumber(getFileID(), getFileOffset(), Invalid); 198 unsigned FullSourceLoc::getColumnNumber(bool *Invalid) const { 200 return SrcMgr->getColumnNumber(getFileID(), getFileOffset(), Invalid); 203 const FileEntry *FullSourceLoc::getFileEntry() const { 205 return SrcMgr->getFileEntryForID(getFileID()); 208 unsigned FullSourceLoc::getExpansionLineNumber(bool *Invalid) const { 210 return SrcMgr->getExpansionLineNumber(*this, Invalid); 213 unsigned FullSourceLoc::getExpansionColumnNumber(bool *Invalid) const { 215 return SrcMgr->getExpansionColumnNumber(*this, Invalid); 218 unsigned FullSourceLoc::getSpellingLineNumber(bool *Invalid) const { 220 return SrcMgr->getSpellingLineNumber(*this, Invalid); 223 unsigned FullSourceLoc::getSpellingColumnNumber(bool *Invalid) const { 225 return SrcMgr->getSpellingColumnNumber(*this, Invalid); 228 bool FullSourceLoc::isInSystemHeader() const { 230 return SrcMgr->isInSystemHeader(*this); 233 bool FullSourceLoc::isBeforeInTranslationUnitThan(SourceLocation Loc) const { 235 return SrcMgr->isBeforeInTranslationUnit(*this, Loc); 238 LLVM_DUMP_METHOD void FullSourceLoc::dump() const { 239 SourceLocation::dump(*SrcMgr); 242 const char *FullSourceLoc::getCharacterData(bool *Invalid) const { 244 return SrcMgr->getCharacterData(*this, Invalid); 247 StringRef FullSourceLoc::getBufferData(bool *Invalid) const { 249 return SrcMgr->getBuffer(SrcMgr->getFileID(*this), Invalid)->getBuffer(); 252 std::pair<FileID, unsigned> FullSourceLoc::getDecomposedLoc() const { 253 return SrcMgr->getDecomposedLoc(*this); Defines the SourceManager interface.
Defines the PrettyStackTraceEntry class, which is used to make crashes give more contextual informati...
void print(raw_ostream &OS) const override
void print(raw_ostream &OS, const SourceManager &SM) const
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified...
SourceLocation getExpansionLoc(SourceLocation Loc) const
Given a SourceLocation object Loc, return the expansion location referenced by the ID...
SourceLocation getSpellingLoc(SourceLocation Loc) const
Given a SourceLocation object, return the spelling location referenced by the ID. ...
bool isInvalid() const
Return true if this object is invalid or uninitialized.
unsigned getLine() const
Return the presumed line number of this location.
Represents an unpacked "presumed" location which can be presented to the user.
const char * getFilename() const
Return the presumed filename of this location.
unsigned getColumn() const
Return the presumed column number of this location.
Dataflow Directional Tag Classes.
bool isValid() const
Return true if this is a valid SourceLocation object.
PresumedLoc getPresumedLoc(SourceLocation Loc, bool UseLineDirectives=true) const
Returns the "presumed" location of a SourceLocation specifies.
Defines the clang::SourceLocation class and associated facilities.
This class handles loading and caching of source files into memory.