From af9c4746276242ded99b786f17bc48ec100f2ea2 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 22 Apr 2010 22:04:03 +0200 Subject: Name anonymous union members They might be used via the new enum synthesis feature. --- xsd-frontend/transformations/anonymous.cxx | 86 ++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) diff --git a/xsd-frontend/transformations/anonymous.cxx b/xsd-frontend/transformations/anonymous.cxx index 6998176..65d8e76 100644 --- a/xsd-frontend/transformations/anonymous.cxx +++ b/xsd-frontend/transformations/anonymous.cxx @@ -239,6 +239,7 @@ namespace XSDFrontend // // struct Type: Traversal::List, + Traversal::Union, Traversal::Complex, protected virtual Context { @@ -326,6 +327,91 @@ namespace XSDFrontend } virtual Void + traverse (SemanticGraph::Union& u) + { + String file_str; + + for (SemanticGraph::Union::ArgumentedIterator i ( + u.argumented_begin ()); i != u.argumented_end (); ++i) + { + SemanticGraph::Type& t (i->type ()); + + if (!t.named_p () && + !t.is_a () && + !t.is_a ()) + { + try + { + // Run the name through the translation service. + // + + if (!file_str) + { + SemanticGraph::Path file (path (u)); + + // Try to use the portable representation of the path. If + // that fails, fall back to the native representation. + // + try + { + file_str = file.string (); + } + catch (SemanticGraph::InvalidPath const&) + { + file_str = file.native_file_string (); + } + } + + String name ( + trans.translate ( + file_str, ns->name (), u.name () + L"_member", xpath (u))); + + // Make sure the name is unique. + // + UnsignedLong n (1); + String escaped (name); + + while (conflict (escaped)) + { + std::wostringstream os; + os << n++; + escaped = name + os.str (); + } + + t.context ().set ("anonymous", true); + schema.new_edge (*ns, t, escaped); + } + catch (UnstableConflict const& ex) + { + SemanticGraph::Type& t (ex.type ()); + + wcerr << u.file () << ":" << u.line () << ":" << u.column () + << ": error: union type name '" << xpath (u) << "' " + << "creates an unstable conflict when used as a base " + << "for the member type name" + << endl; + + wcerr << t.file () << ":" << t.line () << ":" << t.column () + << ": info: conflicting type is defined here" << endl; + + wcerr << u.file () << ":" << u.line () << ":" << u.column () + << ": info: " + << "use --anonymous-regex to resolve this conflict" + << endl; + + wcerr << u.file () << ":" << u.line () << ":" << u.column () + << ": info: " + << "and don't forget to pass the same option when " + << "translating '" << u.file ().leaf () << "' and all " + << "the schemas that refer to it" << endl; + + failed = true; + } + } + } + } + + virtual Void traverse (SemanticGraph::Complex& c) { if (!c.inherits_p ()) -- cgit v1.1