From 3e10322425fa0a3cf6e125bc6f9d833b015cc9b5 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Tue, 14 Sep 2010 10:52:55 +0200 Subject: Implement the --cli-namespace option --- cli/context.cxx | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) (limited to 'cli/context.cxx') diff --git a/cli/context.cxx b/cli/context.cxx index a740374..8d5cba3 100644 --- a/cli/context.cxx +++ b/cli/context.cxx @@ -105,12 +105,18 @@ context (ostream& os_, inl (data_->inl_), opt_prefix (options.option_prefix ()), opt_sep (options.option_separator ()), + cli (data_->cli_), reserved_name_map (options.reserved_name ()), keyword_set (data_->keyword_set_) { if (!options.suppress_inline ()) data_->inl_ = "inline "; + data_->cli_ = options.cli_namespace (); + + if (!cli.empty () && cli[0] != ':') + data_->cli_ = "::" + data_->cli_; + for (size_t i (0); i < sizeof (keywords) / sizeof (char*); ++i) data_->keyword_set_.insert (keywords[i]); } @@ -127,6 +133,7 @@ context (context& c) inl (c.inl), opt_prefix (c.opt_prefix), opt_sep (c.opt_sep), + cli (c.cli), reserved_name_map (c.reserved_name_map), keyword_set (c.keyword_set) { @@ -614,6 +621,52 @@ fq_name (semantics::nameable& n, bool cxx_name) return r; } +void context:: +cli_open () +{ + string::size_type b (0), e; + + do + { + e = cli.find ("::", b); + string n (cli, b, e == string::npos ? e : e - b); + + if (!n.empty ()) + os << "namespace " << n << "{"; + + b = e; + + if (b == string::npos) + break; + + b += 2; + + } while (true); +} + +void context:: +cli_close () +{ + string::size_type b (0), e; + + do + { + e = cli.find ("::", b); + string n (cli, b, e == string::npos ? e : e - b); + + if (!n.empty ()) + os << "}"; + + b = e; + + if (b == string::npos) + break; + + b += 2; + + } while (true); +} + // namespace // -- cgit v1.1