Commit 7f984871 authored by darin@apple.com's avatar darin@apple.com

Reviewed by Geoff.

        - fix use of prefix and config.h, got rid of a few unneeded things in
          the PCRE code; no behavior changes

        * API/JSBase.cpp: Added include of config.h.
        * API/JSCallbackConstructor.cpp: Ditto.
        * API/JSCallbackFunction.cpp: Ditto.
        * API/JSCallbackObject.cpp: Ditto.
        * API/JSClassRef.cpp: Ditto.
        * API/JSContextRef.cpp: Ditto.
        * API/JSObjectRef.cpp: Ditto.
        * API/JSStringRef.cpp: Ditto.
        * API/JSValueRef.cpp: Ditto.

        * JavaScriptCorePrefix.h: Removed obsolete <ctype.h> workaround.
        Moved new/delete macros after includes, as they are in WebCore's prefix.
        Removed "config.h".

        * pcre/dftables.cpp: (main): Changed back to not use a separate maketables
        function. This is needed for PCRE, but not helpful for our use. Also changed
        the tables to all be 128 entries long instead of 256, since only the first
        128 are ever used.

        * pcre/pcre_compile.cpp: Added include of config.h. Eliminated digitab,
        which was only being used to check hex digits. Changed all uses of TRUE and
        FALSE to use the C++ true and false instead.
        (check_escape): Just the TRUE/FALSE thing.
        (is_counted_repeat): Ditto.
        (could_be_empty_branch): Ditto.
        (get_othercase_range): Ditto.
        (compile_branch): Ditto.
        (compile_regex): Ditto.
        (is_anchored): Ditto.
        (is_startline): Ditto.
        (find_firstassertedchar): Ditto.
        (jsRegExpCompile): Ditto.

        * pcre/pcre_exec.cpp: Added include of config.h. Changed all uses of TRUE and
        FALSE to use the C++ true and false instead.
        (match_ref): Just the TRUE/FALSE thing.
        (match): Ditto. Removed some unneeded braces.
        (jsRegExpExecute): Just the TRUE/FALSE thing.

        * pcre/pcre_internal.h: Moved the constants needed by dftables.cpp to the top
        of the file instead of the bottom, so they can be used. Also changed the table
        sizes to 128 instead of 256. Removed macro definitions of FALSE and TRUE.
        Set array sizes for all the const arrays. Changed _pcre_utf8_table1_size to
        be a macro instead of a extern int.

        * pcre/pcre_maketables.cpp: Removed. It's all in dftables.cpp now.

        * pcre/pcre_tables.cpp: Made table sizes explicit.

        * pcre/pcre_xclass.cpp: Just the TRUE/FALSE thing.



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@27730 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 34fea3a8
......@@ -24,6 +24,8 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "config.h"
#include <wtf/Platform.h>
#include "JSBase.h"
......
......@@ -24,6 +24,8 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "config.h"
#include <wtf/Platform.h>
#include "JSCallbackConstructor.h"
......
......@@ -24,6 +24,7 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "config.h"
#include <wtf/Platform.h>
#include "JSCallbackFunction.h"
......
......@@ -25,6 +25,7 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "config.h"
#include <wtf/Platform.h>
#include "JSCallbackObject.h"
......
......@@ -24,6 +24,7 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "config.h"
#include <wtf/Platform.h>
#include "APICast.h"
#include "JSCallbackObject.h"
......
// -*- mode: c++; c-basic-offset: 4 -*-
/*
* Copyright (C) 2006 Apple Computer, Inc. All rights reserved.
* Copyright (C) 2006, 2007 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
......@@ -24,9 +24,11 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "config.h"
#include "JSContextRef.h"
#include <wtf/Platform.h>
#include "APICast.h"
#include "JSContextRef.h"
#include "JSCallbackObject.h"
#include "JSGlobalObject.h"
......
// -*- mode: c++; c-basic-offset: 4 -*-
/*
* Copyright (C) 2006 Apple Computer, Inc. All rights reserved.
* Copyright (C) 2006, 2007 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
......@@ -24,10 +24,12 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "config.h"
#include "JSObjectRef.h"
#include <wtf/Platform.h>
#include "APICast.h"
#include "JSValueRef.h"
#include "JSObjectRef.h"
#include "JSCallbackConstructor.h"
#include "JSCallbackFunction.h"
#include "JSCallbackObject.h"
......
// -*- mode: c++; c-basic-offset: 4 -*-
/*
* Copyright (C) 2006 Apple Computer, Inc. All rights reserved.
* Copyright (C) 2006, 2007 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
......@@ -24,9 +24,11 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <wtf/Platform.h>
#include "config.h"
#include "JSStringRef.h"
#include <wtf/Platform.h>
#include "APICast.h"
#include <kjs/JSLock.h>
#include <kjs/JSType.h>
......
// -*- mode: c++; c-basic-offset: 4 -*-
/*
* Copyright (C) 2006 Apple Computer, Inc. All rights reserved.
* Copyright (C) 2006, 2007 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
......@@ -24,10 +24,12 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "config.h"
#include "JSValueRef.h"
#include <wtf/Platform.h>
#include "APICast.h"
#include "JSCallbackObject.h"
#include "JSValueRef.h"
#include <kjs/JSType.h>
#include <kjs/JSGlobalObject.h>
......
2007-11-12 Darin Adler <darin@apple.com>
Reviewed by Geoff.
- fix use of prefix and config.h, got rid of a few unneeded things in
the PCRE code; no behavior changes
* API/JSBase.cpp: Added include of config.h.
* API/JSCallbackConstructor.cpp: Ditto.
* API/JSCallbackFunction.cpp: Ditto.
* API/JSCallbackObject.cpp: Ditto.
* API/JSClassRef.cpp: Ditto.
* API/JSContextRef.cpp: Ditto.
* API/JSObjectRef.cpp: Ditto.
* API/JSStringRef.cpp: Ditto.
* API/JSValueRef.cpp: Ditto.
* JavaScriptCorePrefix.h: Removed obsolete <ctype.h> workaround.
Moved new/delete macros after includes, as they are in WebCore's prefix.
Removed "config.h".
* pcre/dftables.cpp: (main): Changed back to not use a separate maketables
function. This is needed for PCRE, but not helpful for our use. Also changed
the tables to all be 128 entries long instead of 256, since only the first
128 are ever used.
* pcre/pcre_compile.cpp: Added include of config.h. Eliminated digitab,
which was only being used to check hex digits. Changed all uses of TRUE and
FALSE to use the C++ true and false instead.
(check_escape): Just the TRUE/FALSE thing.
(is_counted_repeat): Ditto.
(could_be_empty_branch): Ditto.
(get_othercase_range): Ditto.
(compile_branch): Ditto.
(compile_regex): Ditto.
(is_anchored): Ditto.
(is_startline): Ditto.
(find_firstassertedchar): Ditto.
(jsRegExpCompile): Ditto.
* pcre/pcre_exec.cpp: Added include of config.h. Changed all uses of TRUE and
FALSE to use the C++ true and false instead.
(match_ref): Just the TRUE/FALSE thing.
(match): Ditto. Removed some unneeded braces.
(jsRegExpExecute): Just the TRUE/FALSE thing.
* pcre/pcre_internal.h: Moved the constants needed by dftables.cpp to the top
of the file instead of the bottom, so they can be used. Also changed the table
sizes to 128 instead of 256. Removed macro definitions of FALSE and TRUE.
Set array sizes for all the const arrays. Changed _pcre_utf8_table1_size to
be a macro instead of a extern int.
* pcre/pcre_maketables.cpp: Removed. It's all in dftables.cpp now.
* pcre/pcre_tables.cpp: Made table sizes explicit.
* pcre/pcre_xclass.cpp: Just the TRUE/FALSE thing.
2007-11-12 Adam Roben <aroben@apple.com>
Build fix
......
#ifdef __cplusplus
#define new ("if you use new/delete make sure to include config.h at the top of the file"())
#define delete ("if you use new/delete make sure to include config.h at the top of the file"())
#endif
#ifdef __cplusplus
#define NULL __null
#else
#define NULL ((void *)0)
#endif
#include "config.h"
#include <ctype.h>
#include <float.h>
#include <locale.h>
......@@ -27,27 +20,16 @@
#ifdef __cplusplus
/* Work around bug 3553309 by re-including <ctype.h>. */
#include <cctype>
#define isalnum(c) __istype((c), (_CTYPE_A|_CTYPE_D))
#define isalpha(c) __istype((c), _CTYPE_A)
#define iscntrl(c) __istype((c), _CTYPE_C)
#define isdigit(c) __isctype((c), _CTYPE_D) /* ANSI -- locale independent */
#define isgraph(c) __istype((c), _CTYPE_G)
#define islower(c) __istype((c), _CTYPE_L)
#define isprint(c) __istype((c), _CTYPE_R)
#define ispunct(c) __istype((c), _CTYPE_P)
#define isspace(c) __istype((c), _CTYPE_S)
#define isupper(c) __istype((c), _CTYPE_U)
#define isxdigit(c) __isctype((c), _CTYPE_X) /* ANSI -- locale independent */
#define tolower(c) __tolower(c)
#define toupper(c) __toupper(c)
#include <list>
#include <typeinfo>
#endif
#ifdef __cplusplus
#define new ("if you use new/delete make sure to include config.h at the top of the file"())
#define delete ("if you use new/delete make sure to include config.h at the top of the file"())
#endif
/* Work around bug with C++ library that screws up Objective-C++ when exception support is disabled. */
#undef try
#undef catch
......@@ -37,8 +37,7 @@ POSSIBILITY OF SUCH DAMAGE.
-----------------------------------------------------------------------------
*/
/* This is a freestanding support program to generate a file containing default
/* This is a freestanding support program to generate a file containing
character tables. The tables are built according to the default C
locale. */
......@@ -46,34 +45,27 @@ locale. */
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "pcre_internal.h"
#include "pcre_maketables.cpp"
int main(int argc, char **argv)
{
int i;
FILE *f;
const unsigned char *tables = pcre_maketables();
const unsigned char *base_of_tables = tables;
if (argc != 2)
{
fprintf(stderr, "dftables: one filename argument is required\n");
return 1;
}
f = fopen(argv[1], "wb");
FILE* f = fopen(argv[1], "wb");
if (f == NULL)
{
fprintf(stderr, "dftables: failed to open %s for writing\n", argv[1]);
return 1;
}
/* There are two fprintf() calls here, because gcc in pedantic mode complains
about the very long string otherwise. */
int i;
fprintf(f,
"/*************************************************\n"
......@@ -86,35 +78,53 @@ fprintf(f,
"This file contains the default tables for characters with codes less than\n"
"128 (ASCII characters). These tables are used when no external tables are\n"
"passed to PCRE. */\n\n"
"const unsigned char _pcre_default_tables[] = {\n\n"
"/* This table is a lower casing table. */\n\n");
"const unsigned char _pcre_default_tables[%d] = {\n\n"
"/* This table is a lower casing table. */\n\n", tables_length);
if (lcc_offset != 0)
abort();
fprintf(f, " ");
for (i = 0; i < 256; i++)
for (i = 0; i < 128; i++)
{
if ((i & 7) == 0 && i != 0) fprintf(f, "\n ");
fprintf(f, "%3d", *tables++);
if (i != 255) fprintf(f, ",");
fprintf(f, "0x%02X", tolower(i));
if (i != 127) fprintf(f, ", ");
}
fprintf(f, ",\n\n");
fprintf(f, "/* This table is a case flipping table. */\n\n");
if (fcc_offset != 128)
abort();
fprintf(f, " ");
for (i = 0; i < 256; i++)
for (i = 0; i < 128; i++)
{
if ((i & 7) == 0 && i != 0) fprintf(f, "\n ");
fprintf(f, "%3d", *tables++);
if (i != 255) fprintf(f, ",");
fprintf(f, "0x%02X", islower(i) ? toupper(i) : tolower(i));
if (i != 127) fprintf(f, ", ");
}
fprintf(f, ",\n\n");
fprintf(f,
"/* This table contains bit maps for various character classes.\n"
"Each map is 32 bytes long and the bits run from the least\n"
"significant end of each byte. The classes that have their own\n"
"maps are: space, xdigit, digit, upper, lower, word, graph\n"
"print, punct, and cntrl. Other classes are built from combinations. */\n\n");
"significant end of each byte. The classes are: space, digit, word. */\n\n");
if (cbits_offset != fcc_offset + 128)
abort();
unsigned char cbit_table[cbit_length];
memset(cbit_table, 0, cbit_length);
for (i = '0'; i <= '9'; i++)
cbit_table[cbit_digit + i / 8] |= 1 << (i & 7);
cbit_table[cbit_word + '_' / 8] |= 1 << ('_' & 7);
for (i = 0; i < 128; i++)
{
if (isalnum(i)) cbit_table[cbit_word + i/8] |= 1 << (i & 7);
if (isspace(i)) cbit_table[cbit_space + i/8] |= 1 << (i & 7);
}
fprintf(f, " ");
for (i = 0; i < cbit_length; i++)
......@@ -124,8 +134,8 @@ for (i = 0; i < cbit_length; i++)
if ((i & 31) == 0) fprintf(f, "\n");
fprintf(f, "\n ");
}
fprintf(f, "0x%02x", *tables++);
if (i != cbit_length - 1) fprintf(f, ",");
fprintf(f, "0x%02X", cbit_table[i]);
if (i != cbit_length - 1) fprintf(f, ", ");
}
fprintf(f, ",\n\n");
......@@ -136,30 +146,39 @@ fprintf(f,
" 0x%02x alphanumeric or '_'\n*/\n\n",
ctype_space, ctype_xdigit, ctype_word);
if (ctypes_offset != cbits_offset + cbit_length)
abort();
fprintf(f, " ");
for (i = 0; i < 256; i++)
for (i = 0; i < 128; i++)
{
if ((i & 7) == 0 && i != 0)
int x = 0;
if (isspace(i)) x += ctype_space;
if (isxdigit(i)) x += ctype_xdigit;
if (isalnum(i) || i == '_') x += ctype_word;
fprintf(f, "0x%02X", x);
if (i != 127)
fprintf(f, ", ");
else
fprintf(f, "};");
if ((i & 7) == 7)
{
fprintf(f, " /* ");
if (isprint(i-8)) fprintf(f, " %c -", i-8);
else fprintf(f, "%3d-", i-8);
if (isprint(i-1)) fprintf(f, " %c ", i-1);
else fprintf(f, "%3d", i-1);
fprintf(f, " */\n ");
if (isprint(i - 7)) fprintf(f, " %c -", i - 7);
else fprintf(f, "%3d-", i - 7);
if (isprint(i)) fprintf(f, " %c ", i);
else fprintf(f, "%3d", i);
fprintf(f, " */\n");
if (i != 127)
fprintf(f, " ");
}
fprintf(f, "0x%02x", *tables++);
if (i != 255) fprintf(f, ",");
}
fprintf(f, "};/* ");
if (isprint(i-8)) fprintf(f, " %c -", i-8);
else fprintf(f, "%3d-", i-8);
if (isprint(i-1)) fprintf(f, " %c ", i-1);
else fprintf(f, "%3d", i-1);
fprintf(f, " */\n\n/* End of chartables.c */\n");
if (tables_length != ctypes_offset + 128)
abort();
fprintf(f, "\n\n/* End of chartables.c */\n");
fclose(f);
delete []base_of_tables;
return 0;
}
This diff is collapsed.
......@@ -41,6 +41,8 @@ POSSIBILITY OF SUCH DAMAGE.
that does pattern matching using an NFA algorithm, following the rules from
the JavaScript specification. There are also some supporting functions. */
#include "config.h"
#include "pcre_internal.h"
#include <wtf/ASCIICType.h>
......@@ -128,7 +130,7 @@ typedef struct match_data {
BOOL caseless;
} match_data;
#define match_isgroup TRUE /* Set if start of bracketed group */
#define match_isgroup true /* Set if start of bracketed group */
/* Non-error returns from the match() function. Error returns are externally
defined PCRE_ERROR_xxx codes, which are all negative. */
......@@ -154,8 +156,8 @@ subject if the requested.
Arguments:
p points to characters
length number to print
is_subject TRUE if printing from within md->start_subject
md pointer to matching data block, if is_subject is TRUE
is_subject true if printing from within md->start_subject
md pointer to matching data block, if is_subject is true
Returns: nothing
*/
......@@ -187,7 +189,7 @@ Arguments:
length length to be matched
md points to match data block
Returns: TRUE if matched
Returns: true if matched
*/
static BOOL
......@@ -201,16 +203,16 @@ if (eptr >= md->end_subject)
else
{
printf("matching subject ");
pchars(eptr, length, TRUE, md);
pchars(eptr, length, true, md);
}
printf(" against backref ");
pchars(p, length, FALSE, md);
pchars(p, length, false, md);
printf("\n");
#endif
/* Always fail if not enough characters left */
if (length > md->end_subject - eptr) return FALSE;
if (length > md->end_subject - eptr) return false;
/* Separate the caselesss case for speed */
......@@ -221,13 +223,13 @@ if (md->caseless)
pcre_uchar c = *p++;
int othercase = _pcre_ucp_othercase(c);
pcre_uchar d = *eptr++;
if (c != d && othercase != d) return FALSE;
if (c != d && othercase != d) return false;
}
}
else
{ while (length-- > 0) if (*p++ != *eptr++) return FALSE; }
{ while (length-- > 0) if (*p++ != *eptr++) return false; }
return TRUE;
return true;
}
......@@ -297,7 +299,7 @@ RRETURN_##num:\
#define RRETURN_NO_MATCH \
{\
is_match = FALSE;\
is_match = false;\
RRETURN;\
}
......@@ -332,7 +334,7 @@ Returns: MATCH_MATCH if matched ) these values are >= 0
static int match(USPTR eptr, const uschar *ecode, int offset_top, match_data *md)
{
register int is_match = FALSE;
register int is_match = false;
register int i;
register int c;
......@@ -340,9 +342,9 @@ unsigned rdepth = 0;
BOOL cur_is_word;
BOOL prev_is_word;
BOOL is_group_start = TRUE;
BOOL is_group_start = true;
int min;
BOOL minimize = FALSE; /* Initialization not really needed, but some compilers think so. */
BOOL minimize = false; /* Initialization not really needed, but some compilers think so. */
/* The value 16 here is large enough that most regular expressions don't require
any calls to pcre_stack_malloc, yet the amount of stack used for the array is
......@@ -449,7 +451,7 @@ for (;;)
BEGIN_OPCODE(END):
md->end_match_ptr = frame->eptr; /* Record where we ended */
md->end_offset_top = frame->offset_top; /* and how many extracts were taken */
is_match = TRUE;
is_match = true;
RRETURN;
/* Assertion brackets. Check the alternative branches in turn - the
......@@ -498,7 +500,6 @@ for (;;)
the end of a normal bracket, leaving the subject pointer. */
BEGIN_OPCODE(ONCE):
{
frame->prev = frame->ecode;
frame->saved_eptr = frame->eptr;
......@@ -553,7 +554,6 @@ for (;;)
RMATCH(13, frame->ecode + 1+LINK_SIZE, frame->eptrb, 0);
if (is_match) RRETURN;
}
}
RRETURN;
/* An alternation is the end of a branch; scan along to find the end of the
......@@ -609,7 +609,7 @@ for (;;)
{
md->end_match_ptr = frame->eptr; /* For ONCE */
md->end_offset_top = frame->offset_top;
is_match = TRUE;
is_match = true;
RRETURN;
}
......@@ -617,7 +617,6 @@ for (;;)
group number back at the start and if necessary complete handling an
extraction by setting the offsets and bumping the high water mark. */
{
frame->number = *frame->prev - OP_BRA;
/* For extended extraction brackets (large number), we have to fish out
......@@ -638,7 +637,7 @@ for (;;)
if (frame->number > 0)
{
if (frame->offset >= md->offset_max) md->offset_overflow = TRUE; else
if (frame->offset >= md->offset_max) md->offset_overflow = true; else
{
md->offset_vector[frame->offset] =
md->offset_vector[md->offset_end - frame->number];
......@@ -646,7 +645,6 @@ for (;;)
if (frame->offset_top <= frame->offset) frame->offset_top = frame->offset + 2;
}
}
}
/* For a non-repeating ket, just continue at this level. This also
happens for a repeating ket if no characters were matched in the group.
......@@ -723,14 +721,14 @@ for (;;)
be "non-word" characters. */
{
if (frame->eptr == md->start_subject) prev_is_word = FALSE; else
if (frame->eptr == md->start_subject) prev_is_word = false; else
{
const pcre_uchar *lastptr = frame->eptr - 1;
while(ISMIDCHAR(*lastptr)) lastptr--;
GETCHAR(c, lastptr);
prev_is_word = c < 128 && (md->ctypes[c] & ctype_word) != 0;
}
if (frame->eptr >= md->end_subject) cur_is_word = FALSE; else
if (frame->eptr >= md->end_subject) cur_is_word = false; else
{
GETCHAR(c, frame->eptr);
cur_is_word = c < 128 && (md->ctypes[c] & ctype_word) != 0;
......@@ -812,7 +810,6 @@ for (;;)
loops). */
BEGIN_OPCODE(REF):
{
frame->offset = GET2(frame->ecode, 1) << 1; /* Doubled ref number */
frame->ecode += 3; /* Advance past item */
......@@ -910,7 +907,6 @@ for (;;)
}
RRETURN_NO_MATCH;
}
}
/* Control never gets here */
/* Match a bit-mapped character class, possibly repeatedly. This op code is
......@@ -926,7 +922,6 @@ for (;;)
BEGIN_OPCODE(NCLASS):
BEGIN_OPCODE(CLASS):
{
frame->data = frame->ecode + 1; /* Save for matching */
frame->ecode += 33; /* Advance past the item */
......@@ -1036,14 +1031,12 @@ for (;;)
RRETURN;
}
}
/* Control never gets here */
/* Match an extended character class. This opcode is encountered only
in UTF-8 mode, because that's the only time it is compiled. */
BEGIN_OPCODE(XCLASS):
{
frame->data = frame->ecode + 1 + LINK_SIZE; /* Save for matching */
frame->ecode += GET(frame->ecode, 1); /* Advance past the item */
......@@ -1129,13 +1122,11 @@ for (;;)
RRETURN;
}
/* Control never gets here */
}
/* Control never gets here */
/* Match a single character, casefully */
BEGIN_OPCODE(CHAR):
{
frame->length = 1;
frame->ecode++;
GETUTF8CHARLEN(frame->