/[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 1376 by ph10, Sat Oct 12 18:02:11 2013 UTC revision 1379 by ph10, Mon Oct 14 13:54:07 2013 UTC
# Line 1817  for (;;) Line 1817  for (;;)
1817    
1818      switch (*cc)      switch (*cc)
1819        {        {
       case OP_CRPLUS:  
       case OP_CRMINPLUS:  
1820        case OP_CRSTAR:        case OP_CRSTAR:
1821        case OP_CRMINSTAR:        case OP_CRMINSTAR:
1822          case OP_CRPLUS:
1823          case OP_CRMINPLUS:
1824        case OP_CRQUERY:        case OP_CRQUERY:
1825        case OP_CRMINQUERY:        case OP_CRMINQUERY:
1826          case OP_CRPOSSTAR:
1827          case OP_CRPOSPLUS:
1828          case OP_CRPOSQUERY:
1829        return -1;        return -1;
1830    
1831        case OP_CRRANGE:        case OP_CRRANGE:
1832        case OP_CRMINRANGE:        case OP_CRMINRANGE:
1833          case OP_CRPOSRANGE:
1834        if (GET2(cc,1) != GET2(cc,1+IMM2_SIZE)) return -1;        if (GET2(cc,1) != GET2(cc,1+IMM2_SIZE)) return -1;
1835        branchlength += (int)GET2(cc,1);        branchlength += (int)GET2(cc,1);
1836        cc += 1 + 2 * IMM2_SIZE;        cc += 1 + 2 * IMM2_SIZE;
# Line 2419  for (code = first_significant_code(code Line 2423  for (code = first_significant_code(code
2423        case OP_CRMINSTAR:        case OP_CRMINSTAR:
2424        case OP_CRQUERY:        case OP_CRQUERY:
2425        case OP_CRMINQUERY:        case OP_CRMINQUERY:
2426          case OP_CRPOSSTAR:
2427          case OP_CRPOSQUERY:
2428        break;        break;
2429    
2430        default:                   /* Non-repeat => class must match */        default:                   /* Non-repeat => class must match */
2431        case OP_CRPLUS:            /* These repeats aren't empty */        case OP_CRPLUS:            /* These repeats aren't empty */
2432        case OP_CRMINPLUS:        case OP_CRMINPLUS:
2433          case OP_CRPOSPLUS:
2434        return FALSE;        return FALSE;
2435    
2436        case OP_CRRANGE:        case OP_CRRANGE:
2437        case OP_CRMINRANGE:        case OP_CRMINRANGE:
2438          case OP_CRPOSRANGE:
2439        if (GET2(ccode, 1) > 0) return FALSE;  /* Minimum > 0 */        if (GET2(ccode, 1) > 0) return FALSE;  /* Minimum > 0 */
2440        break;        break;
2441        }        }
# Line 2920  switch(c) Line 2928  switch(c)
2928      case OP_CRMINSTAR:      case OP_CRMINSTAR:
2929      case OP_CRQUERY:      case OP_CRQUERY:
2930      case OP_CRMINQUERY:      case OP_CRMINQUERY:
2931        case OP_CRPOSSTAR:
2932        case OP_CRPOSQUERY:
2933      list[1] = TRUE;      list[1] = TRUE;
2934      end++;      end++;
2935      break;      break;
2936    
2937        case OP_CRPLUS:
2938        case OP_CRMINPLUS:
2939        case OP_CRPOSPLUS:
2940        end++;
2941        break;
2942    
2943      case OP_CRRANGE:      case OP_CRRANGE:
2944      case OP_CRMINRANGE:      case OP_CRMINRANGE:
2945        case OP_CRPOSRANGE:
2946      list[1] = (GET2(end, 1) == 0);      list[1] = (GET2(end, 1) == 0);
2947      end += 1 + 2 * IMM2_SIZE;      end += 1 + 2 * IMM2_SIZE;
2948      break;      break;
# Line 2956  Returns:      TRUE if the auto-possessif Line 2973  Returns:      TRUE if the auto-possessif
2973    
2974  static BOOL  static BOOL
2975  compare_opcodes(const pcre_uchar *code, BOOL utf, const compile_data *cd,  compare_opcodes(const pcre_uchar *code, BOOL utf, const compile_data *cd,
2976    const pcre_uint32* base_list)    const pcre_uint32* base_list, const pcre_uchar *base_end)
2977  {  {
2978  pcre_uchar c;  pcre_uchar c;
2979  pcre_uint32 list[8];  pcre_uint32 list[8];
# Line 2964  const pcre_uint32* chr_ptr; Line 2981  const pcre_uint32* chr_ptr;
2981  const pcre_uint32* ochr_ptr;  const pcre_uint32* ochr_ptr;
2982  const pcre_uint32* list_ptr;  const pcre_uint32* list_ptr;
2983  const pcre_uchar *next_code;  const pcre_uchar *next_code;
2984    const pcre_uint8 *class_bits;
2985  pcre_uint32 chr;  pcre_uint32 chr;
2986    
2987  /* Note: the base_list[1] contains whether the current opcode has greedy  /* Note: the base_list[1] contains whether the current opcode has greedy
# Line 3039  for(;;) Line 3057  for(;;)
3057    
3058      while (*next_code == OP_ALT)      while (*next_code == OP_ALT)
3059        {        {
3060        if (!compare_opcodes(code, utf, cd, base_list)) return FALSE;        if (!compare_opcodes(code, utf, cd, base_list, base_end)) return FALSE;
3061        code = next_code + 1 + LINK_SIZE;        code = next_code + 1 + LINK_SIZE;
3062        next_code += GET(next_code, 1);        next_code += GET(next_code, 1);
3063        }        }
# Line 3061  for(;;) Line 3079  for(;;)
3079      /* The bracket content will be checked by the      /* The bracket content will be checked by the
3080      OP_BRA/OP_CBRA case above. */      OP_BRA/OP_CBRA case above. */
3081      next_code += 1 + LINK_SIZE;      next_code += 1 + LINK_SIZE;
3082      if (!compare_opcodes(next_code, utf, cd, base_list)) return FALSE;      if (!compare_opcodes(next_code, utf, cd, base_list, base_end)) return FALSE;
3083    
3084      code += PRIV(OP_lengths)[c];      code += PRIV(OP_lengths)[c];
3085      continue;      continue;
# Line 3318  for(;;) Line 3336  for(;;)
3336          return FALSE;          return FALSE;
3337        break;        break;
3338    
       /* The class comparisons work only when the class is the second item  
       of the pair, because there are at present no possessive forms of the  
       class opcodes. Note also that the "code" variable that is used below  
       points after the second item, and that the pointer for the first item  
       is not available, so even if there were possessive forms of the class  
       opcodes, the correct comparison could not be done. */  
   
3339        case OP_NCLASS:        case OP_NCLASS:
3340        if (chr > 255) return FALSE;        if (chr > 255) return FALSE;
3341        /* Fall through */        /* Fall through */
3342    
3343        case OP_CLASS:        case OP_CLASS:
       if (list_ptr != list) return FALSE;   /* Class is first opcode */  
3344        if (chr > 255) break;        if (chr > 255) break;
3345        if ((((pcre_uint8 *)(code - list_ptr[2]))[chr >> 3] & (1 << (chr & 7))) != 0)        class_bits = (pcre_uint8 *)((list_ptr == list ? code : base_end) - list_ptr[2]);
3346          if ((class_bits[chr >> 3] & (1 << (chr & 7))) != 0)
3347          return FALSE;          return FALSE;
3348        break;        break;
3349    
# Line 3380  Returns:      nothing Line 3391  Returns:      nothing
3391  static void  static void
3392  auto_possessify(pcre_uchar *code, BOOL utf, const compile_data *cd)  auto_possessify(pcre_uchar *code, BOOL utf, const compile_data *cd)
3393  {  {
3394  register pcre_uchar c;  register pcre_uchar c, d;
3395  const pcre_uchar *end;  const pcre_uchar *end;
3396    pcre_uchar *repeat_code;
3397  pcre_uint32 list[8];  pcre_uint32 list[8];
3398    
3399  for (;;)  for (;;)
3400    {    {
3401    c = *code;    c = *code;
3402    
3403    if (c >= OP_STAR && c <= OP_TYPEPOSUPTO)    if (c >= OP_STAR && c <= OP_TYPEPOSUPTO)
3404      {      {
3405      c -= get_repeat_base(c) - OP_STAR;      c -= get_repeat_base(c) - OP_STAR;
# Line 3395  for (;;) Line 3407  for (;;)
3407        get_chr_property_list(code, utf, cd->fcc, list) : NULL;        get_chr_property_list(code, utf, cd->fcc, list) : NULL;
3408      list[1] = c == OP_STAR || c == OP_PLUS || c == OP_QUERY || c == OP_UPTO;      list[1] = c == OP_STAR || c == OP_PLUS || c == OP_QUERY || c == OP_UPTO;
3409    
3410      if (end != NULL && compare_opcodes(end, utf, cd, list))      if (end != NULL && compare_opcodes(end, utf, cd, list, end))
3411        {        {
3412        switch(c)        switch(c)
3413          {          {
# Line 3434  for (;;) Line 3446  for (;;)
3446        }        }
3447      c = *code;      c = *code;
3448      }      }
3449      else if (c == OP_CLASS || c == OP_NCLASS || c == OP_XCLASS)
3450        {
3451    #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
3452        if (c == OP_XCLASS)
3453          repeat_code = code + 1 + GET(code, 1);
3454        else
3455    #endif
3456          repeat_code = code + 1 + (32 / sizeof(pcre_uchar));
3457    
3458        d = *repeat_code;
3459        if (d >= OP_CRSTAR && d <= OP_CRMINRANGE)
3460          {
3461          /* end must not be NULL. */
3462          end = get_chr_property_list(code, utf, cd->fcc, list);
3463    
3464          list[1] = d == OP_CRSTAR || d == OP_CRPLUS || d == OP_CRQUERY ||
3465            d == OP_CRRANGE;
3466    
3467          if (compare_opcodes(end, utf, cd, list, end))
3468            {
3469            switch (d)
3470              {
3471              case OP_CRSTAR:
3472              *repeat_code = OP_CRPOSSTAR;
3473              break;
3474    
3475              case OP_CRPLUS:
3476              *repeat_code = OP_CRPOSPLUS;
3477              break;
3478    
3479              case OP_CRQUERY:
3480              *repeat_code = OP_CRPOSQUERY;
3481              break;
3482    
3483              case OP_CRRANGE:
3484              *repeat_code = OP_CRPOSRANGE;
3485              break;
3486              }
3487            }
3488          }
3489        }
3490    
3491    switch(c)    switch(c)
3492      {      {
# Line 3460  for (;;) Line 3513  for (;;)
3513        code += 2;        code += 2;
3514      break;      break;
3515    
3516    #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
3517      case OP_XCLASS:      case OP_XCLASS:
3518      code += GET(code, 1);      code += GET(code, 1);
3519      break;      break;
3520    #endif
3521    
3522      case OP_MARK:      case OP_MARK:
3523      case OP_PRUNE_ARG:      case OP_PRUNE_ARG:

Legend:
Removed from v.1376  
changed lines
  Added in v.1379

  ViewVC Help
Powered by ViewVC 1.1.5