From b0cbea713f15e511630d2626c4694f119206dc94 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Sun, 4 Oct 2009 10:04:34 +0200 Subject: Add options for various include settings --include-with-brackets --include-prefix --guard-prefix --- cli/generator.cxx | 25 ++++++++++++++++++------- cli/makefile | 1 + cli/options.cli | 4 ++++ cli/options.cxx | 26 ++++++++++++++++++++++---- cli/options.hxx | 18 +++++++++++++++--- cli/options.ixx | 18 ++++++++++++++++++ 6 files changed, 78 insertions(+), 14 deletions(-) (limited to 'cli') diff --git a/cli/generator.cxx b/cli/generator.cxx index f7a9a1f..844981a 100644 --- a/cli/generator.cxx +++ b/cli/generator.cxx @@ -38,13 +38,10 @@ namespace "//\n\n"; string - make_guard (string const& file, string const& prefix, context& ctx) + make_guard (string const& file, context& ctx) { string g (file); - if (!prefix.empty ()) - g = prefix + '_' + g; - // Split words, e.g., "FooBar" to "Foo_Bar" and convert everything // to upper case. // @@ -159,13 +156,25 @@ generate (options const& ops, semantics::cli_unit& unit, path const& p) typedef compiler::ostream_filter cxx_filter; + // Include settings. + // + bool br (ops.include_with_brackets ()); + string ip (ops.include_prefix ()); + string gp (ops.guard_prefix ()); + + if (!ip.empty () && ip[ip.size () - 1] != '/') + ip.append ("/"); + + if (!gp.empty () && gp[gp.size () - 1] != '_') + gp.append ("_"); + // HXX // { cxx_filter filt (hxx); context ctx (hxx, unit, ops); - string guard (make_guard (hxx_name, "", ctx)); + string guard (make_guard (gp + hxx_name, ctx)); hxx << "#ifndef " << guard << endl << "#define " << guard << endl @@ -177,7 +186,8 @@ generate (options const& ops, semantics::cli_unit& unit, path const& p) if (inl) { - hxx << "#include \"" << ixx_name << "\"" << endl + hxx << "#include " << (br ? '<' : '"') << ip << ixx_name << + (br ? '>' : '"') << endl << endl; } @@ -199,7 +209,8 @@ generate (options const& ops, semantics::cli_unit& unit, path const& p) cxx_filter filt (cxx); context ctx (cxx, unit, ops); - cxx << "#include \"" << hxx_name << "\"" << endl + cxx << "#include " << (br ? '<' : '"') << ip << hxx_name << + (br ? '>' : '"') << endl << endl; if (!inl) diff --git a/cli/makefile b/cli/makefile index 86df489..5e1238b 100644 --- a/cli/makefile +++ b/cli/makefile @@ -62,6 +62,7 @@ genf := $(cli_tun:.cli=.hxx) $(cli_tun:.cli=.ixx) $(cli_tun:.cli=.cxx) gen := $(addprefix $(out_base)/,$(genf)) $(gen): cli := $(out_root)/cli/cli +$(gen): cli_options := --guard-prefix CLI $(call include-dep,$(cxx_od)) diff --git a/cli/options.cli b/cli/options.cli index 2ef8738..28f6495 100644 --- a/cli/options.cli +++ b/cli/options.cli @@ -21,4 +21,8 @@ class options std::string --hxx-suffix = ".hxx"; std::string --ixx-suffix = ".ixx"; std::string --cxx-suffix = ".cxx"; + + bool --include-with-brackets; + std::string --include-prefix; + std::string --guard-prefix; }; diff --git a/cli/options.cxx b/cli/options.cxx index c38ca35..803e22b 100644 --- a/cli/options.cxx +++ b/cli/options.cxx @@ -171,7 +171,10 @@ options (int argc, output_dir_ (), hxx_suffix_ (".hxx"), ixx_suffix_ (".ixx"), - cxx_suffix_ (".cxx") + cxx_suffix_ (".cxx"), + include_with_brackets_ (), + include_prefix_ (), + guard_prefix_ () { _parse (1, argc, argv, opt, arg); } @@ -188,7 +191,10 @@ options (int start, output_dir_ (), hxx_suffix_ (".hxx"), ixx_suffix_ (".ixx"), - cxx_suffix_ (".cxx") + cxx_suffix_ (".cxx"), + include_with_brackets_ (), + include_prefix_ (), + guard_prefix_ () { _parse (start, argc, argv, opt, arg); } @@ -205,7 +211,10 @@ options (int argc, output_dir_ (), hxx_suffix_ (".hxx"), ixx_suffix_ (".ixx"), - cxx_suffix_ (".cxx") + cxx_suffix_ (".cxx"), + include_with_brackets_ (), + include_prefix_ (), + guard_prefix_ () { end = _parse (1, argc, argv, opt, arg); } @@ -223,7 +232,10 @@ options (int start, output_dir_ (), hxx_suffix_ (".hxx"), ixx_suffix_ (".ixx"), - cxx_suffix_ (".cxx") + cxx_suffix_ (".cxx"), + include_with_brackets_ (), + include_prefix_ (), + guard_prefix_ () { end = _parse (start, argc, argv, opt, arg); } @@ -252,6 +264,12 @@ struct _cli_options_map_init &::cli::thunk; _cli_options_map_["--cxx-suffix"] = &::cli::thunk; + _cli_options_map_["--include-with-brackets"] = + &::cli::thunk; + _cli_options_map_["--include-prefix"] = + &::cli::thunk; + _cli_options_map_["--guard-prefix"] = + &::cli::thunk; } } _cli_options_map_init_; diff --git a/cli/options.hxx b/cli/options.hxx index 2594947..e2c0109 100644 --- a/cli/options.hxx +++ b/cli/options.hxx @@ -2,8 +2,8 @@ // compiler for C++. // -#ifndef OPTIONS_HXX -#define OPTIONS_HXX +#ifndef CLI_OPTIONS_HXX +#define CLI_OPTIONS_HXX #include #include @@ -225,6 +225,15 @@ class options std::string const& cxx_suffix () const; + bool const& + include_with_brackets () const; + + std::string const& + include_prefix () const; + + std::string const& + guard_prefix () const; + private: int _parse (int start, @@ -241,8 +250,11 @@ class options std::string hxx_suffix_; std::string ixx_suffix_; std::string cxx_suffix_; + bool include_with_brackets_; + std::string include_prefix_; + std::string guard_prefix_; }; #include "options.ixx" -#endif // OPTIONS_HXX +#endif // CLI_OPTIONS_HXX diff --git a/cli/options.ixx b/cli/options.ixx index 9e15c36..11a1776 100644 --- a/cli/options.ixx +++ b/cli/options.ixx @@ -47,3 +47,21 @@ cxx_suffix () const return cxx_suffix_; } +inline bool const& options:: +include_with_brackets () const +{ + return include_with_brackets_; +} + +inline std::string const& options:: +include_prefix () const +{ + return include_prefix_; +} + +inline std::string const& options:: +guard_prefix () const +{ + return guard_prefix_; +} + -- cgit v1.1