From 2615896faa646e5830abf2c269150e1165c66515 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Fri, 18 Dec 2020 18:48:46 +0300 Subject: Switch to build2 --- xsd/xsd/cxx/tree/tree-forward.cxx | 325 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 325 insertions(+) create mode 100644 xsd/xsd/cxx/tree/tree-forward.cxx (limited to 'xsd/xsd/cxx/tree/tree-forward.cxx') diff --git a/xsd/xsd/cxx/tree/tree-forward.cxx b/xsd/xsd/cxx/tree/tree-forward.cxx new file mode 100644 index 0000000..dfc4f89 --- /dev/null +++ b/xsd/xsd/cxx/tree/tree-forward.cxx @@ -0,0 +1,325 @@ +// file : xsd/cxx/tree/tree-forward.cxx +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include +#include + +#include +#include + +namespace CXX +{ + namespace Tree + { + namespace + { + struct List: Traversal::List, Context + { + List (Context& c) + : Context (c) + { + } + + virtual void + traverse (Type& l) + { + String const& name (ename (l)); + + if (String custom = custom_type (l)) + { + String new_name; + renamed_type (l, new_name); + + if (new_name) + os << "class " << new_name << ";"; + + if (custom == name) + os << "class " << name << ";"; + else + os << "typedef " << custom << " " << name << ";"; + } + else + os << "class " << name << ";"; + } + }; + + struct Union: Traversal::Union, Context + { + Union (Context& c) + : Context (c) + { + } + + virtual void + traverse (Type& u) + { + String const& name (ename (u)); + + if (String custom = custom_type (u)) + { + String new_name; + renamed_type (u, new_name); + + if (new_name) + os << "class " << new_name << ";"; + + if (custom == name) + os << "class " << name << ";"; + else + os << "typedef " << custom << " " << name << ";"; + } + else + os << "class " << name << ";"; + } + }; + + struct Enumeration: Traversal::Enumeration, Context + { + Enumeration (Context& c) + : Context (c) + { + } + + virtual void + traverse (Type& e) + { + String const& name (ename (e)); + + if (String custom = custom_type (e)) + { + String new_name; + renamed_type (e, new_name); + + if (new_name) + os << "class " << new_name << ";"; + + if (custom == name) + os << "class " << name << ";"; + else + os << "typedef " << custom << " " << name << ";"; + } + else + os << "class " << name << ";"; + } + }; + + struct Complex: Traversal::Complex, Context + { + Complex (Context& c) + : Context (c) + { + } + + virtual void + traverse (Type& c) + { + String const& name (ename (c)); + + if (String custom = custom_type (c)) + { + String new_name; + renamed_type (c, new_name); + + if (new_name) + os << "class " << new_name << ";"; + + if (custom == name) + os << "class " << name << ";"; + else + os << "typedef " << custom << " " << name << ";"; + } + else + os << "class " << name << ";"; + } + }; + } + + void + generate_forward (Context& ctx) + { + NarrowString xml_schema (ctx.options.extern_xml_schema ()); + + // Inlcude or Emit fundamental types. + // + if (xml_schema) + { + String name (ctx.hxx_expr->replace (xml_schema)); + + ctx.os << "#include " << ctx.process_include_path (name) << endl + << endl; + } + else + { + if (ctx.char_type == L"char" && ctx.char_encoding != L"custom") + { + ctx.os << "#include " << endl + << endl; + } + + ctx.os << "#include " << endl + << "#include " << endl + << "#include " << endl + << endl; + + if (!ctx.options.suppress_parsing () || + ctx.options.generate_serialization ()) + { + ctx.os << "#include " << endl + << endl; + } + + if (!ctx.options.suppress_parsing () || + ctx.options.generate_serialization ()) + { + ctx.os << "#include " << endl + << endl; + } + + bool element_map (ctx.options.generate_element_map ()); + + if (element_map) + ctx.os << "#include " << endl + << endl; + + // I need to include all the "optional" headers here (instead of + // later in the individual generators for each feature because + // those headers provide implementation for the fundamental types. + // + if (!ctx.options.suppress_parsing ()) + { + ctx.os << "#include " << endl; + + Traversal::Schema schema, xsd; + Traversal::Implies implies; + Traversal::Names names; + Traversal::Namespace ns; + Traversal::Names ns_names; + FundIncludes type (ctx, "parsing"); + + schema >> implies >> xsd >> names >> ns >> ns_names >> type; + + schema.dispatch (ctx.schema_root); + + if (element_map) + ctx.os << "#include " << + endl; + + ctx.os << endl; + } + + if (ctx.options.generate_serialization ()) + { + ctx.os << "#include " << endl + << "#include " << endl; + + Traversal::Schema schema, xsd; + Traversal::Implies implies; + Traversal::Names names; + Traversal::Namespace ns; + Traversal::Names ns_names; + FundIncludes type (ctx, "serialization"); + + schema >> implies >> xsd >> names >> ns >> ns_names >> type; + + schema.dispatch (ctx.schema_root); + + if (element_map) + ctx.os << "#include " << + endl; + + ctx.os << endl; + } + + if (ctx.options.generate_ostream ()) + { + ctx.os << "#include " << endl + << endl; + } + + NarrowStrings const& ist (ctx.options.generate_insertion ()); + if (!ist.empty ()) + { + for (NarrowStrings::const_iterator i (ist.begin ()); i != ist.end (); + ++i) + { + if (*i == "ACE_OutputCDR") + ctx.os << "#include " + << endl; + else if (*i == "XDR") + ctx.os << "#include " + << endl; + } + + ctx.os << "#include " << endl + << endl; + } + + NarrowStrings const& est (ctx.options.generate_extraction ()); + if (!est.empty ()) + { + for (NarrowStrings::const_iterator i (est.begin ()); i != est.end (); + ++i) + { + if (*i == "ACE_InputCDR") + ctx.os << "#include " + << endl; + else if (*i == "XDR") + ctx.os << "#include " + << endl; + } + + ctx.os << "#include " << endl + << endl; + } + + + Traversal::Schema schema, xsd; + Traversal::Implies implies; + Traversal::Names names; + FundamentalNamespace ns (ctx); + + schema >> implies >> xsd >> names >> ns; + + schema.dispatch (ctx.schema_root); + } + + // First emit header includes. + // + if (ctx.options.generate_forward ()) + { + Traversal::Schema schema; + Includes includes (ctx, Includes::forward); + + schema >> includes; + + schema.dispatch (ctx.schema_root); + } + + ctx.os << "// Forward declarations." << endl + << "//" << endl; + + Traversal::Schema schema; + Sources sources; + Traversal::Names names_ns, names; + Namespace ns (ctx); + + List list (ctx); + Union union_ (ctx); + Complex complex (ctx); + Enumeration enumeration (ctx); + + schema >> sources >> schema; + schema >> names_ns >> ns >> names; + + names >> list; + names >> union_; + names >> complex; + names >> enumeration; + + schema.dispatch (ctx.schema_root); + + ctx.os << endl; + } + } +} -- cgit v1.1