aboutsummaryrefslogtreecommitdiffstats
path: root/libsolidity/parsing/Parser.cpp
diff options
context:
space:
mode:
authorDaniel Kirchner <daniel@ekpyron.org>2018-03-02 01:39:01 +0800
committerAlex Beregszaszi <alex@rtfs.hu>2018-04-04 00:21:55 +0800
commitd664a599e68291166c47fcece464cb8d0af31df8 (patch)
tree26668133eed7076b9d5a94d2a1f6ba982f79250e /libsolidity/parsing/Parser.cpp
parent0edce4b570c157927933697b30f0f94cbdf173b2 (diff)
downloaddexon-solidity-d664a599e68291166c47fcece464cb8d0af31df8.tar
dexon-solidity-d664a599e68291166c47fcece464cb8d0af31df8.tar.gz
dexon-solidity-d664a599e68291166c47fcece464cb8d0af31df8.tar.bz2
dexon-solidity-d664a599e68291166c47fcece464cb8d0af31df8.tar.lz
dexon-solidity-d664a599e68291166c47fcece464cb8d0af31df8.tar.xz
dexon-solidity-d664a599e68291166c47fcece464cb8d0af31df8.tar.zst
dexon-solidity-d664a599e68291166c47fcece464cb8d0af31df8.zip
Constructors are defined using the ``constructor`` keyword.
Diffstat (limited to 'libsolidity/parsing/Parser.cpp')
-rw-r--r--libsolidity/parsing/Parser.cpp26
1 files changed, 20 insertions, 6 deletions
diff --git a/libsolidity/parsing/Parser.cpp b/libsolidity/parsing/Parser.cpp
index 8c97f55f..e5cc69d8 100644
--- a/libsolidity/parsing/Parser.cpp
+++ b/libsolidity/parsing/Parser.cpp
@@ -238,7 +238,10 @@ ASTPointer<ContractDefinition> Parser::parseContractDefinition(Token::Value _exp
Token::Value currentTokenValue = m_scanner->currentToken();
if (currentTokenValue == Token::RBrace)
break;
- else if (currentTokenValue == Token::Function)
+ else if (
+ currentTokenValue == Token::Function ||
+ (currentTokenValue == Token::Identifier && m_scanner->currentLiteral() == "constructor")
+ )
// This can be a function or a state variable of function type (especially
// complicated to distinguish fallback function from function type state variable)
subNodes.push_back(parseFunctionDefinitionOrFunctionTypeStateVariable(name.get()));
@@ -333,9 +336,19 @@ Parser::FunctionHeaderParserResult Parser::parseFunctionHeader(bool _forceEmptyN
{
RecursionGuard recursionGuard(*this);
FunctionHeaderParserResult result;
- expectToken(Token::Function);
- if (_forceEmptyName || m_scanner->currentToken() == Token::LParen)
- result.name = make_shared<ASTString>(); // anonymous function
+
+ if (m_scanner->currentToken() == Token::Function)
+ // In case of old style constructors, i.e. functions with the same name as the contract,
+ // this is set to true later in parseFunctionDefinitionOrFunctionTypeStateVariable.
+ result.isConstructor = false;
+ else if (m_scanner->currentToken() == Token::Identifier && m_scanner->currentLiteral() == "constructor")
+ result.isConstructor = true;
+ else
+ solAssert(false, "Function or constructor expected.");
+ m_scanner->next();
+
+ if (result.isConstructor || _forceEmptyName || m_scanner->currentToken() == Token::LParen)
+ result.name = make_shared<ASTString>();
else
result.name = expectIdentifierToken();
VarDeclParserOptions options;
@@ -426,12 +439,13 @@ ASTPointer<ASTNode> Parser::parseFunctionDefinitionOrFunctionTypeStateVariable(A
}
else
m_scanner->next(); // just consume the ';'
- bool const c_isConstructor = (_contractName && *header.name == *_contractName);
+ if (_contractName && *header.name == *_contractName)
+ header.isConstructor = true;
return nodeFactory.createNode<FunctionDefinition>(
header.name,
header.visibility,
header.stateMutability,
- c_isConstructor,
+ header.isConstructor,
docstring,
header.parameters,
header.modifiers,