Mercurial > hg > Members > masakoha > testcode
changeset 168:6b31d6ef9ba4 pairPro
impl createCharClassRange()
author | Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Sat, 19 Dec 2015 16:09:19 +0900 |
parents | 3bf2c6d6d53e |
children | 313f1c176328 |
files | regexParser/subsetConstraction.cc |
diffstat | 1 files changed, 38 insertions(+), 63 deletions(-) [+] |
line wrap: on
line diff
--- a/regexParser/subsetConstraction.cc Sat Dec 19 15:38:45 2015 +0900 +++ b/regexParser/subsetConstraction.cc Sat Dec 19 16:09:19 2015 +0900 @@ -6,6 +6,17 @@ CharClassPtr createCharClassWord(unsigned char *w, CharClassPtr cc1, CharClassPtr cc2) { CharClassPtr cc = NEW(CharClass); return cc; +} + +CharClassPtr createCharClassRange(unsigned long begin, unsigned long end,unsigned long state, CharClassPtr left, CharClassPtr right) { + CharClassPtr cc = NEW(CharClass); + cc->type = 'r'; + cc->cond.range.begin = begin; + cc->cond.range.end = end; + cc->left = left; + cc->right = right; + cc->nextState.bitContainer = state; + return cc; } CharClassPtr mergeCCTree(CharClassPtr cc,unsigned char mBegin,unsigned char mEnd,BitVector nextState) { @@ -13,8 +24,7 @@ if (cc) { cc1 = charClassMerge(cc,mBegin,mEnd,nextState); } else { - cc1 = createCharClassRange(mBegin,mEnd,NULL,NULL); - cc1->nextState = nextState; + cc1 = createCharClassRange(mBegin,mEnd,nextState.bitContainer,NULL,NULL); } return cc1; } @@ -27,110 +37,75 @@ if (cc->left) { 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; - return cc1; + return createCharClassRange(begin,end,nextState.bitContainer,NULL,cc); } } else if (end == cc->cond.range.begin && begin != end ) { // 2 CharClassPtr cc1 = mergeCCTree(cc->left,begin,end-1,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; + return createCharClassRange(cc->cond.range.begin,cc->cond.range.end, + cc->nextState.bitContainer | nextState.bitContainer, cc1,cc->right); } - CharClassPtr cc3 = createCharClassRange(cc->cond.range.begin+1,cc->cond.range.end,cc->left,cc->right); - cc3->nextState = cc->nextState; - CharClassPtr cc2 = createCharClassRange(cc->cond.range.begin,cc->cond.range.begin,cc1,cc3); - cc2->nextState.bitContainer = cc->nextState.bitContainer | nextState.bitContainer; - return cc2; + CharClassPtr cc3 = createCharClassRange(cc->cond.range.begin+1,cc->cond.range.end,cc->nextState.bitContainer,cc->left,cc->right); + return createCharClassRange(cc->cond.range.begin,cc->cond.range.begin, + cc->nextState.bitContainer | nextState.bitContainer,cc1,cc3); } else if (end < cc->cond.range.end) { // range.begin < end if (begin < cc->cond.range.begin) { // 3 CharClassPtr cc1 = mergeCCTree(cc->left,begin,cc->cond.range.begin-1,nextState); - CharClassPtr cc3 = createCharClassRange(end+1,cc->cond.range.end,cc->left,cc->right); - cc3->nextState = cc->nextState; - CharClassPtr cc2 = createCharClassRange(cc->cond.range.begin,end,cc1,cc3); - cc2->nextState.bitContainer = cc->nextState.bitContainer | nextState.bitContainer; - return cc2; + CharClassPtr cc3 = createCharClassRange(end+1,cc->cond.range.end,cc->nextState.bitContainer,cc->left,cc->right); + return createCharClassRange(cc->cond.range.begin,end,cc->nextState.bitContainer | nextState.bitContainer,cc1,cc3); } if (begin == cc->cond.range.begin) { // 6 - CharClassPtr cc2 = createCharClassRange(end+1,cc->cond.range.end,NULL,cc->right); - cc2->nextState = cc->nextState; - CharClassPtr cc1 = createCharClassRange(begin,end,cc->left,cc2); - cc1->nextState.bitContainer = cc->nextState.bitContainer | nextState.bitContainer; - return cc1; + CharClassPtr cc2 = createCharClassRange(end+1,cc->cond.range.end,cc->nextState.bitContainer,NULL,cc->right); + return createCharClassRange(begin,end,cc->nextState.bitContainer | nextState.bitContainer,cc->left,cc2); } // 9 - CharClassPtr cc2 = createCharClassRange(cc->cond.range.begin,begin-1,cc->left,NULL); - cc2->nextState = cc->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.bitContainer = cc->nextState.bitContainer | nextState.bitContainer; - return cc1; + CharClassPtr cc2 = createCharClassRange(cc->cond.range.begin,begin-1,cc->nextState.bitContainer,cc->left,NULL); + CharClassPtr cc3 = createCharClassRange(end+1,cc->cond.range.end,cc->nextState.bitContainer,NULL,cc->right); + return createCharClassRange(begin,end,cc->nextState.bitContainer | nextState.bitContainer,cc2,cc3); } 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.bitContainer = cc->nextState.bitContainer | nextState.bitContainer; - return cc1; + return createCharClassRange(begin,end,cc->nextState.bitContainer | nextState.bitContainer,cc->left,cc->right); } else if (begin < cc->cond.range.begin) { // 4 CharClassPtr cc1 = mergeCCTree(cc->left,begin,cc->cond.range.begin-1,nextState); - CharClassPtr cc3 = createCharClassRange(cc->cond.range.begin,end,cc1,cc->right); - cc3->nextState.bitContainer = cc->nextState.bitContainer | nextState.bitContainer; - return cc3; + return createCharClassRange(cc->cond.range.begin,end,cc->nextState.bitContainer | nextState.bitContainer,cc1,cc->right); } // 10 cond.range.begin < begin - CharClassPtr cc2 = createCharClassRange(begin,cc->cond.range.end,NULL,cc->right); - cc2->nextState.bitContainer = cc->nextState.bitContainer | nextState.bitContainer; - CharClassPtr cc1 = createCharClassRange(cc->cond.range.begin,begin-1,cc->left,cc2); - cc1->nextState = cc->nextState; - return cc1; + CharClassPtr cc2 = createCharClassRange(begin,cc->cond.range.end,cc->nextState.bitContainer | nextState.bitContainer,NULL,cc->right); + return createCharClassRange(cc->cond.range.begin,begin-1,cc->nextState.bitContainer,cc->left,cc2); } if (begin > cc->cond.range.end ) { // 13 if (cc->right) { 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; - return cc1; + return createCharClassRange(begin,end,nextState.bitContainer,cc,NULL); } } if (begin >= cc->cond.range.begin && begin <= cc->cond.range.end) { if (end > cc->cond.range.end) { // cond.range.end < end if (begin == cc->cond.range.begin) { // 8 CharClassPtr cc1 = mergeCCTree(cc->right,cc->cond.range.end+1,end,nextState); - CharClassPtr cc3 = createCharClassRange(cc->cond.range.begin,cc->cond.range.end,cc->left,cc1); - cc3->nextState.bitContainer = cc->nextState.bitContainer | nextState.bitContainer; - return cc3; + return createCharClassRange(cc->cond.range.begin,cc->cond.range.end, + cc->nextState.bitContainer | nextState.bitContainer,cc->left,cc1); } if (begin > cc->cond.range.begin) { // 11 CharClassPtr cc1 = mergeCCTree(cc->right,cc->cond.range.end+1,end,nextState); - CharClassPtr cc3 = createCharClassRange(cc->cond.range.begin,begin-1,cc->left,NULL); - cc3->nextState = cc->nextState; - CharClassPtr cc2 = createCharClassRange(begin,cc->cond.range.end,cc3,cc1); - cc2->nextState.bitContainer = cc->nextState.bitContainer | nextState.bitContainer; - return cc2; + CharClassPtr cc3 = createCharClassRange(cc->cond.range.begin,begin-1,cc->nextState.bitContainer,cc->left,NULL); + return createCharClassRange(begin,cc->cond.range.end,cc->nextState.bitContainer | nextState.bitContainer,cc3,cc1); } } // begin != end && end != cc->cond.range.end if (begin == cc->cond.range.end) { // 12 CharClassPtr cc1 = mergeCCTree(cc->right,begin+1,end,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; + return createCharClassRange(cc->cond.range.begin,cc->cond.range.end,cc->nextState.bitContainer | nextState.bitContainer,cc1,cc->right); } - CharClassPtr cc3 = createCharClassRange(cc->cond.range.begin,cc->cond.range.end-1,cc->left,NULL); - 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->cond.range.begin,cc->cond.range.end-1,cc->nextState.bitContainer,cc->left,NULL); + return createCharClassRange(cc->cond.range.end,cc->cond.range.end,cc->nextState.bitContainer | nextState.bitContainer,cc1,cc3); } } else if (begin < cc->cond.range.begin) { // 5 CharClassPtr cc1 = mergeCCTree(cc->left,begin,cc->cond.range.begin-1,nextState); CharClassPtr cc3 = mergeCCTree(cc->right,cc->cond.range.end+1,end,nextState); - CharClassPtr cc2 = createCharClassRange(cc->cond.range.begin,cc->cond.range.end,cc1,cc3); - cc2->nextState.bitContainer = cc->nextState.bitContainer | nextState.bitContainer; - return cc2; + return createCharClassRange(cc->cond.range.begin,cc->cond.range.end,cc->nextState.bitContainer | nextState.bitContainer,cc1,cc3); } 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); }