From dc372de1346545000a2c846895be098a95d98dc7 Mon Sep 17 00:00:00 2001 From: Ulya Trofimovich Date: Mon, 31 Jul 2017 11:29:36 +0100 Subject: [PATCH] Fixed some of the warnings that Clang emits with '-Weverythng'. --- re2c/bootstrap/src/conf/help.cc | 1 + re2c/configure.ac | 6 ++-- re2c/genhelp.sh | 4 ++- re2c/src/adfa/adfa.cc | 22 +++++++-------- re2c/src/adfa/adfa.h | 10 +++---- re2c/src/adfa/dump.cc | 25 ++++++++--------- re2c/src/adfa/prepare.cc | 14 +++++----- re2c/src/code/emit_dfa.cc | 12 ++++---- re2c/src/code/go_construct.cc | 22 +++++++++------ re2c/src/conf/opt.cc | 11 ++++---- re2c/src/dfa/closure.cc | 8 ++++-- re2c/src/nfa/estimate_size.cc | 2 +- re2c/src/re/ast_to_re.cc | 35 +++++++++++++++-------- re2c/src/re/encoding/enc.h | 49 +++++++++++++++------------------ re2c/src/re/nullable.cc | 2 +- re2c/src/re/split_charset.cc | 1 - 16 files changed, 122 insertions(+), 102 deletions(-) diff --git a/re2c/bootstrap/src/conf/help.cc b/re2c/bootstrap/src/conf/help.cc index 1a92949b..10ac400c 100644 --- a/re2c/bootstrap/src/conf/help.cc +++ b/re2c/bootstrap/src/conf/help.cc @@ -1,3 +1,4 @@ +extern const char *help; const char *help = "\n" " -? -h --help\n" diff --git a/re2c/configure.ac b/re2c/configure.ac index f772150b..361d4203 100644 --- a/re2c/configure.ac +++ b/re2c/configure.ac @@ -56,6 +56,7 @@ AC_DEFUN([TRY_CXXFLAG], [ AS_VAR_SET([CXXFLAGS], ["$CXXFLAGS_BACKUP"]) AC_MSG_RESULT([$TRY_CXXFLAG_RESULT]) ]) +TRY_CXXFLAG([-std=c++98]) TRY_CXXFLAG([-W]) TRY_CXXFLAG([-Wall]) TRY_CXXFLAG([-Wextra]) @@ -70,9 +71,10 @@ TRY_CXXFLAG([-O2]) TRY_CXXFLAG([-Weverything], m4_join([ ], [-Wno-unknown-warning-option], dnl CLANG eats some GCC options only to warn they are unknown [-Wno-reserved-id-macro], dnl to allow header guards of the form '_RE2C_PATH_TO_HEADER_BASENAME_' - [-Wno-padded], dnl perhaps later + [-Wno-padded], [-Wno-old-style-cast], dnl RE2C-generated lexer has lots of C-syle casts because of 're2c:yych:conversion = 1;' - [-Wno-covered-switch-default])) dnl GCC reports false positives in some cases + [-Wno-nested-anon-types], + [-Wno-global-constructors])) dnl initialization of global constants with std::numeric_limits<...> (mostly for size_t) # needed by src/c99_stdint.h diff --git a/re2c/genhelp.sh b/re2c/genhelp.sh index 988ac0fb..d6680137 100755 --- a/re2c/genhelp.sh +++ b/re2c/genhelp.sh @@ -1,5 +1,7 @@ -echo "const char *help =" > "$2" +> "$2" +echo "extern const char *help;" >> "$2" +echo "const char *help =" >> "$2" PAGER=cat man "$1" \ | tail -n +7 \ | head -n -3 \ diff --git a/re2c/src/adfa/adfa.cc b/re2c/src/adfa/adfa.cc index e1352561..cefb982a 100644 --- a/re2c/src/adfa/adfa.cc +++ b/re2c/src/adfa/adfa.cc @@ -20,15 +20,15 @@ DFA::DFA , const std::vector &fill , size_t def , size_t key - , const std::string &n - , const std::string &c - , uint32_t l - , const std::string &s + , const std::string &nm + , const std::string &cn + , uint32_t ln + , const std::string &su ) : accepts () - , name (n) - , cond (c) - , line (l) + , name (nm) + , cond (cn) + , line (ln) , lbChar(0) , ubChar(dfa.charset.back()) , nStates(0) @@ -48,7 +48,7 @@ DFA::DFA , def_rule (def) , key_size (key) , bitmaps (std::min(ubChar, 256u)) - , setup(s) + , setup(su) { const size_t nstates = dfa.states.size(); const size_t nchars = dfa.nchars; @@ -80,11 +80,11 @@ DFA::DFA for (uint32_t c = 0; c < nchars; ++j) { const size_t to = t->arcs[c]; - const tcid_t tags = t->tcid[c]; - for (;++c < nchars && t->arcs[c] == to && t->tcid[c] == tags;); + const tcid_t tc = t->tcid[c]; + for (;++c < nchars && t->arcs[c] == to && t->tcid[c] == tc;); s->go.span[j].to = to == dfa_t::NIL ? NULL : i2s[to]; s->go.span[j].ub = charset[c]; - s->go.span[j].tags = tags; + s->go.span[j].tags = tc; } s->go.nSpans = j; } diff --git a/re2c/src/adfa/adfa.h b/re2c/src/adfa/adfa.h index f62e9e84..cc198b5b 100644 --- a/re2c/src/adfa/adfa.h +++ b/re2c/src/adfa/adfa.h @@ -87,15 +87,15 @@ struct DFA , const std::vector &fill , size_t def , size_t key - , const std::string &n - , const std::string &c - , uint32_t l - , const std::string &s + , const std::string &nm + , const std::string &cn + , uint32_t ln + , const std::string &su ); ~DFA (); void reorder(); void prepare(const opt_t *opts); - void calc_stats(uint32_t line, bool explicit_tags); + void calc_stats(uint32_t ln, bool explicit_tags); void emit (Output &, uint32_t &, bool, bool &); private: diff --git a/re2c/src/adfa/dump.cc b/re2c/src/adfa/dump.cc index 8a970e69..34bd95d7 100644 --- a/re2c/src/adfa/dump.cc +++ b/re2c/src/adfa/dump.cc @@ -32,10 +32,12 @@ void dump_adfa(const DFA &dfa) const char *attr; Action::type_t action = s->action.type; - switch (action) { - case Action::ACCEPT: attr = "style=filled fillcolor=gray"; break; - case Action::RULE: attr = "style=filled fillcolor=lightgray"; break; - default: attr = ""; break; + if (action == Action::ACCEPT) { + attr = "style=filled fillcolor=gray"; + } else if (action == Action::RULE) { + attr = "style=filled fillcolor=lightgray"; + } else { + attr = ""; } fprintf(stderr, " n%p [height=0.2 width=0.2 label=\"", (void*)s); if (s->fill && action != Action::MOVE) { @@ -68,15 +70,12 @@ void dump_adfa(const DFA &dfa) if (!x->to) continue; bool eat = true; - switch (x->to->action.type) { - case Action::MOVE: - case Action::RULE: - attr = "style=dotted"; - eat = false; - break; - default: - attr = ""; - break; + const Action::type_t act = x->to->action.type; + if (act == Action::MOVE || act == Action::RULE) { + attr = "style=dotted"; + eat = false; + } else { + attr = ""; } fprintf(stderr, " n%p -> n%p [label=\"", (void*)s, (void*)x->to); if (eat) dump_adfa_range(lb, x->ub); diff --git a/re2c/src/adfa/prepare.cc b/re2c/src/adfa/prepare.cc index 0c7b0034..c8202d97 100644 --- a/re2c/src/adfa/prepare.cc +++ b/re2c/src/adfa/prepare.cc @@ -226,7 +226,7 @@ void DFA::prepare(const opt_t *opts) } } -void DFA::calc_stats(uint32_t line, bool explicit_tags) +void DFA::calc_stats(uint32_t ln, bool explicit_tags) { // calculate 'YYMAXFILL' max_fill = 0; @@ -254,7 +254,7 @@ void DFA::calc_stats(uint32_t line, bool explicit_tags) // error if tags are not enabled, but we need them if (!explicit_tags && maxtagver > 1) { - fatal_l(line, "overlapping trailing contexts need " + fatal_l(ln, "overlapping trailing contexts need " "multiple context markers, use '-t, --tags' " "option and '/*!stags:re2c ... */' directive"); } @@ -267,15 +267,15 @@ void DFA::hoist_tags() const size_t nspan = s->go.nSpans; if (nspan == 0) continue; - tcid_t tags = span[0].tags; + tcid_t ts = span[0].tags; for (uint32_t i = 1; i < nspan; ++i) { - if (span[i].tags != tags) { - tags = TCID0; + if (span[i].tags != ts) { + ts = TCID0; break; } } - if (tags != TCID0) { - s->go.tags = tags; + if (ts != TCID0) { + s->go.tags = ts; for (uint32_t i = 0; i < nspan; ++i) { span[i].tags = TCID0; } diff --git a/re2c/src/code/emit_dfa.cc b/re2c/src/code/emit_dfa.cc index a47609b1..5c0f8cb8 100644 --- a/re2c/src/code/emit_dfa.cc +++ b/re2c/src/code/emit_dfa.cc @@ -98,10 +98,10 @@ void DFA::emit_dot(OutputFile &o, bool last_cond) const } for (State *s = head; s; s = s->next) { if (s->action.type == Action::ACCEPT) { - const accept_t &accepts = *s->action.info.accepts; - for (uint32_t i = 0; i < accepts.size(); ++i) { + const accept_t &accs = *s->action.info.accepts; + for (uint32_t i = 0; i < accs.size(); ++i) { o.wlabel(s->label).ws(" -> ") - .wlabel(accepts[i].first->label) + .wlabel(accs[i].first->label) .ws(" [label=\"yyaccept=") .wu32(i).ws("\"]").ws("\n"); } @@ -138,11 +138,11 @@ void DFA::emit(Output & output, uint32_t& ind, bool isLastCond, bool& bPrologBra } } for (tagver_t v = 1; v <= maxtagver; ++v) { - const std::string name = vartag_name(v, opts->tags_prefix); + const std::string s = vartag_name(v, opts->tags_prefix); if (mtagvers.find(v) != mtagvers.end()) { - mtagnames.insert(name); + mtagnames.insert(s); } else { - stagnames.insert(name); + stagnames.insert(s); } } ob.stags.insert(stagnames.begin(), stagnames.end()); diff --git a/re2c/src/code/go_construct.cc b/re2c/src/code/go_construct.cc index 2ccbc5b1..609cc958 100644 --- a/re2c/src/code/go_construct.cc +++ b/re2c/src/code/go_construct.cc @@ -1,3 +1,4 @@ +#include #include #include "src/util/c99_stdint.h" #include @@ -17,11 +18,14 @@ static uint32_t unmap (Span * new_span, const Span * old_span, uint32_t old_nspa bool consume(const State *s) { switch (s->action.type) { - default: return true; case Action::RULE: - case Action::MOVE: + case Action::MOVE: case Action::ACCEPT: return false; + case Action::MATCH: + case Action::INITIAL: + case Action::SAVE: return true; } + assert(false); } Cases::Cases(const Span *spans, uint32_t nspans, bool skip) @@ -32,15 +36,15 @@ Cases::Cases(const Span *spans, uint32_t nspans, bool skip) // first case is default case Case &c = cases[cases_size++]; - const Span &s = spans[nspans - 1]; - c.to = s.to; - c.tags = s.tags; - c.skip = skip && consume(s.to); + const Span *s = spans + (nspans - 1); + c.to = s->to; + c.tags = s->tags; + c.skip = skip && consume(s->to); for (uint32_t i = 0, lb = 0; i < nspans; ++i) { - const Span &s = spans[i]; - add(lb, s.ub, s.to, s.tags, skip && consume(s.to)); - lb = s.ub; + s = spans + i; + add(lb, s->ub, s->to, s->tags, skip && consume(s->to)); + lb = s->ub; } } diff --git a/re2c/src/conf/opt.cc b/re2c/src/conf/opt.cc index 2f24e357..33b30518 100644 --- a/re2c/src/conf/opt.cc +++ b/re2c/src/conf/opt.cc @@ -97,7 +97,7 @@ void mutopt_t::fix(const conopt_t *globopts) startlabel = Opt::baseopt.startlabel; startlabel_force = Opt::baseopt.startlabel_force; break; - default: + case TARGET_CODE: break; } @@ -199,17 +199,18 @@ void mutopt_t::fix(const conopt_t *globopts) indString = " "; topIndent = 2; break; - default: + case TARGET_CODE: break; } - switch (encoding.type ()) - { + switch (encoding.type()) { case Enc::UCS2: case Enc::UTF16: case Enc::UTF32: sFlag = true; break; - default: + case Enc::ASCII: + case Enc::EBCDIC: + case Enc::UTF8: break; } if (bFlag) diff --git a/re2c/src/dfa/closure.cc b/re2c/src/dfa/closure.cc index 143338c7..cdda60c1 100644 --- a/re2c/src/dfa/closure.cc +++ b/re2c/src/dfa/closure.cc @@ -118,7 +118,6 @@ static void scan(nfa_state_t *n, std::stack &bstack, closure_t &do tagtree_t &history = tagpool.history; clos_t x = done[n->clos]; switch (n->type) { - default: break; case nfa_state_t::NIL: x.state = n->nil.out; enqueue(x, bstack, done, shadow, tagpool, tags); @@ -135,6 +134,9 @@ static void scan(nfa_state_t *n, std::stack &bstack, closure_t &do n->tag.bottom ? TAGVER_BOTTOM : TAGVER_CURSOR); enqueue(x, bstack, done, shadow, tagpool, tags); break; + case nfa_state_t::RAN: + case nfa_state_t::FIN: + break; } } @@ -258,7 +260,6 @@ void closure_leftmost(const closure_t &init, closure_t &done, } switch (n->type) { - default: break; case nfa_state_t::NIL: x.state = n->nil.out; todo.push(x); @@ -275,6 +276,9 @@ void closure_leftmost(const closure_t &init, closure_t &done, n->tag.bottom ? TAGVER_BOTTOM : TAGVER_CURSOR); todo.push(x); break; + case nfa_state_t::RAN: + case nfa_state_t::FIN: + break; } } diff --git a/re2c/src/nfa/estimate_size.cc b/re2c/src/nfa/estimate_size.cc index 1930eceb..e82c59d4 100644 --- a/re2c/src/nfa/estimate_size.cc +++ b/re2c/src/nfa/estimate_size.cc @@ -5,7 +5,6 @@ namespace re2c { static size_t estimate(const RE *re) { switch (re->type) { - default: assert(false); case RE::NIL: return 0; case RE::SYM: return 1; case RE::TAG: return 1; @@ -26,6 +25,7 @@ static size_t estimate(const RE *re) : iter * max + (max - min); } } + assert(false); } size_t estimate_size(const std::vector &res) diff --git a/re2c/src/re/ast_to_re.cc b/re2c/src/re/ast_to_re.cc index e3a56ff6..ac3ffa86 100644 --- a/re2c/src/re/ast_to_re.cc +++ b/re2c/src/re/ast_to_re.cc @@ -34,7 +34,6 @@ namespace re2c { static bool has_tags(const AST *ast) { switch (ast->type) { - default: assert(false); case AST::NIL: case AST::STR: case AST::CLS: @@ -48,12 +47,12 @@ static bool has_tags(const AST *ast) case AST::REF: return has_tags(ast->ref.ast); case AST::ITER: return has_tags(ast->iter.ast); } + assert(false); } static size_t fixlen(const AST *ast) { switch (ast->type) { - default: assert(false); case AST::NIL: case AST::TAG: return 0; case AST::CLS: @@ -83,6 +82,7 @@ static size_t fixlen(const AST *ast) } case AST::CAP: return fixlen(ast->cap); } + assert(false); } static RE *ast_to_re(RESpec &spec, const AST *ast, size_t &ncap) @@ -93,7 +93,6 @@ static RE *ast_to_re(RESpec &spec, const AST *ast, size_t &ncap) Warn &warn = spec.warn; switch (ast->type) { - default: assert(false); case AST::NIL: return re_nil(alc); case AST::STR: { @@ -253,6 +252,7 @@ static RE *ast_to_re(RESpec &spec, const AST *ast, size_t &ncap) return y; } } + assert(false); } RE *re_schar(RE::alc_t &alc, uint32_t line, uint32_t column, uint32_t c, const opt_t *opts) @@ -260,11 +260,18 @@ RE *re_schar(RE::alc_t &alc, uint32_t line, uint32_t column, uint32_t c, const o if (!opts->encoding.encode(c)) { fatal_lc(line, column, "bad code point: '0x%X'", c); } - switch (opts->encoding.type ()) { - case Enc::UTF16: return UTF16Symbol(alc, c); - case Enc::UTF8: return UTF8Symbol(alc, c); - default: return re_sym(alc, Range::sym(c)); + switch (opts->encoding.type()) { + case Enc::UTF16: + return UTF16Symbol(alc, c); + case Enc::UTF8: + return UTF8Symbol(alc, c); + case Enc::ASCII: + case Enc::EBCDIC: + case Enc::UTF32: + case Enc::UCS2: + return re_sym(alc, Range::sym(c)); } + assert(false); } RE *re_ichar(RE::alc_t &alc, uint32_t line, uint32_t column, uint32_t c, const opt_t *opts) @@ -290,14 +297,20 @@ RE *re_class(RE::alc_t &alc, uint32_t line, uint32_t column, const Range *r, con break; case EMPTY_CLASS_ERROR: fatal_lc(line, column, "empty character class"); - break; } } switch (opts->encoding.type()) { - case Enc::UTF16: return UTF16Range(alc, r); - case Enc::UTF8: return UTF8Range(alc, r); - default: return re_sym(alc, r); + case Enc::UTF16: + return UTF16Range(alc, r); + case Enc::UTF8: + return UTF8Range(alc, r); + case Enc::ASCII: + case Enc::EBCDIC: + case Enc::UTF32: + case Enc::UCS2: + return re_sym(alc, r); } + assert(false); } static void assert_tags_used_once(const Rule &rule, const std::vector &tags) diff --git a/re2c/src/re/encoding/enc.h b/re2c/src/re/encoding/enc.h index 37f069f4..b4afa835 100644 --- a/re2c/src/re/encoding/enc.h +++ b/re2c/src/re/encoding/enc.h @@ -94,73 +94,68 @@ public: inline const char * Enc::name (type_t t) { - switch (t) - { + switch (t) { case ASCII: return "ASCII"; case EBCDIC: return "EBCDIC"; case UTF8: return "UTF8"; case UCS2: return "USC2"; case UTF16: return "UTF16"; case UTF32: return "UTF32"; - default: return ""; } + return ""; /* error */ } inline uint32_t Enc::nCodePoints() const { - switch (type_) - { + switch (type_) { case ASCII: - case EBCDIC: return 0x100; - case UCS2: return 0x10000; + case EBCDIC: return 0x100; + case UCS2: return 0x10000; case UTF16: case UTF32: - case UTF8: - default: return 0x110000; + case UTF8: return 0x110000; } + return 0; /* error */ } inline uint32_t Enc::nCodeUnits() const { - switch (type_) - { + switch (type_) { case ASCII: case EBCDIC: - case UTF8: return 0x100; + case UTF8: return 0x100; case UCS2: - case UTF16: return 0x10000; - case UTF32: - default: return 0x110000; + case UTF16: return 0x10000; + case UTF32: return 0x110000; } + return 0; /* error */ } // returns *maximal* code point size for encoding inline uint32_t Enc::szCodePoint() const { - switch (type_) - { + switch (type_) { case ASCII: - case EBCDIC: return 1; - case UCS2: return 2; + case EBCDIC: return 1; + case UCS2: return 2; case UTF16: case UTF32: - case UTF8: - default: return 4; + case UTF8: return 4; } + return 0; /* error */ } inline uint32_t Enc::szCodeUnit() const { - switch (type_) - { + switch (type_) { case ASCII: case EBCDIC: - case UTF8: return 1; + case UTF8: return 1; case UCS2: - case UTF16: return 2; - case UTF32: - default: return 4; + case UTF16: return 2; + case UTF32: return 4; } + return 0; /* error */ } inline void Enc::set(type_t t) diff --git a/re2c/src/re/nullable.cc b/re2c/src/re/nullable.cc index 8a79c071..6201a2ee 100644 --- a/re2c/src/re/nullable.cc +++ b/re2c/src/re/nullable.cc @@ -7,7 +7,6 @@ static bool nullable(const RESpec &spec, const RE *re, bool &trail) if (trail) return true; switch (re->type) { - default: assert(false); case RE::NIL: return true; case RE::SYM: return false; case RE::ITER: @@ -22,6 +21,7 @@ static bool nullable(const RESpec &spec, const RE *re, bool &trail) return nullable(spec, re->cat.re1, trail) && nullable(spec, re->cat.re2, trail); } + assert(false); } /* diff --git a/re2c/src/re/split_charset.cc b/re2c/src/re/split_charset.cc index b1c91b8e..4c1a4b0e 100644 --- a/re2c/src/re/split_charset.cc +++ b/re2c/src/re/split_charset.cc @@ -8,7 +8,6 @@ namespace re2c { static void split(const RE* re, std::set &cs) { switch (re->type) { - default: assert(false); case RE::NIL: break; case RE::TAG: break; case RE::SYM: -- 2.40.0