aboutsummaryrefslogtreecommitdiffstats
path: root/libsolidity
diff options
context:
space:
mode:
Diffstat (limited to 'libsolidity')
-rw-r--r--libsolidity/analysis/TypeChecker.cpp40
-rw-r--r--libsolidity/ast/AST.h4
-rw-r--r--libsolidity/ast/ASTJsonConverter.cpp17
-rw-r--r--libsolidity/ast/Types.cpp95
-rw-r--r--libsolidity/ast/Types.h26
-rw-r--r--libsolidity/codegen/CompilerUtils.cpp8
-rw-r--r--libsolidity/codegen/ContractCompiler.cpp14
-rw-r--r--libsolidity/codegen/ExpressionCompiler.cpp13
-rw-r--r--libsolidity/grammar.txt9
-rw-r--r--libsolidity/interface/InterfaceHandler.cpp3
-rw-r--r--libsolidity/parsing/Parser.cpp9
-rw-r--r--libsolidity/parsing/ParserBase.cpp12
-rw-r--r--libsolidity/parsing/Token.h5
13 files changed, 197 insertions, 58 deletions
diff --git a/libsolidity/analysis/TypeChecker.cpp b/libsolidity/analysis/TypeChecker.cpp
index bc03da01..d9c54f75 100644
--- a/libsolidity/analysis/TypeChecker.cpp
+++ b/libsolidity/analysis/TypeChecker.cpp
@@ -75,8 +75,14 @@ bool TypeChecker::visit(ContractDefinition const& _contract)
checkContractAbstractConstructors(_contract);
FunctionDefinition const* function = _contract.constructor();
- if (function && !function->returnParameters().empty())
- typeError(function->returnParameterList()->location(), "Non-empty \"returns\" directive for constructor.");
+ if (function) {
+ if (!function->returnParameters().empty())
+ typeError(function->returnParameterList()->location(), "Non-empty \"returns\" directive for constructor.");
+ if (function->isDeclaredConst())
+ typeError(function->location(), "Constructor cannot be defined as constant.");
+ if (function->visibility() != FunctionDefinition::Visibility::Public && function->visibility() != FunctionDefinition::Visibility::Internal)
+ typeError(function->location(), "Constructor must be public or internal.");
+ }
FunctionDefinition const* fallbackFunction = nullptr;
for (FunctionDefinition const* function: _contract.definedFunctions())
@@ -94,6 +100,8 @@ bool TypeChecker::visit(ContractDefinition const& _contract)
fallbackFunction = function;
if (_contract.isLibrary())
typeError(fallbackFunction->location(), "Libraries cannot have fallback functions.");
+ if (fallbackFunction->isDeclaredConst())
+ typeError(fallbackFunction->location(), "Fallback function cannot be declared constant.");
if (!fallbackFunction->parameters().empty())
typeError(fallbackFunction->parameterList().location(), "Fallback function cannot take parameters.");
if (!fallbackFunction->returnParameters().empty())
@@ -272,6 +280,7 @@ void TypeChecker::checkContractIllegalOverrides(ContractDefinition const& _contr
if (
overriding->visibility() != function->visibility() ||
overriding->isDeclaredConst() != function->isDeclaredConst() ||
+ overriding->isPayable() != function->isPayable() ||
overridingType != functionType
)
typeError(overriding->location(), "Override changes extended function signature.");
@@ -348,7 +357,7 @@ void TypeChecker::endVisit(InheritanceSpecifier const& _inheritance)
typeError(_inheritance.location(), "Libraries cannot be inherited from.");
auto const& arguments = _inheritance.arguments();
- TypePointers parameterTypes = ContractType(*base).constructorType()->parameterTypes();
+ TypePointers parameterTypes = ContractType(*base).newExpressionType()->parameterTypes();
if (!arguments.empty() && parameterTypes.size() != arguments.size())
{
typeError(
@@ -416,6 +425,15 @@ bool TypeChecker::visit(StructDefinition const& _struct)
bool TypeChecker::visit(FunctionDefinition const& _function)
{
bool isLibraryFunction = dynamic_cast<ContractDefinition const&>(*_function.scope()).isLibrary();
+ if (_function.isPayable())
+ {
+ if (isLibraryFunction)
+ typeError(_function.location(), "Library functions cannot be payable.");
+ if (!_function.isConstructor() && !_function.name().empty() && !_function.isPartOfExternalInterface())
+ typeError(_function.location(), "Internal functions cannot be payable.");
+ if (_function.isDeclaredConst())
+ typeError(_function.location(), "Functions cannot be constant and payable at the same time.");
+ }
for (ASTPointer<VariableDeclaration> const& var: _function.parameters() + _function.returnParameters())
{
if (!type(*var)->canLiveOutsideStorage())
@@ -1256,15 +1274,7 @@ void TypeChecker::endVisit(NewExpression const& _newExpression)
"Circular reference for contract creation (cannot create instance of derived or same contract)."
);
- auto contractType = make_shared<ContractType>(*contract);
- TypePointers parameterTypes = contractType->constructorType()->parameterTypes();
- _newExpression.annotation().type = make_shared<FunctionType>(
- parameterTypes,
- TypePointers{contractType},
- strings(),
- strings(),
- FunctionType::Location::Creation
- );
+ _newExpression.annotation().type = FunctionType::newExpressionType(*contract);
}
else if (type->category() == Type::Category::Array)
{
@@ -1328,14 +1338,16 @@ bool TypeChecker::visit(MemberAccess const& _memberAccess)
fatalTypeError(
_memberAccess.location(),
"Member \"" + memberName + "\" not found or not visible "
- "after argument-dependent lookup in " + exprType->toString()
+ "after argument-dependent lookup in " + exprType->toString() +
+ (memberName == "value" ? " - did you forget the \"payable\" modifier?" : "")
);
}
else if (possibleMembers.size() > 1)
fatalTypeError(
_memberAccess.location(),
"Member \"" + memberName + "\" not unique "
- "after argument-dependent lookup in " + exprType->toString()
+ "after argument-dependent lookup in " + exprType->toString() +
+ (memberName == "value" ? " - did you forget the \"payable\" modifier?" : "")
);
auto& annotation = _memberAccess.annotation();
diff --git a/libsolidity/ast/AST.h b/libsolidity/ast/AST.h
index 761d85fe..8fd1584d 100644
--- a/libsolidity/ast/AST.h
+++ b/libsolidity/ast/AST.h
@@ -540,6 +540,7 @@ public:
bool _isDeclaredConst,
std::vector<ASTPointer<ModifierInvocation>> const& _modifiers,
ASTPointer<ParameterList> const& _returnParameters,
+ bool _isPayable,
ASTPointer<Block> const& _body
):
CallableDeclaration(_location, _name, _visibility, _parameters, _returnParameters),
@@ -547,6 +548,7 @@ public:
ImplementationOptional(_body != nullptr),
m_isConstructor(_isConstructor),
m_isDeclaredConst(_isDeclaredConst),
+ m_isPayable(_isPayable),
m_functionModifiers(_modifiers),
m_body(_body)
{}
@@ -556,6 +558,7 @@ public:
bool isConstructor() const { return m_isConstructor; }
bool isDeclaredConst() const { return m_isDeclaredConst; }
+ bool isPayable() const { return m_isPayable; }
std::vector<ASTPointer<ModifierInvocation>> const& modifiers() const { return m_functionModifiers; }
std::vector<ASTPointer<VariableDeclaration>> const& returnParameters() const { return m_returnParameters->parameters(); }
Block const& body() const { return *m_body; }
@@ -578,6 +581,7 @@ public:
private:
bool m_isConstructor;
bool m_isDeclaredConst;
+ bool m_isPayable;
std::vector<ASTPointer<ModifierInvocation>> m_functionModifiers;
ASTPointer<Block> m_body;
};
diff --git a/libsolidity/ast/ASTJsonConverter.cpp b/libsolidity/ast/ASTJsonConverter.cpp
index 49ee6d34..0ea5e093 100644
--- a/libsolidity/ast/ASTJsonConverter.cpp
+++ b/libsolidity/ast/ASTJsonConverter.cpp
@@ -22,6 +22,7 @@
#include <libsolidity/ast/ASTJsonConverter.h>
#include <boost/algorithm/string/join.hpp>
+#include <libdevcore/UTF8.h>
#include <libsolidity/ast/AST.h>
using namespace std;
@@ -397,9 +398,21 @@ bool ASTJsonConverter::visit(ElementaryTypeNameExpression const& _node)
bool ASTJsonConverter::visit(Literal const& _node)
{
char const* tokenString = Token::toString(_node.token());
+ size_t invalidPos = 0;
+ Json::Value value{_node.value()};
+ if (!dev::validate(_node.value(), invalidPos))
+ value = Json::nullValue;
+ Token::Value subdenomination = Token::Value(_node.subDenomination());
addJsonNode(_node, "Literal", {
- make_pair("string", tokenString ? tokenString : Json::Value()),
- make_pair("value", _node.value()),
+ make_pair("token", tokenString ? tokenString : Json::Value()),
+ make_pair("value", value),
+ make_pair("hexvalue", toHex(_node.value())),
+ make_pair(
+ "subdenomination",
+ subdenomination == Token::Illegal ?
+ Json::nullValue :
+ Json::Value{Token::toString(subdenomination)}
+ ),
make_pair("type", type(_node))
});
return true;
diff --git a/libsolidity/ast/Types.cpp b/libsolidity/ast/Types.cpp
index d86a2caf..4b5f12ce 100644
--- a/libsolidity/ast/Types.cpp
+++ b/libsolidity/ast/Types.cpp
@@ -362,8 +362,8 @@ MemberList::MemberMap IntegerType::nativeMembers(ContractDefinition const*) cons
if (isAddress())
return {
{"balance", make_shared<IntegerType >(256)},
- {"call", make_shared<FunctionType>(strings(), strings{"bool"}, FunctionType::Location::Bare, true)},
- {"callcode", make_shared<FunctionType>(strings(), strings{"bool"}, FunctionType::Location::BareCallCode, true)},
+ {"call", make_shared<FunctionType>(strings(), strings{"bool"}, FunctionType::Location::Bare, true, false, true)},
+ {"callcode", make_shared<FunctionType>(strings(), strings{"bool"}, FunctionType::Location::BareCallCode, true, false, true)},
{"delegatecall", make_shared<FunctionType>(strings(), strings{"bool"}, FunctionType::Location::BareDelegateCall, true)},
{"send", make_shared<FunctionType>(strings{"uint"}, strings{"bool"}, FunctionType::Location::Send)}
};
@@ -1329,16 +1329,10 @@ MemberList::MemberMap ContractType::nativeMembers(ContractDefinition const*) con
return members;
}
-shared_ptr<FunctionType const> const& ContractType::constructorType() const
+shared_ptr<FunctionType const> const& ContractType::newExpressionType() const
{
if (!m_constructorType)
- {
- FunctionDefinition const* constructor = m_contract.constructor();
- if (constructor)
- m_constructorType = make_shared<FunctionType>(*constructor);
- else
- m_constructorType = make_shared<FunctionType>(TypePointers(), TypePointers());
- }
+ m_constructorType = FunctionType::newExpressionType(m_contract);
return m_constructorType;
}
@@ -1653,6 +1647,7 @@ TypePointer TupleType::closestTemporaryType(TypePointer const& _targetType) cons
FunctionType::FunctionType(FunctionDefinition const& _function, bool _isInternal):
m_location(_isInternal ? Location::Internal : Location::External),
m_isConstant(_function.isDeclaredConst()),
+ m_isPayable(_function.isPayable()),
m_declaration(&_function)
{
TypePointers params;
@@ -1737,7 +1732,7 @@ FunctionType::FunctionType(VariableDeclaration const& _varDecl):
swap(retParamNames, m_returnParameterNames);
}
-FunctionType::FunctionType(const EventDefinition& _event):
+FunctionType::FunctionType(EventDefinition const& _event):
m_location(Location::Event), m_isConstant(true), m_declaration(&_event)
{
TypePointers params;
@@ -1753,6 +1748,35 @@ FunctionType::FunctionType(const EventDefinition& _event):
swap(paramNames, m_parameterNames);
}
+FunctionTypePointer FunctionType::newExpressionType(ContractDefinition const& _contract)
+{
+ FunctionDefinition const* constructor = _contract.constructor();
+ TypePointers parameters;
+ strings parameterNames;
+ bool payable = false;
+
+ if (constructor)
+ {
+ for (ASTPointer<VariableDeclaration> const& var: constructor->parameters())
+ {
+ parameterNames.push_back(var->name());
+ parameters.push_back(var->annotation().type);
+ }
+ payable = constructor->isPayable();
+ }
+ return make_shared<FunctionType>(
+ parameters,
+ TypePointers{make_shared<ContractType>(_contract)},
+ parameterNames,
+ strings{""},
+ Location::Creation,
+ false,
+ nullptr,
+ false,
+ payable
+ );
+}
+
vector<string> FunctionType::parameterNames() const
{
if (!bound())
@@ -1871,7 +1895,12 @@ FunctionTypePointer FunctionType::interfaceFunctionType() const
if (variable && retParamTypes.empty())
return FunctionTypePointer();
- return make_shared<FunctionType>(paramTypes, retParamTypes, m_parameterNames, m_returnParameterNames, m_location, m_arbitraryParameters);
+ return make_shared<FunctionType>(
+ paramTypes, retParamTypes,
+ m_parameterNames, m_returnParameterNames,
+ m_location, m_arbitraryParameters,
+ m_declaration, m_isConstant, m_isPayable
+ );
}
MemberList::MemberMap FunctionType::nativeMembers(ContractDefinition const*) const
@@ -1889,20 +1918,25 @@ MemberList::MemberMap FunctionType::nativeMembers(ContractDefinition const*) con
{
MemberList::MemberMap members;
if (m_location != Location::BareDelegateCall && m_location != Location::DelegateCall)
- members.push_back(MemberList::Member(
- "value",
- make_shared<FunctionType>(
- parseElementaryTypeVector({"uint"}),
- TypePointers{copyAndSetGasOrValue(false, true)},
- strings(),
- strings(),
- Location::SetValue,
- false,
- nullptr,
- m_gasSet,
- m_valueSet
- )
- ));
+ {
+ if (m_isPayable)
+ members.push_back(MemberList::Member(
+ "value",
+ make_shared<FunctionType>(
+ parseElementaryTypeVector({"uint"}),
+ TypePointers{copyAndSetGasOrValue(false, true)},
+ strings(),
+ strings(),
+ Location::SetValue,
+ false,
+ nullptr,
+ false,
+ false,
+ m_gasSet,
+ m_valueSet
+ )
+ ));
+ }
if (m_location != Location::Creation)
members.push_back(MemberList::Member(
"gas",
@@ -1914,6 +1948,8 @@ MemberList::MemberMap FunctionType::nativeMembers(ContractDefinition const*) con
Location::SetGas,
false,
nullptr,
+ false,
+ false,
m_gasSet,
m_valueSet
)
@@ -2019,6 +2055,8 @@ TypePointer FunctionType::copyAndSetGasOrValue(bool _setGas, bool _setValue) con
m_location,
m_arbitraryParameters,
m_declaration,
+ m_isConstant,
+ m_isPayable,
m_gasSet || _setGas,
m_valueSet || _setValue,
m_bound
@@ -2064,6 +2102,8 @@ FunctionTypePointer FunctionType::asMemberFunction(bool _inLibrary, bool _bound)
location,
m_arbitraryParameters,
m_declaration,
+ m_isConstant,
+ m_isPayable,
m_gasSet,
m_valueSet,
_bound
@@ -2090,7 +2130,8 @@ vector<string> const FunctionType::returnParameterTypeNames(bool _addDataLocatio
TypePointer FunctionType::selfType() const
{
- solAssert(bound(), "");
+ solAssert(bound(), "Function is not bound.");
+ solAssert(m_parameterTypes.size() > 0, "Function has no self type.");
return m_parameterTypes.at(0);
}
diff --git a/libsolidity/ast/Types.h b/libsolidity/ast/Types.h
index 1282e5d8..9173f39a 100644
--- a/libsolidity/ast/Types.h
+++ b/libsolidity/ast/Types.h
@@ -640,9 +640,8 @@ public:
bool isSuper() const { return m_super; }
ContractDefinition const& contractDefinition() const { return m_contract; }
- /// Returns the function type of the constructor. Note that the location part of the function type
- /// is not used, as this type cannot be the type of a variable or expression.
- FunctionTypePointer const& constructorType() const;
+ /// Returns the function type of the constructor modified to return an object of the contract's type.
+ FunctionTypePointer const& newExpressionType() const;
/// @returns the identifier of the function with the given name or Invalid256 if such a name does
/// not exist.
@@ -820,21 +819,32 @@ public:
explicit FunctionType(VariableDeclaration const& _varDecl);
/// Creates the function type of an event.
explicit FunctionType(EventDefinition const& _event);
+ /// Function type constructor to be used for a plain type (not derived from a declaration).
FunctionType(
strings const& _parameterTypes,
strings const& _returnParameterTypes,
Location _location = Location::Internal,
- bool _arbitraryParameters = false
+ bool _arbitraryParameters = false,
+ bool _constant = false,
+ bool _payable = false
): FunctionType(
parseElementaryTypeVector(_parameterTypes),
parseElementaryTypeVector(_returnParameterTypes),
strings(),
strings(),
_location,
- _arbitraryParameters
+ _arbitraryParameters,
+ nullptr,
+ _constant,
+ _payable
)
{
}
+
+ /// @returns the type of the "new Contract" function, i.e. basically the constructor.
+ static FunctionTypePointer newExpressionType(ContractDefinition const& _contract);
+
+ /// Detailed constructor, use with care.
FunctionType(
TypePointers const& _parameterTypes,
TypePointers const& _returnParameterTypes,
@@ -843,6 +853,8 @@ public:
Location _location = Location::Internal,
bool _arbitraryParameters = false,
Declaration const* _declaration = nullptr,
+ bool _isConstant = false,
+ bool _isPayable = false,
bool _gasSet = false,
bool _valueSet = false,
bool _bound = false
@@ -856,6 +868,8 @@ public:
m_gasSet(_gasSet),
m_valueSet(_valueSet),
m_bound(_bound),
+ m_isConstant(_isConstant),
+ m_isPayable(_isPayable),
m_declaration(_declaration)
{}
@@ -905,6 +919,7 @@ public:
}
bool hasDeclaration() const { return !!m_declaration; }
bool isConstant() const { return m_isConstant; }
+ bool isPayable() const { return m_isPayable; }
/// @return A shared pointer of an ASTString.
/// Can contain a nullptr in which case indicates absence of documentation
ASTPointer<ASTString> documentation() const;
@@ -942,6 +957,7 @@ private:
bool const m_valueSet = false; ///< true iff the value to be sent is on the stack
bool const m_bound = false; ///< true iff the function is called as arg1.fun(arg2, ..., argn)
bool m_isConstant = false;
+ bool m_isPayable = false;
Declaration const* m_declaration = nullptr;
};
diff --git a/libsolidity/codegen/CompilerUtils.cpp b/libsolidity/codegen/CompilerUtils.cpp
index d7d17b8e..ec496df8 100644
--- a/libsolidity/codegen/CompilerUtils.cpp
+++ b/libsolidity/codegen/CompilerUtils.cpp
@@ -160,7 +160,15 @@ void CompilerUtils::encodeToMemory(
TypePointers targetTypes = _targetTypes.empty() ? _givenTypes : _targetTypes;
solAssert(targetTypes.size() == _givenTypes.size(), "");
for (TypePointer& t: targetTypes)
+ {
+ solAssert(
+ t->mobileType() &&
+ t->mobileType()->interfaceType(_encodeAsLibraryTypes) &&
+ t->mobileType()->interfaceType(_encodeAsLibraryTypes)->encodingType(),
+ "Encoding type \"" + t->toString() + "\" not yet implemented."
+ );
t = t->mobileType()->interfaceType(_encodeAsLibraryTypes)->encodingType();
+ }
// Stack during operation:
// <v1> <v2> ... <vn> <mem_start> <dyn_head_1> ... <dyn_head_r> <end_of_mem>
diff --git a/libsolidity/codegen/ContractCompiler.cpp b/libsolidity/codegen/ContractCompiler.cpp
index 9d77ccdc..33571bc0 100644
--- a/libsolidity/codegen/ContractCompiler.cpp
+++ b/libsolidity/codegen/ContractCompiler.cpp
@@ -242,6 +242,12 @@ void ContractCompiler::appendFunctionSelector(ContractDefinition const& _contrac
m_context << notFound;
if (fallback)
{
+ if (!fallback->isPayable())
+ {
+ // Throw if function is not payable but call contained ether.
+ m_context << Instruction::CALLVALUE;
+ m_context.appendConditionalJumpTo(m_context.errorTag());
+ }
eth::AssemblyItem returnTag = m_context.pushNewTag();
fallback->accept(*this);
m_context << returnTag;
@@ -255,7 +261,15 @@ void ContractCompiler::appendFunctionSelector(ContractDefinition const& _contrac
FunctionTypePointer const& functionType = it.second;
solAssert(functionType->hasDeclaration(), "");
CompilerContext::LocationSetter locationSetter(m_context, functionType->declaration());
+
m_context << callDataUnpackerEntryPoints.at(it.first);
+ if (!functionType->isPayable())
+ {
+ // Throw if function is not payable but call contained ether.
+ m_context << Instruction::CALLVALUE;
+ m_context.appendConditionalJumpTo(m_context.errorTag());
+ }
+
eth::AssemblyItem returnTag = m_context.pushNewTag();
m_context << CompilerUtils::dataStartOffset;
appendCalldataUnpacker(functionType->parameterTypes());
diff --git a/libsolidity/codegen/ExpressionCompiler.cpp b/libsolidity/codegen/ExpressionCompiler.cpp
index 4a81e27d..96ca4296 100644
--- a/libsolidity/codegen/ExpressionCompiler.cpp
+++ b/libsolidity/codegen/ExpressionCompiler.cpp
@@ -568,12 +568,17 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall)
break;
case Location::Send:
_functionCall.expression().accept(*this);
- m_context << u256(0); // do not send gas (there still is the stipend)
+ // Provide the gas stipend manually at first because we may send zero ether.
+ // Will be zeroed if we send more than zero ether.
+ m_context << u256(eth::GasCosts::callStipend);
arguments.front()->accept(*this);
utils().convertType(
*arguments.front()->annotation().type,
*function.parameterTypes().front(), true
);
+ // gas <- gas * !value
+ m_context << Instruction::SWAP1 << Instruction::DUP2;
+ m_context << Instruction::ISZERO << Instruction::MUL << Instruction::SWAP1;
appendExternalFunctionCall(
FunctionType(
TypePointers{},
@@ -583,6 +588,8 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall)
Location::Bare,
false,
nullptr,
+ false,
+ false,
true,
true
),
@@ -1524,11 +1531,13 @@ void ExpressionCompiler::appendExternalFunctionCall(
m_context << u256(0);
m_context << dupInstruction(m_context.baseToCurrentStackOffset(contractStackPos));
+ bool existenceChecked = false;
// Check the the target contract exists (has code) for non-low-level calls.
if (funKind == FunctionKind::External || funKind == FunctionKind::CallCode || funKind == FunctionKind::DelegateCall)
{
m_context << Instruction::DUP1 << Instruction::EXTCODESIZE << Instruction::ISZERO;
m_context.appendConditionalJumpTo(m_context.errorTag());
+ existenceChecked = true;
}
if (_functionType.gasSet())
@@ -1540,7 +1549,7 @@ void ExpressionCompiler::appendExternalFunctionCall(
u256 gasNeededByCaller = eth::GasCosts::callGas + 10;
if (_functionType.valueSet())
gasNeededByCaller += eth::GasCosts::callValueTransferGas;
- if (!isCallCode && !isDelegateCall)
+ if (!isCallCode && !isDelegateCall && !existenceChecked)
gasNeededByCaller += eth::GasCosts::callNewAccountGas; // we never know
m_context <<
gasNeededByCaller <<
diff --git a/libsolidity/grammar.txt b/libsolidity/grammar.txt
index 0230729a..755cf281 100644
--- a/libsolidity/grammar.txt
+++ b/libsolidity/grammar.txt
@@ -41,10 +41,11 @@ ArrayTypeName = TypeName StorageLocation? '[' Expression? ']'
StorageLocation = 'memory' | 'storage'
Block = '{' Statement* '}'
-Statement = IfStatement | WhileStatement | ForStatement | Block | PlaceholderStatement |
- ( Continue | Break | Return | Throw | SimpleStatement | ExpressionStatement ) ';'
+Statement = IfStatement | WhileStatement | ForStatement | Block |
+ ( PlaceholderStatement | Continue | Break | Return |
+ Throw | SimpleStatement ) ';'
-ExpressionStatement = Expression | VariableDefinition
+ExpressionStatement = Expression
IfStatement = 'if' '(' Expression ')' Statement ( 'else' Statement )?
WhileStatement = 'while' '(' Expression ')' Statement
PlaceholderStatement = '_'
@@ -78,7 +79,7 @@ Expression =
PrimaryExpression = Identifier | BooleanLiteral | NumberLiteral | StringLiteral
-FunctionCall = Identifier '(' Expression? ( ',' Expression )* ')'
+FunctionCall = ( PrimaryExpression | NewExpression | TypeName ) ( ( '.' Identifier ) | ( '[' Expression ']' ) )* '(' Expression? ( ',' Expression )* ')'
NewExpression = 'new' Identifier
MemberAccess = Expression '.' Identifier
IndexAccess = Expression '[' Expression? ']'
diff --git a/libsolidity/interface/InterfaceHandler.cpp b/libsolidity/interface/InterfaceHandler.cpp
index d39f8285..de16a372 100644
--- a/libsolidity/interface/InterfaceHandler.cpp
+++ b/libsolidity/interface/InterfaceHandler.cpp
@@ -52,6 +52,7 @@ string InterfaceHandler::abiInterface(ContractDefinition const& _contractDef)
method["type"] = "function";
method["name"] = it.second->declaration().name();
method["constant"] = it.second->isConstant();
+ method["payable"] = it.second->isPayable();
method["inputs"] = populateParameters(
externalFunctionType->parameterNames(),
externalFunctionType->parameterTypeNames(_contractDef.isLibrary())
@@ -80,7 +81,7 @@ string InterfaceHandler::abiInterface(ContractDefinition const& _contractDef)
solAssert(!!externalFunctionType, "");
Json::Value method;
method["type"] = "fallback";
- method["constant"] = externalFunctionType->isConstant();
+ method["payable"] = externalFunctionType->isPayable();
abi.append(method);
}
for (auto const& it: _contractDef.interfaceEvents())
diff --git a/libsolidity/parsing/Parser.cpp b/libsolidity/parsing/Parser.cpp
index b2f4a156..0e99d1e7 100644
--- a/libsolidity/parsing/Parser.cpp
+++ b/libsolidity/parsing/Parser.cpp
@@ -305,6 +305,7 @@ ASTPointer<FunctionDefinition> Parser::parseFunctionDefinition(ASTString const*
options.allowLocationSpecifier = true;
ASTPointer<ParameterList> parameters(parseParameterList(options));
bool isDeclaredConst = false;
+ bool isPayable = false;
Declaration::Visibility visibility(Declaration::Visibility::Default);
vector<ASTPointer<ModifierInvocation>> modifiers;
while (true)
@@ -315,6 +316,11 @@ ASTPointer<FunctionDefinition> Parser::parseFunctionDefinition(ASTString const*
isDeclaredConst = true;
m_scanner->next();
}
+ else if (m_scanner->currentToken() == Token::Payable)
+ {
+ isPayable = true;
+ m_scanner->next();
+ }
else if (token == Token::Identifier)
modifiers.push_back(parseModifierInvocation());
else if (Token::isVisibilitySpecifier(token))
@@ -354,6 +360,7 @@ ASTPointer<FunctionDefinition> Parser::parseFunctionDefinition(ASTString const*
isDeclaredConst,
modifiers,
returnParameters,
+ isPayable,
block
);
}
@@ -753,7 +760,7 @@ ASTPointer<Statement> Parser::parseStatement()
{
statement = ASTNodeFactory(*this).createNode<PlaceholderStatement>(docString);
m_scanner->next();
- return statement;
+ break;
}
// fall-through
default:
diff --git a/libsolidity/parsing/ParserBase.cpp b/libsolidity/parsing/ParserBase.cpp
index 71085a4d..2abf58cc 100644
--- a/libsolidity/parsing/ParserBase.cpp
+++ b/libsolidity/parsing/ParserBase.cpp
@@ -47,7 +47,17 @@ void ParserBase::expectToken(Token::Value _value)
Token::Value tok = m_scanner->currentToken();
if (tok != _value)
{
- if (Token::isElementaryTypeName(tok)) //for the sake of accuracy in reporting
+ if (Token::isReservedKeyword(tok))
+ {
+ fatalParserError(
+ string("Expected token ") +
+ string(Token::name(_value)) +
+ string(" got reserved keyword '") +
+ string(Token::name(tok)) +
+ string("'")
+ );
+ }
+ else if (Token::isElementaryTypeName(tok)) //for the sake of accuracy in reporting
{
ElementaryTypeNameToken elemTypeName = m_scanner->currentElementaryTypeNameToken();
fatalParserError(
diff --git a/libsolidity/parsing/Token.h b/libsolidity/parsing/Token.h
index 15d4860f..5dd42992 100644
--- a/libsolidity/parsing/Token.h
+++ b/libsolidity/parsing/Token.h
@@ -166,6 +166,7 @@ namespace solidity
K(Memory, "memory", 0) \
K(Modifier, "modifier", 0) \
K(New, "new", 0) \
+ K(Payable, "payable", 0) \
K(Public, "public", 0) \
K(Pragma, "pragma", 0) \
K(Private, "private", 0) \
@@ -229,13 +230,14 @@ namespace solidity
K(Let, "let", 0) \
K(Match, "match", 0) \
K(Of, "of", 0) \
- K(Payable, "payable", 0) \
+ K(Pure, "pure", 0) \
K(Relocatable, "relocatable", 0) \
K(Static, "static", 0) \
K(Switch, "switch", 0) \
K(Try, "try", 0) \
K(Type, "type", 0) \
K(TypeOf, "typeof", 0) \
+ K(View, "view", 0) \
/* Illegal token - not able to scan. */ \
T(Illegal, "ILLEGAL", 0) \
\
@@ -291,6 +293,7 @@ public:
static bool isLocationSpecifier(Value op) { return op == Memory || op == Storage; }
static bool isEtherSubdenomination(Value op) { return op == SubWei || op == SubSzabo || op == SubFinney || op == SubEther; }
static bool isTimeSubdenomination(Value op) { return op == SubSecond || op == SubMinute || op == SubHour || op == SubDay || op == SubWeek || op == SubYear; }
+ static bool isReservedKeyword(Value op) { return (Abstract <= op && op <= TypeOf); }
// @returns a string corresponding to the JS token string
// (.e., "<" for the token LT) or NULL if the token doesn't