diff options
Diffstat (limited to 'xsd/xsd/cxx/parser/validator.cxx')
-rw-r--r-- | xsd/xsd/cxx/parser/validator.cxx | 140 |
1 files changed, 66 insertions, 74 deletions
diff --git a/xsd/xsd/cxx/parser/validator.cxx b/xsd/xsd/cxx/parser/validator.cxx index 19b15c6..da9f8b0 100644 --- a/xsd/xsd/cxx/parser/validator.cxx +++ b/xsd/xsd/cxx/parser/validator.cxx @@ -1,8 +1,10 @@ // file : xsd/cxx/parser/validator.cxx -// author : Boris Kolpackov <boris@codesynthesis.com> -// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// copyright : Copyright (c) 2005-2014 Code Synthesis Tools CC // license : GNU GPL v2 + exceptions; see accompanying LICENSE file +#include <set> +#include <iostream> + #include <cxx/parser/validator.hxx> #include <xsd-frontend/semantic-graph.hxx> @@ -10,9 +12,7 @@ #include <cxx/parser/elements.hxx> -#include <iostream> - -using std::wcerr; +using namespace std; namespace CXX { @@ -25,10 +25,10 @@ namespace CXX public: ValidationContext (SemanticGraph::Schema& root, SemanticGraph::Path const& path, - CLI::Options const& options, + Parser::options const& ops, const WarningSet& disabled_warnings, - Boolean& valid_) - : Context (std::wcerr, root, path, options, 0, 0, 0, 0), + bool& valid_) + : Context (std::wcerr, root, path, ops, 0, 0, 0, 0), disabled_warnings_ (disabled_warnings), disabled_warnings_all_ (false), valid (valid_), @@ -38,8 +38,8 @@ namespace CXX } public: - Boolean - is_disabled (Char const* w) + bool + is_disabled (char const* w) { return disabled_warnings_all_ || disabled_warnings_.find (w) != disabled_warnings_.end (); @@ -74,10 +74,10 @@ namespace CXX protected: const WarningSet& disabled_warnings_; - Boolean disabled_warnings_all_; - Boolean& valid; - Boolean& subst_group_warning_issued; - Boolean subst_group_warning_issued_; + bool disabled_warnings_all_; + bool& valid; + bool& subst_group_warning_issued; + bool subst_group_warning_issued_; }; // @@ -98,20 +98,20 @@ namespace CXX { } - virtual Void + virtual void traverse (SemanticGraph::Element& e) { if (skip (e)) return; using SemanticGraph::Any; - Boolean q (e.qualified_p ()); + bool q (e.qualified_p ()); String ns (q ? e.namespace_ ().name () : ""); for (Any::NamespaceIterator i (any_.namespace_begin ()); i != any_.namespace_end (); ++i) { - Boolean failed (false); + bool failed (false); if (*i == L"##any") { @@ -184,14 +184,14 @@ namespace CXX { } - virtual Void + virtual void post (Type& c) { // Go down the inheritance hierarchy. // if (down_) { - Boolean up = up_; + bool up = up_; up_ = false; if (c.inherits_p ()) @@ -204,7 +204,7 @@ namespace CXX // if (up_) { - Boolean down = down_; + bool down = down_; down_ = false; for (Type::BegetsIterator i (c.begets_begin ()); @@ -218,10 +218,10 @@ namespace CXX } private: - Boolean up_, down_; + bool up_, down_; }; - virtual Void + virtual void traverse (SemanticGraph::Any& a) { using SemanticGraph::Compositor; @@ -273,7 +273,7 @@ namespace CXX } } - virtual Void + virtual void traverse (SemanticGraph::Complex& c) { using SemanticGraph::Schema; @@ -319,7 +319,7 @@ namespace CXX Complex::traverse (c); } - virtual Void + virtual void traverse (SemanticGraph::Type& t) { if (t.named_p ()) @@ -328,14 +328,14 @@ namespace CXX } } - virtual Void + virtual void traverse (SemanticGraph::Element& e) { if (is_disabled ("P002")) return; if (e.substitutes_p () && - !options.value<CLI::generate_polymorphic> () && + !options.generate_polymorphic () && !subst_group_warning_issued) { subst_group_warning_issued = true; @@ -352,7 +352,7 @@ namespace CXX // Return true if root sources s. // - Boolean + bool sources_p (SemanticGraph::Schema& root, SemanticGraph::Schema& s) { using SemanticGraph::Schema; @@ -372,9 +372,9 @@ namespace CXX } private: - Containers::Set<String> types_; + set<String> types_; - Traversal::Sources sources_; + Sources sources_; Traversal::Names schema_names_; Traversal::Namespace ns_; @@ -405,7 +405,7 @@ namespace CXX *this >> names_; } - Boolean + bool traverse_common (SemanticGraph::Member& m) { SemanticGraph::Type& t (m.type ()); @@ -434,7 +434,7 @@ namespace CXX << "automatically name them" << endl; - if (!options.value<CLI::show_anonymous> ()) + if (!options.show_anonymous ()) wcerr << t.file () << ": info: use --show-anonymous option to see these " << "types" << endl; @@ -446,14 +446,14 @@ namespace CXX return false; } - virtual Void + virtual void traverse (SemanticGraph::Element& e) { if (skip (e)) return; if (traverse_common (e)) { - if (options.value<CLI::show_anonymous> ()) + if (options.show_anonymous ()) { wcerr << e.file () << ":" << e.line () << ":" << e.column () << ": error: element '" << xpath (e) << "' " @@ -464,12 +464,12 @@ namespace CXX Traversal::Element::traverse (e); } - virtual Void + virtual void traverse (SemanticGraph::Attribute& a) { if (traverse_common (a)) { - if (options.value<CLI::show_anonymous> ()) + if (options.show_anonymous ()) { wcerr << a.file () << ":" << a.line () << ":" << a.column () << ": error: attribute '" << xpath (a) << "' " @@ -481,11 +481,11 @@ namespace CXX } private: - Boolean anonymous_error_issued_; + bool anonymous_error_issued_; - Containers::Set<String> types_; + set<String> types_; - Traversal::Sources sources_; + Sources sources_; Traversal::Names schema_names_; Traversal::Namespace ns_; @@ -500,22 +500,22 @@ namespace CXX { } - virtual Void + virtual void traverse (Type& e) { if (!valid) return; - if (options.value<CLI::root_element_first> ()) + if (options.root_element_first ()) { if (element_ == 0) element_ = &e; } - else if (options.value<CLI::root_element_last> ()) + else if (options.root_element_last ()) { element_ = &e; } - else if (String name = options.value<CLI::root_element> ()) + else if (String name = options.root_element ()) { if (e.name () == name) element_ = &e; @@ -544,46 +544,40 @@ namespace CXX } - Validator:: - Validator () - { - // Dummy ctor, helps with long symbols on HP-UX. - } - - Boolean Validator:: - validate (CLI::Options const& options, + bool Validator:: + validate (options const& ops, SemanticGraph::Schema& root, SemanticGraph::Path const& path, - Boolean gen_driver, + bool gen_driver, const WarningSet& disabled_warnings) { - Boolean valid (true); - ValidationContext ctx (root, path, options, disabled_warnings, valid); + bool valid (true); + ValidationContext ctx (root, path, ops, disabled_warnings, valid); // // - if (options.value<CLI::char_type> () != "char" && - options.value<CLI::char_type> () != "wchar_t" && + if (ops.char_type () != "char" && + ops.char_type () != "wchar_t" && !ctx.is_disabled ("P003")) { wcerr << "warning P003: unknown base character type '" << - options.value<CLI::char_type> ().c_str () << "'" << endl; + ops.char_type ().c_str () << "'" << endl; } // // - if (options.value<CLI::xml_parser> () != "xerces" && - options.value<CLI::xml_parser> () != "expat" && + if (ops.xml_parser () != "xerces" && + ops.xml_parser () != "expat" && !ctx.is_disabled ("P004")) { wcerr << "warning P004: unknown underlying XML parser '" << - options.value<CLI::xml_parser> ().c_str () << "'" << endl; + ops.xml_parser ().c_str () << "'" << endl; } // // - if (options.value<CLI::xml_parser> () == "expat" && - options.value<CLI::char_type> () == "wchar_t") + if (ops.xml_parser () == "expat" && + ops.char_type () == "wchar_t") { wcerr << "error: using expat with wchar_t is not supported" << endl; @@ -593,9 +587,9 @@ namespace CXX // // - if (options.value<CLI::xml_parser> () == "expat" && - !options.value<CLI::char_encoding> ().empty () && - options.value<CLI::char_encoding> () != "utf8") + if (ops.xml_parser () == "expat" && + !ops.char_encoding ().empty () && + ops.char_encoding () != "utf8") { wcerr << "error: using expat with character encoding other than " << "utf8 is not supported" @@ -606,8 +600,7 @@ namespace CXX // // - if (options.value<CLI::generate_validation> () && - options.value<CLI::suppress_validation> ()) + if (ops.generate_validation () && ops.suppress_validation ()) { wcerr << "error: mutually exclusive options specified: " << "--generate-validation and --suppress-validation" @@ -618,8 +611,7 @@ namespace CXX // // - if (options.value<CLI::generate_noop_impl> () && - options.value<CLI::generate_print_impl> ()) + if (ops.generate_noop_impl () && ops.generate_print_impl ()) { wcerr << "error: mutually exclusive options specified: " << "--generate-noop-impl and --generate-print-impl" @@ -631,9 +623,9 @@ namespace CXX // // { - Boolean ref (options.value<CLI::root_element_first> ()); - Boolean rel (options.value<CLI::root_element_last> ()); - Boolean re (options.value<CLI::root_element> ()); + bool ref (ops.root_element_first ()); + bool rel (ops.root_element_last ()); + bool re (ops.root_element ()); if ((ref && rel) || (ref && re) || (rel && re)) { @@ -648,8 +640,8 @@ namespace CXX // // - Boolean import_maps (options.value<CLI::import_maps> ()); - Boolean export_maps (options.value<CLI::export_maps> ()); + bool import_maps (ops.import_maps ()); + bool export_maps (ops.export_maps ()); if (import_maps && export_maps) { @@ -698,7 +690,7 @@ namespace CXX SemanticGraph::Element* element (0); Traversal::Schema schema; - Traversal::Sources sources; + Sources sources; schema >> sources >> schema; |