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