]> granicus.if.org Git - re2c/commitdiff
Fixed some of the warnings that Clang emits with '-Weverythng'.
authorUlya Trofimovich <skvadrik@gmail.com>
Mon, 31 Jul 2017 10:29:36 +0000 (11:29 +0100)
committerUlya Trofimovich <skvadrik@gmail.com>
Mon, 31 Jul 2017 10:29:36 +0000 (11:29 +0100)
16 files changed:
re2c/bootstrap/src/conf/help.cc
re2c/configure.ac
re2c/genhelp.sh
re2c/src/adfa/adfa.cc
re2c/src/adfa/adfa.h
re2c/src/adfa/dump.cc
re2c/src/adfa/prepare.cc
re2c/src/code/emit_dfa.cc
re2c/src/code/go_construct.cc
re2c/src/conf/opt.cc
re2c/src/dfa/closure.cc
re2c/src/nfa/estimate_size.cc
re2c/src/re/ast_to_re.cc
re2c/src/re/encoding/enc.h
re2c/src/re/nullable.cc
re2c/src/re/split_charset.cc

index 1a92949b015ab4afe213058f5c321dbc69c15389..10ac400c5a5b7e1c8c0ec277a2e86d93acef41ec 100644 (file)
@@ -1,3 +1,4 @@
+extern const char *help;
 const char *help =
 "\n"
 "       -? -h --help\n"
index f772150bff062074baa1725b2be6966dce80473d..361d4203f3d5fdc45a348109eaf73f49c4b95e6a 100644 (file)
@@ -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
index 988ac0fbad2895cedf10928d82bf16ad607fcbe1..d6680137885aee1d33f8226cb07164019c17b4a2 100755 (executable)
@@ -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 \
index e1352561cecf9922dc4b1a10f37ad77bb0ad21c4..cefb982ae0191cf243af9f6dc0348a2044714dd6 100644 (file)
@@ -20,15 +20,15 @@ DFA::DFA
        , const std::vector<size_t> &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;
        }
index f62e9e843a0269a8e57380eb1c0933f8764a3aea..cc198b5b3ee6714dc0308a2a0a6b3e18ed73d7f3 100644 (file)
@@ -87,15 +87,15 @@ struct DFA
                , const std::vector<size_t> &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:
index 8a970e696b0e3c4fd7d129196c607bd24e2057a5..34bd95d76b651e64c472262e8f1cad82997de64a 100644 (file)
@@ -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);
index 0c7b00341b334b98d84c9651e8dc9fea0b7fb2b2..c8202d97031ae4077b8a9559866b43cf667a1340 100644 (file)
@@ -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;
                        }
index a47609b12b2f9286f4bdda6a5c6a78afe59a3cd1..5c0f8cb830ebd732eb7149cc7e70f84fd15ead0d 100644 (file)
@@ -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());
index 2ccbc5b16a039d4916aaa1e6268b647372ce7e41..609cc958ac35a8068a5f26a18e6a2e510bb7bf44 100644 (file)
@@ -1,3 +1,4 @@
+#include <assert.h>
 #include <stddef.h>
 #include "src/util/c99_stdint.h"
 #include <string>
@@ -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;
        }
 }
 
index 2f24e3576cd4976d0c2d30d6de792c630ac32a52..33b305184ad52252655114cbb57a76d2e512a133 100644 (file)
@@ -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)
index 143338c770f0a6f19e42f339191e71c0be2c2f68..cdda60c1e0ce111898937c2100b452c9de50acba 100644 (file)
@@ -118,7 +118,6 @@ static void scan(nfa_state_t *n, std::stack<nfa_state_t*> &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<nfa_state_t*> &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;
                }
        }
 
index 1930eceb62d1ef1a988115832ae6285deb9da283..e82c59d4956b46ad7c661d98a4cbbcc68a726e74 100644 (file)
@@ -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<RE*> &res)
index e3a56ff6172a455b90f4e63b2f8feb563c1dd1e5..ac3ffa8603f0cb1b9c37ffa9c2d73523adc94286 100644 (file)
@@ -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<Tag> &tags)
index 37f069f40f716e78299f9fb8f59574d2a16241ab..b4afa835b9e2a7b8a81187ec100f61e23f6ed6c6 100644 (file)
@@ -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 "<bad encoding>";
        }
+       return "<bad encoding>"; /* 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)
index 8a79c0719bcbe41e2c82a0209e690566069d6656..6201a2eeca6aa9feb6d426b3cf966de089dbd730 100644 (file)
@@ -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);
 }
 
 /*
index b1c91b8e7d407e47e9dcd8046bc03b632ebeed1f..4c1a4b0ee4c74ea27201b34190cb449b2ead0829 100644 (file)
@@ -8,7 +8,6 @@ namespace re2c {
 static void split(const RE* re, std::set<uint32_t> &cs)
 {
        switch (re->type) {
-               default: assert(false);
                case RE::NIL: break;
                case RE::TAG: break;
                case RE::SYM: