summaryrefslogtreecommitdiff
path: root/libxsd-frontend/xsd-frontend/transformations
diff options
context:
space:
mode:
Diffstat (limited to 'libxsd-frontend/xsd-frontend/transformations')
-rw-r--r--libxsd-frontend/xsd-frontend/transformations/anonymous.cxx377
-rw-r--r--libxsd-frontend/xsd-frontend/transformations/anonymous.hxx21
-rw-r--r--libxsd-frontend/xsd-frontend/transformations/enum-synthesis.cxx20
-rw-r--r--libxsd-frontend/xsd-frontend/transformations/enum-synthesis.hxx9
-rw-r--r--libxsd-frontend/xsd-frontend/transformations/restriction.cxx56
-rw-r--r--libxsd-frontend/xsd-frontend/transformations/restriction.hxx9
-rw-r--r--libxsd-frontend/xsd-frontend/transformations/schema-per-type.cxx148
-rw-r--r--libxsd-frontend/xsd-frontend/transformations/schema-per-type.hxx23
-rw-r--r--libxsd-frontend/xsd-frontend/transformations/simplifier.cxx23
-rw-r--r--libxsd-frontend/xsd-frontend/transformations/simplifier.hxx9
10 files changed, 481 insertions, 214 deletions
diff --git a/libxsd-frontend/xsd-frontend/transformations/anonymous.cxx b/libxsd-frontend/xsd-frontend/transformations/anonymous.cxx
index 118fd5d..1c42d98 100644
--- a/libxsd-frontend/xsd-frontend/transformations/anonymous.cxx
+++ b/libxsd-frontend/xsd-frontend/transformations/anonymous.cxx
@@ -1,6 +1,5 @@
// file : xsd-frontend/transformations/anonymous.cxx
-// author : Boris Kolpackov <boris@codesynthesis.com>
-// copyright : Copyright (c) 2006-2010 Code Synthesis Tools CC
+// copyright : Copyright (c) 2006-2014 Code Synthesis Tools CC
// license : GNU GPL v2 + exceptions; see accompanying LICENSE file
#include <xsd-frontend/transformations/anonymous.hxx>
@@ -10,27 +9,281 @@
#include <iostream>
#include <sstream>
+#include <typeinfo>
using std::wcerr;
using std::endl;
namespace XSDFrontend
{
- using namespace Cult;
-
- typedef WideString String;
-
namespace
{
using Transformations::AnonymousNameTranslator;
+ //
+ //
+ struct CompareMembers: Traversal::Element,
+ Traversal::Attribute,
+ Traversal::Any,
+ Traversal::AnyAttribute
+ {
+ CompareMembers (SemanticGraph::Nameable& m, bool& r)
+ : member_ (m), result_ (r)
+ {
+ }
+
+ virtual void
+ traverse (SemanticGraph::Element& x)
+ {
+ using SemanticGraph::Element;
+
+ Element& y (dynamic_cast<Element&> (member_));
+
+ // Check cardinalities.
+ //
+ if (x.min () != y.min () || x.max () != y.max ())
+ return;
+
+ traverse_member (x);
+ }
+
+ virtual void
+ traverse (SemanticGraph::Attribute& x)
+ {
+ using SemanticGraph::Attribute;
+
+ Attribute& y (dynamic_cast<Attribute&> (member_));
+
+ // Check cardinalities.
+ //
+ if (x.optional_p () != y.optional_p ())
+ return;
+
+ traverse_member (x);
+ }
+
+ virtual void
+ traverse_member (SemanticGraph::Member& x)
+ {
+ using SemanticGraph::Member;
+
+ Member& y (dynamic_cast<Member&> (member_));
+
+ // Check name.
+ //
+ if (x.name () != y.name ())
+ return;
+
+ // Check namespace.
+ //
+ if (x.qualified_p () || y.qualified_p ())
+ {
+ if (!x.qualified_p () || !y.qualified_p ())
+ return;
+
+ if (x.namespace_ ().name () != y.namespace_ ().name ())
+ return;
+ }
+
+ // Check type.
+ //
+ // @@ What if types are anonymous and structurally equal?
+ //
+ if (&x.type () != &y.type ())
+ return;
+
+ // Check default/fixed values.
+ //
+ if (x.default_p () != y.default_p () || x.fixed_p () != y.fixed_p ())
+ return;
+
+ if (x.default_p () && x.value () != y.value ())
+ return;
+
+ result_ = true;
+ }
+
+ virtual void
+ traverse (SemanticGraph::Any&)
+ {
+ //@@ TODO
+ }
+
+ virtual void
+ traverse (SemanticGraph::AnyAttribute&)
+ {
+ //@@ TODO
+ }
+
+ private:
+ SemanticGraph::Nameable& member_;
+ bool& result_;
+ };
+
+ // Compare two types for structural equality.
+ //
+ struct CompareTypes: Traversal::List,
+ Traversal::Union,
+ Traversal::Enumeration,
+ Traversal::Complex
+ {
+ CompareTypes (SemanticGraph::Type& t, bool& r)
+ : type_ (t), result_ (r)
+ {
+ }
+
+
+ virtual void
+ traverse (SemanticGraph::List&)
+ {
+ using SemanticGraph::List;
+
+ //List& y (dynamic_cast<List&> (type_));
+ }
+
+ virtual void
+ traverse (SemanticGraph::Union& x)
+ {
+ using SemanticGraph::Union;
+
+ Union& y (dynamic_cast<Union&> (type_));
+
+ Union::ArgumentedIterator ix (x.argumented_begin ()),
+ iy (y.argumented_begin ());
+
+ for (; ix != x.argumented_end () && iy != y.argumented_end ();
+ ++ix, ++iy)
+ {
+ // @@ Anon structurally equivalent.
+ //
+ if (&iy->type () != &ix->type ())
+ return;
+ }
+
+ result_ = true;
+ }
+
+ virtual void
+ traverse (SemanticGraph::Enumeration& x)
+ {
+ using SemanticGraph::Enumeration;
+
+ Enumeration& y (dynamic_cast<Enumeration&> (type_));
+
+ // Bases should be the same.
+ //
+ if (&x.inherits ().base () != &y.inherits ().base ())
+ return;
+
+ // Make sure facets match.
+ //
+ using SemanticGraph::Restricts;
+
+ Restricts& rx (dynamic_cast<Restricts&> (x.inherits ()));
+ Restricts& ry (dynamic_cast<Restricts&> (y.inherits ()));
+
+ if (rx.facets () != ry.facets ())
+ return;
+
+ // Compare enumerators.
+ //
+ using SemanticGraph::Scope;
+
+ Scope::NamesIterator ix (x.names_begin ()), iy (y.names_begin ());
+ for (; ix != x.names_end () && iy != y.names_end (); ++ix, ++iy)
+ {
+ if (ix->name () != iy->name ())
+ return;
+ }
+
+ if (ix != x.names_end () || iy != y.names_end ())
+ return;
+
+ result_ = true;
+ }
+
+ virtual void
+ traverse (SemanticGraph::Complex& x)
+ {
+ using SemanticGraph::Complex;
+
+ Complex& y (dynamic_cast<Complex&> (type_));
+
+ // Check inheritance.
+ //
+ if (x.inherits_p () || y.inherits_p ())
+ {
+ // They both must inherits.
+ //
+ if (!x.inherits_p () || !y.inherits_p ())
+ return;
+
+ // With the same kind of inheritance (restriction or extension).
+ //
+ if (typeid (x.inherits ()) != typeid (y.inherits ()))
+ return;
+
+ // Bases should be the same.
+ //
+ // @@ What if bases are anonymous?
+ //
+ if (&x.inherits ().base () != &y.inherits ().base ())
+ return;
+
+ // If it is a restriction, make sure facets match.
+ //
+ using SemanticGraph::Restricts;
+
+ if (x.inherits ().is_a<Restricts> ())
+ {
+ Restricts& rx (dynamic_cast<Restricts&> (x.inherits ()));
+ Restricts& ry (dynamic_cast<Restricts&> (y.inherits ()));
+
+ if (rx.facets () != ry.facets ())
+ return;
+ }
+ }
+
+ // Check the member list.
+ //
+ // @@ Ignoring compositors at the moment.
+ //
+ using SemanticGraph::Scope;
+
+ Scope::NamesIterator ix (x.names_begin ()), iy (y.names_begin ());
+ for (; ix != x.names_end () && iy != y.names_end (); ++ix, ++iy)
+ {
+ if (typeid (ix->named ()) != typeid (iy->named ()))
+ return;
+
+ bool equal (false);
+ CompareMembers t (iy->named (), equal);
+ t.dispatch (ix->named ());
+
+ if (!equal)
+ return;
+ }
+
+ if (ix != x.names_end () || iy != y.names_end ())
+ return;
+
+ result_ = true;
+ }
+
+ private:
+ SemanticGraph::Type& type_;
+ bool& result_;
+ };
+
+ //
+ //
class Context
{
public:
Context (SemanticGraph::Schema& schema_,
SemanticGraph::Path const& file,
AnonymousNameTranslator& trans_,
- Boolean du)
+ bool du)
: schema_path_ (file),
ns_ (0),
failed_ (false),
@@ -56,6 +309,19 @@ namespace XSDFrontend
}
public:
+
+ bool
+ structurally_equal (SemanticGraph::Type& x, SemanticGraph::Type& y)
+ {
+ if (typeid (x) != typeid (y))
+ return false;
+
+ bool r (false);
+ CompareTypes t (y, r);
+ t.dispatch (x);
+ return r;
+ }
+
struct UnstableConflict
{
UnstableConflict (SemanticGraph::Type& type)
@@ -73,7 +339,7 @@ namespace XSDFrontend
SemanticGraph::Type& type_;
};
- Boolean
+ SemanticGraph::Type*
conflict (String const& name)
{
using SemanticGraph::Type;
@@ -96,10 +362,10 @@ namespace XSDFrontend
throw UnstableConflict (*t1);
}
- return true;
+ return t1;
}
- return false;
+ return 0;
}
SemanticGraph::Type*
@@ -179,17 +445,17 @@ namespace XSDFrontend
private:
SemanticGraph::Path const schema_path_;
SemanticGraph::Namespace* ns_;
- Boolean failed_;
+ bool failed_;
public:
AnonymousNameTranslator& trans;
- Boolean detect_unstable;
+ bool detect_unstable;
public:
SemanticGraph::Schema& schema;
SemanticGraph::Path const& schema_path;
SemanticGraph::Namespace*& ns;
- Boolean& failed;
+ bool& failed;
};
@@ -198,7 +464,7 @@ namespace XSDFrontend
//
struct Uses: Traversal::Uses
{
- virtual Void
+ virtual void
traverse (Type& u)
{
SemanticGraph::Schema& s (u.schema ());
@@ -220,13 +486,13 @@ namespace XSDFrontend
{
}
- Void
+ void
pre (SemanticGraph::Namespace& ns)
{
ns_ = &ns;
}
- Void
+ void
post (SemanticGraph::Namespace&)
{
ns_ = 0;
@@ -248,7 +514,7 @@ namespace XSDFrontend
{
}
- virtual Void
+ virtual void
traverse (SemanticGraph::List& l)
{
SemanticGraph::Type& t (l.argumented ().type ());
@@ -264,6 +530,7 @@ namespace XSDFrontend
// Run the name through the translation service.
//
SemanticGraph::Path file (path (l));
+ file.normalize ();
String file_str;
// Try to use the portable representation of the path. If that
@@ -271,15 +538,11 @@ namespace XSDFrontend
//
try
{
- file_str = file.string ();
+ file_str = file.posix_string ();
}
catch (SemanticGraph::InvalidPath const&)
{
-#if !defined(BOOST_FILESYSTEM_VERSION) || BOOST_FILESYSTEM_VERSION == 2
- file_str = file.native_file_string ();
-#else
file_str = file.string ();
-#endif
}
String name (
@@ -288,7 +551,7 @@ namespace XSDFrontend
// Make sure the name is unique.
//
- UnsignedLong n (1);
+ unsigned long n (1);
String escaped (name);
while (conflict (escaped))
@@ -330,7 +593,7 @@ namespace XSDFrontend
}
}
- virtual Void
+ virtual void
traverse (SemanticGraph::Union& u)
{
String file_str;
@@ -352,21 +615,18 @@ namespace XSDFrontend
if (!file_str)
{
SemanticGraph::Path file (path (u));
+ file.normalize ();
// Try to use the portable representation of the path. If
// that fails, fall back to the native representation.
//
try
{
- file_str = file.string ();
+ file_str = file.posix_string ();
}
catch (SemanticGraph::InvalidPath const&)
{
-#if !defined(BOOST_FILESYSTEM_VERSION) || BOOST_FILESYSTEM_VERSION == 2
- file_str = file.native_file_string ();
-#else
file_str = file.string ();
-#endif
}
}
@@ -376,7 +636,7 @@ namespace XSDFrontend
// Make sure the name is unique.
//
- UnsignedLong n (1);
+ unsigned long n (1);
String escaped (name);
while (conflict (escaped))
@@ -419,7 +679,7 @@ namespace XSDFrontend
}
}
- virtual Void
+ virtual void
traverse (SemanticGraph::Complex& c)
{
if (!c.inherits_p ())
@@ -438,6 +698,7 @@ namespace XSDFrontend
// Run the name through the translation service.
//
SemanticGraph::Path file (path (c));
+ file.normalize ();
String file_str;
// Try to use the portable representation of the path. If that
@@ -445,15 +706,11 @@ namespace XSDFrontend
//
try
{
- file_str = file.string ();
+ file_str = file.posix_string ();
}
catch (SemanticGraph::InvalidPath const&)
{
-#if !defined(BOOST_FILESYSTEM_VERSION) || BOOST_FILESYSTEM_VERSION == 2
- file_str = file.native_file_string ();
-#else
file_str = file.string ();
-#endif
}
String name (
@@ -462,7 +719,7 @@ namespace XSDFrontend
// Make sure the name is unique.
//
- UnsignedLong n (1);
+ unsigned long n (1);
String escaped (name);
while (conflict (escaped))
@@ -517,7 +774,7 @@ namespace XSDFrontend
{
}
- virtual Void
+ virtual void
traverse (SemanticGraph::Element& e)
{
SemanticGraph::Type& t (e.type ());
@@ -560,7 +817,7 @@ namespace XSDFrontend
}
}
- virtual Void
+ virtual void
traverse (SemanticGraph::Attribute& a)
{
SemanticGraph::Type& t (a.type ());
@@ -603,7 +860,7 @@ namespace XSDFrontend
}
}
- Void
+ void
traverse_ (SemanticGraph::Member& m)
{
using SemanticGraph::Type;
@@ -640,6 +897,7 @@ namespace XSDFrontend
// Run the name through the translation service.
//
SemanticGraph::Path file (path (m));
+ file.normalize ();
String file_str;
// Try to use the portable representation of the path. If that
@@ -647,27 +905,46 @@ namespace XSDFrontend
//
try
{
- file_str = file.string ();
+ file_str = file.posix_string ();
}
catch (SemanticGraph::InvalidPath const&)
{
-#if !defined(BOOST_FILESYSTEM_VERSION) || BOOST_FILESYSTEM_VERSION == 2
- file_str = file.native_file_string ();
-#else
file_str = file.string ();
-#endif
}
String name (
trans.translate (file_str, ns->name (), m.name (), xpath (m)));
- // Make sure the name is unique.
+ // Check if this name conflicts.
//
- UnsignedLong n (1);
+ unsigned long n (1);
String escaped (name);
- while (conflict (escaped))
+ while (SemanticGraph::Type* other = conflict (escaped))
{
+ // First see if we should just use the other type. It should
+ // also have been anonymous and structurally equal to our type.
+ //
+ if (other->context ().count ("anonymous"))
+ {
+ if (structurally_equal (t, *other))
+ {
+ // Reset the elements that are classified by this type to point
+ // to the other type.
+ //
+ for (Type::ClassifiesIterator i (t.classifies_begin ());
+ i != t.classifies_end (); ++i)
+ {
+ schema.reset_right_node (*i, *other);
+ }
+
+ //wcerr << "equal " << name << endl;
+ return;
+ }
+ //else
+ //wcerr << "unequal " << name << endl;
+ }
+
std::wostringstream os;
os << n++;
escaped = name + os.str ();
@@ -687,10 +964,10 @@ namespace XSDFrontend
{
}
- Void Anonymous::
+ void Anonymous::
transform (SemanticGraph::Schema& s,
SemanticGraph::Path const& f,
- Boolean duc)
+ bool duc)
{
Context ctx (s, f, trans_, duc);
diff --git a/libxsd-frontend/xsd-frontend/transformations/anonymous.hxx b/libxsd-frontend/xsd-frontend/transformations/anonymous.hxx
index 2409822..cafd187 100644
--- a/libxsd-frontend/xsd-frontend/transformations/anonymous.hxx
+++ b/libxsd-frontend/xsd-frontend/transformations/anonymous.hxx
@@ -1,12 +1,11 @@
// file : xsd-frontend/transformations/anonymous.hxx
-// author : Boris Kolpackov <boris@codesynthesis.com>
-// copyright : Copyright (c) 2006-2010 Code Synthesis Tools CC
+// copyright : Copyright (c) 2006-2014 Code Synthesis Tools CC
// license : GNU GPL v2 + exceptions; see accompanying LICENSE file
#ifndef XSD_FRONTEND_TRANSFORMATIONS_ANONYMOUS_HXX
#define XSD_FRONTEND_TRANSFORMATIONS_ANONYMOUS_HXX
-#include <cult/types.hxx>
+#include <xsd-frontend/types.hxx>
#include <xsd-frontend/semantic-graph/elements.hxx> // Path
#include <xsd-frontend/semantic-graph/schema.hxx>
@@ -15,8 +14,6 @@ namespace XSDFrontend
{
namespace Transformations
{
- using namespace Cult::Types;
-
class AnonymousNameTranslator
{
public:
@@ -26,11 +23,11 @@ namespace XSDFrontend
// The file argument is empty for the currect translation
// unit.
//
- virtual WideString
- translate (WideString const& file,
- WideString const& ns,
- WideString const& name,
- WideString const& xpath) = 0;
+ virtual String
+ translate (String const& file,
+ String const& ns,
+ String const& name,
+ String const& xpath) = 0;
};
// This transformation morphs anonymous types into named ones
@@ -46,10 +43,10 @@ namespace XSDFrontend
Anonymous (AnonymousNameTranslator&);
- Void
+ void
transform (SemanticGraph::Schema&,
SemanticGraph::Path const&,
- Boolean detect_unstable_conflicts);
+ bool detect_unstable_conflicts);
private:
AnonymousNameTranslator& trans_;
diff --git a/libxsd-frontend/xsd-frontend/transformations/enum-synthesis.cxx b/libxsd-frontend/xsd-frontend/transformations/enum-synthesis.cxx
index e10b9d3..26ad16c 100644
--- a/libxsd-frontend/xsd-frontend/transformations/enum-synthesis.cxx
+++ b/libxsd-frontend/xsd-frontend/transformations/enum-synthesis.cxx
@@ -1,23 +1,19 @@
// file : xsd-frontend/transformations/enum-synthesis.cxx
-// author : Boris Kolpackov <boris@codesynthesis.com>
-// copyright : Copyright (c) 2006-2010 Code Synthesis Tools CC
+// copyright : Copyright (c) 2006-2014 Code Synthesis Tools CC
// license : GNU GPL v2 + exceptions; see accompanying LICENSE file
-#include <xsd-frontend/transformations/enum-synthesis.hxx>
+#include <set>
#include <xsd-frontend/semantic-graph.hxx>
#include <xsd-frontend/traversal.hxx>
-#include <cult/containers/set.hxx>
+#include <xsd-frontend/transformations/enum-synthesis.hxx>
namespace XSDFrontend
{
- using namespace Cult;
- typedef WideString String;
-
namespace
{
- typedef Cult::Containers::Set<String> Enumerators;
+ typedef std::set<String> Enumerators;
struct Enumerator: Traversal::Enumerator
{
@@ -28,7 +24,7 @@ namespace XSDFrontend
{
}
- virtual Void
+ virtual void
traverse (Type& e)
{
String const& name (e.name ());
@@ -64,7 +60,7 @@ namespace XSDFrontend
{
}
- virtual Void
+ virtual void
traverse (Type& u)
{
using SemanticGraph::Enumeration;
@@ -208,7 +204,7 @@ namespace XSDFrontend
//
struct Uses: Traversal::Uses
{
- virtual Void
+ virtual void
traverse (Type& u)
{
SemanticGraph::Schema& s (u.schema ());
@@ -224,7 +220,7 @@ namespace XSDFrontend
namespace Transformations
{
- Void EnumSynthesis::
+ void EnumSynthesis::
transform (SemanticGraph::Schema& s, SemanticGraph::Path const&)
{
Traversal::Schema schema;
diff --git a/libxsd-frontend/xsd-frontend/transformations/enum-synthesis.hxx b/libxsd-frontend/xsd-frontend/transformations/enum-synthesis.hxx
index e3c38c7..9f0f970 100644
--- a/libxsd-frontend/xsd-frontend/transformations/enum-synthesis.hxx
+++ b/libxsd-frontend/xsd-frontend/transformations/enum-synthesis.hxx
@@ -1,12 +1,11 @@
// file : xsd-frontend/transformations/enum-synthesis.hxx
-// author : Boris Kolpackov <boris@codesynthesis.com>
-// copyright : Copyright (c) 2006-2010 Code Synthesis Tools CC
+// copyright : Copyright (c) 2006-2014 Code Synthesis Tools CC
// license : GNU GPL v2 + exceptions; see accompanying LICENSE file
#ifndef XSD_FRONTEND_TRANSFORMATIONS_ENUM_SYNTHESIS_HXX
#define XSD_FRONTEND_TRANSFORMATIONS_ENUM_SYNTHESIS_HXX
-#include <cult/types.hxx>
+#include <xsd-frontend/types.hxx>
#include <xsd-frontend/semantic-graph/elements.hxx> // Path
#include <xsd-frontend/semantic-graph/schema.hxx>
@@ -15,8 +14,6 @@ namespace XSDFrontend
{
namespace Transformations
{
- using namespace Cult::Types;
-
// This transformation replaces unions of one or more enumerations
// with the same base with an equivalent synthesized enumeration.
// This transformation assumes that there are no anonymous types.
@@ -24,7 +21,7 @@ namespace XSDFrontend
class EnumSynthesis
{
public:
- Void
+ void
transform (SemanticGraph::Schema&, SemanticGraph::Path const&);
};
}
diff --git a/libxsd-frontend/xsd-frontend/transformations/restriction.cxx b/libxsd-frontend/xsd-frontend/transformations/restriction.cxx
index c58d98f..edd74be 100644
--- a/libxsd-frontend/xsd-frontend/transformations/restriction.cxx
+++ b/libxsd-frontend/xsd-frontend/transformations/restriction.cxx
@@ -1,27 +1,21 @@
// file : xsd-frontend/transformations/restriction.cxx
-// author : Boris Kolpackov <boris@codesynthesis.com>
-// copyright : Copyright (c) 2006-2010 Code Synthesis Tools CC
+// copyright : Copyright (c) 2006-2014 Code Synthesis Tools CC
// license : GNU GPL v2 + exceptions; see accompanying LICENSE file
-#include <xsd-frontend/transformations/restriction.hxx>
+#include <vector>
+#include <iostream>
#include <xsd-frontend/semantic-graph.hxx>
#include <xsd-frontend/traversal.hxx>
-#include <cult/containers/vector.hxx>
-
-#include <iostream>
+#include <xsd-frontend/transformations/restriction.hxx>
-using std::wcerr;
-using std::endl;
+using namespace std;
namespace XSDFrontend
{
- using namespace Cult;
-
- typedef WideString String;
typedef Transformations::Restriction::Failed Failed;
- typedef Containers::Vector<SemanticGraph::Complex*> BaseList;
+ typedef std::vector<SemanticGraph::Complex*> BaseList;
namespace
{
@@ -34,7 +28,7 @@ namespace XSDFrontend
{
}
- virtual Void
+ virtual void
traverse (Type& c)
{
using namespace SemanticGraph;
@@ -107,7 +101,7 @@ namespace XSDFrontend
else
{
Compositor::ContainsIterator i (root.contains_begin ());
- BaseList::ReverseIterator j (base_model.rbegin ());
+ BaseList::reverse_iterator j (base_model.rbegin ());
for (; i != root.contains_end (); ++i, ++j)
{
@@ -153,7 +147,7 @@ namespace XSDFrontend
}
private:
- Void
+ void
handle (SemanticGraph::Particle& r, SemanticGraph::Particle& b)
{
using namespace SemanticGraph;
@@ -215,7 +209,7 @@ namespace XSDFrontend
}
}
- Boolean
+ bool
match (SemanticGraph::Particle& r, SemanticGraph::Particle& b)
{
using namespace SemanticGraph;
@@ -282,7 +276,7 @@ namespace XSDFrontend
return false;
}
- Void
+ void
merge_attributes (SemanticGraph::Complex& c,
SemanticGraph::Complex& base)
{
@@ -364,12 +358,12 @@ namespace XSDFrontend
}
}
- Void
+ void
handle_any_attributes (SemanticGraph::Complex& c, BaseList& bl)
{
using namespace SemanticGraph;
- BaseList::ReverseIterator bi (bl.rbegin ()), be (bl.rend ());
+ BaseList::reverse_iterator bi (bl.rbegin ()), be (bl.rend ());
Scope::NamesIterator si;
if (bi != be)
@@ -432,14 +426,14 @@ namespace XSDFrontend
struct Anonymous : Traversal::Element,
Traversal::Attribute
{
- Anonymous (Traversal::NodeDispatcherBase& d1)
+ Anonymous (Traversal::NodeDispatcher& d1)
: complex_ (&d1, 0)
{
*this >> belongs_ >> complex_;
}
- Anonymous (Traversal::NodeDispatcherBase& d1,
- Traversal::NodeDispatcherBase& d2)
+ Anonymous (Traversal::NodeDispatcher& d1,
+ Traversal::NodeDispatcher& d2)
: complex_ (&d1, &d2)
{
*this >> belongs_ >> complex_;
@@ -460,7 +454,7 @@ namespace XSDFrontend
public:
- virtual Void
+ virtual void
traverse (SemanticGraph::Element& e)
{
SemanticGraph::Type& t (e.type ());
@@ -479,7 +473,7 @@ namespace XSDFrontend
}
}
- virtual Void
+ virtual void
traverse (SemanticGraph::Attribute& a)
{
SemanticGraph::Type& t (a.type ());
@@ -501,13 +495,13 @@ namespace XSDFrontend
private:
struct Complex : Traversal::Complex
{
- Complex (Traversal::NodeDispatcherBase* d1,
- Traversal::NodeDispatcherBase* d2)
+ Complex (Traversal::NodeDispatcher* d1,
+ Traversal::NodeDispatcher* d2)
: d1_ (d1), d2_ (d2)
{
}
- virtual Void
+ virtual void
traverse (SemanticGraph::Complex& c)
{
if (d1_)
@@ -518,8 +512,8 @@ namespace XSDFrontend
}
private:
- Traversal::NodeDispatcherBase* d1_;
- Traversal::NodeDispatcherBase* d2_;
+ Traversal::NodeDispatcher* d1_;
+ Traversal::NodeDispatcher* d2_;
} complex_;
@@ -532,7 +526,7 @@ namespace XSDFrontend
//
struct Uses: Traversal::Uses
{
- virtual Void
+ virtual void
traverse (Type& u)
{
SemanticGraph::Schema& s (u.schema ());
@@ -548,7 +542,7 @@ namespace XSDFrontend
namespace Transformations
{
- Void Restriction::
+ void Restriction::
transform (SemanticGraph::Schema& s, SemanticGraph::Path const&)
{
Traversal::Schema schema;
diff --git a/libxsd-frontend/xsd-frontend/transformations/restriction.hxx b/libxsd-frontend/xsd-frontend/transformations/restriction.hxx
index 7c3282e..6d7410c 100644
--- a/libxsd-frontend/xsd-frontend/transformations/restriction.hxx
+++ b/libxsd-frontend/xsd-frontend/transformations/restriction.hxx
@@ -1,12 +1,11 @@
// file : xsd-frontend/transformations/restriction.hxx
-// author : Boris Kolpackov <boris@codesynthesis.com>
-// copyright : Copyright (c) 2006-2010 Code Synthesis Tools CC
+// copyright : Copyright (c) 2006-2014 Code Synthesis Tools CC
// license : GNU GPL v2 + exceptions; see accompanying LICENSE file
#ifndef XSD_FRONTEND_TRANSFORMATIONS_RESTRICTION_HXX
#define XSD_FRONTEND_TRANSFORMATIONS_RESTRICTION_HXX
-#include <cult/types.hxx>
+#include <xsd-frontend/types.hxx>
#include <xsd-frontend/semantic-graph/elements.hxx> // Path
#include <xsd-frontend/semantic-graph/schema.hxx>
@@ -15,8 +14,6 @@ namespace XSDFrontend
{
namespace Transformations
{
- using namespace Cult::Types;
-
// This transformation performs two major tasks. It transfers omitted
// attribute declarations from the base to derived-by-restriction type
// and establishes correspondence between particles and compositors by
@@ -30,7 +27,7 @@ namespace XSDFrontend
public:
struct Failed {};
- Void
+ void
transform (SemanticGraph::Schema&, SemanticGraph::Path const&);
};
}
diff --git a/libxsd-frontend/xsd-frontend/transformations/schema-per-type.cxx b/libxsd-frontend/xsd-frontend/transformations/schema-per-type.cxx
index 9ac8445..2fc14b5 100644
--- a/libxsd-frontend/xsd-frontend/transformations/schema-per-type.cxx
+++ b/libxsd-frontend/xsd-frontend/transformations/schema-per-type.cxx
@@ -1,48 +1,42 @@
// file : xsd-frontend/transformations/schema-per-type.cxx
-// author : Boris Kolpackov <boris@codesynthesis.com>
-// copyright : Copyright (c) 2006-2010 Code Synthesis Tools CC
+// copyright : Copyright (c) 2006-2014 Code Synthesis Tools CC
// license : GNU GPL v2 + exceptions; see accompanying LICENSE file
-#include <xsd-frontend/transformations/schema-per-type.hxx>
-
-#include <xsd-frontend/semantic-graph.hxx>
-#include <xsd-frontend/traversal.hxx>
+#include <strings.h> // strcasecmp
-#include <cult/containers/map.hxx>
-#include <cult/containers/set.hxx>
-#include <cult/containers/vector.hxx>
+#include <map>
+#include <set>
+#include <vector>
#include <sstream>
#include <iostream>
-#include <strings.h> // strcasecmp
+#include <xsd-frontend/semantic-graph.hxx>
+#include <xsd-frontend/traversal.hxx>
+
+#include <xsd-frontend/transformations/schema-per-type.hxx>
using std::wcerr;
using std::endl;
namespace XSDFrontend
{
- using namespace Cult;
-
- typedef WideString String;
typedef Transformations::SchemaPerType::Failed Failed;
-
- typedef Containers::Vector<SemanticGraph::Schema*> Schemas;
- typedef Containers::Map<SemanticGraph::Type*,
- SemanticGraph::Schema*> TypeSchemaMap;
+ typedef std::vector<SemanticGraph::Schema*> Schemas;
+ typedef std::map<SemanticGraph::Type*, SemanticGraph::Schema*> TypeSchemaMap;
// Compare file paths case-insensitively.
//
struct FileComparator
{
- Boolean
+ bool
operator() (NarrowString const& x, NarrowString const& y) const
{
return strcasecmp (x.c_str (), y.c_str ()) < 0;
}
};
- typedef Containers::Set<NarrowString, FileComparator> FileSet;
+ typedef std::set<NarrowString, FileComparator> FileSet;
namespace
{
@@ -59,7 +53,7 @@ namespace XSDFrontend
xsd_ = 0;
}
- virtual Void
+ virtual void
traverse (SemanticGraph::Includes& i)
{
SemanticGraph::Schema& s (i.schema ());
@@ -72,7 +66,7 @@ namespace XSDFrontend
}
}
- virtual Void
+ virtual void
traverse (SemanticGraph::Imports& i)
{
SemanticGraph::Schema& s (i.schema ());
@@ -85,7 +79,7 @@ namespace XSDFrontend
}
}
- virtual Void
+ virtual void
traverse (SemanticGraph::Implies& i)
{
if (xsd_ == 0)
@@ -97,12 +91,13 @@ namespace XSDFrontend
SemanticGraph::Schema*& xsd_;
};
- Void
+ void
process_schema (SemanticGraph::Schema& s,
SemanticGraph::Schema& root,
SemanticGraph::Schema& xsd,
TypeSchemaMap& tsm,
FileSet& file_set,
+ bool fat_type_file,
Transformations::SchemaPerTypeTranslator& trans)
{
using namespace SemanticGraph;
@@ -141,7 +136,7 @@ namespace XSDFrontend
//
if (!tn)
{
- for (NarrowString::Iterator i (base.begin ()), e (base.end ());
+ for (NarrowString::iterator i (base.begin ()), e (base.end ());
i != e; ++i)
{
if (*i == '/' || *i == '\\')
@@ -153,7 +148,7 @@ namespace XSDFrontend
//
NarrowString file_name (base);
- for (UnsignedLong i (1);
+ for (unsigned long i (1);
file_set.find (file_name) != file_set.end ();
++i)
{
@@ -167,11 +162,7 @@ namespace XSDFrontend
try
{
-#if !defined(BOOST_FILESYSTEM_VERSION) || BOOST_FILESYSTEM_VERSION == 2
path = Path (file_name);
-#else
- path = Path (file_name.c_str());
-#endif
}
catch (InvalidPath const&)
{
@@ -184,7 +175,7 @@ namespace XSDFrontend
throw Failed ();
}
}
- catch (String::NonRepresentable const&)
+ catch (NonRepresentable const&)
{
wcerr << "error: '" << wbase << "' cannot be represented as a "
<< "narrow string" << endl;
@@ -195,6 +186,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);
@@ -202,11 +195,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;
@@ -219,7 +244,7 @@ namespace XSDFrontend
{
Type (SemanticGraph::Schema& schema,
SemanticGraph::Schema& root,
- Char const* by_value_key,
+ char const* by_value_key,
TypeSchemaMap& tsm)
: schema_ (schema),
root_ (root),
@@ -229,7 +254,7 @@ namespace XSDFrontend
*this >> names_ >> *this;
}
- virtual Void
+ virtual void
traverse (SemanticGraph::List& l)
{
// Treat item type as base type since it is impossible
@@ -239,7 +264,7 @@ namespace XSDFrontend
set_dep (t, false);
}
- virtual Void
+ virtual void
traverse (SemanticGraph::Complex& c)
{
if (c.inherits_p ())
@@ -248,26 +273,26 @@ namespace XSDFrontend
Traversal::Complex::names (c);
}
- virtual Void
+ virtual void
traverse (SemanticGraph::Member& m)
{
SemanticGraph::Type& t (m.type ());
- Boolean weak (
+ bool weak (
by_value_key_ == 0 ||
!t.context ().count (by_value_key_) ||
- !t.context ().get<Boolean> (by_value_key_));
+ !t.context ().get<bool> (by_value_key_));
set_dep (t, weak);
}
private:
- Void
- set_dep (SemanticGraph::Type& t, Boolean weak)
+ void
+ set_dep (SemanticGraph::Type& t, bool weak)
{
using namespace SemanticGraph;
- TypeSchemaMap::Iterator i (tsm_.find (&t));
+ TypeSchemaMap::iterator i (tsm_.find (&t));
// If a type is not present in the map then it must be
// a built-in type.
@@ -301,9 +326,9 @@ namespace XSDFrontend
private:
SemanticGraph::Schema& schema_;
SemanticGraph::Schema& root_;
- Char const* by_value_key_;
+ char const* by_value_key_;
TypeSchemaMap& tsm_;
- Containers::Set<SemanticGraph::Type*> type_set_;
+ std::set<SemanticGraph::Type*> type_set_;
Traversal::Names names_;
};
@@ -312,8 +337,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,
+ bool fat,
+ char const* key)
+ : fat_type_file_ (fat), by_value_key_ (key), trans_ (trans)
{
}
@@ -344,8 +371,10 @@ namespace XSDFrontend
//
FileSet file_set;
- for (Schemas::Iterator i (schemas.begin ()); i != schemas.end (); ++i)
+ for (Schemas::iterator i (schemas.begin ()); i != schemas.end (); ++i)
{
+ // This path was already normalized by the parser.
+ //
SemanticGraph::Path const& path (
(*i)->context ().get<SemanticGraph::Path> ("absolute-path"));
@@ -353,31 +382,22 @@ namespace XSDFrontend
//
NarrowString abs_path;
-#if !defined(BOOST_FILESYSTEM_VERSION) || BOOST_FILESYSTEM_VERSION == 2
// Try to use the portable representation of the path. If that
// fails, fall back to the native representation.
//
try
{
- abs_path = path.string ();
+ abs_path = path.posix_string ();
}
catch (SemanticGraph::InvalidPath const&)
{
- abs_path = path.native_file_string ();
+ abs_path = path.string ();
}
-#else
- // The new ABI does not have a fallback native representation
- abs_path = path.string ();
-#endif
NarrowString tf (trans_.translate_schema (abs_path));
-#if !defined(BOOST_FILESYSTEM_VERSION) || BOOST_FILESYSTEM_VERSION == 2
- NarrowString file (tf ? tf : path.leaf ());
-#else
- NarrowString file (tf ? tf : path.filename ().string());
-#endif
+ NarrowString file (tf ? tf : path.leaf ().string ());
- Size p (file.rfind ('.'));
+ size_t p (file.rfind ('.'));
NarrowString ext (
p != NarrowString::npos ? NarrowString (file, p) : "");
@@ -388,7 +408,7 @@ namespace XSDFrontend
//
NarrowString new_name (base);
- for (UnsignedLong n (1);
+ for (unsigned long n (1);
file_set.find (new_name) != file_set.end ();
++n)
{
@@ -402,11 +422,7 @@ namespace XSDFrontend
try
{
-#if !defined(BOOST_FILESYSTEM_VERSION) || BOOST_FILESYSTEM_VERSION == 2
(*i)->context ().set ("renamed", SemanticGraph::Path (new_name));
-#else
- (*i)->context ().set ("renamed", SemanticGraph::Path (new_name.c_str()));
-#endif
}
catch (SemanticGraph::InvalidPath const&)
{
@@ -424,9 +440,9 @@ namespace XSDFrontend
//
TypeSchemaMap tsm;
- for (Schemas::Iterator i (schemas.begin ()); i != schemas.end (); ++i)
+ 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;
@@ -434,7 +450,7 @@ namespace XSDFrontend
// Establish include/import dependencies. While at it add the
// new schemas to the list which we will return.
//
- for (TypeSchemaMap::Iterator i (tsm.begin ()); i != tsm.end (); ++i)
+ for (TypeSchemaMap::iterator i (tsm.begin ()); i != tsm.end (); ++i)
{
SemanticGraph::Schema& s (*i->second);
Type t (s, root, by_value_key_, tsm);
diff --git a/libxsd-frontend/xsd-frontend/transformations/schema-per-type.hxx b/libxsd-frontend/xsd-frontend/transformations/schema-per-type.hxx
index 89b6d83..8b6a69e 100644
--- a/libxsd-frontend/xsd-frontend/transformations/schema-per-type.hxx
+++ b/libxsd-frontend/xsd-frontend/transformations/schema-per-type.hxx
@@ -1,13 +1,13 @@
// file : xsd-frontend/transformations/schema-per-type.hxx
-// author : Boris Kolpackov <boris@codesynthesis.com>
-// copyright : Copyright (c) 2006-2010 Code Synthesis Tools CC
+// copyright : Copyright (c) 2006-2014 Code Synthesis Tools CC
// license : GNU GPL v2 + exceptions; see accompanying LICENSE file
#ifndef XSD_FRONTEND_TRANSFORMATIONS_SCHEMA_PER_TYPE_HXX
#define XSD_FRONTEND_TRANSFORMATIONS_SCHEMA_PER_TYPE_HXX
-#include <cult/types.hxx>
-#include <cult/containers/vector.hxx>
+#include <vector>
+
+#include <xsd-frontend/types.hxx>
#include <xsd-frontend/semantic-graph/elements.hxx> // Path
#include <xsd-frontend/semantic-graph/schema.hxx>
@@ -16,8 +16,6 @@ namespace XSDFrontend
{
namespace Transformations
{
- using namespace Cult::Types;
-
class SchemaPerTypeTranslator
{
public:
@@ -27,8 +25,8 @@ namespace XSDFrontend
// The following two functions should return empty string if
// there is no match.
//
- virtual WideString
- translate_type (WideString const& ns, WideString const& name) = 0;
+ virtual String
+ translate_type (String const& ns, String const& name) = 0;
virtual NarrowString
translate_schema (NarrowString const& abs_path) = 0;
@@ -46,13 +44,16 @@ 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&,
+ bool fat_type_file,
+ char const* by_value_key = 0);
- Cult::Containers::Vector<SemanticGraph::Schema*>
+ std::vector<SemanticGraph::Schema*>
transform (SemanticGraph::Schema&);
private:
- Char const* by_value_key_;
+ bool fat_type_file_;
+ char const* by_value_key_;
SchemaPerTypeTranslator& trans_;
};
}
diff --git a/libxsd-frontend/xsd-frontend/transformations/simplifier.cxx b/libxsd-frontend/xsd-frontend/transformations/simplifier.cxx
index 2ccaed2..9372a4a 100644
--- a/libxsd-frontend/xsd-frontend/transformations/simplifier.cxx
+++ b/libxsd-frontend/xsd-frontend/transformations/simplifier.cxx
@@ -1,19 +1,14 @@
// file : xsd-frontend/transformations/simplifier.cxx
-// author : Boris Kolpackov <boris@codesynthesis.com>
-// copyright : Copyright (c) 2006-2010 Code Synthesis Tools CC
+// copyright : Copyright (c) 2006-2014 Code Synthesis Tools CC
// license : GNU GPL v2 + exceptions; see accompanying LICENSE file
-#include <xsd-frontend/transformations/simplifier.hxx>
-
#include <xsd-frontend/semantic-graph.hxx>
#include <xsd-frontend/traversal.hxx>
-#include <cult/containers/vector.hxx>
+#include <xsd-frontend/transformations/simplifier.hxx>
namespace XSDFrontend
{
- using namespace Cult;
-
namespace
{
struct Compositor: Traversal::All,
@@ -25,7 +20,7 @@ namespace XSDFrontend
{
}
- virtual Void
+ virtual void
traverse (SemanticGraph::All& a)
{
// The all compositor cannot contain compositors.
@@ -34,7 +29,7 @@ namespace XSDFrontend
remove (a);
}
- virtual Void
+ virtual void
traverse (SemanticGraph::Choice& c)
{
// Do the depth-first traversal so that we take into account
@@ -54,7 +49,7 @@ namespace XSDFrontend
remove (c);
}
- virtual Void
+ virtual void
traverse (SemanticGraph::Sequence& s)
{
// Do the depth-first traversal so that we take into account
@@ -73,7 +68,7 @@ namespace XSDFrontend
}
private:
- virtual Void
+ virtual void
remove (SemanticGraph::Compositor& c)
{
using SemanticGraph::Node;
@@ -106,7 +101,7 @@ namespace XSDFrontend
//
struct Type: Traversal::Complex
{
- virtual Void
+ virtual void
traverse (SemanticGraph::Complex& c)
{
if (c.contains_compositor_p ())
@@ -119,7 +114,7 @@ namespace XSDFrontend
//
struct Uses: Traversal::Uses
{
- virtual Void
+ virtual void
traverse (Type& u)
{
SemanticGraph::Schema& s (u.schema ());
@@ -135,7 +130,7 @@ namespace XSDFrontend
namespace Transformations
{
- Void Simplifier::
+ void Simplifier::
transform (SemanticGraph::Schema& s, SemanticGraph::Path const&)
{
Traversal::Schema schema;
diff --git a/libxsd-frontend/xsd-frontend/transformations/simplifier.hxx b/libxsd-frontend/xsd-frontend/transformations/simplifier.hxx
index 676c166..674ee45 100644
--- a/libxsd-frontend/xsd-frontend/transformations/simplifier.hxx
+++ b/libxsd-frontend/xsd-frontend/transformations/simplifier.hxx
@@ -1,12 +1,11 @@
// file : xsd-frontend/transformations/simplifier.hxx
-// author : Boris Kolpackov <boris@codesynthesis.com>
-// copyright : Copyright (c) 2006-2010 Code Synthesis Tools CC
+// copyright : Copyright (c) 2006-2014 Code Synthesis Tools CC
// license : GNU GPL v2 + exceptions; see accompanying LICENSE file
#ifndef XSD_FRONTEND_TRANSFORMATIONS_SIMPLIFIER_HXX
#define XSD_FRONTEND_TRANSFORMATIONS_SIMPLIFIER_HXX
-#include <cult/types.hxx>
+#include <xsd-frontend/types.hxx>
#include <xsd-frontend/semantic-graph/elements.hxx> // Path
#include <xsd-frontend/semantic-graph/schema.hxx>
@@ -15,8 +14,6 @@ namespace XSDFrontend
{
namespace Transformations
{
- using namespace Cult::Types;
-
// This transformation performs various schema simplifications
// (e.g., removing empty compositors, etc). This transformation
// assumes that there are no anonymous types.
@@ -24,7 +21,7 @@ namespace XSDFrontend
class Simplifier
{
public:
- Void
+ void
transform (SemanticGraph::Schema&, SemanticGraph::Path const&);
};
}