From 720c5a33b6a49cf328fdd7611f49153cf8f60247 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Wed, 8 Apr 2020 14:51:57 +0300 Subject: Separate tests and examples into individual packages Also make cli module to be explicitly enabled via the config.cli configuration variable. --- cli/cli/inline.cxx | 108 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 cli/cli/inline.cxx (limited to 'cli/cli/inline.cxx') diff --git a/cli/cli/inline.cxx b/cli/cli/inline.cxx new file mode 100644 index 0000000..05b83db --- /dev/null +++ b/cli/cli/inline.cxx @@ -0,0 +1,108 @@ +// file : cli/inline.cxx +// author : Boris Kolpackov +// license : MIT; see accompanying LICENSE file + +#include + +namespace +{ + // + // + struct option: traversal::option, context + { + option (context& c) : context (c) {} + + virtual void + traverse (type& o) + { + string name (ename (o)); + string type (o.type ().name ()); + string scope (escape (o.scope ().name ())); + + os << inl << "const " << type << "& " << scope << "::" << endl + << name << " () const" + << "{" + << "return this->" << emember (o) << ";" + << "}"; + + if (gen_modifier) + { + os << inl << type << "& " << scope << "::" << endl + << name << " ()" + << "{" + << "return this->" << emember (o) << ";" + << "}"; + + os << inl << "void " << scope << "::" << endl + << name << "(const " << type << "& x)" + << "{" + << "this->" << emember (o) << " = x;" + << "}"; + } + + if (gen_specifier && type != "bool") + { + string spec (especifier (o)); + + os << inl << "bool " << scope << "::" << endl + << spec << " () const" + << "{" + << "return this->" << especifier_member (o) << ";" + << "}"; + + if (gen_modifier) + os << inl << "void " << scope << "::" << endl + << spec << "(bool x)" + << "{" + << "this->" << especifier_member (o) << " = x;" + << "}"; + } + } + }; + + // + // + struct class_: traversal::class_, context + { + class_ (context& c) + : context (c), option_ (c) + { + names_option_ >> option_; + } + + virtual void + traverse (type& c) + { + string name (escape (c.name ())); + + os << "// " << name << endl + << "//" << endl + << endl; + + names (c, names_option_); + } + + private: + option option_; + traversal::names names_option_; + }; +} + +void +generate_inline (context& ctx) +{ + traversal::cli_unit unit; + traversal::names unit_names; + namespace_ ns (ctx); + class_ cl (ctx); + + unit >> unit_names >> ns; + unit_names >> cl; + + traversal::names ns_names; + + ns >> ns_names >> ns; + ns_names >> cl; + + unit.dispatch (ctx.unit); +} -- cgit v1.1