From 6f6c10491ce0e973fe8328508fe2a232c2189016 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Sun, 4 Oct 2009 14:18:38 +0200 Subject: Move runtime inline function to inline file --- cli/generator.cxx | 13 ++++-- cli/makefile | 1 + cli/options.cxx | 2 +- cli/options.hxx | 61 +++++++--------------------- cli/options.ixx | 83 ++++++++++++++++++++++++++++++++++++++ cli/runtime-header.cxx | 80 ++++++++++++------------------------ cli/runtime-header.hxx | 5 +-- cli/runtime-inline.cxx | 107 +++++++++++++++++++++++++++++++++++++++++++++++++ cli/runtime-inline.hxx | 14 +++++++ 9 files changed, 256 insertions(+), 110 deletions(-) create mode 100644 cli/runtime-inline.cxx create mode 100644 cli/runtime-inline.hxx (limited to 'cli') diff --git a/cli/generator.cxx b/cli/generator.cxx index 844981a..801f7e5 100644 --- a/cli/generator.cxx +++ b/cli/generator.cxx @@ -14,10 +14,11 @@ #include #include "header.hxx" -#include "source.hxx" #include "inline.hxx" +#include "source.hxx" #include "runtime-header.hxx" +#include "runtime-inline.hxx" #include "runtime-source.hxx" #include "context.hxx" @@ -180,9 +181,8 @@ generate (options const& ops, semantics::cli_unit& unit, path const& p) << "#define " << guard << endl << endl; - generate_runtime_header_decl (ctx); + generate_runtime_header (ctx); generate_header (ctx); - generate_runtime_header_impl (ctx); if (inl) { @@ -200,6 +200,7 @@ generate (options const& ops, semantics::cli_unit& unit, path const& p) { cxx_filter filt (ixx); context ctx (ixx, unit, ops); + generate_runtime_inline (ctx); generate_inline (ctx); } @@ -214,9 +215,13 @@ generate (options const& ops, semantics::cli_unit& unit, path const& p) << endl; if (!inl) - generate_inline (ctx); + generate_runtime_inline (ctx); generate_runtime_source (ctx); + + if (!inl) + generate_inline (ctx); + generate_source (ctx); } diff --git a/cli/makefile b/cli/makefile index 5e1238b..8f4ccfc 100644 --- a/cli/makefile +++ b/cli/makefile @@ -14,6 +14,7 @@ header.cxx \ inline.cxx \ source.cxx \ runtime-header.cxx \ +runtime-inline.cxx \ runtime-source.cxx \ generator.cxx \ name-processor.cxx diff --git a/cli/options.cxx b/cli/options.cxx index d92af58..d5e7e67 100644 --- a/cli/options.cxx +++ b/cli/options.cxx @@ -393,7 +393,7 @@ _parse (int start, { start += (*(i->second)) (*this, argv + start, argc - start); } - else if (opt && s[0] == '-' && s[1] != '\0') + else if (opt && std::strncmp (s, "-", 1) == 0 && s[1] != '\0') { switch (opt_mode) { diff --git a/cli/options.hxx b/cli/options.hxx index 97f1246..b856fbc 100644 --- a/cli/options.hxx +++ b/cli/options.hxx @@ -13,17 +13,15 @@ namespace cli { class unknown_mode { - public:enum value + public: + enum value { skip, stop, fail }; - unknown_mode (value v) - : v_ (v) - { - } + unknown_mode (value v); operator value () const { @@ -44,12 +42,8 @@ namespace cli print (std::ostream&) const = 0; }; - inline std::ostream& - operator<< (std::ostream& os, const exception& e) - { - e.print (os); - return os; - } + std::ostream& + operator<< (std::ostream&, const exception&); class unknown_option: public exception { @@ -57,16 +51,10 @@ namespace cli virtual ~unknown_option () throw (); - unknown_option (const std::string& option) - : option_ (option) - { - } + unknown_option (const std::string& option); const std::string& - option () const - { - return option_; - } + option () const; virtual void print (std::ostream&) const; @@ -84,16 +72,10 @@ namespace cli virtual ~unknown_argument () throw (); - unknown_argument (const std::string& argument) - : argument_ (argument) - { - } + unknown_argument (const std::string& argument); const std::string& - argument () const - { - return argument_; - } + argument () const; virtual void print (std::ostream&) const; @@ -111,16 +93,10 @@ namespace cli virtual ~missing_value () throw (); - missing_value (const std::string& option) - : option_ (option) - { - } + missing_value (const std::string& option); const std::string& - option () const - { - return option_; - } + option () const; virtual void print (std::ostream&) const; @@ -139,22 +115,13 @@ namespace cli ~invalid_value () throw (); invalid_value (const std::string& option, - const std::string& value) - : option_ (option), value_ (value) - { - } + const std::string& value); const std::string& - option () const - { - return option_; - } + option () const; const std::string& - value () const - { - return value_; - } + value () const; virtual void print (std::ostream&) const; diff --git a/cli/options.ixx b/cli/options.ixx index 01fbd37..0ca4c9e 100644 --- a/cli/options.ixx +++ b/cli/options.ixx @@ -2,6 +2,89 @@ // compiler for C++. // +namespace cli +{ + // unknown_mode + // + inline unknown_mode:: + unknown_mode (value v) + : v_ (v) + { + } + + // exception + // + inline std::ostream& + operator<< (std::ostream& os, const exception& e) + { + e.print (os); + return os; + } + + // unknown_option + // + inline unknown_option:: + unknown_option (const std::string& option) + : option_ (option) + { + } + + inline const std::string& unknown_option:: + option () const + { + return option_; + } + + // unknown_argument + // + inline unknown_argument:: + unknown_argument (const std::string& argument) + : argument_ (argument) + { + } + + inline const std::string& unknown_argument:: + argument () const + { + return argument_; + } + + // missing_value + // + inline missing_value:: + missing_value (const std::string& option) + : option_ (option) + { + } + + inline const std::string& missing_value:: + option () const + { + return option_; + } + + // invalid_value + // + inline invalid_value:: + invalid_value (const std::string& option, + const std::string& value) + : option_ (option), value_ (value) + { + } + + inline const std::string& invalid_value:: + option () const + { + return option_; + } + + inline const std::string& invalid_value:: + value () const + { + return value_; + } +} + // options // diff --git a/cli/runtime-header.cxx b/cli/runtime-header.cxx index 87cdf11..055754c 100644 --- a/cli/runtime-header.cxx +++ b/cli/runtime-header.cxx @@ -8,7 +8,7 @@ using namespace std; void -generate_runtime_header_decl (context& ctx) +generate_runtime_header (context& ctx) { ostream& os (ctx.os); @@ -24,16 +24,16 @@ generate_runtime_header_decl (context& ctx) // os << "class unknown_mode" << "{" - << "public:" + << "public:" << endl << "enum value" << "{" << "skip," << endl << "stop," << endl << "fail" << endl << "};" - << "unknown_mode (value v)" << endl - << ": v_ (v) {}" - << "operator value () const {return v_;}" + << "unknown_mode (value v);" + << endl + << "operator value () const {return v_;}" // Can't generate outside. << "private:" << endl << "value v_;" << "};"; @@ -52,12 +52,9 @@ generate_runtime_header_decl (context& ctx) << "print (std::ostream&) const = 0;" << "};"; - os << "inline std::ostream&" << endl - << "operator<< (std::ostream& os, const exception& e)" - << "{" - << "e.print (os);" - << "return os;" - << "}"; + os << "std::ostream&" << endl + << "operator<< (std::ostream&, const exception&);" + << endl; os << "class unknown_option: public exception" << "{" @@ -65,15 +62,11 @@ generate_runtime_header_decl (context& ctx) << "virtual" << endl << "~unknown_option () throw ();" << endl - << "unknown_option (const std::string& option)" << endl - << ": option_ (option)" - << "{" - << "}" + << "unknown_option (const std::string& option);" + << endl << "const std::string&" << endl - << "option () const" - << "{" - << "return option_;" - << "}" + << "option () const;" + << endl << "virtual void" << endl << "print (std::ostream&) const;" << endl @@ -90,15 +83,11 @@ generate_runtime_header_decl (context& ctx) << "virtual" << endl << "~unknown_argument () throw ();" << endl - << "unknown_argument (const std::string& argument)" << endl - << ": argument_ (argument)" - << "{" - << "}" + << "unknown_argument (const std::string& argument);" + << endl << "const std::string&" << endl - << "argument () const" - << "{" - << "return argument_;" - << "}" + << "argument () const;" + << endl << "virtual void" << endl << "print (std::ostream&) const;" << endl @@ -115,15 +104,11 @@ generate_runtime_header_decl (context& ctx) << "virtual" << endl << "~missing_value () throw ();" << endl - << "missing_value (const std::string& option)" << endl - << ": option_ (option)" - << "{" - << "}" + << "missing_value (const std::string& option);" + << endl << "const std::string&" << endl - << "option () const" - << "{" - << "return option_;" - << "}" + << "option () const;" + << endl << "virtual void" << endl << "print (std::ostream&) const;" << endl @@ -141,21 +126,14 @@ generate_runtime_header_decl (context& ctx) << "~invalid_value () throw ();" << endl << "invalid_value (const std::string& option," << endl - << "const std::string& value)" << endl - << ": option_ (option)," - << " value_ (value)" - << "{" - << "}" + << "const std::string& value);" + << endl << "const std::string&" << endl - << "option () const" - << "{" - << "return option_;" - << "}" + << "option () const;" + << endl << "const std::string&" << endl - << "value () const" - << "{" - << "return value_;" - << "}" + << "value () const;" + << endl << "virtual void" << endl << "print (std::ostream&) const;" << endl @@ -169,9 +147,3 @@ generate_runtime_header_decl (context& ctx) os << "}"; // namespace cli } - -void -generate_runtime_header_impl (context& ctx) -{ - ostream& os (ctx.os); -} diff --git a/cli/runtime-header.hxx b/cli/runtime-header.hxx index 5f78e9d..0e3bdff 100644 --- a/cli/runtime-header.hxx +++ b/cli/runtime-header.hxx @@ -9,9 +9,6 @@ #include "context.hxx" void -generate_runtime_header_decl (context&); - -void -generate_runtime_header_impl (context&); +generate_runtime_header (context&); #endif // CLI_RUNTIME_HEADER_HXX diff --git a/cli/runtime-inline.cxx b/cli/runtime-inline.cxx new file mode 100644 index 0000000..9c33c2e --- /dev/null +++ b/cli/runtime-inline.cxx @@ -0,0 +1,107 @@ +// file : cli/runtime-inline.cxx +// author : Boris Kolpackov +// copyright : Copyright (c) 2009 Code Synthesis Tools CC +// license : MIT; see accompanying LICENSE file + +#include "runtime-inline.hxx" + +using namespace std; + +void +generate_runtime_inline (context& ctx) +{ + ostream& os (ctx.os); + string const& inl (ctx.inl); + + os << "namespace cli" + << "{"; + + os << "// unknown_mode" << endl + << "//" << endl; + + os << inl << "unknown_mode::" << endl + << "unknown_mode (value v)" << endl + << ": v_ (v)" + << "{" + << "}"; + + os << "// exception" << endl + << "//" << endl; + + os << inl << "std::ostream&" << endl + << "operator<< (std::ostream& os, const exception& e)" + << "{" + << "e.print (os);" + << "return os;" + << "}"; + + os << "// unknown_option" << endl + << "//" << endl; + + os << inl << "unknown_option::" << endl + << "unknown_option (const std::string& option)" << endl + << ": option_ (option)" + << "{" + << "}"; + + os << inl << "const std::string& unknown_option::" << endl + << "option () const" + << "{" + << "return option_;" + << "}"; + + os << "// unknown_argument" << endl + << "//" << endl; + + os << inl << "unknown_argument::" << endl + << "unknown_argument (const std::string& argument)" << endl + << ": argument_ (argument)" + << "{" + << "}"; + + os << inl << "const std::string& unknown_argument::" << endl + << "argument () const" + << "{" + << "return argument_;" + << "}"; + + os << "// missing_value" << endl + << "//" << endl; + + os << inl << "missing_value::" << endl + << "missing_value (const std::string& option)" << endl + << ": option_ (option)" + << "{" + << "}"; + + os << inl << "const std::string& missing_value::" << endl + << "option () const" + << "{" + << "return option_;" + << "}"; + + os << "// invalid_value" << endl + << "//" << endl; + + os << inl << "invalid_value::" << endl + << "invalid_value (const std::string& option," << endl + << "const std::string& value)" << endl + << ": option_ (option)," + << " value_ (value)" + << "{" + << "}"; + + os << inl << "const std::string& invalid_value::" << endl + << "option () const" + << "{" + << "return option_;" + << "}"; + + os << inl << "const std::string& invalid_value::" << endl + << "value () const" + << "{" + << "return value_;" + << "}"; + + os << "}"; // namespace cli +} diff --git a/cli/runtime-inline.hxx b/cli/runtime-inline.hxx new file mode 100644 index 0000000..84eb655 --- /dev/null +++ b/cli/runtime-inline.hxx @@ -0,0 +1,14 @@ +// file : cli/runtime-inline.hxx +// author : Boris Kolpackov +// copyright : Copyright (c) 2009 Code Synthesis Tools CC +// license : MIT; see accompanying LICENSE file + +#ifndef CLI_RUNTIME_INLINE_HXX +#define CLI_RUNTIME_INLINE_HXX + +#include "context.hxx" + +void +generate_runtime_inline (context&); + +#endif // CLI_RUNTIME_INLINE_HXX -- cgit v1.1