From: helly Date: Sun, 1 Jan 2006 02:52:01 +0000 (+0000) Subject: - Constify X-Git-Tag: 0.13.6~522 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=871e6c1a6018f1c1e0268ecf4209ed727cf7e929;p=re2c - Constify - Provide pendantic stuff with PEDANTIC define only, which allows to check the code, however we don't want this functions otherwise - Change from custom type label_list to std::set --- diff --git a/actions.cc b/actions.cc index 1952c88c..74afc423 100644 --- a/actions.cc +++ b/actions.cc @@ -75,7 +75,7 @@ uint RegExp::fixedLength() return ~0; } -char *NullOp::type = "NullOp"; +const char *NullOp::type = "NullOp"; void NullOp::calcSize(Char*) { @@ -233,7 +233,7 @@ MatchOp *merge(MatchOp *m1, MatchOp *m2) return new MatchOp(doUnion(m1->match, m2->match)); } -char *MatchOp::type = "MatchOp"; +const char *MatchOp::type = "MatchOp"; void MatchOp::display(std::ostream &o) const { @@ -371,7 +371,7 @@ RegExp *mkAlt(RegExp *e1, RegExp *e2) return doAlt(merge(m1, m2), doAlt(e1, e2)); } -char *AltOp::type = "AltOp"; +const char *AltOp::type = "AltOp"; void AltOp::calcSize(Char *rep) { @@ -408,7 +408,7 @@ void AltOp::split(CharSet &s) exp2->split(s); } -char *CatOp::type = "CatOp"; +const char *CatOp::type = "CatOp"; void CatOp::calcSize(Char *rep) { @@ -440,7 +440,7 @@ void CatOp::split(CharSet &s) exp2->split(s); } -char *CloseOp::type = "CloseOp"; +const char *CloseOp::type = "CloseOp"; void CloseOp::calcSize(Char *rep) { @@ -461,7 +461,7 @@ void CloseOp::split(CharSet &s) exp->split(s); } -char *CloseVOp::type = "CloseVOp"; +const char *CloseVOp::type = "CloseVOp"; void CloseVOp::calcSize(Char *rep) { @@ -544,14 +544,18 @@ uint Scanner::unescape(SubStr &s) const || !(p2 = strchr(hex, tolower(s.str[1])))) { fatal("Illegal hexadecimal character code"); + return ~0; + } + else + { + s.len -= 2; + s.str += 2; + + uint v = (uint)((p1 - hex) << 4) + + (uint)((p2 - hex)); + + return v; } - s.len -= 2; - s.str += 2; - - uint v = (uint)((p1 - hex) << 4) - + (uint)((p2 - hex)); - - return v; } case 'X': @@ -770,10 +774,15 @@ RegExp * Scanner::mkDot() const return inv; } -char *RuleOp::type = "RuleOp"; +const char *RuleOp::type = "RuleOp"; RuleOp::RuleOp(RegExp *e, RegExp *c, Token *t, uint a) - : exp(e), ctx(c), ins(NULL), accept(a), code(t) + : exp(e) + , ctx(c) + , ins(NULL) + , accept(a) + , code(t) + , line(0) { ; } @@ -802,8 +811,6 @@ void RuleOp::split(CharSet &s) ctx->split(s); } -extern void printSpan(std::ostream&, uint, uint); - void optimize(Ins *i) { while (!isMarked(i)) diff --git a/bootstrap/parser.cc b/bootstrap/parser.cc index a53764d4..8a241d56 100644 --- a/bootstrap/parser.cc +++ b/bootstrap/parser.cc @@ -100,13 +100,15 @@ #include "parser.h" #include "basics.h" +#define YYMALLOC malloc +#define YYFREE free + using namespace re2c; extern "C" { -int yyparse(); int yylex(); -void yyerror(char*); +void yyerror(const char*); } static re2c::uint accept; @@ -155,7 +157,7 @@ static char* strdup(const char* s) #endif #if ! defined (YYSTYPE) && ! defined (YYSTYPE_IS_DECLARED) -#line 56 "parser.y" +#line 58 "parser.y" typedef union YYSTYPE { re2c::Symbol *symbol; re2c::RegExp *regexp; @@ -166,7 +168,7 @@ typedef union YYSTYPE { re2c::Str *str; } YYSTYPE; /* Line 196 of yacc.c. */ -#line 170 "parser.cc" +#line 172 "parser.cc" # define yystype YYSTYPE /* obsolescent; will be withdrawn */ # define YYSTYPE_IS_DECLARED 1 # define YYSTYPE_IS_TRIVIAL 1 @@ -178,7 +180,7 @@ typedef union YYSTYPE { /* Line 219 of yacc.c. */ -#line 182 "parser.cc" +#line 184 "parser.cc" #if ! defined (YYSIZE_T) && defined (__SIZE_TYPE__) # define YYSIZE_T __SIZE_TYPE__ @@ -405,9 +407,9 @@ static const yysigned_char yyrhs[] = /* YYRLINE[YYN] -- source line where rule number YYN was defined. */ static const unsigned char yyrline[] = { - 0, 82, 82, 84, 86, 89, 93, 95, 99, 104, - 105, 109, 111, 115, 117, 124, 126, 130, 132, 146, - 152, 154, 158, 162, 164, 166 + 0, 84, 84, 86, 88, 91, 95, 97, 101, 106, + 107, 111, 113, 117, 119, 126, 128, 132, 134, 148, + 154, 156, 160, 164, 166, 168 }; #endif @@ -1183,65 +1185,65 @@ yyreduce: switch (yyn) { case 2: -#line 82 "parser.y" +#line 84 "parser.y" { accept = 0; spec = NULL; } break; case 3: -#line 85 "parser.y" +#line 87 "parser.y" { spec = spec? mkAlt(spec, (yyvsp[0].regexp)) : (yyvsp[0].regexp); } break; case 5: -#line 90 "parser.y" +#line 92 "parser.y" { if((yyvsp[-3].symbol)->re) in->fatal("sym already defined"); (yyvsp[-3].symbol)->re = (yyvsp[-1].regexp); } break; case 6: -#line 94 "parser.y" +#line 96 "parser.y" { in->config((yyvsp[-3].str), (yyvsp[-1].str)); } break; case 7: -#line 96 "parser.y" +#line 98 "parser.y" { in->config((yyvsp[-3].str), (yyvsp[-1].number)); } break; case 8: -#line 100 "parser.y" +#line 102 "parser.y" { (yyval.regexp) = new RuleOp((yyvsp[-2].regexp), (yyvsp[-1].regexp), (yyvsp[0].token), accept++); } break; case 9: -#line 104 "parser.y" +#line 106 "parser.y" { (yyval.regexp) = new NullOp; } break; case 10: -#line 106 "parser.y" +#line 108 "parser.y" { (yyval.regexp) = (yyvsp[0].regexp); } break; case 11: -#line 110 "parser.y" +#line 112 "parser.y" { (yyval.regexp) = (yyvsp[0].regexp); } break; case 12: -#line 112 "parser.y" +#line 114 "parser.y" { (yyval.regexp) = mkAlt((yyvsp[-2].regexp), (yyvsp[0].regexp)); } break; case 13: -#line 116 "parser.y" +#line 118 "parser.y" { (yyval.regexp) = (yyvsp[0].regexp); } break; case 14: -#line 118 "parser.y" +#line 120 "parser.y" { (yyval.regexp) = mkDiff((yyvsp[-2].regexp), (yyvsp[0].regexp)); if(!(yyval.regexp)) in->fatal("can only difference char sets"); @@ -1249,22 +1251,22 @@ yyreduce: break; case 15: -#line 125 "parser.y" +#line 127 "parser.y" { (yyval.regexp) = (yyvsp[0].regexp); } break; case 16: -#line 127 "parser.y" +#line 129 "parser.y" { (yyval.regexp) = new CatOp((yyvsp[-1].regexp), (yyvsp[0].regexp)); } break; case 17: -#line 131 "parser.y" +#line 133 "parser.y" { (yyval.regexp) = (yyvsp[0].regexp); } break; case 18: -#line 133 "parser.y" +#line 135 "parser.y" { switch((yyvsp[0].op)){ case '*': @@ -1281,41 +1283,41 @@ yyreduce: break; case 19: -#line 147 "parser.y" +#line 149 "parser.y" { (yyval.regexp) = new CloseVOp((yyvsp[-1].regexp), (yyvsp[0].extop).minsize, (yyvsp[0].extop).maxsize); } break; case 20: -#line 153 "parser.y" +#line 155 "parser.y" { (yyval.op) = (yyvsp[0].op); } break; case 21: -#line 155 "parser.y" +#line 157 "parser.y" { (yyval.op) = ((yyvsp[-1].op) == (yyvsp[0].op)) ? (yyvsp[-1].op) : '*'; } break; case 22: -#line 159 "parser.y" +#line 161 "parser.y" { if(!(yyvsp[0].symbol)->re) in->fatal("can't find symbol"); (yyval.regexp) = (yyvsp[0].symbol)->re; } break; case 23: -#line 163 "parser.y" +#line 165 "parser.y" { (yyval.regexp) = (yyvsp[0].regexp); } break; case 24: -#line 165 "parser.y" +#line 167 "parser.y" { (yyval.regexp) = (yyvsp[0].regexp); } break; case 25: -#line 167 "parser.y" +#line 169 "parser.y" { (yyval.regexp) = (yyvsp[-1].regexp); } break; @@ -1324,7 +1326,7 @@ yyreduce: } /* Line 1126 of yacc.c. */ -#line 1328 "parser.cc" +#line 1330 "parser.cc" yyvsp -= yylen; yyssp -= yylen; @@ -1592,11 +1594,12 @@ yyreturn: } -#line 170 "parser.y" +#line 172 "parser.y" extern "C" { -void yyerror(char* s){ +void yyerror(const char* s) +{ in->fatal(s); } diff --git a/bootstrap/y.tab.h b/bootstrap/y.tab.h index 326185c2..1c3e5849 100644 --- a/bootstrap/y.tab.h +++ b/bootstrap/y.tab.h @@ -55,7 +55,7 @@ #if ! defined (YYSTYPE) && ! defined (YYSTYPE_IS_DECLARED) -#line 56 "parser.y" +#line 58 "parser.y" typedef union YYSTYPE { re2c::Symbol *symbol; re2c::RegExp *regexp; diff --git a/code.cc b/code.cc index 76f836e7..ecb2d4fd 100644 --- a/code.cc +++ b/code.cc @@ -160,7 +160,12 @@ bool matches(const Go *g1, const State *s1, const Go *g2, const State *s2) BitMap *BitMap::first = NULL; -BitMap::BitMap(const Go *g, const State *x) : go(g), on(x), next(first) +BitMap::BitMap(const Go *g, const State *x) + : go(g) + , on(x) + , next(first) + , i(0) + , m(0) { first = this; } @@ -262,10 +267,10 @@ void genGoTo(std::ostream &o, uint ind, const State *from, const State *to, bool o << indent(ind) << "goto yy" << to->label << ";\n"; ++oline; - vUsedLabels.append(to->label); + vUsedLabels.insert(to->label); } -void genIf(std::ostream &o, uint ind, char *cmp, uint v, bool &readCh) +void genIf(std::ostream &o, uint ind, const char *cmp, uint v, bool &readCh) { if (readCh) { @@ -282,17 +287,21 @@ void genIf(std::ostream &o, uint ind, char *cmp, uint v, bool &readCh) o << ") "; } -static void need(std::ostream &o, uint ind, uint n, bool & readCh, uint mask) +static void need(std::ostream &o, uint ind, uint n, bool & readCh) { uint fillIndex; bool hasFillIndex = (0<=vFillIndexes); - if ( hasFillIndex == true ) + if (hasFillIndex) { fillIndex = vFillIndexes++; o << indent(ind) << "YYSETSTATE(" << fillIndex << ");\n"; ++oline; } + else + { + fillIndex = ~0; + } if (n == 1) { @@ -338,7 +347,7 @@ void Match::emit(std::ostream &o, uint ind, bool &readCh) const if (state->link) { - need(o, ind, state->depth, readCh, 0); + need(o, ind, state->depth, readCh); } } @@ -349,7 +358,7 @@ void Enter::emit(std::ostream &o, uint ind, bool &readCh) const o << indent(ind) << "++YYCURSOR;\n"; o << "yy" << label << ":\n"; oline += 2; - need(o, ind, state->depth, readCh, 0); + need(o, ind, state->depth, readCh); } else { @@ -373,7 +382,7 @@ void Save::emit(std::ostream &o, uint ind, bool &readCh) const { o << indent(ind) << "YYMARKER = ++YYCURSOR;\n"; ++oline; - need(o, ind, state->depth, readCh, 0); + need(o, ind, state->depth, readCh); } else { @@ -431,7 +440,7 @@ Rule::Rule(State *s, RuleOp *r) : Action(s), rule(r) ; } -void Rule::emit(std::ostream &o, uint ind, bool &readCh) const +void Rule::emit(std::ostream &o, uint ind, bool &) const { uint back = rule->ctx->fixedLength(); @@ -790,7 +799,7 @@ void Go::genGoto(std::ostream &o, uint ind, const State *from, const State *next void State::emit(std::ostream &o, uint ind, bool &readCh) const { - if (vUsedLabels.contains(label)) + if (vUsedLabels.count(label)) { o << "yy" << label << ":\n"; oline++; @@ -890,11 +899,26 @@ public: SCC(uint); ~SCC(); void traverse(State*); + +#ifdef PEDANTIC +private: + SCC(const SCC& oth) + : top(oth.top) + , stk(oth.stk) + { + } + SCC& operator = (const SCC& oth) + { + new(this) SCC(oth); + return *this; + } +#endif }; SCC::SCC(uint size) + : top(new State * [size]) + , stk(top) { - top = stk = new State * [size]; } SCC::~SCC() @@ -983,7 +1007,7 @@ uint maxDist(State *s) if (!t->link) // marked as non-key state { - if (t->depth == -1) + if (t->depth == cInfinity) { t->depth = maxDist(t); } @@ -1248,7 +1272,7 @@ void DFA::emit(std::ostream &o, uint ind) uint start_label = label; - vUsedLabels.append(label); + vUsedLabels.insert(label); (void) new Enter(head, label++); for (s = head; s; s = s->next) @@ -1258,8 +1282,8 @@ void DFA::emit(std::ostream &o, uint ind) null_stream noWhere; unsigned int nOrgOline = oline; - int maxFillIndexes = vFillIndexes; - int orgVFillIndexes = vFillIndexes; + uint maxFillIndexes = vFillIndexes; + uint orgVFillIndexes = vFillIndexes; for (s = head; s; s = s->next) { diff --git a/code.h b/code.h index 89ea7f8e..a27cf976 100755 --- a/code.h +++ b/code.h @@ -26,40 +26,62 @@ public: static void stats(); BitMap(const Go*, const State*); ~BitMap(); + +#if PEDANTIC + BitMap(const BitMap& oth) + : go(oth.go) + , on(oth.on) + , next(oth.next) + , i(oth.i) + , m(oth.m) + { + } + BitMap& operator = (const BitMap& oth) + { + new(this) BitMap(oth); + return *this; + } +#endif }; -class null_stream: public std::ostream +template +class basic_null_streambuf + : public std::basic_streambuf { public: - null_stream() - : std::ostream(&ns) + basic_null_streambuf() + : std::basic_streambuf() + { + } +}; + +template +class basic_null_stream + : protected basic_null_streambuf + , public std::basic_ostream +{ +public: + basic_null_stream() + : basic_null_streambuf() + , std::basic_ostream(static_cast*>(this)) { } - null_stream& put(char_type) + basic_null_stream& put(char_type) { // nothing to do return *this; } - null_stream& write(const char_type *, std::streamsize) + basic_null_stream& write(const char_type *, std::streamsize) { // nothing to do return *this; } - -protected: - class null_streambuf: public std::streambuf - { - public: - null_streambuf() - : std::streambuf() - { - } - }; - null_streambuf ns; }; +typedef basic_null_stream null_stream; + } // end namespace re2c #endif diff --git a/dfa.cc b/dfa.cc index 833d99c1..8df1837d 100644 --- a/dfa.cc +++ b/dfa.cc @@ -165,10 +165,18 @@ std::ostream& operator<<(std::ostream &o, const DFA &dfa) return o; } -State::State() : rule(NULL), link(NULL), kCount(0), kernel(NULL), action(NULL) +State::State() + : label(0) + , rule(NULL) + , next(0) + , link(NULL) + , depth(0) + , kCount(0) + , kernel(NULL) + , isBase(0) + , go() + , action(NULL) { - go.nSpans = 0; - go.span = NULL; } State::~State() @@ -207,17 +215,18 @@ struct GoTo }; DFA::DFA(Ins *ins, uint ni, uint lb, uint ub, Char *rep) - : lbChar(lb), ubChar(ub) + : lbChar(lb) + , ubChar(ub) + , nStates(0) + , head(NULL) + , tail(&head) + , toDo(NULL) { Ins **work = new Ins * [ni + 1]; uint nc = ub - lb; GoTo *goTo = new GoTo[nc]; Span *span = new Span[nc]; memset((char*) goTo, 0, nc*sizeof(GoTo)); - tail = &head; - head = NULL; - nStates = 0; - toDo = NULL; findState(work, closure(work, &ins[0]) - work); while (toDo) diff --git a/dfa.h b/dfa.h index 0fdb9ea4..58b7a65a 100644 --- a/dfa.h +++ b/dfa.h @@ -24,10 +24,25 @@ public: public: Action(State*); + virtual ~Action(); + virtual void emit(std::ostream&, uint, bool&) const = 0; virtual bool isRule() const; virtual bool isMatch() const; virtual bool readAhead() const; + +#ifdef PEDANTIC +protected: + Action(const Action& oth) + : state(oth.state) + { + } + Action& operator = (const Action& oth) + { + state = oth.state; + return *this; + } +#endif }; class Match: public Action @@ -81,6 +96,22 @@ public: public: Accept(State*, uint, uint*, State**); void emit(std::ostream&, uint, bool&) const; + +#ifdef PEDANTIC +private: + Accept(const Accept& oth) + : Action(oth) + , nRules(oth.nRules) + , saves(oth.saves) + , rules(oth.rules) + { + } + Accept& operator=(const Accept& oth) + { + new(this) Accept(oth); + return *this; + } +#endif }; class Rule: public Action @@ -93,6 +124,20 @@ public: Rule(State*, RuleOp*); void emit(std::ostream&, uint, bool&) const; bool isRule() const; + +#ifdef PEDANTIC +private: + Rule (const Rule& oth) + : Action(oth) + , rule(oth.rule) + { + } + Rule& operator=(const Rule& oth) + { + new(this) Rule(oth); + return *this; + } +#endif }; class Span @@ -145,6 +190,28 @@ public: void emit(std::ostream&, uint, bool&) const; friend std::ostream& operator<<(std::ostream&, const State&); friend std::ostream& operator<<(std::ostream&, const State*); + +#ifdef PEDANTIC +private: + State(const State& oth) + : label(oth.label) + , rule(oth.rule) + , next(oth.next) + , link(oth.link) + , depth(oth.depth) + , kCount(oth.kCount) + , kernel(oth.kernel) + , isBase(oth.isBase) + , go(oth.go) + , action(oth.action) + { + } + State& operator = (const State& oth) + { + new(this) State(oth); + return *this; + } +#endif }; class DFA @@ -170,6 +237,23 @@ public: friend std::ostream& operator<<(std::ostream&, const DFA&); friend std::ostream& operator<<(std::ostream&, const DFA*); + +#ifdef PEDANTIC + DFA(const DFA& oth) + : lbChar(oth.lbChar) + , ubChar(oth.ubChar) + , nStates(oth.nStates) + , head(oth.head) + , tail(oth.tail) + , toDo(oth.toDo) + { + } + DFA& operator = (const DFA& oth) + { + new(this) DFA(oth); + return *this; + } +#endif }; inline Action::Action(State *s) : state(s) @@ -177,6 +261,10 @@ inline Action::Action(State *s) : state(s) s->action = this; } +inline Action::~Action() +{ +} + inline bool Action::isRule() const { return false; diff --git a/globals.h b/globals.h index 4cc448c5..3010acc4 100644 --- a/globals.h +++ b/globals.h @@ -6,30 +6,10 @@ #include #include -template -class label_list: protected std::set<_Ty> -{ -public: - label_list() - : std::set<_Ty>() - { - } - - void append(const _Ty &val) - { - std::set<_Ty>::insert(val); - } - - bool contains(const _Ty &val) - { - return find(val) != std::set<_Ty>::end(); - } -}; - namespace re2c { -extern char *fileName; +extern const char *fileName; extern char *outputFileName; extern bool bFlag; extern bool dFlag; @@ -49,7 +29,7 @@ extern uint ebc2asc[256]; extern uint *xlat, *talx; extern int vFillIndexes; -extern label_list vUsedLabels; +extern std::set vUsedLabels; extern uint nRealChars; diff --git a/main.cc b/main.cc index 1613eb3b..764bcf3b 100644 --- a/main.cc +++ b/main.cc @@ -18,7 +18,7 @@ namespace re2c { -char *fileName = 0; +const char *fileName = 0; char *outputFileName = 0; bool bFlag = false; bool dFlag = false; @@ -33,7 +33,7 @@ uint topIndent = 0; uint nRealChars = 256; int vFillIndexes = -1; -label_list vUsedLabels; +std::set vUsedLabels; using namespace std; @@ -187,7 +187,8 @@ int main(int argc, char *argv[]) } // set up the input stream - istream* input = 0; + //istream* input = 0; + basic_istream *input = 0; ifstream inputFile; diff --git a/parser.h b/parser.h index 1827367f..7abc0d37 100644 --- a/parser.h +++ b/parser.h @@ -29,8 +29,8 @@ public: protected: Symbol(const SubStr& str) - : name(str) - , re(NULL) + : re(NULL) + , name(str) { } @@ -39,6 +39,19 @@ private: static SymbolTable symbol_table; Str name; + +#if PEDANTIC + Symbol(const Symbol& oth) + : re(oth.re) + , name(oth.name) + { + } + Symbol& operator = (const Symbol& oth) + { + new(this) Symbol(oth); + return *this; + } +#endif }; void line_source(unsigned int, std::ostream&); diff --git a/parser.y b/parser.y index f379c94a..4b29951e 100644 --- a/parser.y +++ b/parser.y @@ -15,13 +15,15 @@ #include "parser.h" #include "basics.h" +#define YYMALLOC malloc +#define YYFREE free + using namespace re2c; extern "C" { -int yyparse(); int yylex(); -void yyerror(char*); +void yyerror(const char*); } static re2c::uint accept; @@ -170,7 +172,8 @@ primary : ID %% extern "C" { -void yyerror(char* s){ +void yyerror(const char* s) +{ in->fatal(s); } diff --git a/re.h b/re.h index c01e2ddd..089f1ea2 100644 --- a/re.h +++ b/re.h @@ -63,8 +63,13 @@ public: uint size; public: - virtual char *typeOf() = 0; - RegExp *isA(char *t) + RegExp() : size(0) + { + } + + virtual ~RegExp() {} + virtual const char *typeOf() = 0; + RegExp *isA(const char *t) { return typeOf() == t ? this : NULL; } @@ -93,10 +98,10 @@ class NullOp: public RegExp { public: - static char *type; + static const char *type; public: - char *typeOf() + const char *typeOf() { return type; } @@ -115,14 +120,15 @@ class MatchOp: public RegExp { public: - static char *type; + static const char *type; Range *match; public: MatchOp(Range *m) : match(m) - { } + { + } - char *typeOf() + const char *typeOf() { return type; } @@ -132,25 +138,41 @@ public: uint fixedLength(); void compile(Char*, Ins*); void display(std::ostream&) const; + +#ifdef PEDANTIC +private: + MatchOp(const MatchOp& oth) + : RegExp(oth) + , match(oth.match) + { + } + + MatchOp& operator = (const MatchOp& oth) + { + new(this) MatchOp(oth); + return *this; + } +#endif }; class RuleOp: public RegExp { +public: + static const char *type; private: - RegExp *exp; + RegExp *exp; public: - RegExp *ctx; - static char *type; - Ins *ins; - uint accept; - Token *code; - uint line; + RegExp *ctx; + Ins *ins; + uint accept; + Token *code; + uint line; public: RuleOp(RegExp*, RegExp*, Token*, uint); - char *typeOf() + const char *typeOf() { return type; } @@ -162,6 +184,25 @@ public: { o << exp << "/" << ctx << ";"; } + +#ifdef PEDANTIC +private: + RuleOp(const RuleOp& oth) + : RegExp(oth) + , exp(oth.exp) + , ctx(oth.ctx) + , ins(oth.ins) + , accept(oth.accept) + , code(oth.code) + , line(oth.line) + { + } + RuleOp& operator = (const RuleOp& oth) + { + new(this) RuleOp(oth); + return *this; + } +#endif }; class AltOp: public RegExp @@ -171,16 +212,16 @@ private: RegExp *exp1, *exp2; public: - static char *type; + static const char *type; public: AltOp(RegExp *e1, RegExp *e2) + : exp1(e1) + , exp2(e2) { - exp1 = e1; - exp2 = e2; } - char *typeOf() + const char *typeOf() { return type; } @@ -195,6 +236,21 @@ public: } friend RegExp *mkAlt(RegExp*, RegExp*); + +#ifdef PEDANTIC +private: + AltOp(const AltOp& oth) + : RegExp(oth) + , exp1(oth.exp1) + , exp2(oth.exp2) + { + } + AltOp& operator = (const AltOp& oth) + { + new(this) AltOp(oth); + return *this; + } +#endif }; class CatOp: public RegExp @@ -204,16 +260,16 @@ private: RegExp *exp1, *exp2; public: - static char *type; + static const char *type; public: CatOp(RegExp *e1, RegExp *e2) + : exp1(e1) + , exp2(e2) { - exp1 = e1; - exp2 = e2; } - char *typeOf() + const char *typeOf() { return type; } @@ -226,6 +282,21 @@ public: { o << exp1 << exp2; } + +#ifdef PEDANTIC +private: + CatOp(const CatOp& oth) + : RegExp(oth) + , exp1(oth.exp1) + , exp2(oth.exp2) + { + } + CatOp& operator = (const CatOp& oth) + { + new(this) CatOp(oth); + return *this; + } +#endif }; class CloseOp: public RegExp @@ -235,15 +306,15 @@ private: RegExp *exp; public: - static char *type; + static const char *type; public: CloseOp(RegExp *e) + : exp(e) { - exp = e; } - char *typeOf() + const char *typeOf() { return type; } @@ -255,6 +326,20 @@ public: { o << exp << "+"; } + +#ifdef PEDANTIC +private: + CloseOp(const CloseOp& oth) + : RegExp(oth) + , exp(oth.exp) + { + } + CloseOp& operator = (const CloseOp& oth) + { + new(this) CloseOp(oth); + return *this; + } +#endif }; class CloseVOp: public RegExp @@ -266,17 +351,17 @@ private: int max; public: - static char *type; + static const char *type; public: CloseVOp(RegExp *e, int lb, int ub) + : exp(e) + , min(lb) + , max(ub) { - exp = e; - min = lb; - max = ub; } - char *typeOf() + const char *typeOf() { return type; } @@ -288,6 +373,21 @@ public: { o << exp << "+"; } +#ifdef PEDANTIC +private: + CloseVOp(const CloseVOp& oth) + : RegExp(oth) + , exp(oth.exp) + , min(oth.min) + , max(oth.max) + { + } + CloseVOp& operator = (const CloseVOp& oth) + { + new(this) CloseVOp(oth); + return *this; + } +#endif }; extern void genCode(std::ostream&, RegExp*); diff --git a/substr.h b/substr.h index a4a43ec2..bbc78a55 100644 --- a/substr.h +++ b/substr.h @@ -11,7 +11,6 @@ namespace re2c class SubStr { - public: const char * str; uint len; @@ -22,16 +21,20 @@ public: SubStr(const char*, uint); SubStr(const char*); SubStr(const SubStr&); + virtual ~SubStr(); void out(std::ostream&) const; std::string to_string() const { return std::string(str, len); } +#ifdef PEDANTIC +protected: + SubStr& operator = (const SubStr& oth); +#endif }; class Str: public SubStr { - public: Str(const SubStr&); Str(Str&); @@ -66,6 +69,17 @@ inline SubStr::SubStr(const SubStr &s) : str(s.str), len(s.len) { } +inline SubStr::~SubStr() +{ } + +#ifdef PEDANTIC +inline SubStr& SubStr::operator = (const SubStr& oth) +{ + str = oth.str; + return *this; +} +#endif + } // end namespace re2c #ifndef HAVE_STRNDUP