aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2011-06-02 04:32:17 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2011-06-02 04:32:17 +0200
commitfdebdeb76de5ac844973f06aec797444ec9f809f (patch)
tree40004401c3c0a3e607e452d00d796e6ea87883d1
parentfbe57707af97fdc63a00209db54e62d46e4ffbff (diff)
Add support for fat type files
Such files also contain all the global elements that this type classifies.
-rw-r--r--xsd-frontend/transformations/schema-per-type.cxx45
-rw-r--r--xsd-frontend/transformations/schema-per-type.hxx5
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<Type&> (n));
+
Schema& ts (root.new_node<Schema> (path, 1, 1));
root.new_edge<Implies> (ts, xsd, xsd_path);
@@ -198,11 +201,43 @@ namespace XSDFrontend
root.new_edge<Names> (ts, tns, ns.name ());
root.new_edge<Names> (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<Element> () &&
+ e.scope ().is_a<Namespace> () &&
+ 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<Names> (tns, e, name);
+ }
+ }
+ }
+
// Add include to the original schema and enter into the
// type-schema map.
//
root.new_edge<Includes> (s, ts, path);
- tsm[&dynamic_cast<Type&> (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<SemanticGraph::Schema*>
transform (SemanticGraph::Schema&);
private:
+ Boolean fat_type_file_;
Char const* by_value_key_;
SchemaPerTypeTranslator& trans_;
};