aboutsummaryrefslogtreecommitdiffstats
path: root/libsolidity/parsing
diff options
context:
space:
mode:
authorErik Kundt <bitshift@posteo.org>2018-06-27 18:29:03 +0800
committerErik Kundt <bitshift@posteo.org>2018-07-18 20:29:01 +0800
commit182a0a95516e4f218524b929035e6a1bd5d2742c (patch)
treebcf6743a43070346a5193f1a4d9d12c3b5bd092c /libsolidity/parsing
parentb909df4573130e020c7f4dfb61c0571ba1bc02ab (diff)
downloaddexon-solidity-182a0a95516e4f218524b929035e6a1bd5d2742c.tar.gz
dexon-solidity-182a0a95516e4f218524b929035e6a1bd5d2742c.tar.zst
dexon-solidity-182a0a95516e4f218524b929035e6a1bd5d2742c.zip
Disallows old constructor syntax.
Diffstat (limited to 'libsolidity/parsing')
-rw-r--r--libsolidity/parsing/Parser.cpp30
-rw-r--r--libsolidity/parsing/Parser.h8
-rw-r--r--libsolidity/parsing/Token.h1
3 files changed, 17 insertions, 22 deletions
diff --git a/libsolidity/parsing/Parser.cpp b/libsolidity/parsing/Parser.cpp
index e2bd6fb4..0bee2a91 100644
--- a/libsolidity/parsing/Parser.cpp
+++ b/libsolidity/parsing/Parser.cpp
@@ -239,13 +239,10 @@ ASTPointer<ContractDefinition> Parser::parseContractDefinition(Token::Value _exp
Token::Value currentTokenValue = m_scanner->currentToken();
if (currentTokenValue == Token::RBrace)
break;
- else if (
- currentTokenValue == Token::Function ||
- (currentTokenValue == Token::Identifier && m_scanner->currentLiteral() == "constructor")
- )
+ else if (currentTokenValue == Token::Function || currentTokenValue == Token::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()));
+ subNodes.push_back(parseFunctionDefinitionOrFunctionTypeStateVariable());
else if (currentTokenValue == Token::Struct)
subNodes.push_back(parseStructDefinition());
else if (currentTokenValue == Token::Enum)
@@ -340,30 +337,31 @@ StateMutability Parser::parseStateMutability(Token::Value _token)
return stateMutability;
}
-Parser::FunctionHeaderParserResult Parser::parseFunctionHeader(
- bool _forceEmptyName,
- bool _allowModifiers,
- ASTString const* _contractName
-)
+Parser::FunctionHeaderParserResult Parser::parseFunctionHeader(bool _forceEmptyName, bool _allowModifiers)
{
RecursionGuard recursionGuard(*this);
FunctionHeaderParserResult result;
result.isConstructor = false;
- if (m_scanner->currentToken() == Token::Identifier && m_scanner->currentLiteral() == "constructor")
+ if (m_scanner->currentToken() == Token::Constructor)
result.isConstructor = true;
else if (m_scanner->currentToken() != Token::Function)
solAssert(false, "Function or constructor expected.");
m_scanner->next();
- if (result.isConstructor || _forceEmptyName || m_scanner->currentToken() == Token::LParen)
+ if (result.isConstructor)
result.name = make_shared<ASTString>();
+ else if (_forceEmptyName || m_scanner->currentToken() == Token::LParen)
+ result.name = make_shared<ASTString>();
+ else if (m_scanner->currentToken() == Token::Constructor)
+ fatalParserError(string(
+ "This function is named \"constructor\" but is not the constructor of the contract. "
+ "If you intend this to be a constructor, use \"constructor(...) { ... }\" without the \"function\" keyword to define it."
+ ));
else
result.name = expectIdentifierToken();
- if (!result.name->empty() && _contractName && *result.name == *_contractName)
- result.isConstructor = true;
VarDeclParserOptions options;
options.allowLocationSpecifier = true;
@@ -435,7 +433,7 @@ Parser::FunctionHeaderParserResult Parser::parseFunctionHeader(
return result;
}
-ASTPointer<ASTNode> Parser::parseFunctionDefinitionOrFunctionTypeStateVariable(ASTString const* _contractName)
+ASTPointer<ASTNode> Parser::parseFunctionDefinitionOrFunctionTypeStateVariable()
{
RecursionGuard recursionGuard(*this);
ASTNodeFactory nodeFactory(*this);
@@ -443,7 +441,7 @@ ASTPointer<ASTNode> Parser::parseFunctionDefinitionOrFunctionTypeStateVariable(A
if (m_scanner->currentCommentLiteral() != "")
docstring = make_shared<ASTString>(m_scanner->currentCommentLiteral());
- FunctionHeaderParserResult header = parseFunctionHeader(false, true, _contractName);
+ FunctionHeaderParserResult header = parseFunctionHeader(false, true);
if (
header.isConstructor ||
diff --git a/libsolidity/parsing/Parser.h b/libsolidity/parsing/Parser.h
index 08653364..c906771a 100644
--- a/libsolidity/parsing/Parser.h
+++ b/libsolidity/parsing/Parser.h
@@ -74,12 +74,8 @@ private:
ASTPointer<InheritanceSpecifier> parseInheritanceSpecifier();
Declaration::Visibility parseVisibilitySpecifier(Token::Value _token);
StateMutability parseStateMutability(Token::Value _token);
- FunctionHeaderParserResult parseFunctionHeader(
- bool _forceEmptyName,
- bool _allowModifiers,
- ASTString const* _contractName = nullptr
- );
- ASTPointer<ASTNode> parseFunctionDefinitionOrFunctionTypeStateVariable(ASTString const* _contractName);
+ FunctionHeaderParserResult parseFunctionHeader(bool _forceEmptyName, bool _allowModifiers);
+ ASTPointer<ASTNode> parseFunctionDefinitionOrFunctionTypeStateVariable();
ASTPointer<FunctionDefinition> parseFunctionDefinition(ASTString const* _contractName);
ASTPointer<StructDefinition> parseStructDefinition();
ASTPointer<EnumDefinition> parseEnumDefinition();
diff --git a/libsolidity/parsing/Token.h b/libsolidity/parsing/Token.h
index cb855cbe..7ce24e69 100644
--- a/libsolidity/parsing/Token.h
+++ b/libsolidity/parsing/Token.h
@@ -144,6 +144,7 @@ namespace solidity
K(Assembly, "assembly", 0) \
K(Break, "break", 0) \
K(Constant, "constant", 0) \
+ K(Constructor, "constructor", 0) \
K(Continue, "continue", 0) \
K(Contract, "contract", 0) \
K(Do, "do", 0) \