liblangutil: SourceLocation: adds (shared) pointer to underlying CharStream source, eliminating sourceName

Also, adapted affecting code to those changes.
This commit is contained in:
Christian Parpart
2018-11-30 17:07:12 +01:00
parent 22eff22492
commit c48a5264be
17 changed files with 127 additions and 102 deletions
+3 -3
View File
@@ -492,9 +492,9 @@ bool DeclarationRegistrationHelper::registerDeclaration(
Declaration const* conflictingDeclaration = _container.conflictingDeclaration(_declaration, _name);
solAssert(conflictingDeclaration, "");
bool const comparable =
_errorLocation->sourceName &&
conflictingDeclaration->location().sourceName &&
*_errorLocation->sourceName == *conflictingDeclaration->location().sourceName;
_errorLocation->source &&
conflictingDeclaration->location().source &&
_errorLocation->source->name() == conflictingDeclaration->location().source->name();
if (comparable && _errorLocation->start < conflictingDeclaration->location().start)
{
firstDeclarationLocation = *_errorLocation;
+2 -2
View File
@@ -122,8 +122,8 @@ void ASTJsonConverter::setJsonNode(
string ASTJsonConverter::sourceLocationToString(SourceLocation const& _location) const
{
int sourceIndex{-1};
if (_location.sourceName && m_sourceIndices.count(*_location.sourceName))
sourceIndex = m_sourceIndices.at(*_location.sourceName);
if (_location.source && m_sourceIndices.count(_location.source->name()))
sourceIndex = m_sourceIndices.at(_location.source->name());
int length = -1;
if (_location.start >= 0 && _location.end >= 0)
length = _location.end - _location.start;
+4 -4
View File
@@ -598,8 +598,8 @@ tuple<int, int, int, int> CompilerStack::positionFromSourceLocation(SourceLocati
int startColumn;
int endLine;
int endColumn;
tie(startLine, startColumn) = scanner(*_sourceLocation.sourceName).translatePositionToLineColumn(_sourceLocation.start);
tie(endLine, endColumn) = scanner(*_sourceLocation.sourceName).translatePositionToLineColumn(_sourceLocation.end);
tie(startLine, startColumn) = scanner(_sourceLocation.source->name()).translatePositionToLineColumn(_sourceLocation.start);
tie(endLine, endColumn) = scanner(_sourceLocation.source->name()).translatePositionToLineColumn(_sourceLocation.end);
return make_tuple(++startLine, ++startColumn, ++endLine, ++endColumn);
}
@@ -922,8 +922,8 @@ string CompilerStack::computeSourceMapping(eth::AssemblyItems const& _items) con
SourceLocation const& location = item.location();
int length = location.start != -1 && location.end != -1 ? location.end - location.start : -1;
int sourceIndex =
location.sourceName && sourceIndicesMap.count(*location.sourceName) ?
sourceIndicesMap.at(*location.sourceName) :
location.source && sourceIndicesMap.count(location.source->name()) ?
sourceIndicesMap.at(location.source->name()) :
-1;
char jump = '-';
if (item.getJumpType() == eth::AssemblyItem::JumpType::IntoFunction)
+2 -2
View File
@@ -85,9 +85,9 @@ Json::Value formatErrorWithException(
message = _message;
Json::Value sourceLocation;
if (location && location->sourceName)
if (location && location->source && location->source->name() != "")
{
sourceLocation["file"] = *location->sourceName;
sourceLocation["file"] = location->source->name();
sourceLocation["start"] = location->start;
sourceLocation["end"] = location->end;
}
+2 -2
View File
@@ -42,7 +42,7 @@ class Parser::ASTNodeFactory
{
public:
explicit ASTNodeFactory(Parser const& _parser):
m_parser(_parser), m_location(_parser.position(), -1, _parser.sourceName()) {}
m_parser(_parser), m_location(_parser.position(), -1, _parser.source()) {}
ASTNodeFactory(Parser const& _parser, ASTPointer<ASTNode> const& _childNode):
m_parser(_parser), m_location(_childNode->location()) {}
@@ -55,7 +55,7 @@ public:
template <class NodeType, typename... Args>
ASTPointer<NodeType> createNode(Args&& ... _args)
{
solAssert(m_location.sourceName, "");
solAssert(m_location.source, "");
if (m_location.end < 0)
markEndPosition();
return make_shared<NodeType>(m_location, std::forward<Args>(_args)...);