Skip to content

Commit c68bc34

Browse files
authored
Merge pull request #6858 from ethereum/develop
Merge develop into release for 0.5.9 (2)
2 parents e560f70 + 4eb1722 commit c68bc34

27 files changed

+137
-489
lines changed

Changelog.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ Language Features:
88
Compiler Features:
99
* Assembler: Encode the compiler version in the deployed bytecode.
1010
* Code Generator: Fix handling of structs of dynamic size as constructor parameters.
11-
* Commandline Interface: Experimental parser error recovery via the ``--error-recovery`` commandline switch.
1211
* Inline Assembly: Disallow the combination of ``msize()`` and the Yul optimizer.
1312
* Metadata: Add IPFS hashes of source files.
1413
* Optimizer: Add rule to simplify SHL/SHR combinations.
@@ -22,6 +21,7 @@ Compiler Features:
2221
* Yul Optimizer: Do not inline recursive functions.
2322
* Yul Optimizer: Do not remove instructions that affect ``msize()`` if ``msize()`` is used.
2423

24+
2525
Bugfixes:
2626
* Code Generator: Explicitly turn uninitialized internal function pointers into invalid functions when loaded from storage.
2727
* Code Generator: Fix assertion failure when assigning structs containing array of mapping.

liblangutil/CharStream.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,6 @@ char CharStream::rollback(size_t _amount)
7373
return get();
7474
}
7575

76-
char CharStream::setPosition(size_t _location)
77-
{
78-
solAssert(_location <= m_source.size(), "Attempting to set position past end of source.");
79-
m_position = _location;
80-
return get();
81-
}
82-
8376
string CharStream::lineAtPosition(int _position) const
8477
{
8578
// if _position points to \n, it returns the line before the \n
@@ -113,3 +106,5 @@ tuple<int, int> CharStream::translatePositionToLineColumn(int _position) const
113106
}
114107
return tuple<int, int>(lineNumber, searchPosition - lineStart);
115108
}
109+
110+

liblangutil/CharStream.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,7 @@ class CharStream
7676

7777
char get(size_t _charsForward = 0) const { return m_source[m_position + _charsForward]; }
7878
char advanceAndGet(size_t _chars = 1);
79-
/// Sets scanner position to @ _amount characters backwards in source text.
80-
/// @returns The character of the current location after update is returned.
8179
char rollback(size_t _amount);
82-
/// Sets scanner position to @ _location if it refers a valid offset in m_source.
83-
/// If not, nothing is done.
84-
/// @returns The character of the current location after update is returned.
85-
char setPosition(size_t _location);
8680

8781
void reset() { m_position = 0; }
8882

liblangutil/ErrorReporter.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,6 @@ void ErrorReporter::error(Error::Type _type, SourceLocation const& _location, Se
8686
m_errorList.push_back(err);
8787
}
8888

89-
bool ErrorReporter::hasExcessiveErrors() const
90-
{
91-
return m_errorCount > c_maxErrorsAllowed;
92-
}
93-
9489
bool ErrorReporter::checkForExcessiveErrors(Error::Type _type)
9590
{
9691
if (_type == Error::Type::Warning)

liblangutil/ErrorReporter.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,6 @@ class ErrorReporter
118118
return m_errorCount > 0;
119119
}
120120

121-
// @returns true if the maximum error count has been reached.
122-
bool hasExcessiveErrors() const;
123-
124121
private:
125122
void error(
126123
Error::Type _type,
@@ -152,3 +149,4 @@ class ErrorReporter
152149
};
153150

154151
}
152+

liblangutil/ParserBase.cpp

Lines changed: 19 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ Token ParserBase::peekNextToken() const
4747
return m_scanner->peekNextToken();
4848
}
4949

50-
string ParserBase::currentLiteral() const
50+
std::string ParserBase::currentLiteral() const
5151
{
5252
return m_scanner->currentLiteral();
5353
}
@@ -57,79 +57,30 @@ Token ParserBase::advance()
5757
return m_scanner->next();
5858
}
5959

60-
string ParserBase::tokenName(Token _token)
61-
{
62-
if (_token == Token::Identifier)
63-
return "identifier";
64-
else if (_token == Token::EOS)
65-
return "end of source";
66-
else if (TokenTraits::isReservedKeyword(_token))
67-
return "reserved keyword '" + TokenTraits::friendlyName(_token) + "'";
68-
else if (TokenTraits::isElementaryTypeName(_token)) //for the sake of accuracy in reporting
69-
{
70-
ElementaryTypeNameToken elemTypeName = m_scanner->currentElementaryTypeNameToken();
71-
return "'" + elemTypeName.toString() + "'";
72-
}
73-
else
74-
return "'" + TokenTraits::friendlyName(_token) + "'";
75-
}
76-
7760
void ParserBase::expectToken(Token _value, bool _advance)
7861
{
7962
Token tok = m_scanner->currentToken();
8063
if (tok != _value)
8164
{
82-
string const expectedToken = ParserBase::tokenName(_value);
83-
if (m_parserErrorRecovery)
84-
parserError("Expected " + expectedToken + " but got " + tokenName(tok));
85-
else
86-
fatalParserError("Expected " + expectedToken + " but got " + tokenName(tok));
87-
// Do not advance so that recovery can sync or make use of the current token.
88-
// This is especially useful if the expected token
89-
// is the only one that is missing and is at the end of a construct.
90-
// "{ ... ; }" is such an example.
91-
// ^
92-
_advance = false;
93-
}
94-
if (_advance)
95-
m_scanner->next();
96-
}
97-
98-
void ParserBase::expectTokenOrConsumeUntil(Token _value, string const& _currentNodeName, bool _advance)
99-
{
100-
Token tok = m_scanner->currentToken();
101-
if (tok != _value)
102-
{
103-
int startPosition = position();
104-
SourceLocation errorLoc = SourceLocation{startPosition, endPosition(), source()};
105-
while (m_scanner->currentToken() != _value && m_scanner->currentToken() != Token::EOS)
106-
m_scanner->next();
107-
108-
string const expectedToken = ParserBase::tokenName(_value);
109-
string const msg = "In " + _currentNodeName + ", " + expectedToken + "is expected; got " + ParserBase::tokenName(tok) + "instead.";
110-
if (m_scanner->currentToken() == Token::EOS)
65+
auto tokenName = [this](Token _token)
11166
{
112-
// rollback to where the token started, and raise exception to be caught at a higher level.
113-
m_scanner->setPosition(startPosition);
114-
m_inParserRecovery = true;
115-
fatalParserError(errorLoc, msg);
116-
}
117-
else
118-
{
119-
if (m_inParserRecovery)
120-
parserWarning("Recovered in " + _currentNodeName + " at " + expectedToken + ".");
67+
if (_token == Token::Identifier)
68+
return string("identifier");
69+
else if (_token == Token::EOS)
70+
return string("end of source");
71+
else if (TokenTraits::isReservedKeyword(_token))
72+
return string("reserved keyword '") + TokenTraits::friendlyName(_token) + "'";
73+
else if (TokenTraits::isElementaryTypeName(_token)) //for the sake of accuracy in reporting
74+
{
75+
ElementaryTypeNameToken elemTypeName = m_scanner->currentElementaryTypeNameToken();
76+
return string("'") + elemTypeName.toString() + "'";
77+
}
12178
else
122-
parserError(errorLoc, msg + "Recovered at next " + expectedToken);
123-
m_inParserRecovery = false;
124-
}
125-
}
126-
else if (m_inParserRecovery)
127-
{
128-
string expectedToken = ParserBase::tokenName(_value);
129-
parserWarning("Recovered in " + _currentNodeName + " at " + expectedToken + ".");
130-
m_inParserRecovery = false;
131-
}
79+
return string("'") + TokenTraits::friendlyName(_token) + "'";
80+
};
13281

82+
fatalParserError(string("Expected ") + tokenName(_value) + string(" but got ") + tokenName(tok));
83+
}
13384
if (_advance)
13485
m_scanner->next();
13586
}
@@ -147,27 +98,12 @@ void ParserBase::decreaseRecursionDepth()
14798
m_recursionDepth--;
14899
}
149100

150-
void ParserBase::parserWarning(string const& _description)
151-
{
152-
m_errorReporter.warning(SourceLocation{position(), endPosition(), source()}, _description);
153-
}
154-
155-
void ParserBase::parserError(SourceLocation const& _location, string const& _description)
156-
{
157-
m_errorReporter.parserError(_location, _description);
158-
}
159-
160101
void ParserBase::parserError(string const& _description)
161102
{
162-
parserError(SourceLocation{position(), endPosition(), source()}, _description);
103+
m_errorReporter.parserError(SourceLocation{position(), endPosition(), source()}, _description);
163104
}
164105

165106
void ParserBase::fatalParserError(string const& _description)
166107
{
167-
fatalParserError(SourceLocation{position(), endPosition(), source()}, _description);
168-
}
169-
170-
void ParserBase::fatalParserError(SourceLocation const& _location, string const& _description)
171-
{
172-
m_errorReporter.fatalParserError(_location, _description);
108+
m_errorReporter.fatalParserError(SourceLocation{position(), endPosition(), source()}, _description);
173109
}

liblangutil/ParserBase.h

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,7 @@ class Scanner;
3636
class ParserBase
3737
{
3838
public:
39-
/// Set @a _parserErrorRecovery to true for additional error
40-
/// recovery. This is experimental and intended for use
41-
/// by front-end tools that need partial AST information even
42-
/// when errors occur.
43-
explicit ParserBase(ErrorReporter& errorReporter, bool _parserErrorRecovery = false): m_errorReporter(errorReporter)
44-
{
45-
m_parserErrorRecovery = _parserErrorRecovery;
46-
}
39+
explicit ParserBase(ErrorReporter& errorReporter): m_errorReporter(errorReporter) {}
4740

4841
std::shared_ptr<CharStream> source() const { return m_scanner->charStream(); }
4942

@@ -69,17 +62,10 @@ class ParserBase
6962

7063
///@{
7164
///@name Helper functions
72-
/// If current token value is not @a _value, throw exception otherwise advance token
73-
// @a if _advance is true and error recovery is in effect.
65+
/// If current token value is not _value, throw exception otherwise advance token.
7466
void expectToken(Token _value, bool _advance = true);
75-
76-
/// Like expectToken but if there is an error ignores tokens until
77-
/// the expected token or EOS is seen. If EOS is encountered, back up to the error point,
78-
/// and throw an exception so that a higher grammar rule has an opportunity to recover.
79-
void expectTokenOrConsumeUntil(Token _value, std::string const& _currentNodeName, bool _advance = true);
8067
Token currentToken() const;
8168
Token peekNextToken() const;
82-
std::string tokenName(Token _token);
8369
std::string currentLiteral() const;
8470
Token advance();
8571
///@}
@@ -91,26 +77,16 @@ class ParserBase
9177
/// Creates a @ref ParserError and annotates it with the current position and the
9278
/// given @a _description.
9379
void parserError(std::string const& _description);
94-
void parserError(SourceLocation const& _location, std::string const& _description);
95-
96-
/// Creates a @ref ParserWarning and annotates it with the current position and the
97-
/// given @a _description.
98-
void parserWarning(std::string const& _description);
9980

10081
/// Creates a @ref ParserError and annotates it with the current position and the
10182
/// given @a _description. Throws the FatalError.
10283
void fatalParserError(std::string const& _description);
103-
void fatalParserError(SourceLocation const& _location, std::string const& _description);
10484

10585
std::shared_ptr<Scanner> m_scanner;
10686
/// The reference to the list of errors and warning to add errors/warnings during parsing
10787
ErrorReporter& m_errorReporter;
10888
/// Current recursion depth during parsing.
10989
size_t m_recursionDepth = 0;
110-
/// True if we are in parser error recovery. Usually this means we are scanning for
111-
/// a synchronization token like ';', or '}'. We use this to reduce cascaded error messages.
112-
bool m_inParserRecovery = false;
113-
bool m_parserErrorRecovery = false;
11490
};
11591

11692
}

liblangutil/Scanner.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -156,13 +156,6 @@ void Scanner::reset()
156156
next();
157157
}
158158

159-
void Scanner::setPosition(size_t _offset)
160-
{
161-
m_char = m_source->setPosition(_offset);
162-
scanToken();
163-
next();
164-
}
165-
166159
void Scanner::supportPeriodInIdentifier(bool _value)
167160
{
168161
m_supportPeriodInIdentifier = _value;

liblangutil/Scanner.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,6 @@ class Scanner
110110
/// @returns the next token and advances input
111111
Token next();
112112

113-
/// Set scanner to a specific offset. This is used in error recovery.
114-
void setPosition(size_t _offset);
115-
116113
///@{
117114
///@name Information about the current token
118115

libsolidity/interface/CompilerStack.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ bool CompilerStack::parse()
217217
string const& path = sourcesToParse[i];
218218
Source& source = m_sources[path];
219219
source.scanner->reset();
220-
source.ast = Parser(m_errorReporter, m_evmVersion, m_parserErrorRecovery).parse(source.scanner);
220+
source.ast = Parser(m_errorReporter, m_evmVersion).parse(source.scanner);
221221
if (!source.ast)
222222
solAssert(!Error::containsOnlyWarnings(m_errorReporter.errors()), "Parser returned null but did not report error.");
223223
else

0 commit comments

Comments
 (0)