| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "tools/gn/location.h" | 5 #include "tools/gn/location.h" |
| 6 | 6 |
| 7 #include <tuple> | 7 #include <tuple> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| 11 #include "tools/gn/input_file.h" | 11 #include "tools/gn/input_file.h" |
| 12 | 12 |
| 13 Location::Location() | 13 Location::Location() |
| 14 : file_(nullptr), | 14 : file_(nullptr), |
| 15 line_number_(-1), | 15 line_number_(-1), |
| 16 column_number_(-1) { | 16 column_number_(-1) { |
| 17 } | 17 } |
| 18 | 18 |
| 19 Location::Location(const InputFile* file, | 19 Location::Location(const InputFile* file, |
| 20 int line_number, | 20 int line_number, |
| 21 int column_number, | 21 int column_number, |
| 22 int byte) | 22 int byte) |
| 23 : file_(file), | 23 : file_(file), |
| 24 line_number_(line_number), | 24 line_number_(line_number), |
| 25 column_number_(column_number), | 25 column_number_(column_number), |
| 26 byte_(byte) { | 26 byte_(byte) { |
| 27 } | 27 } |
| 28 | 28 |
| 29 bool Location::is_null() const { |
| 30 return *this == Location(); |
| 31 } |
| 32 |
| 29 bool Location::operator==(const Location& other) const { | 33 bool Location::operator==(const Location& other) const { |
| 30 return other.file_ == file_ && | 34 return other.file_ == file_ && |
| 31 other.line_number_ == line_number_ && | 35 other.line_number_ == line_number_ && |
| 32 other.column_number_ == column_number_; | 36 other.column_number_ == column_number_; |
| 33 } | 37 } |
| 34 | 38 |
| 35 bool Location::operator!=(const Location& other) const { | 39 bool Location::operator!=(const Location& other) const { |
| 36 return !operator==(other); | 40 return !operator==(other); |
| 37 } | 41 } |
| 38 | 42 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 63 | 67 |
| 64 LocationRange::LocationRange() { | 68 LocationRange::LocationRange() { |
| 65 } | 69 } |
| 66 | 70 |
| 67 LocationRange::LocationRange(const Location& begin, const Location& end) | 71 LocationRange::LocationRange(const Location& begin, const Location& end) |
| 68 : begin_(begin), | 72 : begin_(begin), |
| 69 end_(end) { | 73 end_(end) { |
| 70 DCHECK(begin_.file() == end_.file()); | 74 DCHECK(begin_.file() == end_.file()); |
| 71 } | 75 } |
| 72 | 76 |
| 77 bool LocationRange::is_null() const { |
| 78 return begin_.is_null(); // No need to check both for the null case. |
| 79 } |
| 80 |
| 73 LocationRange LocationRange::Union(const LocationRange& other) const { | 81 LocationRange LocationRange::Union(const LocationRange& other) const { |
| 74 DCHECK(begin_.file() == other.begin_.file()); | 82 DCHECK(begin_.file() == other.begin_.file()); |
| 75 return LocationRange( | 83 return LocationRange( |
| 76 begin_ < other.begin_ ? begin_ : other.begin_, | 84 begin_ < other.begin_ ? begin_ : other.begin_, |
| 77 end_ < other.end_ ? other.end_ : end_); | 85 end_ < other.end_ ? other.end_ : end_); |
| 78 } | 86 } |
| OLD | NEW |