Skip to content

Commit

Permalink
Merge branch 'develop' into fix-known-state-typo
Browse files Browse the repository at this point in the history
  • Loading branch information
nikola-matic authored Aug 22, 2023
2 parents 4a97de8 + c703b5c commit f9c14d2
Show file tree
Hide file tree
Showing 64 changed files with 742 additions and 988 deletions.
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Language Features:


Compiler Features:
* Parser: Remove the experimental error recovery mode (``--error-recovery`` / ``settings.parserErrorRecovery``).
* Yul Optimizer: If ``PUSH0`` is supported, favor zero literals over storing zero values in variables.


Expand Down
54 changes: 4 additions & 50 deletions liblangutil/ParserBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,56 +74,10 @@ void ParserBase::expectToken(Token _value, bool _advance)
{
Token tok = m_scanner->currentToken();
if (tok != _value)
{
std::string const expectedToken = ParserBase::tokenName(_value);
if (m_parserErrorRecovery)
parserError(6635_error, "Expected " + expectedToken + " but got " + tokenName(tok));
else
fatalParserError(2314_error, "Expected " + expectedToken + " but got " + tokenName(tok));
// Do not advance so that recovery can sync or make use of the current token.
// This is especially useful if the expected token
// is the only one that is missing and is at the end of a construct.
// "{ ... ; }" is such an example.
// ^
_advance = false;
}
if (_advance)
advance();
}

void ParserBase::expectTokenOrConsumeUntil(Token _value, std::string const& _currentNodeName, bool _advance)
{
solAssert(m_inParserRecovery, "The function is supposed to be called during parser recovery only.");

Token tok = m_scanner->currentToken();
if (tok != _value)
{
SourceLocation errorLoc = currentLocation();
int startPosition = errorLoc.start;
while (m_scanner->currentToken() != _value && m_scanner->currentToken() != Token::EOS)
advance();

std::string const expectedToken = ParserBase::tokenName(_value);
if (m_scanner->currentToken() == Token::EOS)
{
// rollback to where the token started, and raise exception to be caught at a higher level.
m_scanner->setPosition(static_cast<size_t>(startPosition));
std::string const msg = "In " + _currentNodeName + ", " + expectedToken + "is expected; got " + ParserBase::tokenName(tok) + " instead.";
fatalParserError(1957_error, errorLoc, msg);
}
else
{
parserWarning(3796_error, "Recovered in " + _currentNodeName + " at " + expectedToken + ".");
m_inParserRecovery = false;
}
}
else
{
std::string expectedToken = ParserBase::tokenName(_value);
parserWarning(3347_error, "Recovered in " + _currentNodeName + " at " + expectedToken + ".");
m_inParserRecovery = false;
}

fatalParserError(
2314_error,
"Expected " + ParserBase::tokenName(_value) + " but got " + tokenName(tok)
);
if (_advance)
advance();
}
Expand Down
21 changes: 4 additions & 17 deletions liblangutil/ParserBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,9 @@ struct ErrorId;
class ParserBase
{
public:
/// Set @a _parserErrorRecovery to true for additional error
/// recovery. This is experimental and intended for use
/// by front-end tools that need partial AST information even
/// when errors occur.
explicit ParserBase(ErrorReporter& errorReporter, bool _parserErrorRecovery = false): m_errorReporter(errorReporter)
{
m_parserErrorRecovery = _parserErrorRecovery;
}
explicit ParserBase(ErrorReporter& errorReporter):
m_errorReporter(errorReporter)
{}

virtual ~ParserBase() = default;

Expand All @@ -70,13 +65,9 @@ class ParserBase
///@{
///@name Helper functions
/// If current token value is not @a _value, throw exception otherwise advance token
// @a if _advance is true and error recovery is in effect.
// if @a _advance is true
void expectToken(Token _value, bool _advance = true);

/// Like expectToken but if there is an error ignores tokens until
/// the expected token or EOS is seen. If EOS is encountered, back up to the error point,
/// and throw an exception so that a higher grammar rule has an opportunity to recover.
void expectTokenOrConsumeUntil(Token _value, std::string const& _currentNodeName, bool _advance = true);
Token currentToken() const;
Token peekNextToken() const;
std::string tokenName(Token _token);
Expand Down Expand Up @@ -108,10 +99,6 @@ class ParserBase
ErrorReporter& m_errorReporter;
/// Current recursion depth during parsing.
size_t m_recursionDepth = 0;
/// True if we are in parser error recovery. Usually this means we are scanning for
/// a synchronization token like ';', or '}'. We use this to reduce cascaded error messages.
bool m_inParserRecovery = false;
bool m_parserErrorRecovery = false;
};

}
9 changes: 1 addition & 8 deletions libsolidity/analysis/SyntaxChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,14 +159,7 @@ bool SyntaxChecker::visit(PragmaDirective const& _pragma)
SemVerMatchExpressionParser parser(tokens, literals);
SemVerMatchExpression matchExpression = parser.parse();
static SemVerVersion const currentVersion{std::string(VersionString)};
if (!matchExpression.matches(currentVersion))
m_errorReporter.syntaxError(
3997_error,
_pragma.location(),
"Source file requires different compiler version (current compiler is " +
std::string(VersionString) + ") - note that nightly builds are considered to be "
"strictly less than the released version"
);
solAssert(matchExpression.matches(currentVersion));
m_versionPragmaFound = true;
}
catch (SemVerError const&)
Expand Down
12 changes: 8 additions & 4 deletions libsolidity/ast/AST.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,19 @@ class ASTNode
static void listAccept(std::vector<T> const& _list, ASTVisitor& _visitor)
{
for (T const& element: _list)
if (element)
element->accept(_visitor);
{
solAssert(element);
element->accept(_visitor);
}
}
template <class T>
static void listAccept(std::vector<T> const& _list, ASTConstVisitor& _visitor)
{
for (T const& element: _list)
if (element)
element->accept(_visitor);
{
solAssert(element);
element->accept(_visitor);
}
}

/// @returns a copy of the vector containing only the nodes which derive from T.
Expand Down
4 changes: 2 additions & 2 deletions libsolidity/ast/ASTJsonExporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,7 @@ bool ASTJsonExporter::visit(EventDefinition const& _node)
std::make_pair("parameters", toJson(_node.parameterList())),
std::make_pair("anonymous", _node.isAnonymous())
};
if (m_stackState >= CompilerStack::State::AnalysisPerformed)
if (m_stackState >= CompilerStack::State::AnalysisSuccessful)
_attributes.emplace_back(
std::make_pair(
"eventSelector",
Expand All @@ -579,7 +579,7 @@ bool ASTJsonExporter::visit(ErrorDefinition const& _node)
std::make_pair("documentation", _node.documentation() ? toJson(*_node.documentation()) : Json::nullValue),
std::make_pair("parameters", toJson(_node.parameterList()))
};
if (m_stackState >= CompilerStack::State::AnalysisPerformed)
if (m_stackState >= CompilerStack::State::AnalysisSuccessful)
_attributes.emplace_back(std::make_pair("errorSelector", _node.functionType(true)->externalIdentifierHex()));

setJsonNode(_node, "ErrorDefinition", std::move(_attributes));
Expand Down
Loading

0 comments on commit f9c14d2

Please sign in to comment.