diff options
author | Gav Wood <i@gavwood.com> | 2015-02-04 03:57:36 +0800 |
---|---|---|
committer | Gav Wood <i@gavwood.com> | 2015-02-04 03:57:36 +0800 |
commit | 04164b612c61ea2ea5c18f56600f95f03ded7235 (patch) | |
tree | 7cb9ae18f9bea6ec2a244e9de69d7c1814b788b9 /AST.cpp | |
parent | e321b956a1381e569fad2e1ee7d9b23c1baff321 (diff) | |
parent | 5c828dc8b25f223f45d85359dbbb5d9e275167c2 (diff) | |
download | dexon-solidity-04164b612c61ea2ea5c18f56600f95f03ded7235.tar.gz dexon-solidity-04164b612c61ea2ea5c18f56600f95f03ded7235.tar.zst dexon-solidity-04164b612c61ea2ea5c18f56600f95f03ded7235.zip |
Merge branch 'named-args' of https://github.com/guanqun/cpp-ethereum into guanqun-named-args
Diffstat (limited to 'AST.cpp')
-rw-r--r-- | AST.cpp | 43 |
1 files changed, 40 insertions, 3 deletions
@@ -475,6 +475,8 @@ void FunctionCall::checkTypeRequirements() // number of non-mapping members if (m_arguments.size() != 1) BOOST_THROW_EXCEPTION(createTypeError("More than one argument for explicit type conversion.")); + if (!m_names.empty()) + BOOST_THROW_EXCEPTION(createTypeError("Type conversion can't allow named arguments.")); if (!m_arguments.front()->getType()->isExplicitlyConvertibleTo(*type.getActualType())) BOOST_THROW_EXCEPTION(createTypeError("Explicit type conversion not allowed.")); m_type = type.getActualType(); @@ -487,9 +489,44 @@ void FunctionCall::checkTypeRequirements() TypePointers const& parameterTypes = functionType->getParameterTypes(); if (parameterTypes.size() != m_arguments.size()) BOOST_THROW_EXCEPTION(createTypeError("Wrong argument count for function call.")); - for (size_t i = 0; i < m_arguments.size(); ++i) - if (!m_arguments[i]->getType()->isImplicitlyConvertibleTo(*parameterTypes[i])) - BOOST_THROW_EXCEPTION(createTypeError("Invalid type for argument in function call.")); + + if (m_names.empty()) + { + for (size_t i = 0; i < m_arguments.size(); ++i) + if (!m_arguments[i]->getType()->isImplicitlyConvertibleTo(*parameterTypes[i])) + BOOST_THROW_EXCEPTION(createTypeError("Invalid type for argument in function call.")); + } + else + { + auto const& parameterNames = functionType->getParameterNames(); + if (parameterNames.size() != m_names.size()) + BOOST_THROW_EXCEPTION(createTypeError("Some argument names are missing.")); + + // check duplicate names + for (size_t i = 0; i < m_names.size(); i++) { + for (size_t j = i + 1; j < m_names.size(); j++) { + if (m_names[i] == m_names[j]) + BOOST_THROW_EXCEPTION(createTypeError("Duplicate named argument.")); + } + } + + for (size_t i = 0; i < m_names.size(); i++) { + bool found = false; + for (size_t j = 0; j < parameterNames.size(); j++) { + if (parameterNames[j] == m_names[i]) { + // check type convertible + if (!m_arguments[i]->getType()->isImplicitlyConvertibleTo(*parameterTypes[j])) + BOOST_THROW_EXCEPTION(createTypeError("Invalid type for argument in function call.")); + + found = true; + break; + } + } + if (!found) + BOOST_THROW_EXCEPTION(createTypeError("Named argument doesn't match function declaration.")); + } + } + // @todo actually the return type should be an anonymous struct, // but we change it to the type of the first return value until we have structs if (functionType->getReturnParameterTypes().empty()) |