+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.
'wtf/win/MainThreadWin.cpp',
'wtf/win/OwnPtrWin.cpp',
'wtf/wx/MainThreadWx.cpp',
+ 'yarr/Yarr.h'
'yarr/YarrInterpreter.cpp',
'yarr/YarrInterpreter.h',
'yarr/YarrJIT.cpp',
<Filter
Name="yarr"
>
+ <File
+ RelativePath="..\..\yarr\Yarr.h"
+ >
+ </File>
<File
RelativePath="..\..\yarr\YarrInterpreter.cpp"
>
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;
};
#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 {
--- /dev/null
+/*
+ * 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
+
#include "config.h"
#include "YarrInterpreter.h"
-#include "YarrPattern.h"
+#include "Yarr.h"
#include <wtf/BumpPointerAllocator.h>
#ifndef NDEBUG
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);
#ifndef YarrInterpreter_h
#define YarrInterpreter_h
-#include "YarrParser.h"
#include "YarrPattern.h"
#include <wtf/PassOwnPtr.h>
#include <wtf/unicode/Unicode.h>
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 {
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
#include "JSGlobalData.h"
#include "LinkBuffer.h"
#include "MacroAssembler.h"
-#include "YarrParser.h"
+#include "Yarr.h"
#if ENABLE(YARR_JIT)
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);
+}
}}
#if ENABLE(YARR_JIT)
#include "MacroAssembler.h"
-#include "YarrPattern.h"
#include "UString.h"
#if CPU(X86) && !COMPILER(MSVC)
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
#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 {
#include "config.h"
#include "YarrPattern.h"
-#include "YarrInterpreter.h"
+#include "Yarr.h"
+#include "YarrParser.h"
#include <wtf/Vector.h>
using namespace WTF;
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;
// 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();
constructor.setupBeginChars();
return 0;
-};
+}
YarrPattern::YarrPattern(const UString& pattern, bool ignoreCase, bool multiline, const char** error)
: m_ignoreCase(ignoreCase)
, nonspacesCached(0)
, nonwordcharCached(0)
{
- *error = compile(pattern, *this);
+ *error = compile(pattern);
}
} }
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 {
Vector<BeginChar> m_beginChars;
private:
+ const char* compile(const UString& patternString);
+
CharacterClass* newlineCached;
CharacterClass* digitsCached;
CharacterClass* spacesCached;