2009-06-02 17:58:47 +00:00
|
|
|
//==--- SourceLocation.cpp - Compact identifier for Source Files -*- C++ -*-==//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file defines accessor methods for the FullSourceLoc class.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "clang/Basic/SourceLocation.h"
|
|
|
|
#include "clang/Basic/PrettyStackTrace.h"
|
|
|
|
#include "clang/Basic/SourceManager.h"
|
|
|
|
#include "llvm/Support/MemoryBuffer.h"
|
|
|
|
#include "llvm/Support/raw_ostream.h"
|
|
|
|
#include <cstdio>
|
|
|
|
using namespace clang;
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// PrettyStackTraceLoc
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2011-10-20 21:14:49 +00:00
|
|
|
void PrettyStackTraceLoc::print(raw_ostream &OS) const {
|
2009-06-02 17:58:47 +00:00
|
|
|
if (Loc.isValid()) {
|
|
|
|
Loc.print(OS, SM);
|
|
|
|
OS << ": ";
|
|
|
|
}
|
|
|
|
OS << Message << '\n';
|
|
|
|
}
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// SourceLocation
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2011-10-20 21:14:49 +00:00
|
|
|
void SourceLocation::print(raw_ostream &OS, const SourceManager &SM)const{
|
2009-06-02 17:58:47 +00:00
|
|
|
if (!isValid()) {
|
|
|
|
OS << "<invalid loc>";
|
|
|
|
return;
|
|
|
|
}
|
2009-10-14 18:03:49 +00:00
|
|
|
|
2009-06-02 17:58:47 +00:00
|
|
|
if (isFileID()) {
|
|
|
|
PresumedLoc PLoc = SM.getPresumedLoc(*this);
|
2011-02-20 13:06:31 +00:00
|
|
|
|
|
|
|
if (PLoc.isInvalid()) {
|
|
|
|
OS << "<invalid>";
|
|
|
|
return;
|
|
|
|
}
|
2011-10-20 21:14:49 +00:00
|
|
|
// The macro expansion and spelling pos is identical for file locs.
|
2009-06-02 17:58:47 +00:00
|
|
|
OS << PLoc.getFilename() << ':' << PLoc.getLine()
|
|
|
|
<< ':' << PLoc.getColumn();
|
|
|
|
return;
|
|
|
|
}
|
2009-10-14 18:03:49 +00:00
|
|
|
|
2011-10-20 21:14:49 +00:00
|
|
|
SM.getExpansionLoc(*this).print(OS, SM);
|
2009-06-02 17:58:47 +00:00
|
|
|
|
|
|
|
OS << " <Spelling=";
|
|
|
|
SM.getSpellingLoc(*this).print(OS, SM);
|
|
|
|
OS << '>';
|
|
|
|
}
|
|
|
|
|
2014-11-24 09:15:30 +00:00
|
|
|
LLVM_DUMP_METHOD std::string
|
|
|
|
SourceLocation::printToString(const SourceManager &SM) const {
|
2012-12-02 13:20:44 +00:00
|
|
|
std::string S;
|
|
|
|
llvm::raw_string_ostream OS(S);
|
|
|
|
print(OS, SM);
|
2013-04-08 18:45:10 +00:00
|
|
|
return OS.str();
|
2012-12-02 13:20:44 +00:00
|
|
|
}
|
|
|
|
|
2014-11-24 09:15:30 +00:00
|
|
|
LLVM_DUMP_METHOD void SourceLocation::dump(const SourceManager &SM) const {
|
2009-06-02 17:58:47 +00:00
|
|
|
print(llvm::errs(), SM);
|
|
|
|
}
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// FullSourceLoc
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
FileID FullSourceLoc::getFileID() const {
|
|
|
|
assert(isValid());
|
|
|
|
return SrcMgr->getFileID(*this);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-20 21:14:49 +00:00
|
|
|
FullSourceLoc FullSourceLoc::getExpansionLoc() const {
|
2009-06-02 17:58:47 +00:00
|
|
|
assert(isValid());
|
2011-10-20 21:14:49 +00:00
|
|
|
return FullSourceLoc(SrcMgr->getExpansionLoc(*this), *SrcMgr);
|
2009-06-02 17:58:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
FullSourceLoc FullSourceLoc::getSpellingLoc() const {
|
|
|
|
assert(isValid());
|
|
|
|
return FullSourceLoc(SrcMgr->getSpellingLoc(*this), *SrcMgr);
|
|
|
|
}
|
|
|
|
|
2011-10-20 21:14:49 +00:00
|
|
|
unsigned FullSourceLoc::getExpansionLineNumber(bool *Invalid) const {
|
2009-06-02 17:58:47 +00:00
|
|
|
assert(isValid());
|
2011-10-20 21:14:49 +00:00
|
|
|
return SrcMgr->getExpansionLineNumber(*this, Invalid);
|
2009-06-02 17:58:47 +00:00
|
|
|
}
|
|
|
|
|
2011-10-20 21:14:49 +00:00
|
|
|
unsigned FullSourceLoc::getExpansionColumnNumber(bool *Invalid) const {
|
2009-06-02 17:58:47 +00:00
|
|
|
assert(isValid());
|
2011-10-20 21:14:49 +00:00
|
|
|
return SrcMgr->getExpansionColumnNumber(*this, Invalid);
|
2009-06-02 17:58:47 +00:00
|
|
|
}
|
|
|
|
|
2010-03-21 10:50:08 +00:00
|
|
|
unsigned FullSourceLoc::getSpellingLineNumber(bool *Invalid) const {
|
2009-06-02 17:58:47 +00:00
|
|
|
assert(isValid());
|
2010-03-21 10:50:08 +00:00
|
|
|
return SrcMgr->getSpellingLineNumber(*this, Invalid);
|
2009-06-02 17:58:47 +00:00
|
|
|
}
|
|
|
|
|
2010-03-21 10:50:08 +00:00
|
|
|
unsigned FullSourceLoc::getSpellingColumnNumber(bool *Invalid) const {
|
2009-06-02 17:58:47 +00:00
|
|
|
assert(isValid());
|
2010-03-21 10:50:08 +00:00
|
|
|
return SrcMgr->getSpellingColumnNumber(*this, Invalid);
|
2009-06-02 17:58:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool FullSourceLoc::isInSystemHeader() const {
|
|
|
|
assert(isValid());
|
|
|
|
return SrcMgr->isInSystemHeader(*this);
|
|
|
|
}
|
|
|
|
|
2011-02-20 13:06:31 +00:00
|
|
|
bool FullSourceLoc::isBeforeInTranslationUnitThan(SourceLocation Loc) const {
|
|
|
|
assert(isValid());
|
|
|
|
return SrcMgr->isBeforeInTranslationUnit(*this, Loc);
|
|
|
|
}
|
|
|
|
|
2014-11-24 09:15:30 +00:00
|
|
|
LLVM_DUMP_METHOD void FullSourceLoc::dump() const {
|
2012-04-14 14:01:31 +00:00
|
|
|
SourceLocation::dump(*SrcMgr);
|
|
|
|
}
|
|
|
|
|
2010-03-21 10:50:08 +00:00
|
|
|
const char *FullSourceLoc::getCharacterData(bool *Invalid) const {
|
2009-06-02 17:58:47 +00:00
|
|
|
assert(isValid());
|
2010-03-21 10:50:08 +00:00
|
|
|
return SrcMgr->getCharacterData(*this, Invalid);
|
2009-06-02 17:58:47 +00:00
|
|
|
}
|
|
|
|
|
2011-10-20 21:14:49 +00:00
|
|
|
StringRef FullSourceLoc::getBufferData(bool *Invalid) const {
|
2015-01-18 16:23:48 +00:00
|
|
|
assert(isValid());
|
2015-06-09 19:08:19 +00:00
|
|
|
return SrcMgr->getBuffer(SrcMgr->getFileID(*this), Invalid)->getBuffer();
|
2009-06-02 17:58:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
std::pair<FileID, unsigned> FullSourceLoc::getDecomposedLoc() const {
|
|
|
|
return SrcMgr->getDecomposedLoc(*this);
|
|
|
|
}
|