From b7053a4aed95219ab9a407e1345e4068614b331a Mon Sep 17 00:00:00 2001 From: Ulya Trofimovich Date: Mon, 27 Jul 2015 11:41:23 +0100 Subject: [PATCH] Don't output generated code when failed with -Werror. --- re2c/src/codegen/output.cc | 7 +++++-- re2c/src/conf/warn.cc | 12 ++++++------ re2c/src/conf/warn.h | 4 ++-- re2c/src/main.cc | 2 +- 4 files changed, 14 insertions(+), 11 deletions(-) diff --git a/re2c/src/codegen/output.cc b/re2c/src/codegen/output.cc index b2461531..520e62b7 100644 --- a/re2c/src/codegen/output.cc +++ b/re2c/src/codegen/output.cc @@ -336,8 +336,11 @@ Output::Output (const char * source_name, const char * header_name) Output::~Output () { - source.emit (types, max_fill); - header.emit (types); + if (!warn.error ()) + { + source.emit (types, max_fill); + header.emit (types); + } } void output_state_goto_sub (std::ostream & o, uint32_t ind, uint32_t start_label, int cMin, int cMax) diff --git a/re2c/src/conf/warn.cc b/re2c/src/conf/warn.cc index 6bd045f6..01c2fee9 100644 --- a/re2c/src/conf/warn.cc +++ b/re2c/src/conf/warn.cc @@ -22,7 +22,7 @@ const char * Warn::names [TYPES] = Warn::Warn () : mask () - , error (false) + , error_accuml (false) { for (uint32_t i = 0; i < TYPES; ++i) { @@ -30,9 +30,9 @@ Warn::Warn () } } -uint32_t Warn::error_code () const +bool Warn::error () const { - return error; + return error_accuml; } void Warn::set (type_t t, option_t o) @@ -68,7 +68,7 @@ void Warn::empty_class (uint32_t line) { if (mask[EMPTY_CHARACTER_CLASS] & ERROR) { - error = true; + error_accuml = true; } warning (names[EMPTY_CHARACTER_CLASS], "empty character class at line %u", line); } @@ -80,7 +80,7 @@ void Warn::empty_rule (uint32_t line) { if (mask[EMPTY_RULE] & ERROR) { - error = true; + error_accuml = true; } warning (names[EMPTY_RULE], "empty rule at line %u", line); } @@ -92,7 +92,7 @@ void Warn::naked_default (const std::vector > & st { if (mask[NAKED_DEFAULT] & ERROR) { - error = true; + error_accuml = true; } std::ostringstream s; for (uint32_t i = 0; i < stray_cunits.size (); ++i) diff --git a/re2c/src/conf/warn.h b/re2c/src/conf/warn.h index f0b11fa1..f07304f8 100644 --- a/re2c/src/conf/warn.h +++ b/re2c/src/conf/warn.h @@ -36,11 +36,11 @@ private: static const uint8_t ERROR; static const char * names [TYPES]; uint8_t mask[TYPES]; - bool error; + bool error_accuml; public: Warn (); - uint32_t error_code () const; + bool error () const; void set (type_t t, option_t o); void set_all (option_t o); void empty_class (uint32_t line); diff --git a/re2c/src/main.cc b/re2c/src/main.cc index fa23b25a..ab069d33 100644 --- a/re2c/src/main.cc +++ b/re2c/src/main.cc @@ -57,5 +57,5 @@ int main(int argc, char *argv[]) Scanner scanner (input, output.source); parse (scanner, output); - return warn.error_code (); + return warn.error () ? 1 : 0; } -- 2.40.0