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
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file defines serialization methods for the SourceLocation class.
|
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"
|
2007-12-12 22:39:36 +00:00
|
|
|
#include "clang/Basic/SourceManager.h"
|
2007-10-25 16:02:43 +00:00
|
|
|
#include "llvm/Bitcode/Serialize.h"
|
|
|
|
#include "llvm/Bitcode/Deserialize.h"
|
2009-01-28 20:46:26 +00:00
|
|
|
#include "llvm/Support/MemoryBuffer.h"
|
2009-03-02 22:20:04 +00:00
|
|
|
#include <cstdio>
|
2009-01-28 20:46:26 +00:00
|
|
|
|
2007-10-25 16:02:43 +00:00
|
|
|
using namespace clang;
|
|
|
|
|
2007-11-01 22:25:41 +00:00
|
|
|
void SourceLocation::Emit(llvm::Serializer& S) const {
|
|
|
|
S.EmitInt(getRawEncoding());
|
2007-10-25 16:02:43 +00:00
|
|
|
}
|
|
|
|
|
2007-11-01 22:25:41 +00:00
|
|
|
SourceLocation SourceLocation::ReadVal(llvm::Deserializer& D) {
|
2007-10-25 16:02:43 +00:00
|
|
|
return SourceLocation::getFromRawEncoding(D.ReadInt());
|
|
|
|
}
|
2007-11-01 22:25:41 +00:00
|
|
|
|
2009-01-27 07:57:44 +00:00
|
|
|
void SourceLocation::dump(const SourceManager &SM) const {
|
|
|
|
if (!isValid()) {
|
|
|
|
fprintf(stderr, "<invalid loc>");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isFileID()) {
|
|
|
|
PresumedLoc PLoc = SM.getPresumedLoc(*this);
|
|
|
|
|
|
|
|
// The instantiation and spelling pos is identical for file locs.
|
|
|
|
fprintf(stderr, "%s:%d:%d",
|
|
|
|
PLoc.getFilename(), PLoc.getLine(), PLoc.getColumn());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
SM.getInstantiationLoc(*this).dump(SM);
|
|
|
|
|
|
|
|
fprintf(stderr, " <Spelling=");
|
|
|
|
SM.getSpellingLoc(*this).dump(SM);
|
|
|
|
fprintf(stderr, ">");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-11-01 22:25:41 +00:00
|
|
|
void SourceRange::Emit(llvm::Serializer& S) const {
|
|
|
|
B.Emit(S);
|
|
|
|
E.Emit(S);
|
|
|
|
}
|
|
|
|
|
|
|
|
SourceRange SourceRange::ReadVal(llvm::Deserializer& D) {
|
|
|
|
SourceLocation A = SourceLocation::ReadVal(D);
|
|
|
|
SourceLocation B = SourceLocation::ReadVal(D);
|
|
|
|
return SourceRange(A,B);
|
|
|
|
}
|
2007-12-12 22:39:36 +00:00
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2009-01-16 07:36:28 +00:00
|
|
|
unsigned FullSourceLoc::getInstantiationLineNumber() const {
|
2009-01-16 23:03:56 +00:00
|
|
|
assert(isValid());
|
|
|
|
return SrcMgr->getInstantiationLineNumber(*this);
|
2008-04-03 17:55:15 +00:00
|
|
|
}
|
|
|
|
|
2009-01-16 07:36:28 +00:00
|
|
|
unsigned FullSourceLoc::getInstantiationColumnNumber() const {
|
2009-01-16 23:03:56 +00:00
|
|
|
assert(isValid());
|
|
|
|
return SrcMgr->getInstantiationColumnNumber(*this);
|
2008-04-03 17:55:15 +00:00
|
|
|
}
|
|
|
|
|
2009-01-16 07:00:02 +00:00
|
|
|
unsigned FullSourceLoc::getSpellingLineNumber() const {
|
2009-01-16 23:03:56 +00:00
|
|
|
assert(isValid());
|
|
|
|
return SrcMgr->getSpellingLineNumber(*this);
|
2008-09-29 21:46:13 +00:00
|
|
|
}
|
|
|
|
|
2009-01-16 07:00:02 +00:00
|
|
|
unsigned FullSourceLoc::getSpellingColumnNumber() const {
|
2009-01-16 23:03:56 +00:00
|
|
|
assert(isValid());
|
|
|
|
return SrcMgr->getSpellingColumnNumber(*this);
|
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
|
|
|
}
|
|
|
|
|
2009-01-16 22:59:51 +00:00
|
|
|
const char *FullSourceLoc::getCharacterData() const {
|
|
|
|
assert(isValid());
|
2009-01-16 23:03:56 +00:00
|
|
|
return SrcMgr->getCharacterData(*this);
|
2007-12-12 22:39:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const llvm::MemoryBuffer* FullSourceLoc::getBuffer() const {
|
2009-01-16 23:03:56 +00:00
|
|
|
assert(isValid());
|
2009-01-19 07:46:45 +00:00
|
|
|
return SrcMgr->getBuffer(SrcMgr->getFileID(*this));
|
2007-12-12 22:39:36 +00:00
|
|
|
}
|
2008-04-14 21:04:18 +00:00
|
|
|
|
2009-01-28 20:46:26 +00:00
|
|
|
std::pair<const char*, const char*> FullSourceLoc::getBufferData() const {
|
|
|
|
const llvm::MemoryBuffer *Buf = getBuffer();
|
|
|
|
return std::make_pair(Buf->getBufferStart(), Buf->getBufferEnd());
|
|
|
|
}
|