]> granicus.if.org Git - re2c/commitdiff
Moved 'Range' stuff to separate file.
authorUlya Fokanova <skvadrik@gmail.com>
Wed, 9 Apr 2014 22:15:40 +0000 (01:15 +0300)
committerUlya Fokanova <skvadrik@gmail.com>
Wed, 9 Apr 2014 22:15:40 +0000 (01:15 +0300)
re2c/Makefile.am
re2c/actions.cc
re2c/range.cc [new file with mode: 0644]
re2c/range.h [new file with mode: 0644]
re2c/re.h

index 170d25a3f508e0af2b39aa1bbda8308742996235..74fdce0e58d6035354eb3f7c61b24267fd0f2689 100755 (executable)
@@ -2,7 +2,7 @@
 
 bin_PROGRAMS = re2c
 win_BINARIES = $(WINBUILDDIR)/re2c.exe
-re2c_SOURCES = code.cc dfa.cc main.cc parser.cc actions.cc scanner.re substr.cc\
+re2c_SOURCES = code.cc dfa.cc main.cc parser.cc actions.cc scanner.re substr.cc range.cc \
        translate.cc scanner.cc mbo_getopt.cc print.cc \
        enc.cc utf8.cc utf8_range.cc utf8_regexp.cc utf16.cc utf16_range.cc utf16_regexp.cc range_suffix.cc \
        basics.h dfa.h globals.h ins.h parser.h re.h scanner.h \
index 9a76681e804ff007ba47ccee7d49aa473c538dfb..a9008b5c17bdb0ec56987353119f8794f889ee74 100644 (file)
@@ -120,131 +120,6 @@ void NullOp::split(CharSet&)
        ;
 }
 
-std::ostream& operator<<(std::ostream &o, const Range &r)
-{
-       if ((r.ub - r.lb) == 1)
-       {
-               prtCh(o, r.lb);
-       }
-       else
-       {
-               prtCh(o, r.lb);
-               o << "-";
-               prtCh(o, r.ub - 1);
-       }
-
-       return o << r.next;
-}
-
-Range *doUnion(Range *r1, Range *r2)
-{
-       Range *r, **rP = &r;
-
-       for (;;)
-       {
-               Range *s;
-
-               if (r1->lb <= r2->lb)
-               {
-                       s = new Range(*r1);
-               }
-               else
-               {
-                       s = new Range(*r2);
-               }
-
-               *rP = s;
-               rP = &s->next;
-
-               for (;;)
-               {
-                       if (r1->lb <= r2->lb)
-                       {
-                               if (r1->lb > s->ub)
-                                       break;
-
-                               if (r1->ub > s->ub)
-                                       s->ub = r1->ub;
-
-                               if (!(r1 = r1->next))
-                               {
-                                       uint ub = 0;
-
-                                       for (; r2 && r2->lb <= s->ub; r2 = r2->next)
-                                               ub = r2->ub;
-
-                                       if (ub > s->ub)
-                                               s->ub = ub;
-
-                                       *rP = r2;
-
-                                       return r;
-                               }
-                       }
-                       else
-                       {
-                               if (r2->lb > s->ub)
-                                       break;
-
-                               if (r2->ub > s->ub)
-                                       s->ub = r2->ub;
-
-                               if (!(r2 = r2->next))
-                               {
-                                       uint ub = 0;
-
-                                       for (; r1 && r1->lb <= s->ub; r1 = r1->next)
-                                               ub = r1->ub;
-
-                                       if (ub > s->ub)
-                                               s->ub = ub;
-
-                                       *rP = r1;
-
-                                       return r;
-                               }
-                       }
-               }
-       }
-
-       *rP = NULL;
-       return r;
-}
-
-Range *doDiff(Range *r1, Range *r2)
-{
-       Range *r, *s, **rP = &r;
-
-       for (; r1; r1 = r1->next)
-       {
-               uint lb = r1->lb;
-
-               for (; r2 && r2->ub <= r1->lb; r2 = r2->next)
-
-                       ;
-               for (; r2 && r2->lb < r1->ub; r2 = r2->next)
-               {
-                       if (lb < r2->lb)
-                       {
-                               *rP = s = new Range(lb, r2->lb);
-                               rP = &s->next;
-                       }
-
-                       if ((lb = r2->ub) >= r1->ub)
-                               goto noMore;
-               }
-
-               *rP = s = new Range(lb, r1->ub);
-               rP = &s->next;
-
-noMore:
-               ;
-       }
-
-       *rP = NULL;
-       return r;
-}
-
 MatchOp *merge(MatchOp *m1, MatchOp *m2)
 {
        if (!m1)
diff --git a/re2c/range.cc b/re2c/range.cc
new file mode 100644 (file)
index 0000000..2a9dfb7
--- /dev/null
@@ -0,0 +1,137 @@
+#include "print.h"
+#include "range.h"
+
+namespace re2c
+{
+
+std::ostream& operator<<(std::ostream &o, const Range &r)
+{
+       if ((r.ub - r.lb) == 1)
+       {
+               prtCh(o, r.lb);
+       }
+       else
+       {
+               prtCh(o, r.lb);
+               o << "-";
+               prtCh(o, r.ub - 1);
+       }
+
+       return o << r.next;
+}
+
+Range *doUnion(Range *r1, Range *r2)
+{
+       if (r1 == NULL)
+               return r2;
+       if (r2 == NULL)
+               return r1;
+
+       Range *r, **rP = &r;
+
+       for (;;)
+       {
+               Range *s;
+
+               if (r1->lb <= r2->lb)
+               {
+                       s = new Range(*r1);
+               }
+               else
+               {
+                       s = new Range(*r2);
+               }
+
+               *rP = s;
+               rP = &s->next;
+
+               for (;;)
+               {
+                       if (r1->lb <= r2->lb)
+                       {
+                               if (r1->lb > s->ub)
+                                       break;
+
+                               if (r1->ub > s->ub)
+                                       s->ub = r1->ub;
+
+                               if (!(r1 = r1->next))
+                               {
+                                       uint ub = 0;
+
+                                       for (; r2 && r2->lb <= s->ub; r2 = r2->next)
+                                               ub = r2->ub;
+
+                                       if (ub > s->ub)
+                                               s->ub = ub;
+
+                                       *rP = r2;
+
+                                       return r;
+                               }
+                       }
+                       else
+                       {
+                               if (r2->lb > s->ub)
+                                       break;
+
+                               if (r2->ub > s->ub)
+                                       s->ub = r2->ub;
+
+                               if (!(r2 = r2->next))
+                               {
+                                       uint ub = 0;
+
+                                       for (; r1 && r1->lb <= s->ub; r1 = r1->next)
+                                               ub = r1->ub;
+
+                                       if (ub > s->ub)
+                                               s->ub = ub;
+
+                                       *rP = r1;
+
+                                       return r;
+                               }
+                       }
+               }
+       }
+
+       *rP = NULL;
+       return r;
+}
+
+Range *doDiff(Range *r1, Range *r2)
+{
+       Range *r, *s, **rP = &r;
+
+       for (; r1; r1 = r1->next)
+       {
+               uint lb = r1->lb;
+
+               for (; r2 && r2->ub <= r1->lb; r2 = r2->next)
+
+                       ;
+               for (; r2 && r2->lb < r1->ub; r2 = r2->next)
+               {
+                       if (lb < r2->lb)
+                       {
+                               *rP = s = new Range(lb, r2->lb);
+                               rP = &s->next;
+                       }
+
+                       if ((lb = r2->ub) >= r1->ub)
+                               goto noMore;
+               }
+
+               *rP = s = new Range(lb, r1->ub);
+               rP = &s->next;
+
+noMore:
+               ;
+       }
+
+       *rP = NULL;
+       return r;
+}
+
+} // end namespace re2c
diff --git a/re2c/range.h b/re2c/range.h
new file mode 100644 (file)
index 0000000..a1f5284
--- /dev/null
@@ -0,0 +1,51 @@
+#ifndef _range_h
+#define _range_h
+
+#include <iostream>
+
+#include "basics.h"
+#include "free_list.h"
+
+namespace re2c
+{
+
+class Range
+{
+
+public:
+       Range   *next;
+       uint    lb, ub;         // [lb,ub)
+
+       static free_list<Range*> vFreeList;
+
+public:
+       Range(uint l, uint u) : next(NULL), lb(l), ub(u)
+       {
+               vFreeList.insert(this);
+       }
+
+       Range(Range &r) : next(NULL), lb(r.lb), ub(r.ub)
+       {
+               vFreeList.insert(this);
+       }
+
+       ~Range()
+       {
+               vFreeList.erase(this);
+       }
+
+       friend std::ostream& operator<<(std::ostream&, const Range&);
+       friend std::ostream& operator<<(std::ostream&, const Range*);
+};
+
+inline std::ostream& operator<<(std::ostream &o, const Range *r)
+{
+       return r ? o << *r : o;
+}
+
+Range *doUnion(Range *r1, Range *r2);
+Range *doDiff(Range *r1, Range *r2);
+
+} // end namespace re2c
+
+#endif
index a164fece1fabfa88b6058e976c0458c3992304e1..a58745453797ec4f3d91054121732c02243dc372 100644 (file)
--- a/re2c/re.h
+++ b/re2c/re.h
@@ -12,6 +12,7 @@
 #include "ins.h"
 #include "free_list.h"
 #include "globals.h"
+#include "range.h"
 #include "smart_ptr.h"
 
 namespace re2c
@@ -46,40 +47,6 @@ struct CharSet
        CharPtn *ptn;
 };
 
-class Range
-{
-
-public:
-       Range   *next;
-       uint    lb, ub;         // [lb,ub)
-
-       static free_list<Range*> vFreeList;
-
-public:
-       Range(uint l, uint u) : next(NULL), lb(l), ub(u)
-       {
-               vFreeList.insert(this);
-       }
-
-       Range(Range &r) : next(NULL), lb(r.lb), ub(r.ub)
-       {
-               vFreeList.insert(this);
-       }
-
-       ~Range()
-       {
-               vFreeList.erase(this);
-       }
-
-       friend std::ostream& operator<<(std::ostream&, const Range&);
-       friend std::ostream& operator<<(std::ostream&, const Range*);
-};
-
-inline std::ostream& operator<<(std::ostream &o, const Range *r)
-{
-       return r ? o << *r : o;
-}
-
 class RegExp
 {