]> granicus.if.org Git - re2c/commitdiff
- Constify
authorhelly <helly@642ea486-5414-0410-9d7f-a0204ed87703>
Sun, 1 Jan 2006 02:52:01 +0000 (02:52 +0000)
committerhelly <helly@642ea486-5414-0410-9d7f-a0204ed87703>
Sun, 1 Jan 2006 02:52:01 +0000 (02:52 +0000)
- 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<uint> to std::set<uint>

13 files changed:
actions.cc
bootstrap/parser.cc
bootstrap/y.tab.h
code.cc
code.h
dfa.cc
dfa.h
globals.h
main.cc
parser.h
parser.y
re.h
substr.h

index 1952c88c083f9b738ed3e53b1d6e77266d137476..74afc42326c953400c356468e7df9f0ab1da7e62 100644 (file)
@@ -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))
index a53764d44919e5f621cba76c9f7aaa69eb78358a..8a241d566a78f87b0fc5d9ff0cf087372439ebaf 100644 (file)
 #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"
 \f
   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);
 }
 
index 326185c23261c898c88c9d1a5e434af79fd48b01..1c3e5849eac4419f47c6f8570cf5f26a39cfdc72 100644 (file)
@@ -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 76f836e72285f7d0107d0ea4ab4c839294c19d7d..ecb2d4fd14b31f4178b39907e8c6f42a0b9ca0b1 100644 (file)
--- 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 89ea7f8ebe5bc7cee495b8f4dd312175c3981ee0..a27cf9769d4baeaa91b257d0f333619fe2db79da 100755 (executable)
--- 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 char_type>
+class basic_null_streambuf
+       : public std::basic_streambuf<char_type>
 {
 public:
-       null_stream()
-               : std::ostream(&ns)
+       basic_null_streambuf()
+               : std::basic_streambuf<char_type>()
+       {
+       }       
+};
+
+template <class char_type>
+class basic_null_stream
+       : protected basic_null_streambuf<char_type>
+       , public std::basic_ostream<char_type>
+{
+public:
+       basic_null_stream()
+               : basic_null_streambuf<char_type>()
+               , std::basic_ostream<char_type>(static_cast<basic_null_streambuf<char_type>*>(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<char> null_stream;
+
 } // end namespace re2c
 
 #endif
diff --git a/dfa.cc b/dfa.cc
index 833d99c1afd53c8486267ec8a7bf264389e86bb1..8df1837d45507690f92332d149f6b80c499a5832 100644 (file)
--- 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 0fdb9ea4d68de9a2fb9d7664a33e6fe1dcb89e3f..58b7a65aff486aebcff6cd4bf0f628f0058faf49 100644 (file)
--- 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;
index 4cc448c5d0e8ab87a05bd3ec8d80ba19fadfc569..3010acc439d4012c89b6216fe8bf01f082b33146 100644 (file)
--- a/globals.h
+++ b/globals.h
@@ -6,30 +6,10 @@
 #include <set>
 #include <algorithm>
 
-template<typename _Ty>
-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<uint> vUsedLabels;
+extern std::set<uint> vUsedLabels;
 
 extern uint nRealChars;
 
diff --git a/main.cc b/main.cc
index 1613eb3b9143fe3252b77272881022e81308e8f3..764bcf3b9d47a6af36119c19b44658567ff6e566 100644 (file)
--- 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<uint> vUsedLabels;
+std::set<uint> 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<char> *input = 0;
 
        ifstream inputFile;
 
index 1827367f296b9668eedc56906052055fe65c4c8c..7abc0d371cf24913030a6c7f887814b1fc9992d5 100644 (file)
--- 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&);
index f379c94a71eafe7dc6ef65a27dc6062c3a7aecab..4b29951ed39135d21d4810be7389174e8658cfbf 100644 (file)
--- a/parser.y
+++ b/parser.y
 #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 c01e2dddd514aa308a35a9426c5f6fe0aa173096..089f1ea20149874ff0e99e9a545bec0a683a6061 100644 (file)
--- 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*);
index a4a43ec27eb195668def6b7d5f3d81dd831db089..bbc78a559e848cdc12cfa248b3404796cdbfe43e 100644 (file)
--- 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