From 973221821ac8e20da4eadbf4ad552f686b1ace48 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Fri, 22 Jun 2012 15:07:35 +0200 Subject: Get rid of dependency on libcult --- xsde/xsde.cxx | 143 +++++++++++++++++++++++++++------------------------------- 1 file changed, 67 insertions(+), 76 deletions(-) (limited to 'xsde/xsde.cxx') diff --git a/xsde/xsde.cxx b/xsde/xsde.cxx index 9d05a70..566ce61 100644 --- a/xsde/xsde.cxx +++ b/xsde/xsde.cxx @@ -3,6 +3,8 @@ // copyright : Copyright (c) 2005-2011 Code Synthesis Tools CC // license : GNU GPL v2 + exceptions; see accompanying LICENSE file +#include +#include #include #include // std::auto_ptr #include // std::size_t @@ -12,13 +14,6 @@ #include -#include - -#include - -#include -#include - #include #include #include @@ -44,8 +39,6 @@ #include "../libxsde/xsde/cxx/version.hxx" -using namespace Cult::Types; - namespace SemanticGraph = XSDFrontend::SemanticGraph; namespace Transformations = XSDFrontend::Transformations; @@ -59,24 +52,24 @@ struct LocationTranslator: XSDFrontend::LocationTranslator LocationTranslator (NarrowStrings const& map, NarrowStrings const& regex, - Boolean trace); + bool trace); virtual NarrowString translate (NarrowString const&); private: - typedef Cult::Containers::Map Map; + typedef map Map; typedef cutl::re::regexsub Regex; typedef cutl::re::format RegexFormat; - typedef Cult::Containers::Vector RegexVector; + typedef vector RegexVector; - typedef Cult::Containers::Map Cache; + typedef map Cache; Map map_; RegexVector regex_; Cache cache_; - Boolean trace_; + bool trace_; }; // @@ -85,21 +78,21 @@ struct AnonymousNameTranslator: Transformations::AnonymousNameTranslator { struct Failed {}; - AnonymousNameTranslator (NarrowStrings const& regex, Boolean trace); + AnonymousNameTranslator (NarrowStrings const& regex, bool trace); - virtual WideString - translate (WideString const& file, - WideString const& ns, - WideString const& name, - WideString const& xpath); + virtual String + translate (String const& file, + String const& ns, + String const& name, + String const& xpath); private: typedef cutl::re::wregexsub Regex; typedef cutl::re::wformat RegexFormat; - typedef Cult::Containers::Vector RegexVector; + typedef vector RegexVector; RegexVector regex_; - Boolean trace_; + bool trace_; }; @@ -110,12 +103,12 @@ struct SchemaPerTypeTranslator: Transformations::SchemaPerTypeTranslator struct Failed {}; SchemaPerTypeTranslator (NarrowStrings const& type_regex, - Boolean type_trace, + bool type_trace, NarrowStrings const& schema_regex, - Boolean schema_trace); + bool schema_trace); - virtual WideString - translate_type (WideString const& ns, WideString const& name); + virtual String + translate_type (String const& ns, String const& name); virtual NarrowString translate_schema (NarrowString const& file); @@ -123,30 +116,28 @@ struct SchemaPerTypeTranslator: Transformations::SchemaPerTypeTranslator private: typedef cutl::re::wregexsub TypeRegex; typedef cutl::re::wformat TypeRegexFormat; - typedef Cult::Containers::Vector TypeRegexVector; + typedef vector TypeRegexVector; TypeRegexVector type_regex_; - Boolean type_trace_; + bool type_trace_; typedef cutl::re::regexsub SchemaRegex; typedef cutl::re::format SchemaRegexFormat; - typedef Cult::Containers::Vector SchemaRegexVector; + typedef vector SchemaRegexVector; SchemaRegexVector schema_regex_; - Boolean schema_trace_; + bool schema_trace_; }; // Expand the \n escape sequence. // -Void +void expand_nl (NarrowString& s); -Int -main (Int argc, Char* argv[]) +int +main (int argc, char* argv[]) { - std::wostream& e (wcerr); - - Cult::Trace::Log::instance ().level (0); + wostream& e (wcerr); try { @@ -159,7 +150,7 @@ main (Int argc, Char* argv[]) if (help_ops.version () || cmd == "version") { - std::wostream& o (wcout); + wostream& o (wcout); o << "CodeSynthesis XSD/e XML Schema to C++ compiler " << "for embedded systems " << XSDE_STR_VERSION << endl @@ -191,7 +182,7 @@ main (Int argc, Char* argv[]) if (help_ops.help () || cmd == "help") { - std::wostream& o (wcout); + wostream& o (wcout); if (cmd == "help" && args.more ()) { @@ -305,7 +296,7 @@ main (Int argc, Char* argv[]) disabled_w.insert (*i); } - Boolean disabled_w_all (disabled_w.find ("all") != disabled_w.end ()); + bool disabled_w_all (disabled_w.find ("all") != disabled_w.end ()); // Collect all the files to compile in a vector. // @@ -320,7 +311,7 @@ main (Int argc, Char* argv[]) return 1; } - Boolean fpt (common_ops.file_per_type ()); + bool fpt (common_ops.file_per_type ()); // Generate/extern XML Schema checks. // @@ -396,17 +387,17 @@ main (Int argc, Char* argv[]) common_ops.anonymous_regex (), common_ops.anonymous_regex_trace ()); - Boolean gen_hybrid (cmd == "cxx-hybrid"); + bool gen_hybrid (cmd == "cxx-hybrid"); - Boolean gen_parser ( + bool gen_parser ( cmd == "cxx-parser" || (gen_hybrid && h_ops->generate_parser ())); - Boolean gen_serializer ( + bool gen_serializer ( cmd == "cxx-serializer" || (gen_hybrid && h_ops->generate_serializer ())); - Boolean poly_aggr ( + bool poly_aggr ( gen_hybrid && h_ops->generate_polymorphic () && h_ops->generate_aggregate ()); @@ -465,13 +456,13 @@ main (Int argc, Char* argv[]) // define derived polymorphic types, except for the fake XML // Schema file. // - Boolean multi (poly_aggr && !gen_xml_schema); + bool multi (poly_aggr && !gen_xml_schema); if (multi) { paths.push_back (tu); - Size ai (0); + size_t ai (0); try { for (; ai < files.size (); ++ai) @@ -815,7 +806,7 @@ main (Int argc, Char* argv[]) // SemanticGraph::Paths paths; - for (Size i (0); i < files.size (); ++i) + for (size_t i (0); i < files.size (); ++i) { try { @@ -911,7 +902,7 @@ main (Int argc, Char* argv[]) // Rearrange the graph so that each type is in a seperate // schema file. // - typedef std::vector Schemas; + typedef vector Schemas; SchemaPerTypeTranslator type_translator ( common_ops.type_file_regex (), @@ -1079,7 +1070,7 @@ main (Int argc, Char* argv[]) OutputFileStream ofs; SemanticGraph::Path path (fl); - ofs.open (fl, std::ios_base::out); + ofs.open (fl, ios_base::out); if (!ofs.is_open ()) { @@ -1096,7 +1087,7 @@ main (Int argc, Char* argv[]) ofs << p; } - for (FileList::Iterator i (file_list.begin ()), e (file_list.end ()); + for (FileList::iterator i (file_list.begin ()), e (file_list.end ()); i != e;) { ofs << *i; @@ -1172,7 +1163,7 @@ main (Int argc, Char* argv[]) LocationTranslator:: LocationTranslator (NarrowStrings const& map, NarrowStrings const& regex, - Boolean trace) + bool trace) : trace_ (trace) { // Map. @@ -1181,7 +1172,7 @@ LocationTranslator (NarrowStrings const& map, { // Split the string in two parts at the last '='. // - Size pos (i->rfind ('=')); + size_t pos (i->rfind ('=')); if (pos == NarrowString::npos) { @@ -1218,14 +1209,14 @@ translate (NarrowString const& l) { // First check the cache. // - Cache::ConstIterator ci (cache_.find (l)); + Cache::const_iterator ci (cache_.find (l)); if (ci != cache_.end ()) return ci->second; // Then check the direct map. // - Map::ConstIterator mi (map_.find (l)); + Map::const_iterator mi (map_.find (l)); if (mi != map_.end ()) { @@ -1238,7 +1229,7 @@ translate (NarrowString const& l) if (trace_) wcerr << "location: '" << l.c_str () << "'" << endl; - for (RegexVector::ReverseIterator i (regex_.rbegin ()); + for (RegexVector::reverse_iterator i (regex_.rbegin ()); i != regex_.rend (); ++i) { if (trace_) @@ -1269,14 +1260,14 @@ translate (NarrowString const& l) // AnonymousNameTranslator:: -AnonymousNameTranslator (NarrowStrings const& regex, Boolean trace) +AnonymousNameTranslator (NarrowStrings const& regex, bool trace) : trace_ (trace) { for (NarrowStrings::const_iterator i (regex.begin ()); i != regex.end (); ++i) { try { - regex_.push_back (Regex (WideString (*i))); + regex_.push_back (Regex (String (*i))); } catch (RegexFormat const& e) { @@ -1288,18 +1279,18 @@ AnonymousNameTranslator (NarrowStrings const& regex, Boolean trace) } } -WideString AnonymousNameTranslator:: -translate (WideString const& file, - WideString const& ns, - WideString const& name, - WideString const& xpath) +String AnonymousNameTranslator:: +translate (String const& file, + String const& ns, + String const& name, + String const& xpath) { - WideString s (file + L' ' + ns + L' ' + xpath); + String s (file + L' ' + ns + L' ' + xpath); if (trace_) wcerr << "anonymous type: '" << s << "'" << endl; - for (RegexVector::ReverseIterator i (regex_.rbegin ()); + for (RegexVector::reverse_iterator i (regex_.rbegin ()); i != regex_.rend (); ++i) { if (trace_) @@ -1307,7 +1298,7 @@ translate (WideString const& file, if (i->match (s)) { - WideString r (i->replace (s)); + String r (i->replace (s)); if (trace_) wcerr << "'" << r << "' : +" << endl; @@ -1329,9 +1320,9 @@ translate (WideString const& file, SchemaPerTypeTranslator:: SchemaPerTypeTranslator (NarrowStrings const& type_regex, - Boolean type_trace, + bool type_trace, NarrowStrings const& schema_regex, - Boolean schema_trace) + bool schema_trace) : type_trace_ (type_trace), schema_trace_ (schema_trace) { for (NarrowStrings::const_iterator i (type_regex.begin ()); @@ -1339,7 +1330,7 @@ SchemaPerTypeTranslator (NarrowStrings const& type_regex, { try { - type_regex_.push_back (TypeRegex (WideString (*i))); + type_regex_.push_back (TypeRegex (String (*i))); } catch (TypeRegexFormat const& e) { @@ -1367,15 +1358,15 @@ SchemaPerTypeTranslator (NarrowStrings const& type_regex, } } -WideString SchemaPerTypeTranslator:: -translate_type (WideString const& ns, WideString const& name) +String SchemaPerTypeTranslator:: +translate_type (String const& ns, String const& name) { - WideString s (ns + L' ' + name); + String s (ns + L' ' + name); if (type_trace_) wcerr << "type: '" << s << "'" << endl; - for (TypeRegexVector::ReverseIterator i (type_regex_.rbegin ()); + for (TypeRegexVector::reverse_iterator i (type_regex_.rbegin ()); i != type_regex_.rend (); ++i) { if (type_trace_) @@ -1383,7 +1374,7 @@ translate_type (WideString const& ns, WideString const& name) if (i->match (s)) { - WideString r (i->replace (s)); + String r (i->replace (s)); if (type_trace_) wcerr << "'" << r << "' : +" << endl; @@ -1406,7 +1397,7 @@ translate_schema (NarrowString const& file) if (schema_trace_) wcerr << "schema: '" << file.c_str () << "'" << endl; - for (SchemaRegexVector::ReverseIterator i (schema_regex_.rbegin ()); + for (SchemaRegexVector::reverse_iterator i (schema_regex_.rbegin ()); i != schema_regex_.rend (); ++i) { if (schema_trace_) @@ -1433,10 +1424,10 @@ translate_schema (NarrowString const& file) // // -Void +void expand_nl (NarrowString& s) { - for (Size i (0); i < s.size ();) + for (size_t i (0); i < s.size ();) { if (s[i] == '\\' && (i + 1) < s.size () && s[i + 1] == 'n') { -- cgit v1.1