aboutsummaryrefslogtreecommitdiff
path: root/xsde/cxx/hybrid
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2010-10-14 12:21:35 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2010-10-14 12:21:35 +0200
commitb7197929af1cca15e490703ba3632ae52a348b60 (patch)
treee4ed9dc7cf2021d6ad398fade7fc8148ff982b16 /xsde/cxx/hybrid
parent6f395f9f769866a04f6949cb7ed14f93d90cf728 (diff)
New mapping for anyType with support for polymorphism
Diffstat (limited to 'xsde/cxx/hybrid')
-rw-r--r--xsde/cxx/hybrid/generator.cxx440
-rw-r--r--xsde/cxx/hybrid/generator.hxx8
-rw-r--r--xsde/cxx/hybrid/parser-aggregate-header.cxx13
-rw-r--r--xsde/cxx/hybrid/parser-source.cxx124
-rw-r--r--xsde/cxx/hybrid/serializer-aggregate-header.cxx13
-rw-r--r--xsde/cxx/hybrid/serializer-source.cxx32
-rw-r--r--xsde/cxx/hybrid/tree-header.cxx9
-rw-r--r--xsde/cxx/hybrid/tree-size-processor.cxx23
8 files changed, 385 insertions, 277 deletions
diff --git a/xsde/cxx/hybrid/generator.cxx b/xsde/cxx/hybrid/generator.cxx
index ee39079..8e3d8d1 100644
--- a/xsde/cxx/hybrid/generator.cxx
+++ b/xsde/cxx/hybrid/generator.cxx
@@ -46,6 +46,7 @@
#include <boost/filesystem/fstream.hpp>
+#include <sstream>
#include <iostream>
#include <usage.hxx>
@@ -56,6 +57,7 @@ using std::endl;
using std::wcerr;
using namespace XSDFrontend::SemanticGraph;
+namespace Indentation = BackendElements::Indentation;
//
//
@@ -825,10 +827,67 @@ namespace CXX
*i, p == NarrowString::npos ? 0 : p + 1, NarrowString::npos));
}
}
+
+ struct FundNamespace: Namespace, Hybrid::Context
+ {
+ FundNamespace (Hybrid::Context& c, Char type)
+ : Namespace (c), Hybrid::Context (c), type_ (type)
+ {
+ }
+
+ void
+ traverse (Type& ns)
+ {
+ namespace CLI = Hybrid::CLI;
+
+ pre (ns);
+
+ os << "using ::xsde::cxx::hybrid::any_type;"
+ << endl;
+
+ Boolean us, ui;
+ String skel, impl;
+
+ if (type_ == 'p')
+ {
+ skel = options.value<CLI::pskel_type_suffix> ();
+ impl = options.value<CLI::pimpl_type_suffix> ();
+
+ us = skel == L"_pskel";
+ ui = impl == L"_pimpl";
+ }
+ else
+ {
+ skel = options.value<CLI::sskel_type_suffix> ();
+ impl = options.value<CLI::simpl_type_suffix> ();
+
+ us = skel == L"_sskel";
+ ui = impl == L"_simpl";
+ }
+
+ if (us)
+ os << "using ::xsde::cxx::hybrid::any_type_" << type_ << "skel;";
+ else
+ os << "using ::xsde::cxx::hybrid::any_type_" << type_ << "skel " <<
+ "any_type" << skel << ";";
+
+ if (ui)
+ os << "using ::xsde::cxx::hybrid::any_type_" << type_ << "impl;";
+ else
+ os << "using ::xsde::cxx::hybrid::any_type_" << type_ << "impl " <<
+ "any_type" << impl << ";";
+
+ post (ns);
+ }
+
+ private:
+ Char type_;
+ };
}
+
Parser::CLI::Options* Hybrid::Generator::
- parser_options (CLI::Options const& h)
+ parser_options (CLI::Options const& h, Schema& schema, Path const& path)
{
namespace H = CLI;
namespace P = Parser::CLI;
@@ -907,11 +966,33 @@ namespace CXX
r->value<P::show_sloc> () = h.value<H::show_sloc> ();
r->value<P::proprietary_license> () = h.value<H::proprietary_license> ();
+ // Add the anyType parser.
+ //
+ {
+ std::wostringstream os;
+ Context ctx (os, schema, path, h, 0, 0, 0);
+
+ os << endl
+ << "#include <xsde/cxx/hybrid/any-type.hxx>" << endl
+ << "#include <xsde/cxx/hybrid/any-type-pskel.hxx>" << endl
+ << "#include <xsde/cxx/hybrid/any-type-pimpl.hxx>" << endl
+ << endl;
+
+ {
+ Indentation::Clip<Indentation::CXX, WideChar> clip (os);
+
+ FundNamespace ns (ctx, 'p');
+ ns.dispatch (ctx.xs_ns ());
+ }
+
+ r->value<P::hxx_prologue> ().push_back (String (os.str ()).to_narrow ());
+ }
+
return r.release ();
}
Serializer::CLI::Options* Hybrid::Generator::
- serializer_options (CLI::Options const& h)
+ serializer_options (CLI::Options const& h, Schema& schema, Path const& path)
{
namespace H = CLI;
namespace S = Serializer::CLI;
@@ -990,6 +1071,28 @@ namespace CXX
r->value<S::show_sloc> () = h.value<H::show_sloc> ();
r->value<S::proprietary_license> () = h.value<H::proprietary_license> ();
+ // Add the anyType parser.
+ //
+ {
+ std::wostringstream os;
+ Context ctx (os, schema, path, h, 0, 0, 0);
+
+ os << endl
+ << "#include <xsde/cxx/hybrid/any-type.hxx>" << endl
+ << "#include <xsde/cxx/hybrid/any-type-sskel.hxx>" << endl
+ << "#include <xsde/cxx/hybrid/any-type-simpl.hxx>" << endl
+ << endl;
+
+ {
+ Indentation::Clip<Indentation::CXX, WideChar> clip (os);
+
+ FundNamespace ns (ctx, 's');
+ ns.dispatch (ctx.xs_ns ());
+ }
+
+ r->value<S::hxx_prologue> ().push_back (String (os.str ()).to_narrow ());
+ }
+
return r.release ();
}
@@ -1162,8 +1265,6 @@ namespace CXX
AutoUnlinks& unlinks)
{
using std::ios_base;
- namespace Indentation = BackendElements::Indentation;
-
typedef Context::Regex Regex;
try
@@ -1454,6 +1555,18 @@ namespace CXX
<< "#define " << guard << endl
<< endl;
+ // Version check.
+ //
+ fwd << "#include <xsde/cxx/version.hxx>" << endl
+ << endl
+ << "#if (XSDE_INT_VERSION != " << XSDE_INT_VERSION << "L)" << endl
+ << "#error XSD/e runtime version mismatch" << endl
+ << "#endif" << endl
+ << endl;
+
+ fwd << "#include <xsde/cxx/pre.hxx>" << endl
+ << endl;
+
// Copy prologue.
//
fwd << "// Begin prologue." << endl
@@ -1471,18 +1584,6 @@ namespace CXX
<< endl;
{
- // Version check.
- //
- fwd << "#include <xsde/cxx/version.hxx>" << endl
- << endl
- << "#if (XSDE_INT_VERSION != " << XSDE_INT_VERSION << "L)" << endl
- << "#error XSD/e runtime version mismatch" << endl
- << "#endif" << endl
- << endl;
-
- fwd << "#include <xsde/cxx/pre.hxx>" << endl
- << endl;
-
// Set auto-indentation.
//
Indentation::Clip<Indentation::CXX, WideChar> fwd_clip (fwd);
@@ -1490,9 +1591,6 @@ namespace CXX
// Generate.
//
generate_tree_forward (ctx, false);
-
- fwd << "#include <xsde/cxx/post.hxx>" << endl
- << endl;
}
// Copy epilogue.
@@ -1511,6 +1609,9 @@ namespace CXX
<< "// End epilogue." << endl
<< endl;
+ fwd << "#include <xsde/cxx/post.hxx>" << endl
+ << endl;
+
fwd << "#endif // " << guard << endl;
if (show_sloc)
@@ -1522,6 +1623,9 @@ namespace CXX
}
}
+ // C++ namespace mapping for the XML Schema namespace.
+ //
+ String xs_ns;
// HXX
//
@@ -1529,6 +1633,8 @@ namespace CXX
Context ctx (
hxx, schema, file_path, ops, &fwd_expr, &hxx_expr, &ixx_expr);
+ xs_ns = ctx.xs_ns_name ();
+
Indentation::Clip<Indentation::SLOC, WideChar> hxx_sloc (hxx);
String guard (guard_expr.merge (guard_prefix + hxx_name));
@@ -1539,140 +1645,140 @@ namespace CXX
<< "#define " << guard << endl
<< endl;
- // Copy prologue.
+ // Version check.
//
- hxx << "// Begin prologue." << endl
- << "//" << endl;
+ hxx << "#include <xsde/cxx/version.hxx>" << endl
+ << endl
+ << "#if (XSDE_INT_VERSION != " << XSDE_INT_VERSION << "L)" << endl
+ << "#error XSD/e runtime version mismatch" << endl
+ << "#endif" << endl
+ << endl;
- append (hxx,
- ops.value<CLI::hxx_prologue> (),
- ops.value<CLI::prologue> (),
- "");
- append (hxx,
- find_value (ops.value<CLI::hxx_prologue_file> (), ""),
- prologue);
+ // Runtime/generated code compatibility checks.
+ //
- hxx << "//" << endl
- << "// End prologue." << endl
+ hxx << "#include <xsde/cxx/config.hxx>" << endl
<< endl;
+ if (ops.value<CLI::char_encoding> () == "iso8859-1")
{
- // Version check.
- //
- hxx << "#include <xsde/cxx/version.hxx>" << endl
- << endl
- << "#if (XSDE_INT_VERSION != " << XSDE_INT_VERSION << "L)" << endl
- << "#error XSD/e runtime version mismatch" << endl
+ hxx << "#ifndef XSDE_ENCODING_ISO8859_1" << endl
+ << "#error the generated code uses the ISO-8859-1 encoding" <<
+ "while the XSD/e runtime does not (reconfigure the runtime " <<
+ "or change the --char-encoding value)" << endl
+ << "#endif" << endl
+ << endl;
+ }
+ else
+ {
+ hxx << "#ifndef XSDE_ENCODING_UTF8" << endl
+ << "#error the generated code uses the UTF-8 encoding" <<
+ "while the XSD/e runtime does not (reconfigure the runtime " <<
+ "or change the --char-encoding value)" << endl
<< "#endif" << endl
<< endl;
+ }
- // Runtime/generated code compatibility checks.
- //
+ if (ops.value<CLI::no_stl> ())
+ {
+ hxx << "#ifdef XSDE_STL" << endl
+ << "#error the XSD/e runtime uses STL while the " <<
+ "generated code does not (reconfigure the runtime or " <<
+ "remove --no-stl)" << endl
+ << "#endif" << endl
+ << endl;
+ }
+ else
+ {
+ hxx << "#ifndef XSDE_STL" << endl
+ << "#error the generated code uses STL while the " <<
+ "XSD/e runtime does not (reconfigure the runtime or " <<
+ "add --no-stl)" << endl
+ << "#endif" << endl
+ << endl;
+ }
- hxx << "#include <xsde/cxx/config.hxx>" << endl
+ if (ops.value<CLI::no_exceptions> ())
+ {
+ hxx << "#ifdef XSDE_EXCEPTIONS" << endl
+ << "#error the XSD/e runtime uses exceptions while the " <<
+ "generated code does not (reconfigure the runtime or " <<
+ "remove --no-exceptions)" << endl
+ << "#endif" << endl
<< endl;
+ }
+ else
+ {
+ hxx << "#ifndef XSDE_EXCEPTIONS" << endl
+ << "#error the generated code uses exceptions while the " <<
+ "XSD/e runtime does not (reconfigure the runtime or " <<
+ "add --no-exceptions)" << endl
+ << "#endif" << endl
+ << endl;
+ }
- if (ops.value<CLI::char_encoding> () == "iso8859-1")
- {
- hxx << "#ifndef XSDE_ENCODING_ISO8859_1" << endl
- << "#error the generated code uses the ISO-8859-1 encoding" <<
- "while the XSD/e runtime does not (reconfigure the runtime " <<
- "or change the --char-encoding value)" << endl
- << "#endif" << endl
- << endl;
- }
- else
- {
- hxx << "#ifndef XSDE_ENCODING_UTF8" << endl
- << "#error the generated code uses the UTF-8 encoding" <<
- "while the XSD/e runtime does not (reconfigure the runtime " <<
- "or change the --char-encoding value)" << endl
- << "#endif" << endl
- << endl;
- }
+ if (ops.value<CLI::no_long_long> ())
+ {
+ hxx << "#ifdef XSDE_LONGLONG" << endl
+ << "#error the XSD/e runtime uses long long while the " <<
+ "generated code does not (reconfigure the runtime or " <<
+ "remove --no-long-long)" << endl
+ << "#endif" << endl
+ << endl;
+ }
+ else
+ {
+ hxx << "#ifndef XSDE_LONGLONG" << endl
+ << "#error the generated code uses long long while the " <<
+ "XSD/e runtime does not (reconfigure the runtime or " <<
+ "add --no-long-long)" << endl
+ << "#endif" << endl
+ << endl;
+ }
- if (ops.value<CLI::no_stl> ())
- {
- hxx << "#ifdef XSDE_STL" << endl
- << "#error the XSD/e runtime uses STL while the " <<
- "generated code does not (reconfigure the runtime or " <<
- "remove --no-stl)" << endl
- << "#endif" << endl
- << endl;
- }
- else
- {
- hxx << "#ifndef XSDE_STL" << endl
- << "#error the generated code uses STL while the " <<
- "XSD/e runtime does not (reconfigure the runtime or " <<
- "add --no-stl)" << endl
- << "#endif" << endl
- << endl;
- }
+ if (ops.value<CLI::custom_allocator> ())
+ {
+ hxx << "#ifndef XSDE_CUSTOM_ALLOCATOR" << endl
+ << "#error the generated code uses custom allocator while " <<
+ "the XSD/e runtime does not (reconfigure the runtime or " <<
+ "remove --custom-allocator)" << endl
+ << "#endif" << endl
+ << endl;
+ }
+ else
+ {
+ hxx << "#ifdef XSDE_CUSTOM_ALLOCATOR" << endl
+ << "#error the XSD/e runtime uses custom allocator while " <<
+ "the generated code does not (reconfigure the runtime or " <<
+ "add --custom-allocator)" << endl
+ << "#endif" << endl
+ << endl;
+ }
- if (ops.value<CLI::no_exceptions> ())
- {
- hxx << "#ifdef XSDE_EXCEPTIONS" << endl
- << "#error the XSD/e runtime uses exceptions while the " <<
- "generated code does not (reconfigure the runtime or " <<
- "remove --no-exceptions)" << endl
- << "#endif" << endl
- << endl;
- }
- else
- {
- hxx << "#ifndef XSDE_EXCEPTIONS" << endl
- << "#error the generated code uses exceptions while the " <<
- "XSD/e runtime does not (reconfigure the runtime or " <<
- "add --no-exceptions)" << endl
- << "#endif" << endl
- << endl;
- }
+ //
+ //
- if (ops.value<CLI::no_long_long> ())
- {
- hxx << "#ifdef XSDE_LONGLONG" << endl
- << "#error the XSD/e runtime uses long long while the " <<
- "generated code does not (reconfigure the runtime or " <<
- "remove --no-long-long)" << endl
- << "#endif" << endl
- << endl;
- }
- else
- {
- hxx << "#ifndef XSDE_LONGLONG" << endl
- << "#error the generated code uses long long while the " <<
- "XSD/e runtime does not (reconfigure the runtime or " <<
- "add --no-long-long)" << endl
- << "#endif" << endl
- << endl;
- }
+ hxx << "#include <xsde/cxx/pre.hxx>" << endl
+ << endl;
- if (ops.value<CLI::custom_allocator> ())
- {
- hxx << "#ifndef XSDE_CUSTOM_ALLOCATOR" << endl
- << "#error the generated code uses custom allocator while " <<
- "the XSD/e runtime does not (reconfigure the runtime or " <<
- "remove --custom-allocator)" << endl
- << "#endif" << endl
- << endl;
- }
- else
- {
- hxx << "#ifdef XSDE_CUSTOM_ALLOCATOR" << endl
- << "#error the XSD/e runtime uses custom allocator while " <<
- "the generated code does not (reconfigure the runtime or " <<
- "add --custom-allocator)" << endl
- << "#endif" << endl
- << endl;
- }
+ // Copy prologue.
+ //
+ hxx << "// Begin prologue." << endl
+ << "//" << endl;
- //
- //
+ append (hxx,
+ ops.value<CLI::hxx_prologue> (),
+ ops.value<CLI::prologue> (),
+ "");
+ append (hxx,
+ find_value (ops.value<CLI::hxx_prologue_file> (), ""),
+ prologue);
- hxx << "#include <xsde/cxx/pre.hxx>" << endl
- << endl;
+ hxx << "//" << endl
+ << "// End prologue." << endl
+ << endl;
+ {
// Set auto-indentation.
//
Indentation::Clip<Indentation::CXX, WideChar> hxx_clip (hxx);
@@ -1705,9 +1811,6 @@ namespace CXX
<< "#endif // XSDE_DONT_INCLUDE_INLINE" << endl
<< endl;
}
-
- hxx << "#include <xsde/cxx/post.hxx>" << endl
- << endl;
}
// Copy epilogue.
@@ -1727,6 +1830,9 @@ namespace CXX
<< "// End epilogue." << endl
<< endl;
+ hxx << "#include <xsde/cxx/post.hxx>" << endl
+ << endl;
+
hxx << "#endif // " << guard << endl;
if (show_sloc)
@@ -1822,6 +1928,9 @@ namespace CXX
Indentation::Clip<Indentation::SLOC, WideChar> cxx_sloc (cxx);
+ cxx << "#include <xsde/cxx/pre.hxx>" << endl
+ << endl;
+
// Copy prologue.
//
cxx << "// Begin prologue." << endl
@@ -1840,9 +1949,6 @@ namespace CXX
<< endl;
{
- cxx << "#include <xsde/cxx/pre.hxx>" << endl
- << endl;
-
// Set auto-indentation.
//
Indentation::Clip<Indentation::CXX, WideChar> cxx_clip (cxx);
@@ -1860,9 +1966,6 @@ namespace CXX
if (!ops.value<CLI::generate_extraction> ().empty ())
generate_extraction_source (ctx);
-
- cxx << "#include <xsde/cxx/post.hxx>" << endl
- << endl;
}
// Copy epilogue.
@@ -1882,6 +1985,9 @@ namespace CXX
<< "// End epilogue." << endl
<< endl;
+ cxx << "#include <xsde/cxx/post.hxx>" << endl
+ << endl;
+
if (show_sloc)
{
wcerr << cxx_path << ": "
@@ -1899,6 +2005,26 @@ namespace CXX
{
generate_tree_type_map (ops, schema, file_path, hxx_name,
parser_type_map, serializer_type_map);
+
+ // Re-map anyType.
+ //
+ if (ops.value<CLI::generate_parser> ())
+ {
+ parser_type_map.push_back (
+ TypeMap::Namespace ("http://www.w3.org/2001/XMLSchema"));
+
+ TypeMap::Namespace& xs (parser_type_map.back ());
+ xs.types_push_back ("anyType", xs_ns + L"::any_type*");
+ }
+
+ if (ops.value<CLI::generate_serializer> ())
+ {
+ serializer_type_map.push_back (
+ TypeMap::Namespace ("http://www.w3.org/2001/XMLSchema"));
+
+ TypeMap::Namespace& xs (serializer_type_map.back ());
+ xs.types_push_back ("anyType", L"const " + xs_ns + L"::any_type&");
+ }
}
return sloc;
@@ -1949,8 +2075,6 @@ namespace CXX
AutoUnlinks& unlinks)
{
using std::ios_base;
- namespace Indentation = BackendElements::Indentation;
-
typedef BackendElements::Regex::Expression<Char> Regex;
try
@@ -2171,6 +2295,9 @@ namespace CXX
<< "#define " << guard << endl
<< endl;
+ hxx << "#include <xsde/cxx/pre.hxx>" << endl
+ << endl;
+
// Copy prologue.
//
hxx << "// Begin prologue." << endl
@@ -2189,9 +2316,6 @@ namespace CXX
<< endl;
{
- hxx << "#include <xsde/cxx/pre.hxx>" << endl
- << endl;
-
// Define omit aggregate macro.
//
hxx << "#ifndef XSDE_OMIT_PAGGR" << endl
@@ -2226,9 +2350,6 @@ namespace CXX
hxx << "#endif // XSDE_OMIT_PAGGR" << endl
<< endl;
}
-
- hxx << "#include <xsde/cxx/post.hxx>" << endl
- << endl;
}
// Copy epilogue.
@@ -2248,6 +2369,9 @@ namespace CXX
<< "// End epilogue." << endl
<< endl;
+ hxx << "#include <xsde/cxx/post.hxx>" << endl
+ << endl;
+
hxx << "#endif // " << guard << endl;
if (show_sloc)
@@ -2371,8 +2495,6 @@ namespace CXX
AutoUnlinks& unlinks)
{
using std::ios_base;
- namespace Indentation = BackendElements::Indentation;
-
typedef BackendElements::Regex::Expression<Char> Regex;
try
@@ -2580,6 +2702,9 @@ namespace CXX
<< "#define " << guard << endl
<< endl;
+ hxx << "#include <xsde/cxx/pre.hxx>" << endl
+ << endl;
+
// Copy prologue.
//
hxx << "// Begin prologue." << endl
@@ -2598,9 +2723,6 @@ namespace CXX
<< endl;
{
- hxx << "#include <xsde/cxx/pre.hxx>" << endl
- << endl;
-
// Define omit aggregate macro.
//
hxx << "#ifndef XSDE_OMIT_SAGGR" << endl
@@ -2635,9 +2757,6 @@ namespace CXX
hxx << "#endif // XSDE_OMIT_SAGGR" << endl
<< endl;
}
-
- hxx << "#include <xsde/cxx/post.hxx>" << endl
- << endl;
}
// Copy epilogue.
@@ -2657,6 +2776,9 @@ namespace CXX
<< "// End epilogue." << endl
<< endl;
+ hxx << "#include <xsde/cxx/post.hxx>" << endl
+ << endl;
+
hxx << "#endif // " << guard << endl;
if (show_sloc)
diff --git a/xsde/cxx/hybrid/generator.hxx b/xsde/cxx/hybrid/generator.hxx
index e812801..805e282 100644
--- a/xsde/cxx/hybrid/generator.hxx
+++ b/xsde/cxx/hybrid/generator.hxx
@@ -39,10 +39,14 @@ namespace CXX
options_spec ();
static Parser::CLI::Options*
- parser_options (CLI::Options const&);
+ parser_options (CLI::Options const&,
+ XSDFrontend::SemanticGraph::Schema&,
+ XSDFrontend::SemanticGraph::Path const&);
static Serializer::CLI::Options*
- serializer_options (CLI::Options const&);
+ serializer_options (CLI::Options const&,
+ XSDFrontend::SemanticGraph::Schema&,
+ XSDFrontend::SemanticGraph::Path const&);
// Calculate type sizes.
//
diff --git a/xsde/cxx/hybrid/parser-aggregate-header.cxx b/xsde/cxx/hybrid/parser-aggregate-header.cxx
index a769e6d..de76640 100644
--- a/xsde/cxx/hybrid/parser-aggregate-header.cxx
+++ b/xsde/cxx/hybrid/parser-aggregate-header.cxx
@@ -219,7 +219,11 @@ namespace CXX
virtual Void
traverse (SemanticGraph::AnyType& t)
{
- fund_type (t, "any_type");
+ if (fund_type (t, "any_type"))
+ {
+ if (polymorphic (t))
+ collect (t);
+ }
}
virtual Void
@@ -510,11 +514,16 @@ namespace CXX
}
private:
- virtual Void
+ virtual Boolean
fund_type (SemanticGraph::Type& t, String const& name)
{
if (map_.find (&t) == map_.end ())
+ {
map_[&t] = find_instance_name (name);
+ return true;
+ }
+
+ return false;
}
String
diff --git a/xsde/cxx/hybrid/parser-source.cxx b/xsde/cxx/hybrid/parser-source.cxx
index c610101..3bfac39 100644
--- a/xsde/cxx/hybrid/parser-source.cxx
+++ b/xsde/cxx/hybrid/parser-source.cxx
@@ -1836,30 +1836,25 @@ namespace CXX
// The following code is similar to what we have in post().
//
- // Default parser implementation for anyType returns void.
+ // If our base is a fixed-length type then copy the data
+ // over. Note that it cannot be a C-string.
//
- if (!b.is_a<SemanticGraph::AnyType> ())
+ if (fixed_length (b))
{
- // If our base is a fixed-length type then copy the data
- // over. Note that it cannot be a C-string.
- //
- if (fixed_length (b))
- {
- os << "static_cast< ";
+ os << "static_cast< ";
- base_name_.dispatch (b);
+ base_name_.dispatch (b);
- os << "& > (" << endl
- << "*" << top_member << ") = " << endl;
- }
+ os << "& > (" << endl
+ << "*" << top_member << ") = " << endl;
+ }
- if (tiein)
- os << "this->base_impl_.";
- else
- os << epimpl (b) << "::"; //@@ fq-name.
+ if (tiein)
+ os << "this->base_impl_.";
+ else
+ os << epimpl (b) << "::"; //@@ fq-name.
- os << post_name (b) << " ();";
- }
+ os << post_name (b) << " ();";
os << "}"
<< "else" << endl
@@ -1997,72 +1992,67 @@ namespace CXX
{
SemanticGraph::Type& b (c.inherits ().base ());
- // Default parser implementation for anyType returns void.
+ // If we are recursive but our base is not, we only call
+ // base post() if it is the first post call.
//
- if (!b.is_a<SemanticGraph::AnyType> ())
+ if (rec && !recursive (b))
{
- // If we are recursive but our base is not, we only call
- // base post() if it is the first post call.
- //
- if (rec && !recursive (b))
- {
- os << "if (this->" << epstate_top (c) << ")"
- << "{"
- << "this->" << epstate_top (c) << " = false;";
- }
+ os << "if (this->" << epstate_top (c) << ")"
+ << "{"
+ << "this->" << epstate_top (c) << " = false;";
+ }
- // If our base is a fixed-length type or C-string-base, then
- // copy the data over.
- //
- if (fixed_length (b))
- {
- os << "static_cast< ";
+ // If our base is a fixed-length type or C-string-base, then
+ // copy the data over.
+ //
+ if (fixed_length (b))
+ {
+ os << "static_cast< ";
- base_name_.dispatch (b);
+ base_name_.dispatch (b);
- os << "& > (";
+ os << "& > (";
- if (!rec)
- os << (fixed ? "" : "*") << "this->" << state << "." <<
- member;
- else
- os << endl
- << "*" << top_member;
+ if (!rec)
+ os << (fixed ? "" : "*") << "this->" << state << "." <<
+ member;
+ else
+ os << endl
+ << "*" << top_member;
- os << ") = " << endl;
- }
+ os << ") = " << endl;
+ }
- if (c_string_base)
- {
- os << "static_cast< ";
+ if (c_string_base)
+ {
+ os << "static_cast< ";
- base_name_.dispatch (b);
+ base_name_.dispatch (b);
- os << "* > (";
+ os << "* > (";
- if (!rec)
- os << "this->" << state << "." << member;
- else
- os << top_member;
+ if (!rec)
+ os << "this->" << state << "." << member;
+ else
+ os << top_member;
- os << ")->base_value (" << endl;
- }
+ os << ")->base_value (" << endl;
+ }
- if (tiein)
- os << "this->base_impl_.";
- else
- os << epimpl (b) << "::"; //@@ fq-name.
+ if (tiein)
+ os << "this->base_impl_.";
+ else
+ os << epimpl (b) << "::"; //@@ fq-name.
- os << post_name (b) << " ()";
+ os << post_name (b) << " ()";
- if (c_string_base)
- os << ")";
+ if (c_string_base)
+ os << ")";
- os << ";";
+ os << ";";
- if (rec && !recursive (b))
- os << "}";
- }
+ if (rec && !recursive (b))
+ os << "}";
}
if (fixed)
diff --git a/xsde/cxx/hybrid/serializer-aggregate-header.cxx b/xsde/cxx/hybrid/serializer-aggregate-header.cxx
index 1b4a03d..bacf474 100644
--- a/xsde/cxx/hybrid/serializer-aggregate-header.cxx
+++ b/xsde/cxx/hybrid/serializer-aggregate-header.cxx
@@ -219,7 +219,11 @@ namespace CXX
virtual Void
traverse (SemanticGraph::AnyType& t)
{
- fund_type (t, "any_type");
+ if (fund_type (t, "any_type"))
+ {
+ if (polymorphic (t))
+ collect (t);
+ }
}
virtual Void
@@ -510,11 +514,16 @@ namespace CXX
}
private:
- virtual Void
+ virtual Boolean
fund_type (SemanticGraph::Type& t, String const& name)
{
if (map_.find (&t) == map_.end ())
+ {
map_[&t] = find_instance_name (name);
+ return true;
+ }
+
+ return false;
}
String
diff --git a/xsde/cxx/hybrid/serializer-source.cxx b/xsde/cxx/hybrid/serializer-source.cxx
index ef9eae9..fa613d4 100644
--- a/xsde/cxx/hybrid/serializer-source.cxx
+++ b/xsde/cxx/hybrid/serializer-source.cxx
@@ -947,11 +947,13 @@ namespace CXX
if (polymorphic (t))
{
+ String skel (fq_name (t, "s:impl"));
+
if (stl)
{
os << "const ::std::string& dt = " << access << iter <<
"->_dynamic_type ();"
- << "if (dt != " << esskel (t) << "::_static_type ())" << endl
+ << "if (dt != " << skel << "::_static_type ())" << endl
<< "this->_context ().type_id (dt.c_str ());"
<< endl;
}
@@ -959,7 +961,7 @@ namespace CXX
{
os << "const char* dt = " << access << iter <<
"->_dynamic_type ();"
- << "if (strcmp (dt, " << esskel (t) <<
+ << "if (strcmp (dt, " << skel <<
"::_static_type ()) != 0)" << endl
<< "this->_context ().type_id (dt);"
<< endl;
@@ -994,11 +996,13 @@ namespace CXX
if (polymorphic (t))
{
+ String skel (fq_name (t, "s:impl"));
+
if (stl)
{
os << "const ::std::string& dt = " << access << ename (e) <<
" ()._dynamic_type ();"
- << "if (dt != " << esskel (t) << "::_static_type ())" << endl
+ << "if (dt != " << skel << "::_static_type ())" << endl
<< "this->_context ().type_id (dt.c_str ());"
<< endl;
}
@@ -1006,7 +1010,7 @@ namespace CXX
{
os << "const char* dt = " << access << ename (e) <<
" ()._dynamic_type ();"
- << "if (strcmp (dt, " << esskel (t) <<
+ << "if (strcmp (dt, " << skel <<
"::_static_type ()) != 0)" << endl
<< "this->_context ().type_id (dt);"
<< endl;
@@ -1163,7 +1167,7 @@ namespace CXX
if (rec || (tiein && hb))
{
os << name << "::" << endl
- << name << " ()" << endl;
+ << name << " ()";
String d ("\n: ");
@@ -1234,20 +1238,16 @@ namespace CXX
<< endl;
}
- // Call base pre(). Default serializer implementation for
- // anyType takes void.
+ // Call base pre().
//
- if (!b.is_a<SemanticGraph::AnyType> ())
- {
- if (tiein)
- os << "this->base_impl_.pre (";
- else
- os << esimpl (b) << "::pre (";
+ if (tiein)
+ os << "this->base_impl_.pre (";
+ else
+ os << esimpl (b) << "::pre (";
- type_pass_.dispatch (b);
+ type_pass_.dispatch (b);
- os << "x);";
- }
+ os << "x);";
}
if (!restriction)
diff --git a/xsde/cxx/hybrid/tree-header.cxx b/xsde/cxx/hybrid/tree-header.cxx
index b82cb7b..90bdd24 100644
--- a/xsde/cxx/hybrid/tree-header.cxx
+++ b/xsde/cxx/hybrid/tree-header.cxx
@@ -608,7 +608,6 @@ namespace CXX
Traversal::Union,
Traversal::Complex,
- Traversal::AnyType,
Traversal::AnySimpleType,
Traversal::Fundamental::Byte,
@@ -729,15 +728,9 @@ namespace CXX
Complex::contains_compositor (c, contains_compositor_);
}
- // anyType & anySimpleType.
+ // anySimpleType
//
virtual Void
- traverse (SemanticGraph::AnyType&)
- {
- align_type ("char", 1);
- }
-
- virtual Void
traverse (SemanticGraph::AnySimpleType&)
{
align_type ("size_t", 5); // std::string
diff --git a/xsde/cxx/hybrid/tree-size-processor.cxx b/xsde/cxx/hybrid/tree-size-processor.cxx
index e56b828..4aad4a2 100644
--- a/xsde/cxx/hybrid/tree-size-processor.cxx
+++ b/xsde/cxx/hybrid/tree-size-processor.cxx
@@ -542,18 +542,12 @@ namespace CXX
virtual Void
traverse (SemanticGraph::AnyType& t)
{
- /*
- @@ disabled
+ set (t, false);
+
// Check if this type is marked polymorphic.
//
if (poly_types_.find (t.name ()) != poly_types_.end ())
- {
t.context ().set ("polymorphic", true);
- set (t, false);
- }
- else
- */
- set (t, true);
}
virtual Void
@@ -880,14 +874,8 @@ namespace CXX
// Only user-defined and anyType can be declared polymorphic.
//
- /*
- @@ disabled
if (rt.is_a<SemanticGraph::Fundamental::Type> () ||
rt.is_a<SemanticGraph::AnySimpleType> ())
- */
- if (rt.is_a<SemanticGraph::Fundamental::Type> () ||
- rt.is_a<SemanticGraph::AnySimpleType> () ||
- rt.is_a<SemanticGraph::AnyType> ())
{
wcerr << r.file () << ":" << r.line () << ":" << r.column ()
<< ": error: built-in type '" << rt.name () << "' "
@@ -897,16 +885,9 @@ namespace CXX
<< ": info: because type '" << rt.name () << "' is "
<< "used in a substitution group declared here" << endl;
- /*
- @@ disabled
wcerr << r.file () << ":" << r.line () << ":" << r.column ()
<< ": info: only user-defined types and anyType can "
<< "be polymorphic in this mapping" << endl;
- */
-
- wcerr << r.file () << ":" << r.line () << ":" << r.column ()
- << ": info: only user-defined types can "
- << "be polymorphic in this mapping" << endl;
valid_ = false;
return;