mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Use shared DebugData for when using source locations from comments.
This commit is contained in:
parent
5e4868d5d6
commit
f129a3498c
@ -128,21 +128,20 @@ void Parser::fetchSourceLocationFromComment()
|
||||
auto const end = toInt(matchResult[4].str());
|
||||
|
||||
auto const commentLocation = m_scanner->currentCommentLocation();
|
||||
m_locationOverride = SourceLocation{};
|
||||
m_debugDataOverride = DebugData::create();
|
||||
if (!sourceIndex || !start || !end)
|
||||
m_errorReporter.syntaxError(6367_error, commentLocation, "Invalid value in source location mapping. Could not parse location specification.");
|
||||
else if (!((*start < 0 && *end < 0) || (*start >= 0 && *start <= *end)))
|
||||
m_errorReporter.syntaxError(5798_error, commentLocation, "Invalid value in source location mapping. Start offset larger than end offset.");
|
||||
else if (sourceIndex == -1 && (0 <= *start && *start <= *end)) // Use source index -1 to indicate original source.
|
||||
m_locationOverride = SourceLocation{*start, *end, ParserBase::currentLocation().source};
|
||||
m_debugDataOverride = DebugData::create(SourceLocation{*start, *end, ParserBase::currentLocation().source});
|
||||
else if (!(sourceIndex >= 0 && m_charStreamMap->count(static_cast<unsigned>(*sourceIndex))))
|
||||
m_errorReporter.syntaxError(2674_error, commentLocation, "Invalid source mapping. Source index not defined via @use-src.");
|
||||
else
|
||||
{
|
||||
shared_ptr<CharStream> charStream = m_charStreamMap->at(static_cast<unsigned>(*sourceIndex));
|
||||
solAssert(charStream, "");
|
||||
|
||||
m_locationOverride = SourceLocation{*start, *end, charStream};
|
||||
m_debugDataOverride = DebugData::create(SourceLocation{*start, *end, charStream});
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -371,7 +370,7 @@ variant<Literal, Identifier> Parser::parseLiteralOrIdentifier()
|
||||
{
|
||||
case Token::Identifier:
|
||||
{
|
||||
Identifier identifier{DebugData::create(currentLocation()), YulString{currentLiteral()}};
|
||||
Identifier identifier{createDebugData(), YulString{currentLiteral()}};
|
||||
advance();
|
||||
return identifier;
|
||||
}
|
||||
@ -402,7 +401,7 @@ variant<Literal, Identifier> Parser::parseLiteralOrIdentifier()
|
||||
}
|
||||
|
||||
Literal literal{
|
||||
DebugData::create(currentLocation()),
|
||||
createDebugData(),
|
||||
kind,
|
||||
YulString{currentLiteral()},
|
||||
kind == LiteralKind::Boolean ? m_dialect.boolType : m_dialect.defaultType
|
||||
|
@ -59,6 +59,7 @@ public:
|
||||
ParserBase(_errorReporter),
|
||||
m_dialect(_dialect),
|
||||
m_locationOverride{_locationOverride ? *_locationOverride : langutil::SourceLocation{}},
|
||||
m_debugDataOverride{},
|
||||
m_useSourceLocationFrom{
|
||||
_locationOverride ?
|
||||
UseSourceLocationFrom::LocationOverride :
|
||||
@ -76,6 +77,7 @@ public:
|
||||
ParserBase(_errorReporter),
|
||||
m_dialect(_dialect),
|
||||
m_charStreamMap{std::move(_charStreamMap)},
|
||||
m_debugDataOverride{DebugData::create()},
|
||||
m_useSourceLocationFrom{UseSourceLocationFrom::Comments}
|
||||
{}
|
||||
|
||||
@ -96,11 +98,26 @@ protected:
|
||||
|
||||
void fetchSourceLocationFromComment();
|
||||
|
||||
/// Creates a DebugData object with the correct source location set.
|
||||
std::shared_ptr<DebugData const> createDebugData() const
|
||||
{
|
||||
switch (m_useSourceLocationFrom)
|
||||
{
|
||||
case UseSourceLocationFrom::Scanner:
|
||||
return DebugData::create(ParserBase::currentLocation());
|
||||
case UseSourceLocationFrom::LocationOverride:
|
||||
return DebugData::create(m_locationOverride);
|
||||
case UseSourceLocationFrom::Comments:
|
||||
return m_debugDataOverride;
|
||||
}
|
||||
solAssert(false, "");
|
||||
}
|
||||
|
||||
/// Creates an inline assembly node with the current source location.
|
||||
template <class T> T createWithLocation() const
|
||||
{
|
||||
T r;
|
||||
r.debugData = DebugData::create(currentLocation());
|
||||
r.debugData = createDebugData();
|
||||
return r;
|
||||
}
|
||||
|
||||
@ -129,6 +146,7 @@ private:
|
||||
|
||||
std::optional<std::map<unsigned, std::shared_ptr<langutil::CharStream>>> m_charStreamMap;
|
||||
langutil::SourceLocation m_locationOverride;
|
||||
std::shared_ptr<DebugData const> m_debugDataOverride;
|
||||
UseSourceLocationFrom m_useSourceLocationFrom = UseSourceLocationFrom::Scanner;
|
||||
ForLoopComponent m_currentForLoopComponent = ForLoopComponent::None;
|
||||
bool m_insideFunction = false;
|
||||
|
Loading…
Reference in New Issue
Block a user