From b7197929af1cca15e490703ba3632ae52a348b60 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 14 Oct 2010 12:21:35 +0200 Subject: New mapping for anyType with support for polymorphism --- NEWS | 4 + dist/libxsde/xsde/makefile | 8 +- dist/libxsde/xsde/nmakefile | 8 +- dist/tests/cxx/hybrid/makefile | 2 +- dist/tests/cxx/hybrid/nmakefile | 2 +- documentation/cxx/hybrid/guide/index.xhtml | 87 ++++ libxsde/xsde/cxx/hybrid/any-type-pimpl.cxx | 102 +++++ libxsde/xsde/cxx/hybrid/any-type-pimpl.hxx | 48 +++ libxsde/xsde/cxx/hybrid/any-type-pskel.cxx | 104 +++++ libxsde/xsde/cxx/hybrid/any-type-pskel.hxx | 84 ++++ libxsde/xsde/cxx/hybrid/any-type-pskel.ixx | 29 ++ libxsde/xsde/cxx/hybrid/any-type-simpl.cxx | 20 + libxsde/xsde/cxx/hybrid/any-type-simpl.hxx | 32 ++ libxsde/xsde/cxx/hybrid/any-type-sskel.cxx | 29 ++ libxsde/xsde/cxx/hybrid/any-type-sskel.hxx | 66 ++++ libxsde/xsde/cxx/hybrid/any-type-sskel.ixx | 27 ++ libxsde/xsde/cxx/hybrid/any-type.cxx | 151 ++++++- libxsde/xsde/cxx/hybrid/any-type.hxx | 56 ++- libxsde/xsde/makefile | 8 +- tests/cxx/hybrid/polymorphism/any-type/driver.cxx | 2 +- .../cxx/hybrid/polymorphism/any-type/test-000.std | 15 + .../cxx/hybrid/polymorphism/any-type/test-000.xml | 27 +- tests/cxx/hybrid/polymorphism/any-type/test.xsd | 2 + tests/cxx/hybrid/polymorphism/makefile | 4 +- xsde/cxx/elements.cxx | 1 - xsde/cxx/hybrid/generator.cxx | 440 +++++++++++++-------- xsde/cxx/hybrid/generator.hxx | 8 +- xsde/cxx/hybrid/parser-aggregate-header.cxx | 13 +- xsde/cxx/hybrid/parser-source.cxx | 124 +++--- xsde/cxx/hybrid/serializer-aggregate-header.cxx | 13 +- xsde/cxx/hybrid/serializer-source.cxx | 32 +- xsde/cxx/hybrid/tree-header.cxx | 9 +- xsde/cxx/hybrid/tree-size-processor.cxx | 23 +- xsde/cxx/parser/generator.cxx | 392 +++++++++--------- xsde/cxx/parser/parser-header.cxx | 14 +- xsde/cxx/parser/parser-inline.cxx | 19 +- xsde/cxx/serializer/generator.cxx | 392 +++++++++--------- xsde/cxx/serializer/serializer-header.cxx | 14 +- xsde/cxx/serializer/serializer-inline.cxx | 19 +- xsde/xsde.cxx | 42 +- 40 files changed, 1747 insertions(+), 725 deletions(-) create mode 100644 libxsde/xsde/cxx/hybrid/any-type-pimpl.cxx create mode 100644 libxsde/xsde/cxx/hybrid/any-type-pimpl.hxx create mode 100644 libxsde/xsde/cxx/hybrid/any-type-pskel.cxx create mode 100644 libxsde/xsde/cxx/hybrid/any-type-pskel.hxx create mode 100644 libxsde/xsde/cxx/hybrid/any-type-pskel.ixx create mode 100644 libxsde/xsde/cxx/hybrid/any-type-simpl.cxx create mode 100644 libxsde/xsde/cxx/hybrid/any-type-simpl.hxx create mode 100644 libxsde/xsde/cxx/hybrid/any-type-sskel.cxx create mode 100644 libxsde/xsde/cxx/hybrid/any-type-sskel.hxx create mode 100644 libxsde/xsde/cxx/hybrid/any-type-sskel.ixx create mode 100644 tests/cxx/hybrid/polymorphism/any-type/test-000.std diff --git a/NEWS b/NEWS index 0ce961e..b76baec 100644 --- a/NEWS +++ b/NEWS @@ -51,6 +51,10 @@ Version 3.2.0 * The anySimpleType build-in type is now mapped to std::string or a C-string, depending on whether STL is enabled or not. + * New mapping for anyType with support for polymorphism. For more + information, see Section 5.14, "Mapping for anyType" in the Embedded + C++/Hybrid Mapping Getting Started Guide. + * New configuration parameter, XSDE_STL_ITERATOR, makes iterators provided by the mapping conform to the STL requirements. This feature requires working header and allows you to use the standard diff --git a/dist/libxsde/xsde/makefile b/dist/libxsde/xsde/makefile index af6cfe9..99cddc1 100644 --- a/dist/libxsde/xsde/makefile +++ b/dist/libxsde/xsde/makefile @@ -69,7 +69,13 @@ endif ## C++/Hybrid ## -src += cxx/hybrid/sequence.cxx +src += \ +cxx/hybrid/any-type.cxx \ +cxx/hybrid/any-type-pimpl.cxx \ +cxx/hybrid/any-type-pskel.cxx \ +cxx/hybrid/any-type-simpl.cxx \ +cxx/hybrid/any-type-sskel.cxx \ +cxx/hybrid/sequence.cxx ifeq ($(XSDE_POLYMORPHIC),y) src += \ diff --git a/dist/libxsde/xsde/nmakefile b/dist/libxsde/xsde/nmakefile index aaffe74..bbf8797 100644 --- a/dist/libxsde/xsde/nmakefile +++ b/dist/libxsde/xsde/nmakefile @@ -75,7 +75,13 @@ src = $(src) cxx\xml\char-table.cxx cxx\xml\ncname.cxx ## C++/Hybrid ## -src = $(src) cxx\hybrid\sequence.cxx +src = $(src) \ +cxx\hybrid\any-type.cxx \ +cxx\hybrid\any-type-pimpl.cxx \ +cxx\hybrid\any-type-pskel.cxx \ +cxx\hybrid\any-type-simpl.cxx \ +cxx\hybrid\any-type-sskel.cxx \ +cxx\hybrid\sequence.cxx !if "$(XSDE_POLYMORPHIC)" == "y" src = $(src) \ diff --git a/dist/tests/cxx/hybrid/makefile b/dist/tests/cxx/hybrid/makefile index 2117324..828d663 100644 --- a/dist/tests/cxx/hybrid/makefile +++ b/dist/tests/cxx/hybrid/makefile @@ -5,7 +5,7 @@ include $(root)/build/config.make dirs := sequences ifeq ($(XSDE_POLYMORPHIC),y) -dirs += polymorphism/enumeration polymorphism/multischema +dirs += polymorphism/any-type polymorphism/enumeration polymorphism/multischema endif ifeq ($(XSDE_STL),y) diff --git a/dist/tests/cxx/hybrid/nmakefile b/dist/tests/cxx/hybrid/nmakefile index 57d2324..3f94ad0 100644 --- a/dist/tests/cxx/hybrid/nmakefile +++ b/dist/tests/cxx/hybrid/nmakefile @@ -5,7 +5,7 @@ root = ..\..\.. dirs = sequences !if "$(XSDE_POLYMORPHIC)" == "y" -dirs = $(dirs) polymorphism\enumeration polymorphism\multischema +dirs = $(dirs) polymorphism\any-type polymorphism\enumeration polymorphism\multischema !endif !if "$(XSDE_STL)" == "y" diff --git a/documentation/cxx/hybrid/guide/index.xhtml b/documentation/cxx/hybrid/guide/index.xhtml index 7d33a4e..b3edc1d 100644 --- a/documentation/cxx/hybrid/guide/index.xhtml +++ b/documentation/cxx/hybrid/guide/index.xhtml @@ -270,6 +270,7 @@ 5.11Mapping for gYear 5.12Mapping for gYearMonth 5.13Mapping for time + 5.14Mapping for anyType @@ -4599,6 +4600,21 @@ for (supermen::person_iterator i = sm->person ().begin (); time Section 5.13, "Mapping for time" + + + anyType and anySimpleType + + + anyType + any_type + Section 5.14, "Mapping for anyType" + + + anySimpleType + any_simple_type + std::string or char*
+ Section 3.1, "Standard Template Library" +

As you can see from the table above a number of built-in @@ -5644,6 +5660,77 @@ namespace xml_schema } +

5.14 Mapping for anyType

+ +

The anyType built-in XML Schema type is mapped to + the any_type class in the xml_schema + namespace. With C++ exceptions enabled (Section 3.3, + "C++ Exceptions"), it has the following interface:

+ +
+namespace xml_schema
+{
+  class any_type
+  {
+  public:
+    // Custom data.
+    //
+    typedef xml_schema::data_sequence custom_data_sequence;
+    typedef custom_data_sequence::iterator custom_data_iterator;
+    typedef custom_data_sequence::const_iterator custom_data_const_iterator;
+
+    void
+    allocate_custom_data ();
+
+    const custom_data_sequence&
+    custom_data () const;
+
+    custom_data_sequence&
+    custom_data ();
+  };
+}
+  
+ +

If C++ exceptions are disabled, the any_type class has + the following interface:

+ +
+namespace xml_schema
+{
+  class any_type
+  {
+  public:
+    // Custom data.
+    //
+    typedef xml_schema::data_sequence custom_data_sequence;
+    typedef custom_data_sequence::iterator custom_data_iterator;
+    typedef custom_data_sequence::const_iterator custom_data_const_iterator;
+
+    bool
+    allocate_custom_data ();
+
+    const custom_data_sequence&
+    custom_data () const;
+
+    custom_data_sequence&
+    custom_data ();
+  };
+}
+  
+ +

The allocate_custom_data() function allocates the + custom data sequence. With C++ exceptions disabled, it returns + false if memory allocation has failed and true + otherwise. For more information on custom data, refer to + Section 4.9, "Customizing the Object Model".

+ +

The default parser and serializer implementations for the + anyType built-in type ignore all its content and + return an empty any_type instance. If your application + needs to access this content, then you will need to provide your + own implementations of these parser and serializer and use the + custom data sequence to store the extracted data.

+

6 Parsing and Serialization

diff --git a/libxsde/xsde/cxx/hybrid/any-type-pimpl.cxx b/libxsde/xsde/cxx/hybrid/any-type-pimpl.cxx new file mode 100644 index 0000000..30ec8f6 --- /dev/null +++ b/libxsde/xsde/cxx/hybrid/any-type-pimpl.cxx @@ -0,0 +1,102 @@ +// file : xsde/cxx/hybrid/any-type-pimpl.cxx +// author : Boris Kolpackov +// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include + +#ifdef XSDE_CUSTOM_ALLOCATOR +# include +#endif + +#include + +namespace xsde +{ + namespace cxx + { + namespace hybrid + { + any_type_pimpl:: + ~any_type_pimpl () + { + if (!base_ && val_) + { +#ifndef XSDE_CUSTOM_ALLOCATOR + delete val_; +#else + val_->~any_type (); + cxx::free (val_); +#endif + } + } + + void any_type_pimpl:: + _reset () + { + any_type_pskel::_reset (); + + if (!base_ && val_) + { +#ifndef XSDE_CUSTOM_ALLOCATOR + delete val_; +#else + val_->~any_type (); + cxx::free (val_); +#endif + val_ = 0; + } + } + + any_type_pimpl:: + any_type_pimpl (bool base) + : base_ (base), val_ (0) + { + } + + void any_type_pimpl:: + pre_impl (any_type* qn) + { + val_ = qn; + } + + void any_type_pimpl:: + _pre () + { + if (val_ == 0) + { +#ifndef XSDE_CUSTOM_ALLOCATOR + val_ = new any_type (); +#else + val_ = static_cast (alloc (sizeof (any_type))); + +#ifdef XSDE_EXCEPTIONS + alloc_guard ag (val_); + new (val_) any_type (); + ag.release (); +#else + if (val_) + new (val_) any_type (); +#endif +#endif + +#ifndef XSDE_EXCEPTIONS + if (val_ == 0) + { + _sys_error (sys_error::no_memory); + return; + } +#endif + } + } + + any_type* any_type_pimpl:: + post_any_type () + { + any_type* r = val_; + val_ = 0; + return r; + } + } + } +} diff --git a/libxsde/xsde/cxx/hybrid/any-type-pimpl.hxx b/libxsde/xsde/cxx/hybrid/any-type-pimpl.hxx new file mode 100644 index 0000000..4e799a6 --- /dev/null +++ b/libxsde/xsde/cxx/hybrid/any-type-pimpl.hxx @@ -0,0 +1,48 @@ +// file : xsde/cxx/hybrid/any-type-pimpl.hxx +// author : Boris Kolpackov +// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_HYBRID_ANY_TYPE_PIMPL_HXX +#define XSDE_CXX_HYBRID_ANY_TYPE_PIMPL_HXX + +#include + +#include + +namespace xsde +{ + namespace cxx + { + namespace hybrid + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct any_type_pimpl: virtual any_type_pskel +#else + struct any_type_pimpl: any_type_pskel +#endif + { + ~any_type_pimpl (); + any_type_pimpl (bool base = false); + + void + pre_impl (any_type*); + + virtual void + _pre (); + + virtual any_type* + post_any_type (); + + virtual void + _reset (); + + protected: + bool base_; + any_type* val_; + }; + } + } +} + +#endif // XSDE_CXX_HYBRID_ANY_TYPE_PIMPL_HXX diff --git a/libxsde/xsde/cxx/hybrid/any-type-pskel.cxx b/libxsde/xsde/cxx/hybrid/any-type-pskel.cxx new file mode 100644 index 0000000..d8434b2 --- /dev/null +++ b/libxsde/xsde/cxx/hybrid/any-type-pskel.cxx @@ -0,0 +1,104 @@ +// file : xsde/cxx/hybrid/any-type-pskel.cxx +// author : Boris Kolpackov +// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include + +namespace xsde +{ + namespace cxx + { + namespace hybrid + { +#ifdef XSDE_POLYMORPHIC + bool any_type_pskel:: + _start_element_impl (const ro_string& ns, + const ro_string& name, + const char* type) + { +#ifdef XSDE_PARSER_VALIDATION + parser::context& ctx = _context (); + ctx.current_.any_ = true; + ctx.current_.depth_++; + + _start_any_element (ns, name, type); + return true; +#else + return false; +#endif + } +#else + bool any_type_pskel:: + _start_element_impl (const ro_string& ns, const ro_string& name) + { +#ifdef XSDE_PARSER_VALIDATION + parser::context& ctx = _context (); + ctx.current_.any_ = true; + ctx.current_.depth_++; + + _start_any_element (ns, name); + return true; +#else + return false; +#endif + } +#endif + + bool any_type_pskel:: + _end_element_impl (const ro_string& ns, const ro_string& name) + { +#ifdef XSDE_PARSER_VALIDATION + _end_any_element (ns, name); + return true; +#else + return false; +#endif + } + +#ifdef XSDE_PARSER_VALIDATION + bool any_type_pskel:: + _attribute_impl_phase_two (const ro_string& ns, + const ro_string& name, + const ro_string& value) + { + _any_attribute (ns, name, value); + return true; + } +#else + bool any_type_pskel:: + _attribute_impl (const ro_string&, + const ro_string&, + const ro_string&) + { + return false; + } +#endif + + bool any_type_pskel:: + _characters_impl (const ro_string& s) + { +#ifdef XSDE_PARSER_VALIDATION + _any_characters (s); + return true; +#else + return false; +#endif + } + +#ifdef XSDE_POLYMORPHIC + const char* any_type_pskel:: + _static_type () + { + return "anyType http://www.w3.org/2001/XMLSchema"; + } + + const char* any_type_pskel:: + _dynamic_type () const + { + return _static_type (); + } +#endif + } + } +} diff --git a/libxsde/xsde/cxx/hybrid/any-type-pskel.hxx b/libxsde/xsde/cxx/hybrid/any-type-pskel.hxx new file mode 100644 index 0000000..6751120 --- /dev/null +++ b/libxsde/xsde/cxx/hybrid/any-type-pskel.hxx @@ -0,0 +1,84 @@ +// file : xsde/cxx/hybrid/any-type-pskel.hxx +// author : Boris Kolpackov +// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_HYBRID_ANY_TYPE_PSKEL_HXX +#define XSDE_CXX_HYBRID_ANY_TYPE_PSKEL_HXX + +#include + +#ifdef XSDE_PARSER_VALIDATION +# include +#else +# include +#endif + +#include + +namespace xsde +{ + namespace cxx + { + namespace hybrid + { +#ifdef XSDE_PARSER_VALIDATION + struct any_type_pskel: parser::validating::complex_content +#else + struct any_type_pskel: parser::non_validating::complex_content +#endif + { +#ifdef XSDE_POLYMORPHIC + virtual bool + _start_element_impl (const ro_string&, + const ro_string&, + const char*); +#else + virtual bool + _start_element_impl (const ro_string&, const ro_string&); +#endif + + virtual bool + _end_element_impl (const ro_string&, const ro_string&); + +#ifdef XSDE_PARSER_VALIDATION + virtual bool + _attribute_impl_phase_two (const ro_string&, + const ro_string&, + const ro_string&); +#else + virtual bool + _attribute_impl (const ro_string&, + const ro_string&, + const ro_string&); +#endif + + virtual bool + _characters_impl (const ro_string&); + + virtual any_type* + post_any_type () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + any_type_pskel (); + any_type_pskel (any_type_pskel* impl, void*); + + protected: + any_type_pskel* any_type_impl_; +#endif + }; + } + } +} + +#include + +#endif // XSDE_CXX_HYBRID_ANY_TYPE_PSKEL_HXX diff --git a/libxsde/xsde/cxx/hybrid/any-type-pskel.ixx b/libxsde/xsde/cxx/hybrid/any-type-pskel.ixx new file mode 100644 index 0000000..b63ec72 --- /dev/null +++ b/libxsde/xsde/cxx/hybrid/any-type-pskel.ixx @@ -0,0 +1,29 @@ +// file : xsde/cxx/hybrid/any-type-pskel.ixx +// author : Boris Kolpackov +// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +namespace xsde +{ + namespace cxx + { + namespace hybrid + { + // any_type_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline any_type_pskel:: + any_type_pskel () + : any_type_impl_ (0) + { + } + + inline any_type_pskel:: + any_type_pskel (any_type_pskel* impl, void*) + : complex_content (impl, 0), any_type_impl_ (impl) + { + } +#endif + } + } +} diff --git a/libxsde/xsde/cxx/hybrid/any-type-simpl.cxx b/libxsde/xsde/cxx/hybrid/any-type-simpl.cxx new file mode 100644 index 0000000..fd65e92 --- /dev/null +++ b/libxsde/xsde/cxx/hybrid/any-type-simpl.cxx @@ -0,0 +1,20 @@ +// file : xsde/cxx/hybrid/any-type-simpl.cxx +// author : Boris Kolpackov +// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include + +namespace xsde +{ + namespace cxx + { + namespace hybrid + { + void any_type_simpl:: + pre (const any_type&) + { + } + } + } +} diff --git a/libxsde/xsde/cxx/hybrid/any-type-simpl.hxx b/libxsde/xsde/cxx/hybrid/any-type-simpl.hxx new file mode 100644 index 0000000..a6ef220 --- /dev/null +++ b/libxsde/xsde/cxx/hybrid/any-type-simpl.hxx @@ -0,0 +1,32 @@ +// file : xsde/cxx/hybrid/any-type-simpl.hxx +// author : Boris Kolpackov +// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_HYBRID_ANY_TYPE_SIMPL_HXX +#define XSDE_CXX_HYBRID_ANY_TYPE_SIMPL_HXX + +#include + +#include + +namespace xsde +{ + namespace cxx + { + namespace hybrid + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct any_type_simpl: virtual any_type_sskel +#else + struct any_type_simpl: any_type_sskel +#endif + { + virtual void + pre (const any_type&); + }; + } + } +} + +#endif // XSDE_CXX_HYBRID_ANY_TYPE_SIMPL_HXX diff --git a/libxsde/xsde/cxx/hybrid/any-type-sskel.cxx b/libxsde/xsde/cxx/hybrid/any-type-sskel.cxx new file mode 100644 index 0000000..7c6c1c1 --- /dev/null +++ b/libxsde/xsde/cxx/hybrid/any-type-sskel.cxx @@ -0,0 +1,29 @@ +// file : xsde/cxx/hybrid/any-type-sskel.cxx +// author : Boris Kolpackov +// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include + +namespace xsde +{ + namespace cxx + { + namespace hybrid + { +#ifdef XSDE_POLYMORPHIC + const char* any_type_sskel:: + _static_type () + { + return "anyType http://www.w3.org/2001/XMLSchema"; + } + + const char* any_type_sskel:: + _dynamic_type () const + { + return _static_type (); + } +#endif + } + } +} diff --git a/libxsde/xsde/cxx/hybrid/any-type-sskel.hxx b/libxsde/xsde/cxx/hybrid/any-type-sskel.hxx new file mode 100644 index 0000000..29663be --- /dev/null +++ b/libxsde/xsde/cxx/hybrid/any-type-sskel.hxx @@ -0,0 +1,66 @@ +// file : xsde/cxx/hybrid/any-type-sskel.hxx +// author : Boris Kolpackov +// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_HYBRID_ANY_TYPE_SSKEL_HXX +#define XSDE_CXX_HYBRID_ANY_TYPE_SSKEL_HXX + +#include + +#ifdef XSDE_SERIALIZER_VALIDATION +# include +#else +# include +#endif + +#include + +namespace xsde +{ + namespace cxx + { + namespace hybrid + { +#ifdef XSDE_SERIALIZER_VALIDATION + struct any_type_sskel: serializer::validating::complex_content +#else + struct any_type_sskel: serializer::non_validating::complex_content +#endif + { + virtual void + pre (const any_type&) = 0; + + // Override the following two functions to implement + // your logic. + // + + // virtual void + // _serialize_attributes (); + + // virtual void + // _serialize_content (); + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + any_type_sskel (); + any_type_sskel (any_type_sskel* impl, void*); + + protected: + any_type_sskel* any_type_impl_; +#endif + }; + } + } +} + +#include + +#endif // XSDE_CXX_HYBRID_ANY_TYPE_SSKEL_HXX diff --git a/libxsde/xsde/cxx/hybrid/any-type-sskel.ixx b/libxsde/xsde/cxx/hybrid/any-type-sskel.ixx new file mode 100644 index 0000000..341a340 --- /dev/null +++ b/libxsde/xsde/cxx/hybrid/any-type-sskel.ixx @@ -0,0 +1,27 @@ +// file : xsde/cxx/hybrid/any-type-sskel.ixx +// author : Boris Kolpackov +// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +namespace xsde +{ + namespace cxx + { + namespace hybrid + { +#ifdef XSDE_REUSE_STYLE_TIEIN + inline any_type_sskel:: + any_type_sskel () + : any_type_impl_ (0) + { + } + + inline any_type_sskel:: + any_type_sskel (any_type_sskel* impl, void*) + : complex_content (impl, 0), any_type_impl_ (impl) + { + } +#endif + } + } +} diff --git a/libxsde/xsde/cxx/hybrid/any-type.cxx b/libxsde/xsde/cxx/hybrid/any-type.cxx index d4f257d..544e11b 100644 --- a/libxsde/xsde/cxx/hybrid/any-type.cxx +++ b/libxsde/xsde/cxx/hybrid/any-type.cxx @@ -3,6 +3,12 @@ // copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC // license : GNU GPL v2 + exceptions; see accompanying LICENSE file +#include + +#ifdef XSDE_CUSTOM_ALLOCATOR +# include +#endif + #include namespace xsde @@ -13,12 +19,155 @@ namespace xsde { // any_type // -#ifdef XSDE_POLYMORPHIC any_type:: ~any_type () { +#ifndef XSDE_CUSTOM_ALLOCATOR + delete data_; +#else + if (data_ != 0) + { + data_->~data_sequence (); + cxx::free (data_); + } +#endif + } + +#ifdef XSDE_EXCEPTIONS + void any_type:: + allocate_custom_data () + { + if (data_ != 0) + return; + +#ifndef XSDE_CUSTOM_ALLOCATOR + data_ = new data_sequence; +#else + // Default data_sequence c-tor cannot throw so we don't need a guard. + // + data_ = static_cast ( + cxx::alloc (sizeof (data_sequence))); + new (data_) data_sequence; +#endif } + void any_type:: + _copy (any_type& c) const + { + if (data_ != 0) + { + c.allocate_custom_data (); + data_->copy (c.custom_data ()); + } + } + + struct any_type_guard + { + any_type_guard (any_type* p) : p_ (p) {} + + ~any_type_guard () + { +#ifndef XSDE_CUSTOM_ALLOCATOR + delete p_; +#else + if (p_ != 0) + { + p_->~any_type (); + cxx::free (p_); + } +#endif + } + + void + release () { p_ = 0; } + + private: + any_type* p_; + }; + + any_type* any_type:: + _clone () const + { +#ifndef XSDE_CUSTOM_ALLOCATOR + any_type* c = new any_type; +#else + // Default any_type c-tor cannot throw so we don't need alloc_guard. + // + any_type* c = static_cast (cxx::alloc (sizeof (any_type))); + new (c) any_type; +#endif + any_type_guard g (c); + _copy (*c); + g.release (); + return c; + } +#else + bool any_type:: + allocate_custom_data () + { + if (data_ != 0) + return true; + +#ifndef XSDE_CUSTOM_ALLOCATOR + data_ = new data_sequence; +#else + data_ = static_cast ( + cxx::alloc (sizeof (data_sequence))); +#endif + if (data_ == 0) + return false; + +#ifdef XSDE_CUSTOM_ALLOCATOR + new (data_) data_sequence; +#endif + return true; + } + + bool + _copy (any_type&) const + { + if (data_ != 0) + { + if (!c.allocate_custom_data () || + !data_.copy (c.custom_data ())) + return false; + } + + return true; + } + + any_type* any_type:: + _clone () const + { +#ifndef XSDE_CUSTOM_ALLOCATOR + any_type* c = new any_type; +#else + any_type* c = static_cast (cxx::alloc (sizeof (any_type))); +#endif + + if (c == 0) + return 0; + +#ifdef XSDE_CUSTOM_ALLOCATOR + new (c) any_type; +#endif + + if (!_copy (*c)) + { +#ifndef XSDE_CUSTOM_ALLOCATOR + delete c; +#else + c->~any_type (); + cxx::free (c); +#endif + return 0; + } + + return c; + } +#endif + +#ifdef XSDE_POLYMORPHIC #ifdef XSDE_STL const std::string& any_type:: _dynamic_type () const diff --git a/libxsde/xsde/cxx/hybrid/any-type.hxx b/libxsde/xsde/cxx/hybrid/any-type.hxx index a356564..48b0e22 100644 --- a/libxsde/xsde/cxx/hybrid/any-type.hxx +++ b/libxsde/xsde/cxx/hybrid/any-type.hxx @@ -8,11 +8,11 @@ #include -/* #ifdef XSDE_STL # include #endif -*/ + +#include namespace xsde { @@ -22,11 +22,55 @@ namespace xsde { struct any_type { - /* -#ifdef XSDE_POLYMORPHIC + any_type () + : data_ (0) + { + } + + // Custom data. + // + typedef data_sequence custom_data_sequence; + typedef custom_data_sequence::iterator custom_data_iterator; + typedef custom_data_sequence::const_iterator custom_data_const_iterator; + +#ifndef XSDE_EXCEPTIONS + bool +#else + void +#endif + allocate_custom_data (); + + const custom_data_sequence& + custom_data () const + { + return *data_; + } + + custom_data_sequence& + custom_data () + { + return *data_; + } + +#ifndef XSDE_EXCEPTIONS + bool +#else + void +#endif + _copy (any_type&) const; + +#ifndef XSDE_POLYMORPHIC + ~any_type (); + + any_type* + _clone () const; +#else virtual ~any_type (); + virtual any_type* + _clone () const; + #ifdef XSDE_STL virtual const std::string& _dynamic_type () const; @@ -41,7 +85,9 @@ namespace xsde _static_type (); #endif #endif - */ + + private: + data_sequence* data_; }; } } diff --git a/libxsde/xsde/makefile b/libxsde/xsde/makefile index ce95980..0741d13 100644 --- a/libxsde/xsde/makefile +++ b/libxsde/xsde/makefile @@ -77,7 +77,13 @@ endif ## C++/Hybrid ## -cxx_tun += cxx/hybrid/sequence.cxx +cxx_tun += \ +cxx/hybrid/any-type.cxx \ +cxx/hybrid/any-type-pimpl.cxx \ +cxx/hybrid/any-type-pskel.cxx \ +cxx/hybrid/any-type-simpl.cxx \ +cxx/hybrid/any-type-sskel.cxx \ +cxx/hybrid/sequence.cxx ifeq ($(xsde_polymorphic),y) cxx_tun += \ diff --git a/tests/cxx/hybrid/polymorphism/any-type/driver.cxx b/tests/cxx/hybrid/polymorphism/any-type/driver.cxx index bfea16f..cf39e15 100644 --- a/tests/cxx/hybrid/polymorphism/any-type/driver.cxx +++ b/tests/cxx/hybrid/polymorphism/any-type/driver.cxx @@ -52,7 +52,7 @@ main (int argc, char* argv[]) doc_s.add_prefix ("xsi", "http://www.w3.org/2001/XMLSchema-instance"); root_s.pre (*r); - doc_s.serialize (cout); + doc_s.serialize (cout, xml_schema::document_simpl::pretty_print); root_s.post (); delete r; diff --git a/tests/cxx/hybrid/polymorphism/any-type/test-000.std b/tests/cxx/hybrid/polymorphism/any-type/test-000.std new file mode 100644 index 0000000..0c40a51 --- /dev/null +++ b/tests/cxx/hybrid/polymorphism/any-type/test-000.std @@ -0,0 +1,15 @@ + + + + + 123 + abc + + + 123 + abc + 9 + 8 + 7 + + \ No newline at end of file diff --git a/tests/cxx/hybrid/polymorphism/any-type/test-000.xml b/tests/cxx/hybrid/polymorphism/any-type/test-000.xml index f0a8bcb..7a6563c 100644 --- a/tests/cxx/hybrid/polymorphism/any-type/test-000.xml +++ b/tests/cxx/hybrid/polymorphism/any-type/test-000.xml @@ -1,7 +1,28 @@ - abcjunk123 - 123abc - 123abc987 + + abc + junk + 123 + + + + abc + junk + 123 + + + + 123 + abc + + + + 123 + abc + 9 + 8 + 7 + diff --git a/tests/cxx/hybrid/polymorphism/any-type/test.xsd b/tests/cxx/hybrid/polymorphism/any-type/test.xsd index 33b5251..ab35171 100644 --- a/tests/cxx/hybrid/polymorphism/any-type/test.xsd +++ b/tests/cxx/hybrid/polymorphism/any-type/test.xsd @@ -2,6 +2,7 @@ + @@ -10,6 +11,7 @@ + diff --git a/tests/cxx/hybrid/polymorphism/makefile b/tests/cxx/hybrid/polymorphism/makefile index 7523bb2..c418d34 100644 --- a/tests/cxx/hybrid/polymorphism/makefile +++ b/tests/cxx/hybrid/polymorphism/makefile @@ -8,12 +8,12 @@ include $(dir $(lastword $(MAKEFILE_LIST)))../../../../build/bootstrap.make # NOTE: remember to update dist/tests/cxx/hybrid/polymorphis/{makefile, # nmakefile} if you change anything here. # -all_tests := enumeration multischema +all_tests := any-type enumeration multischema build_tests := ifeq ($(xsde_iostream),y) -build_tests += enumeration multischema +build_tests += any-type enumeration multischema endif default := $(out_base)/ diff --git a/xsde/cxx/elements.cxx b/xsde/cxx/elements.cxx index 2289e32..be77456 100644 --- a/xsde/cxx/elements.cxx +++ b/xsde/cxx/elements.cxx @@ -105,7 +105,6 @@ namespace CXX }; } - // Context // 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 +#include #include #include @@ -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 (); + impl = options.value (); + + us = skel == L"_pskel"; + ui = impl == L"_pimpl"; + } + else + { + skel = options.value (); + impl = options.value (); + + 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 () = h.value (); r->value () = h.value (); + // Add the anyType parser. + // + { + std::wostringstream os; + Context ctx (os, schema, path, h, 0, 0, 0); + + os << endl + << "#include " << endl + << "#include " << endl + << "#include " << endl + << endl; + + { + Indentation::Clip clip (os); + + FundNamespace ns (ctx, 'p'); + ns.dispatch (ctx.xs_ns ()); + } + + r->value ().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 () = h.value (); r->value () = h.value (); + // Add the anyType parser. + // + { + std::wostringstream os; + Context ctx (os, schema, path, h, 0, 0, 0); + + os << endl + << "#include " << endl + << "#include " << endl + << "#include " << endl + << endl; + + { + Indentation::Clip clip (os); + + FundNamespace ns (ctx, 's'); + ns.dispatch (ctx.xs_ns ()); + } + + r->value ().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 " << endl + << endl + << "#if (XSDE_INT_VERSION != " << XSDE_INT_VERSION << "L)" << endl + << "#error XSD/e runtime version mismatch" << endl + << "#endif" << endl + << endl; + + fwd << "#include " << endl + << endl; + // Copy prologue. // fwd << "// Begin prologue." << endl @@ -1471,18 +1584,6 @@ namespace CXX << endl; { - // Version check. - // - fwd << "#include " << endl - << endl - << "#if (XSDE_INT_VERSION != " << XSDE_INT_VERSION << "L)" << endl - << "#error XSD/e runtime version mismatch" << endl - << "#endif" << endl - << endl; - - fwd << "#include " << endl - << endl; - // Set auto-indentation. // Indentation::Clip fwd_clip (fwd); @@ -1490,9 +1591,6 @@ namespace CXX // Generate. // generate_tree_forward (ctx, false); - - fwd << "#include " << endl - << endl; } // Copy epilogue. @@ -1511,6 +1609,9 @@ namespace CXX << "// End epilogue." << endl << endl; + fwd << "#include " << 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 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 " << 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 (), - ops.value (), - ""); - append (hxx, - find_value (ops.value (), ""), - prologue); + // Runtime/generated code compatibility checks. + // - hxx << "//" << endl - << "// End prologue." << endl + hxx << "#include " << endl << endl; + if (ops.value () == "iso8859-1") { - // Version check. - // - hxx << "#include " << 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 ()) + { + 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 " << endl + if (ops.value ()) + { + 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 () == "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 ()) + { + 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 ()) - { - 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 ()) + { + 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 ()) - { - 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 ()) - { - 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 " << endl + << endl; - if (ops.value ()) - { - 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 (), + ops.value (), + ""); + append (hxx, + find_value (ops.value (), ""), + prologue); - hxx << "#include " << endl - << endl; + hxx << "//" << endl + << "// End prologue." << endl + << endl; + { // Set auto-indentation. // Indentation::Clip hxx_clip (hxx); @@ -1705,9 +1811,6 @@ namespace CXX << "#endif // XSDE_DONT_INCLUDE_INLINE" << endl << endl; } - - hxx << "#include " << endl - << endl; } // Copy epilogue. @@ -1727,6 +1830,9 @@ namespace CXX << "// End epilogue." << endl << endl; + hxx << "#include " << endl + << endl; + hxx << "#endif // " << guard << endl; if (show_sloc) @@ -1822,6 +1928,9 @@ namespace CXX Indentation::Clip cxx_sloc (cxx); + cxx << "#include " << endl + << endl; + // Copy prologue. // cxx << "// Begin prologue." << endl @@ -1840,9 +1949,6 @@ namespace CXX << endl; { - cxx << "#include " << endl - << endl; - // Set auto-indentation. // Indentation::Clip cxx_clip (cxx); @@ -1860,9 +1966,6 @@ namespace CXX if (!ops.value ().empty ()) generate_extraction_source (ctx); - - cxx << "#include " << endl - << endl; } // Copy epilogue. @@ -1882,6 +1985,9 @@ namespace CXX << "// End epilogue." << endl << endl; + cxx << "#include " << 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 ()) + { + 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 ()) + { + 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 Regex; try @@ -2171,6 +2295,9 @@ namespace CXX << "#define " << guard << endl << endl; + hxx << "#include " << endl + << endl; + // Copy prologue. // hxx << "// Begin prologue." << endl @@ -2189,9 +2316,6 @@ namespace CXX << endl; { - hxx << "#include " << 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 " << endl - << endl; } // Copy epilogue. @@ -2248,6 +2369,9 @@ namespace CXX << "// End epilogue." << endl << endl; + hxx << "#include " << 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 Regex; try @@ -2580,6 +2702,9 @@ namespace CXX << "#define " << guard << endl << endl; + hxx << "#include " << endl + << endl; + // Copy prologue. // hxx << "// Begin prologue." << endl @@ -2598,9 +2723,6 @@ namespace CXX << endl; { - hxx << "#include " << 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 " << endl - << endl; } // Copy epilogue. @@ -2657,6 +2776,9 @@ namespace CXX << "// End epilogue." << endl << endl; + hxx << "#include " << 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 ()) + 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 ()) + 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 ()) - { - 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 () || rt.is_a ()) - */ - if (rt.is_a () || - rt.is_a () || - rt.is_a ()) { 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; diff --git a/xsde/cxx/parser/generator.cxx b/xsde/cxx/parser/generator.cxx index b6f91ee..859a7dc 100644 --- a/xsde/cxx/parser/generator.cxx +++ b/xsde/cxx/parser/generator.cxx @@ -1215,222 +1215,222 @@ namespace CXX << "#define " << guard << endl << endl; - // Copy prologue. + // Version check. // - hxx << "// Begin prologue." << endl - << "//" << endl; + hxx << "#include " << 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 (), ops.value ()); - append (hxx, ops.value (), prologue); + // Runtime/generated code compatibility checks. + // - hxx << "//" << endl - << "// End prologue." << endl + hxx << "#include " << endl << endl; + if (ops.value () == "iso8859-1") { - // Version check. - // - hxx << "#include " << 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 ()) + { + 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 " << endl + if (ops.value ()) + { + hxx << "#ifdef XSDE_IOSTREAM" << endl + << "#error the XSD/e runtime uses iostream while the " << + "generated code does not (reconfigure the runtime or " << + "remove --no-iostream)" << endl + << "#endif" << endl + << endl; + } + else + { + hxx << "#ifndef XSDE_IOSTREAM" << endl + << "#error the generated code uses iostream while the " << + "XSD/e runtime does not (reconfigure the runtime or " << + "add --no-iostream)" << endl + << "#endif" << endl << endl; + } - if (ops.value () == "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 ()) + { + 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 ()) - { - 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 ()) + { + 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 ()) - { - hxx << "#ifdef XSDE_IOSTREAM" << endl - << "#error the XSD/e runtime uses iostream while the " << - "generated code does not (reconfigure the runtime or " << - "remove --no-iostream)" << endl - << "#endif" << endl - << endl; - } - else - { - hxx << "#ifndef XSDE_IOSTREAM" << endl - << "#error the generated code uses iostream while the " << - "XSD/e runtime does not (reconfigure the runtime or " << - "add --no-iostream)" << endl - << "#endif" << endl - << endl; - } + if (ops.value ()) + { + hxx << "#ifdef XSDE_PARSER_VALIDATION" << endl + << "#error the XSD/e runtime uses validation while the " << + "generated code does not (reconfigure the runtime or " << + "remove --suppress-validation)" << endl + << "#endif" << endl + << endl; + } + else + { + hxx << "#ifndef XSDE_PARSER_VALIDATION" << endl + << "#error the generated code uses validation while the " << + "XSD/e runtime does not (reconfigure the runtime or " << + "add --suppress-validation)" << endl + << "#endif" << endl + << endl; + } - if (ops.value ()) - { - 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 () || + ops.value ()) + { + hxx << "#ifndef XSDE_POLYMORPHIC" << endl + << "#error the generated code expects XSD/e runtime with " << + "polymorphism support (reconfigure the runtime or remove " << + "--generate-polymorphic/--runtime-polymorphic)" << endl + << "#endif" << endl + << endl; + } + else + { + hxx << "#ifdef XSDE_POLYMORPHIC" << endl + << "#error the generated code expects XSD/e runtime " << + "without polymorphism support (reconfigure the runtime or " << + "add --generate-polymorphic/--runtime-polymorphic)" << endl + << "#endif" << endl + << endl; + } - if (ops.value ()) - { - 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 ()) + { + hxx << "#ifndef XSDE_REUSE_STYLE_MIXIN" << endl + << "#error the generated code uses the mixin reuse style " << + "while the XSD/e runtime does not (reconfigure the runtime " << + "or remove --reuse-style-mixin)" << endl + << "#endif" << endl + << endl; + } + else if (ops.value ()) + { + hxx << "#ifndef XSDE_REUSE_STYLE_NONE" << endl + << "#error the generated code does not provide support " << + "for parser reuse while the XSD/e runtime does (reconfigure " << + "the runtime or remove --reuse-style-none)" << endl + << "#endif" << endl + << endl; + } + else + { + hxx << "#ifndef XSDE_REUSE_STYLE_TIEIN" << endl + << "#error the generated code uses the tiein reuse style " << + "while the XSD/e runtime does not (reconfigure the runtime " << + "or add --reuse-style-mixin or --reuse-style-none)" << endl + << "#endif" << endl + << endl; + } - if (ops.value ()) - { - hxx << "#ifdef XSDE_PARSER_VALIDATION" << endl - << "#error the XSD/e runtime uses validation while the " << - "generated code does not (reconfigure the runtime or " << - "remove --suppress-validation)" << endl - << "#endif" << endl - << endl; - } - else - { - hxx << "#ifndef XSDE_PARSER_VALIDATION" << endl - << "#error the generated code uses validation while the " << - "XSD/e runtime does not (reconfigure the runtime or " << - "add --suppress-validation)" << endl - << "#endif" << endl - << endl; - } + if (ops.value ()) + { + 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 () || - ops.value ()) - { - hxx << "#ifndef XSDE_POLYMORPHIC" << endl - << "#error the generated code expects XSD/e runtime with " << - "polymorphism support (reconfigure the runtime or remove " << - "--generate-polymorphic/--runtime-polymorphic)" << endl - << "#endif" << endl - << endl; - } - else - { - hxx << "#ifdef XSDE_POLYMORPHIC" << endl - << "#error the generated code expects XSD/e runtime " << - "without polymorphism support (reconfigure the runtime or " << - "add --generate-polymorphic/--runtime-polymorphic)" << endl - << "#endif" << endl - << endl; - } + // + // - if (ops.value ()) - { - hxx << "#ifndef XSDE_REUSE_STYLE_MIXIN" << endl - << "#error the generated code uses the mixin reuse style " << - "while the XSD/e runtime does not (reconfigure the runtime " << - "or remove --reuse-style-mixin)" << endl - << "#endif" << endl - << endl; - } - else if (ops.value ()) - { - hxx << "#ifndef XSDE_REUSE_STYLE_NONE" << endl - << "#error the generated code does not provide support " << - "for parser reuse while the XSD/e runtime does (reconfigure " << - "the runtime or remove --reuse-style-none)" << endl - << "#endif" << endl - << endl; - } - else - { - hxx << "#ifndef XSDE_REUSE_STYLE_TIEIN" << endl - << "#error the generated code uses the tiein reuse style " << - "while the XSD/e runtime does not (reconfigure the runtime " << - "or add --reuse-style-mixin or --reuse-style-none)" << endl - << "#endif" << endl - << endl; - } + hxx << "#include " << endl + << endl; - if (ops.value ()) - { - 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 (), ops.value ()); + append (hxx, ops.value (), prologue); - hxx << "#include " << endl - << endl; + hxx << "//" << endl + << "// End prologue." << endl + << endl; + { // Set auto-indentation. // Indentation::Clip hxx_clip (hxx); @@ -1445,9 +1445,6 @@ namespace CXX if (inline_) hxx << "#include " << ctx.process_include_path (ixx_name) << endl << endl; - - hxx << "#include " << endl - << endl; } // Copy epilogue. @@ -1463,6 +1460,9 @@ namespace CXX << "// End epilogue." << endl << endl; + hxx << "#include " << endl + << endl; + hxx << "#endif // " << guard << endl; if (show_sloc) diff --git a/xsde/cxx/parser/parser-header.cxx b/xsde/cxx/parser/parser-header.cxx index fe6d67b..2498768 100644 --- a/xsde/cxx/parser/parser-header.cxx +++ b/xsde/cxx/parser/parser-header.cxx @@ -1523,14 +1523,20 @@ namespace CXX String const& real_name (c.get ("p:real-name")); String const& name (c.get ("p:name")); - os << "typedef " << real_name << " " << name << ";"; - String const& real_impl (c.get ("p:real-impl")); String const& impl (c.get ("p:impl")); - os << "typedef " << real_impl << " " << impl << ";" - << endl; + if (options.value () == "_pskel") + os << "using " << real_name << ";"; + else + os << "typedef " << real_name << " " << name << ";"; + if (options.value () == "_pimpl") + os << "using " << real_impl << ";"; + else + os << "typedef " << real_impl << " " << impl << ";"; + + os << endl; return true; } diff --git a/xsde/cxx/parser/parser-inline.cxx b/xsde/cxx/parser/parser-inline.cxx index 5ebf014..f0d9e7b 100644 --- a/xsde/cxx/parser/parser-inline.cxx +++ b/xsde/cxx/parser/parser-inline.cxx @@ -169,12 +169,11 @@ namespace CXX // SemanticGraph::Type& base (e.inherits ().base ()); String fq_base (fq_name (base)); - String real_fq_base (real_fq_name (base)); os << inl << name << "::" << endl << name << " (" << fq_base << "* tiein)" << endl - << ": " << real_fq_base << " (tiein, 0)," << endl + << ": " << fq_base << " (tiein, 0)," << endl << " " << impl << " (0)" << "{"; @@ -186,7 +185,7 @@ namespace CXX os << inl << name << "::" << endl << name << " (" << name << "* impl, void*)" << endl - << ": " << real_fq_base << " (impl, 0)," << endl + << ": " << fq_base << " (impl, 0)," << endl << " " << impl << " (impl)" << "{"; @@ -630,13 +629,10 @@ namespace CXX os << "}"; } - // We have to use "real" (non-typedef) base name in base - // initializer because of some broken compilers (EVC 4.0). - // - String real_fq_base; + String fq_base; if (hb && tiein) - real_fq_base = real_fq_name (c.inherits ().base ()); + fq_base = fq_name (c.inherits ().base ()); // Default c-tor. // @@ -644,8 +640,7 @@ namespace CXX << name << "::" << endl; if (hb && tiein) - os << name << " (" << fq_name (c.inherits ().base ()) << - "* tiein)" << endl; + os << name << " (" << fq_base << "* tiein)" << endl; else os << name << " ()" << endl; @@ -658,7 +653,7 @@ namespace CXX if (hb && tiein) { - os << real_fq_base << " (tiein, 0)"; + os << fq_base << " (tiein, 0)"; comma = true; } @@ -741,7 +736,7 @@ namespace CXX << ": "; if (hb) - os << real_fq_base << " (impl, 0)," << endl; + os << fq_base << " (impl, 0)," << endl; else os << complex_base << " (impl, 0)," << endl; diff --git a/xsde/cxx/serializer/generator.cxx b/xsde/cxx/serializer/generator.cxx index 36539f4..3366ff4 100644 --- a/xsde/cxx/serializer/generator.cxx +++ b/xsde/cxx/serializer/generator.cxx @@ -1201,222 +1201,222 @@ namespace CXX << "#define " << guard << endl << endl; - // Copy prologue. + // Version check. // - hxx << "// Begin prologue." << endl - << "//" << endl; + hxx << "#include " << 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 (), ops.value ()); - append (hxx, ops.value (), prologue); + // Runtime/generated code compatibility checks. + // - hxx << "//" << endl - << "// End prologue." << endl + hxx << "#include " << endl << endl; + if (ops.value () == "iso8859-1") { - // Version check. - // - hxx << "#include " << 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 ()) + { + 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 " << endl + if (ops.value ()) + { + hxx << "#ifdef XSDE_IOSTREAM" << endl + << "#error the XSD/e runtime uses iostream while the " << + "generated code does not (reconfigure the runtime or " << + "remove --no-iostream)" << endl + << "#endif" << endl + << endl; + } + else + { + hxx << "#ifndef XSDE_IOSTREAM" << endl + << "#error the generated code uses iostream while the " << + "XSD/e runtime does not (reconfigure the runtime or " << + "add --no-iostream)" << endl + << "#endif" << endl << endl; + } - if (ops.value () == "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 ()) + { + 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 ()) - { - 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 ()) + { + 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 ()) - { - hxx << "#ifdef XSDE_IOSTREAM" << endl - << "#error the XSD/e runtime uses iostream while the " << - "generated code does not (reconfigure the runtime or " << - "remove --no-iostream)" << endl - << "#endif" << endl - << endl; - } - else - { - hxx << "#ifndef XSDE_IOSTREAM" << endl - << "#error the generated code uses iostream while the " << - "XSD/e runtime does not (reconfigure the runtime or " << - "add --no-iostream)" << endl - << "#endif" << endl - << endl; - } + if (ops.value ()) + { + hxx << "#ifdef XSDE_SERIALIZER_VALIDATION" << endl + << "#error the XSD/e runtime uses validation while the " << + "generated code does not (reconfigure the runtime or " << + "remove --suppress-validation)" << endl + << "#endif" << endl + << endl; + } + else + { + hxx << "#ifndef XSDE_SERIALIZER_VALIDATION" << endl + << "#error the generated code uses validation while the " << + "XSD/e runtime does not (reconfigure the runtime or " << + "add --suppress-validation)" << endl + << "#endif" << endl + << endl; + } - if (ops.value ()) - { - 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 () || + ops.value ()) + { + hxx << "#ifndef XSDE_POLYMORPHIC" << endl + << "#error the generated code expects XSD/e runtime with " << + "polymorphism support (reconfigure the runtime or remove " << + "--generate-polymorphic/--runtime-polymorphic)" << endl + << "#endif" << endl + << endl; + } + else + { + hxx << "#ifdef XSDE_POLYMORPHIC" << endl + << "#error the generated code expects XSD/e runtime " << + "without polymorphism support (reconfigure the runtime or " << + "add --generate-polymorphic/--runtime-polymorphic)" << endl + << "#endif" << endl + << endl; + } - if (ops.value ()) - { - 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 ()) + { + hxx << "#ifndef XSDE_REUSE_STYLE_MIXIN" << endl + << "#error the generated code uses the mixin reuse style " << + "while the XSD/e runtime does not (reconfigure the runtime " << + "or remove --reuse-style-mixin)" << endl + << "#endif" << endl + << endl; + } + else if (ops.value ()) + { + hxx << "#ifndef XSDE_REUSE_STYLE_NONE" << endl + << "#error the generated code does not provide support " << + "for serializer reuse while the XSD/e runtime does (" << + "reconfigure the runtime or remove --reuse-style-none)" << endl + << "#endif" << endl + << endl; + } + else + { + hxx << "#ifndef XSDE_REUSE_STYLE_TIEIN" << endl + << "#error the generated code uses the tiein reuse style " << + "while the XSD/e runtime does not (reconfigure the runtime " << + "or add --reuse-style-mixin or --reuse-style-none)" << endl + << "#endif" << endl + << endl; + } - if (ops.value ()) - { - hxx << "#ifdef XSDE_SERIALIZER_VALIDATION" << endl - << "#error the XSD/e runtime uses validation while the " << - "generated code does not (reconfigure the runtime or " << - "remove --suppress-validation)" << endl - << "#endif" << endl - << endl; - } - else - { - hxx << "#ifndef XSDE_SERIALIZER_VALIDATION" << endl - << "#error the generated code uses validation while the " << - "XSD/e runtime does not (reconfigure the runtime or " << - "add --suppress-validation)" << endl - << "#endif" << endl - << endl; - } + if (ops.value ()) + { + 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 () || - ops.value ()) - { - hxx << "#ifndef XSDE_POLYMORPHIC" << endl - << "#error the generated code expects XSD/e runtime with " << - "polymorphism support (reconfigure the runtime or remove " << - "--generate-polymorphic/--runtime-polymorphic)" << endl - << "#endif" << endl - << endl; - } - else - { - hxx << "#ifdef XSDE_POLYMORPHIC" << endl - << "#error the generated code expects XSD/e runtime " << - "without polymorphism support (reconfigure the runtime or " << - "add --generate-polymorphic/--runtime-polymorphic)" << endl - << "#endif" << endl - << endl; - } + // + // - if (ops.value ()) - { - hxx << "#ifndef XSDE_REUSE_STYLE_MIXIN" << endl - << "#error the generated code uses the mixin reuse style " << - "while the XSD/e runtime does not (reconfigure the runtime " << - "or remove --reuse-style-mixin)" << endl - << "#endif" << endl - << endl; - } - else if (ops.value ()) - { - hxx << "#ifndef XSDE_REUSE_STYLE_NONE" << endl - << "#error the generated code does not provide support " << - "for serializer reuse while the XSD/e runtime does (" << - "reconfigure the runtime or remove --reuse-style-none)" << endl - << "#endif" << endl - << endl; - } - else - { - hxx << "#ifndef XSDE_REUSE_STYLE_TIEIN" << endl - << "#error the generated code uses the tiein reuse style " << - "while the XSD/e runtime does not (reconfigure the runtime " << - "or add --reuse-style-mixin or --reuse-style-none)" << endl - << "#endif" << endl - << endl; - } + hxx << "#include " << endl + << endl; - if (ops.value ()) - { - 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 (), ops.value ()); + append (hxx, ops.value (), prologue); - hxx << "#include " << endl - << endl; + hxx << "//" << endl + << "// End prologue." << endl + << endl; + { // Set auto-indentation. // Indentation::Clip hxx_clip (hxx); @@ -1432,9 +1432,6 @@ namespace CXX if (inline_) hxx << "#include " << ctx.process_include_path (ixx_name) << endl << endl; - - hxx << "#include " << endl - << endl; } // Copy epilogue. @@ -1450,6 +1447,9 @@ namespace CXX << "// End epilogue." << endl << endl; + hxx << "#include " << endl + << endl; + hxx << "#endif // " << guard << endl; if (show_sloc) diff --git a/xsde/cxx/serializer/serializer-header.cxx b/xsde/cxx/serializer/serializer-header.cxx index e8fd2f5..bf2c724 100644 --- a/xsde/cxx/serializer/serializer-header.cxx +++ b/xsde/cxx/serializer/serializer-header.cxx @@ -1686,14 +1686,20 @@ namespace CXX String const& real_name (c.get ("s:real-name")); String const& name (c.get ("s:name")); - os << "typedef " << real_name << " " << name << ";"; - String const& real_impl (c.get ("s:real-impl")); String const& impl (c.get ("s:impl")); - os << "typedef " << real_impl << " " << impl << ";" - << endl; + if (options.value () == "_sskel") + os << "using " << real_name << ";"; + else + os << "typedef " << real_name << " " << name << ";"; + if (options.value () == "_simpl") + os << "using " << real_impl << ";"; + else + os << "typedef " << real_impl << " " << impl << ";"; + + os << endl; return true; } diff --git a/xsde/cxx/serializer/serializer-inline.cxx b/xsde/cxx/serializer/serializer-inline.cxx index 998f0f1..621f8b2 100644 --- a/xsde/cxx/serializer/serializer-inline.cxx +++ b/xsde/cxx/serializer/serializer-inline.cxx @@ -154,12 +154,11 @@ namespace CXX // SemanticGraph::Type& base (e.inherits ().base ()); String fq_base (fq_name (base)); - String real_fq_base (real_fq_name (base)); os << inl << name << "::" << endl << name << " (" << fq_base << "* tiein)" << endl - << ": " << real_fq_base << " (tiein, 0)," << endl + << ": " << fq_base << " (tiein, 0)," << endl << " " << impl << " (0)" << "{"; @@ -171,7 +170,7 @@ namespace CXX os << inl << name << "::" << endl << name << " (" << name << "* impl, void*)" << endl - << ": " << real_fq_base << " (impl, 0)," << endl + << ": " << fq_base << " (impl, 0)," << endl << " " << impl << " (impl)" << "{"; @@ -575,13 +574,10 @@ namespace CXX os << "}"; } - // We have to use "real" (non-typedef) base name in base - // initializer because of some broken compilers (EVC 4.0). - // - String real_fq_base; + String fq_base; if (hb && tiein) - real_fq_base = real_fq_name (c.inherits ().base ()); + fq_base = fq_name (c.inherits ().base ()); // Default c-tor. // @@ -589,8 +585,7 @@ namespace CXX << name << "::" << endl; if (hb && tiein) - os << name << " (" << fq_name (c.inherits ().base ()) << - "* tiein)" << endl; + os << name << " (" << fq_base << "* tiein)" << endl; else os << name << " ()" << endl; @@ -601,7 +596,7 @@ namespace CXX if (hb && tiein) { - os << real_fq_base << " (tiein, 0)"; + os << fq_base << " (tiein, 0)"; comma = true; } @@ -661,7 +656,7 @@ namespace CXX << ": "; if (hb) - os << real_fq_base << " (impl, 0)," << endl; + os << fq_base << " (impl, 0)," << endl; else os << complex_base << " (impl, 0)," << endl; diff --git a/xsde/xsde.cxx b/xsde/xsde.cxx index 2281ae9..476869e 100644 --- a/xsde/xsde.cxx +++ b/xsde/xsde.cxx @@ -499,12 +499,6 @@ main (Int argc, Char* argv[]) h_ops = new CXX::Hybrid::CLI::Options ( CLI::parse (CXX::Hybrid::Generator::options_spec (), args)); - if (h_ops->value ()) - p_ops = CXX::Hybrid::Generator::parser_options (*h_ops); - - if (h_ops->value ()) - s_ops = CXX::Hybrid::Generator::serializer_options (*h_ops); - show_sloc = h_ops->value (); } @@ -885,6 +879,18 @@ main (Int argc, Char* argv[]) // The first schema. Will be handled later. // root = &b->schema (); + + // Create parser/serializer options (we need a schema, any + // schema to do this). + // + if (gen_parser && !p_ops) + p_ops = CXX::Hybrid::Generator::parser_options ( + *h_ops, *root, b->path ()); + + if (gen_serializer && !s_ops) + s_ops = CXX::Hybrid::Generator::serializer_options ( + *h_ops, *root, b->path ()); + ++b; for (Schema::UsesIterator e (schema->uses_end ()); b != e; ++b) @@ -909,8 +915,21 @@ main (Int argc, Char* argv[]) } } else + { root = schema.get (); + // Create parser/serializer options (we need a schema, any + // schema to do this). + // + if (gen_parser && !p_ops) + p_ops = CXX::Hybrid::Generator::parser_options ( + *h_ops, *root, tu); + + if (gen_serializer && !s_ops) + s_ops = CXX::Hybrid::Generator::serializer_options ( + *h_ops, *root, tu); + } + // Generate mapping. // TypeMap::Namespaces parser_type_map, serializer_type_map; @@ -1157,6 +1176,17 @@ main (Int argc, Char* argv[]) ? s.context ().get ("renamed") : s.used_begin ()->path ()); + // Create parser/serializer options (we need a schema, any + // schema to do this). + // + if (gen_parser && !p_ops) + p_ops = CXX::Hybrid::Generator::parser_options ( + *h_ops, s, path); + + if (gen_serializer && !s_ops) + s_ops = CXX::Hybrid::Generator::serializer_options ( + *h_ops, s, path); + TypeMap::Namespaces parser_type_map, serializer_type_map; if (gen_hybrid) -- cgit v1.1