/[pcre]/code/trunk/pcre_compile.c
ViewVC logotype

Diff of /code/trunk/pcre_compile.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 923 by zherczeg, Mon Jan 23 19:26:03 2012 UTC revision 924 by zherczeg, Wed Feb 22 10:23:56 2012 UTC
# Line 2225  for (;;) Line 2225  for (;;)
2225        {        {
2226        case OP_CHAR:        case OP_CHAR:
2227        case OP_CHARI:        case OP_CHARI:
2228          case OP_NOT:
2229          case OP_NOTI:
2230        case OP_EXACT:        case OP_EXACT:
2231        case OP_EXACTI:        case OP_EXACTI:
2232          case OP_NOTEXACT:
2233          case OP_NOTEXACTI:
2234        case OP_UPTO:        case OP_UPTO:
2235        case OP_UPTOI:        case OP_UPTOI:
2236          case OP_NOTUPTO:
2237          case OP_NOTUPTOI:
2238        case OP_MINUPTO:        case OP_MINUPTO:
2239        case OP_MINUPTOI:        case OP_MINUPTOI:
2240          case OP_NOTMINUPTO:
2241          case OP_NOTMINUPTOI:
2242        case OP_POSUPTO:        case OP_POSUPTO:
2243        case OP_POSUPTOI:        case OP_POSUPTOI:
2244          case OP_NOTPOSUPTO:
2245          case OP_NOTPOSUPTOI:
2246        case OP_STAR:        case OP_STAR:
2247        case OP_STARI:        case OP_STARI:
2248          case OP_NOTSTAR:
2249          case OP_NOTSTARI:
2250        case OP_MINSTAR:        case OP_MINSTAR:
2251        case OP_MINSTARI:        case OP_MINSTARI:
2252          case OP_NOTMINSTAR:
2253          case OP_NOTMINSTARI:
2254        case OP_POSSTAR:        case OP_POSSTAR:
2255        case OP_POSSTARI:        case OP_POSSTARI:
2256          case OP_NOTPOSSTAR:
2257          case OP_NOTPOSSTARI:
2258        case OP_PLUS:        case OP_PLUS:
2259        case OP_PLUSI:        case OP_PLUSI:
2260          case OP_NOTPLUS:
2261          case OP_NOTPLUSI:
2262        case OP_MINPLUS:        case OP_MINPLUS:
2263        case OP_MINPLUSI:        case OP_MINPLUSI:
2264          case OP_NOTMINPLUS:
2265          case OP_NOTMINPLUSI:
2266        case OP_POSPLUS:        case OP_POSPLUS:
2267        case OP_POSPLUSI:        case OP_POSPLUSI:
2268          case OP_NOTPOSPLUS:
2269          case OP_NOTPOSPLUSI:
2270        case OP_QUERY:        case OP_QUERY:
2271        case OP_QUERYI:        case OP_QUERYI:
2272          case OP_NOTQUERY:
2273          case OP_NOTQUERYI:
2274        case OP_MINQUERY:        case OP_MINQUERY:
2275        case OP_MINQUERYI:        case OP_MINQUERYI:
2276          case OP_NOTMINQUERY:
2277          case OP_NOTMINQUERYI:
2278        case OP_POSQUERY:        case OP_POSQUERY:
2279        case OP_POSQUERYI:        case OP_POSQUERYI:
2280          case OP_NOTPOSQUERY:
2281          case OP_NOTPOSQUERYI:
2282        if (HAS_EXTRALEN(code[-1])) code += GET_EXTRALEN(code[-1]);        if (HAS_EXTRALEN(code[-1])) code += GET_EXTRALEN(code[-1]);
2283        break;        break;
2284        }        }
# Line 3069  if (next >= 0) switch(op_code) Line 3097  if (next >= 0) switch(op_code)
3097  #endif  /* SUPPORT_UTF */  #endif  /* SUPPORT_UTF */
3098    return (c != TABLE_GET((unsigned int)next, cd->fcc, next));  /* Non-UTF-8 mode */    return (c != TABLE_GET((unsigned int)next, cd->fcc, next));  /* Non-UTF-8 mode */
3099    
   /* For OP_NOT and OP_NOTI, the data is always a single-byte character. These  
   opcodes are not used for multi-byte characters, because they are coded using  
   an XCLASS instead. */  
   
3100    case OP_NOT:    case OP_NOT:
3101    return (c = *previous) == next;  #ifdef SUPPORT_UTF
3102      GETCHARTEST(c, previous);
3103    #else
3104      c = *previous;
3105    #endif
3106      return c == next;
3107    
3108    case OP_NOTI:    case OP_NOTI:
3109    if ((c = *previous) == next) return TRUE;  #ifdef SUPPORT_UTF
3110      GETCHARTEST(c, previous);
3111    #else
3112      c = *previous;
3113    #endif
3114      if (c == next) return TRUE;
3115  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
3116    if (utf)    if (utf)
3117      {      {
3118      unsigned int othercase;      unsigned int othercase;
3119      if (next < 128) othercase = cd->fcc[next]; else      if (next < 128) othercase = cd->fcc[next]; else
3120  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
3121      othercase = UCD_OTHERCASE(next);      othercase = UCD_OTHERCASE((unsigned int)next);
3122  #else  #else
3123      othercase = NOTACHAR;      othercase = NOTACHAR;
3124  #endif  #endif
# Line 3092  if (next >= 0) switch(op_code) Line 3126  if (next >= 0) switch(op_code)
3126      }      }
3127    else    else
3128  #endif  /* SUPPORT_UTF */  #endif  /* SUPPORT_UTF */
3129    return (c == (int)(TABLE_GET((unsigned int)next, cd->fcc, next)));  /* Non-UTF-8 mode */    return (c == TABLE_GET((unsigned int)next, cd->fcc, next));  /* Non-UTF-8 mode */
3130    
3131    /* Note that OP_DIGIT etc. are generated only when PCRE_UCP is *not* set.    /* Note that OP_DIGIT etc. are generated only when PCRE_UCP is *not* set.
3132    When it is set, \d etc. are converted into OP_(NOT_)PROP codes. */    When it is set, \d etc. are converted into OP_(NOT_)PROP codes. */
# Line 4485  for (;; ptr++) Line 4519  for (;; ptr++)
4519        if (class_single_char < 2) class_single_char++;        if (class_single_char < 2) class_single_char++;
4520    
4521        /* If class_charcount is 1, we saw precisely one character. As long as        /* If class_charcount is 1, we saw precisely one character. As long as
4522        there were no negated characters >= 128 and there was no use of \p or \P,        there was no use of \p or \P, in other words, no use of any XCLASS features,
4523        in other words, no use of any XCLASS features, we can optimize.        we can optimize.
   
       In UTF-8 mode, we can optimize the negative case only if there were no  
       characters >= 128 because OP_NOT and the related opcodes like OP_NOTSTAR  
       operate on single-bytes characters only. This is an historical hangover.  
       Maybe one day we can tidy these opcodes to handle multi-byte characters.  
4524    
4525        The optimization throws away the bit map. We turn the item into a        The optimization throws away the bit map. We turn the item into a
4526        1-character OP_CHAR[I] if it's positive, or OP_NOT[I] if it's negative.        1-character OP_CHAR[I] if it's positive, or OP_NOT[I] if it's negative.
4527        Note that OP_NOT[I] does not support multibyte characters. In the positive        In the positive case, it can cause firstchar to be set. Otherwise, there
4528        case, it can cause firstchar to be set. Otherwise, there can be no first        can be no first char if this item is first, whatever repeat count may
4529        char if this item is first, whatever repeat count may follow. In the case        follow. In the case of reqchar, save the previous value for reinstating. */
       of reqchar, save the previous value for reinstating. */  
4530    
 #ifdef SUPPORT_UTF  
       if (class_single_char == 1 && ptr[1] == CHAR_RIGHT_SQUARE_BRACKET  
         && (!utf || !negate_class || c < (MAX_VALUE_FOR_SINGLE_CHAR + 1)))  
 #else  
4531        if (class_single_char == 1 && ptr[1] == CHAR_RIGHT_SQUARE_BRACKET)        if (class_single_char == 1 && ptr[1] == CHAR_RIGHT_SQUARE_BRACKET)
 #endif  
4532          {          {
4533          ptr++;          ptr++;
4534          zeroreqchar = reqchar;          zeroreqchar = reqchar;
# Line 4517  for (;; ptr++) Line 4540  for (;; ptr++)
4540            if (firstchar == REQ_UNSET) firstchar = REQ_NONE;            if (firstchar == REQ_UNSET) firstchar = REQ_NONE;
4541            zerofirstchar = firstchar;            zerofirstchar = firstchar;
4542            *code++ = ((options & PCRE_CASELESS) != 0)? OP_NOTI: OP_NOT;            *code++ = ((options & PCRE_CASELESS) != 0)? OP_NOTI: OP_NOT;
4543            *code++ = c;  #ifdef SUPPORT_UTF
4544              if (utf && c > MAX_VALUE_FOR_SINGLE_CHAR)
4545                code += PRIV(ord2utf)(c, code);
4546              else
4547    #endif
4548                *code++ = c;
4549            goto NOT_CHAR;            goto NOT_CHAR;
4550            }            }
4551    
# Line 4775  for (;; ptr++) Line 4803  for (;; ptr++)
4803    
4804      /* Now handle repetition for the different types of item. */      /* Now handle repetition for the different types of item. */
4805    
4806      /* If previous was a character match, abolish the item and generate a      /* If previous was a character or negated character match, abolish the item
4807      repeat item instead. If a char item has a minumum of more than one, ensure      and generate a repeat item instead. If a char item has a minumum of more
4808      that it is set in reqchar - it might not be if a sequence such as x{3} is      than one, ensure  that it is set in reqchar - it might not be if a sequence
4809      the first thing in a branch because the x will have gone into firstchar      such as x{3} is  the first thing in a branch because the x will have gone
4810      instead.  */      into firstchar instead.  */
4811    
4812      if (*previous == OP_CHAR || *previous == OP_CHARI)      if (*previous == OP_CHAR || *previous == OP_CHARI
4813        {          || *previous == OP_NOT || *previous == OP_NOTI)
4814        op_type = (*previous == OP_CHAR)? 0 : OP_STARI - OP_STAR;        {
4815          switch (*previous) {
4816          default: /* Make compiler happy. */
4817          case OP_CHAR:  op_type = OP_STAR - OP_STAR; break;
4818          case OP_CHARI: op_type = OP_STARI - OP_STAR; break;
4819          case OP_NOT:   op_type = OP_NOTSTAR - OP_STAR; break;
4820          case OP_NOTI:  op_type = OP_NOTSTARI - OP_STAR; break;
4821          }
4822    
4823        /* Deal with UTF characters that take up more than one character. It's        /* Deal with UTF characters that take up more than one character. It's
4824        easier to write this out separately than try to macrify it. Use c to        easier to write this out separately than try to macrify it. Use c to
# Line 4806  for (;; ptr++) Line 4841  for (;; ptr++)
4841        with UTF disabled, or for a single character UTF character. */        with UTF disabled, or for a single character UTF character. */
4842          {          {
4843          c = code[-1];          c = code[-1];
4844          if (repeat_min > 1) reqchar = c | req_caseopt | cd->req_varyopt;          if (*previous <= OP_CHARI && repeat_min > 1)
4845              reqchar = c | req_caseopt | cd->req_varyopt;
4846          }          }
4847    
4848        /* If the repetition is unlimited, it pays to see if the next thing on        /* If the repetition is unlimited, it pays to see if the next thing on
# Line 4825  for (;; ptr++) Line 4861  for (;; ptr++)
4861        goto OUTPUT_SINGLE_REPEAT;   /* Code shared with single character types */        goto OUTPUT_SINGLE_REPEAT;   /* Code shared with single character types */
4862        }        }
4863    
     /* If previous was a single negated character ([^a] or similar), we use  
     one of the special opcodes, replacing it. The code is shared with single-  
     character repeats by setting opt_type to add a suitable offset into  
     repeat_type. We can also test for auto-possessification. OP_NOT and OP_NOTI  
     are currently used only for single-byte chars. */  
   
     else if (*previous == OP_NOT || *previous == OP_NOTI)  
       {  
       op_type = ((*previous == OP_NOT)? OP_NOTSTAR : OP_NOTSTARI) - OP_STAR;  
       c = previous[1];  
       if (!possessive_quantifier &&  
           repeat_max < 0 &&  
           check_auto_possessive(previous, utf, ptr + 1, options, cd))  
         {  
         repeat_type = 0;    /* Force greedy */  
         possessive_quantifier = TRUE;  
         }  
       goto OUTPUT_SINGLE_REPEAT;  
       }  
   
4864      /* If previous was a character type match (\d or similar), abolish it and      /* If previous was a character type match (\d or similar), abolish it and
4865      create a suitable repeat item. The code is shared with single-character      create a suitable repeat item. The code is shared with single-character
4866      repeats by setting op_type to add a suitable offset into repeat_type. Note      repeats by setting op_type to add a suitable offset into repeat_type. Note

Legend:
Removed from v.923  
changed lines
  Added in v.924

webmaster@exim.org
ViewVC Help
Powered by ViewVC 1.1.12