diff options
author | Lu Guanqun <guanqun.lu@gmail.com> | 2015-01-30 01:26:00 +0800 |
---|---|---|
committer | Lu Guanqun <guanqun.lu@gmail.com> | 2015-01-30 01:32:55 +0800 |
commit | 5c828dc8b25f223f45d85359dbbb5d9e275167c2 (patch) | |
tree | 290d64097f64744341cc147391693ef8c16a9055 /ExpressionCompiler.cpp | |
parent | 77384af827d7d941620552c4f5f740c3b7c576ef (diff) | |
download | dexon-solidity-5c828dc8b25f223f45d85359dbbb5d9e275167c2.tar.gz dexon-solidity-5c828dc8b25f223f45d85359dbbb5d9e275167c2.tar.zst dexon-solidity-5c828dc8b25f223f45d85359dbbb5d9e275167c2.zip |
implement named arguments
Diffstat (limited to 'ExpressionCompiler.cpp')
-rw-r--r-- | ExpressionCompiler.cpp | 32 |
1 files changed, 30 insertions, 2 deletions
diff --git a/ExpressionCompiler.cpp b/ExpressionCompiler.cpp index 5d44c86f..62066ac6 100644 --- a/ExpressionCompiler.cpp +++ b/ExpressionCompiler.cpp @@ -193,6 +193,7 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall) { //@todo struct construction solAssert(_functionCall.getArguments().size() == 1, ""); + solAssert(_functionCall.getNames().empty(), ""); Expression const& firstArgument = *_functionCall.getArguments().front(); firstArgument.accept(*this); appendTypeConversion(*firstArgument.getType(), *_functionCall.getType()); @@ -200,8 +201,35 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall) else { FunctionType const& function = dynamic_cast<FunctionType const&>(*_functionCall.getExpression().getType()); - vector<ASTPointer<Expression const>> arguments = _functionCall.getArguments(); - solAssert(arguments.size() == function.getParameterTypes().size(), ""); + TypePointers const& parameterTypes = function.getParameterTypes(); + vector<string> const& parameterNames = function.getParameterNames(); + vector<ASTPointer<Expression const>> const& callArguments = _functionCall.getArguments(); + vector<string> const& callArgumentNames = _functionCall.getNames(); + solAssert(callArguments.size() == parameterTypes.size(), ""); + + vector<ASTPointer<Expression const>> arguments; + if (callArgumentNames.empty()) + { + // normal arguments + arguments = {callArguments.begin(), callArguments.end()}; + } + else + { + // named arguments + for (size_t i = 0; i < parameterNames.size(); i++) { + bool found = false; + for (size_t j = 0; j < callArgumentNames.size(); j++) { + if (parameterNames[i] == callArgumentNames[j]) { + // we found the actual parameter position + arguments.push_back(callArguments[j]); + + found = true; + break; + } + } + solAssert(found, ""); + } + } switch (function.getLocation()) { |