diff options
author | chriseth <chris@ethereum.org> | 2018-12-20 01:06:13 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-12-20 01:06:13 +0800 |
commit | 1df8f40cd2fd7b47698d847907b8ca7b47eb488d (patch) | |
tree | 5ed5816fe2d1a8a207e750d39884aca7957c8289 /libsolidity/parsing | |
parent | c8a2cb62832afb2dc09ccee6fd42c1516dfdb981 (diff) | |
parent | ddf54b21d1d002903624f61173ab4af197f50053 (diff) | |
download | dexon-solidity-1df8f40cd2fd7b47698d847907b8ca7b47eb488d.tar dexon-solidity-1df8f40cd2fd7b47698d847907b8ca7b47eb488d.tar.gz dexon-solidity-1df8f40cd2fd7b47698d847907b8ca7b47eb488d.tar.bz2 dexon-solidity-1df8f40cd2fd7b47698d847907b8ca7b47eb488d.tar.lz dexon-solidity-1df8f40cd2fd7b47698d847907b8ca7b47eb488d.tar.xz dexon-solidity-1df8f40cd2fd7b47698d847907b8ca7b47eb488d.tar.zst dexon-solidity-1df8f40cd2fd7b47698d847907b8ca7b47eb488d.zip |
Merge pull request #5697 from ethereum/develop
Merge develop into release for 0.5.2
Diffstat (limited to 'libsolidity/parsing')
-rw-r--r-- | libsolidity/parsing/DocStringParser.cpp | 20 | ||||
-rw-r--r-- | libsolidity/parsing/DocStringParser.h | 2 | ||||
-rw-r--r-- | libsolidity/parsing/Parser.cpp | 43 | ||||
-rw-r--r-- | libsolidity/parsing/Parser.h | 8 |
4 files changed, 60 insertions, 13 deletions
diff --git a/libsolidity/parsing/DocStringParser.cpp b/libsolidity/parsing/DocStringParser.cpp index d8927fea..d1d45150 100644 --- a/libsolidity/parsing/DocStringParser.cpp +++ b/libsolidity/parsing/DocStringParser.cpp @@ -1,17 +1,33 @@ +/* + This file is part of solidity. + + solidity is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + solidity is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with solidity. If not, see <http://www.gnu.org/licenses/>. +*/ #include <libsolidity/parsing/DocStringParser.h> + #include <liblangutil/ErrorReporter.h> #include <liblangutil/Exceptions.h> -#include <boost/range/irange.hpp> #include <boost/range/algorithm.hpp> +#include <boost/range/irange.hpp> using namespace std; using namespace dev; using namespace langutil; using namespace dev::solidity; - namespace { diff --git a/libsolidity/parsing/DocStringParser.h b/libsolidity/parsing/DocStringParser.h index c83b416d..671a2f34 100644 --- a/libsolidity/parsing/DocStringParser.h +++ b/libsolidity/parsing/DocStringParser.h @@ -22,8 +22,8 @@ #pragma once -#include <string> #include <libsolidity/ast/ASTAnnotations.h> +#include <string> namespace langutil { diff --git a/libsolidity/parsing/Parser.cpp b/libsolidity/parsing/Parser.cpp index 6cab7be3..8a6bc343 100644 --- a/libsolidity/parsing/Parser.cpp +++ b/libsolidity/parsing/Parser.cpp @@ -20,13 +20,17 @@ * Solidity parser. */ -#include <cctype> -#include <vector> #include <libsolidity/parsing/Parser.h> + +#include <libsolidity/analysis/SemVerHandler.h> +#include <libsolidity/interface/Version.h> #include <libyul/AsmParser.h> -#include <liblangutil/SourceLocation.h> +#include <libyul/backends/evm/EVMDialect.h> #include <liblangutil/ErrorReporter.h> #include <liblangutil/Scanner.h> +#include <liblangutil/SourceLocation.h> +#include <cctype> +#include <vector> using namespace std; using namespace langutil; @@ -42,9 +46,9 @@ class Parser::ASTNodeFactory { public: explicit ASTNodeFactory(Parser const& _parser): - m_parser(_parser), m_location(_parser.position(), -1, _parser.source()) {} + 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()) {} + m_parser(_parser), m_location{_childNode->location()} {} void markEndPosition() { m_location.end = m_parser.endPosition(); } void setLocation(SourceLocation const& _location) { m_location = _location; } @@ -104,6 +108,20 @@ ASTPointer<SourceUnit> Parser::parse(shared_ptr<Scanner> const& _scanner) } } +void Parser::parsePragmaVersion(vector<Token> const& tokens, vector<string> const& literals) +{ + SemVerMatchExpressionParser parser(tokens, literals); + auto matchExpression = parser.parse(); + static SemVerVersion const currentVersion{string(VersionString)}; + // FIXME: only match for major version incompatibility + if (!matchExpression.matches(currentVersion)) + fatalParserError( + "Source file requires different compiler version (current compiler is " + + string(VersionString) + " - note that nightly builds are considered to be " + "strictly less than the released version" + ); +} + ASTPointer<PragmaDirective> Parser::parsePragmaDirective() { RecursionGuard recursionGuard(*this); @@ -132,6 +150,15 @@ ASTPointer<PragmaDirective> Parser::parsePragmaDirective() while (m_scanner->currentToken() != Token::Semicolon && m_scanner->currentToken() != Token::EOS); nodeFactory.markEndPosition(); expectToken(Token::Semicolon); + + if (literals.size() >= 2 && literals[0] == "solidity") + { + parsePragmaVersion( + vector<Token>(tokens.begin() + 1, tokens.end()), + vector<string>(literals.begin() + 1, literals.end()) + ); + } + return nodeFactory.createNode<PragmaDirective>(tokens, literals); } @@ -170,7 +197,7 @@ ASTPointer<ImportDirective> Parser::parseImportDirective() expectToken(Token::As); alias = expectIdentifierToken(); } - symbolAliases.push_back(make_pair(move(id), move(alias))); + symbolAliases.emplace_back(move(id), move(alias)); if (m_scanner->currentToken() != Token::Comma) break; m_scanner->next(); @@ -1012,7 +1039,7 @@ ASTPointer<InlineAssembly> Parser::parseInlineAssembly(ASTPointer<ASTString> con m_scanner->next(); } - yul::Parser asmParser(m_errorReporter); + yul::Parser asmParser(m_errorReporter, yul::EVMDialect::looseAssemblyForEVM()); shared_ptr<yul::Block> block = asmParser.parse(m_scanner, true); nodeFactory.markEndPosition(); return nodeFactory.createNode<InlineAssembly>(_docString, block); @@ -1690,7 +1717,7 @@ Parser::IndexAccessedPath Parser::parseIndexAccessedPath() index = parseExpression(); SourceLocation indexLocation = iap.path.front()->location(); indexLocation.end = endPosition(); - iap.indices.push_back(make_pair(index, indexLocation)); + iap.indices.emplace_back(index, indexLocation); expectToken(Token::RBrack); } diff --git a/libsolidity/parsing/Parser.h b/libsolidity/parsing/Parser.h index 15852096..b8d0e9a8 100644 --- a/libsolidity/parsing/Parser.h +++ b/libsolidity/parsing/Parser.h @@ -47,7 +47,10 @@ private: struct VarDeclParserOptions { + // This is actually not needed, but due to a defect in the C++ standard, we have to. + // https://stackoverflow.com/questions/17430377 VarDeclParserOptions() {} + bool allowVar = false; bool isStateVariable = false; bool allowIndexed = false; @@ -70,6 +73,7 @@ private: ///@{ ///@name Parsing functions for the AST nodes + void parsePragmaVersion(std::vector<Token> const& tokens, std::vector<std::string> const& literals); ASTPointer<PragmaDirective> parsePragmaDirective(); ASTPointer<ImportDirective> parseImportDirective(); ContractDefinition::ContractKind parseContractKind(); @@ -84,7 +88,7 @@ private: ASTPointer<EnumDefinition> parseEnumDefinition(); ASTPointer<EnumValue> parseEnumValue(); ASTPointer<VariableDeclaration> parseVariableDeclaration( - VarDeclParserOptions const& _options = VarDeclParserOptions(), + VarDeclParserOptions const& _options = {}, ASTPointer<TypeName> const& _lookAheadArrayType = ASTPointer<TypeName>() ); ASTPointer<ModifierDefinition> parseModifierDefinition(); @@ -98,7 +102,7 @@ private: ASTPointer<FunctionTypeName> parseFunctionType(); ASTPointer<Mapping> parseMapping(); ASTPointer<ParameterList> parseParameterList( - VarDeclParserOptions const& _options, + VarDeclParserOptions const& _options = {}, bool _allowEmpty = true ); ASTPointer<Block> parseBlock(ASTPointer<ASTString> const& _docString = {}); |