//////////////////////////////////////////////////////////////////////////////// /// @brief Aql, scopes /// /// @file /// /// DISCLAIMER /// /// Copyright 2014 ArangoDB GmbH, Cologne, Germany /// Copyright 2004-2014 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 ArangoDB GmbH, Cologne, Germany /// /// @author Jan Steemann /// @author Copyright 2014, ArangoDB GmbH, Cologne, Germany /// @author Copyright 2012-2013, triAGENS GmbH, Cologne, Germany //////////////////////////////////////////////////////////////////////////////// #ifndef ARANGODB_AQL_SCOPES_H #define ARANGODB_AQL_SCOPES_H 1 #include "Basics/Common.h" #include "Aql/Variable.h" namespace triagens { namespace aql { // ----------------------------------------------------------------------------- // --SECTION-- public types // ----------------------------------------------------------------------------- enum ScopeType { AQL_SCOPE_MAIN, AQL_SCOPE_SUBQUERY, AQL_SCOPE_FOR, AQL_SCOPE_COLLECT }; // ----------------------------------------------------------------------------- // --SECTION-- class Scope // ----------------------------------------------------------------------------- class Scope { // ----------------------------------------------------------------------------- // --SECTION-- constructors / destructors // ----------------------------------------------------------------------------- public: //////////////////////////////////////////////////////////////////////////////// /// @brief create a scope //////////////////////////////////////////////////////////////////////////////// Scope (ScopeType); //////////////////////////////////////////////////////////////////////////////// /// @brief destroy the scope //////////////////////////////////////////////////////////////////////////////// ~Scope (); // ----------------------------------------------------------------------------- // --SECTION-- public methods // ----------------------------------------------------------------------------- public: //////////////////////////////////////////////////////////////////////////////// /// @brief return the name of a scope type //////////////////////////////////////////////////////////////////////////////// std::string typeName () const; //////////////////////////////////////////////////////////////////////////////// /// @brief return the scope type //////////////////////////////////////////////////////////////////////////////// inline ScopeType type () const { return _type; } //////////////////////////////////////////////////////////////////////////////// /// @brief adds a variable to the scope //////////////////////////////////////////////////////////////////////////////// void addVariable (Variable*); //////////////////////////////////////////////////////////////////////////////// /// @brief checks if a variable exists in the scope //////////////////////////////////////////////////////////////////////////////// bool existsVariable (char const*) const; //////////////////////////////////////////////////////////////////////////////// /// @brief checks if a variable exists in the scope //////////////////////////////////////////////////////////////////////////////// bool existsVariable (std::string const&) const; //////////////////////////////////////////////////////////////////////////////// /// @brief return a variable //////////////////////////////////////////////////////////////////////////////// Variable* getVariable (char const*) const; //////////////////////////////////////////////////////////////////////////////// /// @brief return a variable //////////////////////////////////////////////////////////////////////////////// Variable* getVariable (std::string const&) const; // ----------------------------------------------------------------------------- // --SECTION-- private variables // ----------------------------------------------------------------------------- private: //////////////////////////////////////////////////////////////////////////////// /// @brief scope type //////////////////////////////////////////////////////////////////////////////// ScopeType const _type; //////////////////////////////////////////////////////////////////////////////// /// @brief variables introduced by the scope //////////////////////////////////////////////////////////////////////////////// std::unordered_map _variables; }; // ----------------------------------------------------------------------------- // --SECTION-- class Scopes // ----------------------------------------------------------------------------- //////////////////////////////////////////////////////////////////////////////// /// @brief scope management //////////////////////////////////////////////////////////////////////////////// class Scopes { // ----------------------------------------------------------------------------- // --SECTION-- constructors / destructors // ----------------------------------------------------------------------------- public: //////////////////////////////////////////////////////////////////////////////// /// @brief create the scopes //////////////////////////////////////////////////////////////////////////////// Scopes (); //////////////////////////////////////////////////////////////////////////////// /// @brief destroy the scopes //////////////////////////////////////////////////////////////////////////////// ~Scopes (); // ----------------------------------------------------------------------------- // --SECTION-- public methods // ----------------------------------------------------------------------------- public: //////////////////////////////////////////////////////////////////////////////// /// @brief number of currently active scopes //////////////////////////////////////////////////////////////////////////////// inline size_t numActive () const { return _activeScopes.size(); } //////////////////////////////////////////////////////////////////////////////// /// @brief start a new scope //////////////////////////////////////////////////////////////////////////////// void start (ScopeType); //////////////////////////////////////////////////////////////////////////////// /// @brief end the current scope //////////////////////////////////////////////////////////////////////////////// void endCurrent (); //////////////////////////////////////////////////////////////////////////////// /// @brief end the current scope plus any FOR scopes it is nested in //////////////////////////////////////////////////////////////////////////////// void endNested (); //////////////////////////////////////////////////////////////////////////////// /// @brief adds a variable to the current scope //////////////////////////////////////////////////////////////////////////////// void addVariable (Variable*); //////////////////////////////////////////////////////////////////////////////// /// @brief checks whether a variable exists in any scope //////////////////////////////////////////////////////////////////////////////// bool existsVariable (char const*) const; //////////////////////////////////////////////////////////////////////////////// /// @brief return a variable by name - this respects the current scopes //////////////////////////////////////////////////////////////////////////////// Variable* getVariable (char const*) const; // ----------------------------------------------------------------------------- // --SECTION-- private variables // ----------------------------------------------------------------------------- private: //////////////////////////////////////////////////////////////////////////////// /// @brief currently active scopes //////////////////////////////////////////////////////////////////////////////// std::vector _activeScopes; }; } } #endif // ----------------------------------------------------------------------------- // --SECTION-- END-OF-FILE // ----------------------------------------------------------------------------- // Local Variables: // mode: outline-minor // outline-regexp: "/// @brief\\|/// {@inheritDoc}\\|/// @page\\|// --SECTION--\\|/// @\\}" // End: