From f5b85ddc9a0e3ac4bb8a200d2ab1a05d5ca9f41b Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Sun, 28 Mar 2010 18:58:03 +0200 Subject: Validate facets in C++/Hybrid enum parser/serializer implementations --- xsde/cxx/hybrid/parser-header.cxx | 29 +++++++-- xsde/cxx/hybrid/parser-source.cxx | 113 +++++++++++++++++++--------------- xsde/cxx/hybrid/serializer-source.cxx | 28 ++++++++- 3 files changed, 114 insertions(+), 56 deletions(-) (limited to 'xsde/cxx') diff --git a/xsde/cxx/hybrid/parser-header.cxx b/xsde/cxx/hybrid/parser-header.cxx index d3ba4b4..a09375a 100644 --- a/xsde/cxx/hybrid/parser-header.cxx +++ b/xsde/cxx/hybrid/parser-header.cxx @@ -113,17 +113,38 @@ namespace CXX // pre // - os << "virtual void" << endl - << "pre ();" - << endl; + if (!fl || !base_enum) + os << "virtual void" << endl + << "pre ();" + << endl; - // _characters + // _pre // if (!base_enum) os << "virtual void" << endl + << "_pre ();" + << endl; + + if (!base_enum) + { + // _characters + // + os << "virtual void" << endl << "_characters (const " << string_type << "&);" << endl; + // _post + // + if (!options.value () && + !options.value ()) + { + os << "virtual void" << endl + << "_post ();" + << endl; + } + } + + // post // String const& ret (pret_type (e)); diff --git a/xsde/cxx/hybrid/parser-source.cxx b/xsde/cxx/hybrid/parser-source.cxx index a1f28e2..7d8c434 100644 --- a/xsde/cxx/hybrid/parser-source.cxx +++ b/xsde/cxx/hybrid/parser-source.cxx @@ -245,27 +245,13 @@ namespace CXX // pre // - os << "void " << name << "::" << endl - << "pre ()" - << "{"; - - if (fl) + if (!fl || !base_enum) { - if (base_enum) - { - // Our base is also fixed-length so call its pre() - // - if (tiein) - os << "this->base_impl_."; - else - os << epimpl (b) << "::"; //@@ fq-name. - - os << "pre ();"; - } + os << "void " << name << "::" << endl + << "pre ()" + << "{"; - // Clear the string buffer. - // - if (!base_enum) + if (fl) { if (stl) os << "this->" << state << ".str_.clear ();"; @@ -281,25 +267,34 @@ namespace CXX } } } - } - else - { - if (exceptions) - os << "this->" << pre_impl_name (e) << " (new " << type << ");"; else - os << type << "* x = new " << type << ";" - << "if (x)" << endl - << "this->" << pre_impl_name (e) << " (x);" - << "else" << endl - << "this->_sys_error (::xsde::cxx::sys_error::no_memory);"; - } + { + if (exceptions) + os << "this->" << pre_impl_name (e) << " (new " << type << ");"; + else + os << type << "* x = new " << type << ";" + << "if (x)" << endl + << "this->" << pre_impl_name (e) << " (x);" + << "else" << endl + << "this->_sys_error (::xsde::cxx::sys_error::no_memory);"; + } - os << "}"; + os << "}"; + } - // _characters - // if (!base_enum) { + // _pre + // + os << "void " << name << "::" << endl + << "_pre ()" + << "{" + // Override it to cut off our base. + // + << "}"; + + // _characters + // os << "void " << name << "::" << endl << "_characters (const " << string_type << "& s)" << "{"; @@ -319,6 +314,31 @@ namespace CXX } os << "}"; + + // _post + // + if (!options.value () && + !options.value ()) + { + // Do facet validation. + // + os << "void " << name << "::" << endl + << "_post ()" + << "{" + << "::xsde::cxx::parser::validating::string_common::" << + "validate_facets (" << endl; + + if (stl) + os << "this->" << state << ".str_.c_str ()," << endl + << "this->" << state << ".str_.size ()," << endl; + else + os << "this->" << state << ".str_.data ()," << endl + << "this->" << state << ".str_.size ()," << endl; + + os << "this->_facets ()," << endl + << "this->_context ());" + << "}"; + } } // post @@ -371,10 +391,6 @@ namespace CXX os << ";"; } - - // - // @@ TODO: check enumerators (switch) - // } else { @@ -388,19 +404,6 @@ namespace CXX names (e, names_, 0, 0, 0, &Enumeration::comma); - - /* - // @@ Cannot do error checking in post. - - if (!options.value () && - !options.value ()) - { - os << "else" << endl - << "this->_schema_error (" << - "::xsde::cxx::schema_error::invalid_enumeration_value);"; - } - */ - os << endl; if (fl) @@ -1787,6 +1790,16 @@ namespace CXX Void generate_parser_source (Context& ctx) { + if (ctx.enum_ && + !ctx.options.value () && + !ctx.options.value ()) + { + // We need this functionality for enum mapping. + // + ctx.os << "#include " << endl + << endl; + } + { // Emit "weak" header includes for the object model types. // Otherwise we cannot delete the objects of forward-declared diff --git a/xsde/cxx/hybrid/serializer-source.cxx b/xsde/cxx/hybrid/serializer-source.cxx index 87004fa..b15a3bf 100644 --- a/xsde/cxx/hybrid/serializer-source.cxx +++ b/xsde/cxx/hybrid/serializer-source.cxx @@ -204,8 +204,22 @@ namespace CXX os << "void " << name << "::" << endl << "_serialize_content ()" - << "{" - << "this->_characters (this->" << state << "->" << + << "{"; + + if (!options.value () && + !options.value ()) + { + // Do facet validation. + // + os << "::xsde::cxx::serializer::validating::string_common::" << + "validate_facets (" << endl + << "this->" << state << "->" << string << " ()," << endl + << "this->_facets ()," << endl + << "this->_context ());" + << endl; + } + + os << "this->_characters (this->" << state << "->" << string << " ());" << "}"; } @@ -1377,6 +1391,16 @@ namespace CXX ctx.os << "#include " << endl << endl; + if (ctx.enum_ && + !ctx.options.value () && + !ctx.options.value ()) + { + // We need this functionality for enum mapping. + // + ctx.os << "#include " << endl + << endl; + } + Traversal::Schema schema; Traversal::Sources sources; -- cgit v1.1