1
0
Fork 0

Merge branch 'devel' of github.com:triAGENS/ArangoDB into devel

This commit is contained in:
Michael Hackstein 2014-07-18 17:00:00 +02:00
commit 3b78858360
9 changed files with 107 additions and 81 deletions

View File

@ -44,22 +44,32 @@
/// @brief shortcut macro to create a new node or fail in case of OOM /// @brief shortcut macro to create a new node or fail in case of OOM
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
#define CREATE_NODE(type) \ inline TRI_aql_node_t* CREATE_NODE_FUNC(TRI_aql_node_type_e type,
TRI_aql_node_t* node = (TRI_aql_node_t*) \ TRI_aql_context_t* context) {
TRI_Allocate(TRI_UNKNOWN_MEM_ZONE, sizeof(TRI_aql_node_t), false); \ TRI_aql_node_t* node;
if (node == NULL) { \ try {
TRI_SetErrorContextAql( \ node = new TRI_aql_node_t();
__FILE__, \ }
__LINE__, \ catch (std::exception&) {
context, \ node = nullptr;
TRI_ERROR_OUT_OF_MEMORY, \ }
NULL); \ if (node == nullptr) {
return NULL; \ TRI_SetErrorContextAql(
} \ __FILE__,
\ __LINE__,
node->_type = type; \ context,
TRI_InitVectorPointer(&node->_members, TRI_UNKNOWN_MEM_ZONE); \ TRI_ERROR_OUT_OF_MEMORY,
nullptr);
return nullptr;
}
node->_type = type;
TRI_InitVectorPointer(&node->_members, TRI_UNKNOWN_MEM_ZONE);
TRI_RegisterNodeContextAql(context, node); TRI_RegisterNodeContextAql(context, node);
return node;
}
#define CREATE_NODE(type) TRI_aql_node_t* node = CREATE_NODE_FUNC(type, context);
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
/// @brief add a sub node to a node /// @brief add a sub node to a node
@ -206,10 +216,12 @@ static TRI_aql_node_t* CreateNodeUserFcall (TRI_aql_context_t* const context,
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
TRI_aql_node_t* TRI_CreateNodeNopAql (void) { TRI_aql_node_t* TRI_CreateNodeNopAql (void) {
TRI_aql_node_t* node = (TRI_aql_node_t*) TRI_Allocate(TRI_UNKNOWN_MEM_ZONE, sizeof(TRI_aql_node_t), false); TRI_aql_node_t* node;
try {
if (node == NULL) { node = new TRI_aql_node_t;
return NULL; }
catch (std::exception&) {
return nullptr;
} }
node->_type = TRI_AQL_NODE_NOP; node->_type = TRI_AQL_NODE_NOP;
@ -228,20 +240,29 @@ TRI_aql_node_t* TRI_CreateNodeReturnEmptyAql (void) {
TRI_aql_node_t* list; TRI_aql_node_t* list;
int res; int res;
node = (TRI_aql_node_t*) TRI_Allocate(TRI_UNKNOWN_MEM_ZONE, sizeof(TRI_aql_node_t), false); try {
node = new TRI_aql_node_t();
}
catch (std::exception&) {
node = nullptr;
}
if (node == NULL) { if (node == nullptr) {
return NULL; return nullptr;
} }
node->_type = TRI_AQL_NODE_RETURN_EMPTY; node->_type = TRI_AQL_NODE_RETURN_EMPTY;
list = (TRI_aql_node_t*) TRI_Allocate(TRI_UNKNOWN_MEM_ZONE, sizeof(TRI_aql_node_t), false); try {
list = new TRI_aql_node_t();
}
catch (std::exception&) {
list = nullptr;
}
if (list == NULL) { if (list == nullptr) {
TRI_Free(TRI_UNKNOWN_MEM_ZONE, node); delete node;
return nullptr;
return NULL;
} }
list->_type = TRI_AQL_NODE_LIST; list->_type = TRI_AQL_NODE_LIST;
@ -251,8 +272,8 @@ TRI_aql_node_t* TRI_CreateNodeReturnEmptyAql (void) {
if (res != TRI_ERROR_NO_ERROR) { if (res != TRI_ERROR_NO_ERROR) {
TRI_DestroyVectorPointer(&list->_members); TRI_DestroyVectorPointer(&list->_members);
TRI_Free(TRI_UNKNOWN_MEM_ZONE, list); delete list;
TRI_Free(TRI_UNKNOWN_MEM_ZONE, node); delete node;
return NULL; return NULL;
} }
@ -262,8 +283,8 @@ TRI_aql_node_t* TRI_CreateNodeReturnEmptyAql (void) {
if (res != TRI_ERROR_NO_ERROR) { if (res != TRI_ERROR_NO_ERROR) {
TRI_DestroyVectorPointer(&node->_members); TRI_DestroyVectorPointer(&node->_members);
TRI_DestroyVectorPointer(&list->_members); TRI_DestroyVectorPointer(&list->_members);
TRI_Free(TRI_UNKNOWN_MEM_ZONE, list); delete list;
TRI_Free(TRI_UNKNOWN_MEM_ZONE, node); delete node;
return NULL; return NULL;
} }

View File

@ -2985,7 +2985,7 @@ static void ProcessNode (TRI_aql_codegen_js_t* const generator, const TRI_aql_no
static TRI_aql_codegen_register_t CreateCode (TRI_aql_codegen_js_t* generator) { static TRI_aql_codegen_register_t CreateCode (TRI_aql_codegen_js_t* generator) {
TRI_aql_codegen_register_t startRegister = IncRegister(generator); TRI_aql_codegen_register_t startRegister = IncRegister(generator);
TRI_vector_pointer_t* statements; std::vector<TRI_aql_node_t*>* statements;
size_t i, n; size_t i, n;
StartScope(generator, &generator->_buffer, TRI_AQL_SCOPE_MAIN, 0, 0, 0, startRegister, NULL); StartScope(generator, &generator->_buffer, TRI_AQL_SCOPE_MAIN, 0, 0, 0, startRegister, NULL);
@ -2997,11 +2997,11 @@ static TRI_aql_codegen_register_t CreateCode (TRI_aql_codegen_js_t* generator) {
InitList(generator, startRegister); InitList(generator, startRegister);
statements = &generator->_context->_statements->_statements; statements = &generator->_context->_statements->_statements;
n = statements->_length; n = statements->size();
for (i = 0; i < n; ++i) { for (i = 0; i < n; ++i) {
TRI_aql_node_t* node; TRI_aql_node_t* node;
node = static_cast<TRI_aql_node_t*>(TRI_AtVectorPointer(statements, i)); node = statements->at(i);
ProcessNode(generator, node); ProcessNode(generator, node);
} }

View File

@ -131,7 +131,7 @@ static void FreeNodes (TRI_aql_context_t* const context) {
} }
// free node itself // free node itself
TRI_Free(TRI_UNKNOWN_MEM_ZONE, node); delete node;
} }
TRI_DestroyVectorPointer(&context->_memory._nodes); TRI_DestroyVectorPointer(&context->_memory._nodes);

View File

@ -37,7 +37,7 @@
#include "Ahuacatl/ahuacatl-error.h" #include "Ahuacatl/ahuacatl-error.h"
#include "Ahuacatl/ahuacatl-statementlist.h" #include "Ahuacatl/ahuacatl-statementlist.h"
struct TRI_aql_node_s; struct TRI_aql_node_t;
struct TRI_aql_parser_s; struct TRI_aql_parser_s;
struct TRI_json_s; struct TRI_json_s;
struct TRI_vocbase_s; struct TRI_vocbase_s;
@ -94,7 +94,7 @@ typedef struct TRI_aql_context_s {
TRI_aql_query_type_e _type; TRI_aql_query_type_e _type;
char* _writeCollection; char* _writeCollection;
struct TRI_aql_node_s* _writeOptions; struct TRI_aql_node_t* _writeOptions;
struct TRI_json_s* _userOptions; struct TRI_json_s* _userOptions;
bool _fullCount; bool _fullCount;

View File

@ -211,12 +211,11 @@ TRI_aql_value_t;
/// @brief an abstract AST node type /// @brief an abstract AST node type
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
typedef struct TRI_aql_node_s { struct TRI_aql_node_t {
TRI_vector_pointer_t _members; TRI_vector_pointer_t _members;
TRI_aql_node_type_e _type; TRI_aql_node_type_e _type;
TRI_aql_value_t _value; TRI_aql_value_t _value;
} };
TRI_aql_node_t;
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// --SECTION-- public functions // --SECTION-- public functions

View File

@ -32,7 +32,7 @@
#include "Basics/Common.h" #include "Basics/Common.h"
struct TRI_aql_statement_list_s; struct TRI_aql_statement_list_t;
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// --SECTION-- public types // --SECTION-- public types
@ -55,7 +55,7 @@ TRI_aql_dump_t;
/// @brief dump statement list /// @brief dump statement list
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void TRI_DumpStatementsAql (struct TRI_aql_statement_list_s* const); void TRI_DumpStatementsAql (struct TRI_aql_statement_list_t* const);
#endif #endif

View File

@ -53,7 +53,7 @@ static void VisitStatement (TRI_aql_statement_walker_t* const walker,
TRI_aql_node_t* node; TRI_aql_node_t* node;
TRI_aql_node_t* modified; TRI_aql_node_t* modified;
node = (TRI_aql_node_t*) TRI_AtVectorPointer(&walker->_statements->_statements, position); node = walker->_statements->_statements[position];
TRI_ASSERT(node); TRI_ASSERT(node);
modified = func(walker, node); modified = func(walker, node);
@ -62,7 +62,7 @@ static void VisitStatement (TRI_aql_statement_walker_t* const walker,
modified = TRI_GetDummyNopNodeAql(); modified = TRI_GetDummyNopNodeAql();
} }
walker->_statements->_statements._buffer[position] = modified; walker->_statements->_statements[position] = modified;
} }
} }
@ -108,13 +108,13 @@ static void RunWalk (TRI_aql_statement_walker_t* const walker) {
size_t i, n; size_t i, n;
TRI_ASSERT(walker); TRI_ASSERT(walker);
n = walker->_statements->_statements._length; n = walker->_statements->_statements.size();
for (i = 0; i < n; ++i) { for (i = 0; i < n; ++i) {
TRI_aql_node_t* node; TRI_aql_node_t* node;
TRI_aql_node_type_e nodeType; TRI_aql_node_type_e nodeType;
node = (TRI_aql_node_t*) TRI_AtVectorPointer(&walker->_statements->_statements, i); node = walker->_statements->_statements[i];
if (! node) { if (! node) {
continue; continue;
@ -131,8 +131,7 @@ static void RunWalk (TRI_aql_statement_walker_t* const walker) {
if (walker->preVisitStatement != NULL) { if (walker->preVisitStatement != NULL) {
// this might change the node ptr // this might change the node ptr
VisitStatement(walker, i, walker->preVisitStatement); VisitStatement(walker, i, walker->preVisitStatement);
node = static_cast<TRI_aql_node_t*> node = walker->_statements->_statements[i];
(walker->_statements->_statements._buffer[i]);
} }

View File

@ -60,7 +60,7 @@ static TRI_aql_node_t* DummyReturnEmptyNode;
static inline TRI_aql_node_t* StatementAt (const TRI_aql_statement_list_t* const list, static inline TRI_aql_node_t* StatementAt (const TRI_aql_statement_list_t* const list,
const size_t position) { const size_t position) {
return (TRI_aql_node_t*) TRI_AtVectorPointer(&list->_statements, position); return list->_statements[position];
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -73,7 +73,7 @@ static size_t InvalidateEmptyScope (TRI_aql_statement_list_t* const list,
size_t scopes; size_t scopes;
TRI_ASSERT(list); TRI_ASSERT(list);
n = list->_statements._length; n = list->_statements.size();
i = position; i = position;
scopes = 0; scopes = 0;
@ -83,10 +83,10 @@ static size_t InvalidateEmptyScope (TRI_aql_statement_list_t* const list,
if (i == position) { if (i == position) {
TRI_ASSERT(type == TRI_AQL_NODE_SCOPE_START); TRI_ASSERT(type == TRI_AQL_NODE_SCOPE_START);
list->_statements._buffer[i] = DummyReturnEmptyNode; list->_statements[i] = DummyReturnEmptyNode;
} }
else { else {
list->_statements._buffer[i] = TRI_GetDummyNopNodeAql(); list->_statements[i] = TRI_GetDummyNopNodeAql();
} }
++i; ++i;
@ -118,13 +118,17 @@ static size_t InvalidateEmptyScope (TRI_aql_statement_list_t* const list,
TRI_aql_statement_list_t* TRI_CreateStatementListAql (void) { TRI_aql_statement_list_t* TRI_CreateStatementListAql (void) {
TRI_aql_statement_list_t* list; TRI_aql_statement_list_t* list;
list = (TRI_aql_statement_list_t*) TRI_Allocate(TRI_UNKNOWN_MEM_ZONE, sizeof(TRI_aql_statement_list_t), false); try {
list = new TRI_aql_statement_list_t();
}
catch (std::exception&) {
list = nullptr;
}
if (list == NULL) { if (list == NULL) {
return NULL; return NULL;
} }
TRI_InitVectorPointer(&list->_statements, TRI_UNKNOWN_MEM_ZONE);
list->_currentLevel = 0; list->_currentLevel = 0;
return list; return list;
@ -139,8 +143,7 @@ void TRI_FreeStatementListAql (TRI_aql_statement_list_t* const list) {
return; return;
} }
TRI_DestroyVectorPointer(&list->_statements); delete list;
TRI_Free(TRI_UNKNOWN_MEM_ZONE, list);
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
@ -163,17 +166,17 @@ void TRI_GlobalInitStatementListAql (void) {
void TRI_GlobalFreeStatementListAql (void) { void TRI_GlobalFreeStatementListAql (void) {
if (DummyNopNode != NULL) { if (DummyNopNode != NULL) {
TRI_DestroyVectorPointer(&DummyNopNode->_members); TRI_DestroyVectorPointer(&DummyNopNode->_members);
TRI_Free(TRI_UNKNOWN_MEM_ZONE, DummyNopNode); delete DummyNopNode;
} }
if (DummyReturnEmptyNode != NULL) { if (DummyReturnEmptyNode != NULL) {
TRI_aql_node_t* list = TRI_AQL_NODE_MEMBER(DummyReturnEmptyNode, 0); TRI_aql_node_t* list = TRI_AQL_NODE_MEMBER(DummyReturnEmptyNode, 0);
TRI_DestroyVectorPointer(&list->_members); TRI_DestroyVectorPointer(&list->_members);
TRI_Free(TRI_UNKNOWN_MEM_ZONE, list); delete list;
TRI_DestroyVectorPointer(&DummyReturnEmptyNode->_members); TRI_DestroyVectorPointer(&DummyReturnEmptyNode->_members);
TRI_Free(TRI_UNKNOWN_MEM_ZONE, DummyReturnEmptyNode); delete DummyReturnEmptyNode;
} }
} }
@ -200,7 +203,7 @@ void TRI_PulloutStatementListAql (TRI_aql_statement_list_t* const list) {
TRI_ASSERT(list); TRI_ASSERT(list);
i = 0; i = 0;
n = list->_statements._length; n = list->_statements.size();
while (i < n) { while (i < n) {
TRI_aql_node_t* node = StatementAt(list, i); TRI_aql_node_t* node = StatementAt(list, i);
@ -245,7 +248,7 @@ void TRI_PulloutStatementListAql (TRI_aql_statement_list_t* const list) {
} }
// insert a dummy node in place of the moved node // insert a dummy node in place of the moved node
list->_statements._buffer[j + inserted + 1] = TRI_GetDummyNopNodeAql(); list->_statements[j + inserted + 1] = TRI_GetDummyNopNodeAql();
// next // next
++j; ++j;
@ -272,14 +275,16 @@ void TRI_PulloutStatementListAql (TRI_aql_statement_list_t* const list) {
bool TRI_InsertStatementListAql (TRI_aql_statement_list_t* const list, bool TRI_InsertStatementListAql (TRI_aql_statement_list_t* const list,
TRI_aql_node_t* const node, TRI_aql_node_t* const node,
const size_t position) { const size_t position) {
int res;
TRI_ASSERT(list != NULL); TRI_ASSERT(list != NULL);
TRI_ASSERT(node != NULL); TRI_ASSERT(node != NULL);
res = TRI_InsertVectorPointer(&list->_statements, node, position); try {
list->_statements.insert(list->_statements.begin() + position, node);
return res == TRI_ERROR_NO_ERROR; }
catch (std::exception&) {
return false;
}
return true;
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -289,7 +294,6 @@ bool TRI_InsertStatementListAql (TRI_aql_statement_list_t* const list,
bool TRI_AppendStatementListAql (TRI_aql_statement_list_t* const list, bool TRI_AppendStatementListAql (TRI_aql_statement_list_t* const list,
TRI_aql_node_t* const node) { TRI_aql_node_t* const node) {
TRI_aql_node_type_e type; TRI_aql_node_type_e type;
int res;
TRI_ASSERT(list != NULL); TRI_ASSERT(list != NULL);
TRI_ASSERT(node != NULL); TRI_ASSERT(node != NULL);
@ -305,9 +309,13 @@ bool TRI_AppendStatementListAql (TRI_aql_statement_list_t* const list,
--list->_currentLevel; --list->_currentLevel;
} }
res = TRI_PushBackVectorPointer(&list->_statements, node); try {
list->_statements.push_back(node);
return res == TRI_ERROR_NO_ERROR; }
catch (std::exception&) {
return false;
}
return true;
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -321,7 +329,7 @@ void TRI_CompactStatementListAql (TRI_aql_statement_list_t* const list) {
i = 0; i = 0;
j = 0; j = 0;
n = list->_statements._length; n = list->_statements.size();
while (i < n) { while (i < n) {
TRI_aql_node_t* node = StatementAt(list, i); TRI_aql_node_t* node = StatementAt(list, i);
@ -347,11 +355,11 @@ void TRI_CompactStatementListAql (TRI_aql_statement_list_t* const list) {
} }
*/ */
list->_statements._buffer[j++] = node; list->_statements[j++] = node;
++i; ++i;
} }
list->_statements._length = j; list->_statements.resize(j);
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------

View File

@ -33,17 +33,16 @@
#include "Basics/Common.h" #include "Basics/Common.h"
#include "BasicsC/vector.h" #include "BasicsC/vector.h"
struct TRI_aql_node_s; struct TRI_aql_node_t;
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// --SECTION-- public types // --SECTION-- public types
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
typedef struct TRI_aql_statement_list_s { struct TRI_aql_statement_list_t {
TRI_vector_pointer_t _statements; std::vector<struct TRI_aql_node_t*> _statements;
size_t _currentLevel; size_t _currentLevel;
} };
TRI_aql_statement_list_t;
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// --SECTION-- constructors / destructors // --SECTION-- constructors / destructors
@ -81,7 +80,7 @@ void TRI_FreeStatementListAql (TRI_aql_statement_list_t* const);
/// @brief get the address of the dummy non-op node /// @brief get the address of the dummy non-op node
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
struct TRI_aql_node_s* TRI_GetDummyNopNodeAql (void); struct TRI_aql_node_t* TRI_GetDummyNopNodeAql (void);
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
/// @brief pull out subqueries in the statement list from the middle to the /// @brief pull out subqueries in the statement list from the middle to the
@ -104,7 +103,7 @@ void TRI_CompactStatementListAql (TRI_aql_statement_list_t* const);
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
bool TRI_InsertStatementListAql (TRI_aql_statement_list_t* const, bool TRI_InsertStatementListAql (TRI_aql_statement_list_t* const,
struct TRI_aql_node_s* const, struct TRI_aql_node_t* const,
const size_t); const size_t);
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -112,7 +111,7 @@ bool TRI_InsertStatementListAql (TRI_aql_statement_list_t* const,
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
bool TRI_AppendStatementListAql (TRI_aql_statement_list_t* const, bool TRI_AppendStatementListAql (TRI_aql_statement_list_t* const,
struct TRI_aql_node_s* const); struct TRI_aql_node_t* const);
#endif #endif