From 01f77f6d38283b4efbe2b55fc9c7c837fd6498dc Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 25 Mar 2010 13:47:43 +0200 Subject: Add support for union, enum, class/union template --- odb/semantics/template.hxx | 158 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 158 insertions(+) create mode 100644 odb/semantics/template.hxx (limited to 'odb/semantics/template.hxx') diff --git a/odb/semantics/template.hxx b/odb/semantics/template.hxx new file mode 100644 index 0000000..1357dbf --- /dev/null +++ b/odb/semantics/template.hxx @@ -0,0 +1,158 @@ +// file : odb/semantics/template.hxx +// author : Boris Kolpackov +// copyright : Copyright (c) 2009-2010 Code Synthesis Tools CC +// license : GNU GPL v2; see accompanying LICENSE file + +#ifndef ODB_SEMANTICS_TEMPLATE_HXX +#define ODB_SEMANTICS_TEMPLATE_HXX + +#include +#include + +namespace semantics +{ + // + // + class instantiates; + + class template_: public virtual nameable + { + typedef std::vector instantiated; + + public: + typedef + pointer_iterator + instantiated_iterator; + + instantiated_iterator + instantiated_begin () const + { + return instantiated_.begin (); + } + + instantiated_iterator + instantiated_end () const + { + return instantiated_.end (); + } + + public: + void + add_edge_right (instantiates& e) + { + instantiated_.push_back (&e); + } + + using nameable::add_edge_right; + + protected: + template_ () + { + } + + private: + instantiated instantiated_; + }; + + // + // + class instantiation; + + class instantiates: public edge + { + public: + typedef semantics::template_ template_type; + typedef semantics::instantiation instantiation_type; + + template_type& + template_ () const + { + return *template__; + } + + instantiation_type& + instantiation () const + { + return *instantiation_; + } + + public: + instantiates () + { + } + + void + set_left_node (instantiation_type& n) + { + instantiation_ = &n; + } + + void + set_right_node (template_type& n) + { + template__ = &n; + } + + private: + template_type* template__; + instantiation_type* instantiation_; + }; + + // + // + class instantiation: public virtual node + { + public: + typedef semantics::template_ template_type; + typedef semantics::instantiates instantiates_type; + + template_type& + template_ () const + { + return instantiates_->template_ (); + } + + instantiates_type& + instantiates () const + { + return *instantiates_; + } + + public: + void + add_edge_left (instantiates_type& e) + { + instantiates_ = &e; + } + + protected: + instantiation () + { + } + + private: + instantiates_type* instantiates_; + }; + + // + // Type template and instantiation. + // + + class type_template: public template_ + { + protected: + type_template () + { + } + }; + + class type_instantiation: public virtual type, public instantiation + { + protected: + type_instantiation () + { + } + }; +} + +#endif // ODB_SEMANTICS_TEMPLATE_HXX -- cgit v1.1