FullSourceLoc getSpellingLoc() const;
unsigned getLineNumber() const;
- unsigned getColumnNumber() const;
unsigned getInstantiationLineNumber() const;
unsigned getInstantiationColumnNumber() const;
/// returns zero if the column number isn't known. This may only be called on
/// a file sloc, so you must choose a spelling or instantiation location
/// before calling this method.
- unsigned getColumnNumber(SourceLocation Loc) const;
-
- unsigned getSpellingColumnNumber(SourceLocation Loc) const {
- return getColumnNumber(getSpellingLoc(Loc));
- }
- unsigned getInstantiationColumnNumber(SourceLocation Loc) const {
- return getColumnNumber(getInstantiationLoc(Loc));
- }
+ unsigned getColumnNumber(FileID FID, unsigned FilePos) const;
+ unsigned getSpellingColumnNumber(SourceLocation Loc) const;
+ unsigned getInstantiationColumnNumber(SourceLocation Loc) const;
/// getLineNumber - Given a SourceLocation, return the spelling line number
if (SLoc.isFileID()) {
Out << "\\lline="
- << GraphPrintSourceManager->getLineNumber(SLoc) << " col="
- << GraphPrintSourceManager->getColumnNumber(SLoc) << "\\l";
+ << GraphPrintSourceManager->getInstantiationLineNumber(SLoc)
+ << " col="
+ << GraphPrintSourceManager->getInstantiationColumnNumber(SLoc)
+ << "\\l";
}
if (GraphPrintCheckerState->isImplicitNullDeref(N))
if (SLoc.isFileID()) {
Out << "\\lline="
- << GraphPrintSourceManager->getLineNumber(SLoc) << " col="
- << GraphPrintSourceManager->getColumnNumber(SLoc);
+ << GraphPrintSourceManager->getInstantiationLineNumber(SLoc)
+ << " col="
+ << GraphPrintSourceManager->getInstantiationColumnNumber(SLoc);
}
if (isa<SwitchStmt>(T)) {
return SrcMgr->getLineNumber(*this);
}
-unsigned FullSourceLoc::getColumnNumber() const {
- assert(isValid());
- return SrcMgr->getColumnNumber(*this);
-}
-
-
unsigned FullSourceLoc::getInstantiationLineNumber() const {
assert(isValid());
return SrcMgr->getInstantiationLineNumber(*this);
};
} // namespace clang
-
-
-
unsigned LineTableInfo::getLineTableFilenameID(const char *Ptr, unsigned Len) {
// Look up the filename in the string table, returning the pre-existing value
// if it exists.
/// getColumnNumber - Return the column # for the specified file position.
-/// this is significantly cheaper to compute than the line number. This returns
-/// zero if the column number isn't known.
-unsigned SourceManager::getColumnNumber(SourceLocation Loc) const {
- if (Loc.isInvalid()) return 0;
- assert(Loc.isFileID() && "Don't know what part of instantiation loc to get");
+/// this is significantly cheaper to compute than the line number.
+unsigned SourceManager::getColumnNumber(FileID FID, unsigned FilePos) const {
+ const char *Buf = getBuffer(FID)->getBufferStart();
- std::pair<FileID, unsigned> LocInfo = getDecomposedLoc(Loc);
- unsigned FilePos = LocInfo.second;
-
- const char *Buf = getBuffer(LocInfo.first)->getBufferStart();
-
unsigned LineStart = FilePos;
while (LineStart && Buf[LineStart-1] != '\n' && Buf[LineStart-1] != '\r')
--LineStart;
return FilePos-LineStart+1;
}
+unsigned SourceManager::getSpellingColumnNumber(SourceLocation Loc) const {
+ std::pair<FileID, unsigned> LocInfo = getDecomposedSpellingLoc(Loc);
+ return getColumnNumber(LocInfo.first, LocInfo.second);
+}
+
+unsigned SourceManager::getInstantiationColumnNumber(SourceLocation Loc) const {
+ std::pair<FileID, unsigned> LocInfo = getDecomposedInstantiationLoc(Loc);
+ return getColumnNumber(LocInfo.first, LocInfo.second);
+}
+
+
+
static void ComputeLineNumbers(ContentCache* FI,
llvm::BumpPtrAllocator &Alloc) DISABLE_INLINE;
static void ComputeLineNumbers(ContentCache* FI, llvm::BumpPtrAllocator &Alloc){
if (Loc.isInvalid()) return PresumedLoc();
// Presumed locations are always for instantiation points.
+ std::pair<FileID, unsigned> LocInfo = getDecomposedInstantiationLoc(Loc);
Loc = getInstantiationLoc(Loc);
-
+
// FIXME: Could just decompose Loc once!
const SrcMgr::FileInfo &FI = getSLocEntry(getFileID(Loc)).getFile();
const char *Filename =
C->Entry ? C->Entry->getName() : C->getBuffer()->getBufferIdentifier();
- return PresumedLoc(Filename, getLineNumber(Loc), getColumnNumber(Loc),
+ return PresumedLoc(Filename, getLineNumber(Loc),
+ getColumnNumber(LocInfo.first, LocInfo.second),
FI.getIncludeLoc());
}
return;
SourceManager &SM = R.getSourceMgr();
- FullSourceLoc LPos = Pos.getInstantiationLoc();
- FileID FID = SM.getFileID(LPos);
- assert(&LPos.getManager() == &SM && "SourceManagers are different!");
+ assert(&Pos.getManager() == &SM && "SourceManagers are different!");
+ std::pair<FileID, unsigned> LPosInfo = SM.getDecomposedInstantiationLoc(Pos);
- if (SM.getFileID(LPos) != BugFileID)
+ if (LPosInfo.first != BugFileID)
return;
- const llvm::MemoryBuffer *Buf = SM.getBuffer(FID);
+ const llvm::MemoryBuffer *Buf = SM.getBuffer(LPosInfo.first);
const char* FileStart = Buf->getBufferStart();
// Compute the column number. Rewind from the current position to the start
// of the line.
- unsigned ColNo = LPos.getColumnNumber();
- const char *TokInstantiationPtr = LPos.getCharacterData();
+ unsigned ColNo = SM.getColumnNumber(LPosInfo.first, LPosInfo.second);
+ const char *TokInstantiationPtr =Pos.getInstantiationLoc().getCharacterData();
const char *LineStart = TokInstantiationPtr-ColNo;
// Only compute LineEnd if we display below a line.
}
SourceLocation Loc =
- SM.getLocForStartOfFile(FID).getFileLocWithOffset(DisplayPos);
+ SM.getLocForStartOfFile(LPosInfo.first).getFileLocWithOffset(DisplayPos);
R.InsertStrBefore(Loc, os.str());
}
for (const SourceRange *I = P.ranges_begin(), *E = P.ranges_end();
I != E; ++I)
- HighlightRange(R, FID, *I);
+ HighlightRange(R, LPosInfo.first, *I);
}
void HTMLDiagnostics::HighlightRange(Rewriter& R, FileID BugFileID,
return;
// Compute the column number of the end.
- unsigned EndColNo = SM.getColumnNumber(InstantiationEnd);
+ unsigned EndColNo = SM.getInstantiationColumnNumber(InstantiationEnd);
unsigned OldEndColNo = EndColNo;
if (EndColNo) {
// Compute the column number of the start.
unsigned StartColNo = 0;
if (StartLineNo == LineNo) {
- StartColNo = SM.getColumnNumber(Begin);
+ StartColNo = SM.getInstantiationColumnNumber(Begin);
if (StartColNo) --StartColNo; // Zero base the col #.
}
// Compute the column number of the end.
unsigned EndColNo = CaretLine.size();
if (EndLineNo == LineNo) {
- EndColNo = SM.getColumnNumber(End);
+ EndColNo = SM.getInstantiationColumnNumber(End);
if (EndColNo) {
--EndColNo; // Zero base the col #.