From: Ulya Trofimovich Date: Mon, 22 Feb 2016 13:17:57 +0000 (+0000) Subject: Now regexp AST is immutable. X-Git-Tag: 1.0~39^2~366 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=915296e17853f5f5cb62900cee0d122c911bacef;p=re2c Now regexp AST is immutable. We don't do any transformations on AST anyway: it is analysed and converted to NFA. This patch simply fixes the fact that AST is immutable. --- diff --git a/re2c/bootstrap/src/parse/lex.cc b/re2c/bootstrap/src/parse/lex.cc index c9ce0c2c..ef098f89 100644 --- a/re2c/bootstrap/src/parse/lex.cc +++ b/re2c/bootstrap/src/parse/lex.cc @@ -1,4 +1,4 @@ -/* Generated by re2c 0.16 on Mon Feb 22 12:14:07 2016 */ +/* Generated by re2c 0.16 on Mon Feb 22 13:12:30 2016 */ #line 1 "../src/parse/lex.re" #include "src/util/c99_stdint.h" #include @@ -1023,7 +1023,7 @@ yy153: yylval.str = new std::string (tok, tok_len()); return TOKEN_ID; } else { - RegExp *r = NULL; + const RegExp *r = NULL; const bool casing = opts->bCaseInsensitive || opts->bCaseInverted; for (char *s = tok; s < cur; ++s) { const uint32_t c = static_cast(*s); @@ -2070,7 +2070,7 @@ static void escape (std::string & dest, const std::string & src) } } -RegExp *Scanner::lex_cls(bool neg) +const RegExp *Scanner::lex_cls(bool neg) { Range *r = NULL, *s; uint32_t u, l; @@ -2714,9 +2714,9 @@ yy419: } -RegExp *Scanner::lex_str(char quote, bool casing) +const RegExp *Scanner::lex_str(char quote, bool casing) { - RegExp *r = NULL; + const RegExp *r = NULL; for (bool end;;) { const uint32_t c = lex_str_chr(quote, end); if (end) { diff --git a/re2c/bootstrap/src/parse/parser.cc b/re2c/bootstrap/src/parse/parser.cc index 3b8f7de1..9307c37b 100644 --- a/re2c/bootstrap/src/parse/parser.cc +++ b/re2c/bootstrap/src/parse/parser.cc @@ -116,9 +116,9 @@ static counter_t rank_counter; static std::vector condnames; static re2c::SpecMap specMap; static Spec spec; -static RegExp *specNone = NULL; +static const RegExp *specNone = NULL; static RuleList specStar; -static RegExp *star_default = NULL; +static const RegExp *star_default = NULL; static Scanner *in = NULL; static Scanner::ParseMode parseMode; static SetupMap ruleSetupMap; @@ -151,8 +151,8 @@ void context_none(CondList *clist) void context_rule ( CondList * clist , const Loc & loc - , RegExp * expr - , RegExp * look + , const RegExp * expr + , const RegExp * look , const Code * code , const std::string * newcond ) @@ -165,7 +165,7 @@ void context_rule condnames.push_back (*it); } - RegExp *rule = RegExp::rule + const RegExp *rule = RegExp::rule ( loc , expr , look @@ -202,7 +202,7 @@ void default_rule(CondList *clist, const Code * code) context_check(clist); for(CondList::const_iterator it = clist->begin(); it != clist->end(); ++it) { - RegExp * def = RegExp::rule + const RegExp * def = RegExp::rule ( code->loc , in->mkDefault () , RegExp::nil() @@ -267,7 +267,7 @@ typedef union YYSTYPE { - re2c::RegExp * regexp; + const re2c::RegExp * regexp; const re2c::Code * code; char op; re2c::ExtOp extop; @@ -1619,7 +1619,7 @@ yyreduce: { in->fatal("condition or '<*>' required when using -c switch"); } - RegExp * rule = RegExp::rule + const RegExp * rule = RegExp::rule ( (yyvsp[(3) - (3)].code)->loc , (yyvsp[(1) - (3)].regexp) , (yyvsp[(2) - (3)].regexp) @@ -1636,7 +1636,7 @@ yyreduce: { if (opts->cFlag) in->fatal("condition or '<*>' required when using -c switch"); - RegExp * def = RegExp::rule + const RegExp * def = RegExp::rule ( (yyvsp[(2) - (2)].code)->loc , in->mkDefault () , RegExp::nil() @@ -1695,7 +1695,7 @@ yyreduce: { context_check(NULL); - RegExp * rule = RegExp::rule + const RegExp * rule = RegExp::rule ( (yyvsp[(7) - (7)].code)->loc , (yyvsp[(4) - (7)].regexp) , (yyvsp[(5) - (7)].regexp) @@ -1714,7 +1714,7 @@ yyreduce: assert((yyvsp[(7) - (7)].str)); context_check(NULL); Loc loc (in->get_fname (), in->get_cline ()); - RegExp * rule = RegExp::rule + const RegExp * rule = RegExp::rule ( loc , (yyvsp[(4) - (7)].regexp) , (yyvsp[(5) - (7)].regexp) @@ -2337,7 +2337,7 @@ void parse(Scanner& i, Output & o) { for (RuleList::const_iterator itOp = specStar.begin(); itOp != specStar.end(); ++itOp) { - RegExp *r = RegExp::rule_copy(*itOp, rank_counter.next()); + const RegExp *r = RegExp::rule_copy(*itOp, rank_counter.next()); it->second.add (r); } if (star_default) diff --git a/re2c/bootstrap/src/parse/y.tab.h b/re2c/bootstrap/src/parse/y.tab.h index 5a876216..061f7587 100644 --- a/re2c/bootstrap/src/parse/y.tab.h +++ b/re2c/bootstrap/src/parse/y.tab.h @@ -59,7 +59,7 @@ typedef union YYSTYPE { - re2c::RegExp * regexp; + const re2c::RegExp * regexp; const re2c::Code * code; char op; re2c::ExtOp extop; diff --git a/re2c/src/ir/dfa/determinization.cc b/re2c/src/ir/dfa/determinization.cc index 83f795d5..428e91d3 100644 --- a/re2c/src/ir/dfa/determinization.cc +++ b/re2c/src/ir/dfa/determinization.cc @@ -116,7 +116,7 @@ dfa_t::dfa_t(const nfa_t &nfa, const charset_t &charset) { nfa_state_t *m = n->value.ran.out; size_t c = 0; - for (Range *r = n->value.ran.ran; r; r = r->next ()) + for (const Range *r = n->value.ran.ran; r; r = r->next ()) { for (; charset[c] != r->lower(); ++c); for (; charset[c] != r->upper(); ++c) diff --git a/re2c/src/ir/nfa/nfa.cc b/re2c/src/ir/nfa/nfa.cc index 5769aa7b..1420e634 100644 --- a/re2c/src/ir/nfa/nfa.cc +++ b/re2c/src/ir/nfa/nfa.cc @@ -6,7 +6,7 @@ namespace re2c { static uint32_t calc_size(const RegExp *re); static nfa_state_t *compile(const RegExp *re, nfa_t &nfa, nfa_state_t *n); -nfa_t::nfa_t(RegExp *re) +nfa_t::nfa_t(const RegExp *re) : max_size(calc_size(re)) , size(0) , states(new nfa_state_t[max_size]) @@ -91,5 +91,4 @@ nfa_state_t *compile(const RegExp *re, nfa_t &nfa, nfa_state_t *t) return s; } - } // namespace re2c diff --git a/re2c/src/ir/nfa/nfa.h b/re2c/src/ir/nfa/nfa.h index aebf0d46..f2ed08d2 100644 --- a/re2c/src/ir/nfa/nfa.h +++ b/re2c/src/ir/nfa/nfa.h @@ -31,7 +31,7 @@ struct nfa_state_t struct { nfa_state_t *out; - Range *ran; + const Range *ran; } ran; struct { @@ -51,7 +51,7 @@ struct nfa_state_t value.alt.out2 = s2; mark = false; } - void ran(nfa_state_t *s, Range *r) + void ran(nfa_state_t *s, const Range *r) { type = RAN; value.ran.out = s; @@ -79,7 +79,7 @@ struct nfa_t nfa_state_t *states; nfa_state_t *root; - nfa_t(RegExp *re); + nfa_t(const RegExp *re); ~nfa_t(); FORBID_COPY(nfa_t); diff --git a/re2c/src/ir/regexp/encoding/range_suffix.cc b/re2c/src/ir/regexp/encoding/range_suffix.cc index c5e519c4..304f188b 100644 --- a/re2c/src/ir/regexp/encoding/range_suffix.cc +++ b/re2c/src/ir/regexp/encoding/range_suffix.cc @@ -4,11 +4,11 @@ namespace re2c { -static RegExp * emit (RangeSuffix * p, RegExp * re); +static const RegExp * emit (RangeSuffix * p, const RegExp * re); free_list RangeSuffix::freeList; -RegExp * to_regexp (RangeSuffix * p) +const RegExp * to_regexp (RangeSuffix * p) { return p ? emit (p, NULL) @@ -18,16 +18,16 @@ RegExp * to_regexp (RangeSuffix * p) /* * Build regexp from suffix tree. */ -RegExp * emit(RangeSuffix * p, RegExp * re) +const RegExp * emit(RangeSuffix * p, const RegExp * re) { if (p == NULL) return re; else { - RegExp * regexp = NULL; + const RegExp * regexp = NULL; for (; p != NULL; p = p->next) { - RegExp * re1 = doCat(RegExp::sym(Range::ran (p->l, p->h + 1)), re); + const RegExp * re1 = doCat(RegExp::sym(Range::ran (p->l, p->h + 1)), re); regexp = doAlt(regexp, emit(p->child, re1)); } return regexp; diff --git a/re2c/src/ir/regexp/encoding/range_suffix.h b/re2c/src/ir/regexp/encoding/range_suffix.h index ea46bdd8..f50ccb14 100644 --- a/re2c/src/ir/regexp/encoding/range_suffix.h +++ b/re2c/src/ir/regexp/encoding/range_suffix.h @@ -32,7 +32,7 @@ struct RangeSuffix FORBID_COPY (RangeSuffix); }; -RegExp * to_regexp (RangeSuffix * p); +const RegExp * to_regexp (RangeSuffix * p); } // namespace re2c diff --git a/re2c/src/ir/regexp/encoding/utf16/utf16_regexp.cc b/re2c/src/ir/regexp/encoding/utf16/utf16_regexp.cc index 02b00a50..c8b97fca 100644 --- a/re2c/src/ir/regexp/encoding/utf16/utf16_regexp.cc +++ b/re2c/src/ir/regexp/encoding/utf16/utf16_regexp.cc @@ -8,7 +8,7 @@ namespace re2c { -RegExp * UTF16Symbol(utf16::rune r) +const RegExp * UTF16Symbol(utf16::rune r) { if (r <= utf16::MAX_1WORD_RUNE) return RegExp::sym(Range::sym (r)); @@ -26,7 +26,7 @@ RegExp * UTF16Symbol(utf16::rune r) * them. We store partially built range in suffix tree, which * allows to eliminate common suffixes while building. */ -RegExp * UTF16Range(const Range * r) +const RegExp * UTF16Range(const Range * r) { RangeSuffix * root = NULL; for (; r != NULL; r = r->next ()) diff --git a/re2c/src/ir/regexp/encoding/utf16/utf16_regexp.h b/re2c/src/ir/regexp/encoding/utf16/utf16_regexp.h index d381de94..13c209c5 100644 --- a/re2c/src/ir/regexp/encoding/utf16/utf16_regexp.h +++ b/re2c/src/ir/regexp/encoding/utf16/utf16_regexp.h @@ -8,8 +8,8 @@ namespace re2c { class Range; class RegExp; -RegExp * UTF16Symbol(utf16::rune r); -RegExp * UTF16Range(const Range * r); +const RegExp * UTF16Symbol(utf16::rune r); +const RegExp * UTF16Range(const Range * r); } // namespace re2c diff --git a/re2c/src/ir/regexp/encoding/utf8/utf8_regexp.cc b/re2c/src/ir/regexp/encoding/utf8/utf8_regexp.cc index 70b864cd..e2e8c82a 100644 --- a/re2c/src/ir/regexp/encoding/utf8/utf8_regexp.cc +++ b/re2c/src/ir/regexp/encoding/utf8/utf8_regexp.cc @@ -8,11 +8,11 @@ namespace re2c { -RegExp * UTF8Symbol(utf8::rune r) +const RegExp * UTF8Symbol(utf8::rune r) { uint32_t chars[utf8::MAX_RUNE_LENGTH]; const uint32_t chars_count = utf8::rune_to_bytes(chars, r); - RegExp * re = RegExp::sym(Range::sym (chars[0])); + const RegExp * re = RegExp::sym(Range::sym (chars[0])); for (uint32_t i = 1; i < chars_count; ++i) re = RegExp::cat(re, RegExp::sym(Range::sym (chars[i]))); return re; @@ -24,7 +24,7 @@ RegExp * UTF8Symbol(utf8::rune r) * them. We store partially built range in suffix tree, which * allows to eliminate common suffixes while building. */ -RegExp * UTF8Range(const Range * r) +const RegExp * UTF8Range(const Range * r) { RangeSuffix * root = NULL; for (; r != NULL; r = r->next ()) diff --git a/re2c/src/ir/regexp/encoding/utf8/utf8_regexp.h b/re2c/src/ir/regexp/encoding/utf8/utf8_regexp.h index 676759a3..4295937c 100644 --- a/re2c/src/ir/regexp/encoding/utf8/utf8_regexp.h +++ b/re2c/src/ir/regexp/encoding/utf8/utf8_regexp.h @@ -8,8 +8,8 @@ namespace re2c { class Range; class RegExp; -RegExp * UTF8Symbol(utf8::rune r); -RegExp * UTF8Range(const Range * r); +const RegExp * UTF8Symbol(utf8::rune r); +const RegExp * UTF8Range(const Range * r); } // namespace re2c diff --git a/re2c/src/ir/regexp/regexp.cc b/re2c/src/ir/regexp/regexp.cc index f362778f..b260ff39 100644 --- a/re2c/src/ir/regexp/regexp.cc +++ b/re2c/src/ir/regexp/regexp.cc @@ -19,7 +19,7 @@ static uint32_t fixlen(const RegExp *re); free_list RegExp::flist; -RegExp *doAlt(RegExp *re1, RegExp *re2) +const RegExp *doAlt(const RegExp *re1, const RegExp *re2) { if (!re1) { return re2; @@ -30,7 +30,7 @@ RegExp *doAlt(RegExp *re1, RegExp *re2) return RegExp::alt(re1, re2); } -static RegExp *merge(RegExp *sym1, RegExp *sym2) +static const RegExp *merge(const RegExp *sym1, const RegExp *sym2) { if (!sym1) { return sym2; @@ -43,19 +43,19 @@ static RegExp *merge(RegExp *sym1, RegExp *sym2) sym2->pld.sym.range)); } -static RegExp *lift_sym(RegExp *&re) +static const RegExp *lift_sym(const RegExp *&re) { if (!re) { return NULL; } if (re->tag == RegExp::SYM) { - RegExp *sym = re; + const RegExp *sym = re; re = NULL; return sym; } if (re->tag == RegExp::ALT) { // second alternative cannot be SYM by construction - RegExp *alt1 = re->pld.alt.re1; + const RegExp *alt1 = re->pld.alt.re1; if (alt1 && alt1->tag == RegExp::SYM) { re = re->pld.alt.re2; return alt1; @@ -64,16 +64,16 @@ static RegExp *lift_sym(RegExp *&re) return NULL; } -RegExp *mkAlt(RegExp *re1, RegExp *re2) +const RegExp *mkAlt(const RegExp *re1, const RegExp *re2) { - RegExp *sym1 = lift_sym(re1); - RegExp *sym2 = lift_sym(re2); + const RegExp *sym1 = lift_sym(re1); + const RegExp *sym2 = lift_sym(re2); return doAlt( merge(sym1, sym2), doAlt(re1, re2)); } -RegExp *doCat(RegExp *re1, RegExp *re2) +const RegExp *doCat(const RegExp *re1, const RegExp *re2) { if (!re1) { return re2; @@ -84,7 +84,7 @@ RegExp *doCat(RegExp *re1, RegExp *re2) return RegExp::cat(re1, re2); } -RegExp *Scanner::schr(uint32_t c) const +const RegExp *Scanner::schr(uint32_t c) const { if (!opts->encoding.encode(c)) { fatalf("Bad code point: '0x%X'", c); @@ -96,18 +96,18 @@ RegExp *Scanner::schr(uint32_t c) const } } -RegExp *Scanner::ichr(uint32_t c) const +const RegExp *Scanner::ichr(uint32_t c) const { if (is_alpha(c)) { - RegExp *l = schr(to_lower_unsafe(c)); - RegExp *u = schr(to_upper_unsafe(c)); + const RegExp *l = schr(to_lower_unsafe(c)); + const RegExp *u = schr(to_upper_unsafe(c)); return mkAlt(l, u); } else { return schr(c); } } -RegExp *Scanner::cls(Range *r) const +const RegExp *Scanner::cls(const Range *r) const { if (!r) { switch (opts->empty_class_policy) { @@ -130,7 +130,7 @@ RegExp *Scanner::cls(Range *r) const } } -RegExp *Scanner::mkDiff(RegExp *re1, RegExp *re2) const +const RegExp *Scanner::mkDiff(const RegExp *re1, const RegExp *re2) const { if (re1 && re2 && re1->tag == RegExp::SYM @@ -143,7 +143,7 @@ RegExp *Scanner::mkDiff(RegExp *re1, RegExp *re2) const return NULL; } -RegExp *Scanner::mkDot() const +const RegExp *Scanner::mkDot() const { uint32_t c = '\n'; if (!opts->encoding.encode(c)) { @@ -164,7 +164,7 @@ RegExp *Scanner::mkDot() const * Also note that default range doesn't respect encoding policy * (the way invalid code points are treated). */ -RegExp *Scanner::mkDefault() const +const RegExp *Scanner::mkDefault() const { return RegExp::sym(Range::ran(0, opts->encoding.nCodeUnits())); @@ -180,9 +180,9 @@ RegExp *Scanner::mkDefault() const */ // see note [counted repetition expansion] -RegExp *repeat(RegExp *re, uint32_t n) +const RegExp *repeat(const RegExp *re, uint32_t n) { - RegExp *r = NULL; + const RegExp *r = NULL; for (uint32_t i = 0; i < n; ++i) { r = doCat(r, re); } @@ -190,10 +190,10 @@ RegExp *repeat(RegExp *re, uint32_t n) } // see note [counted repetition expansion] -RegExp *repeat_from_to(RegExp *re, uint32_t n, uint32_t m) +const RegExp *repeat_from_to(const RegExp *re, uint32_t n, uint32_t m) { - RegExp *r1 = repeat(re, n); - RegExp *r2 = NULL; + const RegExp *r1 = repeat(re, n); + const RegExp *r2 = NULL; for (uint32_t i = n; i < m; ++i) { r2 = mkAlt( RegExp::nil(), @@ -203,14 +203,14 @@ RegExp *repeat_from_to(RegExp *re, uint32_t n, uint32_t m) } // see note [counted repetition expansion] -RegExp *repeat_from(RegExp *re, uint32_t n) +const RegExp *repeat_from(const RegExp *re, uint32_t n) { return doCat( repeat(re, n), RegExp::iter(re)); } -RegExp* RegExp::rule(const Loc &loc, RegExp *r1, RegExp *r2, +const RegExp* RegExp::rule(const Loc &loc, const RegExp *r1, const RegExp *r2, rule_rank_t rank, const Code *code, const std::string *newcond) { RegExp *re = new RegExp(RULE); @@ -231,7 +231,7 @@ RegExp* RegExp::rule(const Loc &loc, RegExp *r1, RegExp *r2, // shallow-copies regexps, but deep-copies rule info // used to duplicate <*> rules in conditions -RegExp* RegExp::rule_copy(const RegExp *rule, rule_rank_t rank) +const RegExp* RegExp::rule_copy(const RegExp *rule, rule_rank_t rank) { RegExp *re = new RegExp(RULE); re->pld.rule.re = rule->pld.rule.re; diff --git a/re2c/src/ir/regexp/regexp.h b/re2c/src/ir/regexp/regexp.h index 39923c28..0cdef9e3 100644 --- a/re2c/src/ir/regexp/regexp.h +++ b/re2c/src/ir/regexp/regexp.h @@ -32,26 +32,26 @@ struct RegExp { struct { - Range *range; + const Range *range; } sym; struct { - RegExp *re1; - RegExp *re2; + const RegExp *re1; + const RegExp *re2; } alt; struct { - RegExp *re1; - RegExp *re2; + const RegExp *re1; + const RegExp *re2; } cat; struct { - RegExp *re; + const RegExp *re; } iter; struct { - RegExp *re; - RegExp *ctx; + const RegExp *re; + const RegExp *ctx; RuleInfo *info; } rule; }; @@ -61,39 +61,39 @@ struct RegExp tag_t tag; payload_t pld; - static RegExp *nil() + static const RegExp *nil() { return new RegExp(NIL); } - static RegExp *sym(Range *r) + static const RegExp *sym(const Range *r) { RegExp *re = new RegExp(SYM); re->pld.sym.range = r; return re; } - static RegExp *alt(RegExp *r1, RegExp *r2) + static const RegExp *alt(const RegExp *r1, const RegExp *r2) { RegExp *re = new RegExp(ALT); re->pld.alt.re1 = r1; re->pld.alt.re2 = r2; return re; } - static RegExp *cat(RegExp *r1, RegExp *r2) + static const RegExp *cat(const RegExp *r1, const RegExp *r2) { RegExp *re = new RegExp(CAT); re->pld.cat.re1 = r1; re->pld.cat.re2 = r2; return re; } - static RegExp *iter(RegExp *r) + static const RegExp *iter(const RegExp *r) { RegExp *re = new RegExp(ITER); re->pld.iter.re = r; return re; } - static RegExp *rule(const Loc &loc, RegExp *r1, RegExp *r2, + static const RegExp *rule(const Loc &loc, const RegExp *r1, const RegExp *r2, rule_rank_t rank, const Code *code, const std::string *newcond); - static RegExp *rule_copy(const RegExp *rule, rule_rank_t rank); + static const RegExp *rule_copy(const RegExp *rule, rule_rank_t rank); inline ~RegExp() { if (tag == RULE) { @@ -112,12 +112,12 @@ private: void split(const RegExp *re, std::set &cs); void nullable_rules(const RegExp *re, std::vector &rs); -RegExp *mkAlt(RegExp *re1, RegExp *re2); -RegExp *doAlt(RegExp *re1, RegExp *re2); -RegExp *doCat(RegExp *re1, RegExp *re2); -RegExp *repeat(RegExp *re, uint32_t n); -RegExp *repeat_from_to(RegExp *re, uint32_t n, uint32_t m); -RegExp *repeat_from(RegExp *re, uint32_t n); +const RegExp *mkAlt(const RegExp *re1, const RegExp *re2); +const RegExp *doAlt(const RegExp *re1, const RegExp *re2); +const RegExp *doCat(const RegExp *re1, const RegExp *re2); +const RegExp *repeat(const RegExp *re, uint32_t n); +const RegExp *repeat_from_to(const RegExp *re, uint32_t n, uint32_t m); +const RegExp *repeat_from(const RegExp *re, uint32_t n); } // end namespace re2c diff --git a/re2c/src/ir/regexp/split_charset.cc b/re2c/src/ir/regexp/split_charset.cc index ce0dd759..8056085b 100644 --- a/re2c/src/ir/regexp/split_charset.cc +++ b/re2c/src/ir/regexp/split_charset.cc @@ -12,7 +12,7 @@ void split(const RegExp* re, std::set &cs) case RegExp::NIL: break; case RegExp::SYM: - for (Range *r = re->pld.sym.range; r; r = r->next()) { + for (const Range *r = re->pld.sym.range; r; r = r->next()) { cs.insert(r->lower()); cs.insert(r->upper()); } diff --git a/re2c/src/parse/lex.re b/re2c/src/parse/lex.re index cf1c2642..93602175 100644 --- a/re2c/src/parse/lex.re +++ b/re2c/src/parse/lex.re @@ -352,7 +352,7 @@ start: yylval.str = new std::string (tok, tok_len()); return TOKEN_ID; } else { - RegExp *r = NULL; + const RegExp *r = NULL; const bool casing = opts->bCaseInsensitive || opts->bCaseInverted; for (char *s = tok; s < cur; ++s) { const uint32_t c = static_cast(*s); @@ -555,7 +555,7 @@ static void escape (std::string & dest, const std::string & src) } } -RegExp *Scanner::lex_cls(bool neg) +const RegExp *Scanner::lex_cls(bool neg) { Range *r = NULL, *s; uint32_t u, l; @@ -651,9 +651,9 @@ uint32_t Scanner::lex_str_chr(char quote, bool &end) */ } -RegExp *Scanner::lex_str(char quote, bool casing) +const RegExp *Scanner::lex_str(char quote, bool casing) { - RegExp *r = NULL; + const RegExp *r = NULL; for (bool end;;) { const uint32_t c = lex_str_chr(quote, end); if (end) { diff --git a/re2c/src/parse/parser.h b/re2c/src/parse/parser.h index 53b7dd70..69aeacf8 100644 --- a/re2c/src/parse/parser.h +++ b/re2c/src/parse/parser.h @@ -17,11 +17,11 @@ extern void parse(Scanner &, Output &); extern void parse_cleanup(); typedef std::set CondList; -typedef std::list RuleList; +typedef std::list RuleList; typedef std::map SpecMap; typedef std::map > SetupMap; typedef std::map DefaultMap; -typedef std::map symbol_table_t; +typedef std::map symbol_table_t; } // namespace re2c diff --git a/re2c/src/parse/parser.ypp b/re2c/src/parse/parser.ypp index e959421b..cfa8d593 100644 --- a/re2c/src/parse/parser.ypp +++ b/re2c/src/parse/parser.ypp @@ -48,9 +48,9 @@ static counter_t rank_counter; static std::vector condnames; static re2c::SpecMap specMap; static Spec spec; -static RegExp *specNone = NULL; +static const RegExp *specNone = NULL; static RuleList specStar; -static RegExp *star_default = NULL; +static const RegExp *star_default = NULL; static Scanner *in = NULL; static Scanner::ParseMode parseMode; static SetupMap ruleSetupMap; @@ -83,8 +83,8 @@ void context_none(CondList *clist) void context_rule ( CondList * clist , const Loc & loc - , RegExp * expr - , RegExp * look + , const RegExp * expr + , const RegExp * look , const Code * code , const std::string * newcond ) @@ -97,7 +97,7 @@ void context_rule condnames.push_back (*it); } - RegExp *rule = RegExp::rule + const RegExp *rule = RegExp::rule ( loc , expr , look @@ -134,7 +134,7 @@ void default_rule(CondList *clist, const Code * code) context_check(clist); for(CondList::const_iterator it = clist->begin(); it != clist->end(); ++it) { - RegExp * def = RegExp::rule + const RegExp * def = RegExp::rule ( code->loc , in->mkDefault () , RegExp::nil() @@ -155,7 +155,7 @@ void default_rule(CondList *clist, const Code * code) %start spec %union { - re2c::RegExp * regexp; + const re2c::RegExp * regexp; const re2c::Code * code; char op; re2c::ExtOp extop; @@ -230,7 +230,7 @@ rule: { in->fatal("condition or '<*>' required when using -c switch"); } - RegExp * rule = RegExp::rule + const RegExp * rule = RegExp::rule ( $3->loc , $1 , $2 @@ -244,7 +244,7 @@ rule: { if (opts->cFlag) in->fatal("condition or '<*>' required when using -c switch"); - RegExp * def = RegExp::rule + const RegExp * def = RegExp::rule ( $2->loc , in->mkDefault () , RegExp::nil() @@ -285,7 +285,7 @@ rule: | '<' TOKEN_STAR '>' expr look newcond TOKEN_CODE { context_check(NULL); - RegExp * rule = RegExp::rule + const RegExp * rule = RegExp::rule ( $7->loc , $4 , $5 @@ -301,7 +301,7 @@ rule: assert($7); context_check(NULL); Loc loc (in->get_fname (), in->get_cline ()); - RegExp * rule = RegExp::rule + const RegExp * rule = RegExp::rule ( loc , $4 , $5 @@ -649,7 +649,7 @@ void parse(Scanner& i, Output & o) { for (RuleList::const_iterator itOp = specStar.begin(); itOp != specStar.end(); ++itOp) { - RegExp *r = RegExp::rule_copy(*itOp, rank_counter.next()); + const RegExp *r = RegExp::rule_copy(*itOp, rank_counter.next()); it->second.add (r); } if (star_default) diff --git a/re2c/src/parse/scanner.h b/re2c/src/parse/scanner.h index d13eeaa1..d17f01bb 100644 --- a/re2c/src/parse/scanner.h +++ b/re2c/src/parse/scanner.h @@ -62,11 +62,11 @@ private: void set_sourceline (); uint32_t lex_cls_chr(); uint32_t lex_str_chr(char quote, bool &end); - RegExp *lex_cls(bool neg); - RegExp *lex_str(char quote, bool casing); - RegExp *schr(uint32_t c) const; - RegExp *ichr(uint32_t c) const; - RegExp *cls(Range *r) const; + const RegExp *lex_cls(bool neg); + const RegExp *lex_str(char quote, bool casing); + const RegExp *schr(uint32_t c) const; + const RegExp *ichr(uint32_t c) const; + const RegExp *cls(const Range *r) const; void lex_conf (); void lex_conf_assign (); @@ -104,9 +104,9 @@ public: void fatal(const char*) const; void fatal(ptrdiff_t, const char*) const; - RegExp * mkDiff (RegExp * e1, RegExp * e2) const; - RegExp * mkDot () const; - RegExp * mkDefault () const; + const RegExp * mkDiff (const RegExp * e1, const RegExp * e2) const; + const RegExp * mkDot () const; + const RegExp * mkDefault () const; FORBID_COPY (Scanner); }; diff --git a/re2c/src/parse/spec.h b/re2c/src/parse/spec.h index b34e7410..88d8ceed 100644 --- a/re2c/src/parse/spec.h +++ b/re2c/src/parse/spec.h @@ -17,7 +17,7 @@ static bool is_def(const RuleInfo *r) struct Spec { - RegExp * re; + const RegExp * re; rules_t rules; Spec () @@ -34,7 +34,7 @@ struct Spec rules = spec.rules; return *this; } - bool add_def (RegExp * r) + bool add_def (const RegExp * r) { if (std::find_if(rules.begin(), rules.end(), is_def) != rules.end()) { @@ -46,7 +46,7 @@ struct Spec return true; } } - void add (RegExp * r) + void add (const RegExp * r) { rules.push_back(r->pld.rule.info); re = mkAlt (re, r);