From 66bec2bcadf7574784b4775c97b8552f041c56b2 Mon Sep 17 00:00:00 2001 From: Jan Steemann Date: Mon, 30 Apr 2012 09:35:13 +0200 Subject: [PATCH] factored out stack --- Ahuacatl/ahuacatl-ast-node.c | 5 ++- Ahuacatl/ahuacatl-context.c | 39 ------------------ Ahuacatl/ahuacatl-context.h | 18 -------- Ahuacatl/ahuacatl-grammar.c | 28 ++++++------- Ahuacatl/ahuacatl-grammar.y | 28 ++++++------- Ahuacatl/ahuacatl-parser-functions.c | 61 ++++++++++++++++++---------- Ahuacatl/ahuacatl-parser-functions.h | 18 ++++++++ Ahuacatl/ahuacatl-variable.h | 1 - 8 files changed, 89 insertions(+), 109 deletions(-) diff --git a/Ahuacatl/ahuacatl-ast-node.c b/Ahuacatl/ahuacatl-ast-node.c index 44c6df067f..ef1fb37698 100644 --- a/Ahuacatl/ahuacatl-ast-node.c +++ b/Ahuacatl/ahuacatl-ast-node.c @@ -27,6 +27,7 @@ #include "Ahuacatl/ahuacatl-ast-node.h" #include "Ahuacatl/ahuacatl-functions.h" +#include "Ahuacatl/ahuacatl-parser-functions.h" // ----------------------------------------------------------------------------- // --SECTION-- private macros @@ -969,7 +970,7 @@ TRI_aql_node_t* TRI_CreateNodeFcallAql (TRI_aql_context_t* const context, bool TRI_PushListAql (TRI_aql_context_t* const context, const TRI_aql_node_t* const value) { - TRI_aql_node_t* node = TRI_PeekStackAql(context); + TRI_aql_node_t* node = TRI_PeekStackParseAql(context); assert(node); @@ -985,7 +986,7 @@ bool TRI_PushListAql (TRI_aql_context_t* const context, bool TRI_PushArrayAql (TRI_aql_context_t* const context, const char* const name, const TRI_aql_node_t* const value) { - TRI_aql_node_t* node = TRI_PeekStackAql(context); + TRI_aql_node_t* node = TRI_PeekStackParseAql(context); TRI_aql_node_t* element; assert(node); diff --git a/Ahuacatl/ahuacatl-context.c b/Ahuacatl/ahuacatl-context.c index 5bd89f4dea..7da3b8f3b0 100644 --- a/Ahuacatl/ahuacatl-context.c +++ b/Ahuacatl/ahuacatl-context.c @@ -387,45 +387,6 @@ void TRI_SetErrorContextAql (TRI_aql_context_t* const context, } } -//////////////////////////////////////////////////////////////////////////////// -/// @brief push something on the stack -//////////////////////////////////////////////////////////////////////////////// - -bool TRI_PushStackAql (TRI_aql_context_t* const context, - const void* const value) { - assert(context); - - if (!value) { - ABORT_OOM - } - - TRI_PushBackVectorPointer(&context->_stack, (void*) value); - - return true; -} - -//////////////////////////////////////////////////////////////////////////////// -/// @brief pop something from the stack -//////////////////////////////////////////////////////////////////////////////// - -void* TRI_PopStackAql (TRI_aql_context_t* const context) { - assert(context); - assert(context->_stack._length > 0); - - return TRI_RemoveVectorPointer(&context->_stack, context->_stack._length - 1); -} - -//////////////////////////////////////////////////////////////////////////////// -/// @brief peek at the end of the stack -//////////////////////////////////////////////////////////////////////////////// - -void* TRI_PeekStackAql (TRI_aql_context_t* const context) { - assert(context); - assert(context->_stack._length > 0); - - return context->_stack._buffer[context->_stack._length - 1]; -} - //////////////////////////////////////////////////////////////////////////////// /// @brief get first statement in the current scope //////////////////////////////////////////////////////////////////////////////// diff --git a/Ahuacatl/ahuacatl-context.h b/Ahuacatl/ahuacatl-context.h index aa7353da96..3387f88a73 100644 --- a/Ahuacatl/ahuacatl-context.h +++ b/Ahuacatl/ahuacatl-context.h @@ -165,24 +165,6 @@ void TRI_SetErrorContextAql (TRI_aql_context_t* const, const int, const char* const); -//////////////////////////////////////////////////////////////////////////////// -/// @brief push something on the stack -//////////////////////////////////////////////////////////////////////////////// - -bool TRI_PushStackAql (TRI_aql_context_t* const, const void* const); - -//////////////////////////////////////////////////////////////////////////////// -/// @brief pop something from the stack -//////////////////////////////////////////////////////////////////////////////// - -void* TRI_PopStackAql (TRI_aql_context_t* const); - -//////////////////////////////////////////////////////////////////////////////// -/// @brief peek at the end of the stack -//////////////////////////////////////////////////////////////////////////////// - -void* TRI_PeekStackAql (TRI_aql_context_t* const); - //////////////////////////////////////////////////////////////////////////////// /// @brief get first statement in the current scope //////////////////////////////////////////////////////////////////////////////// diff --git a/Ahuacatl/ahuacatl-grammar.c b/Ahuacatl/ahuacatl-grammar.c index f2ef89df87..6364872a9b 100644 --- a/Ahuacatl/ahuacatl-grammar.c +++ b/Ahuacatl/ahuacatl-grammar.c @@ -1808,7 +1808,7 @@ yyreduce: /* Line 1455 of yacc.c */ #line 237 "Ahuacatl/ahuacatl-grammar.y" { - if (!TRI_PushStackAql(context, (yyvsp[(2) - (2)].strval)) || !TRI_StartScopeContextAql(context)) { + if (!TRI_PushStackParseAql(context, (yyvsp[(2) - (2)].strval)) || !TRI_StartScopeContextAql(context)) { YYABORT; } ;} @@ -1823,7 +1823,7 @@ yyreduce: TRI_EndScopeContextAql(context); - node = TRI_CreateNodeAssignAql(context, TRI_PopStackAql(context), (yyvsp[(6) - (7)].node)); + node = TRI_CreateNodeAssignAql(context, TRI_PopStackParseAql(context), (yyvsp[(6) - (7)].node)); if (!node) { YYABORT; } @@ -1843,7 +1843,7 @@ yyreduce: YYABORT; } - TRI_PushStackAql(context, node); + TRI_PushStackParseAql(context, node); ;} break; @@ -1852,7 +1852,7 @@ yyreduce: /* Line 1455 of yacc.c */ #line 264 "Ahuacatl/ahuacatl-grammar.y" { - TRI_aql_node_t* node = TRI_CreateNodeCollectAql(context, TRI_PopStackAql(context), (yyvsp[(4) - (4)].strval)); + TRI_aql_node_t* node = TRI_CreateNodeCollectAql(context, TRI_PopStackParseAql(context), (yyvsp[(4) - (4)].strval)); if (!node) { YYABORT; } @@ -1933,7 +1933,7 @@ yyreduce: YYABORT; } - TRI_PushStackAql(context, node); + TRI_PushStackParseAql(context, node); ;} break; @@ -1942,7 +1942,7 @@ yyreduce: /* Line 1455 of yacc.c */ #line 317 "Ahuacatl/ahuacatl-grammar.y" { - TRI_aql_node_t* list = TRI_PopStackAql(context); + TRI_aql_node_t* list = TRI_PopStackParseAql(context); TRI_aql_node_t* node = TRI_CreateNodeSortAql(context, list); if (!node) { YYABORT; @@ -2114,7 +2114,7 @@ yyreduce: { TRI_aql_node_t* node; - if (!TRI_PushStackAql(context, (yyvsp[(1) - (1)].strval))) { + if (!TRI_PushStackParseAql(context, (yyvsp[(1) - (1)].strval))) { YYABORT; } @@ -2123,7 +2123,7 @@ yyreduce: YYABORT; } - TRI_PushStackAql(context, node); + TRI_PushStackParseAql(context, node); ;} break; @@ -2132,8 +2132,8 @@ yyreduce: /* Line 1455 of yacc.c */ #line 429 "Ahuacatl/ahuacatl-grammar.y" { - TRI_aql_node_t* list = TRI_PopStackAql(context); - TRI_aql_node_t* node = TRI_CreateNodeFcallAql(context, TRI_PopStackAql(context), list); + TRI_aql_node_t* list = TRI_PopStackParseAql(context); + TRI_aql_node_t* node = TRI_CreateNodeFcallAql(context, TRI_PopStackParseAql(context), list); if (!node) { YYABORT; } @@ -2483,7 +2483,7 @@ yyreduce: YYABORT; } - TRI_PushStackAql(context, node); + TRI_PushStackParseAql(context, node); ;} break; @@ -2492,7 +2492,7 @@ yyreduce: /* Line 1455 of yacc.c */ #line 635 "Ahuacatl/ahuacatl-grammar.y" { - (yyval.node) = TRI_PopStackAql(context); + (yyval.node) = TRI_PopStackParseAql(context); ;} break; @@ -2544,7 +2544,7 @@ yyreduce: YYABORT; } - TRI_PushStackAql(context, node); + TRI_PushStackParseAql(context, node); ;} break; @@ -2553,7 +2553,7 @@ yyreduce: /* Line 1455 of yacc.c */ #line 668 "Ahuacatl/ahuacatl-grammar.y" { - (yyval.node) = TRI_PopStackAql(context); + (yyval.node) = TRI_PopStackParseAql(context); ;} break; diff --git a/Ahuacatl/ahuacatl-grammar.y b/Ahuacatl/ahuacatl-grammar.y index 8ab21c7d80..e9ca9db881 100644 --- a/Ahuacatl/ahuacatl-grammar.y +++ b/Ahuacatl/ahuacatl-grammar.y @@ -235,7 +235,7 @@ filter_statement: let_statement: T_LET variable_name { - if (!TRI_PushStackAql(context, $2) || !TRI_StartScopeContextAql(context)) { + if (!TRI_PushStackParseAql(context, $2) || !TRI_StartScopeContextAql(context)) { YYABORT; } } T_ASSIGN T_OPEN expression T_CLOSE { @@ -243,7 +243,7 @@ let_statement: TRI_EndScopeContextAql(context); - node = TRI_CreateNodeAssignAql(context, TRI_PopStackAql(context), $6); + node = TRI_CreateNodeAssignAql(context, TRI_PopStackParseAql(context), $6); if (!node) { YYABORT; } @@ -260,9 +260,9 @@ collect_statement: YYABORT; } - TRI_PushStackAql(context, node); + TRI_PushStackParseAql(context, node); } collect_list optional_into { - TRI_aql_node_t* node = TRI_CreateNodeCollectAql(context, TRI_PopStackAql(context), $4); + TRI_aql_node_t* node = TRI_CreateNodeCollectAql(context, TRI_PopStackParseAql(context), $4); if (!node) { YYABORT; } @@ -313,9 +313,9 @@ sort_statement: YYABORT; } - TRI_PushStackAql(context, node); + TRI_PushStackParseAql(context, node); } sort_list { - TRI_aql_node_t* list = TRI_PopStackAql(context); + TRI_aql_node_t* list = TRI_PopStackParseAql(context); TRI_aql_node_t* node = TRI_CreateNodeSortAql(context, list); if (!node) { YYABORT; @@ -416,7 +416,7 @@ expression: | T_STRING { TRI_aql_node_t* node; - if (!TRI_PushStackAql(context, $1)) { + if (!TRI_PushStackParseAql(context, $1)) { YYABORT; } @@ -425,10 +425,10 @@ expression: YYABORT; } - TRI_PushStackAql(context, node); + TRI_PushStackParseAql(context, node); } T_OPEN optional_function_call_arguments T_CLOSE %prec FUNCCALL { - TRI_aql_node_t* list = TRI_PopStackAql(context); - TRI_aql_node_t* node = TRI_CreateNodeFcallAql(context, TRI_PopStackAql(context), list); + TRI_aql_node_t* list = TRI_PopStackParseAql(context); + TRI_aql_node_t* node = TRI_CreateNodeFcallAql(context, TRI_PopStackParseAql(context), list); if (!node) { YYABORT; } @@ -631,9 +631,9 @@ list: YYABORT; } - TRI_PushStackAql(context, node); + TRI_PushStackParseAql(context, node); } optional_list_elements T_LIST_CLOSE { - $$ = TRI_PopStackAql(context); + $$ = TRI_PopStackParseAql(context); } ; @@ -664,9 +664,9 @@ array: YYABORT; } - TRI_PushStackAql(context, node); + TRI_PushStackParseAql(context, node); } optional_array_elements T_DOC_CLOSE { - $$ = TRI_PopStackAql(context); + $$ = TRI_PopStackParseAql(context); } ; diff --git a/Ahuacatl/ahuacatl-parser-functions.c b/Ahuacatl/ahuacatl-parser-functions.c index 9f8012d8a1..b4b04f0cde 100644 --- a/Ahuacatl/ahuacatl-parser-functions.c +++ b/Ahuacatl/ahuacatl-parser-functions.c @@ -27,27 +27,6 @@ #include "Ahuacatl/ahuacatl-parser-functions.h" -// ----------------------------------------------------------------------------- -// --SECTION-- private macros -// ----------------------------------------------------------------------------- - -//////////////////////////////////////////////////////////////////////////////// -/// @addtogroup Ahuacatl -/// @{ -//////////////////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////////////////// -/// @brief shortcut macro for signalling out of memory -//////////////////////////////////////////////////////////////////////////////// - -#define ABORT_OOM \ - TRI_SetErrorAql(context, TRI_ERROR_OUT_OF_MEMORY, NULL); \ - return NULL; - -//////////////////////////////////////////////////////////////////////////////// -/// @} -//////////////////////////////////////////////////////////////////////////////// - // ----------------------------------------------------------------------------- // --SECTION-- public functions // ----------------------------------------------------------------------------- @@ -105,6 +84,46 @@ void TRI_SetErrorParseAql (TRI_aql_context_t* const context, TRI_SetErrorContextAql(context, TRI_ERROR_QUERY_PARSE, buffer); } +//////////////////////////////////////////////////////////////////////////////// +/// @brief push something on the stack +//////////////////////////////////////////////////////////////////////////////// + +bool TRI_PushStackParseAql (TRI_aql_context_t* const context, + const void* const value) { + assert(context); + + if (!value) { + TRI_SetErrorContextAql(context, TRI_ERROR_OUT_OF_MEMORY, NULL); \ + return NULL; + } + + TRI_PushBackVectorPointer(&context->_stack, (void*) value); + + return true; +} + +//////////////////////////////////////////////////////////////////////////////// +/// @brief pop something from the stack +//////////////////////////////////////////////////////////////////////////////// + +void* TRI_PopStackParseAql (TRI_aql_context_t* const context) { + assert(context); + assert(context->_stack._length > 0); + + return TRI_RemoveVectorPointer(&context->_stack, context->_stack._length - 1); +} + +//////////////////////////////////////////////////////////////////////////////// +/// @brief peek at the end of the stack +//////////////////////////////////////////////////////////////////////////////// + +void* TRI_PeekStackParseAql (TRI_aql_context_t* const context) { + assert(context); + assert(context->_stack._length > 0); + + return context->_stack._buffer[context->_stack._length - 1]; +} + //////////////////////////////////////////////////////////////////////////////// /// @} //////////////////////////////////////////////////////////////////////////////// diff --git a/Ahuacatl/ahuacatl-parser-functions.h b/Ahuacatl/ahuacatl-parser-functions.h index 6a00583e51..aec569f9fc 100644 --- a/Ahuacatl/ahuacatl-parser-functions.h +++ b/Ahuacatl/ahuacatl-parser-functions.h @@ -105,6 +105,24 @@ void TRI_SetErrorParseAql (TRI_aql_context_t* const, const int, const int); +//////////////////////////////////////////////////////////////////////////////// +/// @brief push something on the stack +//////////////////////////////////////////////////////////////////////////////// + +bool TRI_PushStackParseAql (TRI_aql_context_t* const, const void* const); + +//////////////////////////////////////////////////////////////////////////////// +/// @brief pop something from the stack +//////////////////////////////////////////////////////////////////////////////// + +void* TRI_PopStackParseAql (TRI_aql_context_t* const); + +//////////////////////////////////////////////////////////////////////////////// +/// @brief peek at the end of the stack +//////////////////////////////////////////////////////////////////////////////// + +void* TRI_PeekStackParseAql (TRI_aql_context_t* const); + //////////////////////////////////////////////////////////////////////////////// /// @} //////////////////////////////////////////////////////////////////////////////// diff --git a/Ahuacatl/ahuacatl-variable.h b/Ahuacatl/ahuacatl-variable.h index 925233d542..5f273dd41d 100644 --- a/Ahuacatl/ahuacatl-variable.h +++ b/Ahuacatl/ahuacatl-variable.h @@ -33,7 +33,6 @@ #include #include #include -#include #ifdef __cplusplus extern "C" {