blob: 79af5ddb72487361d66d04f821fe31822119b7a5 [file] [log] [blame]
// Copyright (c) 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <string>
class InputFile;
// Represents a place in a source file. Used for error reporting.
class Location {
Location(const InputFile* file, int line_number, int column_number);
const InputFile* file() const { return file_; }
int line_number() const { return line_number_; }
int column_number() const { return column_number_; }
bool is_null() const { return *this == Location(); }
bool operator==(const Location& other) const;
bool operator!=(const Location& other) const;
bool operator<(const Location& other) const;
bool operator<=(const Location& other) const;
bool operator>(const Location& other) const { return !(*this <= other); }
bool operator>=(const Location& other) const { return !(*this < other); }
// Returns a string with the file, line, and (optionally) the character
// offset for this location. If this location is null, returns an empty
// string.
std::string Describe(bool include_column_number) const;
const InputFile* file_ = nullptr; // Null when unset.
int line_number_ = -1; // -1 when unset. 1-based.
int column_number_ = -1; // -1 when unset. 1-based.
// Represents a range in a source file. Used for error reporting.
// The end is exclusive i.e. [begin, end)
class LocationRange {
LocationRange(const Location& begin, const Location& end);
const Location& begin() const { return begin_; }
const Location& end() const { return end_; }
bool is_null() const {
return begin_.is_null(); // No need to check both for the null case.
LocationRange Union(const LocationRange& other) const;
Location begin_;
Location end_;