From 2fefe3b5497172a16094014b66e148b707bc7492 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Wed, 24 May 2017 22:55:29 +0100 Subject: Move Solidity specific methods from ParserBase to the Solidity Parser --- libsolidity/parsing/Parser.cpp | 56 ++++++++++++++++++++++++++++++++++++++ libsolidity/parsing/Parser.h | 4 +++ libsolidity/parsing/ParserBase.cpp | 56 -------------------------------------- libsolidity/parsing/ParserBase.h | 4 --- 4 files changed, 60 insertions(+), 60 deletions(-) (limited to 'libsolidity/parsing') diff --git a/libsolidity/parsing/Parser.cpp b/libsolidity/parsing/Parser.cpp index 72150a3e..470586cf 100644 --- a/libsolidity/parsing/Parser.cpp +++ b/libsolidity/parsing/Parser.cpp @@ -1437,5 +1437,61 @@ ASTPointer Parser::createEmptyParameterList() return nodeFactory.createNode(vector>()); } +Token::Value Parser::expectAssignmentOperator() +{ + Token::Value op = m_scanner->currentToken(); + if (!Token::isAssignmentOp(op)) + { + if (Token::isElementaryTypeName(op)) //for the sake of accuracy in reporting + { + ElementaryTypeNameToken elemTypeName = m_scanner->currentElementaryTypeNameToken(); + fatalParserError( + string("Expected assignment operator, got '") + + elemTypeName.toString() + + string("'") + ); + } + else + fatalParserError( + string("Expected assignment operator, got '") + + string(Token::name(m_scanner->currentToken())) + + string("'") + ); + } + m_scanner->next(); + return op; +} + +ASTPointer Parser::expectIdentifierToken() +{ + Token::Value id = m_scanner->currentToken(); + if (id != Token::Identifier) + { + if (Token::isElementaryTypeName(id)) //for the sake of accuracy in reporting + { + ElementaryTypeNameToken elemTypeName = m_scanner->currentElementaryTypeNameToken(); + fatalParserError( + string("Expected identifier, got '") + + elemTypeName.toString() + + string("'") + ); + } + else + fatalParserError( + string("Expected identifier, got '") + + string(Token::name(id)) + + string("'") + ); + } + return getLiteralAndAdvance(); +} + +ASTPointer Parser::getLiteralAndAdvance() +{ + ASTPointer identifier = make_shared(m_scanner->currentLiteral()); + m_scanner->next(); + return identifier; +} + } } diff --git a/libsolidity/parsing/Parser.h b/libsolidity/parsing/Parser.h index 282617ab..05e99566 100644 --- a/libsolidity/parsing/Parser.h +++ b/libsolidity/parsing/Parser.h @@ -154,6 +154,10 @@ private: std::vector> const& _path, std::vector, SourceLocation>> const& _indices ); + + Token::Value expectAssignmentOperator(); + ASTPointer expectIdentifierToken(); + ASTPointer getLiteralAndAdvance(); ///@} /// Creates an empty ParameterList at the current location (used if parameters can be omitted). diff --git a/libsolidity/parsing/ParserBase.cpp b/libsolidity/parsing/ParserBase.cpp index 87d47f4b..ac103bda 100644 --- a/libsolidity/parsing/ParserBase.cpp +++ b/libsolidity/parsing/ParserBase.cpp @@ -80,62 +80,6 @@ void ParserBase::expectToken(Token::Value _value) m_scanner->next(); } -Token::Value ParserBase::expectAssignmentOperator() -{ - Token::Value op = m_scanner->currentToken(); - if (!Token::isAssignmentOp(op)) - { - if (Token::isElementaryTypeName(op)) //for the sake of accuracy in reporting - { - ElementaryTypeNameToken elemTypeName = m_scanner->currentElementaryTypeNameToken(); - fatalParserError( - string("Expected assignment operator, got '") + - elemTypeName.toString() + - string("'") - ); - } - else - fatalParserError( - string("Expected assignment operator, got '") + - string(Token::name(m_scanner->currentToken())) + - string("'") - ); - } - m_scanner->next(); - return op; -} - -ASTPointer ParserBase::expectIdentifierToken() -{ - Token::Value id = m_scanner->currentToken(); - if (id != Token::Identifier) - { - if (Token::isElementaryTypeName(id)) //for the sake of accuracy in reporting - { - ElementaryTypeNameToken elemTypeName = m_scanner->currentElementaryTypeNameToken(); - fatalParserError( - string("Expected identifier, got '") + - elemTypeName.toString() + - string("'") - ); - } - else - fatalParserError( - string("Expected identifier, got '") + - string(Token::name(id)) + - string("'") - ); - } - return getLiteralAndAdvance(); -} - -ASTPointer ParserBase::getLiteralAndAdvance() -{ - ASTPointer identifier = make_shared(m_scanner->currentLiteral()); - m_scanner->next(); - return identifier; -} - void ParserBase::parserError(string const& _description) { auto err = make_shared(Error::Type::ParserError); diff --git a/libsolidity/parsing/ParserBase.h b/libsolidity/parsing/ParserBase.h index dfb7cab7..768b3bbf 100644 --- a/libsolidity/parsing/ParserBase.h +++ b/libsolidity/parsing/ParserBase.h @@ -25,7 +25,6 @@ #include #include #include -#include namespace dev { @@ -52,9 +51,6 @@ protected: ///@name Helper functions /// If current token value is not _value, throw exception otherwise advance token. void expectToken(Token::Value _value); - Token::Value expectAssignmentOperator(); - ASTPointer expectIdentifierToken(); - ASTPointer getLiteralAndAdvance(); ///@} /// Creates a @ref ParserError and annotates it with the current position and the -- cgit