From 4974b4763bd60eb875f93a71dbe2fe82ecfed9fc Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Sat, 5 Sep 2009 16:29:23 +0200 Subject: Add semantic graph and traversal mechanism The parser now builds the semantic graph. --- cli/semantics/option.hxx | 168 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 168 insertions(+) create mode 100644 cli/semantics/option.hxx (limited to 'cli/semantics/option.hxx') diff --git a/cli/semantics/option.hxx b/cli/semantics/option.hxx new file mode 100644 index 0000000..21fc900 --- /dev/null +++ b/cli/semantics/option.hxx @@ -0,0 +1,168 @@ +// file : cli/semantics/option.hxx +// author : Boris Kolpackov +// copyright : Copyright (c) 2009 Code Synthesis Tools CC +// license : MIT; see accompanying LICENSE file + +#ifndef CLI_SEMANTICS_OPTION_HXX +#define CLI_SEMANTICS_OPTION_HXX + +#include + +namespace semantics +{ + // + // + class option; + + // + // + class belongs: public edge + { + public: + typedef semantics::type type_type; + typedef semantics::option option_type; + + option_type& + option () const + { + return *option_; + } + + type_type& + type () const + { + return *type_; + } + + protected: + friend class graph; + + void + set_left_node (option_type& n) + { + option_ = &n; + } + + void + set_right_node (type_type& n) + { + type_ = &n; + } + + private: + option_type* option_; + type_type* type_; + }; + + // + // + class expression; + + // + // + class initialized: public edge + { + public: + typedef semantics::option option_type; + typedef semantics::expression expression_type; + + option_type& + option () const + { + return *option_; + } + + expression_type& + expression () const + { + return *expression_; + } + + protected: + friend class graph; + + void + set_left_node (option_type& n) + { + option_ = &n; + } + + void + set_right_node (expression_type& n) + { + expression_ = &n; + } + + private: + option_type* option_; + expression_type* expression_; + }; + + // + // + class option: public nameable + { + public: + typedef semantics::belongs belongs_type; + typedef semantics::type type_type; + + belongs_type& + belongs () const + { + return *belongs_; + } + + type_type& + type () const + { + return belongs_->type (); + } + + public: + typedef semantics::initialized initialized_type; + + bool + initialized_p () const + { + return initialized_ != 0; + } + + initialized_type& + initialized () const + { + return *initialized_; + } + + expression& + initializer () const + { + return initialized_->expression (); + } + + protected: + friend class graph; + + option (path const& file, size_t line, size_t column) + : node (file, line, column), initialized_ (0) + { + } + + void + add_edge_left (belongs_type& e) + { + belongs_ = &e; + } + + void + add_edge_left (initialized_type& e) + { + initialized_ = &e; + } + + private: + belongs_type* belongs_; + initialized_type* initialized_; + }; +} + +#endif // CLI_SEMANTICS_OPTION_HXX -- cgit v1.1