mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Ast-Import from standard-json
This commit is contained in:
@@ -23,13 +23,12 @@
|
||||
#pragma once
|
||||
|
||||
#include <libsolutil/Assertions.h>
|
||||
#include <libsolutil/Common.h> // defines noexcept macro for MSVC
|
||||
#include <libsolutil/Exceptions.h>
|
||||
|
||||
#include <liblangutil/CharStream.h>
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <ostream>
|
||||
#include <tuple>
|
||||
|
||||
namespace solidity::langutil
|
||||
{
|
||||
@@ -46,9 +45,28 @@ struct SourceLocation
|
||||
return source.get() == _other.source.get() && start == _other.start && end == _other.end;
|
||||
}
|
||||
bool operator!=(SourceLocation const& _other) const { return !operator==(_other); }
|
||||
inline bool operator<(SourceLocation const& _other) const;
|
||||
inline bool contains(SourceLocation const& _other) const;
|
||||
inline bool intersects(SourceLocation const& _other) const;
|
||||
|
||||
inline bool operator<(SourceLocation const& _other) const
|
||||
{
|
||||
if (!source|| !_other.source)
|
||||
return std::make_tuple(int(!!source), start, end) < std::make_tuple(int(!!_other.source), _other.start, _other.end);
|
||||
else
|
||||
return std::make_tuple(source->name(), start, end) < std::make_tuple(_other.source->name(), _other.start, _other.end);
|
||||
}
|
||||
|
||||
inline bool contains(SourceLocation const& _other) const
|
||||
{
|
||||
if (isEmpty() || _other.isEmpty() || source.get() != _other.source.get())
|
||||
return false;
|
||||
return start <= _other.start && _other.end <= end;
|
||||
}
|
||||
|
||||
inline bool intersects(SourceLocation const& _other) const
|
||||
{
|
||||
if (isEmpty() || _other.isEmpty() || source.get() != _other.source.get())
|
||||
return false;
|
||||
return _other.start < end && start < _other.end;
|
||||
}
|
||||
|
||||
bool isEmpty() const { return start == -1 && end == -1; }
|
||||
|
||||
@@ -86,6 +104,8 @@ struct SourceLocation
|
||||
std::shared_ptr<CharStream> source;
|
||||
};
|
||||
|
||||
SourceLocation const parseSourceLocation(std::string const& _input, std::string const& _sourceName, size_t _maxIndex = -1);
|
||||
|
||||
/// Stream output for Location (used e.g. in boost exceptions).
|
||||
inline std::ostream& operator<<(std::ostream& _out, SourceLocation const& _location)
|
||||
{
|
||||
@@ -100,26 +120,4 @@ inline std::ostream& operator<<(std::ostream& _out, SourceLocation const& _locat
|
||||
return _out;
|
||||
}
|
||||
|
||||
bool SourceLocation::operator<(SourceLocation const& _other) const
|
||||
{
|
||||
if (!source|| !_other.source)
|
||||
return std::make_tuple(int(!!source), start, end) < std::make_tuple(int(!!_other.source), _other.start, _other.end);
|
||||
else
|
||||
return std::make_tuple(source->name(), start, end) < std::make_tuple(_other.source->name(), _other.start, _other.end);
|
||||
}
|
||||
|
||||
bool SourceLocation::contains(SourceLocation const& _other) const
|
||||
{
|
||||
if (isEmpty() || _other.isEmpty() || source.get() != _other.source.get())
|
||||
return false;
|
||||
return start <= _other.start && _other.end <= end;
|
||||
}
|
||||
|
||||
bool SourceLocation::intersects(SourceLocation const& _other) const
|
||||
{
|
||||
if (isEmpty() || _other.isEmpty() || source.get() != _other.source.get())
|
||||
return false;
|
||||
return _other.start < end && start < _other.end;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user