summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>2011-09-19 20:40:29 +0000
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>2011-09-19 20:40:29 +0000
commit532c5196b016847ee4fcdb06bb6b1cbee774f3be (patch)
treef9908f8f7f2445e14a4d5805e19e5f4665dc9183
parent64f6381097aeeac4891d985ee9bf0a3208112334 (diff)
downloadbcm5719-llvm-532c5196b016847ee4fcdb06bb6b1cbee774f3be.tar.gz
bcm5719-llvm-532c5196b016847ee4fcdb06bb6b1cbee774f3be.zip
Break SourceManager::translateFileLineCol into translateLineCol that returns the
source location of line:col of a specific FileID. llvm-svn: 140059
-rw-r--r--clang/include/clang/Basic/SourceManager.h4
-rw-r--r--clang/lib/Basic/SourceManager.cpp29
2 files changed, 26 insertions, 7 deletions
diff --git a/clang/include/clang/Basic/SourceManager.h b/clang/include/clang/Basic/SourceManager.h
index 2bd07c6d5f5..09aadcebba4 100644
--- a/clang/include/clang/Basic/SourceManager.h
+++ b/clang/include/clang/Basic/SourceManager.h
@@ -1119,6 +1119,10 @@ public:
SourceLocation translateFileLineCol(const FileEntry *SourceFile,
unsigned Line, unsigned Col);
+ /// \brief Get the source location in \arg FID for the given line:col.
+ /// Returns null location if \arg FID is not a file SLocEntry.
+ SourceLocation translateLineCol(FileID FID, unsigned Line, unsigned Col);
+
/// \brief If \arg Loc points inside a function macro argument, the returned
/// location will be the macro location in which the argument was expanded.
/// If a macro argument is used multiple times, the expanded location will
diff --git a/clang/lib/Basic/SourceManager.cpp b/clang/lib/Basic/SourceManager.cpp
index 5fe1b190985..38cc9946be1 100644
--- a/clang/lib/Basic/SourceManager.cpp
+++ b/clang/lib/Basic/SourceManager.cpp
@@ -1432,15 +1432,30 @@ SourceLocation SourceManager::translateFileLineCol(const FileEntry *SourceFile,
}
}
}
-
- if (FirstFID.isInvalid())
+
+ return translateLineCol(FirstFID, Line, Col);
+}
+
+/// \brief Get the source location in \arg FID for the given line:col.
+/// Returns null location if \arg FID is not a file SLocEntry.
+SourceLocation SourceManager::translateLineCol(FileID FID,
+ unsigned Line, unsigned Col) {
+ if (FID.isInvalid())
+ return SourceLocation();
+
+ bool Invalid = false;
+ const SLocEntry &Entry = getSLocEntry(FID, &Invalid);
+ if (Invalid)
+ return SourceLocation();
+
+ if (!Entry.isFile())
return SourceLocation();
if (Line == 1 && Col == 1)
- return getLocForStartOfFile(FirstFID);
+ return getLocForStartOfFile(FID);
ContentCache *Content
- = const_cast<ContentCache *>(getOrCreateContentCache(SourceFile));
+ = const_cast<ContentCache *>(Entry.getFile().getContentCache());
if (!Content)
return SourceLocation();
@@ -1457,7 +1472,7 @@ SourceLocation SourceManager::translateFileLineCol(const FileEntry *SourceFile,
unsigned Size = Content->getBuffer(Diag, *this)->getBufferSize();
if (Size > 0)
--Size;
- return getLocForStartOfFile(FirstFID).getLocWithOffset(Size);
+ return getLocForStartOfFile(FID).getLocWithOffset(Size);
}
unsigned FilePos = Content->SourceLineCache[Line - 1];
@@ -1469,9 +1484,9 @@ SourceLocation SourceManager::translateFileLineCol(const FileEntry *SourceFile,
while (i < BufLength-1 && i < Col-1 && Buf[i] != '\n' && Buf[i] != '\r')
++i;
if (i < Col-1)
- return getLocForStartOfFile(FirstFID).getLocWithOffset(FilePos + i);
+ return getLocForStartOfFile(FID).getLocWithOffset(FilePos + i);
- return getLocForStartOfFile(FirstFID).getLocWithOffset(FilePos + Col - 1);
+ return getLocForStartOfFile(FID).getLocWithOffset(FilePos + Col - 1);
}
/// \brief Compute a map of macro argument chunks to their expanded source
OpenPOWER on IntegriCloud