From bb25bad874ca98690b4ea980a314f210c9afb86c Mon Sep 17 00:00:00 2001 From: Ulya Trofimovich Date: Wed, 13 May 2015 15:07:01 +0100 Subject: [PATCH] CXXFLAGS: removed -DPEDANTIC, added -Weffc++. Fixed warnings. --- re2c/Makefile.am | 4 +- re2c/src/codegen/bitmap.h | 17 +---- re2c/src/codegen/dfa_prepare.cc | 7 +- re2c/src/codegen/go.h | 37 +++++++++ re2c/src/codegen/go_construct.cc | 3 +- re2c/src/codegen/output.h | 7 +- re2c/src/codegen/scc.h | 5 +- re2c/src/codegen/skeleton/skeleton.cc | 3 +- re2c/src/codegen/skeleton/skeleton.h | 9 ++- re2c/src/dfa/action.h | 14 ++-- re2c/src/dfa/actions.cc | 5 +- re2c/src/dfa/dfa.cc | 9 ++- re2c/src/dfa/dfa.h | 5 +- re2c/src/dfa/encoding/range_suffix.h | 3 + re2c/src/dfa/re.h | 103 ++++---------------------- re2c/src/dfa/state.h | 5 +- re2c/src/parse/input.h | 4 + re2c/src/parse/parser.h | 14 +--- re2c/src/parse/scanner.cc | 55 ++++++++++++-- re2c/src/parse/scanner.h | 34 +++++++-- re2c/src/parse/token.h | 21 +++--- re2c/src/util/allocate.h | 17 +++++ re2c/src/util/forbid_copy.h | 11 +++ re2c/src/util/range.h | 3 + re2c/src/util/substr.h | 14 +--- 25 files changed, 227 insertions(+), 182 deletions(-) create mode 100644 re2c/src/util/allocate.h create mode 100644 re2c/src/util/forbid_copy.h diff --git a/re2c/Makefile.am b/re2c/Makefile.am index 5a93afd5..47134af8 100644 --- a/re2c/Makefile.am +++ b/re2c/Makefile.am @@ -1,6 +1,6 @@ # $Id$ -AM_CXXFLAGS = -W -Wall -Wextra -pedantic -Wredundant-decls -DPEDANTIC -O2 +AM_CXXFLAGS = -W -Wall -Wextra -Weffc++ -pedantic -Wredundant-decls -O2 AM_YFLAGS = -y -d --no-lines RE2CFLAGS = -bi @@ -56,7 +56,9 @@ SRC_HDR = \ $(srcdir)/src/parse/parser.h \ $(srcdir)/src/parse/scanner.h \ $(srcdir)/src/parse/token.h \ + $(srcdir)/src/util/allocate.h \ $(srcdir)/src/util/c99_stdint.h \ + $(srcdir)/src/util/forbid_copy.h \ $(srcdir)/src/util/free_list.h \ $(srcdir)/src/util/range.h \ $(srcdir)/src/util/smart_ptr.h \ diff --git a/re2c/src/codegen/bitmap.h b/re2c/src/codegen/bitmap.h index 32ce85cb..5b83fdaa 100644 --- a/re2c/src/codegen/bitmap.h +++ b/re2c/src/codegen/bitmap.h @@ -3,6 +3,7 @@ #include "src/codegen/output.h" #include "src/util/c99_stdint.h" +#include "src/util/forbid_copy.h" namespace re2c { @@ -28,21 +29,7 @@ public: 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 + FORBID_COPY (BitMap); }; #ifdef _MSC_VER diff --git a/re2c/src/codegen/dfa_prepare.cc b/re2c/src/codegen/dfa_prepare.cc index 2a703d37..42415990 100644 --- a/re2c/src/codegen/dfa_prepare.cc +++ b/re2c/src/codegen/dfa_prepare.cc @@ -1,6 +1,7 @@ #include "src/codegen/bitmap.h" #include "src/codegen/scc.h" #include "src/dfa/dfa.h" +#include "src/util/allocate.h" namespace re2c { @@ -36,7 +37,7 @@ void DFA::split(State *s) move->go = s->go; s->rule = NULL; s->go.nSpans = 1; - s->go.span = new Span[1]; + s->go.span = allocate (1); s->go.span[0].ub = ubChar; s->go.span[0].to = move; } @@ -118,7 +119,7 @@ static uint32_t merge(Span *x0, State *fg, State *bg) void DFA::findBaseState() { - Span *span = new Span[ubChar - lbChar]; + Span *span = allocate (ubChar - lbChar); for (State *s = head; s; s = s->next) { @@ -137,7 +138,7 @@ void DFA::findBaseState() { delete [] s->go.span; s->go.nSpans = nSpans; - s->go.span = new Span[nSpans]; + s->go.span = allocate (nSpans); memcpy(s->go.span, span, nSpans*sizeof(Span)); } diff --git a/re2c/src/codegen/go.h b/re2c/src/codegen/go.h index aa99e138..01337515 100644 --- a/re2c/src/codegen/go.h +++ b/re2c/src/codegen/go.h @@ -6,6 +6,7 @@ #include "src/codegen/output.h" #include "src/util/c99_stdint.h" +#include "src/util/forbid_copy.h" namespace re2c { @@ -19,6 +20,8 @@ struct Span uint32_t ub; State * to; uint32_t show (std::ostream&, uint32_t) const; + + FORBID_COPY (Span); }; struct Case @@ -26,6 +29,13 @@ struct Case std::vector > ranges; const State * to; void emit (OutputFile & o, uint32_t ind); + + inline Case () + : ranges () + , to (NULL) + {} + + FORBID_COPY (Case); }; struct Cases @@ -38,6 +48,8 @@ struct Cases ~Cases (); void emit (OutputFile & o, uint32_t ind, bool & readCh); void used_labels (); + + FORBID_COPY (Cases); }; struct Cond @@ -56,6 +68,8 @@ struct Binary ~Binary (); void emit (OutputFile & o, uint32_t ind, bool & readCh); void used_labels (); + + FORBID_COPY (Binary); }; struct Linear @@ -113,6 +127,8 @@ struct GoBitmap ~GoBitmap (); void emit (OutputFile & o, uint32_t ind, bool & readCh); void used_labels (); + + FORBID_COPY (GoBitmap); }; struct CpgotoTable @@ -123,6 +139,8 @@ struct CpgotoTable ~CpgotoTable (); void emit (OutputFile & o, uint32_t ind); void used_labels (); + + FORBID_COPY (CpgotoTable); }; struct Cpgoto @@ -133,6 +151,8 @@ struct Cpgoto ~Cpgoto (); void emit (OutputFile & o, uint32_t ind, bool & readCh); void used_labels (); + + FORBID_COPY (Cpgoto); }; struct Dot @@ -142,6 +162,8 @@ struct Dot Dot (const Span * sp, uint32_t nsp, const State * from); ~Dot (); void emit (OutputFile & o); + + FORBID_COPY (Dot); }; struct Go @@ -169,6 +191,21 @@ struct Go void init (const State * from); void emit (OutputFile & o, uint32_t ind, bool & readCh); void used_labels (); + + Go (const Go & g) + : nSpans (g.nSpans) + , span (g.span) + , type (g.type) + , info (g.info) + {} + Go & operator = (const Go & g) + { + nSpans = g.nSpans; + span = g.span; + type = g.type; + info = g.info; + return * this; + } }; // construct helpers diff --git a/re2c/src/codegen/go_construct.cc b/re2c/src/codegen/go_construct.cc index 91570275..bec1098b 100644 --- a/re2c/src/codegen/go_construct.cc +++ b/re2c/src/codegen/go_construct.cc @@ -1,6 +1,7 @@ #include "src/codegen/bitmap.h" #include "src/codegen/go.h" #include "src/dfa/dfa.h" +#include "src/util/allocate.h" namespace re2c { @@ -131,7 +132,7 @@ GoBitmap::GoBitmap (const Span * span, uint32_t nSpans, const Span * hspan, uint , hgo (hSpans == 0 ? NULL : new SwitchIf (hspan, hSpans, next)) , lgo (NULL) { - Span * bspan = new Span [nSpans]; + Span * bspan = allocate (nSpans); uint32_t bSpans = unmap (bspan, span, nSpans, bm_state); lgo = bSpans == 0 ? NULL diff --git a/re2c/src/codegen/output.h b/re2c/src/codegen/output.h index 5ac99b16..e7358821 100644 --- a/re2c/src/codegen/output.h +++ b/re2c/src/codegen/output.h @@ -7,11 +7,12 @@ #include #include "src/util/c99_stdint.h" +#include "src/util/forbid_copy.h" namespace re2c { -struct Str; +class Str; struct OutputFragment { @@ -90,6 +91,8 @@ private: std::ostream & stream (); void insert_code (); + + FORBID_COPY (OutputFile); }; struct HeaderFile @@ -103,6 +106,8 @@ private: std::ostringstream stream; const char * file_name; FILE * file; + + FORBID_COPY (HeaderFile); }; struct DataFile diff --git a/re2c/src/codegen/scc.h b/re2c/src/codegen/scc.h index a08966f4..7d2bd1c3 100644 --- a/re2c/src/codegen/scc.h +++ b/re2c/src/codegen/scc.h @@ -2,6 +2,7 @@ #define __SCC__ #include "src/util/c99_stdint.h" +#include "src/util/forbid_copy.h" namespace re2c { @@ -19,9 +20,7 @@ public: ~SCC (); void traverse (State *); -private: - SCC (const SCC &); - SCC & operator = (const SCC &); + FORBID_COPY (SCC); }; bool state_is_in_non_trivial_SCC (const State * s); diff --git a/re2c/src/codegen/skeleton/skeleton.cc b/re2c/src/codegen/skeleton/skeleton.cc index 3ca07b22..73df589e 100644 --- a/re2c/src/codegen/skeleton/skeleton.cc +++ b/re2c/src/codegen/skeleton/skeleton.cc @@ -1,6 +1,7 @@ #include "src/codegen/indent.h" #include "src/codegen/print.h" #include "src/codegen/skeleton/skeleton.h" +#include "src/util/allocate.h" namespace re2c { @@ -222,7 +223,7 @@ const uint32_t Skeleton::DATA_LIMIT = 1024 * 1024 * 1024; // 1Gb Skeleton::Skeleton (const DFA & dfa) // +1 for default DFA state (NULL) - : nodes (new Node [dfa.nStates + 1]) + : nodes (allocate (dfa.nStates + 1)) { Node * n; diff --git a/re2c/src/codegen/skeleton/skeleton.h b/re2c/src/codegen/skeleton/skeleton.h index ece9e36d..8ad67877 100644 --- a/re2c/src/codegen/skeleton/skeleton.h +++ b/re2c/src/codegen/skeleton/skeleton.h @@ -6,6 +6,7 @@ #include "src/dfa/dfa.h" #include "src/util/c99_stdint.h" +#include "src/util/forbid_copy.h" namespace re2c { @@ -59,13 +60,14 @@ public: { return wrapped; } - void operator ++ () + wrap_iter_t & operator ++ () { if (++iter == cont.end ()) { iter = cont.begin (); wrapped = true; } + return * this; } typename container_t::value_type * operator -> () { @@ -95,7 +97,6 @@ struct Node uint32_t path_len; Path * path; - inline Node () {} // only to allow array allocation with 'new' Node (const State * s, const s2n_map & s2n); ~Node (); bool end () const; @@ -103,6 +104,8 @@ struct Node uint32_t estimate_size_cover (uint32_t inarcs, uint32_t len); void generate_paths_all (const std::vector & prefixes, std::vector & results); void generate_paths_cover (const std::vector & prefixes, std::vector & results); + + FORBID_COPY (Node); }; struct Skeleton @@ -115,6 +118,8 @@ struct Skeleton ~Skeleton (); void generate_paths (std::vector & results); void emit_data (DataFile & o); + + FORBID_COPY (Skeleton); }; void emit_prolog (OutputFile & o, uint32_t ind, const char * data_name); diff --git a/re2c/src/dfa/action.h b/re2c/src/dfa/action.h index 0e06f47b..b972f10e 100644 --- a/re2c/src/dfa/action.h +++ b/re2c/src/dfa/action.h @@ -4,6 +4,7 @@ #include #include "src/dfa/state.h" +#include "src/util/forbid_copy.h" namespace re2c { @@ -40,9 +41,7 @@ public: } virtual void emit (Output &, uint32_t, bool &, const std::string &) const = 0; -private: - Action (const Action &); - Action & operator = (const Action &); + FORBID_COPY (Action); }; class Match: public Action @@ -112,6 +111,7 @@ public: , nRules (n) , saves (s) , rules (r) + , mapRules () { type = ACCEPT; } @@ -119,9 +119,7 @@ public: void emitBinary (OutputFile & o, uint32_t ind, uint32_t l, uint32_t r, bool & readCh) const; void genRuleMap (); -private: - Accept (const Accept &); - Accept & operator = (const Accept &); + FORBID_COPY (Accept); }; class Rule: public Action @@ -137,9 +135,7 @@ public: } void emit (Output &, uint32_t, bool &, const std::string &) const; -private: - Rule (const Rule &); - Rule & operator = (const Rule &); + FORBID_COPY (Rule); }; } // namespace re2c diff --git a/re2c/src/dfa/actions.cc b/re2c/src/dfa/actions.cc index bb0adbcf..fd372e17 100644 --- a/re2c/src/dfa/actions.cc +++ b/re2c/src/dfa/actions.cc @@ -11,6 +11,7 @@ #include "src/dfa/encoding/utf8/utf8_regexp.h" #include "src/globals.h" #include "src/parse/parser.h" +#include "src/util/allocate.h" namespace re2c { @@ -1026,8 +1027,8 @@ CharSet::CharSet() : fix(0) , freeHead(0) , freeTail(0) - , rep(new CharPtr[encoding.nCodeUnits()]) - , ptn(new CharPtn[encoding.nCodeUnits()]) + , rep(allocate (encoding.nCodeUnits())) + , ptn(allocate (encoding.nCodeUnits())) { for (uint32_t j = 0; j < encoding.nCodeUnits(); ++j) { diff --git a/re2c/src/dfa/dfa.cc b/re2c/src/dfa/dfa.cc index a5254e69..1d4aa5f3 100644 --- a/re2c/src/dfa/dfa.cc +++ b/re2c/src/dfa/dfa.cc @@ -1,4 +1,5 @@ #include "src/dfa/dfa.h" +#include "src/util/allocate.h" namespace re2c { @@ -41,11 +42,15 @@ DFA::DFA(Ins *ins, uint32_t ni, uint32_t lb, uint32_t ub, const Char *rep) , toDo(NULL) , free_ins(ins) , free_rep(rep) + , bSaveOnHead (false) + , saves (NULL) + , rules (NULL) + { Ins **work = new Ins * [ni + 1]; uint32_t nc = ub - lb; GoTo *goTo = new GoTo[nc]; - Span *span = new Span[nc]; + Span *span = allocate (nc); memset((char*) goTo, 0, nc*sizeof(GoTo)); findState(work, closure(work, &ins[0]) - work); @@ -112,7 +117,7 @@ DFA::DFA(Ins *ins, uint32_t ni, uint32_t lb, uint32_t ub, const Char *rep) for (j = nGoTos; j-- > 0;) goTo[goTo[j].ch - lb].to = NULL; - s->go.span = new Span[s->go.nSpans]; + s->go.span = allocate (s->go.nSpans); memcpy((char*) s->go.span, (char*) span, s->go.nSpans*sizeof(Span)); diff --git a/re2c/src/dfa/dfa.h b/re2c/src/dfa/dfa.h index 78e3c9b3..c56da009 100644 --- a/re2c/src/dfa/dfa.h +++ b/re2c/src/dfa/dfa.h @@ -3,6 +3,7 @@ #include "src/dfa/action.h" #include "src/dfa/state.h" +#include "src/util/forbid_copy.h" #include "src/util/smart_ptr.h" namespace re2c @@ -41,9 +42,7 @@ public: friend std::ostream & operator << (std::ostream &, const DFA &); -private: - DFA (const DFA &); - DFA & operator = (const DFA &); + FORBID_COPY (DFA); }; smart_ptr genCode (RegExp *, Output &, uint32_t); diff --git a/re2c/src/dfa/encoding/range_suffix.h b/re2c/src/dfa/encoding/range_suffix.h index f76d3fc9..26640e85 100644 --- a/re2c/src/dfa/encoding/range_suffix.h +++ b/re2c/src/dfa/encoding/range_suffix.h @@ -4,6 +4,7 @@ #include // NULL #include "src/util/c99_stdint.h" +#include "src/util/forbid_copy.h" #include "src/util/free_list.h" namespace re2c { @@ -28,6 +29,8 @@ public: { freeList.insert(this); } + + FORBID_COPY (RangeSuffix); }; RegExp * emit(RangeSuffix * p, RegExp * re); diff --git a/re2c/src/dfa/re.h b/re2c/src/dfa/re.h index bd95ce97..29b97bd8 100644 --- a/re2c/src/dfa/re.h +++ b/re2c/src/dfa/re.h @@ -13,6 +13,7 @@ #include "src/globals.h" #include "src/parse/token.h" #include "src/util/range.h" +#include "src/util/forbid_copy.h" #include "src/util/free_list.h" namespace re2c @@ -32,6 +33,8 @@ struct CharPtn uint32_t card; CharPtn *fix; CharPtn *nxt; + + FORBID_COPY (CharPtn); }; typedef CharPtn *CharPtr; @@ -45,6 +48,8 @@ struct CharSet CharPtn *freeHead, **freeTail; CharPtr *rep; CharPtn *ptn; + + FORBID_COPY (CharSet); }; class RegExp @@ -101,6 +106,8 @@ public: virtual void display(std::ostream&) const = 0; friend std::ostream& operator<<(std::ostream&, const RegExp&); friend std::ostream& operator<<(std::ostream&, const RegExp*); + + FORBID_COPY (RegExp); }; inline std::ostream& operator<<(std::ostream &o, const RegExp &re) @@ -147,20 +154,7 @@ public: void decompile(); 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 + FORBID_COPY (MatchOp); }; class RuleOp: public RegExp @@ -193,25 +187,7 @@ public: } RuleOp* copy(uint32_t) const; -#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 + FORBID_COPY (RuleOp); }; RegExp *doAlt(RegExp*, RegExp*); @@ -242,20 +218,7 @@ 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 + FORBID_COPY (AltOp); }; RegExp *doCat(RegExp*, RegExp*); @@ -284,20 +247,7 @@ 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 + FORBID_COPY (CatOp); }; class CloseOp: public RegExp @@ -321,19 +271,7 @@ 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 + FORBID_COPY (CloseOp); }; class CloseVOp: public RegExp @@ -361,21 +299,8 @@ 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 + + FORBID_COPY (CloseVOp); }; extern RegExp *mkDiff(RegExp*, RegExp*); diff --git a/re2c/src/dfa/state.h b/re2c/src/dfa/state.h index bfeb7756..bb1a70e7 100644 --- a/re2c/src/dfa/state.h +++ b/re2c/src/dfa/state.h @@ -3,6 +3,7 @@ #include "src/codegen/go.h" #include "src/dfa/re.h" +#include "src/util/forbid_copy.h" namespace re2c { @@ -30,9 +31,7 @@ public: void emit (Output &, uint32_t, bool &, const std::string &) const; friend std::ostream& operator << (std::ostream &, const State &); -private: - State (const State &); - State & operator = (const State &); + FORBID_COPY (State); }; } // namespace re2c diff --git a/re2c/src/parse/input.h b/re2c/src/parse/input.h index b8dd4b1a..910bed1c 100644 --- a/re2c/src/parse/input.h +++ b/re2c/src/parse/input.h @@ -4,6 +4,8 @@ #include #include +#include "src/util/forbid_copy.h" + namespace re2c { struct Input @@ -14,6 +16,8 @@ struct Input Input (const char * fn); ~Input (); bool open (); + + FORBID_COPY (Input); }; } // namespace re2c diff --git a/re2c/src/parse/parser.h b/re2c/src/parse/parser.h index 80bce35d..0da184d9 100644 --- a/re2c/src/parse/parser.h +++ b/re2c/src/parse/parser.h @@ -5,6 +5,7 @@ #include "src/codegen/output.h" #include "src/dfa/re.h" #include "src/parse/scanner.h" +#include "src/util/forbid_copy.h" namespace re2c { @@ -39,18 +40,7 @@ private: 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 + FORBID_COPY (Symbol); }; extern void parse(Scanner &, Output &); diff --git a/re2c/src/parse/scanner.cc b/re2c/src/parse/scanner.cc index 8600a32e..6a1e9757 100644 --- a/re2c/src/parse/scanner.cc +++ b/re2c/src/parse/scanner.cc @@ -268,12 +268,57 @@ void Scanner::config(const Str& cfg, const Str& val) } } -ScannerState::ScannerState() - : tok(NULL), ptr(NULL), cur(NULL), pos(NULL), ctx(NULL) - , bot(NULL), lim(NULL), top(NULL), eof(NULL) - , tchar(0), tline(0), cline(1), iscfg(0) - , in_parse(false) +ScannerState::ScannerState () + : tok (NULL) + , ptr (NULL) + , cur (NULL) + , pos (NULL) + , ctx (NULL) + , bot (NULL) + , lim (NULL) + , top (NULL) + , eof (NULL) + , tchar (0) + , tline (0) + , cline (1) + , iscfg (0) + , in_parse (false) +{} + +ScannerState::ScannerState (const ScannerState & s) + : tok (s.tok) + , ptr (s.ptr) + , cur (s.cur) + , pos (s.pos) + , ctx (s.ctx) + , bot (s.bot) + , lim (s.lim) + , top (s.top) + , eof (s.eof) + , tchar (s.tchar) + , tline (s.tline) + , cline (s.cline) + , iscfg (s.iscfg) + , in_parse (s.in_parse) +{} + +ScannerState & ScannerState::operator = (const ScannerState & s) { + tok = s.tok; + ptr = s.ptr; + cur = s.cur; + pos = s.pos; + ctx = s.ctx; + bot = s.bot; + lim = s.lim; + top = s.top; + eof = s.eof; + tchar = s.tchar; + tline = s.tline; + cline = s.cline; + iscfg = s.iscfg; + in_parse = s.in_parse; + return * this; } Scanner::Scanner (Input & i, OutputFile & o) diff --git a/re2c/src/parse/scanner.h b/re2c/src/parse/scanner.h index 4fd5afdc..7df36a8e 100644 --- a/re2c/src/parse/scanner.h +++ b/re2c/src/parse/scanner.h @@ -9,18 +9,36 @@ #include "src/globals.h" #include "src/parse/input.h" #include "src/parse/token.h" +#include "src/util/forbid_copy.h" namespace re2c { struct ScannerState { - ScannerState(); - - char *tok, *ptr, *cur, *pos, *ctx; // positioning - char *bot, *lim, *top, *eof; // buffer - uint32_t tchar, tline, cline, iscfg, buf_size; - bool in_parse; + // positioning + char * tok; + char * ptr; + char * cur; + char * pos; + char * ctx; + + // buffer + char * bot; + char * lim; + char * top; + char * eof; + + uint32_t tchar; + uint32_t tline; + uint32_t cline; + uint32_t iscfg; + + bool in_parse; + + ScannerState (); + ScannerState (const ScannerState &); + ScannerState & operator = (const ScannerState &); }; class Scanner: private ScannerState @@ -31,8 +49,6 @@ private: private: char *fill(char*, uint32_t); - Scanner(const Scanner&); //unimplemented - Scanner& operator=(const Scanner&); //unimplemented void set_sourceline(char *& cursor); public: @@ -85,6 +101,8 @@ public: RegExp * invToRE(SubStr s) const; RegExp * mkDot() const; RegExp * mkDefault() const; + + FORBID_COPY (Scanner); }; inline size_t Scanner::get_pos() const diff --git a/re2c/src/parse/token.h b/re2c/src/parse/token.h index d4f25f05..f58f936e 100644 --- a/re2c/src/parse/token.h +++ b/re2c/src/parse/token.h @@ -19,8 +19,11 @@ public: public: Token(const SubStr&, const std::string&, uint32_t); Token(const Token*, const std::string&, uint32_t, const Str*); - Token(const Token& oth); + Token (const Token & t); ~Token(); + +private: + Token & operator = (const Token &); }; inline Token::Token(const SubStr& t, const std::string& s, uint32_t l) @@ -43,15 +46,13 @@ inline Token::Token(const Token* t, const std::string& s, uint32_t l, const Str ; } -inline Token::Token(const Token& oth) - : text(oth.text.to_string().c_str()) - , newcond(oth.newcond) - , source(oth.source) - , line(oth.line) - , autogen(oth.autogen) -{ - ; -} +inline Token::Token (const Token & t) + : text (t.text.to_string().c_str()) + , newcond (t.newcond) + , source (t.source) + , line (t.line) + , autogen (t.autogen) +{} inline Token::~Token() { diff --git a/re2c/src/util/allocate.h b/re2c/src/util/allocate.h new file mode 100644 index 00000000..f667ea01 --- /dev/null +++ b/re2c/src/util/allocate.h @@ -0,0 +1,17 @@ +#ifndef __ALLOCATE__ +#define __ALLOCATE__ + +namespace re2c { + +// useful fof allocation of arrays of POD objects +// 'new []' invokes default constructor for each object +// this can be unacceptable for performance reasons +template T * allocate (size_t n) +{ + void * p = operator new (n * sizeof (T)); + return static_cast (p); +} + +} // namespace re2c + +#endif // __ALLOCATE__ diff --git a/re2c/src/util/forbid_copy.h b/re2c/src/util/forbid_copy.h new file mode 100644 index 00000000..bef26ed4 --- /dev/null +++ b/re2c/src/util/forbid_copy.h @@ -0,0 +1,11 @@ +#ifndef __FORBID_COPY__ +#define __FORBID_COPY__ + +// must be used at the end of class definition +// (since this macro changes scope to private) +#define FORBID_COPY(type) \ + private: \ + type (const type &); \ + type & operator = (const type &) + +#endif // __FORBID_COPY__ diff --git a/re2c/src/util/range.h b/re2c/src/util/range.h index 56128178..7b85f4bd 100644 --- a/re2c/src/util/range.h +++ b/re2c/src/util/range.h @@ -4,6 +4,7 @@ #include #include "src/util/c99_stdint.h" +#include "src/util/forbid_copy.h" #include "src/util/free_list.h" namespace re2c @@ -33,6 +34,8 @@ public: { vFreeList.erase(this); } + + FORBID_COPY (Range); }; Range *doUnion(Range *r1, Range *r2); diff --git a/re2c/src/util/substr.h b/re2c/src/util/substr.h index d6f2f452..c9e9aedb 100644 --- a/re2c/src/util/substr.h +++ b/re2c/src/util/substr.h @@ -30,10 +30,8 @@ public: std::string to_string() const; uint32_t ofs() const; -#ifdef PEDANTIC -protected: - SubStr& operator = (const SubStr& oth); -#endif +private: + SubStr & operator = (const SubStr &); }; class Str: public SubStr @@ -85,14 +83,6 @@ inline uint32_t SubStr::ofs() const return str - org; } -#ifdef PEDANTIC -inline SubStr& SubStr::operator = (const SubStr& oth) -{ - new(this) SubStr(oth); - return *this; -} -#endif - } // end namespace re2c #ifndef HAVE_STRNDUP -- 2.50.1