From 1f83704a70b9c4065a5eb9f65e94919415d238ae Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Thu, 30 Jun 2022 14:25:16 +0300 Subject: Add support for using bool with std::vector, std::set, and std::map --- cli/cli/runtime-source.cxx | 44 +++++++++++++++++++++++++++++++++++++------- 1 file changed, 37 insertions(+), 7 deletions(-) (limited to 'cli/cli/runtime-source.cxx') diff --git a/cli/cli/runtime-source.cxx b/cli/cli/runtime-source.cxx index d5334a0..9620648 100644 --- a/cli/cli/runtime-source.cxx +++ b/cli/cli/runtime-source.cxx @@ -17,11 +17,11 @@ generate_runtime_source (context& ctx, bool complete) << "#include " << endl << "#include " << endl // pair << "#include " << endl - << "#include " << endl; + << "#include " << endl + << "#include " << endl; if (complete && ctx.options.generate_file_scanner ()) - os << "#include " << endl - << "#include " << endl; + os << "#include " << endl; os << endl; @@ -1011,11 +1011,33 @@ generate_runtime_source (context& ctx, bool complete) << "{"; os << "static void" << endl - << "parse (bool& x, scanner& s)" + << "parse (bool& x, " << (sp ? "bool& xs, " : "") << "scanner& s)" << "{" - << "s.next ();" - << "x = true;" - << "}"; + << "const char* o (s.next ());" + << endl + << "if (s.more ())" + << "{" + << "const char* v (s.next ());" + << endl + << "if (std::strcmp (v, \"1\") == 0 ||" << endl + << "std::strcmp (v, \"true\") == 0 ||" << endl + << "std::strcmp (v, \"TRUE\") == 0 ||" << endl + << "std::strcmp (v, \"True\") == 0)" << endl + << "x = true;" + << "else if (std::strcmp (v, \"0\") == 0 ||" << endl + << "std::strcmp (v, \"false\") == 0 ||" << endl + << "std::strcmp (v, \"FALSE\") == 0 ||" << endl + << "std::strcmp (v, \"False\") == 0)" << endl + << "x = false;" + << "else" << endl + << "throw invalid_value (o, v);" + << "}" + << "else" << endl + << "throw missing_value (o);"; + if (sp) + os << endl + << "xs = true;"; + os << "}"; if (gen_merge) os << "static void" << endl @@ -1203,6 +1225,14 @@ generate_runtime_source (context& ctx, bool complete) << "parser::parse (x.*M, s);" << "}"; + os << "template " << endl + << "void" << endl + << "thunk (X& x, scanner& s)" + << "{" + << "s.next ();" + << "x.*M = true;" + << "}"; + if (ctx.gen_specifier) os << "template " << endl << "void" << endl -- cgit v1.1