Skip to content

Commit

Permalink
Merge pull request #6858 from ethereum/develop
Browse files Browse the repository at this point in the history
Merge develop into release for 0.5.9 (2)
  • Loading branch information
chriseth authored May 28, 2019
2 parents e560f70 + 4eb1722 commit c68bc34
Show file tree
Hide file tree
Showing 27 changed files with 137 additions and 489 deletions.
2 changes: 1 addition & 1 deletion Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ Language Features:
Compiler Features:
* Assembler: Encode the compiler version in the deployed bytecode.
* Code Generator: Fix handling of structs of dynamic size as constructor parameters.
* Commandline Interface: Experimental parser error recovery via the ``--error-recovery`` commandline switch.
* Inline Assembly: Disallow the combination of ``msize()`` and the Yul optimizer.
* Metadata: Add IPFS hashes of source files.
* Optimizer: Add rule to simplify SHL/SHR combinations.
Expand All @@ -22,6 +21,7 @@ Compiler Features:
* Yul Optimizer: Do not inline recursive functions.
* Yul Optimizer: Do not remove instructions that affect ``msize()`` if ``msize()`` is used.


Bugfixes:
* Code Generator: Explicitly turn uninitialized internal function pointers into invalid functions when loaded from storage.
* Code Generator: Fix assertion failure when assigning structs containing array of mapping.
Expand Down
9 changes: 2 additions & 7 deletions liblangutil/CharStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,6 @@ char CharStream::rollback(size_t _amount)
return get();
}

char CharStream::setPosition(size_t _location)
{
solAssert(_location <= m_source.size(), "Attempting to set position past end of source.");
m_position = _location;
return get();
}

string CharStream::lineAtPosition(int _position) const
{
// if _position points to \n, it returns the line before the \n
Expand Down Expand Up @@ -113,3 +106,5 @@ tuple<int, int> CharStream::translatePositionToLineColumn(int _position) const
}
return tuple<int, int>(lineNumber, searchPosition - lineStart);
}


6 changes: 0 additions & 6 deletions liblangutil/CharStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,7 @@ class CharStream

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

void reset() { m_position = 0; }

Expand Down
5 changes: 0 additions & 5 deletions liblangutil/ErrorReporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,6 @@ void ErrorReporter::error(Error::Type _type, SourceLocation const& _location, Se
m_errorList.push_back(err);
}

bool ErrorReporter::hasExcessiveErrors() const
{
return m_errorCount > c_maxErrorsAllowed;
}

bool ErrorReporter::checkForExcessiveErrors(Error::Type _type)
{
if (_type == Error::Type::Warning)
Expand Down
4 changes: 1 addition & 3 deletions liblangutil/ErrorReporter.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,6 @@ class ErrorReporter
return m_errorCount > 0;
}

// @returns true if the maximum error count has been reached.
bool hasExcessiveErrors() const;

private:
void error(
Error::Type _type,
Expand Down Expand Up @@ -152,3 +149,4 @@ class ErrorReporter
};

}

102 changes: 19 additions & 83 deletions liblangutil/ParserBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Token ParserBase::peekNextToken() const
return m_scanner->peekNextToken();
}

string ParserBase::currentLiteral() const
std::string ParserBase::currentLiteral() const
{
return m_scanner->currentLiteral();
}
Expand All @@ -57,79 +57,30 @@ Token ParserBase::advance()
return m_scanner->next();
}

string ParserBase::tokenName(Token _token)
{
if (_token == Token::Identifier)
return "identifier";
else if (_token == Token::EOS)
return "end of source";
else if (TokenTraits::isReservedKeyword(_token))
return "reserved keyword '" + TokenTraits::friendlyName(_token) + "'";
else if (TokenTraits::isElementaryTypeName(_token)) //for the sake of accuracy in reporting
{
ElementaryTypeNameToken elemTypeName = m_scanner->currentElementaryTypeNameToken();
return "'" + elemTypeName.toString() + "'";
}
else
return "'" + TokenTraits::friendlyName(_token) + "'";
}

void ParserBase::expectToken(Token _value, bool _advance)
{
Token tok = m_scanner->currentToken();
if (tok != _value)
{
string const expectedToken = ParserBase::tokenName(_value);
if (m_parserErrorRecovery)
parserError("Expected " + expectedToken + " but got " + tokenName(tok));
else
fatalParserError("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)
m_scanner->next();
}

void ParserBase::expectTokenOrConsumeUntil(Token _value, string const& _currentNodeName, bool _advance)
{
Token tok = m_scanner->currentToken();
if (tok != _value)
{
int startPosition = position();
SourceLocation errorLoc = SourceLocation{startPosition, endPosition(), source()};
while (m_scanner->currentToken() != _value && m_scanner->currentToken() != Token::EOS)
m_scanner->next();

string const expectedToken = ParserBase::tokenName(_value);
string const msg = "In " + _currentNodeName + ", " + expectedToken + "is expected; got " + ParserBase::tokenName(tok) + "instead.";
if (m_scanner->currentToken() == Token::EOS)
auto tokenName = [this](Token _token)
{
// rollback to where the token started, and raise exception to be caught at a higher level.
m_scanner->setPosition(startPosition);
m_inParserRecovery = true;
fatalParserError(errorLoc, msg);
}
else
{
if (m_inParserRecovery)
parserWarning("Recovered in " + _currentNodeName + " at " + expectedToken + ".");
if (_token == Token::Identifier)
return string("identifier");
else if (_token == Token::EOS)
return string("end of source");
else if (TokenTraits::isReservedKeyword(_token))
return string("reserved keyword '") + TokenTraits::friendlyName(_token) + "'";
else if (TokenTraits::isElementaryTypeName(_token)) //for the sake of accuracy in reporting
{
ElementaryTypeNameToken elemTypeName = m_scanner->currentElementaryTypeNameToken();
return string("'") + elemTypeName.toString() + "'";
}
else
parserError(errorLoc, msg + "Recovered at next " + expectedToken);
m_inParserRecovery = false;
}
}
else if (m_inParserRecovery)
{
string expectedToken = ParserBase::tokenName(_value);
parserWarning("Recovered in " + _currentNodeName + " at " + expectedToken + ".");
m_inParserRecovery = false;
}
return string("'") + TokenTraits::friendlyName(_token) + "'";
};

fatalParserError(string("Expected ") + tokenName(_value) + string(" but got ") + tokenName(tok));
}
if (_advance)
m_scanner->next();
}
Expand All @@ -147,27 +98,12 @@ void ParserBase::decreaseRecursionDepth()
m_recursionDepth--;
}

void ParserBase::parserWarning(string const& _description)
{
m_errorReporter.warning(SourceLocation{position(), endPosition(), source()}, _description);
}

void ParserBase::parserError(SourceLocation const& _location, string const& _description)
{
m_errorReporter.parserError(_location, _description);
}

void ParserBase::parserError(string const& _description)
{
parserError(SourceLocation{position(), endPosition(), source()}, _description);
m_errorReporter.parserError(SourceLocation{position(), endPosition(), source()}, _description);
}

void ParserBase::fatalParserError(string const& _description)
{
fatalParserError(SourceLocation{position(), endPosition(), source()}, _description);
}

void ParserBase::fatalParserError(SourceLocation const& _location, string const& _description)
{
m_errorReporter.fatalParserError(_location, _description);
m_errorReporter.fatalParserError(SourceLocation{position(), endPosition(), source()}, _description);
}
28 changes: 2 additions & 26 deletions liblangutil/ParserBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,7 @@ class Scanner;
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) {}

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

Expand All @@ -69,17 +62,10 @@ 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 current token value is not _value, throw exception otherwise advance token.
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);
std::string currentLiteral() const;
Token advance();
///@}
Expand All @@ -91,26 +77,16 @@ class ParserBase
/// Creates a @ref ParserError and annotates it with the current position and the
/// given @a _description.
void parserError(std::string const& _description);
void parserError(SourceLocation const& _location, std::string const& _description);

/// Creates a @ref ParserWarning and annotates it with the current position and the
/// given @a _description.
void parserWarning(std::string const& _description);

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

std::shared_ptr<Scanner> m_scanner;
/// The reference to the list of errors and warning to add errors/warnings during parsing
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;
};

}
7 changes: 0 additions & 7 deletions liblangutil/Scanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,6 @@ void Scanner::reset()
next();
}

void Scanner::setPosition(size_t _offset)
{
m_char = m_source->setPosition(_offset);
scanToken();
next();
}

void Scanner::supportPeriodInIdentifier(bool _value)
{
m_supportPeriodInIdentifier = _value;
Expand Down
3 changes: 0 additions & 3 deletions liblangutil/Scanner.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,6 @@ class Scanner
/// @returns the next token and advances input
Token next();

/// Set scanner to a specific offset. This is used in error recovery.
void setPosition(size_t _offset);

///@{
///@name Information about the current token

Expand Down
2 changes: 1 addition & 1 deletion libsolidity/interface/CompilerStack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ bool CompilerStack::parse()
string const& path = sourcesToParse[i];
Source& source = m_sources[path];
source.scanner->reset();
source.ast = Parser(m_errorReporter, m_evmVersion, m_parserErrorRecovery).parse(source.scanner);
source.ast = Parser(m_errorReporter, m_evmVersion).parse(source.scanner);
if (!source.ast)
solAssert(!Error::containsOnlyWarnings(m_errorReporter.errors()), "Parser returned null but did not report error.");
else
Expand Down
9 changes: 0 additions & 9 deletions libsolidity/interface/CompilerStack.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,14 +132,6 @@ class CompilerStack: boost::noncopyable
/// Must be set before parsing.
void setOptimiserSettings(OptimiserSettings _settings);

/// Set whether or not parser error is desired.
/// When called without an argument it will revert to the default.
/// Must be set before parsing.
void setParserErrorRecovery(bool _wantErrorRecovery = false)
{
m_parserErrorRecovery = _wantErrorRecovery;
}

/// Set the EVM version used before running compile.
/// When called without an argument it will revert to the default version.
/// Must be set before parsing.
Expand Down Expand Up @@ -394,7 +386,6 @@ class CompilerStack: boost::noncopyable
langutil::ErrorList m_errorList;
langutil::ErrorReporter m_errorReporter;
bool m_metadataLiteralSources = false;
bool m_parserErrorRecovery = false;
State m_stackState = Empty;
bool m_release = VersionIsRelease;
};
Expand Down
Loading

0 comments on commit c68bc34

Please sign in to comment.