From fdebdeb76de5ac844973f06aec797444ec9f809f Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 2 Jun 2011 04:32:17 +0200 Subject: Add support for fat type files Such files also contain all the global elements that this type classifies. --- xsd-frontend/transformations/schema-per-type.cxx | 45 +++++++++++++++++++++--- xsd-frontend/transformations/schema-per-type.hxx | 5 ++- 2 files changed, 45 insertions(+), 5 deletions(-) diff --git a/xsd-frontend/transformations/schema-per-type.cxx b/xsd-frontend/transformations/schema-per-type.cxx index c23bf2b..3b93ea3 100644 --- a/xsd-frontend/transformations/schema-per-type.cxx +++ b/xsd-frontend/transformations/schema-per-type.cxx @@ -103,6 +103,7 @@ namespace XSDFrontend SemanticGraph::Schema& xsd, TypeSchemaMap& tsm, FileSet& file_set, + Boolean fat_type_file, Transformations::SchemaPerTypeTranslator& trans) { using namespace SemanticGraph; @@ -191,6 +192,8 @@ namespace XSDFrontend throw Failed (); } + Type& t (dynamic_cast (n)); + Schema& ts (root.new_node (path, 1, 1)); root.new_edge (ts, xsd, xsd_path); @@ -198,11 +201,43 @@ namespace XSDFrontend root.new_edge (ts, tns, ns.name ()); root.new_edge (tns, n, name); + // If we are generating fat type files, then also move the global + // elements this type classifies to the new schema. + // + if (fat_type_file) + { + for (Type::ClassifiesIterator j (t.classifies_begin ()); + j != t.classifies_end (); ++j) + { + Instance& e (j->instance ()); + + // We can only move a global element from the same namespace. + // + if (e.is_a () && + e.scope ().is_a () && + e.scope ().name () == ns.name ()) + { + Names& n (e.named ()); + String name (n.name ()); + + // Watch out for the iterator validity: the edge we are + // about to remove can be from the same list we are + // currently iterating. + // + if (i != ns.names_end () && &*i == &n) + ++i; + + root.delete_edge (n.scope (), e, n); + root.new_edge (tns, e, name); + } + } + } + // Add include to the original schema and enter into the // type-schema map. // root.new_edge (s, ts, path); - tsm[&dynamic_cast (n)] = &ts; + tsm[&t] = &ts; } else ++i; @@ -308,8 +343,10 @@ namespace XSDFrontend namespace Transformations { SchemaPerType:: - SchemaPerType (SchemaPerTypeTranslator& trans, Char const* by_value_key) - : by_value_key_ (by_value_key), trans_ (trans) + SchemaPerType (SchemaPerTypeTranslator& trans, + Boolean fat, + Char const* key) + : fat_type_file_ (fat), by_value_key_ (key), trans_ (trans) { } @@ -409,7 +446,7 @@ namespace XSDFrontend for (Schemas::Iterator i (schemas.begin ()); i != schemas.end (); ++i) { - process_schema (**i, root, *xsd, tsm, file_set, trans_); + process_schema (**i, root, *xsd, tsm, file_set, fat_type_file_, trans_); } // wcerr << tsm.size () << " type schema nodes" << endl; diff --git a/xsd-frontend/transformations/schema-per-type.hxx b/xsd-frontend/transformations/schema-per-type.hxx index e276617..8f582ae 100644 --- a/xsd-frontend/transformations/schema-per-type.hxx +++ b/xsd-frontend/transformations/schema-per-type.hxx @@ -46,12 +46,15 @@ namespace XSDFrontend // with the by_value_key key and it is true, then the schema // for this type is included "strongly". // - SchemaPerType (SchemaPerTypeTranslator&, Char const* by_value_key = 0); + SchemaPerType (SchemaPerTypeTranslator&, + Boolean fat_type_file, + Char const* by_value_key = 0); Cult::Containers::Vector transform (SemanticGraph::Schema&); private: + Boolean fat_type_file_; Char const* by_value_key_; SchemaPerTypeTranslator& trans_; }; -- cgit v1.1