2011-01-12 Peter Varga <pvarga@webkit.org>
authorpvarga@webkit.org <pvarga@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 12 Jan 2011 10:32:29 +0000 (10:32 +0000)
committerpvarga@webkit.org <pvarga@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 12 Jan 2011 10:32:29 +0000 (10:32 +0000)
        Reviewed by Gavin Barraclough.

        Add Yarr.h to YARR
        https://bugs.webkit.org/show_bug.cgi?id=51021

        Move other common constants and functions from YARR's different files
        to Yarr.h.
        Use Yarr.h header instead of including other YARR headers where it
        is possible.

        * JavaScriptCore.gypi:
        * JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.vcproj:
        * JavaScriptCore.xcodeproj/project.pbxproj:
        * runtime/RegExp.cpp:
        * yarr/Yarr.h: Added.
        * yarr/YarrInterpreter.cpp:
        * yarr/YarrInterpreter.h:
        * yarr/YarrJIT.cpp:
        (JSC::Yarr::jitCompile):
        (JSC::Yarr::execute):
        * yarr/YarrJIT.h:
        * yarr/YarrParser.h:
        * yarr/YarrPattern.cpp:
        (JSC::Yarr::YarrPattern::compile):
        (JSC::Yarr::YarrPattern::YarrPattern):
        * yarr/YarrPattern.h:

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@75595 268f45cc-cd09-0410-ab3c-d52691b4dbfc

13 files changed:
Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/JavaScriptCore.gypi
Source/JavaScriptCore/JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.vcproj
Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj
Source/JavaScriptCore/runtime/RegExp.cpp
Source/JavaScriptCore/yarr/Yarr.h [new file with mode: 0644]
Source/JavaScriptCore/yarr/YarrInterpreter.cpp
Source/JavaScriptCore/yarr/YarrInterpreter.h
Source/JavaScriptCore/yarr/YarrJIT.cpp
Source/JavaScriptCore/yarr/YarrJIT.h
Source/JavaScriptCore/yarr/YarrParser.h
Source/JavaScriptCore/yarr/YarrPattern.cpp
Source/JavaScriptCore/yarr/YarrPattern.h

index 3e8da62cb9bddfd85aef2cbac3dc14c65c074da0..ea799099e77b94cfe2d61e76a92170fc2a13d47b 100644 (file)
@@ -1,3 +1,32 @@
+2011-01-12  Peter Varga  <pvarga@webkit.org>
+
+        Reviewed by Gavin Barraclough.
+
+        Add Yarr.h to YARR
+        https://bugs.webkit.org/show_bug.cgi?id=51021
+
+        Move other common constants and functions from YARR's different files
+        to Yarr.h.
+        Use Yarr.h header instead of including other YARR headers where it
+        is possible.
+
+        * JavaScriptCore.gypi:
+        * JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.vcproj:
+        * JavaScriptCore.xcodeproj/project.pbxproj:
+        * runtime/RegExp.cpp:
+        * yarr/Yarr.h: Added.
+        * yarr/YarrInterpreter.cpp:
+        * yarr/YarrInterpreter.h:
+        * yarr/YarrJIT.cpp:
+        (JSC::Yarr::jitCompile):
+        (JSC::Yarr::execute):
+        * yarr/YarrJIT.h:
+        * yarr/YarrParser.h:
+        * yarr/YarrPattern.cpp:
+        (JSC::Yarr::YarrPattern::compile):
+        (JSC::Yarr::YarrPattern::YarrPattern):
+        * yarr/YarrPattern.h:
+
 2011-01-11  Michael Saboff  <msaboff@apple.com>
 
         Reviewed by Geoffrey Garen.
index a6c1db4edb9e5db47434cb09767af05d137e4dc7..fa30116e7b12b8e553da32a5ffee077c003f34cc 100644 (file)
             'wtf/win/MainThreadWin.cpp',
             'wtf/win/OwnPtrWin.cpp',
             'wtf/wx/MainThreadWx.cpp',
+            'yarr/Yarr.h'
             'yarr/YarrInterpreter.cpp',
             'yarr/YarrInterpreter.h',
             'yarr/YarrJIT.cpp',
index f00c18dfedf3303a7e097955be98f21e0ff9a6b4..c75e85aad00ad774963610483feab9f47602ba4c 100644 (file)
                <Filter
                        Name="yarr"
                        >
+                       <File
+                               RelativePath="..\..\yarr\Yarr.h"
+                               >
+                       </File>
                        <File
                                RelativePath="..\..\yarr\YarrInterpreter.cpp"
                                >
index a778036b87c2ecc8a1bebe77226ce1d8e33c6f37..c867ffae018e3c2e9af4313f1141b8fe918f6742 100644 (file)
                41359CF70FDD89CB00206180 /* DateMath.h in Headers */ = {isa = PBXBuildFile; fileRef = 41359CF50FDD89CB00206180 /* DateMath.h */; settings = {ATTRIBUTES = (Private, ); }; };
                4409D8470FAF80A200523B87 /* OwnPtrCommon.h in Headers */ = {isa = PBXBuildFile; fileRef = 440B7AED0FAF7FCB0073323E /* OwnPtrCommon.h */; settings = {ATTRIBUTES = (Private, ); }; };
                44DD48530FAEA85000D6B4EB /* PassOwnPtr.h in Headers */ = {isa = PBXBuildFile; fileRef = 44DD48520FAEA85000D6B4EB /* PassOwnPtr.h */; settings = {ATTRIBUTES = (Private, ); }; };
+               451539B912DC994500EF7AC4 /* Yarr.h in Headers */ = {isa = PBXBuildFile; fileRef = 451539B812DC994500EF7AC4 /* Yarr.h */; };
                511FC4C9117EE28700425272 /* MD5.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 511FC4C7117EE23D00425272 /* MD5.cpp */; };
                511FC4CB117EE2A800425272 /* MD5.h in Headers */ = {isa = PBXBuildFile; fileRef = 511FC4CA117EE2A800425272 /* MD5.h */; settings = {ATTRIBUTES = (Private, ); }; };
                5135FAF212D26ACE003C083B /* Decoder.h in Headers */ = {isa = PBXBuildFile; fileRef = 5135FAD512D26856003C083B /* Decoder.h */; settings = {ATTRIBUTES = (Private, ); }; };
                440B7AED0FAF7FCB0073323E /* OwnPtrCommon.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OwnPtrCommon.h; sourceTree = "<group>"; };
                449097EE0F8F81B50076A327 /* FeatureDefines.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = FeatureDefines.xcconfig; sourceTree = "<group>"; };
                44DD48520FAEA85000D6B4EB /* PassOwnPtr.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PassOwnPtr.h; sourceTree = "<group>"; };
+               451539B812DC994500EF7AC4 /* Yarr.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Yarr.h; path = yarr/Yarr.h; sourceTree = "<group>"; };
                45E12D8806A49B0F00E9DF84 /* jsc.cpp */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.cpp.cpp; path = jsc.cpp; sourceTree = "<group>"; tabWidth = 4; };
                511FC4C7117EE23D00425272 /* MD5.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MD5.cpp; sourceTree = "<group>"; };
                511FC4CA117EE2A800425272 /* MD5.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MD5.h; sourceTree = "<group>"; };
                86EAC48C0F93E8B9008EC948 /* yarr */ = {
                        isa = PBXGroup;
                        children = (
+                               451539B812DC994500EF7AC4 /* Yarr.h */,
                                86704B7D12DBA33700A9FE7B /* YarrInterpreter.cpp */,
                                86704B7E12DBA33700A9FE7B /* YarrInterpreter.h */,
                                86704B7F12DBA33700A9FE7B /* YarrJIT.cpp */,
                                86704B8712DBA33700A9FE7B /* YarrJIT.h in Headers */,
                                86704B8812DBA33700A9FE7B /* YarrParser.h in Headers */,
                                86704B8A12DBA33700A9FE7B /* YarrPattern.h in Headers */,
+                               451539B912DC994500EF7AC4 /* Yarr.h in Headers */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
index 4ab59bda05fa9c0550f34b73a487c25bc89b35e8..31a1abeb9df2247ea6d2699159b4c3e76ffb5731 100644 (file)
 #include "RegExp.h"
 
 #include "Lexer.h"
-#include "yarr/YarrInterpreter.h"
-#include "yarr/YarrJIT.h"
-#include "yarr/YarrPattern.h"
+#include "yarr/Yarr.h"
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <wtf/Assertions.h>
 #include <wtf/OwnArrayPtr.h>
 
-
 namespace JSC {
 
 struct RegExpRepresentation {
diff --git a/Source/JavaScriptCore/yarr/Yarr.h b/Source/JavaScriptCore/yarr/Yarr.h
new file mode 100644 (file)
index 0000000..57176bc
--- /dev/null
@@ -0,0 +1,72 @@
+/*
+ * Copyright (C) 2009 Apple Inc. All rights reserved.
+ * Copyright (C) 2010 Peter Varga (pvarga@inf.u-szeged.hu), University of Szeged
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY UNIVERSITY OF SZEGED ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL UNIVERSITY OF SZEGED OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef Yarr_h
+#define Yarr_h
+
+#include "YarrInterpreter.h"
+#include "YarrJIT.h"
+#include "YarrPattern.h"
+
+namespace JSC { namespace Yarr {
+
+#define YarrStackSpaceForBackTrackInfoPatternCharacter 1 // Only for !fixed quantifiers.
+#define YarrStackSpaceForBackTrackInfoCharacterClass 1 // Only for !fixed quantifiers.
+#define YarrStackSpaceForBackTrackInfoBackReference 2
+#define YarrStackSpaceForBackTrackInfoAlternative 1 // One per alternative.
+#define YarrStackSpaceForBackTrackInfoParentheticalAssertion 1
+#define YarrStackSpaceForBackTrackInfoParenthesesOnce 1 // Only for !fixed quantifiers.
+#define YarrStackSpaceForBackTrackInfoParenthesesTerminal 1
+#define YarrStackSpaceForBackTrackInfoParentheses 2
+
+static const unsigned quantifyInfinite = UINT_MAX;
+
+// The below limit restricts the number of "recursive" match calls in order to
+// avoid spending exponential time on complex regular expressions.
+static const unsigned matchLimit = 1000000;
+
+enum JSRegExpResult {
+    JSRegExpMatch = 1,
+    JSRegExpNoMatch = 0,
+    JSRegExpErrorNoMatch = -1,
+    JSRegExpErrorHitLimit = -2,
+    JSRegExpErrorNoMemory = -3,
+    JSRegExpErrorInternal = -4
+};
+
+PassOwnPtr<BytecodePattern> byteCompile(YarrPattern&, BumpPointerAllocator*);
+int interpret(BytecodePattern*, const UChar* input, unsigned start, unsigned length, int* output);
+
+#if ENABLE(YARR_JIT)
+void jitCompile(YarrPattern&, JSGlobalData*, YarrCodeBlock& jitObject);
+int execute(YarrCodeBlock& jitObject, const UChar* input, unsigned start, unsigned length, int* output);
+#endif
+
+} } // namespace JSC::Yarr
+
+#endif // Yarr_h
+
index a4ae88f0b8b6a31dfe55c873dc8d783ac31411a2..d2dbf237c51f45b506ed1a3e9f15ea0628f1129b 100644 (file)
@@ -27,7 +27,7 @@
 #include "config.h"
 #include "YarrInterpreter.h"
 
-#include "YarrPattern.h"
+#include "Yarr.h"
 #include <wtf/BumpPointerAllocator.h>
 
 #ifndef NDEBUG
@@ -1878,7 +1878,6 @@ int interpret(BytecodePattern* bytecode, const UChar* input, unsigned start, uns
     return Interpreter(bytecode, output, input, start, length).interpret();
 }
 
-
 COMPILE_ASSERT(sizeof(Interpreter::BackTrackInfoPatternCharacter) == (YarrStackSpaceForBackTrackInfoPatternCharacter * sizeof(uintptr_t)), CheckYarrStackSpaceForBackTrackInfoPatternCharacter);
 COMPILE_ASSERT(sizeof(Interpreter::BackTrackInfoCharacterClass) == (YarrStackSpaceForBackTrackInfoCharacterClass * sizeof(uintptr_t)), CheckYarrStackSpaceForBackTrackInfoCharacterClass);
 COMPILE_ASSERT(sizeof(Interpreter::BackTrackInfoBackReference) == (YarrStackSpaceForBackTrackInfoBackReference * sizeof(uintptr_t)), CheckYarrStackSpaceForBackTrackInfoBackReference);
index 6ffe9b72aace3b627b65c1682877592552ca739d..be703a9c888e56f7f90832470d1959dfe0e04d96 100644 (file)
@@ -26,7 +26,6 @@
 #ifndef YarrInterpreter_h
 #define YarrInterpreter_h
 
-#include "YarrParser.h"
 #include "YarrPattern.h"
 #include <wtf/PassOwnPtr.h>
 #include <wtf/unicode/Unicode.h>
@@ -38,21 +37,6 @@ using WTF::BumpPointerAllocator;
 
 namespace JSC { namespace Yarr {
 
-// TODO move the matchLimit constant and the JSRegExpResult enum to the JSRegExp.h when pcre is removed.
-
-// The below limit restricts the number of "recursive" match calls in order to
-// avoid spending exponential time on complex regular expressions.
-static const unsigned matchLimit = 1000000;
-
-enum JSRegExpResult {
-    JSRegExpMatch = 1,
-    JSRegExpNoMatch = 0,
-    JSRegExpErrorNoMatch = -1,
-    JSRegExpErrorHitLimit = -2,
-    JSRegExpErrorNoMemory = -3,
-    JSRegExpErrorInternal = -4
-};
-
 class ByteDisjunction;
 
 struct ByteTerm {
@@ -373,9 +357,6 @@ private:
     Vector<CharacterClass*> m_userCharacterClasses;
 };
 
-PassOwnPtr<BytecodePattern> byteCompile(YarrPattern&, BumpPointerAllocator*);
-int interpret(BytecodePattern*, const UChar* input, unsigned start, unsigned length, int* output);
-
 } } // namespace JSC::Yarr
 
 #endif // YarrInterpreter_h
index 545fcf5fd90b07e15f1c36a0f13dea2cc73c77fd..ae3cdf2ecd15cb7151ecc3cc036922086e2eea89 100644 (file)
@@ -30,7 +30,7 @@
 #include "JSGlobalData.h"
 #include "LinkBuffer.h"
 #include "MacroAssembler.h"
-#include "YarrParser.h"
+#include "Yarr.h"
 
 #if ENABLE(YARR_JIT)
 
@@ -2203,10 +2203,13 @@ private:
 
 void jitCompile(YarrPattern& pattern, JSGlobalData* globalData, YarrCodeBlock& jitObject)
 {
-    YarrGenerator generator(pattern);
-    generator.compile(globalData, jitObject);
+    YarrGenerator(pattern).compile(globalData, jitObject);
 }
 
+int execute(YarrCodeBlock& jitObject, const UChar* input, unsigned start, unsigned length, int* output)
+{
+    return jitObject.execute(input, start, length, output);
+}
 
 }}
 
index dfdc777c06b4c72f404620c07d489c012f8f203d..414b575063742c9443e26ab05ae8ad16be4d378f 100644 (file)
@@ -29,7 +29,6 @@
 #if ENABLE(YARR_JIT)
 
 #include "MacroAssembler.h"
-#include "YarrPattern.h"
 #include "UString.h"
 
 #if CPU(X86) && !COMPILER(MSVC)
@@ -76,13 +75,6 @@ private:
     bool m_needFallBack;
 };
 
-void jitCompile(YarrPattern&, JSGlobalData*, YarrCodeBlock& jitObject);
-
-inline int execute(YarrCodeBlock& jitObject, const UChar* input, unsigned start, unsigned length, int* output)
-{
-    return jitObject.execute(input, start, length, output);
-}
-
 } } // namespace JSC::Yarr
 
 #endif
index 6c3fba55bdc5f33ed457944426a8debc804d088a..8c5741a0debda5f8c719201801ed5800b5fa72d7 100644 (file)
 #define YarrParser_h
 
 #include "UString.h"
-#include <limits.h>
+#include "Yarr.h"
 #include <wtf/ASCIICType.h>
 #include <wtf/unicode/Unicode.h>
 
 namespace JSC { namespace Yarr {
 
-static const unsigned quantifyInfinite = UINT_MAX;
 #define REGEXP_ERROR_PREFIX "Invalid regular expression: "
 
 enum BuiltInCharacterClassID {
index 9ca04cba103f6aa7a017a18317f2c7a41efb478a..e914f5281ef595aeef70fea4a48c7da47830619d 100644 (file)
@@ -27,7 +27,8 @@
 #include "config.h"
 #include "YarrPattern.h"
 
-#include "YarrInterpreter.h"
+#include "Yarr.h"
+#include "YarrParser.h"
 #include <wtf/Vector.h>
 
 using namespace WTF;
@@ -929,10 +930,9 @@ private:
     bool m_invertParentheticalAssertion;
 };
 
-
-static const char* compile(const UString& patternString, YarrPattern& pattern)
+const char* YarrPattern::compile(const UString& patternString)
 {
-    YarrPatternConstructor constructor(pattern);
+    YarrPatternConstructor constructor(*this);
 
     if (const char* error = parse(constructor, patternString))
         return error;
@@ -941,17 +941,14 @@ static const char* compile(const UString& patternString, YarrPattern& pattern)
     // Quoting Netscape's "What's new in JavaScript 1.2",
     //      "Note: if the number of left parentheses is less than the number specified
     //       in \#, the \# is taken as an octal escape as described in the next row."
-    if (pattern.containsIllegalBackReference()) {
-        unsigned numSubpatterns = pattern.m_numSubpatterns;
-
+    if (containsIllegalBackReference()) {
         constructor.reset();
 #if !ASSERT_DISABLED
         const char* error =
 #endif
-            parse(constructor, patternString, numSubpatterns);
+            parse(constructor, patternString, m_numSubpatterns);
 
         ASSERT(!error);
-        ASSERT(numSubpatterns == pattern.m_numSubpatterns);
     }
 
     constructor.checkForTerminalParentheses();
@@ -961,7 +958,7 @@ static const char* compile(const UString& patternString, YarrPattern& pattern)
     constructor.setupBeginChars();
 
     return 0;
-};
+}
 
 YarrPattern::YarrPattern(const UString& pattern, bool ignoreCase, bool multiline, const char** error)
     : m_ignoreCase(ignoreCase)
@@ -979,7 +976,7 @@ YarrPattern::YarrPattern(const UString& pattern, bool ignoreCase, bool multiline
     , nonspacesCached(0)
     , nonwordcharCached(0)
 {
-    *error = compile(pattern, *this);
+    *error = compile(pattern);
 }
 
 } }
index 14810c64bbf98bed57e6acf8003d0659eda7a6ca..2172dda6fda9380394012bcbf46899883addea20 100644 (file)
 
 namespace JSC { namespace Yarr {
 
-#define YarrStackSpaceForBackTrackInfoPatternCharacter 1 // Only for !fixed quantifiers.
-#define YarrStackSpaceForBackTrackInfoCharacterClass 1 // Only for !fixed quantifiers.
-#define YarrStackSpaceForBackTrackInfoBackReference 2
-#define YarrStackSpaceForBackTrackInfoAlternative 1 // One per alternative.
-#define YarrStackSpaceForBackTrackInfoParentheticalAssertion 1
-#define YarrStackSpaceForBackTrackInfoParenthesesOnce 1 // Only for !fixed quantifiers.
-#define YarrStackSpaceForBackTrackInfoParenthesesTerminal 1
-#define YarrStackSpaceForBackTrackInfoParentheses 2
-
 struct PatternDisjunction;
 
 struct CharacterRange {
@@ -410,6 +401,8 @@ struct YarrPattern {
     Vector<BeginChar> m_beginChars;
 
 private:
+    const char* compile(const UString& patternString);
+
     CharacterClass* newlineCached;
     CharacterClass* digitsCached;
     CharacterClass* spacesCached;