diff options
author | Vedant Kumar <vsk@apple.com> | 2017-07-27 02:20:25 +0000 |
---|---|---|
committer | Vedant Kumar <vsk@apple.com> | 2017-07-27 02:20:25 +0000 |
commit | 5022d62c168c60684227accd5022957a0627f9ee (patch) | |
tree | 1967b1c39778c33c79cbb1ca7cb0988276505eab /lib/CodeGen/CoverageMappingGen.cpp | |
parent | cf6fe9b6196e0eea820482b67e16e48b2044e6fe (diff) |
[Coverage] NFC: Simplify sanity checks with a SpellingRange utility
This should simplify D35925.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@309245 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/CoverageMappingGen.cpp')
-rw-r--r-- | lib/CodeGen/CoverageMappingGen.cpp | 62 |
1 files changed, 41 insertions, 21 deletions
diff --git a/lib/CodeGen/CoverageMappingGen.cpp b/lib/CodeGen/CoverageMappingGen.cpp index 11c57145f7..51f5902b91 100644 --- a/lib/CodeGen/CoverageMappingGen.cpp +++ b/lib/CodeGen/CoverageMappingGen.cpp @@ -73,6 +73,36 @@ public: } }; +/// Spelling locations for the start and end of a source region. +struct SpellingRegion { + /// The line where the region starts. + unsigned LineStart; + + /// The column where the region starts. + unsigned ColumnStart; + + /// The line where the region ends. + unsigned LineEnd; + + /// The column where the region ends. + unsigned ColumnEnd; + + SpellingRegion(SourceManager &SM, SourceLocation LocStart, + SourceLocation LocEnd) { + LineStart = SM.getSpellingLineNumber(LocStart); + ColumnStart = SM.getSpellingColumnNumber(LocStart); + LineEnd = SM.getSpellingLineNumber(LocEnd); + ColumnEnd = SM.getSpellingColumnNumber(LocEnd); + } + + /// Check if the start and end locations appear in source order, i.e + /// top->bottom, left->right. + bool isInSourceOrder() const { + return (LineStart < LineEnd) || + (LineStart == LineEnd && ColumnStart <= ColumnEnd); + } +}; + /// \brief Provides the common functionality for the different /// coverage mapping region builders. class CoverageMappingBuilder { @@ -241,12 +271,9 @@ public: auto CovFileID = getCoverageFileID(LocStart); if (!CovFileID) continue; - unsigned LineStart = SM.getSpellingLineNumber(LocStart); - unsigned ColumnStart = SM.getSpellingColumnNumber(LocStart); - unsigned LineEnd = SM.getSpellingLineNumber(LocEnd); - unsigned ColumnEnd = SM.getSpellingColumnNumber(LocEnd); + SpellingRegion SR{SM, LocStart, LocEnd}; auto Region = CounterMappingRegion::makeSkipped( - *CovFileID, LineStart, ColumnStart, LineEnd, ColumnEnd); + *CovFileID, SR.LineStart, SR.ColumnStart, SR.LineEnd, SR.ColumnEnd); // Make sure that we only collect the regions that are inside // the souce code of this function. if (Region.LineStart >= FileLineRanges[*CovFileID].first && @@ -284,16 +311,12 @@ public: if (Filter.count(std::make_pair(LocStart, LocEnd))) continue; - // Find the spilling locations for the mapping region. - unsigned LineStart = SM.getSpellingLineNumber(LocStart); - unsigned ColumnStart = SM.getSpellingColumnNumber(LocStart); - unsigned LineEnd = SM.getSpellingLineNumber(LocEnd); - unsigned ColumnEnd = SM.getSpellingColumnNumber(LocEnd); - - assert(LineStart <= LineEnd && "region start and end out of order"); + // Find the spelling locations for the mapping region. + SpellingRegion SR{SM, LocStart, LocEnd}; + assert(SR.isInSourceOrder() && "region start and end out of order"); MappingRegions.push_back(CounterMappingRegion::makeRegion( - Region.getCounter(), *CovFileID, LineStart, ColumnStart, LineEnd, - ColumnEnd)); + Region.getCounter(), *CovFileID, SR.LineStart, SR.ColumnStart, + SR.LineEnd, SR.ColumnEnd)); } } @@ -317,14 +340,11 @@ public: "region spans multiple files"); Filter.insert(std::make_pair(ParentLoc, LocEnd)); - unsigned LineStart = SM.getSpellingLineNumber(ParentLoc); - unsigned ColumnStart = SM.getSpellingColumnNumber(ParentLoc); - unsigned LineEnd = SM.getSpellingLineNumber(LocEnd); - unsigned ColumnEnd = SM.getSpellingColumnNumber(LocEnd); - + SpellingRegion SR{SM, ParentLoc, LocEnd}; + assert(SR.isInSourceOrder() && "region start and end out of order"); MappingRegions.push_back(CounterMappingRegion::makeExpansion( - *ParentFileID, *ExpandedFileID, LineStart, ColumnStart, LineEnd, - ColumnEnd)); + *ParentFileID, *ExpandedFileID, SR.LineStart, SR.ColumnStart, + SR.LineEnd, SR.ColumnEnd)); } return Filter; } |