From b7335b8c1425138601698f2deac8e471b371cbcc Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 19 Sep 2011 16:47:07 +0200 Subject: Throw exception instead of returning false to indicate validation failure This is consistent with what's done in processor and generator. --- odb/plugin.cxx | 34 +++++++++++++--------------------- odb/validator.cxx | 5 +++-- odb/validator.hxx | 4 +++- 3 files changed, 19 insertions(+), 24 deletions(-) diff --git a/odb/plugin.cxx b/odb/plugin.cxx index 7f01478..fbf1fa0 100644 --- a/odb/plugin.cxx +++ b/odb/plugin.cxx @@ -112,36 +112,22 @@ gate_callback (void*, void*) // Validate, pass 1. // - { - validator v; - if (!v.validate (*options_, *u, file_, 1)) - r = 1; - } + validator v; + v.validate (*options_, *u, file_, 1); // Process. // - if (r == 0) - { - processor p; - p.process (*options_, *u, file_); - } + processor pr; + pr.process (*options_, *u, file_); // Validate, pass 2. // - if (r == 0) - { - validator v; - if (!v.validate (*options_, *u, file_, 2)) - r = 1; - } + v.validate (*options_, *u, file_, 2); // Generate. // - if (r == 0) - { - generator g; - g.generate (*options_, *u, file_); - } + generator g; + g.generate (*options_, *u, file_); } catch (parser::failed const&) { @@ -149,6 +135,12 @@ gate_callback (void*, void*) // r = 1; } + catch (validator::failed const&) + { + // Diagnostics has aready been issued. + // + r = 1; + } catch (processor::failed const&) { // Diagnostics has aready been issued. diff --git a/odb/validator.cxx b/odb/validator.cxx index 90e6b7e..c12bff0 100644 --- a/odb/validator.cxx +++ b/odb/validator.cxx @@ -629,7 +629,7 @@ namespace }; } -bool validator:: +void validator:: validate (options const& ops, semantics::unit& u, semantics::path const&, @@ -680,5 +680,6 @@ validate (options const& ops, unit.dispatch (u); } - return valid; + if (!valid) + throw failed (); } diff --git a/odb/validator.hxx b/odb/validator.hxx index 370e5e0..cb6076a 100644 --- a/odb/validator.hxx +++ b/odb/validator.hxx @@ -12,9 +12,11 @@ class validator { public: + struct failed {}; + // The first pass is performed before processing. The second -- after. // - bool + void validate (options const&, semantics::unit&, semantics::path const&, -- cgit v1.1