From 2c0a77a8f4565b6ef76c32b970df48369b3d0456 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 22 Feb 2010 14:44:30 +0200 Subject: Add support for excluding export code from compilation Affected options: --generate-xml-schema, --export-maps, --import-maps. New macros: XSD_NO_EXPORT, XSD_MAP_VISIBILITY. Reorder template arguments for the idref type. --- NEWS | 5 + documentation/xsd.1 | 30 +- documentation/xsd.xhtml | 9 + libxsd/xsd/cxx/tree/comparison-map.txx | 2 +- libxsd/xsd/cxx/tree/parsing.txx | 13 +- libxsd/xsd/cxx/tree/serialization.txx | 12 +- libxsd/xsd/cxx/tree/std-ostream-map.txx | 2 +- libxsd/xsd/cxx/tree/std-ostream-operators.hxx | 4 +- libxsd/xsd/cxx/tree/stream-extraction-map.txx | 2 +- libxsd/xsd/cxx/tree/stream-extraction.hxx | 4 +- libxsd/xsd/cxx/tree/stream-insertion-map.txx | 2 +- libxsd/xsd/cxx/tree/stream-insertion.hxx | 4 +- libxsd/xsd/cxx/tree/type-factory-map.txx | 2 +- libxsd/xsd/cxx/tree/type-serializer-map.txx | 2 +- libxsd/xsd/cxx/tree/types.hxx | 2 +- libxsd/xsd/cxx/tree/types.txx | 16 +- tests/cxx/tree/compilation/driver.cxx | 2 +- xsd/cxx/parser/parser-source.cxx | 16 +- xsd/cxx/tree/elements.hxx | 10 +- xsd/cxx/tree/fundamental-header.hxx | 385 +++++++++++++++++--------- xsd/cxx/tree/serialization-source.cxx | 12 +- xsd/cxx/tree/stream-extraction-source.cxx | 13 +- xsd/cxx/tree/stream-insertion-source.cxx | 12 +- xsd/cxx/tree/stream-source.cxx | 12 +- xsd/cxx/tree/tree-source.cxx | 18 +- 25 files changed, 396 insertions(+), 195 deletions(-) diff --git a/NEWS b/NEWS index 73b1cec..5d4fec2 100644 --- a/NEWS +++ b/NEWS @@ -37,6 +37,11 @@ Version 3.3.0 --namespace-regex and --anonymous-regex options now include the file component for the schema being compiled. + * The XSD_NO_EXPORT macro can be used to omit code generated with the + --export/import-maps and, for C++/Tree, --generate-xml-schema options + during C++ compilation. This may be useful if you would like to use + the same generated code across multiple platforms. + C++/Tree * New option, --generate-element-type, triggers the generation of types diff --git a/documentation/xsd.1 b/documentation/xsd.1 index fc652d6..db7cd75 100644 --- a/documentation/xsd.1 +++ b/documentation/xsd.1 @@ -467,13 +467,6 @@ Insert the content of the at the end of each generated file for which there is no file-specific epilogue file. -.IP "\fB\--export-symbol \fIsymbol\fR" -Insert -.I symbol -in places where DLL export/import control statements ( -.BR __declspec(dllexport/dllimport) ) -are necessary. - .IP "\fB\--custom-literals \fIfile\fR" Load custom XML string to C++ literal mappings from .IR file . @@ -485,11 +478,22 @@ strings. The format of this file is specified in the .B custom-literals.xsd XML Schema file that can be found in the documentation directory. +.IP "\fB\--export-symbol \fIsymbol\fR" +Insert +.I symbol +in places where DLL export/import control statements ( +.BR __declspec(dllexport/dllimport) ) +are necessary. + .IP "\fB\--export-xml-schema\fR" Export/import types in the XML Schema namespace using the export symbol provided with the .B --export-symbol -option. +option. The +.B XSD_NO_EXPORT +macro can be used to omit this code during C++ compilation, which may be +useful if you would like to use the same generated code across multiple +platforms. .IP "\fB\--export-maps\fR" Export polymorphism support maps from a Win32 DLL into which this generated @@ -501,6 +505,11 @@ the generated code for all other DLLs should be compiled with .BR --import-maps . This option is only valid together with .BR --generate-polymorphic. +The +.B XSD_NO_EXPORT +macro can be used to omit this code during C++ compilation, which may be +useful if you would like to use the same generated code across multiple +platforms. .IP "\fB\--import-maps\fR" Import polymorphism support maps to a Win32 DLL or executable into which @@ -508,6 +517,11 @@ this generated code is linked. See the .B --export-maps option documentation for details. This option is only valid together with .BR --generate-polymorphic. +The +.B XSD_NO_EXPORT +macro can be used to omit this code during C++ compilation, which may be +useful if you would like to use the same generated code across multiple +platforms. .IP "\fB\--disable-warning \fIwarn\fR" Disable printing warning with id diff --git a/documentation/xsd.xhtml b/documentation/xsd.xhtml index 59aaa76..4acf822 100644 --- a/documentation/xsd.xhtml +++ b/documentation/xsd.xhtml @@ -426,6 +426,9 @@
--export-xml-schema
Export/import types in the XML Schema namespace using the export symbol provided with the --export-symbol option. + The XSD_NO_EXPORT macro can be used to omit + this code during C++ compilation, which may be useful if you + would like to use the same generated code across multiple platforms.
--export-maps
@@ -438,6 +441,9 @@ DLLs should be compiled with --import-maps. This option is only valid together with --generate-polymorphic. + The XSD_NO_EXPORT macro can be used to omit + this code during C++ compilation, which may be useful if you + would like to use the same generated code across multiple platforms.
--import-maps
@@ -445,6 +451,9 @@ which this generated code is linked. See the --export-maps option documentation for details. This options is only valid together with --generate-polymorphic. + The XSD_NO_EXPORT macro can be used to omit + this code during C++ compilation, which may be useful if you + would like to use the same generated code across multiple platforms.
--disable-warning warn
diff --git a/libxsd/xsd/cxx/tree/comparison-map.txx b/libxsd/xsd/cxx/tree/comparison-map.txx index eaccb0d..e638ed4 100644 --- a/libxsd/xsd/cxx/tree/comparison-map.txx +++ b/libxsd/xsd/cxx/tree/comparison-map.txx @@ -92,7 +92,7 @@ namespace xsd &comparator_impl, false); - typedef idref idref; + typedef idref idref; register_type ( typeid (idref), &comparator_impl, diff --git a/libxsd/xsd/cxx/tree/parsing.txx b/libxsd/xsd/cxx/tree/parsing.txx index 642307a..8da53b9 100644 --- a/libxsd/xsd/cxx/tree/parsing.txx +++ b/libxsd/xsd/cxx/tree/parsing.txx @@ -638,22 +638,22 @@ namespace xsd // idref // - template - idref:: + template + idref:: idref (const xercesc::DOMElement& e, flags f, container* c) : base_type (e, f, c), identity_ (*this) { } - template - idref:: + template + idref:: idref (const xercesc::DOMAttr& a, flags f, container* c) : base_type (a, f , c), identity_ (*this) { } - template - idref:: + template + idref:: idref (const std::basic_string& s, const xercesc::DOMElement* e, flags f, @@ -663,7 +663,6 @@ namespace xsd } - // idrefs // template diff --git a/libxsd/xsd/cxx/tree/serialization.txx b/libxsd/xsd/cxx/tree/serialization.txx index 322febe..29364f4 100644 --- a/libxsd/xsd/cxx/tree/serialization.txx +++ b/libxsd/xsd/cxx/tree/serialization.txx @@ -533,23 +533,23 @@ namespace xsd // idref // - template + template inline void - operator<< (xercesc::DOMElement& e, const idref& x) + operator<< (xercesc::DOMElement& e, const idref& x) { bits::insert (e, x); } - template + template inline void - operator<< (xercesc::DOMAttr& a, const idref& x) + operator<< (xercesc::DOMAttr& a, const idref& x) { bits::insert (a, x); } - template + template inline void - operator<< (list_stream& ls, const idref& x) + operator<< (list_stream& ls, const idref& x) { ls.os_ << x; } diff --git a/libxsd/xsd/cxx/tree/std-ostream-map.txx b/libxsd/xsd/cxx/tree/std-ostream-map.txx index 6d8ae83..6a748ec 100644 --- a/libxsd/xsd/cxx/tree/std-ostream-map.txx +++ b/libxsd/xsd/cxx/tree/std-ostream-map.txx @@ -91,7 +91,7 @@ namespace xsd &inserter_impl, false); - typedef idref idref; + typedef idref idref; register_type ( typeid (idref), &inserter_impl, diff --git a/libxsd/xsd/cxx/tree/std-ostream-operators.hxx b/libxsd/xsd/cxx/tree/std-ostream-operators.hxx index bf6db54..a7ab357 100644 --- a/libxsd/xsd/cxx/tree/std-ostream-operators.hxx +++ b/libxsd/xsd/cxx/tree/std-ostream-operators.hxx @@ -180,9 +180,9 @@ namespace xsd // idref // - template + template inline std::basic_ostream& - operator<< (std::basic_ostream& os, const idref& v) + operator<< (std::basic_ostream& os, const idref& v) { const B& r (v); return os << r; diff --git a/libxsd/xsd/cxx/tree/stream-extraction-map.txx b/libxsd/xsd/cxx/tree/stream-extraction-map.txx index c2dc116..a4e429e 100644 --- a/libxsd/xsd/cxx/tree/stream-extraction-map.txx +++ b/libxsd/xsd/cxx/tree/stream-extraction-map.txx @@ -97,7 +97,7 @@ namespace xsd &extractor_impl, false); - typedef idref idref; + typedef idref idref; register_type ( qualified_name (bits::idref (), xsd), &extractor_impl, diff --git a/libxsd/xsd/cxx/tree/stream-extraction.hxx b/libxsd/xsd/cxx/tree/stream-extraction.hxx index 1927157..a7106e7 100644 --- a/libxsd/xsd/cxx/tree/stream-extraction.hxx +++ b/libxsd/xsd/cxx/tree/stream-extraction.hxx @@ -204,9 +204,9 @@ namespace xsd // idref // - template + template template - inline idref:: + inline idref:: idref (istream& s, flags f, container* c) : B (s, f, c), identity_ (*this) { diff --git a/libxsd/xsd/cxx/tree/stream-insertion-map.txx b/libxsd/xsd/cxx/tree/stream-insertion-map.txx index 7107a80..07bfa8b 100644 --- a/libxsd/xsd/cxx/tree/stream-insertion-map.txx +++ b/libxsd/xsd/cxx/tree/stream-insertion-map.txx @@ -108,7 +108,7 @@ namespace xsd &inserter_impl, false); - typedef idref idref; + typedef idref idref; register_type ( typeid (idref), qualified_name (bits::idref (), xsd), diff --git a/libxsd/xsd/cxx/tree/stream-insertion.hxx b/libxsd/xsd/cxx/tree/stream-insertion.hxx index cfec1d9..c345e80 100644 --- a/libxsd/xsd/cxx/tree/stream-insertion.hxx +++ b/libxsd/xsd/cxx/tree/stream-insertion.hxx @@ -177,9 +177,9 @@ namespace xsd // idref // - template + template inline ostream& - operator<< (ostream& s, const idref& x) + operator<< (ostream& s, const idref& x) { const B& r (x); return s << r; diff --git a/libxsd/xsd/cxx/tree/type-factory-map.txx b/libxsd/xsd/cxx/tree/type-factory-map.txx index be5549d..b9e0a06 100644 --- a/libxsd/xsd/cxx/tree/type-factory-map.txx +++ b/libxsd/xsd/cxx/tree/type-factory-map.txx @@ -104,7 +104,7 @@ namespace xsd &factory_impl, false); - typedef idref idref; + typedef idref idref; register_type ( qualified_name (bits::idref (), xsd), &factory_impl, diff --git a/libxsd/xsd/cxx/tree/type-serializer-map.txx b/libxsd/xsd/cxx/tree/type-serializer-map.txx index 9ee673a..859331f 100644 --- a/libxsd/xsd/cxx/tree/type-serializer-map.txx +++ b/libxsd/xsd/cxx/tree/type-serializer-map.txx @@ -115,7 +115,7 @@ namespace xsd &serializer_impl, false); - typedef idref idref; + typedef idref idref; register_type ( typeid (idref), qualified_name (bits::idref (), xsd), diff --git a/libxsd/xsd/cxx/tree/types.hxx b/libxsd/xsd/cxx/tree/types.hxx index e6dc5a4..299824f 100644 --- a/libxsd/xsd/cxx/tree/types.hxx +++ b/libxsd/xsd/cxx/tree/types.hxx @@ -2133,7 +2133,7 @@ namespace xsd * * @nosubgrouping */ - template + template class idref: public B { typedef B base_type; diff --git a/libxsd/xsd/cxx/tree/types.txx b/libxsd/xsd/cxx/tree/types.txx index a13a466..8d6d79f 100644 --- a/libxsd/xsd/cxx/tree/types.txx +++ b/libxsd/xsd/cxx/tree/types.txx @@ -204,8 +204,8 @@ namespace xsd // idref // - template - idref* idref:: + template + idref* idref:: _clone (flags f, container* c) const { return new idref (*this, f, c); @@ -216,8 +216,8 @@ namespace xsd // non-trivial to track down cases. So we are going to use the // old-n-ugly this-> techniques. // - template - const _type* idref:: + template + const _type* idref:: get_ () const { if (!this->empty () && this->_container () != 0) @@ -228,8 +228,8 @@ namespace xsd return 0; } - template - _type* idref:: + template + _type* idref:: get_ () { if (!this->empty () && this->_container () != 0) @@ -240,8 +240,8 @@ namespace xsd return 0; } - template - void idref:: + template + void idref:: true_ () { } diff --git a/tests/cxx/tree/compilation/driver.cxx b/tests/cxx/tree/compilation/driver.cxx index 7b83f84..8135c9b 100644 --- a/tests/cxx/tree/compilation/driver.cxx +++ b/tests/cxx/tree/compilation/driver.cxx @@ -31,7 +31,7 @@ template class xsd::cxx::tree::language< char, xml_schema::token >; // ID/IDREF. // template class xsd::cxx::tree::id< char, xml_schema::ncname >; -template class xsd::cxx::tree::idref< xml_schema::type, char, xml_schema::ncname >; +template class xsd::cxx::tree::idref< char, xml_schema::ncname, xml_schema::type >; template class xsd::cxx::tree::idrefs< char, xml_schema::simple_type, xml_schema::idref >; // URI. diff --git a/xsd/cxx/parser/parser-source.cxx b/xsd/cxx/parser/parser-source.cxx index 6ac0144..68623be 100644 --- a/xsd/cxx/parser/parser-source.cxx +++ b/xsd/cxx/parser/parser-source.cxx @@ -827,7 +827,9 @@ namespace CXX if (import_maps || export_maps) { - ctx.os << "namespace xsd" + ctx.os << "#ifndef XSD_NO_EXPORT" << endl + << endl + << "namespace xsd" << "{" << "namespace cxx" << "{" @@ -859,10 +861,20 @@ namespace CXX ctx.os << "template struct __attribute__ ((visibility(\"default\"))) " << "inheritance_map_init< " << ctx.char_type << " >;"; + ctx.os << "#elif defined(XSD_MAP_VISIBILITY)" << endl + << "template struct XSD_MAP_VISIBILITY " << + "substitution_map_init< " << ctx.char_type << " >;"; + + if (ctx.validation) + ctx.os << "template struct XSD_MAP_VISIBILITY " << + "inheritance_map_init< " << ctx.char_type << " >;"; + ctx.os << "#endif" << endl << "}" // parser << "}" // cxx - << "}"; // xsd + << "}" // xsd + << "#endif // XSD_NO_EXPORT" << endl + << endl; } ctx.os << "static" << endl diff --git a/xsd/cxx/tree/elements.hxx b/xsd/cxx/tree/elements.hxx index d081139..083ed09 100644 --- a/xsd/cxx/tree/elements.hxx +++ b/xsd/cxx/tree/elements.hxx @@ -1048,9 +1048,9 @@ namespace CXX SemanticGraph::Nameable& ncname ( xs_ns ().find ("NCName").first->named ()); - os << "::xsd::cxx::tree::idref< " << - type_name (t.argumented ().type ()) << ", " << - char_type << ", " << fq_name (ncname) << " >"; + os << "::xsd::cxx::tree::idref< " << char_type << ", " << + fq_name (ncname) << ", " << + type_name (t.argumented ().type ()) << " >"; } } @@ -1070,8 +1070,8 @@ namespace CXX os << "::xsd::cxx::tree::idrefs< " << char_type << ", " << any_simple_type << ", ::xsd::cxx::tree::idref< " << - type_name (t.argumented ().type ()) << ", " << char_type << - ", " << fq_name (ncname) << " > >"; + char_type << ", " << fq_name (ncname) << ", " << + type_name (t.argumented ().type ()) << " > >"; } } diff --git a/xsd/cxx/tree/fundamental-header.hxx b/xsd/cxx/tree/fundamental-header.hxx index 6dfe2d1..47e0530 100644 --- a/xsd/cxx/tree/fundamental-header.hxx +++ b/xsd/cxx/tree/fundamental-header.hxx @@ -6,6 +6,8 @@ #ifndef CXX_TREE_FUNDAMENTAL_HEADER_HXX #define CXX_TREE_FUNDAMENTAL_HEADER_HXX +#include + #include #include @@ -80,19 +82,81 @@ namespace CXX export_ (c.options.value () && type_exp) { *this >> names_ >> *this; + + if (export_) + xs_ns_ = ns_name (xs_ns ()); } Void - gen_typedef (String const& type, String const& name) + gen_typedef (String const& name, + String const& type, + String const& arg1 = L"", + String const& arg2 = L"", + String const& arg3 = L"") { - os << "typedef " << type << " " << name << ";"; + os << "typedef " << type; + + // Use unqualified arguments since we are in the same + // namespace. + // + if (arg1) + { + os << arg1; + + if (arg2) + { + os << ", " << arg2; + + if (arg3) + os << ", " << arg3; + } + + os << " >"; + } + + os << " " << name << ";"; if (export_ && type.find (L'<') != String::npos) - os << "template class " << type_exp << type << ";"; + { + String s (type); + + // Use qualified arguments. + // + if (arg1) + { + s += xs_ns_; + s += L"::"; + s += arg1; + + if (arg2) + { + s += L", "; + s += xs_ns_; + s += L"::"; + s += arg2; + + if (arg3) + { + s += L", "; + s += xs_ns_; + s += L"::"; + s += arg3; + } + } + + s += " >"; + } + + exports_.insert (s); + } } String - built_in_type (SemanticGraph::Type& t, String const& type) + built_in_type (SemanticGraph::Type& t, + String const& type, + String const& arg1 = L"", + String const& arg2 = L"", + String const& arg3 = L"") { String custom; @@ -111,7 +175,7 @@ namespace CXX if (new_name) { - gen_typedef (type, new_name); + gen_typedef (new_name, type, arg1, arg2, arg3); if (doxygen) os << endl; @@ -144,7 +208,7 @@ namespace CXX << " * built-in type." << endl << " */" << endl; - gen_typedef (type, name); + gen_typedef (name, type, arg1, arg2, arg3); if (doxygen) os << endl; @@ -171,15 +235,15 @@ namespace CXX traverse (SemanticGraph::AnySimpleType& t) { simple_type_ = built_in_type ( - t, L"::xsd::cxx::tree::simple_type< " + type_ + L" >"); + t, L"::xsd::cxx::tree::simple_type< ", type_); if (doxygen) os << "/**" << endl << " * @brief Alias for the anyType type." << endl << " */" << endl; - gen_typedef ("::xsd::cxx::tree::type", - xs_ns ().context().get ("container")); + gen_typedef (xs_ns ().context().get ("container"), + "::xsd::cxx::tree::type"); os << endl; @@ -358,9 +422,7 @@ namespace CXX os << endl; string_ = built_in_type ( - t, - L"::xsd::cxx::tree::string< " + char_type + L", " + - simple_type_ + L" >"); + t, L"::xsd::cxx::tree::string< " + char_type + L", ", simple_type_); } virtual Void @@ -368,26 +430,22 @@ namespace CXX { norm_string_ = built_in_type ( t, - L"::xsd::cxx::tree::normalized_string< " + char_type + - L", " + string_ + L" >"); + L"::xsd::cxx::tree::normalized_string< " + char_type + L", ", + string_); } virtual Void traverse (SemanticGraph::Fundamental::Token& t) { token_ = built_in_type ( - t, - L"::xsd::cxx::tree::token< " + char_type + L", " + - norm_string_ + L" >"); + t, L"::xsd::cxx::tree::token< " + char_type + L", ", norm_string_); } virtual Void traverse (SemanticGraph::Fundamental::NameToken& t) { nmtoken_ = built_in_type ( - t, - L"::xsd::cxx::tree::nmtoken< " + char_type + L", " + - token_ + L" >"); + t, L"::xsd::cxx::tree::nmtoken< " + char_type + L", ", token_); } virtual Void @@ -395,33 +453,30 @@ namespace CXX { built_in_type ( t, - L"::xsd::cxx::tree::nmtokens< " + char_type + - L", " + simple_type_ + L", " + nmtoken_ + L" >"); + L"::xsd::cxx::tree::nmtokens< " + char_type + L", ", + simple_type_, + nmtoken_); } virtual Void traverse (SemanticGraph::Fundamental::Name& t) { name_ = built_in_type ( - t, - L"::xsd::cxx::tree::name< " + char_type + L", " + token_ + L" >"); + t, L"::xsd::cxx::tree::name< " + char_type + L", ", token_); } virtual Void traverse (SemanticGraph::Fundamental::NCName& t) { ncname_ = built_in_type ( - t, - L"::xsd::cxx::tree::ncname< " + char_type + L", " + name_ + L" >"); + t, L"::xsd::cxx::tree::ncname< " + char_type + L", ", name_); } virtual Void traverse (SemanticGraph::Fundamental::Language& t) { built_in_type ( - t, - L"::xsd::cxx::tree::language< " + char_type + L", " + - token_ + L" >"); + t, L"::xsd::cxx::tree::language< " + char_type + L", ", token_); os << endl; } @@ -438,17 +493,14 @@ namespace CXX os << endl; built_in_type ( - t, - L"::xsd::cxx::tree::id< " + char_type + L", " + ncname_ + L" >"); + t, L"::xsd::cxx::tree::id< " + char_type + L", ", ncname_); } virtual Void traverse (SemanticGraph::Fundamental::IdRef& t) { idref_ = built_in_type ( - t, - L"::xsd::cxx::tree::idref< " + type_ + L", " + char_type + L", " + - ncname_ + L" >"); + t, L"::xsd::cxx::tree::idref< " + char_type + L", ", ncname_, type_); } virtual Void @@ -456,8 +508,9 @@ namespace CXX { built_in_type ( t, - L"::xsd::cxx::tree::idrefs< " + char_type + - L", " + simple_type_ + L", " + idref_ + L" >"); + L"::xsd::cxx::tree::idrefs< " + char_type + L", ", + simple_type_, + idref_); os << endl; } @@ -475,9 +528,7 @@ namespace CXX os << endl; uri_ = built_in_type ( - t, - L"::xsd::cxx::tree::uri< " + char_type + L", " + - simple_type_ + L" >"); + t, L"::xsd::cxx::tree::uri< " + char_type + L", ", simple_type_); os << endl; } @@ -495,8 +546,10 @@ namespace CXX built_in_type ( t, - L"::xsd::cxx::tree::qname< " + char_type + - L", " + simple_type_ + L", " + uri_ + L", " + ncname_ + L" >"); + L"::xsd::cxx::tree::qname< " + char_type + L", ", + simple_type_, + uri_, + ncname_); os << endl; } @@ -515,16 +568,16 @@ namespace CXX << " * @brief Binary buffer type." << endl << " */" << endl; - gen_typedef (L"::xsd::cxx::tree::buffer< " + char_type + L" >", - xs_ns ().context().get ("buffer")); + gen_typedef (xs_ns ().context().get ("buffer"), + L"::xsd::cxx::tree::buffer< " + char_type + L" >"); if (doxygen) os << endl; built_in_type ( t, - L"::xsd::cxx::tree::base64_binary< " + char_type + - L", " + simple_type_ + L" >"); + L"::xsd::cxx::tree::base64_binary< " + char_type + L", ", + simple_type_); } virtual Void @@ -532,8 +585,8 @@ namespace CXX { built_in_type ( t, - L"::xsd::cxx::tree::hex_binary< " + char_type + - L", " + simple_type_ + L" >"); + L"::xsd::cxx::tree::hex_binary< " + char_type + L", ", + simple_type_); os << endl; } @@ -553,16 +606,14 @@ namespace CXX << " * @brief Time zone type." << endl << " */" << endl; - gen_typedef ("::xsd::cxx::tree::time_zone", - xs_ns ().context().get ("time-zone")); + gen_typedef (xs_ns ().context().get ("time-zone"), + "::xsd::cxx::tree::time_zone"); if (doxygen) os << endl; built_in_type ( - t, - L"::xsd::cxx::tree::date< " + char_type + L", " + - simple_type_ + L" >"); + t, L"::xsd::cxx::tree::date< " + char_type + L", ", simple_type_); } virtual Void @@ -570,8 +621,8 @@ namespace CXX { built_in_type ( t, - L"::xsd::cxx::tree::date_time< " + char_type + L", " + - simple_type_ + L" >"); + L"::xsd::cxx::tree::date_time< " + char_type + L", ", + simple_type_); } virtual Void @@ -579,26 +630,22 @@ namespace CXX { built_in_type ( t, - L"::xsd::cxx::tree::duration< " + char_type + L", " + - simple_type_ + L" >"); + L"::xsd::cxx::tree::duration< " + char_type + L", ", + simple_type_); } virtual Void traverse (SemanticGraph::Fundamental::Day& t) { built_in_type ( - t, - L"::xsd::cxx::tree::gday< " + char_type + L", " + - simple_type_ + L" >"); + t, L"::xsd::cxx::tree::gday< " + char_type + L", ", simple_type_); } virtual Void traverse (SemanticGraph::Fundamental::Month& t) { built_in_type ( - t, - L"::xsd::cxx::tree::gmonth< " + char_type + L", " + - simple_type_ + L" >"); + t, L"::xsd::cxx::tree::gmonth< " + char_type + L", ", simple_type_); } virtual Void @@ -606,17 +653,15 @@ namespace CXX { built_in_type ( t, - L"::xsd::cxx::tree::gmonth_day< " + char_type + L", " + - simple_type_ + L" >"); + L"::xsd::cxx::tree::gmonth_day< " + char_type + L", ", + simple_type_); } virtual Void traverse (SemanticGraph::Fundamental::Year& t) { built_in_type ( - t, - L"::xsd::cxx::tree::gyear< " + char_type + L", " + - simple_type_ + L" >"); + t, L"::xsd::cxx::tree::gyear< " + char_type + L", ", simple_type_); } virtual Void @@ -624,17 +669,15 @@ namespace CXX { built_in_type ( t, - L"::xsd::cxx::tree::gyear_month< " + char_type + L", " + - simple_type_ + L" >"); + L"::xsd::cxx::tree::gyear_month< " + char_type + L", ", + simple_type_); } virtual Void traverse (SemanticGraph::Fundamental::Time& t) { built_in_type ( - t, - L"::xsd::cxx::tree::time< " + char_type + L", " + - simple_type_ + L" >"); + t, L"::xsd::cxx::tree::time< " + char_type + L", ", simple_type_); os << endl; } @@ -651,9 +694,7 @@ namespace CXX os << endl; entity_ = built_in_type ( - t, - L"::xsd::cxx::tree::entity< " + char_type + L", " + - ncname_ + L" >"); + t, L"::xsd::cxx::tree::entity< " + char_type + L", ", ncname_); } virtual Void @@ -661,8 +702,9 @@ namespace CXX { built_in_type ( t, - L"::xsd::cxx::tree::entities< " + char_type + - L", " + simple_type_ + L", " + entity_ + L" >"); + L"::xsd::cxx::tree::entities< " + char_type + L", ", + simple_type_, + entity_); os << endl; } @@ -686,9 +728,11 @@ namespace CXX os << "// Base class for element types." << endl << "//" << endl; - gen_typedef (L"::xsd::cxx::tree::element_type < " + - char_type + L", " + type_ + L" >", - c.get ("element-type")); + gen_typedef ( + c.get ("element-type"), + L"::xsd::cxx::tree::element_type< " + char_type + L", ", + type_); + os << endl; } @@ -702,9 +746,11 @@ namespace CXX os << "// Root element map." << endl << "//" << endl; - gen_typedef (L"::xsd::cxx::tree::element_map < " + - char_type + L", " + type_ + L" >", - c.get ("element-map")); + gen_typedef ( + c.get ("element-map"), + L"::xsd::cxx::tree::element_map< " + char_type + L", ", + type_); + os << endl; } @@ -720,8 +766,8 @@ namespace CXX << " */" << endl; gen_typedef ( - L"::xsd::cxx::xml::dom::namespace_info < " + char_type + L" >", - c.get ("namespace-info")); + c.get ("namespace-info"), + L"::xsd::cxx::xml::dom::namespace_info< " + char_type + L" >"); if (doxygen) os << endl @@ -729,9 +775,9 @@ namespace CXX << " * @brief Namespace serialization information map." << endl << " */" << endl; - gen_typedef (L"::xsd::cxx::xml::dom::namespace_infomap < " + - char_type + L" >", - c.get ("namespace-infomap")); + gen_typedef (c.get ("namespace-infomap"), + L"::xsd::cxx::xml::dom::namespace_infomap< " + + char_type + L" >"); if (doxygen) os << endl @@ -740,8 +786,8 @@ namespace CXX << " */" << endl; gen_typedef ( - L"::xsd::cxx::tree::list_stream < " + char_type + L" >", - c.get ("list-stream")); + c.get ("list-stream"), + L"::xsd::cxx::tree::list_stream< " + char_type + L" >"); if (doxygen) os << endl @@ -749,8 +795,8 @@ namespace CXX << " * @brief Serialization wrapper for the %double type." << endl << " */" << endl; - gen_typedef (L"::xsd::cxx::tree::as_double < " + double_ + L" >", - c.get ("as-double")); + gen_typedef (c.get ("as-double"), + L"::xsd::cxx::tree::as_double< ", double_); if (doxygen) os << endl @@ -758,8 +804,8 @@ namespace CXX << " * @brief Serialization wrapper for the %decimal type." << endl << " */" << endl; - gen_typedef (L"::xsd::cxx::tree::as_decimal < " + decimal_ + L" >", - c.get ("as-decimal")); + gen_typedef (c.get ("as-decimal"), + L"::xsd::cxx::tree::as_decimal< ", decimal_); if (doxygen) os << endl @@ -767,7 +813,7 @@ namespace CXX << " * @brief Simple type facet." << endl << " */" << endl; - gen_typedef ("::xsd::cxx::tree::facet", c.get ("facet")); + gen_typedef (c.get ("facet"), "::xsd::cxx::tree::facet"); os << endl; } @@ -812,7 +858,7 @@ namespace CXX << " * @brief Parsing and serialization flags." << endl << " */" << endl; - gen_typedef ("::xsd::cxx::tree::flags", c.get ("flags")); + gen_typedef (c.get ("flags"), "::xsd::cxx::tree::flags"); if (doxygen) os << endl @@ -820,8 +866,8 @@ namespace CXX << " * @brief Parsing properties." << endl << " */" << endl; - gen_typedef (L"::xsd::cxx::tree::properties< " + char_type + L" >", - c.get ("properties")); + gen_typedef (c.get ("properties"), + L"::xsd::cxx::tree::properties< " + char_type + L" >"); os << endl; @@ -836,8 +882,8 @@ namespace CXX << " * @brief Root of the C++/Tree %exception hierarchy." << endl << " */" << endl; - gen_typedef (L"::xsd::cxx::tree::exception< " + char_type + L" >", - c.get ("exception")); + gen_typedef (c.get ("exception"), + L"::xsd::cxx::tree::exception< " + char_type + L" >"); if (doxygen) os << endl @@ -847,8 +893,8 @@ namespace CXX << " * the capacity argument." << endl << " */" << endl; - gen_typedef (L"::xsd::cxx::tree::bounds< " + char_type + L" >", - c.get ("bounds")); + gen_typedef (c.get ("bounds"), + L"::xsd::cxx::tree::bounds< " + char_type + L" >"); if (doxygen) os << endl @@ -858,8 +904,8 @@ namespace CXX << " * was encountered in the object model." << endl << " */" << endl; - gen_typedef (L"::xsd::cxx::tree::duplicate_id< " + char_type + L" >", - c.get ("duplicate-id")); + gen_typedef (c.get ("duplicate-id"), + L"::xsd::cxx::tree::duplicate_id< " + char_type + L" >"); if (parsing) { @@ -869,8 +915,8 @@ namespace CXX << " * @brief Exception indicating a parsing failure." << endl << " */" << endl; - gen_typedef (L"::xsd::cxx::tree::parsing< " + char_type + L" >", - c.get ("parsing")); + gen_typedef (c.get ("parsing"), + L"::xsd::cxx::tree::parsing< " + char_type + L" >"); if (doxygen) os << endl @@ -881,8 +927,8 @@ namespace CXX << " */" << endl; gen_typedef ( - L"::xsd::cxx::tree::expected_element< " + char_type + L" >", - c.get ("expected-element")); + c.get ("expected-element"), + L"::xsd::cxx::tree::expected_element< " + char_type + L" >"); } if (parsing || serialization) @@ -896,8 +942,8 @@ namespace CXX << " */" << endl; gen_typedef ( - L"::xsd::cxx::tree::unexpected_element< " + char_type + L" >", - c.get ("unexpected-element")); + c.get ("unexpected-element"), + L"::xsd::cxx::tree::unexpected_element< " + char_type + L" >"); } if (parsing) @@ -911,8 +957,8 @@ namespace CXX << " */" << endl; gen_typedef ( - L"::xsd::cxx::tree::expected_attribute< " + char_type + L" >", - c.get ("expected-attribute")); + c.get ("expected-attribute"), + L"::xsd::cxx::tree::expected_attribute< " + char_type + L" >"); if (doxygen) os << endl @@ -923,8 +969,8 @@ namespace CXX << " */" << endl; gen_typedef ( - L"::xsd::cxx::tree::unexpected_enumerator< " + char_type + L" >", - c.get ("unexpected-enumerator")); + c.get ("unexpected-enumerator"), + L"::xsd::cxx::tree::unexpected_enumerator< " + char_type + L" >"); if (doxygen) os << endl @@ -935,8 +981,8 @@ namespace CXX << " */" << endl; gen_typedef ( - L"::xsd::cxx::tree::expected_text_content< " + char_type + L" >", - c.get ("expected-text-content")); + c.get ("expected-text-content"), + L"::xsd::cxx::tree::expected_text_content< " + char_type + L" >"); if (doxygen) os << endl @@ -947,8 +993,8 @@ namespace CXX << " */" << endl; gen_typedef ( - L"::xsd::cxx::tree::no_prefix_mapping< " + char_type + L" >", - c.get ("no-prefix-mapping")); + c.get ("no-prefix-mapping"), + L"::xsd::cxx::tree::no_prefix_mapping< " + char_type + L" >"); } if (options.value ()) @@ -964,8 +1010,8 @@ namespace CXX << " */" << endl; gen_typedef ( - L"::xsd::cxx::tree::no_type_info< " + char_type + L" >", - c.get ("no-type-info")); + c.get ("no-type-info"), + L"::xsd::cxx::tree::no_type_info< " + char_type + L" >"); } if (parsing) @@ -979,8 +1025,8 @@ namespace CXX << " */" << endl; gen_typedef ( - L"::xsd::cxx::tree::not_derived< " + char_type + L" >", - c.get ("not-derived")); + c.get ("not-derived"), + L"::xsd::cxx::tree::not_derived< " + char_type + L" >"); } } @@ -995,8 +1041,8 @@ namespace CXX << " */" << endl; gen_typedef ( - L"::xsd::cxx::tree::no_element_info< " + char_type + L" >", - c.get ("no-element-info")); + c.get ("no-element-info"), + L"::xsd::cxx::tree::no_element_info< " + char_type + L" >"); } if (serialization) @@ -1009,8 +1055,8 @@ namespace CXX << " */" << endl; gen_typedef ( - L"::xsd::cxx::tree::serialization< " + char_type + L" >", - c.get ("serialization")); + c.get ("serialization"), + L"::xsd::cxx::tree::serialization< " + char_type + L" >"); } os << endl; @@ -1028,8 +1074,8 @@ namespace CXX << " * @brief Error severity." << endl << " */" << endl; - gen_typedef ("::xsd::cxx::tree::severity", - c.get ("severity")); + gen_typedef (c.get ("severity"), + "::xsd::cxx::tree::severity"); if (doxygen) os << endl @@ -1037,8 +1083,8 @@ namespace CXX << " * @brief Error condition." << endl << " */" << endl; - gen_typedef (L"::xsd::cxx::tree::error< " + char_type + L" >", - c.get ("error")); + gen_typedef (c.get ("error"), + L"::xsd::cxx::tree::error< " + char_type + L" >"); if (doxygen) os << endl @@ -1046,8 +1092,8 @@ namespace CXX << " * @brief List of %error conditions." << endl << " */" << endl; - gen_typedef (L"::xsd::cxx::tree::diagnostics< " + char_type + L" >", - c.get ("diagnostics")); + gen_typedef (c.get ("diagnostics"), + L"::xsd::cxx::tree::diagnostics< " + char_type + L" >"); os << endl; } @@ -1062,8 +1108,8 @@ namespace CXX << "//" << endl; gen_typedef ( - L"::xsd::cxx::xml::error_handler< " + char_type + L" >", - c.get ("error-handler")); + c.get ("error-handler"), + L"::xsd::cxx::xml::error_handler< " + char_type + L" >"); os << endl; } @@ -1145,7 +1191,7 @@ namespace CXX } os << "static" << endl - << "const ::xsd::cxx::tree::element_map_init < " << + << "const ::xsd::cxx::tree::element_map_init< " << char_type << ", " << type_ << " >" << endl << "_xsd_element_map_init;"; @@ -1158,10 +1204,79 @@ namespace CXX } Namespace::post (n); + + // Generate exports. + // + if (export_) + { + StringSet ns_set; + + for (StringSet::ConstIterator i (exports_.begin ()); + i != exports_.end (); ++i) + { + String const& e (*i); + + // 12 is to skip ::xsd::cxx:: + // + ns_set.insert (String (e, 12, e.rfind (':', e.find ('<')) - 13)); + } + + os << "#ifndef XSD_NO_EXPORT" << endl + << endl + << "namespace xsd" + << "{" + << "namespace cxx" + << "{"; + + for (StringSet::ConstIterator i (ns_set.begin ()); + i != ns_set.end (); ++i) + { + String const& ns (*i); + String prefix (L"::xsd::cxx::" + ns); + + Size n (1); + for (Size b (0), e (ns.find (':')); ; n++) + { + os << "namespace " << String (ns, b, e) + << "{"; + + if (e == String::npos) + break; + + b = e + 2; + e = ns.find (':', b); + } + + for (StringSet::ConstIterator i (exports_.begin ()); + i != exports_.end (); ++i) + { + String const& e (*i); + String ens (e, 12, e.rfind (':', e.find ('<')) - 13); + + if (ns == ens) + { + String type (e, e.rfind (':', e.find ('<')) + 1); + os << "template class " << type_exp << type << ";"; + } + } + + while (n--) + os << "}"; + } + + os << "}" // cxx + << "}" // xsd + << "#endif // XSD_NO_EXPORT" << endl + << endl; + } } private: + typedef Cult::Containers::Set StringSet; + Boolean export_; + StringSet exports_; + String xs_ns_; Traversal::Names names_; diff --git a/xsd/cxx/tree/serialization-source.cxx b/xsd/cxx/tree/serialization-source.cxx index 410b59a..5543ae5 100644 --- a/xsd/cxx/tree/serialization-source.cxx +++ b/xsd/cxx/tree/serialization-source.cxx @@ -1257,7 +1257,9 @@ namespace CXX if (import_maps || export_maps) { - ctx.os << "namespace xsd" + ctx.os << "#ifndef XSD_NO_EXPORT" << endl + << endl + << "namespace xsd" << "{" << "namespace cxx" << "{" @@ -1277,10 +1279,16 @@ namespace CXX << "template struct __attribute__ ((visibility(\"default\"))) " << "type_serializer_plate< 0, " << ctx.char_type << " >;"; + ctx.os << "#elif defined(XSD_MAP_VISIBILITY)" << endl + << "template struct XSD_MAP_VISIBILITY " << + "type_serializer_plate< 0, " << ctx.char_type << " >;"; + ctx.os << "#endif" << endl << "}" // tree << "}" // cxx - << "}"; // xsd + << "}" // xsd + << "#endif // XSD_NO_EXPORT" << endl + << endl; } ctx.os << "namespace _xsd" diff --git a/xsd/cxx/tree/stream-extraction-source.cxx b/xsd/cxx/tree/stream-extraction-source.cxx index fe9e31f..39c5994 100644 --- a/xsd/cxx/tree/stream-extraction-source.cxx +++ b/xsd/cxx/tree/stream-extraction-source.cxx @@ -676,7 +676,9 @@ namespace CXX if (import_maps || export_maps) { - ctx.os << "namespace xsd" + ctx.os << "#ifndef XSD_NO_EXPORT" << endl + << endl + << "namespace xsd" << "{" << "namespace cxx" << "{" @@ -703,12 +705,19 @@ namespace CXX << "template struct __attribute__ ((visibility(\"default\"))) " << "stream_extraction_plate< 0, " << stream << ", " << ctx.char_type << " >;" + << "#elif defined(XSD_MAP_VISIBILITY)" << endl + << "template struct XSD_MAP_VISIBILITY " << + "stream_extraction_plate< 0, " << stream << ", " << + ctx.char_type << " >;" << "#endif" << endl; } ctx.os << "}" // tree << "}" // cxx - << "}"; // xsd + << "}" // xsd + << "#endif // XSD_NO_EXPORT" << endl + << endl; + } ctx.os << "namespace _xsd" diff --git a/xsd/cxx/tree/stream-insertion-source.cxx b/xsd/cxx/tree/stream-insertion-source.cxx index ae58dcc..1ab21e7 100644 --- a/xsd/cxx/tree/stream-insertion-source.cxx +++ b/xsd/cxx/tree/stream-insertion-source.cxx @@ -448,7 +448,9 @@ namespace CXX if (import_maps || export_maps) { - ctx.os << "namespace xsd" + ctx.os << "#ifndef XSD_NO_EXPORT" << endl + << endl + << "namespace xsd" << "{" << "namespace cxx" << "{" @@ -475,12 +477,18 @@ namespace CXX << "template struct __attribute__ ((visibility(\"default\"))) " << "stream_insertion_plate< 0, " << stream << ", " << ctx.char_type << " >;" + << "#elif defined(XSD_MAP_VISIBILITY)" << endl + << "template struct XSD_MAP_VISIBILITY " << + "stream_insertion_plate< 0, " << stream << ", " << + ctx.char_type << " >;" << "#endif" << endl; } ctx.os << "}" // tree << "}" // cxx - << "}"; // xsd + << "}" // xsd + << "#endif // XSD_NO_EXPORT" << endl + << endl; } ctx.os << "namespace _xsd" diff --git a/xsd/cxx/tree/stream-source.cxx b/xsd/cxx/tree/stream-source.cxx index c663158..7631050 100644 --- a/xsd/cxx/tree/stream-source.cxx +++ b/xsd/cxx/tree/stream-source.cxx @@ -420,7 +420,9 @@ namespace CXX if (import_maps || export_maps) { - ctx.os << "namespace xsd" + ctx.os << "#ifndef XSD_NO_EXPORT" << endl + << endl + << "namespace xsd" << "{" << "namespace cxx" << "{" @@ -440,10 +442,16 @@ namespace CXX << "template struct __attribute__ ((visibility(\"default\"))) " << "std_ostream_plate< 0, " << ctx.char_type << " >;"; + ctx.os << "#elif defined(XSD_MAP_VISIBILITY)" << endl + << "template struct XSD_MAP_VISIBILITY " << + "std_ostream_plate< 0, " << ctx.char_type << " >;"; + ctx.os << "#endif" << endl << "}" // tree << "}" // cxx - << "}"; // xsd + << "}" // xsd + << "#endif // XSD_NO_EXPORT" << endl + << endl; } ctx.os << "namespace _xsd" diff --git a/xsd/cxx/tree/tree-source.cxx b/xsd/cxx/tree/tree-source.cxx index 3f902e7..ef5ad8e 100644 --- a/xsd/cxx/tree/tree-source.cxx +++ b/xsd/cxx/tree/tree-source.cxx @@ -3370,7 +3370,9 @@ namespace CXX if (import_maps || export_maps) { - ctx.os << "namespace xsd" + ctx.os << "#ifndef XSD_NO_EXPORT" << endl + << endl + << "namespace xsd" << "{" << "namespace cxx" << "{" @@ -3404,10 +3406,22 @@ namespace CXX ctx.os << "template struct __attribute__ ((visibility(\"default\"))) " << "comparison_plate< 0, " << ctx.char_type << " >;"; + ctx.os << "#elif defined(XSD_MAP_VISIBILITY)" << endl; + + if (parsing) + ctx.os << "template struct XSD_MAP_VISIBILITY " << + "type_factory_plate< 0, " << ctx.char_type << " >;"; + + if (comparison) + ctx.os << "template struct XSD_MAP_VISIBILITY " << + "comparison_plate< 0, " << ctx.char_type << " >;"; + ctx.os << "#endif" << endl << "}" // tree << "}" // cxx - << "}"; // xsd + << "}" // xsd + << "#endif // XSD_NO_EXPORT" << endl + << endl; } ctx.os << "namespace _xsd" -- cgit v1.1