|
@ -148,6 +148,7 @@ ASTPointer<ContractDefinition> Parser::parseContractDefinition() |
|
|
{ |
|
|
{ |
|
|
VarDeclParserOptions options; |
|
|
VarDeclParserOptions options; |
|
|
options.isStateVariable = true; |
|
|
options.isStateVariable = true; |
|
|
|
|
|
options.allowInitialValue = true; |
|
|
stateVariables.push_back(parseVariableDeclaration(options)); |
|
|
stateVariables.push_back(parseVariableDeclaration(options)); |
|
|
expectToken(Token::Semicolon); |
|
|
expectToken(Token::Semicolon); |
|
|
} |
|
|
} |
|
@ -324,7 +325,17 @@ ASTPointer<VariableDeclaration> Parser::parseVariableDeclaration(VarDeclParserOp |
|
|
} |
|
|
} |
|
|
else |
|
|
else |
|
|
identifier = expectIdentifierToken(); |
|
|
identifier = expectIdentifierToken(); |
|
|
return nodeFactory.createNode<VariableDeclaration>(type, identifier, |
|
|
ASTPointer<Expression> value; |
|
|
|
|
|
if (_options.allowInitialValue) |
|
|
|
|
|
{ |
|
|
|
|
|
if (m_scanner->getCurrentToken() == Token::Assign) |
|
|
|
|
|
{ |
|
|
|
|
|
m_scanner->next(); |
|
|
|
|
|
value = parseExpression(); |
|
|
|
|
|
nodeFactory.setEndPositionFromNode(value); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
return nodeFactory.createNode<VariableDeclaration>(type, identifier, value, |
|
|
visibility, _options.isStateVariable, |
|
|
visibility, _options.isStateVariable, |
|
|
isIndexed); |
|
|
isIndexed); |
|
|
} |
|
|
} |
|
@ -519,7 +530,7 @@ ASTPointer<Statement> Parser::parseStatement() |
|
|
} |
|
|
} |
|
|
// fall-through
|
|
|
// fall-through
|
|
|
default: |
|
|
default: |
|
|
statement = parseVarDefOrExprStmt(); |
|
|
statement = parseVarDeclOrExprStmt(); |
|
|
} |
|
|
} |
|
|
expectToken(Token::Semicolon); |
|
|
expectToken(Token::Semicolon); |
|
|
return statement; |
|
|
return statement; |
|
@ -568,7 +579,7 @@ ASTPointer<ForStatement> Parser::parseForStatement() |
|
|
|
|
|
|
|
|
// LTODO: Maybe here have some predicate like peekExpression() instead of checking for semicolon and RParen?
|
|
|
// LTODO: Maybe here have some predicate like peekExpression() instead of checking for semicolon and RParen?
|
|
|
if (m_scanner->getCurrentToken() != Token::Semicolon) |
|
|
if (m_scanner->getCurrentToken() != Token::Semicolon) |
|
|
initExpression = parseVarDefOrExprStmt(); |
|
|
initExpression = parseVarDeclOrExprStmt(); |
|
|
expectToken(Token::Semicolon); |
|
|
expectToken(Token::Semicolon); |
|
|
|
|
|
|
|
|
if (m_scanner->getCurrentToken() != Token::Semicolon) |
|
|
if (m_scanner->getCurrentToken() != Token::Semicolon) |
|
@ -587,30 +598,22 @@ ASTPointer<ForStatement> Parser::parseForStatement() |
|
|
body); |
|
|
body); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
ASTPointer<Statement> Parser::parseVarDefOrExprStmt() |
|
|
ASTPointer<Statement> Parser::parseVarDeclOrExprStmt() |
|
|
{ |
|
|
{ |
|
|
if (peekVariableDefinition()) |
|
|
if (peekVariableDeclarationStatement()) |
|
|
return parseVariableDefinition(); |
|
|
return parseVariableDeclarationStatement(); |
|
|
else |
|
|
else |
|
|
return parseExpressionStatement(); |
|
|
return parseExpressionStatement(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
ASTPointer<VariableDefinition> Parser::parseVariableDefinition() |
|
|
ASTPointer<VariableDeclarationStatement> Parser::parseVariableDeclarationStatement() |
|
|
{ |
|
|
{ |
|
|
ASTNodeFactory nodeFactory(*this); |
|
|
ASTNodeFactory nodeFactory(*this); |
|
|
VarDeclParserOptions options; |
|
|
VarDeclParserOptions options; |
|
|
options.allowVar = true; |
|
|
options.allowVar = true; |
|
|
|
|
|
options.allowInitialValue = true; |
|
|
ASTPointer<VariableDeclaration> variable = parseVariableDeclaration(options); |
|
|
ASTPointer<VariableDeclaration> variable = parseVariableDeclaration(options); |
|
|
ASTPointer<Expression> value; |
|
|
return nodeFactory.createNode<VariableDeclarationStatement>(variable); |
|
|
if (m_scanner->getCurrentToken() == Token::Assign) |
|
|
|
|
|
{ |
|
|
|
|
|
m_scanner->next(); |
|
|
|
|
|
value = parseExpression(); |
|
|
|
|
|
nodeFactory.setEndPositionFromNode(value); |
|
|
|
|
|
} |
|
|
|
|
|
else |
|
|
|
|
|
nodeFactory.setEndPositionFromNode(variable); |
|
|
|
|
|
return nodeFactory.createNode<VariableDefinition>(variable, value); |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
ASTPointer<ExpressionStatement> Parser::parseExpressionStatement() |
|
|
ASTPointer<ExpressionStatement> Parser::parseExpressionStatement() |
|
@ -822,11 +825,11 @@ pair<vector<ASTPointer<Expression>>, vector<ASTPointer<ASTString>>> Parser::pars |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool Parser::peekVariableDefinition() |
|
|
bool Parser::peekVariableDeclarationStatement() |
|
|
{ |
|
|
{ |
|
|
// distinguish between variable definition (and potentially assignment) and expression statement
|
|
|
// distinguish between variable declaration (and potentially assignment) and expression statement
|
|
|
// (which include assignments to other expressions and pre-declared variables)
|
|
|
// (which include assignments to other expressions and pre-declared variables)
|
|
|
// We have a variable definition if we get a keyword that specifies a type name, or
|
|
|
// We have a variable declaration if we get a keyword that specifies a type name, or
|
|
|
// in the case of a user-defined type, we have two identifiers following each other.
|
|
|
// in the case of a user-defined type, we have two identifiers following each other.
|
|
|
return (m_scanner->getCurrentToken() == Token::Mapping || |
|
|
return (m_scanner->getCurrentToken() == Token::Mapping || |
|
|
m_scanner->getCurrentToken() == Token::Var || |
|
|
m_scanner->getCurrentToken() == Token::Var || |
|
|