| 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 #ifndef TOOLS_GN_LOCATION_H_ | 5 #ifndef TOOLS_GN_LOCATION_H_ |
| 6 #define TOOLS_GN_LOCATION_H_ | 6 #define TOOLS_GN_LOCATION_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 class InputFile; | 10 class InputFile; |
| 11 | 11 |
| 12 // Represents a place in a source file. Used for error reporting. | 12 // Represents a place in a source file. Used for error reporting. |
| 13 class Location { | 13 class Location { |
| 14 public: | 14 public: |
| 15 Location(); | 15 Location(); |
| 16 Location(const InputFile* file, int line_number, int column_number, int byte); | 16 Location(const InputFile* file, int line_number, int column_number, int byte); |
| 17 | 17 |
| 18 const InputFile* file() const { return file_; } | 18 const InputFile* file() const { return file_; } |
| 19 int line_number() const { return line_number_; } | 19 int line_number() const { return line_number_; } |
| 20 int column_number() const { return column_number_; } | 20 int column_number() const { return column_number_; } |
| 21 int byte() const { return byte_; } | 21 int byte() const { return byte_; } |
| 22 bool is_null() const { return *this == Location(); } |
| 22 | 23 |
| 23 bool operator==(const Location& other) const; | 24 bool operator==(const Location& other) const; |
| 24 bool operator!=(const Location& other) const; | 25 bool operator!=(const Location& other) const; |
| 25 bool operator<(const Location& other) const; | 26 bool operator<(const Location& other) const; |
| 26 | 27 |
| 27 // Returns a string with the file, line, and (optionally) the character | 28 // Returns a string with the file, line, and (optionally) the character |
| 28 // offset for this location. If this location is null, returns an empty | 29 // offset for this location. If this location is null, returns an empty |
| 29 // string. | 30 // string. |
| 30 std::string Describe(bool include_column_number) const; | 31 std::string Describe(bool include_column_number) const; |
| 31 | 32 |
| 32 private: | 33 private: |
| 33 const InputFile* file_; // Null when unset. | 34 const InputFile* file_; // Null when unset. |
| 34 int line_number_; // -1 when unset. 1-based. | 35 int line_number_; // -1 when unset. 1-based. |
| 35 int column_number_; // -1 when unset. 1-based. | 36 int column_number_; // -1 when unset. 1-based. |
| 36 int byte_; // Index into the buffer, 0-based. | 37 int byte_; // Index into the buffer, 0-based. |
| 37 }; | 38 }; |
| 38 | 39 |
| 39 // Represents a range in a source file. Used for error reporting. | 40 // Represents a range in a source file. Used for error reporting. |
| 40 // The end is exclusive i.e. [begin, end) | 41 // The end is exclusive i.e. [begin, end) |
| 41 class LocationRange { | 42 class LocationRange { |
| 42 public: | 43 public: |
| 43 LocationRange(); | 44 LocationRange(); |
| 44 LocationRange(const Location& begin, const Location& end); | 45 LocationRange(const Location& begin, const Location& end); |
| 45 | 46 |
| 46 const Location& begin() const { return begin_; } | 47 const Location& begin() const { return begin_; } |
| 47 const Location& end() const { return end_; } | 48 const Location& end() const { return end_; } |
| 49 bool is_null() const { |
| 50 return begin_.is_null(); // No need to check both for the null case. |
| 51 } |
| 52 |
| 48 | 53 |
| 49 LocationRange Union(const LocationRange& other) const; | 54 LocationRange Union(const LocationRange& other) const; |
| 50 | 55 |
| 51 private: | 56 private: |
| 52 Location begin_; | 57 Location begin_; |
| 53 Location end_; | 58 Location end_; |
| 54 }; | 59 }; |
| 55 | 60 |
| 56 #endif // TOOLS_GN_LOCATION_H_ | 61 #endif // TOOLS_GN_LOCATION_H_ |
| OLD | NEW |