aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>2011-09-27 17:22:25 +0000
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>2011-09-27 17:22:25 +0000
commitb201e16e0c331b0bdeae7b30f9f79aae32beb1b2 (patch)
treefe77b13eb8aa2dbdd7fc8f59ada6ab3f5501ac67
parent17c8c84fbc5cbde336fdef8fffe63c08a955ade9 (diff)
Break SourceManager::translateFileLineCol into translateFile, no functionality change.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@140610 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/clang/Basic/SourceManager.h6
-rw-r--r--lib/Basic/SourceManager.cpp21
2 files changed, 22 insertions, 5 deletions
diff --git a/include/clang/Basic/SourceManager.h b/include/clang/Basic/SourceManager.h
index 6aea0f95ac..12e7cdfc20 100644
--- a/include/clang/Basic/SourceManager.h
+++ b/include/clang/Basic/SourceManager.h
@@ -1110,6 +1110,12 @@ public:
SourceLocation translateFileLineCol(const FileEntry *SourceFile,
unsigned Line, unsigned Col) const;
+ /// \brief Get the FileID for the given file.
+ ///
+ /// If the source file is included multiple times, the FileID will be the
+ /// first inclusion.
+ FileID translateFile(const FileEntry *SourceFile) const;
+
/// \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,
diff --git a/lib/Basic/SourceManager.cpp b/lib/Basic/SourceManager.cpp
index 0c27e996c7..96a526ad14 100644
--- a/lib/Basic/SourceManager.cpp
+++ b/lib/Basic/SourceManager.cpp
@@ -1333,6 +1333,17 @@ SourceLocation SourceManager::translateFileLineCol(const FileEntry *SourceFile,
assert(SourceFile && "Null source file!");
assert(Line && Col && "Line and column should start from 1!");
+ FileID FirstFID = translateFile(SourceFile);
+ return translateLineCol(FirstFID, Line, Col);
+}
+
+/// \brief Get the FileID for the given file.
+///
+/// If the source file is included multiple times, the FileID will be the
+/// first inclusion.
+FileID SourceManager::translateFile(const FileEntry *SourceFile) const {
+ assert(SourceFile && "Null source file!");
+
// Find the first file ID that corresponds to the given file.
FileID FirstFID;
@@ -1344,7 +1355,7 @@ SourceLocation SourceManager::translateFileLineCol(const FileEntry *SourceFile,
bool Invalid = false;
const SLocEntry &MainSLoc = getSLocEntry(MainFileID, &Invalid);
if (Invalid)
- return SourceLocation();
+ return FileID();
if (MainSLoc.isFile()) {
const ContentCache *MainContentCache
@@ -1381,7 +1392,7 @@ SourceLocation SourceManager::translateFileLineCol(const FileEntry *SourceFile,
bool Invalid = false;
const SLocEntry &SLoc = getLocalSLocEntry(I, &Invalid);
if (Invalid)
- return SourceLocation();
+ return FileID();
if (SLoc.isFile() &&
SLoc.getFile().getContentCache() &&
@@ -1418,7 +1429,7 @@ SourceLocation SourceManager::translateFileLineCol(const FileEntry *SourceFile,
IFileID.ID = I;
const SLocEntry &SLoc = getSLocEntry(IFileID, &Invalid);
if (Invalid)
- return SourceLocation();
+ return FileID();
if (SLoc.isFile()) {
const ContentCache *FileContentCache
@@ -1437,8 +1448,8 @@ SourceLocation SourceManager::translateFileLineCol(const FileEntry *SourceFile,
}
}
}
-
- return translateLineCol(FirstFID, Line, Col);
+
+ return FirstFID;
}
/// \brief Get the source location in \arg FID for the given line:col.