diff --git a/Ahuacatl/ahuacatl-context.c b/Ahuacatl/ahuacatl-context.c index 93d7658993..5bd89f4dea 100644 --- a/Ahuacatl/ahuacatl-context.c +++ b/Ahuacatl/ahuacatl-context.c @@ -54,42 +54,6 @@ /// @} //////////////////////////////////////////////////////////////////////////////// -// ----------------------------------------------------------------------------- -// --SECTION-- private functions -// ----------------------------------------------------------------------------- - -//////////////////////////////////////////////////////////////////////////////// -/// @addtogroup Ahuacatl -/// @{ -//////////////////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////////////////// -/// @brief hash variable -//////////////////////////////////////////////////////////////////////////////// - -static uint64_t HashVariable (TRI_associative_pointer_t* array, - void const* element) { - TRI_aql_variable_t* variable = (TRI_aql_variable_t*) element; - - return TRI_FnvHashString(variable->_name); -} - -//////////////////////////////////////////////////////////////////////////////// -/// @brief comparison function used to determine variable equality -//////////////////////////////////////////////////////////////////////////////// - -static bool EqualVariable (TRI_associative_pointer_t* array, - void const* key, - void const* element) { - TRI_aql_variable_t* variable = (TRI_aql_variable_t*) element; - - return TRI_EqualString(key, variable->_name); -} - -//////////////////////////////////////////////////////////////////////////////// -/// @} -//////////////////////////////////////////////////////////////////////////////// - // ----------------------------------------------------------------------------- // --SECTION-- constructors / destructors // ----------------------------------------------------------------------------- @@ -353,8 +317,8 @@ TRI_aql_scope_t* TRI_CreateScopeAql (void) { TRI_InitAssociativePointer(&scope->_variables, TRI_UNKNOWN_MEM_ZONE, TRI_HashStringKeyAssociativePointer, - HashVariable, - EqualVariable, + TRI_HashVariableAql, + TRI_EqualVariableAql, 0); scope->_first = NULL; @@ -620,41 +584,6 @@ bool TRI_AddVariableContextAql (TRI_aql_context_t* const context, const char* na return true; } -//////////////////////////////////////////////////////////////////////////////// -/// @brief register a new variable -//////////////////////////////////////////////////////////////////////////////// - -TRI_aql_variable_t* TRI_CreateVariableAql (const char* const name) { - TRI_aql_variable_t* variable; - - variable = (TRI_aql_variable_t*) TRI_Allocate(TRI_UNKNOWN_MEM_ZONE, sizeof(TRI_aql_variable_t), false); - if (!variable) { - return NULL; - } - - variable->_name = TRI_DuplicateString(name); - if (!variable->_name) { - TRI_FreeVariableAql(variable); - return NULL; - } - - return variable; -} - -//////////////////////////////////////////////////////////////////////////////// -/// @brief free an existing variable -//////////////////////////////////////////////////////////////////////////////// - -void TRI_FreeVariableAql (TRI_aql_variable_t* const variable) { - assert(variable); - - if (variable->_name) { - TRI_Free(TRI_UNKNOWN_MEM_ZONE, variable->_name); - } - - TRI_Free(TRI_UNKNOWN_MEM_ZONE, variable); -} - //////////////////////////////////////////////////////////////////////////////// /// @brief register a string //////////////////////////////////////////////////////////////////////////////// @@ -710,27 +639,6 @@ bool TRI_VariableExistsAql (TRI_aql_context_t* const context, return false; } -//////////////////////////////////////////////////////////////////////////////// -/// @brief checks if a variable name follows the required naming convention -//////////////////////////////////////////////////////////////////////////////// - -bool TRI_IsValidVariableNameAql (const char* const name) { - assert(name); - - if (strlen(name) == 0) { - // name must be at least one char long - return false; - } - - if (*name == '_') { - // name must not start with an underscore - return false; - } - - // everything else is allowed - return true; -} - //////////////////////////////////////////////////////////////////////////////// /// @} //////////////////////////////////////////////////////////////////////////////// diff --git a/Ahuacatl/ahuacatl-context.h b/Ahuacatl/ahuacatl-context.h index c91b5428de..aa7353da96 100644 --- a/Ahuacatl/ahuacatl-context.h +++ b/Ahuacatl/ahuacatl-context.h @@ -40,6 +40,7 @@ #include "Ahuacatl/ahuacatl-error.h" #include "Ahuacatl/ahuacatl-parser.h" +#include "Ahuacatl/ahuacatl-variable.h" #ifdef __cplusplus extern "C" { @@ -54,15 +55,6 @@ extern "C" { /// @{ //////////////////////////////////////////////////////////////////////////////// -//////////////////////////////////////////////////////////////////////////////// -/// @brief a query variable -//////////////////////////////////////////////////////////////////////////////// - -typedef struct TRI_aql_variable_s { - char* _name; -} -TRI_aql_variable_t; - //////////////////////////////////////////////////////////////////////////////// /// @brief a variable scope //////////////////////////////////////////////////////////////////////////////// @@ -114,7 +106,7 @@ TRI_aql_context_t; //////////////////////////////////////////////////////////////////////////////// TRI_aql_context_t* TRI_CreateContextAql (TRI_vocbase_t*, - const char* const); + const char* const); //////////////////////////////////////////////////////////////////////////////// /// @brief free a context @@ -227,18 +219,6 @@ bool TRI_ExchangeScopeContextAql (TRI_aql_context_t* const context); bool TRI_AddVariableContextAql (TRI_aql_context_t* const, const char*); -//////////////////////////////////////////////////////////////////////////////// -/// @brief register a new variable -//////////////////////////////////////////////////////////////////////////////// - -TRI_aql_variable_t* TRI_CreateVariableAql (const char* const); - -//////////////////////////////////////////////////////////////////////////////// -/// @brief free an existing variable -//////////////////////////////////////////////////////////////////////////////// - -void TRI_FreeVariableAql (TRI_aql_variable_t* const); - //////////////////////////////////////////////////////////////////////////////// /// @brief register a string //////////////////////////////////////////////////////////////////////////////// @@ -253,12 +233,6 @@ char* TRI_RegisterStringAql (TRI_aql_context_t* const, bool TRI_VariableExistsAql (TRI_aql_context_t* const, const char* const); -//////////////////////////////////////////////////////////////////////////////// -/// @brief checks if a variable name follows the required naming convention -//////////////////////////////////////////////////////////////////////////////// - -bool TRI_IsValidVariableNameAql (const char* const); - //////////////////////////////////////////////////////////////////////////////// /// @} //////////////////////////////////////////////////////////////////////////////// diff --git a/Ahuacatl/ahuacatl-variable.c b/Ahuacatl/ahuacatl-variable.c new file mode 100644 index 0000000000..a00d323af7 --- /dev/null +++ b/Ahuacatl/ahuacatl-variable.c @@ -0,0 +1,139 @@ +//////////////////////////////////////////////////////////////////////////////// +/// @brief Ahuacatl, variables +/// +/// @file +/// +/// DISCLAIMER +/// +/// Copyright 2010-2012 triagens GmbH, Cologne, Germany +/// +/// Licensed under the Apache License, Version 2.0 (the "License"); +/// you may not use this file except in compliance with the License. +/// You may obtain a copy of the License at +/// +/// http://www.apache.org/licenses/LICENSE-2.0 +/// +/// Unless required by applicable law or agreed to in writing, software +/// distributed under the License is distributed on an "AS IS" BASIS, +/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +/// See the License for the specific language governing permissions and +/// limitations under the License. +/// +/// Copyright holder is triAGENS GmbH, Cologne, Germany +/// +/// @author Jan Steemann +/// @author Copyright 2012, triagens GmbH, Cologne, Germany +//////////////////////////////////////////////////////////////////////////////// + +#include "Ahuacatl/ahuacatl-variable.h" + +// ----------------------------------------------------------------------------- +// --SECTION-- constructors / destructors +// ----------------------------------------------------------------------------- + +//////////////////////////////////////////////////////////////////////////////// +/// @addtogroup Ahuacatl +/// @{ +//////////////////////////////////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////////////////////////// +/// @brief register a new variable +//////////////////////////////////////////////////////////////////////////////// + +TRI_aql_variable_t* TRI_CreateVariableAql (const char* const name) { + TRI_aql_variable_t* variable; + + variable = (TRI_aql_variable_t*) TRI_Allocate(TRI_UNKNOWN_MEM_ZONE, sizeof(TRI_aql_variable_t), false); + if (!variable) { + return NULL; + } + + variable->_name = TRI_DuplicateString(name); + if (!variable->_name) { + TRI_FreeVariableAql(variable); + return NULL; + } + + return variable; +} + +//////////////////////////////////////////////////////////////////////////////// +/// @brief free an existing variable +//////////////////////////////////////////////////////////////////////////////// + +void TRI_FreeVariableAql (TRI_aql_variable_t* const variable) { + assert(variable); + + if (variable->_name) { + TRI_Free(TRI_UNKNOWN_MEM_ZONE, variable->_name); + } + + TRI_Free(TRI_UNKNOWN_MEM_ZONE, variable); +} + +//////////////////////////////////////////////////////////////////////////////// +/// @} +//////////////////////////////////////////////////////////////////////////////// + +// ----------------------------------------------------------------------------- +// --SECTION-- public functions +// ----------------------------------------------------------------------------- + +//////////////////////////////////////////////////////////////////////////////// +/// @addtogroup Ahuacatl +/// @{ +//////////////////////////////////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////////////////////////// +/// @brief hash variable +//////////////////////////////////////////////////////////////////////////////// + +uint64_t TRI_HashVariableAql (TRI_associative_pointer_t* array, + void const* element) { + TRI_aql_variable_t* variable = (TRI_aql_variable_t*) element; + + return TRI_FnvHashString(variable->_name); +} + +//////////////////////////////////////////////////////////////////////////////// +/// @brief comparison function used to determine variable equality +//////////////////////////////////////////////////////////////////////////////// + +bool TRI_EqualVariableAql (TRI_associative_pointer_t* array, + void const* key, + void const* element) { + TRI_aql_variable_t* variable = (TRI_aql_variable_t*) element; + + return TRI_EqualString(key, variable->_name); +} + + +//////////////////////////////////////////////////////////////////////////////// +/// @brief checks if a variable name follows the required naming convention +//////////////////////////////////////////////////////////////////////////////// + +bool TRI_IsValidVariableNameAql (const char* const name) { + assert(name); + + if (strlen(name) == 0) { + // name must be at least one char long + return false; + } + + if (*name == '_') { + // name must not start with an underscore + return false; + } + + // everything else is allowed + return true; +} + +//////////////////////////////////////////////////////////////////////////////// +/// @} +//////////////////////////////////////////////////////////////////////////////// + +// Local Variables: +// mode: outline-minor +// outline-regexp: "^\\(/// @brief\\|/// {@inheritDoc}\\|/// @addtogroup\\|// --SECTION--\\|/// @\\}\\)" +// End: diff --git a/Ahuacatl/ahuacatl-variable.h b/Ahuacatl/ahuacatl-variable.h new file mode 100644 index 0000000000..925233d542 --- /dev/null +++ b/Ahuacatl/ahuacatl-variable.h @@ -0,0 +1,129 @@ +//////////////////////////////////////////////////////////////////////////////// +/// @brief Ahuacatl, variables +/// +/// @file +/// +/// DISCLAIMER +/// +/// Copyright 2010-2012 triagens GmbH, Cologne, Germany +/// +/// Licensed under the Apache License, Version 2.0 (the "License"); +/// you may not use this file except in compliance with the License. +/// You may obtain a copy of the License at +/// +/// http://www.apache.org/licenses/LICENSE-2.0 +/// +/// Unless required by applicable law or agreed to in writing, software +/// distributed under the License is distributed on an "AS IS" BASIS, +/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +/// See the License for the specific language governing permissions and +/// limitations under the License. +/// +/// Copyright holder is triAGENS GmbH, Cologne, Germany +/// +/// @author Jan Steemann +/// @author Copyright 2012, triagens GmbH, Cologne, Germany +//////////////////////////////////////////////////////////////////////////////// + +#ifndef TRIAGENS_DURHAM_AHUACATL_VARIABLE_H +#define TRIAGENS_DURHAM_AHUACATL_VARIABLE_H 1 + +#include +#include +#include +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +// ----------------------------------------------------------------------------- +// --SECTION-- public types +// ----------------------------------------------------------------------------- + +//////////////////////////////////////////////////////////////////////////////// +/// @addtogroup Ahuacatl +/// @{ +//////////////////////////////////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////////////////////////// +/// @brief a query variable +//////////////////////////////////////////////////////////////////////////////// + +typedef struct TRI_aql_variable_s { + char* _name; +} +TRI_aql_variable_t; + +//////////////////////////////////////////////////////////////////////////////// +/// @} +//////////////////////////////////////////////////////////////////////////////// + +// ----------------------------------------------------------------------------- +// --SECTION-- constructors / destructors +// ----------------------------------------------------------------------------- + +//////////////////////////////////////////////////////////////////////////////// +/// @addtogroup Ahuacatl +/// @{ +//////////////////////////////////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////////////////////////// +/// @brief register a new variable +//////////////////////////////////////////////////////////////////////////////// + +TRI_aql_variable_t* TRI_CreateVariableAql (const char* const); + +//////////////////////////////////////////////////////////////////////////////// +/// @brief free an existing variable +//////////////////////////////////////////////////////////////////////////////// + +void TRI_FreeVariableAql (TRI_aql_variable_t* const); + +//////////////////////////////////////////////////////////////////////////////// +/// @} +//////////////////////////////////////////////////////////////////////////////// + +// ----------------------------------------------------------------------------- +// --SECTION-- public functions +// ----------------------------------------------------------------------------- + +//////////////////////////////////////////////////////////////////////////////// +/// @addtogroup Ahuacatl +/// @{ +//////////////////////////////////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////////////////////////// +/// @brief hash variable +//////////////////////////////////////////////////////////////////////////////// + +uint64_t TRI_HashVariableAql (TRI_associative_pointer_t*, void const*); + +//////////////////////////////////////////////////////////////////////////////// +/// @brief comparison function used to determine variable equality +//////////////////////////////////////////////////////////////////////////////// + +bool TRI_EqualVariableAql (TRI_associative_pointer_t*, void const*, void const*); + +//////////////////////////////////////////////////////////////////////////////// +/// @brief checks if a variable name follows the required naming convention +//////////////////////////////////////////////////////////////////////////////// + +bool TRI_IsValidVariableNameAql (const char* const); + +//////////////////////////////////////////////////////////////////////////////// +/// @} +//////////////////////////////////////////////////////////////////////////////// + +#ifdef __cplusplus +} +#endif + +#endif + +// Local Variables: +// mode: outline-minor +// outline-regexp: "^\\(/// @brief\\|/// {@inheritDoc}\\|/// @addtogroup\\|// --SECTION--\\|/// @\\}\\)" +// End: diff --git a/Makefile.files b/Makefile.files index 3f5e7d2e2b..0a6ea18a7c 100644 --- a/Makefile.files +++ b/Makefile.files @@ -165,6 +165,7 @@ avocado_SOURCES = \ Ahuacatl/ahuacatl-tokens.c \ Ahuacatl/ahuacatl-tree-dump.c \ Ahuacatl/ahuacatl-tree-walker.c \ + Ahuacatl/ahuacatl-variable.c \ Ahuacatl/ast-codegen-js.c \ QL/ast-query.c \ QL/formatter.c \ diff --git a/Makefile.in b/Makefile.in index 0270dced60..387d819d94 100644 --- a/Makefile.in +++ b/Makefile.in @@ -346,6 +346,7 @@ am_avocado_OBJECTS = Admin/ApplicationAdminServer.$(OBJEXT) \ Ahuacatl/ahuacatl-tokens.$(OBJEXT) \ Ahuacatl/ahuacatl-tree-dump.$(OBJEXT) \ Ahuacatl/ahuacatl-tree-walker.$(OBJEXT) \ + Ahuacatl/ahuacatl-variable.$(OBJEXT) \ Ahuacatl/ast-codegen-js.$(OBJEXT) QL/ast-query.$(OBJEXT) \ QL/formatter.$(OBJEXT) QL/optimize.$(OBJEXT) \ QL/parser.$(OBJEXT) QL/tokens.$(OBJEXT) \ @@ -779,6 +780,7 @@ avocado_SOURCES = \ Ahuacatl/ahuacatl-tokens.c \ Ahuacatl/ahuacatl-tree-dump.c \ Ahuacatl/ahuacatl-tree-walker.c \ + Ahuacatl/ahuacatl-variable.c \ Ahuacatl/ast-codegen-js.c \ QL/ast-query.c \ QL/formatter.c \ @@ -1693,6 +1695,8 @@ Ahuacatl/ahuacatl-tree-dump.$(OBJEXT): Ahuacatl/$(am__dirstamp) \ Ahuacatl/$(DEPDIR)/$(am__dirstamp) Ahuacatl/ahuacatl-tree-walker.$(OBJEXT): Ahuacatl/$(am__dirstamp) \ Ahuacatl/$(DEPDIR)/$(am__dirstamp) +Ahuacatl/ahuacatl-variable.$(OBJEXT): Ahuacatl/$(am__dirstamp) \ + Ahuacatl/$(DEPDIR)/$(am__dirstamp) Ahuacatl/ast-codegen-js.$(OBJEXT): Ahuacatl/$(am__dirstamp) \ Ahuacatl/$(DEPDIR)/$(am__dirstamp) QL/$(am__dirstamp): @@ -1949,6 +1953,7 @@ mostlyclean-compile: -rm -f Ahuacatl/ahuacatl-tokens.$(OBJEXT) -rm -f Ahuacatl/ahuacatl-tree-dump.$(OBJEXT) -rm -f Ahuacatl/ahuacatl-tree-walker.$(OBJEXT) + -rm -f Ahuacatl/ahuacatl-variable.$(OBJEXT) -rm -f Ahuacatl/ast-codegen-js.$(OBJEXT) -rm -f ApplicationServer/ApplicationServer.$(OBJEXT) -rm -f ApplicationServer/ApplicationServerImpl.$(OBJEXT) @@ -2187,6 +2192,7 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@Ahuacatl/$(DEPDIR)/ahuacatl-tokens.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@Ahuacatl/$(DEPDIR)/ahuacatl-tree-dump.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@Ahuacatl/$(DEPDIR)/ahuacatl-tree-walker.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@Ahuacatl/$(DEPDIR)/ahuacatl-variable.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@Ahuacatl/$(DEPDIR)/ast-codegen-js.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@ApplicationServer/$(DEPDIR)/ApplicationServer.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@ApplicationServer/$(DEPDIR)/ApplicationServerImpl.Po@am__quote@