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