1
0
Fork 0

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

This commit is contained in:
Max Neunhoeffer 2014-07-28 15:13:58 +02:00
commit c9026aa176
8 changed files with 75 additions and 30 deletions

View File

@ -28,6 +28,7 @@
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
#include "Aql/AstNode.h" #include "Aql/AstNode.h"
#include "Aql/Scopes.h"
using namespace triagens::aql; using namespace triagens::aql;
@ -74,8 +75,7 @@ void AstNode::toJson (TRI_json_t* json,
// dump node type // dump node type
TRI_Insert3ArrayJson(zone, node, "type", TRI_CreateStringCopyJson(zone, typeString().c_str())); TRI_Insert3ArrayJson(zone, node, "type", TRI_CreateStringCopyJson(zone, typeString().c_str()));
if (type == NODE_TYPE_VARIABLE || if (type == NODE_TYPE_REFERENCE ||
type == NODE_TYPE_REFERENCE ||
type == NODE_TYPE_COLLECTION || type == NODE_TYPE_COLLECTION ||
type == NODE_TYPE_PARAMETER || type == NODE_TYPE_PARAMETER ||
type == NODE_TYPE_ATTRIBUTE_ACCESS || type == NODE_TYPE_ATTRIBUTE_ACCESS ||
@ -108,6 +108,13 @@ void AstNode::toJson (TRI_json_t* json,
} }
} }
if (type == NODE_TYPE_VARIABLE) {
auto variable = static_cast<Variable*>(getData());
TRI_Insert3ArrayJson(zone, node, "name", TRI_CreateStringCopyJson(zone, variable->name.c_str()));
TRI_Insert3ArrayJson(zone, node, "id", TRI_CreateNumberJson(zone, static_cast<double>(variable->id)));
}
// dump sub-nodes // dump sub-nodes
size_t const n = members._length; size_t const n = members._length;

View File

@ -61,6 +61,7 @@ namespace triagens {
double _double; double _double;
bool _bool; bool _bool;
char const* _string; char const* _string;
void* _data;
} value; } value;
AstNodeValueType type; AstNodeValueType type;
}; };
@ -287,6 +288,22 @@ namespace triagens {
value.value._string = v; value.value._string = v;
} }
////////////////////////////////////////////////////////////////////////////////
/// @brief return the data value of a node
////////////////////////////////////////////////////////////////////////////////
inline void* getData () const {
return value.value._data;
}
////////////////////////////////////////////////////////////////////////////////
/// @brief set the data value of a node
////////////////////////////////////////////////////////////////////////////////
inline void setData (void* v) {
value.value._data = v;
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
/// @brief return the type name of a node /// @brief return the type name of a node
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -299,9 +316,12 @@ namespace triagens {
public: public:
TRI_vector_pointer_t members;
AstNodeType const type; AstNodeType const type;
AstNodeValue value; AstNodeValue value;
private:
TRI_vector_pointer_t members;
}; };
} }

View File

@ -41,14 +41,18 @@ namespace triagens {
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
struct ParseResult { struct ParseResult {
ParseResult () = delete;
ParseResult& operator= (ParseResult const& other) = delete;
ParseResult (ParseResult&& other) { ParseResult (ParseResult&& other) {
code = other.code;
explanation = other.explanation;
json = other.json; json = other.json;
zone = other.zone; zone = other.zone;
other.json = nullptr; other.json = nullptr;
} }
ParseResult& operator= (ParseResult const& other) = delete;
ParseResult (int code, ParseResult (int code,
std::string const& explanation) std::string const& explanation)
: code(code), : code(code),
@ -58,7 +62,9 @@ namespace triagens {
} }
ParseResult (TRI_memory_zone_t* zone) ParseResult (TRI_memory_zone_t* zone)
: zone(zone), : code(TRI_ERROR_NO_ERROR),
explanation(),
zone(zone),
json(nullptr) { json(nullptr) {
} }

View File

@ -128,6 +128,7 @@ ParseResult Parser::parse () {
auto error = _query->error(); auto error = _query->error();
result.code = error->code; result.code = error->code;
result.explanation = error->explanation; result.explanation = error->explanation;
return result; return result;
} }

View File

@ -103,7 +103,7 @@ TRI_json_t* QueryAst::toJson (TRI_memory_zone_t* zone) {
void QueryAst::addOperation (AstNode* node) { void QueryAst::addOperation (AstNode* node) {
TRI_ASSERT(_root != nullptr); TRI_ASSERT(_root != nullptr);
TRI_PushBackVectorPointer(&_root->members, (void*) node); _root->addMember(node);
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -352,7 +352,8 @@ AstNode* QueryAst::createNodeVariable (char const* name,
AstNode* node = createNode(NODE_TYPE_VARIABLE); AstNode* node = createNode(NODE_TYPE_VARIABLE);
node->setStringValue(name); node->setStringValue(name);
_scopes.addVariable(name, isUserDefined); auto variable = _scopes.addVariable(name, isUserDefined);
node->setData(static_cast<void*>(variable));
return node; return node;
} }
@ -667,9 +668,22 @@ void QueryAst::injectBindParameters (BindParameters& parameters) {
// collection parameter // collection parameter
TRI_ASSERT(TRI_IsStringJson(value)); TRI_ASSERT(TRI_IsStringJson(value));
bool isWriteCollection = false;
if (_writeCollection != nullptr &&
_writeCollection->type == NODE_TYPE_PARAMETER &&
strcmp(param, _writeCollection->getStringValue()) == 0) {
isWriteCollection = true;
}
// turn node into a collection node // turn node into a collection node
char const* name = registerString(value->_value._string.data, value->_value._string.length - 1, false); char const* name = registerString(value->_value._string.data, value->_value._string.length - 1, false);
node = createNodeCollection(name); node = createNodeCollection(name);
if (isWriteCollection) {
// this was the bind parameter that contained the collection to update
_writeCollection = node;
}
} }
else { else {
node = nodeFromJson((*it).second); node = nodeFromJson((*it).second);

View File

@ -112,6 +112,7 @@ namespace triagens {
inline void setWriteCollection (AstNode const* node) { inline void setWriteCollection (AstNode const* node) {
TRI_ASSERT(node->type == NODE_TYPE_COLLECTION || TRI_ASSERT(node->type == NODE_TYPE_COLLECTION ||
node->type == NODE_TYPE_PARAMETER); node->type == NODE_TYPE_PARAMETER);
_writeCollection = node; _writeCollection = node;
} }

View File

@ -82,7 +82,7 @@ std::string Scope::typeName () const {
/// @brief adds a variable to the scope /// @brief adds a variable to the scope
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void Scope::addVariable (std::string const& name, Variable* Scope::addVariable (std::string const& name,
size_t id, size_t id,
bool isUserDefined) { bool isUserDefined) {
auto variable = new Variable(name, id, isUserDefined); auto variable = new Variable(name, id, isUserDefined);
@ -95,6 +95,8 @@ void Scope::addVariable (std::string const& name,
delete variable; delete variable;
THROW_ARANGO_EXCEPTION(TRI_ERROR_OUT_OF_MEMORY); THROW_ARANGO_EXCEPTION(TRI_ERROR_OUT_OF_MEMORY);
} }
return variable;
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -198,7 +200,7 @@ void Scopes::endNested () {
/// @brief adds a variable to the current scope /// @brief adds a variable to the current scope
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
bool Scopes::addVariable (char const* name, Variable* Scopes::addVariable (char const* name,
bool isUserDefined) { bool isUserDefined) {
TRI_ASSERT(! _activeScopes.empty()); TRI_ASSERT(! _activeScopes.empty());
@ -207,12 +209,13 @@ bool Scopes::addVariable (char const* name,
if (scope->existsVariable(name)) { if (scope->existsVariable(name)) {
// duplicate variable name // duplicate variable name
return false; return 0;
} }
} }
_activeScopes.back()->addVariable(std::string(name), ++_variableId, isUserDefined); size_t id = ++_variableId;
return true;
return _activeScopes.back()->addVariable(std::string(name), id, isUserDefined);
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////

View File

@ -35,13 +35,6 @@
namespace triagens { namespace triagens {
namespace aql { namespace aql {
template<typename T>
struct CharComparer : public binary_function<T, T, bool> {
bool operator () (T const& lhs, T const& rhs) const {
return strcmp(lhs, rhs) == 0;
}
};
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// --SECTION-- struct Variable // --SECTION-- struct Variable
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
@ -122,7 +115,7 @@ namespace triagens {
/// @brief adds a variable to the scope /// @brief adds a variable to the scope
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void addVariable (std::string const&, Variable* addVariable (std::string const&,
size_t, size_t,
bool); bool);
@ -207,7 +200,7 @@ namespace triagens {
/// @brief adds a variable to the current scope /// @brief adds a variable to the current scope
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
bool addVariable (char const*, Variable* addVariable (char const*,
bool); bool);
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////