From: Ulya Trofimovich Date: Mon, 27 Jul 2015 14:12:49 +0000 (+0100) Subject: Unified location output in warning messages. X-Git-Tag: 0.15~176 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=929c87fdf3a3de5f08206a258dfabbc0a068c561;p=re2c Unified location output in warning messages. --- diff --git a/re2c/src/codegen/output.cc b/re2c/src/codegen/output.cc index 520e62b7..e8e26c4d 100644 --- a/re2c/src/codegen/output.cc +++ b/re2c/src/codegen/output.cc @@ -37,6 +37,7 @@ OutputBlock::OutputBlock () , used_yyaccept (false) , force_start_label (false) , user_start_label () + , line (0) { fragments.push_back (new OutputFragment (OutputFragment::CODE, 0)); } @@ -227,6 +228,16 @@ bool OutputFile::get_force_start_label () const return blocks.back ()->force_start_label; } +void OutputFile::set_block_line (uint32_t l) +{ + blocks.back ()->line = l; +} + +uint32_t OutputFile::get_block_line () const +{ + return blocks.back ()->line; +} + void OutputFile::new_block () { blocks.push_back (new OutputBlock ()); diff --git a/re2c/src/codegen/output.h b/re2c/src/codegen/output.h index 4890a7f4..1f584da1 100644 --- a/re2c/src/codegen/output.h +++ b/re2c/src/codegen/output.h @@ -40,6 +40,7 @@ struct OutputBlock bool used_yyaccept; bool force_start_label; std::string user_start_label; + uint32_t line; OutputBlock (); ~OutputBlock (); @@ -92,6 +93,8 @@ public: void set_force_start_label (bool force); void set_user_start_label (const std::string & label); bool get_force_start_label () const; + void set_block_line (uint32_t l); + uint32_t get_block_line () const; void emit (const std::vector & types, uint32_t max_fill); diff --git a/re2c/src/codegen/prepare_dfa.cc b/re2c/src/codegen/prepare_dfa.cc index 4b904989..4286419e 100644 --- a/re2c/src/codegen/prepare_dfa.cc +++ b/re2c/src/codegen/prepare_dfa.cc @@ -251,7 +251,7 @@ void DFA::prepare(OutputFile & o, uint32_t & max_fill) // warn if default case is not handled if (default_state && !stray_cunits.empty () && !empty_rule) { - warn.naked_default (stray_cunits); + warn.naked_default (o.get_block_line (), stray_cunits); } // warn about not shadowed rule that matches empty string diff --git a/re2c/src/conf/msg.cc b/re2c/src/conf/msg.cc index b16e6ff0..b8a20c69 100644 --- a/re2c/src/conf/msg.cc +++ b/re2c/src/conf/msg.cc @@ -24,9 +24,9 @@ void error_encoding () error ("only one of switches -e, -w, -x, -u and -8 must be set"); } -void warning (const char * type, const char * fmt, ...) +void warning (const char * type, uint32_t line, const char * fmt, ...) { - fprintf (stderr, "re2c: warning: "); + fprintf (stderr, "re2c: warning: line %u: ", line); va_list args; va_start (args, fmt); diff --git a/re2c/src/conf/msg.h b/re2c/src/conf/msg.h index 75239545..c3eed608 100644 --- a/re2c/src/conf/msg.h +++ b/re2c/src/conf/msg.h @@ -2,12 +2,13 @@ #define _RE2C_CONF_MSG_ #include "src/util/attribute.h" +#include "src/util/c99_stdint.h" namespace re2c { void error (const char * fmt, ...) RE2C_GXX_ATTRIBUTE ((format (printf, 1, 2))); void error_encoding (); -void warning (const char * type, const char * fmt, ...) RE2C_GXX_ATTRIBUTE ((format (printf, 2, 3))); +void warning (const char * type, uint32_t line, const char * fmt, ...) RE2C_GXX_ATTRIBUTE ((format (printf, 3, 4))); void usage (); void vernum (); void version (); diff --git a/re2c/src/conf/warn.cc b/re2c/src/conf/warn.cc index 15cfdc06..23714d04 100644 --- a/re2c/src/conf/warn.cc +++ b/re2c/src/conf/warn.cc @@ -70,7 +70,7 @@ void Warn::empty_class (uint32_t line) { error_accuml = true; } - warning (names[EMPTY_CHARACTER_CLASS], "empty character class at line %u", line); + warning (names[EMPTY_CHARACTER_CLASS], line, "empty character class"); } } @@ -82,11 +82,11 @@ void Warn::match_empty_string (uint32_t line) { error_accuml = true; } - warning (names[MATCH_EMPTY_STRING], "rule matches empty string at line %u", line); + warning (names[MATCH_EMPTY_STRING], line, "rule matches empty string"); } } -void Warn::naked_default (const std::vector > & stray_cunits) +void Warn::naked_default (uint32_t line, const std::vector > & stray_cunits) { if (mask[NAKED_DEFAULT] & WARNING) { @@ -99,7 +99,7 @@ void Warn::naked_default (const std::vector > & st { printSpan (s, stray_cunits[i].first, stray_cunits[i].second); } - warning (names[NAKED_DEFAULT], "naked default case (stray code units: %s), better add default rule *", s.str ().c_str ()); + warning (names[NAKED_DEFAULT], line, "naked default case (stray code units: %s), better add default rule *", s.str ().c_str ()); } } diff --git a/re2c/src/conf/warn.h b/re2c/src/conf/warn.h index e74ae220..69a477a5 100644 --- a/re2c/src/conf/warn.h +++ b/re2c/src/conf/warn.h @@ -45,7 +45,7 @@ public: void set_all (option_t o); void empty_class (uint32_t line); void match_empty_string (uint32_t line); - void naked_default (const std::vector > & stray_cunits); + void naked_default (uint32_t line, const std::vector > & stray_cunits); }; } // namespace re2c diff --git a/re2c/src/parse/parser.ypp b/re2c/src/parse/parser.ypp index 14c3f941..e29204b8 100644 --- a/re2c/src/parse/parser.ypp +++ b/re2c/src/parse/parser.ypp @@ -577,6 +577,7 @@ void parse(Scanner& i, Output & o) } encodingOld = encoding; } + o.source.set_block_line (in->get_cline ()); if (cFlag) { RegExpMap::iterator it;