]> granicus.if.org Git - re2c/commitdiff
CXXFLAGS: removed -DPEDANTIC, added -Weffc++. Fixed warnings.
authorUlya Trofimovich <skvadrik@gmail.com>
Wed, 13 May 2015 14:07:01 +0000 (15:07 +0100)
committerUlya Trofimovich <skvadrik@gmail.com>
Wed, 13 May 2015 14:07:01 +0000 (15:07 +0100)
25 files changed:
re2c/Makefile.am
re2c/src/codegen/bitmap.h
re2c/src/codegen/dfa_prepare.cc
re2c/src/codegen/go.h
re2c/src/codegen/go_construct.cc
re2c/src/codegen/output.h
re2c/src/codegen/scc.h
re2c/src/codegen/skeleton/skeleton.cc
re2c/src/codegen/skeleton/skeleton.h
re2c/src/dfa/action.h
re2c/src/dfa/actions.cc
re2c/src/dfa/dfa.cc
re2c/src/dfa/dfa.h
re2c/src/dfa/encoding/range_suffix.h
re2c/src/dfa/re.h
re2c/src/dfa/state.h
re2c/src/parse/input.h
re2c/src/parse/parser.h
re2c/src/parse/scanner.cc
re2c/src/parse/scanner.h
re2c/src/parse/token.h
re2c/src/util/allocate.h [new file with mode: 0644]
re2c/src/util/forbid_copy.h [new file with mode: 0644]
re2c/src/util/range.h
re2c/src/util/substr.h

index 5a93afd5143da27ea07096a589bee668f6e54cd6..47134af8771c3661ed6fe7faa9605e9ae2c2c5bd 100644 (file)
@@ -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 \
index 32ce85cbd143f2e2ad4667d5a861a6ab7d78d4e5..5b83fdaa80a21986498ba058931270124782b10e 100644 (file)
@@ -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
index 2a703d375674ec9f52041f67cb7f65d1d9ad8702..42415990293456b87981ec07ad81ef711d63c5f0 100644 (file)
@@ -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<Span> (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<Span> (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<Span> (nSpans);
                                                memcpy(s->go.span, span, nSpans*sizeof(Span));
                                        }
 
index aa99e1388100f1695a694c032ee9499a579560f9..013375150b36a3d124ff64a4135ec636f21261b6 100644 (file)
@@ -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<std::pair<uint32_t, uint32_t> > 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
index 91570275341348e7ca22877dff136cd5763bbd25..bec1098b79335e4a81aa421f8d70a174ee09be0f 100644 (file)
@@ -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<Span> (nSpans);
        uint32_t bSpans = unmap (bspan, span, nSpans, bm_state);
        lgo = bSpans == 0
                ? NULL
index 5ac99b1680c51f52ab68653878ad10721dc33b64..e7358821ddab83e2c33533261502b0a7be221530 100644 (file)
@@ -7,11 +7,12 @@
 #include <vector>
 
 #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
index a08966f4075dfdfe98191e3861b02256c68be964..7d2bd1c34e562dd1f774da68e95f75858b86ec29 100644 (file)
@@ -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);
index 3ca07b2240bd1cccabbe6930e8b2dbecd32b8f34..73df589eefd7c002655923e607c79b7f9d681a74 100644 (file)
@@ -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<Node> (dfa.nStates + 1))
 {
        Node * n;
 
index ece9e36d2dfc78816975e3e1a7578296462adae1..8ad67877f2bbbaf878e3a81de08265d228e39824 100644 (file)
@@ -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<Path> & prefixes, std::vector<Path> & results);
        void generate_paths_cover (const std::vector<Path> & prefixes, std::vector<Path> & results);
+
+       FORBID_COPY (Node);
 };
 
 struct Skeleton
@@ -115,6 +118,8 @@ struct Skeleton
        ~Skeleton ();
        void generate_paths (std::vector<Path> & results);
        void emit_data (DataFile & o);
+
+       FORBID_COPY (Skeleton);
 };
 
 void emit_prolog (OutputFile & o, uint32_t ind, const char * data_name);
index 0e06f47b5e6068bb617e3f869f93d4eb3963d859..b972f10e496bd53db400727350a8a46b3a486f58 100644 (file)
@@ -4,6 +4,7 @@
 #include <map>
 
 #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
index bb0adbcf09e38e2ff65970a1bff38d7cd0972c56..fd372e17af46fbec6fc023d29eccab0270b0b1bb 100644 (file)
@@ -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<CharPtr> (encoding.nCodeUnits()))
+       , ptn(allocate<CharPtn> (encoding.nCodeUnits()))
 {
        for (uint32_t j = 0; j < encoding.nCodeUnits(); ++j)
        {
index a5254e69a98afe2f0579333aa144d14d24e75b78..1d4aa5f3e18ee880b2f17768892e149cfc03cf96 100644 (file)
@@ -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<Span> (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<Span> (s->go.nSpans);
 
                memcpy((char*) s->go.span, (char*) span, s->go.nSpans*sizeof(Span));
 
index 78e3c9b3dd74e37d121ff26a878e52067e6e2f13..c56da009fcbab72904e2dca61bd7915ecdce06b9 100644 (file)
@@ -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<DFA> genCode (RegExp *, Output &, uint32_t);
index f76d3fc96cda0103da3c149d705984d015c9be66..26640e856e0e226b5435c18a32d8ac6baff6ee05 100644 (file)
@@ -4,6 +4,7 @@
 #include <stddef.h> // 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);
index bd95ce97af8dc8b14b6fe06bcab601785ebf3668..29b97bd8dabc5436cd6d0082ba848c6fd9fd1399 100644 (file)
@@ -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*);
index bfeb77563a5adabb783602e3e59c76fb1a1163b0..bb1a70e71c7dcaf48636ab86bf9c4eb58676cf95 100644 (file)
@@ -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
index b8dd4b1a06fb3d44b6e7a1f29b26400d544c7396..910bed1c43eaca1e4ebf980dc0f1be1305e59fba 100644 (file)
@@ -4,6 +4,8 @@
 #include <stdio.h>
 #include <string>
 
+#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
index 80bce35de1116ea19a3c00967a709c2f7eb2a2ab..0da184d926895e914d46c46c8ff9291636483b4c 100644 (file)
@@ -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 &);
index 8600a32e98726ca836f0ff8844994eb0d2c3522e..6a1e9757a5c6d35f29b18343763a29626125aafa 100644 (file)
@@ -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)
index 4fd5afdc96e0a026e33c40bc3763d4e14b26da0b..7df36a8e2203195f4e53ebbf36e09f0a4f78aac4 100644 (file)
@@ -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
index d4f25f052f85a7381da142c1a622e0de9362b8b3..f58f936ed5eef9431bf3adc79e10082264e447dc 100644 (file)
@@ -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 (file)
index 0000000..f667ea0
--- /dev/null
@@ -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 <typename T> T * allocate (size_t n)
+{
+       void * p = operator new (n * sizeof (T));
+       return static_cast<T *> (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 (file)
index 0000000..bef26ed
--- /dev/null
@@ -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__
index 561281789e2b2fe696a1f31b947a6616c5f3f865..7b85f4bdca027f89c29e7684013d6a7a7f22ce6b 100644 (file)
@@ -4,6 +4,7 @@
 #include <iostream>
 
 #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);
index d6f2f452845f833cc226878ddc961c9c1a867b6b..c9e9aedbfa4c77bad967e9330e26bb985a2361de 100644 (file)
@@ -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