You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
65 lines
2.1 KiB
65 lines
2.1 KiB
10 years ago
|
/*
|
||
10 years ago
|
This file is part of cpp-ethereum.
|
||
10 years ago
|
|
||
10 years ago
|
cpp-ethereum is free software: you can redistribute it and/or modify
|
||
|
it under the terms of the GNU General Public License as published by
|
||
|
the Free Software Foundation, either version 3 of the License, or
|
||
|
(at your option) any later version.
|
||
10 years ago
|
|
||
10 years ago
|
cpp-ethereum is distributed in the hope that it will be useful,
|
||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
|
GNU General Public License for more details.
|
||
10 years ago
|
|
||
10 years ago
|
You should have received a copy of the GNU General Public License
|
||
|
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
||
10 years ago
|
*/
|
||
|
/**
|
||
10 years ago
|
* @author Lefteris Karapetsas <lefteris@ethdev.com>
|
||
|
* @date 2015
|
||
|
* Represents a location in a source file
|
||
10 years ago
|
*/
|
||
|
|
||
10 years ago
|
#pragma once
|
||
|
|
||
10 years ago
|
#include <memory>
|
||
|
#include <string>
|
||
10 years ago
|
#include <ostream>
|
||
10 years ago
|
|
||
10 years ago
|
namespace dev
|
||
|
{
|
||
10 years ago
|
|
||
10 years ago
|
/**
|
||
|
* Representation of an interval of source positions.
|
||
|
* The interval includes start and excludes end.
|
||
|
*/
|
||
10 years ago
|
struct SourceLocation
|
||
10 years ago
|
{
|
||
10 years ago
|
SourceLocation(int _start, int _end, std::shared_ptr<std::string const> _sourceName):
|
||
10 years ago
|
start(_start), end(_end), sourceName(_sourceName) { }
|
||
10 years ago
|
SourceLocation(): start(-1), end(-1) { }
|
||
10 years ago
|
|
||
10 years ago
|
SourceLocation(SourceLocation const& _other):
|
||
|
start(_other.start), end(_other.end), sourceName(_other.sourceName) {}
|
||
|
SourceLocation& operator=(SourceLocation const& _other) { start = _other.start; end = _other.end; sourceName = _other.sourceName; return *this;}
|
||
10 years ago
|
|
||
10 years ago
|
bool operator==(SourceLocation const& _other) const { return start == _other.start && end == _other.end;}
|
||
|
bool operator!=(SourceLocation const& _other) const { return !operator==(_other); }
|
||
10 years ago
|
|
||
10 years ago
|
bool isEmpty() const { return start == -1 && end == -1; }
|
||
|
|
||
10 years ago
|
int start;
|
||
|
int end;
|
||
10 years ago
|
std::shared_ptr<std::string const> sourceName;
|
||
10 years ago
|
};
|
||
|
|
||
10 years ago
|
/// Stream output for Location (used e.g. in boost exceptions).
|
||
10 years ago
|
inline std::ostream& operator<<(std::ostream& _out, SourceLocation const& _location)
|
||
10 years ago
|
{
|
||
10 years ago
|
if (_location.isEmpty())
|
||
|
return _out << "NO_LOCATION_SPECIFIED";
|
||
10 years ago
|
return _out << *_location.sourceName << "[" << _location.start << "," << _location.end << ")";
|
||
10 years ago
|
}
|
||
|
|
||
10 years ago
|
}
|