# $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
$(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 \
#include "src/codegen/output.h"
#include "src/util/c99_stdint.h"
+#include "src/util/forbid_copy.h"
namespace re2c
{
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
#include "src/codegen/bitmap.h"
#include "src/codegen/scc.h"
#include "src/dfa/dfa.h"
+#include "src/util/allocate.h"
namespace re2c {
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;
}
void DFA::findBaseState()
{
- Span *span = new Span[ubChar - lbChar];
+ Span *span = allocate<Span> (ubChar - lbChar);
for (State *s = head; s; s = s->next)
{
{
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));
}
#include "src/codegen/output.h"
#include "src/util/c99_stdint.h"
+#include "src/util/forbid_copy.h"
namespace re2c
{
uint32_t ub;
State * to;
uint32_t show (std::ostream&, uint32_t) const;
+
+ FORBID_COPY (Span);
};
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
~Cases ();
void emit (OutputFile & o, uint32_t ind, bool & readCh);
void used_labels ();
+
+ FORBID_COPY (Cases);
};
struct Cond
~Binary ();
void emit (OutputFile & o, uint32_t ind, bool & readCh);
void used_labels ();
+
+ FORBID_COPY (Binary);
};
struct Linear
~GoBitmap ();
void emit (OutputFile & o, uint32_t ind, bool & readCh);
void used_labels ();
+
+ FORBID_COPY (GoBitmap);
};
struct CpgotoTable
~CpgotoTable ();
void emit (OutputFile & o, uint32_t ind);
void used_labels ();
+
+ FORBID_COPY (CpgotoTable);
};
struct Cpgoto
~Cpgoto ();
void emit (OutputFile & o, uint32_t ind, bool & readCh);
void used_labels ();
+
+ FORBID_COPY (Cpgoto);
};
struct Dot
Dot (const Span * sp, uint32_t nsp, const State * from);
~Dot ();
void emit (OutputFile & o);
+
+ FORBID_COPY (Dot);
};
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
#include "src/codegen/bitmap.h"
#include "src/codegen/go.h"
#include "src/dfa/dfa.h"
+#include "src/util/allocate.h"
namespace re2c
{
, 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
#include <vector>
#include "src/util/c99_stdint.h"
+#include "src/util/forbid_copy.h"
namespace re2c
{
-struct Str;
+class Str;
struct OutputFragment
{
std::ostream & stream ();
void insert_code ();
+
+ FORBID_COPY (OutputFile);
};
struct HeaderFile
std::ostringstream stream;
const char * file_name;
FILE * file;
+
+ FORBID_COPY (HeaderFile);
};
struct DataFile
#define __SCC__
#include "src/util/c99_stdint.h"
+#include "src/util/forbid_copy.h"
namespace re2c {
~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);
#include "src/codegen/indent.h"
#include "src/codegen/print.h"
#include "src/codegen/skeleton/skeleton.h"
+#include "src/util/allocate.h"
namespace re2c
{
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;
#include "src/dfa/dfa.h"
#include "src/util/c99_stdint.h"
+#include "src/util/forbid_copy.h"
namespace re2c
{
{
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 -> ()
{
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;
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
~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);
#include <map>
#include "src/dfa/state.h"
+#include "src/util/forbid_copy.h"
namespace re2c
{
}
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
, nRules (n)
, saves (s)
, rules (r)
+ , mapRules ()
{
type = ACCEPT;
}
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
}
void emit (Output &, uint32_t, bool &, const std::string &) const;
-private:
- Rule (const Rule &);
- Rule & operator = (const Rule &);
+ FORBID_COPY (Rule);
};
} // namespace re2c
#include "src/dfa/encoding/utf8/utf8_regexp.h"
#include "src/globals.h"
#include "src/parse/parser.h"
+#include "src/util/allocate.h"
namespace re2c
{
: 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)
{
#include "src/dfa/dfa.h"
+#include "src/util/allocate.h"
namespace re2c
{
, 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);
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));
#include "src/dfa/action.h"
#include "src/dfa/state.h"
+#include "src/util/forbid_copy.h"
#include "src/util/smart_ptr.h"
namespace re2c
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);
#include <stddef.h> // NULL
#include "src/util/c99_stdint.h"
+#include "src/util/forbid_copy.h"
#include "src/util/free_list.h"
namespace re2c {
{
freeList.insert(this);
}
+
+ FORBID_COPY (RangeSuffix);
};
RegExp * emit(RangeSuffix * p, RegExp * re);
#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
uint32_t card;
CharPtn *fix;
CharPtn *nxt;
+
+ FORBID_COPY (CharPtn);
};
typedef CharPtn *CharPtr;
CharPtn *freeHead, **freeTail;
CharPtr *rep;
CharPtn *ptn;
+
+ FORBID_COPY (CharSet);
};
class RegExp
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)
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
}
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*);
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*);
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
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
{
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*);
#include "src/codegen/go.h"
#include "src/dfa/re.h"
+#include "src/util/forbid_copy.h"
namespace re2c
{
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
#include <stdio.h>
#include <string>
+#include "src/util/forbid_copy.h"
+
namespace re2c {
struct Input
Input (const char * fn);
~Input ();
bool open ();
+
+ FORBID_COPY (Input);
};
} // namespace re2c
#include "src/codegen/output.h"
#include "src/dfa/re.h"
#include "src/parse/scanner.h"
+#include "src/util/forbid_copy.h"
namespace re2c
{
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 &);
}
}
-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)
#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
private:
char *fill(char*, uint32_t);
- Scanner(const Scanner&); //unimplemented
- Scanner& operator=(const Scanner&); //unimplemented
void set_sourceline(char *& cursor);
public:
RegExp * invToRE(SubStr s) const;
RegExp * mkDot() const;
RegExp * mkDefault() const;
+
+ FORBID_COPY (Scanner);
};
inline size_t Scanner::get_pos() const
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)
;
}
-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()
{
--- /dev/null
+#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__
--- /dev/null
+#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__
#include <iostream>
#include "src/util/c99_stdint.h"
+#include "src/util/forbid_copy.h"
#include "src/util/free_list.h"
namespace re2c
{
vFreeList.erase(this);
}
+
+ FORBID_COPY (Range);
};
Range *doUnion(Range *r1, Range *r2);
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
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