aboutsummaryrefslogtreecommitdiff
path: root/include/clang/Basic/SourceManager.h
diff options
context:
space:
mode:
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>2011-08-17 00:31:20 +0000
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>2011-08-17 00:31:20 +0000
commitac836e442cbd17f33533bd0b4879258945bc1723 (patch)
tree20fa7cc1bfa21bd8c22a94499e77c032a4918e11 /include/clang/Basic/SourceManager.h
parent37e59a10a7a537428e5997fd5896f5b89fd34e6b (diff)
Introduce SourceManager::getMacroArgExpandedLocation function.
If we pass it a source location that 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 be at the first expansion of the argument. e.g. MY_MACRO(foo); ^ Passing a file location pointing at 'foo', will yield a macro location where 'foo' was expanded into. Make SourceManager::getLocation call getMacroArgExpandedLocation as well. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@137794 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/clang/Basic/SourceManager.h')
-rw-r--r--include/clang/Basic/SourceManager.h31
1 files changed, 30 insertions, 1 deletions
diff --git a/include/clang/Basic/SourceManager.h b/include/clang/Basic/SourceManager.h
index 2ea19ebc4d..68293a7887 100644
--- a/include/clang/Basic/SourceManager.h
+++ b/include/clang/Basic/SourceManager.h
@@ -489,6 +489,10 @@ class SourceManager : public llvm::RefCountedBase<SourceManager> {
/// not have been loaded, so that value would be unknown.
unsigned CurrentLoadedOffset;
+ /// \brief The highest possible offset is 2^31-1, so CurrentLoadedOffset
+ /// starts at 2^31.
+ static const unsigned MaxLoadedOffset = 1U << 31U;
+
/// \brief A bitmap that indicates whether the entries of LoadedSLocEntryTable
/// have already been loaded from the external source.
///
@@ -1001,8 +1005,33 @@ public:
///
/// If the source file is included multiple times, the source location will
/// be based upon the first inclusion.
+ ///
+ /// If the location points inside a function macro argument, the returned
+ /// location will be the macro location in which the argument was expanded.
+ /// \sa getMacroArgExpandedLocation
SourceLocation getLocation(const FileEntry *SourceFile,
- unsigned Line, unsigned Col);
+ unsigned Line, unsigned Col) {
+ SourceLocation Loc = translateFileLineCol(SourceFile, Line, Col);
+ return getMacroArgExpandedLocation(Loc);
+ }
+
+ /// \brief Get the source location for the given file:line:col triplet.
+ ///
+ /// If the source file is included multiple times, the source location will
+ /// be based upon the first inclusion.
+ SourceLocation translateFileLineCol(const FileEntry *SourceFile,
+ 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
+ /// be at the first expansion of the argument.
+ /// e.g.
+ /// MY_MACRO(foo);
+ /// ^
+ /// Passing a file location pointing at 'foo', will yield a macro location
+ /// where 'foo' was expanded into.
+ SourceLocation getMacroArgExpandedLocation(SourceLocation Loc);
/// \brief Determines the order of 2 source locations in the translation unit.
///