diff options
author | Alex Beregszaszi <alex@rtfs.hu> | 2018-12-12 23:45:17 +0800 |
---|---|---|
committer | Alex Beregszaszi <alex@rtfs.hu> | 2018-12-18 23:02:35 +0800 |
commit | c2ec6d71b4707dab9b7727347077904b7a90eaf2 (patch) | |
tree | e53763da22d68f1b97a5390f07c4d09c633baefa /libsolidity/parsing | |
parent | c60ec958abea4f63eea8783d67a5054ca04d0a64 (diff) | |
download | dexon-solidity-c2ec6d71b4707dab9b7727347077904b7a90eaf2.tar.gz dexon-solidity-c2ec6d71b4707dab9b7727347077904b7a90eaf2.tar.zst dexon-solidity-c2ec6d71b4707dab9b7727347077904b7a90eaf2.zip |
Add version pragma parsing to Parser
Diffstat (limited to 'libsolidity/parsing')
-rw-r--r-- | libsolidity/parsing/Parser.cpp | 25 | ||||
-rw-r--r-- | libsolidity/parsing/Parser.h | 1 |
2 files changed, 26 insertions, 0 deletions
diff --git a/libsolidity/parsing/Parser.cpp b/libsolidity/parsing/Parser.cpp index 9de2146e..bcb28988 100644 --- a/libsolidity/parsing/Parser.cpp +++ b/libsolidity/parsing/Parser.cpp @@ -22,6 +22,8 @@ #include <libsolidity/parsing/Parser.h> +#include <libsolidity/analysis/SemVerHandler.h> +#include <libsolidity/interface/Version.h> #include <libyul/AsmParser.h> #include <libyul/backends/evm/EVMDialect.h> #include <liblangutil/ErrorReporter.h> @@ -106,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); @@ -134,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); } diff --git a/libsolidity/parsing/Parser.h b/libsolidity/parsing/Parser.h index 15852096..bf02c626 100644 --- a/libsolidity/parsing/Parser.h +++ b/libsolidity/parsing/Parser.h @@ -70,6 +70,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(); |