mirror of https://gitee.com/bigwinds/arangodb
factored out stack
This commit is contained in:
parent
f0a6885e86
commit
66bec2bcad
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -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
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
;
|
||||
|
||||
|
|
|
@ -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];
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @}
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -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);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @}
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -33,7 +33,6 @@
|
|||
#include <BasicsC/hashes.h>
|
||||
#include <BasicsC/vector.h>
|
||||
#include <BasicsC/associative.h>
|
||||
#include <BasicsC/json.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
|
Loading…
Reference in New Issue