+extern const char *help;
const char *help =
"\n"
" -? -h --help\n"
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])
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
-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 \
, 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)
, 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;
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;
}
, 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:
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) {
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);
}
}
-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;
// 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");
}
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;
}
}
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");
}
}
}
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());
+#include <assert.h>
#include <stddef.h>
#include "src/util/c99_stdint.h"
#include <string>
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)
// 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;
}
}
startlabel = Opt::baseopt.startlabel;
startlabel_force = Opt::baseopt.startlabel_force;
break;
- default:
+ case TARGET_CODE:
break;
}
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)
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);
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;
}
}
}
switch (n->type) {
- default: break;
case nfa_state_t::NIL:
x.state = n->nil.out;
todo.push(x);
n->tag.bottom ? TAGVER_BOTTOM : TAGVER_CURSOR);
todo.push(x);
break;
+ case nfa_state_t::RAN:
+ case nfa_state_t::FIN:
+ break;
}
}
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;
: iter * max + (max - min);
}
}
+ assert(false);
}
size_t estimate_size(const std::vector<RE*> &res)
static bool has_tags(const AST *ast)
{
switch (ast->type) {
- default: assert(false);
case AST::NIL:
case AST::STR:
case AST::CLS:
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:
}
case AST::CAP: return fixlen(ast->cap);
}
+ assert(false);
}
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: {
return y;
}
}
+ assert(false);
}
RE *re_schar(RE::alc_t &alc, uint32_t line, uint32_t column, uint32_t c, const opt_t *opts)
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)
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)
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)
if (trail) return true;
switch (re->type) {
- default: assert(false);
case RE::NIL: return true;
case RE::SYM: return false;
case RE::ITER:
return nullable(spec, re->cat.re1, trail)
&& nullable(spec, re->cat.re2, trail);
}
+ assert(false);
}
/*
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: