aboutsummaryrefslogtreecommitdiffstats
path: root/Parser.cpp
diff options
context:
space:
mode:
authorChristian <c@ethdev.com>2015-01-21 18:16:18 +0800
committerChristian <c@ethdev.com>2015-01-26 17:23:39 +0800
commit19793dab093ae36b5f2b4d1cabfbf54bed3125b1 (patch)
tree94070079e892a1681fa82a0d4a9db315ce152573 /Parser.cpp
parent570e49c03ab9e09d538218839696fc6159b0a2f1 (diff)
downloaddexon-solidity-19793dab093ae36b5f2b4d1cabfbf54bed3125b1.tar.gz
dexon-solidity-19793dab093ae36b5f2b4d1cabfbf54bed3125b1.tar.zst
dexon-solidity-19793dab093ae36b5f2b4d1cabfbf54bed3125b1.zip
Function modifier parsing.
Diffstat (limited to 'Parser.cpp')
-rw-r--r--Parser.cpp44
1 files changed, 41 insertions, 3 deletions
diff --git a/Parser.cpp b/Parser.cpp
index fcabdb29..a72a5dba 100644
--- a/Parser.cpp
+++ b/Parser.cpp
@@ -121,6 +121,7 @@ ASTPointer<ContractDefinition> Parser::parseContractDefinition()
vector<ASTPointer<StructDefinition>> structs;
vector<ASTPointer<VariableDeclaration>> stateVariables;
vector<ASTPointer<FunctionDefinition>> functions;
+ vector<ASTPointer<ModifierDefinition>> modifiers;
if (m_scanner->getCurrentToken() == Token::IS)
do
{
@@ -152,13 +153,15 @@ ASTPointer<ContractDefinition> Parser::parseContractDefinition()
stateVariables.push_back(parseVariableDeclaration(allowVar));
expectToken(Token::SEMICOLON);
}
+ else if (currentToken == Token::MODIFIER)
+ modifiers.push_back(parseModifierDefinition());
else
- BOOST_THROW_EXCEPTION(createParserError("Function, variable or struct declaration expected."));
+ BOOST_THROW_EXCEPTION(createParserError("Function, variable, struct or modifier declaration expected."));
}
nodeFactory.markEndPosition();
expectToken(Token::RBRACE);
return nodeFactory.createNode<ContractDefinition>(name, docString, baseContracts, structs,
- stateVariables, functions);
+ stateVariables, functions, modifiers);
}
ASTPointer<InheritanceSpecifier> Parser::parseInheritanceSpecifier()
@@ -242,6 +245,33 @@ ASTPointer<VariableDeclaration> Parser::parseVariableDeclaration(bool _allowVar)
return nodeFactory.createNode<VariableDeclaration>(type, expectIdentifierToken());
}
+ASTPointer<ModifierDefinition> Parser::parseModifierDefinition()
+{
+ ScopeGuard resetModifierFlag([this]() { m_insideModifier = false; });
+ m_insideModifier = true;
+
+ ASTNodeFactory nodeFactory(*this);
+ ASTPointer<ASTString> docstring;
+ if (m_scanner->getCurrentCommentLiteral() != "")
+ docstring = make_shared<ASTString>(m_scanner->getCurrentCommentLiteral());
+
+ expectToken(Token::MODIFIER);
+ ASTPointer<ASTString> name(expectIdentifierToken());
+ ASTPointer<ParameterList> parameters;
+ if (m_scanner->getCurrentToken() == Token::LPAREN)
+ parameters = parseParameterList();
+ else
+ {
+ // create an empty parameter list at a zero-length location
+ ASTNodeFactory nodeFactory(*this);
+ nodeFactory.setLocationEmpty();
+ parameters = nodeFactory.createNode<ParameterList>(vector<ASTPointer<VariableDeclaration>>());
+ }
+ ASTPointer<Block> block = parseBlock();
+ nodeFactory.setEndPositionFromNode(block);
+ return nodeFactory.createNode<ModifierDefinition>(name, docstring, parameters, block);
+}
+
ASTPointer<TypeName> Parser::parseTypeName(bool _allowVar)
{
ASTPointer<TypeName> type;
@@ -354,8 +384,16 @@ ASTPointer<Statement> Parser::parseStatement()
nodeFactory.setEndPositionFromNode(expression);
}
statement = nodeFactory.createNode<Return>(expression);
+ break;
}
- break;
+ case Token::IDENTIFIER:
+ if (m_insideModifier && m_scanner->getCurrentLiteral() == "_")
+ {
+ statement = ASTNodeFactory(*this).createNode<PlaceholderStatement>();
+ m_scanner->next();
+ return statement;
+ }
+ // fall-through
default:
statement = parseVarDefOrExprStmt();
}