summaryrefslogtreecommitdiff
path: root/cli
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2009-10-04 10:50:50 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2009-10-04 10:50:50 +0200
commitcfb91e263c22f6f81ae05a2027a2befac6d41e06 (patch)
tree182e84e03664f77d4f37f462abc4d3f6b3966435 /cli
parent68803e8bc8888abdc65cba1a1a6d8b4e9eeea27e (diff)
Add --reserved-name option
Diffstat (limited to 'cli')
-rw-r--r--cli/context.cxx2
-rw-r--r--cli/context.hxx4
-rw-r--r--cli/options.cli3
-rw-r--r--cli/options.cxx73
-rw-r--r--cli/options.hxx6
-rw-r--r--cli/options.ixx6
6 files changed, 86 insertions, 8 deletions
diff --git a/cli/context.cxx b/cli/context.cxx
index 1af10e8..b82a318 100644
--- a/cli/context.cxx
+++ b/cli/context.cxx
@@ -16,7 +16,7 @@ context (ostream& os_, semantics::cli_unit& unit_, options_type const& ops)
unit (unit_),
options (ops),
inl (data_->inl_),
- reserved_name_map (data_->reserved_name_map_)
+ reserved_name_map (options.reserved_name ())
{
if (!options.suppress_inline ())
inl = "inline ";
diff --git a/cli/context.hxx b/cli/context.hxx
index 8063f59..f57ac7f 100644
--- a/cli/context.hxx
+++ b/cli/context.hxx
@@ -38,14 +38,12 @@ public:
string& inl;
typedef std::map<string, string> reserved_name_map_type;
- reserved_name_map_type& reserved_name_map;
+ reserved_name_map_type const& reserved_name_map;
private:
struct data
{
string inl_;
-
- reserved_name_map_type reserved_name_map_;
};
public:
diff --git a/cli/options.cli b/cli/options.cli
index 28f6495..8c7bdda 100644
--- a/cli/options.cli
+++ b/cli/options.cli
@@ -7,6 +7,7 @@
// before modifying this file.
//
+include <map>;
include <string>;
include <vector>;
@@ -25,4 +26,6 @@ class options
bool --include-with-brackets;
std::string --include-prefix;
std::string --guard-prefix;
+
+ std::map<std::string, std::string> --reserved-name;
};
diff --git a/cli/options.cxx b/cli/options.cxx
index 803e22b..b47a5c8 100644
--- a/cli/options.cxx
+++ b/cli/options.cxx
@@ -4,6 +4,7 @@
#include "options.hxx"
+#include <map>
#include <string>
#include <vector>
#include <ostream>
@@ -146,6 +147,64 @@ namespace cli
}
};
+ template <typename K, typename V>
+ struct parser<std::map<K, V> >
+ {
+ static int
+ parse (std::map<K, V>& m, char** argv, int n)
+ {
+ if (n > 1)
+ {
+ std::string s (argv[1]);
+ std::string::size_type p (s.find ('='));
+
+ if (p == std::string::npos)
+ {
+ K k = K ();
+
+ if (!s.empty ())
+ {
+ std::istringstream ks (s);
+
+ if (!(ks >> k && ks.eof ()))
+ throw invalid_value (argv[0], argv[1]);
+ }
+
+ m[k] = V ();
+ }
+ else
+ {
+ K k = K ();
+ V v = V ();
+ std::string kstr (s, 0, p);
+ std::string vstr (s, p + 1);
+
+ if (!kstr.empty ())
+ {
+ std::istringstream ks (kstr);
+
+ if (!(ks >> k && ks.eof ()))
+ throw invalid_value (argv[0], argv[1]);
+ }
+
+ if (!vstr.empty ())
+ {
+ std::istringstream vs (vstr);
+
+ if (!(vs >> v && vs.eof ()))
+ throw invalid_value (argv[0], argv[1]);
+ }
+
+ m[k] = v;
+ }
+
+ return 2;
+ }
+ else
+ throw missing_value (argv[0]);
+ }
+ };
+
template <typename X, typename T, T X::*P>
int
thunk (X& x, char** argv, int n)
@@ -174,7 +233,8 @@ options (int argc,
cxx_suffix_ (".cxx"),
include_with_brackets_ (),
include_prefix_ (),
- guard_prefix_ ()
+ guard_prefix_ (),
+ reserved_name_ ()
{
_parse (1, argc, argv, opt, arg);
}
@@ -194,7 +254,8 @@ options (int start,
cxx_suffix_ (".cxx"),
include_with_brackets_ (),
include_prefix_ (),
- guard_prefix_ ()
+ guard_prefix_ (),
+ reserved_name_ ()
{
_parse (start, argc, argv, opt, arg);
}
@@ -214,7 +275,8 @@ options (int argc,
cxx_suffix_ (".cxx"),
include_with_brackets_ (),
include_prefix_ (),
- guard_prefix_ ()
+ guard_prefix_ (),
+ reserved_name_ ()
{
end = _parse (1, argc, argv, opt, arg);
}
@@ -235,7 +297,8 @@ options (int start,
cxx_suffix_ (".cxx"),
include_with_brackets_ (),
include_prefix_ (),
- guard_prefix_ ()
+ guard_prefix_ (),
+ reserved_name_ ()
{
end = _parse (start, argc, argv, opt, arg);
}
@@ -270,6 +333,8 @@ struct _cli_options_map_init
&::cli::thunk<options, std::string, &options::include_prefix_>;
_cli_options_map_["--guard-prefix"] =
&::cli::thunk<options, std::string, &options::guard_prefix_>;
+ _cli_options_map_["--reserved-name"] =
+ &::cli::thunk<options, std::map<std::string, std::string>, &options::reserved_name_>;
}
} _cli_options_map_init_;
diff --git a/cli/options.hxx b/cli/options.hxx
index e2c0109..2906344 100644
--- a/cli/options.hxx
+++ b/cli/options.hxx
@@ -168,6 +168,8 @@ namespace cli
};
}
+#include <map>
+
#include <string>
#include <vector>
@@ -234,6 +236,9 @@ class options
std::string const&
guard_prefix () const;
+ std::map<std::string, std::string> const&
+ reserved_name () const;
+
private:
int
_parse (int start,
@@ -253,6 +258,7 @@ class options
bool include_with_brackets_;
std::string include_prefix_;
std::string guard_prefix_;
+ std::map<std::string, std::string> reserved_name_;
};
#include "options.ixx"
diff --git a/cli/options.ixx b/cli/options.ixx
index 11a1776..12cb277 100644
--- a/cli/options.ixx
+++ b/cli/options.ixx
@@ -65,3 +65,9 @@ guard_prefix () const
return guard_prefix_;
}
+inline std::map<std::string, std::string> const& options::
+reserved_name () const
+{
+ return reserved_name_;
+}
+