OLD | NEW |
1 /* | 1 /* |
2 Copyright (c) 2009-2010 Sony Pictures Imageworks Inc., et al. | 2 Copyright (c) 2009-2010 Sony Pictures Imageworks Inc., et al. |
3 All Rights Reserved. | 3 All Rights Reserved. |
4 | 4 |
5 Redistribution and use in source and binary forms, with or without | 5 Redistribution and use in source and binary forms, with or without |
6 modification, are permitted provided that the following conditions are | 6 modification, are permitted provided that the following conditions are |
7 met: | 7 met: |
8 * Redistributions of source code must retain the above copyright | 8 * Redistributions of source code must retain the above copyright |
9 notice, this list of conditions and the following disclaimer. | 9 notice, this list of conditions and the following disclaimer. |
10 * Redistributions in binary form must reproduce the above copyright | 10 * Redistributions in binary form must reproduce the above copyright |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 | 115 |
116 DECLOP (OP_printf) | 116 DECLOP (OP_printf) |
117 { | 117 { |
118 ASSERT (nargs >= 1); | 118 ASSERT (nargs >= 1); |
119 Symbol &Format (exec->sym (args[0])); | 119 Symbol &Format (exec->sym (args[0])); |
120 ASSERT (Format.typespec().is_string ()); | 120 ASSERT (Format.typespec().is_string ()); |
121 VaryingRef<ustring> format ((ustring *)Format.data(), Format.step()); | 121 VaryingRef<ustring> format ((ustring *)Format.data(), Format.step()); |
122 bool varying = format.is_varying (); | 122 bool varying = format.is_varying (); |
123 for (int i = 1; i < nargs; ++i) | 123 for (int i = 1; i < nargs; ++i) |
124 varying |= exec->sym(args[i]).is_varying (); | 124 varying |= exec->sym(args[i]).is_varying (); |
125 for (int i = beginpoint; i < endpoint; ++i) { | 125 if (! varying) { |
126 if (runflags[i]) { | 126 std::string s = format_args (exec, format[0].c_str(), |
| 127 nargs-1, args+1, 0); |
| 128 exec->message ("%s", s.c_str()); |
| 129 } else { |
| 130 SHADE_LOOP_BEGIN |
127 std::string s = format_args (exec, format[i].c_str(), | 131 std::string s = format_args (exec, format[i].c_str(), |
128 nargs-1, args+1, i); | 132 nargs-1, args+1, i); |
129 exec->message ("%s", s.c_str()); | 133 exec->message ("%s", s.c_str()); |
130 if (! varying) | 134 SHADE_LOOP_END |
131 break; | |
132 } | |
133 } | 135 } |
134 } | 136 } |
135 | 137 |
136 | 138 |
137 | 139 |
138 DECLOP (OP_error) | 140 DECLOP (OP_error) |
139 { | 141 { |
140 ASSERT (nargs >= 1); | 142 ASSERT (nargs >= 1); |
141 Symbol &Format (exec->sym (args[0])); | 143 Symbol &Format (exec->sym (args[0])); |
142 ASSERT (Format.typespec().is_string ()); | 144 ASSERT (Format.typespec().is_string ()); |
143 VaryingRef<ustring> format ((ustring *)Format.data(), Format.step()); | 145 VaryingRef<ustring> format ((ustring *)Format.data(), Format.step()); |
144 bool varying = format.is_varying (); | 146 bool varying = format.is_varying (); |
145 for (int i = 1; i < nargs; ++i) | 147 for (int i = 1; i < nargs; ++i) |
146 varying |= exec->sym(args[i]).is_varying (); | 148 varying |= exec->sym(args[i]).is_varying (); |
147 for (int i = beginpoint; i < endpoint; ++i) { | 149 if (! varying) { |
148 if (runflags[i]) { | 150 std::string s = format_args (exec, format[0].c_str(), |
| 151 nargs-1, args+1, 0); |
| 152 exec->error ("Shader error [%s]: %s", |
| 153 exec->instance()->master()->shadername().c_str(), |
| 154 s.c_str()); |
| 155 } else { |
| 156 SHADE_LOOP_BEGIN |
149 std::string s = format_args (exec, format[i].c_str(), | 157 std::string s = format_args (exec, format[i].c_str(), |
150 nargs-1, args+1, i); | 158 nargs-1, args+1, i); |
151 exec->error ("Shader error [%s]: %s", | 159 exec->error ("Shader error [%s]: %s", |
152 exec->instance()->master()->shadername().c_str(), | 160 exec->instance()->master()->shadername().c_str(), |
153 s.c_str()); | 161 s.c_str()); |
154 if (! varying) | 162 SHADE_LOOP_END |
155 break; | |
156 } | |
157 } | 163 } |
158 } | 164 } |
159 | 165 |
160 | 166 |
161 | 167 |
162 DECLOP (OP_warning) | 168 DECLOP (OP_warning) |
163 { | 169 { |
164 ASSERT (nargs >= 1); | 170 ASSERT (nargs >= 1); |
165 Symbol &Format (exec->sym (args[0])); | 171 Symbol &Format (exec->sym (args[0])); |
166 ASSERT (Format.typespec().is_string ()); | 172 ASSERT (Format.typespec().is_string ()); |
167 VaryingRef<ustring> format ((ustring *)Format.data(), Format.step()); | 173 VaryingRef<ustring> format ((ustring *)Format.data(), Format.step()); |
168 bool varying = format.is_varying (); | 174 bool varying = format.is_varying (); |
169 for (int i = 1; i < nargs; ++i) | 175 for (int i = 1; i < nargs; ++i) |
170 varying |= exec->sym(args[i]).is_varying (); | 176 varying |= exec->sym(args[i]).is_varying (); |
171 for (int i = beginpoint; i < endpoint; ++i) { | 177 if (! varying) { |
172 if (runflags[i]) { | 178 std::string s = format_args (exec, format[0].c_str(), |
| 179 nargs-1, args+1, 0); |
| 180 exec->warning ("Shader warning [%s]: %s", |
| 181 exec->instance()->master()->shadername().c_str(), |
| 182 s.c_str()); |
| 183 } else { |
| 184 SHADE_LOOP_BEGIN |
173 std::string s = format_args (exec, format[i].c_str(), | 185 std::string s = format_args (exec, format[i].c_str(), |
174 nargs-1, args+1, i); | 186 nargs-1, args+1, i); |
175 exec->warning ("Shader warning [%s]: %s", | 187 exec->warning ("Shader warning [%s]: %s", |
176 exec->instance()->master()->shadername().c_str(), | 188 exec->instance()->master()->shadername().c_str(), |
177 s.c_str()); | 189 s.c_str()); |
178 if (! varying) | 190 SHADE_LOOP_END |
179 break; | |
180 } | |
181 } | 191 } |
182 } | 192 } |
183 | 193 |
184 | 194 |
185 | 195 |
186 DECLOP (OP_format) | 196 DECLOP (OP_format) |
187 { | 197 { |
188 ASSERT (nargs >= 2); | 198 ASSERT (nargs >= 2); |
189 Symbol &Result (exec->sym (args[0])); | 199 Symbol &Result (exec->sym (args[0])); |
190 Symbol &Format (exec->sym (args[1])); | 200 Symbol &Format (exec->sym (args[1])); |
191 ASSERT (Result.typespec().is_string ()); | 201 ASSERT (Result.typespec().is_string ()); |
192 ASSERT (Format.typespec().is_string ()); | 202 ASSERT (Format.typespec().is_string ()); |
193 | 203 |
194 // Adjust the result's uniform/varying status | 204 // Adjust the result's uniform/varying status |
195 bool varying = Format.is_varying (); | 205 bool varying = Format.is_varying (); |
196 for (int i = 2; i < nargs; ++i) | 206 for (int i = 2; i < nargs; ++i) |
197 varying |= exec->sym(args[i]).is_varying (); | 207 varying |= exec->sym(args[i]).is_varying (); |
198 exec->adjust_varying (Result, varying); | 208 exec->adjust_varying (Result, varying); |
199 | 209 |
200 VaryingRef<ustring> result ((ustring *)Result.data(), Result.step()); | 210 VaryingRef<ustring> result ((ustring *)Result.data(), Result.step()); |
201 VaryingRef<ustring> format ((ustring *)Format.data(), Format.step()); | 211 VaryingRef<ustring> format ((ustring *)Format.data(), Format.step()); |
202 for (int i = beginpoint; i < endpoint; ++i) { | 212 if (Result.is_uniform()) { |
203 if (runflags[i]) { | 213 result[0] = format_args (exec, format[0].c_str(), |
| 214 nargs-2, args+2, 0); |
| 215 } else { |
| 216 SHADE_LOOP_BEGIN |
204 result[i] = format_args (exec, format[i].c_str(), | 217 result[i] = format_args (exec, format[i].c_str(), |
205 nargs-2, args+2, i); | 218 nargs-2, args+2, i); |
206 if (! Result.is_varying()) | 219 SHADE_LOOP_END |
207 break; | |
208 } | |
209 } | 220 } |
210 } | 221 } |
211 | 222 |
212 | 223 |
213 | 224 |
214 DECLOP (OP_concat) | 225 DECLOP (OP_concat) |
215 { | 226 { |
216 ASSERT (nargs >= 1); | 227 ASSERT (nargs >= 1); |
217 Symbol &Result (exec->sym (args[0])); | 228 Symbol &Result (exec->sym (args[0])); |
218 ASSERT (Result.typespec().is_string ()); | 229 ASSERT (Result.typespec().is_string ()); |
219 | 230 |
220 // Adjust the result's uniform/varying status and construct our | 231 // Adjust the result's uniform/varying status and construct our |
221 // format string. | 232 // format string. |
222 bool varying = false; | 233 bool varying = false; |
223 std::string format; | 234 std::string format; |
224 for (int i = 1; i < nargs; ++i) { | 235 for (int i = 1; i < nargs; ++i) { |
225 varying |= exec->sym(args[i]).is_varying (); | 236 varying |= exec->sym(args[i]).is_varying (); |
226 format += std::string ("%s"); | 237 format += std::string ("%s"); |
227 } | 238 } |
228 exec->adjust_varying (Result, varying); | 239 exec->adjust_varying (Result, varying); |
229 | 240 |
230 VaryingRef<ustring> result ((ustring *)Result.data(), Result.step()); | 241 VaryingRef<ustring> result ((ustring *)Result.data(), Result.step()); |
231 for (int i = beginpoint; i < endpoint; ++i) { | 242 if (Result.is_uniform()) { |
232 if (runflags[i]) { | 243 result[0] = ustring (format_args (exec, format.c_str(), |
| 244 nargs-1, args+1, 0)); |
| 245 } else { |
| 246 SHADE_LOOP_BEGIN |
233 result[i] = ustring (format_args (exec, format.c_str(), | 247 result[i] = ustring (format_args (exec, format.c_str(), |
234 nargs-1, args+1, i)); | 248 nargs-1, args+1, i)); |
235 if (! Result.is_varying()) | 249 SHADE_LOOP_END |
236 break; | |
237 } | |
238 } | 250 } |
239 } | 251 } |
240 | 252 |
241 | 253 |
242 | 254 |
243 DECLOP (OP_strlen) | 255 DECLOP (OP_strlen) |
244 { | 256 { |
245 DASSERT (nargs == 2); | 257 DASSERT (nargs == 2); |
246 Symbol &Result (exec->sym (args[0])); | 258 Symbol &Result (exec->sym (args[0])); |
247 Symbol &S (exec->sym (args[1])); | 259 Symbol &S (exec->sym (args[1])); |
248 DASSERT (Result.typespec().is_int() && S.typespec().is_string()); | 260 DASSERT (Result.typespec().is_int() && S.typespec().is_string()); |
249 | 261 |
250 exec->adjust_varying (Result, S.is_varying(), false /* can't alias */); | 262 exec->adjust_varying (Result, S.is_varying(), false /* can't alias */); |
251 | 263 |
252 VaryingRef<int> result ((int *)Result.data(), Result.step()); | 264 VaryingRef<int> result ((int *)Result.data(), Result.step()); |
253 VaryingRef<ustring> s ((ustring *)S.data(), S.step()); | 265 VaryingRef<ustring> s ((ustring *)S.data(), S.step()); |
254 for (int i = beginpoint; i < endpoint; ++i) { | 266 if (Result.is_uniform()) { |
255 if (runflags[i]) { | 267 result[0] = s[0].length (); |
| 268 } else { |
| 269 SHADE_LOOP_BEGIN |
256 result[i] = s[i].length (); | 270 result[i] = s[i].length (); |
257 if (! Result.is_varying()) | 271 SHADE_LOOP_END |
258 break; | |
259 } | |
260 } | 272 } |
261 } | 273 } |
262 | 274 |
263 | 275 |
264 | 276 |
265 DECLOP (OP_startswith) | 277 DECLOP (OP_startswith) |
266 { | 278 { |
267 DASSERT (nargs == 3); | 279 DASSERT (nargs == 3); |
268 Symbol &Result (exec->sym (args[0])); | 280 Symbol &Result (exec->sym (args[0])); |
269 Symbol &S (exec->sym (args[1])); | 281 Symbol &S (exec->sym (args[1])); |
270 Symbol &Substr (exec->sym (args[2])); | 282 Symbol &Substr (exec->sym (args[2])); |
271 DASSERT (Result.typespec().is_int() && S.typespec().is_string() && | 283 DASSERT (Result.typespec().is_int() && S.typespec().is_string() && |
272 Substr.typespec().is_string()); | 284 Substr.typespec().is_string()); |
273 | 285 |
274 exec->adjust_varying (Result, S.is_varying() | Substr.is_varying(), | 286 exec->adjust_varying (Result, S.is_varying() | Substr.is_varying(), |
275 false /* can't alias */); | 287 false /* can't alias */); |
276 | 288 |
277 VaryingRef<int> result ((int *)Result.data(), Result.step()); | 289 VaryingRef<int> result ((int *)Result.data(), Result.step()); |
278 VaryingRef<ustring> s ((ustring *)S.data(), S.step()); | 290 VaryingRef<ustring> s ((ustring *)S.data(), S.step()); |
279 VaryingRef<ustring> substr ((ustring *)Substr.data(), Substr.step()); | 291 VaryingRef<ustring> substr ((ustring *)Substr.data(), Substr.step()); |
280 for (int i = beginpoint; i < endpoint; ++i) { | 292 if (Result.is_uniform()) { |
281 if (runflags[i]) { | 293 int c = strncmp (s[0].c_str(), substr[0].c_str(), substr[0].size()); |
| 294 result[0] = (c == 0); |
| 295 } else { |
| 296 SHADE_LOOP_BEGIN |
282 int c = strncmp (s[i].c_str(), substr[i].c_str(), substr[i].size()); | 297 int c = strncmp (s[i].c_str(), substr[i].c_str(), substr[i].size()); |
283 result[i] = (c == 0); | 298 result[i] = (c == 0); |
284 if (! Result.is_varying()) | 299 SHADE_LOOP_END |
285 break; | |
286 } | |
287 } | 300 } |
288 } | 301 } |
289 | 302 |
290 | 303 |
291 | 304 |
292 DECLOP (OP_endswith) | 305 DECLOP (OP_endswith) |
293 { | 306 { |
294 DASSERT (nargs == 3); | 307 DASSERT (nargs == 3); |
295 Symbol &Result (exec->sym (args[0])); | 308 Symbol &Result (exec->sym (args[0])); |
296 Symbol &S (exec->sym (args[1])); | 309 Symbol &S (exec->sym (args[1])); |
297 Symbol &Substr (exec->sym (args[2])); | 310 Symbol &Substr (exec->sym (args[2])); |
298 DASSERT (Result.typespec().is_int() && S.typespec().is_string() && | 311 DASSERT (Result.typespec().is_int() && S.typespec().is_string() && |
299 Substr.typespec().is_string()); | 312 Substr.typespec().is_string()); |
300 | 313 |
301 exec->adjust_varying (Result, S.is_varying() | Substr.is_varying(), | 314 exec->adjust_varying (Result, S.is_varying() | Substr.is_varying(), |
302 false /* can't alias */); | 315 false /* can't alias */); |
303 | 316 |
304 VaryingRef<int> result ((int *)Result.data(), Result.step()); | 317 VaryingRef<int> result ((int *)Result.data(), Result.step()); |
305 VaryingRef<ustring> s ((ustring *)S.data(), S.step()); | 318 VaryingRef<ustring> s ((ustring *)S.data(), S.step()); |
306 VaryingRef<ustring> substr ((ustring *)Substr.data(), Substr.step()); | 319 VaryingRef<ustring> substr ((ustring *)Substr.data(), Substr.step()); |
307 for (int i = beginpoint; i < endpoint; ++i) { | 320 if (Result.is_uniform()) { |
308 if (runflags[i]) { | 321 size_t len = substr[0].length (); |
| 322 if (len > s[0].length()) |
| 323 result[0] = 0; |
| 324 else { |
| 325 int c = strncmp (s[0].c_str() + s[0].length() - len, |
| 326 substr[0].c_str(), substr[0].size()); |
| 327 result[0] = (c == 0); |
| 328 } |
| 329 } else { |
| 330 SHADE_LOOP_BEGIN |
309 size_t len = substr[i].length (); | 331 size_t len = substr[i].length (); |
310 if (len > s[i].length()) | 332 if (len > s[i].length()) |
311 result[i] = 0; | 333 result[i] = 0; |
312 else { | 334 else { |
313 int c = strncmp (s[i].c_str() + s[i].length() - len, | 335 int c = strncmp (s[i].c_str() + s[i].length() - len, |
314 substr[i].c_str(), substr[i].size()); | 336 substr[i].c_str(), substr[i].size()); |
315 result[i] = (c == 0); | 337 result[i] = (c == 0); |
316 } | 338 } |
317 if (! Result.is_varying()) | 339 SHADE_LOOP_END |
318 break; | |
319 } | |
320 } | 340 } |
321 } | 341 } |
322 | 342 |
323 | 343 |
324 | 344 |
325 DECLOP (OP_substr) | 345 DECLOP (OP_substr) |
326 { | 346 { |
327 DASSERT (nargs == 4); | 347 DASSERT (nargs == 4); |
328 Symbol &Result (exec->sym (args[0])); | 348 Symbol &Result (exec->sym (args[0])); |
329 Symbol &S (exec->sym (args[1])); | 349 Symbol &S (exec->sym (args[1])); |
330 Symbol &Start (exec->sym (args[2])); | 350 Symbol &Start (exec->sym (args[2])); |
331 Symbol &Length (exec->sym (args[3])); | 351 Symbol &Length (exec->sym (args[3])); |
332 DASSERT (Result.typespec().is_string() && S.typespec().is_string() && | 352 DASSERT (Result.typespec().is_string() && S.typespec().is_string() && |
333 Start.typespec().is_int() && Length.typespec().is_int()); | 353 Start.typespec().is_int() && Length.typespec().is_int()); |
334 | 354 |
335 bool varying = S.is_varying() | Start.is_varying() | Length.is_varying(); | 355 bool varying = S.is_varying() | Start.is_varying() | Length.is_varying(); |
336 exec->adjust_varying (Result, varying); | 356 exec->adjust_varying (Result, varying); |
337 | 357 |
338 VaryingRef<ustring> result ((ustring *)Result.data(), Result.step()); | 358 VaryingRef<ustring> result ((ustring *)Result.data(), Result.step()); |
339 VaryingRef<ustring> s ((ustring *)S.data(), S.step()); | 359 VaryingRef<ustring> s ((ustring *)S.data(), S.step()); |
340 VaryingRef<int> start ((int *)Start.data(), Start.step()); | 360 VaryingRef<int> start ((int *)Start.data(), Start.step()); |
341 VaryingRef<int> length ((int *)Length.data(), Length.step()); | 361 VaryingRef<int> length ((int *)Length.data(), Length.step()); |
342 for (int i = beginpoint; i < endpoint; ++i) { | 362 if (Result.is_uniform()) { |
343 if (runflags[i]) { | 363 const ustring &str (s[0]); |
| 364 int b = start[0]; |
| 365 if (b < 0) |
| 366 b += str.length(); |
| 367 b = Imath::clamp (b, 0, (int)str.length()); |
| 368 int len = Imath::clamp (length[0], 0, (int)str.length()); |
| 369 result[0] = ustring (s[0], b, len); |
| 370 } else { |
| 371 SHADE_LOOP_BEGIN |
344 const ustring &str (s[i]); | 372 const ustring &str (s[i]); |
345 int b = start[i]; | 373 int b = start[i]; |
346 if (b < 0) | 374 if (b < 0) |
347 b += str.length(); | 375 b += str.length(); |
348 b = Imath::clamp (b, 0, (int)str.length()); | 376 b = Imath::clamp (b, 0, (int)str.length()); |
349 int len = Imath::clamp (length[i], 0, (int)str.length()); | 377 int len = Imath::clamp (length[i], 0, (int)str.length()); |
350 result[i] = ustring (s[i], b, len); | 378 result[i] = ustring (s[i], b, len); |
351 if (! Result.is_varying()) | 379 SHADE_LOOP_END |
352 break; | |
353 } | |
354 } | 380 } |
355 } | 381 } |
356 | 382 |
357 | 383 |
358 | 384 |
359 // This template function does regex_match or regex_search, with or | 385 // This template function does regex_match or regex_search, with or |
360 // without match results being saved, and will be specialized for one of | 386 // without match results being saved, and will be specialized for one of |
361 // those 4 cases by template expansion. | 387 // those 4 cases by template expansion. |
362 template <bool fullmatch, bool do_match_results> | 388 template <bool fullmatch, bool do_match_results> |
363 DECLOP (regex_search_specialized) | 389 DECLOP (regex_search_specialized) |
(...skipping 14 matching lines...) Expand all Loading... |
378 ASSERT (matchtype.arraylen && matchtype.elementtype() == TypeDesc::INT); | 404 ASSERT (matchtype.arraylen && matchtype.elementtype() == TypeDesc::INT); |
379 exec->adjust_varying (Match, varying); | 405 exec->adjust_varying (Match, varying); |
380 } | 406 } |
381 | 407 |
382 VaryingRef<int> result ((int *)Result.data(), Result.step()); | 408 VaryingRef<int> result ((int *)Result.data(), Result.step()); |
383 VaryingRef<ustring> subject ((ustring *)Subject.data(), Subject.step()); | 409 VaryingRef<ustring> subject ((ustring *)Subject.data(), Subject.step()); |
384 VaryingRef<ustring> pattern ((ustring *)Pattern.data(), Pattern.step()); | 410 VaryingRef<ustring> pattern ((ustring *)Pattern.data(), Pattern.step()); |
385 ustring last_pattern; | 411 ustring last_pattern; |
386 boost::match_results<std::string::const_iterator> mresults; | 412 boost::match_results<std::string::const_iterator> mresults; |
387 const boost::regex *regex = NULL; | 413 const boost::regex *regex = NULL; |
388 for (int i = beginpoint; i < endpoint; ++i) { | 414 SHADE_LOOP_BEGIN |
389 if (runflags[i]) { | 415 if (! regex || pattern[i] != last_pattern) { |
390 if (! regex || pattern[i] != last_pattern) { | 416 regex = &exec->context()->find_regex (pattern[i]); |
391 regex = &exec->context()->find_regex (pattern[i]); | 417 last_pattern = pattern[i]; |
392 last_pattern = pattern[i]; | 418 } |
| 419 if (do_match_results && matchtype.arraylen > 0) { |
| 420 std::string::const_iterator start = subject[i].string().begin(); |
| 421 result[i] = fullmatch ?· |
| 422 boost::regex_match (subject[i].string(), mresults, *regex) : |
| 423 boost::regex_search (subject[i].string(), mresults, *regex); |
| 424 int *m = (int *)((char *)Match.data() + i*Match.step()); |
| 425 for (int r = 0; r < matchtype.arraylen; ++r) { |
| 426 if (r/2 < (int)mresults.size()) { |
| 427 if ((r & 1) == 0) |
| 428 m[r] = mresults[r/2].first - start; |
| 429 else |
| 430 m[r] = mresults[r/2].second - start; |
| 431 } else { |
| 432 m[r] = pattern[i].length(); |
| 433 } |
393 } | 434 } |
394 if (do_match_results && matchtype.arraylen > 0) { | 435 } else { |
395 std::string::const_iterator start = subject[i].string().begin(); | 436 result[i] = fullmatch ? regex_match (subject[i].c_str(), *regex) |
396 result[i] = fullmatch ?· | 437 : regex_search (subject[i].c_str(), *regex); |
397 boost::regex_match (subject[i].string(), mresults, *regex) : | |
398 boost::regex_search (subject[i].string(), mresults, *regex); | |
399 int *m = (int *)((char *)Match.data() + i*Match.step()); | |
400 for (int r = 0; r < matchtype.arraylen; ++r) { | |
401 if (r/2 < (int)mresults.size()) { | |
402 if ((r & 1) == 0) | |
403 m[r] = mresults[r/2].first - start; | |
404 else | |
405 m[r] = mresults[r/2].second - start; | |
406 } else { | |
407 m[r] = pattern[i].length(); | |
408 } | |
409 } | |
410 } else { | |
411 result[i] = fullmatch ? regex_match (subject[i].c_str(), *regex) | |
412 : regex_search (subject[i].c_str(), *regex); | |
413 } | |
414 if (! Result.is_varying()) | |
415 break; | |
416 } | 438 } |
417 } | 439 if (! Result.is_varying()) |
| 440 break; |
| 441 SHADE_LOOP_END |
418 } | 442 } |
419 | 443 |
420 | 444 |
421 | 445 |
422 DECLOP (OP_regex_search) | 446 DECLOP (OP_regex_search) |
423 { | 447 { |
424 ASSERT (nargs == 3 || nargs == 4); | 448 ASSERT (nargs == 3 || nargs == 4); |
425 Symbol &Result (exec->sym (args[0])); | 449 Symbol &Result (exec->sym (args[0])); |
426 Symbol &Subject (exec->sym (args[1])); | 450 Symbol &Subject (exec->sym (args[1])); |
427 bool do_match_results = (nargs == 4); | 451 bool do_match_results = (nargs == 4); |
428 Symbol &Match (exec->sym (args[2])); | 452 Symbol &Match (exec->sym (args[2])); |
429 Symbol &Pattern (exec->sym (args[2+do_match_results])); | 453 Symbol &Pattern (exec->sym (args[2+do_match_results])); |
430 ASSERT (Result.typespec().is_int() && Subject.typespec().is_string() && | 454 ASSERT (Result.typespec().is_int() && Subject.typespec().is_string() && |
431 Pattern.typespec().is_string()); | 455 Pattern.typespec().is_string()); |
432 ASSERT (!do_match_results ||· | 456 ASSERT (!do_match_results ||· |
433 (Match.typespec().is_array() && | 457 (Match.typespec().is_array() && |
434 Match.typespec().elementtype().is_int())); | 458 Match.typespec().elementtype().is_int())); |
435 | 459 |
436 OpImpl impl = NULL; | 460 OpImpl impl = NULL; |
437 if (do_match_results) | 461 if (do_match_results) |
438 impl = regex_search_specialized<false, true>; | 462 impl = regex_search_specialized<false, true>; |
439 else | 463 else |
440 impl = regex_search_specialized<false, false>; | 464 impl = regex_search_specialized<false, false>; |
441 impl (exec, nargs, args, runflags, beginpoint, endpoint); | 465 impl (exec, nargs, args); |
442 // Use the specialized one for next time! Never have to check the | 466 // Use the specialized one for next time! Never have to check the |
443 // types or do the other sanity checks again. | 467 // types or do the other sanity checks again. |
444 // FIXME -- is this thread-safe? | 468 // FIXME -- is this thread-safe? |
445 exec->op().implementation (impl); | 469 exec->op().implementation (impl); |
446 } | 470 } |
447 | 471 |
448 | 472 |
449 | 473 |
450 DECLOP (OP_regex_match) | 474 DECLOP (OP_regex_match) |
451 { | 475 { |
452 ASSERT (nargs == 3 || nargs == 4); | 476 ASSERT (nargs == 3 || nargs == 4); |
453 Symbol &Result (exec->sym (args[0])); | 477 Symbol &Result (exec->sym (args[0])); |
454 Symbol &Subject (exec->sym (args[1])); | 478 Symbol &Subject (exec->sym (args[1])); |
455 bool do_match_results = (nargs == 4); | 479 bool do_match_results = (nargs == 4); |
456 Symbol &Match (exec->sym (args[2])); | 480 Symbol &Match (exec->sym (args[2])); |
457 Symbol &Pattern (exec->sym (args[2+do_match_results])); | 481 Symbol &Pattern (exec->sym (args[2+do_match_results])); |
458 ASSERT (Result.typespec().is_int() && Subject.typespec().is_string() && | 482 ASSERT (Result.typespec().is_int() && Subject.typespec().is_string() && |
459 Pattern.typespec().is_string()); | 483 Pattern.typespec().is_string()); |
460 ASSERT (!do_match_results ||· | 484 ASSERT (!do_match_results ||· |
461 (Match.typespec().is_array() && | 485 (Match.typespec().is_array() && |
462 Match.typespec().elementtype().is_int())); | 486 Match.typespec().elementtype().is_int())); |
463 | 487 |
464 OpImpl impl = NULL; | 488 OpImpl impl = NULL; |
465 if (do_match_results) | 489 if (do_match_results) |
466 impl = regex_search_specialized<true, true>; | 490 impl = regex_search_specialized<true, true>; |
467 else | 491 else |
468 impl = regex_search_specialized<true, false>; | 492 impl = regex_search_specialized<true, false>; |
469 impl (exec, nargs, args, runflags, beginpoint, endpoint); | 493 impl (exec, nargs, args); |
470 // Use the specialized one for next time! Never have to check the | 494 // Use the specialized one for next time! Never have to check the |
471 // types or do the other sanity checks again. | 495 // types or do the other sanity checks again. |
472 // FIXME -- is this thread-safe? | 496 // FIXME -- is this thread-safe? |
473 exec->op().implementation (impl); | 497 exec->op().implementation (impl); |
474 } | 498 } |
475 | 499 |
476 | 500 |
477 | 501 |
478 }; // namespace pvt | 502 }; // namespace pvt |
479 }; // namespace OSL | 503 }; // namespace OSL |
480 #ifdef OSL_NAMESPACE | 504 #ifdef OSL_NAMESPACE |
481 }; // end namespace OSL_NAMESPACE | 505 }; // end namespace OSL_NAMESPACE |
482 #endif | 506 #endif |
OLD | NEW |