/[pcre]/code/branches/pcre16/pcre_compile.c
ViewVC logotype

Diff of /code/branches/pcre16/pcre_compile.c

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

revision 218 by ph10, Thu Aug 16 10:13:23 2007 UTC revision 223 by ph10, Mon Aug 20 11:07:53 2007 UTC
# Line 283  static const char *error_texts[] = { Line 283  static const char *error_texts[] = {
283    "(*VERB) with an argument is not supported",    "(*VERB) with an argument is not supported",
284    /* 60 */    /* 60 */
285    "(*VERB) not recognized",    "(*VERB) not recognized",
286    "number is too big"    "number is too big"
287  };  };
288    
289    
# Line 524  else Line 524  else
524      c = 0;      c = 0;
525      while ((digitab[ptr[1]] & ctype_digit) != 0)      while ((digitab[ptr[1]] & ctype_digit) != 0)
526        c = c * 10 + *(++ptr) - '0';        c = c * 10 + *(++ptr) - '0';
527    
528      if (c < 0)      if (c < 0)
529        {        {
530        *errorcodeptr = ERR61;        *errorcodeptr = ERR61;
531        break;        break;
532        }        }
533    
534      if (c == 0 || (braced && *(++ptr) != '}'))      if (c == 0 || (braced && *(++ptr) != '}'))
535        {        {
# Line 574  else Line 574  else
574        if (c < 0)        if (c < 0)
575          {          {
576          *errorcodeptr = ERR61;          *errorcodeptr = ERR61;
577          break;          break;
578          }          }
579        if (c < 10 || c <= bracount)        if (c < 10 || c <= bracount)
580          {          {
581          c = -(ESC_REF + c);          c = -(ESC_REF + c);
# Line 950  for (; *ptr != 0; ptr++) Line 950  for (; *ptr != 0; ptr++)
950      {      {
951      while (*(++ptr) != ']')      while (*(++ptr) != ']')
952        {        {
953        if (*ptr == 0) return -1;        if (*ptr == 0) return -1;
954        if (*ptr == '\\')        if (*ptr == '\\')
955          {          {
956          if (*(++ptr) == 0) return -1;          if (*(++ptr) == 0) return -1;
# Line 1194  for (;;) Line 1194  for (;;)
1194    
1195      case OP_TYPEEXACT:      case OP_TYPEEXACT:
1196      branchlength += GET2(cc,1);      branchlength += GET2(cc,1);
1197      if (cc[3] == OP_PROP || cc[3] == OP_NOTPROP) cc += 2;      if (cc[3] == OP_PROP || cc[3] == OP_NOTPROP) cc += 2;
1198      cc += 4;      cc += 4;
1199      break;      break;
1200    
# Line 1303  for (;;) Line 1303  for (;;)
1303      code += _pcre_OP_lengths[c];      code += _pcre_OP_lengths[c];
1304      }      }
1305    
1306    /* Otherwise, we can get the item's length from the table, except that for    /* Otherwise, we can get the item's length from the table, except that for
1307    repeated character types, we have to test for \p and \P, which have an extra    repeated character types, we have to test for \p and \P, which have an extra
1308    two bytes of parameters. */    two bytes of parameters. */
1309    
1310    else    else
# Line 1317  for (;;) Line 1317  for (;;)
1317        case OP_TYPEMINPLUS:        case OP_TYPEMINPLUS:
1318        case OP_TYPEQUERY:        case OP_TYPEQUERY:
1319        case OP_TYPEMINQUERY:        case OP_TYPEMINQUERY:
       case OP_TYPEUPTO:  
       case OP_TYPEMINUPTO:  
       case OP_TYPEEXACT:  
1320        case OP_TYPEPOSSTAR:        case OP_TYPEPOSSTAR:
1321        case OP_TYPEPOSPLUS:        case OP_TYPEPOSPLUS:
1322        case OP_TYPEPOSQUERY:        case OP_TYPEPOSQUERY:
       case OP_TYPEPOSUPTO:  
1323        if (code[1] == OP_PROP || code[1] == OP_NOTPROP) code += 2;        if (code[1] == OP_PROP || code[1] == OP_NOTPROP) code += 2;
1324        break;        break;
1325        }  
1326          case OP_TYPEUPTO:
1327          case OP_TYPEMINUPTO:
1328          case OP_TYPEEXACT:
1329          case OP_TYPEPOSUPTO:
1330          if (code[3] == OP_PROP || code[3] == OP_NOTPROP) code += 2;
1331          break;
1332          }
1333    
1334      /* Add in the fixed length from the table */      /* Add in the fixed length from the table */
1335    
1336      code += _pcre_OP_lengths[c];      code += _pcre_OP_lengths[c];
1337    
1338    /* In UTF-8 mode, opcodes that are followed by a character may be followed by    /* In UTF-8 mode, opcodes that are followed by a character may be followed by
1339    a multi-byte character. The length in the table is a minimum, so we have to    a multi-byte character. The length in the table is a minimum, so we have to
1340    arrange to skip the extra bytes. */    arrange to skip the extra bytes. */
1341    
1342  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
1343      if (utf8) switch(c)      if (utf8) switch(c)
1344        {        {
# Line 1386  for (;;) Line 1389  for (;;)
1389    register int c = *code;    register int c = *code;
1390    if (c == OP_END) return NULL;    if (c == OP_END) return NULL;
1391    if (c == OP_RECURSE) return code;    if (c == OP_RECURSE) return code;
1392    
1393    /* XCLASS is used for classes that cannot be represented just by a bit    /* XCLASS is used for classes that cannot be represented just by a bit
1394    map. This includes negated single high-valued characters. The length in    map. This includes negated single high-valued characters. The length in
1395    the table is zero; the actual length is stored in the compiled code. */    the table is zero; the actual length is stored in the compiled code. */
1396    
1397    if (c == OP_XCLASS) code += GET(code, 1);    if (c == OP_XCLASS) code += GET(code, 1);
1398    
1399    /* Otherwise, we can get the item's length from the table, except that for    /* Otherwise, we can get the item's length from the table, except that for
1400    repeated character types, we have to test for \p and \P, which have an extra    repeated character types, we have to test for \p and \P, which have an extra
1401    two bytes of parameters. */    two bytes of parameters. */
1402    
1403    else    else
# Line 1407  for (;;) Line 1410  for (;;)
1410        case OP_TYPEMINPLUS:        case OP_TYPEMINPLUS:
1411        case OP_TYPEQUERY:        case OP_TYPEQUERY:
1412        case OP_TYPEMINQUERY:        case OP_TYPEMINQUERY:
       case OP_TYPEUPTO:  
       case OP_TYPEMINUPTO:  
       case OP_TYPEEXACT:  
1413        case OP_TYPEPOSSTAR:        case OP_TYPEPOSSTAR:
1414        case OP_TYPEPOSPLUS:        case OP_TYPEPOSPLUS:
1415        case OP_TYPEPOSQUERY:        case OP_TYPEPOSQUERY:
       case OP_TYPEPOSUPTO:  
1416        if (code[1] == OP_PROP || code[1] == OP_NOTPROP) code += 2;        if (code[1] == OP_PROP || code[1] == OP_NOTPROP) code += 2;
1417        break;        break;
1418        }  
1419          case OP_TYPEPOSUPTO:
1420          case OP_TYPEUPTO:
1421          case OP_TYPEMINUPTO:
1422          case OP_TYPEEXACT:
1423          if (code[3] == OP_PROP || code[3] == OP_NOTPROP) code += 2;
1424          break;
1425          }
1426    
1427      /* Add in the fixed length from the table */      /* Add in the fixed length from the table */
1428    
1429      code += _pcre_OP_lengths[c];      code += _pcre_OP_lengths[c];
1430    
1431      /* In UTF-8 mode, opcodes that are followed by a character may be followed      /* In UTF-8 mode, opcodes that are followed by a character may be followed
1432      by a multi-byte character. The length in the table is a minimum, so we have      by a multi-byte character. The length in the table is a minimum, so we have
1433      to arrange to skip the extra bytes. */      to arrange to skip the extra bytes. */
1434    
1435  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
1436      if (utf8) switch(c)      if (utf8) switch(c)
1437        {        {
# Line 1524  for (code = first_significant_code(code Line 1530  for (code = first_significant_code(code
1530      /* Check for quantifiers after a class. XCLASS is used for classes that      /* Check for quantifiers after a class. XCLASS is used for classes that
1531      cannot be represented just by a bit map. This includes negated single      cannot be represented just by a bit map. This includes negated single
1532      high-valued characters. The length in _pcre_OP_lengths[] is zero; the      high-valued characters. The length in _pcre_OP_lengths[] is zero; the
1533      actual length is stored in the compiled code, so we must update "code"      actual length is stored in the compiled code, so we must update "code"
1534      here. */      here. */
1535    
1536  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
# Line 2722  for (;; ptr++) Line 2728  for (;; ptr++)
2728            else inescq = TRUE;            else inescq = TRUE;
2729            continue;            continue;
2730            }            }
2731          else if (-c == ESC_E) continue;  /* Ignore orphan \E */          else if (-c == ESC_E) continue;  /* Ignore orphan \E */
2732    
2733          if (c < 0)          if (c < 0)
2734            {            {
# Line 3170  for (;; ptr++) Line 3176  for (;; ptr++)
3176        }        }
3177    
3178      /* If class_charcount is 1, we saw precisely one character whose value is      /* If class_charcount is 1, we saw precisely one character whose value is
3179      less than 256. In non-UTF-8 mode we can always optimize. In UTF-8 mode, we      less than 256. As long as there were no characters >= 128 and there was no
3180      can optimize the negative case only if there were no characters >= 128      use of \p or \P, in other words, no use of any XCLASS features, we can
3181      because OP_NOT and the related opcodes like OP_NOTSTAR operate on      optimize.
3182      single-bytes only. This is an historical hangover. Maybe one day we can  
3183      tidy these opcodes to handle multi-byte characters.      In UTF-8 mode, we can optimize the negative case only if there were no
3184        characters >= 128 because OP_NOT and the related opcodes like OP_NOTSTAR
3185        operate on single-bytes only. This is an historical hangover. Maybe one day
3186        we can tidy these opcodes to handle multi-byte characters.
3187    
3188      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
3189      1-character OP_CHAR[NC] if it's positive, or OP_NOT if it's negative. Note      1-character OP_CHAR[NC] if it's positive, or OP_NOT if it's negative. Note
# Line 3184  for (;; ptr++) Line 3193  for (;; ptr++)
3193      reqbyte, save the previous value for reinstating. */      reqbyte, save the previous value for reinstating. */
3194    
3195  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
3196      if (class_charcount == 1 &&      if (class_charcount == 1 && !class_utf8 &&
3197            (!utf8 ||        (!utf8 || !negate_class || class_lastchar < 128))
           (!class_utf8 && (!negate_class || class_lastchar < 128))))  
   
3198  #else  #else
3199      if (class_charcount == 1)      if (class_charcount == 1)
3200  #endif  #endif
# Line 4798  for (;; ptr++) Line 4805  for (;; ptr++)
4805        }        }
4806    
4807      /* In the pre-compile phase, update the length by the length of the group,      /* In the pre-compile phase, update the length by the length of the group,
4808      less the brackets at either end. Then reduce the compiled code to just a      less the brackets at either end. Then reduce the compiled code to just a
4809      set of non-capturing brackets so that it doesn't use much memory if it is      set of non-capturing brackets so that it doesn't use much memory if it is
4810      duplicated by a quantifier.*/      duplicated by a quantifier.*/
4811    
# Line 4810  for (;; ptr++) Line 4817  for (;; ptr++)
4817          goto FAILED;          goto FAILED;
4818          }          }
4819        *lengthptr += length_prevgroup - 2 - 2*LINK_SIZE;        *lengthptr += length_prevgroup - 2 - 2*LINK_SIZE;
4820        *code++ = OP_BRA;        *code++ = OP_BRA;
4821        PUTINC(code, 0, 1 + LINK_SIZE);        PUTINC(code, 0, 1 + LINK_SIZE);
4822        *code++ = OP_KET;        *code++ = OP_KET;
4823        PUTINC(code, 0, 1 + LINK_SIZE);        PUTINC(code, 0, 1 + LINK_SIZE);

Legend:
Removed from v.218  
changed lines
  Added in v.223

  ViewVC Help
Powered by ViewVC 1.1.5