// file : build/scope -*- C++ -*- // copyright : Copyright (c) 2014-2015 Code Synthesis Tools CC // license : MIT; see accompanying LICENSE file #ifndef BUILD_SCOPE #define BUILD_SCOPE #include #include #include #include namespace build { class scope { public: typedef build::path path_type; const path_type& path () const {return i_->first;} // Absolute and normalized. scope* parent () const {return parent_;} // Variable lookup. // public: value_proxy operator[] (const std::string&); value_proxy operator[] (const variable&); private: friend class scope_map; typedef path_map::const_iterator iterator; scope (): variables (*this) {} void init (const iterator& i, scope* p) {i_ = i; parent_ = p;} void parent (scope& p) {parent_ = &p;} public: variable_map variables; prerequisite_set prerequisites; private: iterator i_; scope* parent_; }; class scope_map: public path_map { public: // Note that we assume the first insertion into the map is that // of the root scope. // scope& operator[] (const path&); // Find the most qualified scope that encompasses this path. // scope& find (const path&); private: typedef path_map base; }; extern scope_map scopes; extern scope* root_scope; } #endif // BUILD_SCOPE