diff c/regexParser/subsetConstraction.cc @ 156:b5ecfc008bcf pairPro

impl charClassMerge(not working)
author Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
date Fri, 18 Dec 2015 17:59:16 +0900
parents 6cd0141bed6c
children dcd751ba7103
line wrap: on
line diff
--- a/c/regexParser/subsetConstraction.cc	Fri Dec 18 15:40:55 2015 +0900
+++ b/c/regexParser/subsetConstraction.cc	Fri Dec 18 17:59:16 2015 +0900
@@ -14,7 +14,7 @@
     // 変更があった場合は新しくリストを作って返す
     if (end < cc->cond.range.begin ) { // 1
         if (cc->left) {
-            return createCharClassRange(cc->begin,cc->end,charClassMerge(cc->left,begin,end,nextState),cc->right);
+            return createCharClassRange(cc->cond.range.begin,cc->cond.range.end,charClassMerge(cc->left,begin,end,nextState),cc->right);
         } else {
             CharClassPtr cc1 =  createCharClassRange(begin,end,NULL,cc);
             cc1->nextState = nextState;
@@ -28,75 +28,73 @@
             cc1 = createCharClassRange(begin,end-1,NULL,NULL);
             cc1->nextState = nextState;
         }
-        if (cc->begin == cc->end) {
-            CharClassPtr cc2 = createCharClassRange(cc->begin,cc->end,cc1,cc->right);
-            cc2->nextState = cc->nextState | nextState;
+        if (cc->cond.range.begin == cc->cond.range.end) {
+            CharClassPtr cc2 = createCharClassRange(cc->cond.range.begin,cc->cond.range.end,cc1,cc->right);
+            cc2->nextState.bitContainer = cc->nextState.bitContainer | nextState.bitContainer;
             return cc2;
         }
-        CharClassPtr cc3;
-        createCharClassRange(cc->begin+1,cc->end,cc->left,cc->end);
+        CharClassPtr cc3 = createCharClassRange(cc->cond.range.begin+1,cc->cond.range.end,cc->left,cc->right);
         cc3->nextState = cc->nextState;
-        CharClassPtr cc2 = createCharClassRange(cc->begin,cc->begin,cc1,cc3);
-        cc2->nextState = cc->nextState | nextState;
+        CharClassPtr cc2 = createCharClassRange(cc->cond.range.begin,cc->cond.range.begin,cc1,cc3);
+        cc2->nextState.bitContainer = cc->nextState.bitContainer | nextState.bitContainer;
         return cc2;
     } else if (end < cc->cond.range.end) {
         if (begin < cc->cond.range.begin) {  // 3
             CharClassPtr cc1;
             if (cc->left) {
-                cc1 = charClassMerge(cc->left,begin,cc->begin-1,nextState);
+                cc1 = charClassMerge(cc->left,begin,cc->cond.range.begin-1,nextState);
             } else {
-                cc1 = createCharClassRange(begin,cc->begin-1,NULL,NULL);
+                cc1 = createCharClassRange(begin,cc->cond.range.begin-1,NULL,NULL);
                 cc1->nextState = nextState;
             }
-            CharClassPtr cc3 = createCharClassRange(end+1,cc->end,cc->left,cc->right);
+            CharClassPtr cc3 = createCharClassRange(end+1,cc->cond.range.end,cc->left,cc->right);
             cc3->nextState = cc->nextState;
-            CharClassPtr cc2 = createCharClassRange(cc->begin,end,cc1,cc3);
-            cc2->nextState = cc->nextState | nextState;
+            CharClassPtr cc2 = createCharClassRange(cc->cond.range.begin,end,cc1,cc3);
+            cc2->nextState.bitContainer = cc->nextState.bitContainer | nextState.bitContainer;
             return cc2;
         }
         if (begin == cc->cond.range.begin) {  // 6
-            CharClassPtr cc2 = createCharClassRange(end,cc->end,NULL,cc->right);
+            CharClassPtr cc2 = createCharClassRange(end,cc->cond.range.end,NULL,cc->right);
             cc2->nextState = cc->nextState;
             CharClassPtr cc1 = createCharClassRange(begin,end,cc->left,cc2);
-            cc1->nextState = cc->nextState | nextState;
+            cc1->nextState.bitContainer = cc->nextState.bitContainer | nextState.bitContainer;
             return cc1;
         }
         // 9
-        CharClassPtr cc2 = createCharClassRange(cc->begin,begin-1,cc->left,NULL);
-        cc2->nextState = cc1->nextState;
-        CharClassPtr cc3 = createCharClassRange(end+1,cc->end,NULL,cc->right);
+        CharClassPtr cc2 = createCharClassRange(cc->cond.range.begin,begin-1,cc->left,NULL);
+        cc2->nextState = cc2->nextState;
+        CharClassPtr cc3 = createCharClassRange(end+1,cc->cond.range.end,NULL,cc->right);
         cc3->nextState = cc->nextState;
         CharClassPtr cc1 = createCharClassRange(begin,end,cc2,cc3);
-        cc1->nextState = cc->nextState | nextState;
+        cc1->nextState.bitContainer = cc->nextState.bitContainer | nextState.bitContainer;
         return cc1;
     } else if (end == cc->cond.range.end) {
         if (begin == cc->cond.range.begin) { // 7
             CharClassPtr cc1 = createCharClassRange(begin,end,cc->left,cc->right);
-            cc1->nextState = cc->nextState | nextState;
+            cc1->nextState.bitContainer = cc->nextState.bitContainer | nextState.bitContainer;
             return cc1;
         } else if (begin < cc->cond.range.begin) { // 4
             CharClassPtr cc1;
             if (cc->left) {
-                cc1 = charClassMerge(cc->left,begin,end-1,nextState);
+                cc1 = charClassMerge(cc->left,begin,cc->cond.range.begin-1,nextState);
             } else {
-                cc1 = createCharClassRange(begin,end-1,NULL,NULL);
+                cc1 = createCharClassRange(begin,cc->cond.range.begin-1,NULL,NULL);
                 cc1->nextState = nextState;
             }
-            CharClassPtr cc3 = createCharClassRange(end+1,cc->end,cc1,cc->right);
-            cc3->nextState = cc->nextState | nextState;
+            CharClassPtr cc3 = createCharClassRange(cc->cond.range.begin,end,cc1,cc->right);
+            cc3->nextState.bitContainer = cc->nextState.bitContainer | nextState.bitContainer;
             return cc3;
         }
         // 10
         CharClassPtr cc2 = createCharClassRange(begin,cc->cond.range.end,NULL,cc->right);
-        cc2->nextState = cc->nextState | nextState;
+        cc2->nextState.bitContainer = cc->nextState.bitContainer | nextState.bitContainer;
         CharClassPtr cc1 = createCharClassRange(cc->cond.range.begin,begin-1,NULL,NULL);
         cc1->nextState = cc->nextState;
         return cc1;
-        
     }
     if (begin > cc->cond.range.end ) { // 13
         if (cc->right) {
-            return createCharClassRange(cc->begin,cc->end,cc->left,charClassMerge(cc->right,begin,end,nextState));
+            return createCharClassRange(cc->cond.range.begin,cc->cond.range.end,cc->left,charClassMerge(cc->right,begin,end,nextState));
         } else {
             CharClassPtr cc1 =  createCharClassRange(begin,end,cc,NULL);
             cc1->nextState = nextState;
@@ -107,41 +105,62 @@
         if (end > cc->cond.range.end) {
             if (begin == cc->cond.range.begin) {    // 8
                 CharClassPtr cc1;
-                if (cc->left) {
-                    cc1 = charClassMerge(cc->left,begin,end-1,nextState);
+                if (cc->right) {
+                    cc1 = charClassMerge(cc->right,begin,cc->cond.range.end,nextState);
                 } else {
-                    cc1 = createCharClassRange(begin,end-1,NULL,NULL);
+                    cc1 = createCharClassRange(begin,cc->cond.range.end,NULL,NULL);
                     cc1->nextState = nextState;
                 }
-                CharClassPtr cc3 = createCharClassRange(end+1,cc->end,cc1,cc->right);
-                cc3->nextState = cc->nextState | nextState;
+                CharClassPtr cc3 = createCharClassRange(cc->cond.range.end+1,end,cc->left,cc1);
+                cc3->nextState.bitContainer = cc->nextState.bitContainer | nextState.bitContainer;
                 return cc3;
             }
-            // 11
-            cc->cond.range.end = end; // 11,8
-            return cc;
+
+            if (begin > cc->cond.range.begin) {  // 11
+                CharClassPtr cc1;
+                if (cc->right) {
+                    cc1 = charClassMerge(cc->right,cc->cond.range.end+1,end,nextState);
+                } else {
+                    cc1 = createCharClassRange(cc->cond.range.end+1,end,NULL,NULL);
+                    cc1->nextState = nextState;
+                }
+                CharClassPtr cc3 = createCharClassRange(cc->cond.range.begin,begin-1,cc->left,cc->right);
+                cc3->nextState = cc->nextState;
+                CharClassPtr cc2 = createCharClassRange(begin,cc->cond.range.end,cc3,cc1);
+                cc2->nextState.bitContainer = cc->nextState.bitContainer | nextState.bitContainer;
+                return cc2;
+            }
         }
         // 12
-        CharClassPtr cc1;
-        if (cc->right) {
-            cc1 = charClassMerge(cc->right,begin+1,end,nextState);
-        } else {
-            cc1 = createCharClassRange(begin+1,end,NULL,NULL);
-            cc1->nextState = nextState;
-        }
-        if (cc->begin == cc->end) {
-            CharClassPtr cc2 = createCharClassRange(cc->begin,cc->end,cc->left,cc1);
-            cc2->nextState = cc->nextState | nextState;
+        if (begin == cc->cond.range.end) {
+            CharClassPtr cc1;
+            if (cc->right) {
+                cc1 = charClassMerge(cc->right,begin+1,end,nextState);
+            } else {
+                cc1 = createCharClassRange(begin+1,end,NULL,NULL);
+                cc1->nextState = nextState;
+            }
+            if (cc->cond.range.begin == cc->cond.range.end) {
+                CharClassPtr cc2 = createCharClassRange(cc->cond.range.begin,cc->cond.range.end,cc1,cc->right);
+                cc2->nextState.bitContainer = cc->nextState.bitContainer | nextState.bitContainer;
+                return cc2;
+            }
+            CharClassPtr cc3;
+            createCharClassRange(cc->cond.range.begin,cc->cond.range.end-1,cc->left,cc->right);
+            cc3->nextState = cc->nextState;
+            CharClassPtr cc2 = createCharClassRange(cc->cond.range.end,cc->cond.range.end,cc1,cc3);
+            cc2->nextState.bitContainer = cc->nextState.bitContainer | nextState.bitContainer;
             return cc2;
         }
-        CharClassPtr cc3 = createCharClassRange(cc->begin,cc->end-1,NULL,cc->right);
+
+    } else if (begin < cc->cond.range.begin) { // 5
+        CharClassPtr cc2 = createCharClassRange(cc->cond.range.begin,begin-1,cc->left,NULL);
+        cc2->nextState = cc1->nextState;
+        CharClassPtr cc3 = createCharClassRange(end+1,cc->cond.range.end,NULL,cc->right);
         cc3->nextState = cc->nextState;
-        CharClassPtr cc2 = createCharClassRange(cc->cond.range.end,cc->cond.range.end,cc1,cc3);
-        cc2->nextState = cc->nextState | nextState;
-        return cc2;
-    } else if (begin < cc->cond.range.begin) { // 5
-        cc->cond.range.begin = begin;
-        cc->cond.range.end = end;
+        CharClassPtr cc1 = createCharClassRange(cc->cond.range.begin,cc->cond.range.end,cc2,cc3);
+        cc1->nextState.bitContainer = cc->nextState.bitContainer | nextState.bitContainer;
+        return cc1;
     } else {
         printf("charClassMerge Error : begin %lu end %lu cc->begin %lu cc->end %lu\n", begin,end,cc->cond.range.begin,cc->cond.range.end);
     }