From 7c226df013cd3a1535363aa23a5d1af11742eb7a Mon Sep 17 00:00:00 2001 From: Jan Steemann Date: Wed, 6 Aug 2014 17:30:21 +0200 Subject: [PATCH] handle calls to user-defined functions --- arangod/Aql/V8Executor.cpp | 36 +++++++++++++++++++++++++++++++++++- arangod/Aql/V8Executor.h | 8 +++++++- 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/arangod/Aql/V8Executor.cpp b/arangod/Aql/V8Executor.cpp index a12dfb88f2..5741275fa7 100644 --- a/arangod/Aql/V8Executor.cpp +++ b/arangod/Aql/V8Executor.cpp @@ -529,7 +529,7 @@ void V8Executor::generateCodeCollection (AstNode const* node) { } //////////////////////////////////////////////////////////////////////////////// -/// @brief generate JavaScript code for a function call +/// @brief generate JavaScript code for a call to a built-in function //////////////////////////////////////////////////////////////////////////////// void V8Executor::generateCodeFunctionCall (AstNode const* node) { @@ -557,6 +557,36 @@ void V8Executor::generateCodeFunctionCall (AstNode const* node) { _buffer->appendText(")"); } +//////////////////////////////////////////////////////////////////////////////// +/// @brief generate JavaScript code for a call to a user-defined function +//////////////////////////////////////////////////////////////////////////////// + +void V8Executor::generateCodeUserFunctionCall (AstNode const* node) { + TRI_ASSERT(node != nullptr); + TRI_ASSERT(node->numMembers() == 1); + + char const* name = node->getStringValue(); + TRI_ASSERT(name != nullptr); + + auto args = node->getMember(0); + TRI_ASSERT(args != nullptr); + TRI_ASSERT(args->type == NODE_TYPE_LIST); + + _buffer->appendText("aql.FCALL_USER(\""); + _buffer->appendJsonEncoded(name); + _buffer->appendText("\", ["); + + size_t const n = args->numMembers(); + for (size_t i = 0; i < n; ++i) { + if (i > 0) { + _buffer->appendText(", "); + } + + generateCodeNode(args->getMember(i)); + } + _buffer->appendText("])"); +} + //////////////////////////////////////////////////////////////////////////////// /// @brief generate JavaScript code for an expansion (i.e. [*] operator) //////////////////////////////////////////////////////////////////////////////// @@ -686,6 +716,10 @@ void V8Executor::generateCodeNode (AstNode const* node) { generateCodeFunctionCall(node); break; + case NODE_TYPE_FCALL_USER: + generateCodeUserFunctionCall(node); + break; + case NODE_TYPE_EXPAND: generateCodeExpand(node); break; diff --git a/arangod/Aql/V8Executor.h b/arangod/Aql/V8Executor.h index 4d50e3e03b..c56f8cec07 100644 --- a/arangod/Aql/V8Executor.h +++ b/arangod/Aql/V8Executor.h @@ -154,11 +154,17 @@ namespace triagens { void generateCodeCollection (AstNode const*); //////////////////////////////////////////////////////////////////////////////// -/// @brief generate JavaScript code for a function call +/// @brief generate JavaScript code for a call to a built-in function //////////////////////////////////////////////////////////////////////////////// void generateCodeFunctionCall (AstNode const*); +//////////////////////////////////////////////////////////////////////////////// +/// @brief generate JavaScript code for a user-defined function +//////////////////////////////////////////////////////////////////////////////// + + void generateCodeUserFunctionCall (AstNode const*); + //////////////////////////////////////////////////////////////////////////////// /// @brief generate JavaScript code for an expansion (i.e. [*] operator) ////////////////////////////////////////////////////////////////////////////////