summaryrefslogtreecommitdiff
path: root/xsd/cxx/parser
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2009-12-08 16:18:01 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2009-12-08 16:18:01 +0200
commit1ca6396a3dd284241de11bcaa210ad5836e8e5a8 (patch)
tree465c19f0d668a91bb556d748911847acfb80cb09 /xsd/cxx/parser
parentd71611d5fb575078bdf573c35257bb86bb7054e0 (diff)
Multiple object model character encodings support
Also add support for ISO-8859-1.
Diffstat (limited to 'xsd/cxx/parser')
-rw-r--r--xsd/cxx/parser/cli.hxx2
-rw-r--r--xsd/cxx/parser/elements.cxx3
-rw-r--r--xsd/cxx/parser/elements.hxx1
-rw-r--r--xsd/cxx/parser/generator.cxx82
-rw-r--r--xsd/cxx/parser/generator.hxx2
-rw-r--r--xsd/cxx/parser/name-processor.cxx16
-rw-r--r--xsd/cxx/parser/name-processor.hxx6
-rw-r--r--xsd/cxx/parser/parser-header.cxx7
-rw-r--r--xsd/cxx/parser/validator.cxx17
9 files changed, 113 insertions, 23 deletions
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<NarrowString>,
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<CLI::char_type> (),
+ ops.value<CLI::char_encoding> (),
ops.value<CLI::include_with_brackets> (),
ops.value<CLI::include_prefix> (),
ops.value<CLI::export_symbol> (),
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 <enc>" << 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 <dir>" << endl
<< " Write generated files to <dir> instead of current\n"
<< " directory."
@@ -471,6 +479,11 @@ namespace CXX
// Misc.
//
+ e << "--custom-literals <file>" << endl
+ << " Load custom XML string to C++ literal mappings\n"
+ << " from <file>."
+ << endl;
+
e << "--export-symbol <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<CLI::xml_parser> () == "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<Indentation::SLOC, WideChar> 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<Indentation::SLOC, WideChar> 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<Indentation::SLOC, WideChar> 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 <xsd.hxx>
+#include <cxx/literal-map.hxx>
#include <cxx/parser/cli.hxx>
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 <cxx/elements.hxx>
#include <cxx/parser/name-processor.hxx>
#include <xsd-frontend/semantic-graph.hxx>
@@ -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<CLI::char_type> (),
+ ops.value<CLI::char_encoding> (),
ops.value<CLI::include_with_brackets> (),
ops.value<CLI::include_prefix> (),
ops.value<CLI::export_symbol> (),
@@ -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 <cult/types.hxx>
-
#include <xsd-frontend/semantic-graph.hxx>
+#include <cxx/elements.hxx>
#include <cxx/parser/cli.hxx>
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 <xsd/cxx/xml/char-" << ctx.char_encoding << ".hxx>" << endl;
+ }
+
ctx.os << "#include <xsd/cxx/xml/error-handler.hxx>" << endl
<< "#include <xsd/cxx/parser/exceptions.hxx>" << endl
<< "#include <xsd/cxx/parser/elements.hxx>" << 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<CLI::xml_parser> () == "expat" &&
options.value<CLI::char_type> () == "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<CLI::xml_parser> () == "expat" &&
+ !options.value<CLI::char_encoding> ().empty () &&
+ options.value<CLI::char_encoding> () != "utf8")
+ {
+ wcerr << "error: using expat with character encoding other than "
+ << "utf8 is not supported"
<< endl;
return false;