aboutsummaryrefslogtreecommitdiffstats
path: root/liblangutil
diff options
context:
space:
mode:
authorDaniel Kirchner <daniel@ekpyron.org>2019-01-09 02:33:46 +0800
committerDaniel Kirchner <daniel@ekpyron.org>2019-01-10 17:36:50 +0800
commit0dfd4a726eb7e6fa8a5e886a0d80bb5bf3d9b7dc (patch)
tree8457ac70f7e9921d9825e939f2ff23ffc1259a46 /liblangutil
parent63319cfdcd7668a75caaacd0d8f3a83a62c31525 (diff)
downloaddexon-solidity-0dfd4a726eb7e6fa8a5e886a0d80bb5bf3d9b7dc.tar.gz
dexon-solidity-0dfd4a726eb7e6fa8a5e886a0d80bb5bf3d9b7dc.tar.zst
dexon-solidity-0dfd4a726eb7e6fa8a5e886a0d80bb5bf3d9b7dc.zip
Warn about unreachable code.
Diffstat (limited to 'liblangutil')
-rw-r--r--liblangutil/SourceLocation.h20
1 files changed, 20 insertions, 0 deletions
diff --git a/liblangutil/SourceLocation.h b/liblangutil/SourceLocation.h
index 840891c2..c461909f 100644
--- a/liblangutil/SourceLocation.h
+++ b/liblangutil/SourceLocation.h
@@ -49,6 +49,26 @@ struct SourceLocation
bool isEmpty() const { return start == -1 && end == -1; }
+ /// @returns the smallest SourceLocation that contains both @param _a and @param _b.
+ /// Assumes that @param _a and @param _b refer to the same source (exception: if the source of either one
+ /// is unset, the source of the other will be used for the result, even if that is unset as well).
+ /// Invalid start and end positions (with value of -1) are ignored (if start or end are -1 for both @param _a and
+ /// @param _b, then start resp. end of the result will be -1 as well).
+ static SourceLocation smallestCovering(SourceLocation _a, SourceLocation const& _b)
+ {
+ if (!_a.source)
+ _a.source = _b.source;
+
+ if (_a.start < 0)
+ _a.start = _b.start;
+ else if (_b.start >= 0 && _b.start < _a.start)
+ _a.start = _b.start;
+ if (_b.end > _a.end)
+ _a.end = _b.end;
+
+ return _a;
+ }
+
int start = -1;
int end = -1;
std::shared_ptr<CharStream> source;