Changeset 42481 in webkit for trunk/JavaScriptCore/runtime
- Timestamp:
- Apr 14, 2009, 12:06:41 AM (16 years ago)
- Location:
- trunk/JavaScriptCore/runtime
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/runtime/RegExp.cpp
r40562 r42481 21 21 #include "config.h" 22 22 #include "RegExp.h" 23 24 #include "JIT.h"25 23 #include "Lexer.h" 26 #include "WRECGenerator.h"27 #include <pcre/pcre.h>28 24 #include <stdio.h> 29 25 #include <stdlib.h> … … 32 28 #include <wtf/OwnArrayPtr.h> 33 29 30 31 #if ENABLE(YARR) 32 33 #include "RegexCompiler.h" 34 #if ENABLE(YARR_JIT) 35 #include "RegexJIT.h" 36 #else 37 #include "RegexInterpreter.h" 38 #endif 39 40 #else 41 42 #if ENABLE(WREC) 43 #include "JIT.h" 44 #include "WRECGenerator.h" 45 #endif 46 #include <pcre/pcre.h> 47 48 #endif 49 34 50 namespace JSC { 35 51 … … 41 57 : m_pattern(pattern) 42 58 , m_flagBits(0) 43 , m_regExp(0)44 59 , m_constructionError(0) 45 60 , m_numSubpatterns(0) 46 61 { 47 #if ENABLE(WREC) 48 m_wrecFunction = Generator::compileRegExp(globalData, pattern, &m_numSubpatterns, &m_constructionError, m_executablePool); 49 if (m_wrecFunction || m_constructionError) 50 return; 51 // Fall through to non-WREC case. 52 #else 53 UNUSED_PARAM(globalData); 54 #endif 55 m_regExp = jsRegExpCompile(reinterpret_cast<const UChar*>(pattern.data()), pattern.size(), 56 JSRegExpDoNotIgnoreCase, JSRegExpSingleLine, &m_numSubpatterns, &m_constructionError); 57 } 58 59 PassRefPtr<RegExp> RegExp::create(JSGlobalData* globalData, const UString& pattern) 60 { 61 return adoptRef(new RegExp(globalData, pattern)); 62 compile(globalData); 62 63 } 63 64 … … 66 67 , m_flags(flags) 67 68 , m_flagBits(0) 68 , m_regExp(0)69 69 , m_constructionError(0) 70 70 , m_numSubpatterns(0) … … 74 74 if (flags.find('g') != -1) 75 75 m_flagBits |= Global; 76 77 // FIXME: Eliminate duplication by adding a way ask a JSRegExp what its flags are? 78 JSRegExpIgnoreCaseOption ignoreCaseOption = JSRegExpDoNotIgnoreCase; 79 if (flags.find('i') != -1) { 76 if (flags.find('i') != -1) 80 77 m_flagBits |= IgnoreCase; 81 ignoreCaseOption = JSRegExpIgnoreCase; 78 if (flags.find('m') != -1) 79 m_flagBits |= Multiline; 80 81 compile(globalData); 82 } 83 84 #if !ENABLE(YARR) 85 RegExp::~RegExp() 86 { 87 jsRegExpFree(m_regExp); 88 } 89 #endif 90 91 PassRefPtr<RegExp> RegExp::create(JSGlobalData* globalData, const UString& pattern) 92 { 93 return adoptRef(new RegExp(globalData, pattern)); 94 } 95 96 PassRefPtr<RegExp> RegExp::create(JSGlobalData* globalData, const UString& pattern, const UString& flags) 97 { 98 return adoptRef(new RegExp(globalData, pattern, flags)); 99 } 100 101 #if ENABLE(YARR) 102 103 void RegExp::compile(JSGlobalData* globalData) 104 { 105 #if ENABLE(YARR_JIT) 106 Yarr::jitCompileRegex(globalData, m_regExpJITCode, m_pattern, m_numSubpatterns, m_constructionError, ignoreCase(), multiline()); 107 #else 108 UNUSED_PARAM(globalData); 109 m_regExpBytecode.set(Yarr::byteCompileRegex(m_pattern, m_numSubpatterns, m_constructionError, ignoreCase(), multiline())); 110 #endif 111 } 112 113 int RegExp::match(const UString& s, int startOffset, OwnArrayPtr<int>* ovector) 114 { 115 if (startOffset < 0) 116 startOffset = 0; 117 if (ovector) 118 ovector->clear(); 119 120 if (startOffset > s.size() || s.isNull()) 121 return -1; 122 123 #if ENABLE(YARR_JIT) 124 if (m_regExpJITCode.m_jitCode) { 125 #else 126 if (m_regExpBytecode) { 127 #endif 128 int offsetVectorSize = (m_numSubpatterns + 1) * 2; 129 int* offsetVector = new int [offsetVectorSize]; 130 ASSERT(offsetVector); 131 for (int j = 0; j < offsetVectorSize; ++j) 132 offsetVector[j] = -1; 133 134 OwnArrayPtr<int> nonReturnedOvector; 135 if (!ovector) 136 nonReturnedOvector.set(offsetVector); 137 else 138 ovector->set(offsetVector); 139 140 #if ENABLE(YARR_JIT) 141 int result = Yarr::executeRegex(m_regExpJITCode, s.data(), startOffset, s.size(), offsetVector); 142 #else 143 int result = Yarr::interpretRegex(m_regExpBytecode.get(), s.data(), startOffset, s.size(), offsetVector); 144 #endif 145 146 if (result < 0) { 147 #ifndef NDEBUG 148 // TODO: define up a symbol, rather than magic -1 149 if (result != -1) 150 fprintf(stderr, "jsRegExpExecute failed with result %d\n", result); 151 #endif 152 if (ovector) 153 ovector->clear(); 154 } 155 return result; 82 156 } 83 157 84 JSRegExpMultilineOption multilineOption = JSRegExpSingleLine; 85 if (flags.find('m') != -1) { 86 m_flagBits |= Multiline; 87 multilineOption = JSRegExpMultiline; 88 } 89 90 #if ENABLE(WREC) 91 m_wrecFunction = Generator::compileRegExp(globalData, pattern, &m_numSubpatterns, &m_constructionError, m_executablePool, (m_flagBits & IgnoreCase), (m_flagBits & Multiline)); 158 return -1; 159 } 160 161 #else 162 163 void RegExp::compile(JSGlobalData* globalData) 164 { 165 m_regExp = 0; 166 #if ENABLE(WREC) 167 m_wrecFunction = Generator::compileRegExp(globalData, m_pattern, &m_numSubpatterns, &m_constructionError, m_executablePool, ignoreCase(), multiline()); 92 168 if (m_wrecFunction || m_constructionError) 93 169 return; … … 96 172 UNUSED_PARAM(globalData); 97 173 #endif 98 m_regExp = jsRegExpCompile(reinterpret_cast<const UChar*>(pattern.data()), pattern.size(), 99 ignoreCaseOption, multilineOption, &m_numSubpatterns, &m_constructionError); 100 } 101 102 PassRefPtr<RegExp> RegExp::create(JSGlobalData* globalData, const UString& pattern, const UString& flags) 103 { 104 return adoptRef(new RegExp(globalData, pattern, flags)); 105 } 106 107 RegExp::~RegExp() 108 { 109 jsRegExpFree(m_regExp); 174 175 JSRegExpIgnoreCaseOption ignoreCaseOption = ignoreCase() ? JSRegExpIgnoreCase : JSRegExpDoNotIgnoreCase; 176 JSRegExpMultilineOption multilineOption = multiline() ? JSRegExpMultiline : JSRegExpSingleLine; 177 m_regExp = jsRegExpCompile(reinterpret_cast<const UChar*>(m_pattern.data()), m_pattern.size(), ignoreCaseOption, multilineOption, &m_numSubpatterns, &m_constructionError); 110 178 } 111 179 … … 181 249 } 182 250 251 #endif 252 183 253 } // namespace JSC -
trunk/JavaScriptCore/runtime/RegExp.h
r39554 r42481 27 27 #include <wtf/Forward.h> 28 28 #include <wtf/RefCounted.h> 29 #include "RegexJIT.h" 30 #include "RegexInterpreter.h" 29 31 30 32 struct JSRegExp; … … 38 40 static PassRefPtr<RegExp> create(JSGlobalData* globalData, const UString& pattern); 39 41 static PassRefPtr<RegExp> create(JSGlobalData* globalData, const UString& pattern, const UString& flags); 42 #if !ENABLE(YARR) 40 43 ~RegExp(); 44 #endif 41 45 42 46 bool global() const { return m_flagBits & Global; } … … 57 61 RegExp(JSGlobalData* globalData, const UString& pattern, const UString& flags); 58 62 59 void compile( );63 void compile(JSGlobalData*); 60 64 61 65 enum FlagBits { Global = 1, IgnoreCase = 2, Multiline = 4 }; … … 64 68 UString m_flags; // FIXME: Just decompile m_regExp instead of storing this. 65 69 int m_flagBits; 66 JSRegExp* m_regExp;67 70 const char* m_constructionError; 68 71 unsigned m_numSubpatterns; 69 72 73 #if ENABLE(YARR_JIT) 74 Yarr::RegexCodeBlock m_regExpJITCode; 75 #elif ENABLE(YARR) 76 OwnPtr<Yarr::BytecodePattern> m_regExpBytecode; 77 #else 70 78 #if ENABLE(WREC) 71 79 WREC::CompiledRegExp m_wrecFunction; 72 80 RefPtr<ExecutablePool> m_executablePool; 81 #endif 82 JSRegExp* m_regExp; 73 83 #endif 74 84 };
Note:
See TracChangeset
for help on using the changeset viewer.