diff options
author | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2011-08-23 21:02:38 +0000 |
---|---|---|
committer | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2011-08-23 21:02:38 +0000 |
commit | 499ea5550d6e2fc5cfbd33b47f06d92ce25d7a13 (patch) | |
tree | 94419faa6f8fefb0ef783f2c0bcf637ca4643d8b /include/clang/Basic/SourceManager.h | |
parent | 5d579e7b0463a2e65328df85e4fed8e07799fd9e (diff) |
Introduce SourceManager::isInSLocAddrSpace and use it in TokenLexer instead of isInFileID
since it is a bit more efficient.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@138379 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/clang/Basic/SourceManager.h')
-rw-r--r-- | include/clang/Basic/SourceManager.h | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/include/clang/Basic/SourceManager.h b/include/clang/Basic/SourceManager.h index 487249560c..8799106a03 100644 --- a/include/clang/Basic/SourceManager.h +++ b/include/clang/Basic/SourceManager.h @@ -882,6 +882,30 @@ public: /// expanded. bool isMacroArgExpansion(SourceLocation Loc) const; + /// \brief Returns true if \arg Loc is inside the [\arg Start, +\arg Length) + /// chunk of the source location address space. + /// If it's true and \arg RelativeOffset is non-null, it will be set to the + /// relative offset of \arg Loc inside the chunk. + bool isInSLocAddrSpace(SourceLocation Loc, + SourceLocation Start, unsigned Length, + unsigned *RelativeOffset = 0) const { + assert(((Start.getOffset() < NextLocalOffset && + Start.getOffset()+Length <= NextLocalOffset) || + (Start.getOffset() >= CurrentLoadedOffset && + Start.getOffset()+Length < MaxLoadedOffset)) && + "Chunk is not valid SLoc address space"); + unsigned LocOffs = Loc.getOffset(); + unsigned BeginOffs = Start.getOffset(); + unsigned EndOffs = BeginOffs + Length; + if (LocOffs >= BeginOffs && LocOffs < EndOffs) { + if (RelativeOffset) + *RelativeOffset = LocOffs - BeginOffs; + return true; + } + + return false; + } + //===--------------------------------------------------------------------===// // Queries about the code at a SourceLocation. //===--------------------------------------------------------------------===// |