17 #include "llvm/ADT/StringRef.h" 18 #include "llvm/Support/Compiler.h" 19 #include "llvm/Support/MemoryBuffer.h" 20 #include "llvm/Support/raw_ostream.h" 25 using namespace clang;
36 OS << Message <<
'\n';
45 OS <<
"<invalid loc>";
69 LLVM_DUMP_METHOD std::string 70 SourceLocation::printToString(const SourceManager &SM) const { 72 llvm::raw_string_ostream OS(S); 77 LLVM_DUMP_METHOD void SourceLocation::dump(const SourceManager &SM) const { 78 print(llvm::errs(), SM); 82 LLVM_DUMP_METHOD void SourceRange::dump(const SourceManager &SM) const { 83 print(llvm::errs(), SM); 87 static PresumedLoc PrintDifference(raw_ostream &OS, const SourceManager &SM, 88 SourceLocation Loc, PresumedLoc Previous) { 91 PresumedLoc PLoc = SM.getPresumedLoc(Loc); 93 if (PLoc.isInvalid()) { 94 OS << "<invalid sloc>"; 98 if (Previous.isInvalid() || 99 strcmp(PLoc.getFilename(), Previous.getFilename()) != 0) { 100 OS << PLoc.getFilename() << ':
' << PLoc.getLine() << ':
' 102 } else if (Previous.isInvalid() || PLoc.getLine() != Previous.getLine()) { 103 OS << "line" << ':
' << PLoc.getLine() << ':
' << PLoc.getColumn(); 105 OS << "col" << ':
' << PLoc.getColumn(); 109 auto PrintedLoc = PrintDifference(OS, SM, SM.getExpansionLoc(Loc), Previous); 112 PrintedLoc = PrintDifference(OS, SM, SM.getSpellingLoc(Loc), PrintedLoc); 117 void SourceRange::print(raw_ostream &OS, const SourceManager &SM) const { 120 auto PrintedLoc = PrintDifference(OS, SM, B, {}); 123 PrintDifference(OS, SM, E, PrintedLoc); 128 LLVM_DUMP_METHOD std::string 129 SourceRange::printToString(const SourceManager &SM) const { 131 llvm::raw_string_ostream OS(S); 136 //===----------------------------------------------------------------------===// 138 //===----------------------------------------------------------------------===// 140 FileID FullSourceLoc::getFileID() const { 142 return SrcMgr->getFileID(*this); 145 FullSourceLoc FullSourceLoc::getExpansionLoc() const { 147 return FullSourceLoc(SrcMgr->getExpansionLoc(*this), *SrcMgr); 150 FullSourceLoc FullSourceLoc::getSpellingLoc() const { 152 return FullSourceLoc(SrcMgr->getSpellingLoc(*this), *SrcMgr); 155 FullSourceLoc FullSourceLoc::getFileLoc() const { 157 return FullSourceLoc(SrcMgr->getFileLoc(*this), *SrcMgr); 160 PresumedLoc FullSourceLoc::getPresumedLoc(bool UseLineDirectives) const { 162 return PresumedLoc(); 164 return SrcMgr->getPresumedLoc(*this, UseLineDirectives); 167 bool FullSourceLoc::isMacroArgExpansion(FullSourceLoc *StartLoc) const { 169 return SrcMgr->isMacroArgExpansion(*this, StartLoc); 172 FullSourceLoc FullSourceLoc::getImmediateMacroCallerLoc() const { 174 return FullSourceLoc(SrcMgr->getImmediateMacroCallerLoc(*this), *SrcMgr); 177 std::pair<FullSourceLoc, StringRef> FullSourceLoc::getModuleImportLoc() const { 179 return std::make_pair(FullSourceLoc(), StringRef()); 181 std::pair<SourceLocation, StringRef> ImportLoc = 182 SrcMgr->getModuleImportLoc(*this); 183 return std::make_pair(FullSourceLoc(ImportLoc.first, *SrcMgr), 187 unsigned FullSourceLoc::getFileOffset() const { 189 return SrcMgr->getFileOffset(*this); 192 unsigned FullSourceLoc::getLineNumber(bool *Invalid) const { 194 return SrcMgr->getLineNumber(getFileID(), getFileOffset(), Invalid); 197 unsigned FullSourceLoc::getColumnNumber(bool *Invalid) const { 199 return SrcMgr->getColumnNumber(getFileID(), getFileOffset(), Invalid); 202 const FileEntry *FullSourceLoc::getFileEntry() const { 204 return SrcMgr->getFileEntryForID(getFileID()); 207 unsigned FullSourceLoc::getExpansionLineNumber(bool *Invalid) const { 209 return SrcMgr->getExpansionLineNumber(*this, Invalid); 212 unsigned FullSourceLoc::getExpansionColumnNumber(bool *Invalid) const { 214 return SrcMgr->getExpansionColumnNumber(*this, Invalid); 217 unsigned FullSourceLoc::getSpellingLineNumber(bool *Invalid) const { 219 return SrcMgr->getSpellingLineNumber(*this, Invalid); 222 unsigned FullSourceLoc::getSpellingColumnNumber(bool *Invalid) const { 224 return SrcMgr->getSpellingColumnNumber(*this, Invalid); 227 bool FullSourceLoc::isInSystemHeader() const { 229 return SrcMgr->isInSystemHeader(*this); 232 bool FullSourceLoc::isBeforeInTranslationUnitThan(SourceLocation Loc) const { 234 return SrcMgr->isBeforeInTranslationUnit(*this, Loc); 237 LLVM_DUMP_METHOD void FullSourceLoc::dump() const { 238 SourceLocation::dump(*SrcMgr); 241 const char *FullSourceLoc::getCharacterData(bool *Invalid) const { 243 return SrcMgr->getCharacterData(*this, Invalid); 246 StringRef FullSourceLoc::getBufferData(bool *Invalid) const { 248 return SrcMgr->getBuffer(SrcMgr->getFileID(*this), Invalid)->getBuffer(); 251 std::pair<FileID, unsigned> FullSourceLoc::getDecomposedLoc() const { 252 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.