equal
deleted
inserted
replaced
38 #include "yarr/RegexInterpreter.h" |
38 #include "yarr/RegexInterpreter.h" |
39 #endif |
39 #endif |
40 |
40 |
41 #else |
41 #else |
42 |
42 |
43 #if ENABLE(WREC) |
|
44 #include "JIT.h" |
|
45 #include "WRECGenerator.h" |
|
46 #endif |
|
47 #include <pcre/pcre.h> |
43 #include <pcre/pcre.h> |
48 |
44 |
49 #endif |
45 #endif |
50 |
46 |
51 namespace JSC { |
47 namespace JSC { |
52 |
|
53 #if ENABLE(WREC) |
|
54 using namespace WREC; |
|
55 #endif |
|
56 |
48 |
57 inline RegExp::RegExp(JSGlobalData* globalData, const UString& pattern) |
49 inline RegExp::RegExp(JSGlobalData* globalData, const UString& pattern) |
58 : m_pattern(pattern) |
50 : m_pattern(pattern) |
59 , m_flagBits(0) |
51 , m_flagBits(0) |
60 , m_constructionError(0) |
52 , m_constructionError(0) |
63 compile(globalData); |
55 compile(globalData); |
64 } |
56 } |
65 |
57 |
66 inline RegExp::RegExp(JSGlobalData* globalData, const UString& pattern, const UString& flags) |
58 inline RegExp::RegExp(JSGlobalData* globalData, const UString& pattern, const UString& flags) |
67 : m_pattern(pattern) |
59 : m_pattern(pattern) |
68 , m_flags(flags) |
|
69 , m_flagBits(0) |
60 , m_flagBits(0) |
70 , m_constructionError(0) |
61 , m_constructionError(0) |
71 , m_numSubpatterns(0) |
62 , m_numSubpatterns(0) |
72 { |
63 { |
73 // NOTE: The global flag is handled on a case-by-case basis by functions like |
64 // NOTE: The global flag is handled on a case-by-case basis by functions like |
74 // String::match and RegExpObject::match. |
65 // String::match and RegExpObject::match. |
75 if (flags.find('g') != -1) |
66 if (flags.find('g') != UString::NotFound) |
76 m_flagBits |= Global; |
67 m_flagBits |= Global; |
77 if (flags.find('i') != -1) |
68 if (flags.find('i') != UString::NotFound) |
78 m_flagBits |= IgnoreCase; |
69 m_flagBits |= IgnoreCase; |
79 if (flags.find('m') != -1) |
70 if (flags.find('m') != UString::NotFound) |
80 m_flagBits |= Multiline; |
71 m_flagBits |= Multiline; |
81 |
72 |
82 compile(globalData); |
73 compile(globalData); |
83 } |
74 } |
84 |
75 |
116 if (startOffset < 0) |
107 if (startOffset < 0) |
117 startOffset = 0; |
108 startOffset = 0; |
118 if (ovector) |
109 if (ovector) |
119 ovector->clear(); |
110 ovector->clear(); |
120 |
111 |
121 if (startOffset > s.size() || s.isNull()) |
112 if (static_cast<unsigned>(startOffset) > s.size() || s.isNull()) |
122 return -1; |
113 return -1; |
123 |
114 |
124 #if ENABLE(YARR_JIT) |
115 #if ENABLE(YARR_JIT) |
125 if (!!m_regExpJITCode) { |
116 if (!!m_regExpJITCode) { |
126 #else |
117 #else |
163 return -1; |
154 return -1; |
164 } |
155 } |
165 |
156 |
166 #else |
157 #else |
167 |
158 |
168 void RegExp::compile(JSGlobalData* globalData) |
159 void RegExp::compile(JSGlobalData*) |
169 { |
160 { |
170 m_regExp = 0; |
161 m_regExp = 0; |
171 #if ENABLE(WREC) |
|
172 m_wrecFunction = Generator::compileRegExp(globalData, m_pattern, &m_numSubpatterns, &m_constructionError, m_executablePool, ignoreCase(), multiline()); |
|
173 if (m_wrecFunction || m_constructionError) |
|
174 return; |
|
175 // Fall through to non-WREC case. |
|
176 #else |
|
177 UNUSED_PARAM(globalData); |
|
178 #endif |
|
179 |
|
180 JSRegExpIgnoreCaseOption ignoreCaseOption = ignoreCase() ? JSRegExpIgnoreCase : JSRegExpDoNotIgnoreCase; |
162 JSRegExpIgnoreCaseOption ignoreCaseOption = ignoreCase() ? JSRegExpIgnoreCase : JSRegExpDoNotIgnoreCase; |
181 JSRegExpMultilineOption multilineOption = multiline() ? JSRegExpMultiline : JSRegExpSingleLine; |
163 JSRegExpMultilineOption multilineOption = multiline() ? JSRegExpMultiline : JSRegExpSingleLine; |
182 m_regExp = jsRegExpCompile(reinterpret_cast<const UChar*>(m_pattern.data()), m_pattern.size(), ignoreCaseOption, multilineOption, &m_numSubpatterns, &m_constructionError); |
164 m_regExp = jsRegExpCompile(reinterpret_cast<const UChar*>(m_pattern.data()), m_pattern.size(), ignoreCaseOption, multilineOption, &m_numSubpatterns, &m_constructionError); |
183 } |
165 } |
184 |
166 |
187 if (startOffset < 0) |
169 if (startOffset < 0) |
188 startOffset = 0; |
170 startOffset = 0; |
189 if (ovector) |
171 if (ovector) |
190 ovector->clear(); |
172 ovector->clear(); |
191 |
173 |
192 if (startOffset > s.size() || s.isNull()) |
174 if (static_cast<unsigned>(startOffset) > s.size() || s.isNull()) |
193 return -1; |
175 return -1; |
194 |
176 |
195 #if ENABLE(WREC) |
|
196 if (m_wrecFunction) { |
|
197 int offsetVectorSize = (m_numSubpatterns + 1) * 2; |
|
198 int* offsetVector; |
|
199 Vector<int, 32> nonReturnedOvector; |
|
200 if (ovector) { |
|
201 ovector->resize(offsetVectorSize); |
|
202 offsetVector = ovector->data(); |
|
203 } else { |
|
204 nonReturnedOvector.resize(offsetVectorSize); |
|
205 offsetVector = nonReturnedOvector.data(); |
|
206 } |
|
207 ASSERT(offsetVector); |
|
208 for (int j = 0; j < offsetVectorSize; ++j) |
|
209 offsetVector[j] = -1; |
|
210 |
|
211 int result = m_wrecFunction(s.data(), startOffset, s.size(), offsetVector); |
|
212 |
|
213 if (result < 0) { |
|
214 #ifndef NDEBUG |
|
215 // TODO: define up a symbol, rather than magic -1 |
|
216 if (result != -1) |
|
217 fprintf(stderr, "jsRegExpExecute failed with result %d\n", result); |
|
218 #endif |
|
219 if (ovector) |
|
220 ovector->clear(); |
|
221 } |
|
222 return result; |
|
223 } else |
|
224 #endif |
|
225 if (m_regExp) { |
177 if (m_regExp) { |
226 // Set up the offset vector for the result. |
178 // Set up the offset vector for the result. |
227 // First 2/3 used for result, the last third used by PCRE. |
179 // First 2/3 used for result, the last third used by PCRE. |
228 int* offsetVector; |
180 int* offsetVector; |
229 int offsetVectorSize; |
181 int offsetVectorSize; |