From 1ca6396a3dd284241de11bcaa210ad5836e8e5a8 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Tue, 8 Dec 2009 16:18:01 +0200 Subject: Multiple object model character encodings support Also add support for ISO-8859-1. --- xsd/cxx/parser/cli.hxx | 2 + xsd/cxx/parser/elements.cxx | 3 ++ xsd/cxx/parser/elements.hxx | 1 + xsd/cxx/parser/generator.cxx | 82 +++++++++++++++++++++++++++++++++------ xsd/cxx/parser/generator.hxx | 2 + xsd/cxx/parser/name-processor.cxx | 16 +++++--- xsd/cxx/parser/name-processor.hxx | 6 +-- xsd/cxx/parser/parser-header.cxx | 7 ++++ xsd/cxx/parser/validator.cxx | 17 +++++++- 9 files changed, 113 insertions(+), 23 deletions(-) (limited to 'xsd/cxx/parser') diff --git a/xsd/cxx/parser/cli.hxx b/xsd/cxx/parser/cli.hxx index 504de43..5f31af7 100644 --- a/xsd/cxx/parser/cli.hxx +++ b/xsd/cxx/parser/cli.hxx @@ -24,6 +24,7 @@ namespace CXX typedef Char const Key[]; extern Key type_map; + extern Key char_encoding; extern Key char_type; extern Key output_dir; extern Key xml_parser; @@ -85,6 +86,7 @@ namespace CXX typedef Cult::CLI::Options< type_map, Cult::Containers::Vector, char_type, NarrowString, + char_encoding, NarrowString, output_dir, NarrowString, xml_parser, NarrowString, generate_inline, Boolean, diff --git a/xsd/cxx/parser/elements.cxx b/xsd/cxx/parser/elements.cxx index 8a02ffb..09d1008 100644 --- a/xsd/cxx/parser/elements.cxx +++ b/xsd/cxx/parser/elements.cxx @@ -42,12 +42,15 @@ namespace CXX Context (std::wostream& o, SemanticGraph::Schema& root, CLI::Options const& ops, + StringLiteralMap const* map, Regex const* he, Regex const* ie, Regex const* hie) : CXX::Context (o, root, + map, ops.value (), + ops.value (), ops.value (), ops.value (), ops.value (), diff --git a/xsd/cxx/parser/elements.hxx b/xsd/cxx/parser/elements.hxx index 90ff84e..61cde69 100644 --- a/xsd/cxx/parser/elements.hxx +++ b/xsd/cxx/parser/elements.hxx @@ -39,6 +39,7 @@ namespace CXX Context (std::wostream&, SemanticGraph::Schema&, CLI::Options const&, + StringLiteralMap const*, Regex const* hxx_expr, Regex const* ixx_expr, Regex const* hxx_impl_expr); diff --git a/xsd/cxx/parser/generator.cxx b/xsd/cxx/parser/generator.cxx index 342e3f2..ec08af4 100644 --- a/xsd/cxx/parser/generator.cxx +++ b/xsd/cxx/parser/generator.cxx @@ -126,9 +126,9 @@ namespace CXX { namespace CLI { - extern Key char_type; extern Key type_map = "type-map"; extern Key char_type = "char-type"; + extern Key char_encoding = "char-encoding"; extern Key output_dir = "output-dir"; extern Key xml_parser = "xml-parser"; extern Key generate_inline = "generate-inline"; @@ -206,6 +206,14 @@ namespace CXX << " values are 'char' (default) and 'wchar_t'." << endl; + e << "--char-encoding " << endl + << " Specify the character encoding that should be used\n" + << " in the object model. Valid values for the 'char'\n" + << " character type are 'utf8' (default), 'iso8859-1',\n" + << " 'lcp', and 'custom'. For the 'wchar_t' character\n" + << " type the only valid value is 'auto'." + << endl; + e << "--output-dir " << endl << " Write generated files to instead of current\n" << " directory." @@ -471,6 +479,11 @@ namespace CXX // Misc. // + e << "--custom-literals " << endl + << " Load custom XML string to C++ literal mappings\n" + << " from ." + << endl; + e << "--export-symbol " << endl << " Export symbol for Win32 DLL export/import control." << endl; @@ -600,6 +613,7 @@ namespace CXX generate (Parser::CLI::Options const& ops, Schema& schema, Path const& file_path, + StringLiteralMap const& string_literal_map, Boolean gen_driver, const WarningSet& disabled_warnings, FileList& file_list, @@ -648,7 +662,7 @@ namespace CXX // { NameProcessor proc; - proc.process (ops, schema, file_path); + proc.process (ops, schema, file_path, string_literal_map); } Boolean validation ((ops.value () == "expat" || @@ -701,7 +715,7 @@ namespace CXX String xns; { - Context ctx (std::wcerr, schema, ops, 0, 0, 0); + Context ctx (std::wcerr, schema, ops, 0, 0, 0, 0); xns = ctx.xs_ns_name (); } @@ -1144,7 +1158,13 @@ namespace CXX // HXX // { - Context ctx (hxx, schema, ops, &hxx_expr, &ixx_expr, &hxx_impl_expr); + Context ctx (hxx, + schema, + ops, + &string_literal_map, + &hxx_expr, + &ixx_expr, + &hxx_impl_expr); Indentation::Clip hxx_sloc (hxx); @@ -1231,7 +1251,13 @@ namespace CXX // if (inline_) { - Context ctx (ixx, schema, ops, &hxx_expr, &ixx_expr, &hxx_impl_expr); + Context ctx (ixx, + schema, + ops, + &string_literal_map, + &hxx_expr, + &ixx_expr, + &hxx_impl_expr); Indentation::Clip ixx_sloc (ixx); @@ -1287,7 +1313,13 @@ namespace CXX // if (source) { - Context ctx (cxx, schema, ops, &hxx_expr, &ixx_expr, &hxx_impl_expr); + Context ctx (cxx, + schema, + ops, + &string_literal_map, + &hxx_expr, + &ixx_expr, + &hxx_impl_expr); Indentation::Clip cxx_sloc (cxx); @@ -1351,8 +1383,13 @@ namespace CXX // if (impl) { - Context ctx (hxx_impl, schema, ops, - &hxx_expr, &ixx_expr, &hxx_impl_expr); + Context ctx (hxx_impl, + schema, + ops, + &string_literal_map, + &hxx_expr, + &ixx_expr, + &hxx_impl_expr); String guard (guard_expr.merge (guard_prefix + hxx_impl_name)); guard = ctx.escape (guard); // Make it a C++ id. @@ -1380,8 +1417,13 @@ namespace CXX // if (impl) { - Context ctx (cxx_impl, schema, ops, - &hxx_expr, &ixx_expr, &hxx_impl_expr); + Context ctx (cxx_impl, + schema, + ops, + &string_literal_map, + &hxx_expr, + &ixx_expr, + &hxx_impl_expr); // Set auto-indentation. // @@ -1397,8 +1439,13 @@ namespace CXX // if (driver) { - Context ctx (cxx_driver, schema, ops, - &hxx_expr, &ixx_expr, &hxx_impl_expr); + Context ctx (cxx_driver, + schema, + ops, + &string_literal_map, + &hxx_expr, + &ixx_expr, + &hxx_impl_expr); // Set auto-indentation. // @@ -1412,6 +1459,17 @@ namespace CXX return sloc; } + catch (UnrepresentableCharacter const& e) + { + wcerr << "error: character at position " << e.position () << " " + << "in string '" << e.string () << "' is unrepresentable in " + << "the target encoding" << endl; + + wcerr << "info: use the --custom-literals option to provide custom " + << "string literals mapping" << endl; + + throw Failed (); + } catch (NoNamespaceMapping const& e) { wcerr << e.file () << ":" << e.line () << ":" << e.column () diff --git a/xsd/cxx/parser/generator.hxx b/xsd/cxx/parser/generator.hxx index aaab3b8..8c5631d 100644 --- a/xsd/cxx/parser/generator.hxx +++ b/xsd/cxx/parser/generator.hxx @@ -18,6 +18,7 @@ #include +#include #include namespace CXX @@ -41,6 +42,7 @@ namespace CXX generate (CLI::Options const& options, XSDFrontend::SemanticGraph::Schema&, XSDFrontend::SemanticGraph::Path const& file, + StringLiteralMap const&, Boolean gen_driver, const WarningSet& disabled_warnings, FileList& file_list, diff --git a/xsd/cxx/parser/name-processor.cxx b/xsd/cxx/parser/name-processor.cxx index e9ba876..5f9209e 100644 --- a/xsd/cxx/parser/name-processor.cxx +++ b/xsd/cxx/parser/name-processor.cxx @@ -3,7 +3,6 @@ // copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC // license : GNU GPL v2 + exceptions; see accompanying LICENSE file -#include #include #include @@ -35,10 +34,13 @@ namespace CXX public: Context (CLI::Options const& ops, SemanticGraph::Schema& root, - SemanticGraph::Path const& file) + SemanticGraph::Path const& file, + StringLiteralMap const* map) : CXX::Context (std::wcerr, root, + map, ops.value (), + ops.value (), ops.value (), ops.value (), ops.value (), @@ -1101,9 +1103,10 @@ namespace CXX Void process_impl (CLI::Options const& ops, SemanticGraph::Schema& tu, - SemanticGraph::Path const& file) + SemanticGraph::Path const& file, + StringLiteralMap const& map) { - Context ctx (ops, tu, file); + Context ctx (ops, tu, file, &map); if (tu.names_begin ()->named ().name () == L"http://www.w3.org/2001/XMLSchema") @@ -1196,9 +1199,10 @@ namespace CXX Void NameProcessor:: process (CLI::Options const& ops, SemanticGraph::Schema& tu, - SemanticGraph::Path const& file) + SemanticGraph::Path const& file, + StringLiteralMap const& map) { - process_impl (ops, tu, file); + process_impl (ops, tu, file, map); } } } diff --git a/xsd/cxx/parser/name-processor.hxx b/xsd/cxx/parser/name-processor.hxx index f7849c8..fee7027 100644 --- a/xsd/cxx/parser/name-processor.hxx +++ b/xsd/cxx/parser/name-processor.hxx @@ -6,10 +6,9 @@ #ifndef CXX_PARSER_NAME_PROCESSOR_HXX #define CXX_PARSER_NAME_PROCESSOR_HXX -#include - #include +#include #include namespace CXX @@ -26,7 +25,8 @@ namespace CXX Void process (CLI::Options const& ops, XSDFrontend::SemanticGraph::Schema&, - XSDFrontend::SemanticGraph::Path const& file); + XSDFrontend::SemanticGraph::Path const& file, + StringLiteralMap const& map); }; } } diff --git a/xsd/cxx/parser/parser-header.cxx b/xsd/cxx/parser/parser-header.cxx index 878a891..8ecd898 100644 --- a/xsd/cxx/parser/parser-header.cxx +++ b/xsd/cxx/parser/parser-header.cxx @@ -1324,6 +1324,13 @@ namespace CXX } else { + if (ctx.char_type == L"char" && + ctx.xml_parser == L"xerces" && + ctx.char_encoding != L"custom") + { + ctx.os << "#include " << endl; + } + ctx.os << "#include " << endl << "#include " << endl << "#include " << endl diff --git a/xsd/cxx/parser/validator.cxx b/xsd/cxx/parser/validator.cxx index 526c941..9b5d967 100644 --- a/xsd/cxx/parser/validator.cxx +++ b/xsd/cxx/parser/validator.cxx @@ -27,7 +27,7 @@ namespace CXX CLI::Options const& options, const WarningSet& disabled_warnings, Boolean& valid_) - : Context (std::wcerr, root, options, 0, 0, 0), + : Context (std::wcerr, root, options, 0, 0, 0, 0), disabled_warnings_ (disabled_warnings), disabled_warnings_all_ (false), valid (valid_), @@ -584,7 +584,20 @@ namespace CXX if (options.value () == "expat" && options.value () == "wchar_t") { - wcerr << "error: using expat with wchar_t is not yet supported" + wcerr << "error: using expat with wchar_t is not supported" + << endl; + + return false; + } + + // + // + if (options.value () == "expat" && + !options.value ().empty () && + options.value () != "utf8") + { + wcerr << "error: using expat with character encoding other than " + << "utf8 is not supported" << endl; return false; -- cgit v1.1