| OLD | NEW |
| 1 // Copyright 2006-2009 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2009 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 4171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4182 else | 4182 else |
| 4183 return empty(); | 4183 return empty(); |
| 4184 } | 4184 } |
| 4185 | 4185 |
| 4186 | 4186 |
| 4187 // ------------------------------------------------------------------- | 4187 // ------------------------------------------------------------------- |
| 4188 // Analysis | 4188 // Analysis |
| 4189 | 4189 |
| 4190 | 4190 |
| 4191 void Analysis::EnsureAnalyzed(RegExpNode* that) { | 4191 void Analysis::EnsureAnalyzed(RegExpNode* that) { |
| 4192 StackLimitCheck check; |
| 4193 if (check.HasOverflowed()) { |
| 4194 fail("Stack overflow"); |
| 4195 return; |
| 4196 } |
| 4192 if (that->info()->been_analyzed || that->info()->being_analyzed) | 4197 if (that->info()->been_analyzed || that->info()->being_analyzed) |
| 4193 return; | 4198 return; |
| 4194 that->info()->being_analyzed = true; | 4199 that->info()->being_analyzed = true; |
| 4195 that->Accept(this); | 4200 that->Accept(this); |
| 4196 that->info()->being_analyzed = false; | 4201 that->info()->being_analyzed = false; |
| 4197 that->info()->been_analyzed = true; | 4202 that->info()->been_analyzed = true; |
| 4198 } | 4203 } |
| 4199 | 4204 |
| 4200 | 4205 |
| 4201 void Analysis::VisitEnd(EndNode* that) { | 4206 void Analysis::VisitEnd(EndNode* that) { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 4219 } | 4224 } |
| 4220 } | 4225 } |
| 4221 } | 4226 } |
| 4222 | 4227 |
| 4223 | 4228 |
| 4224 void Analysis::VisitText(TextNode* that) { | 4229 void Analysis::VisitText(TextNode* that) { |
| 4225 if (ignore_case_) { | 4230 if (ignore_case_) { |
| 4226 that->MakeCaseIndependent(); | 4231 that->MakeCaseIndependent(); |
| 4227 } | 4232 } |
| 4228 EnsureAnalyzed(that->on_success()); | 4233 EnsureAnalyzed(that->on_success()); |
| 4229 that->CalculateOffsets(); | 4234 if (!failed()) { |
| 4235 that->CalculateOffsets(); |
| 4236 } |
| 4230 } | 4237 } |
| 4231 | 4238 |
| 4232 | 4239 |
| 4233 void Analysis::VisitAction(ActionNode* that) { | 4240 void Analysis::VisitAction(ActionNode* that) { |
| 4234 RegExpNode* target = that->on_success(); | 4241 RegExpNode* target = that->on_success(); |
| 4235 EnsureAnalyzed(target); | 4242 EnsureAnalyzed(target); |
| 4236 // If the next node is interested in what it follows then this node | 4243 if (!failed()) { |
| 4237 // has to be interested too so it can pass the information on. | 4244 // If the next node is interested in what it follows then this node |
| 4238 that->info()->AddFromFollowing(target->info()); | 4245 // has to be interested too so it can pass the information on. |
| 4246 that->info()->AddFromFollowing(target->info()); |
| 4247 } |
| 4239 } | 4248 } |
| 4240 | 4249 |
| 4241 | 4250 |
| 4242 void Analysis::VisitChoice(ChoiceNode* that) { | 4251 void Analysis::VisitChoice(ChoiceNode* that) { |
| 4243 NodeInfo* info = that->info(); | 4252 NodeInfo* info = that->info(); |
| 4244 for (int i = 0; i < that->alternatives()->length(); i++) { | 4253 for (int i = 0; i < that->alternatives()->length(); i++) { |
| 4245 RegExpNode* node = that->alternatives()->at(i).node(); | 4254 RegExpNode* node = that->alternatives()->at(i).node(); |
| 4246 EnsureAnalyzed(node); | 4255 EnsureAnalyzed(node); |
| 4256 if (failed()) return; |
| 4247 // Anything the following nodes need to know has to be known by | 4257 // Anything the following nodes need to know has to be known by |
| 4248 // this node also, so it can pass it on. | 4258 // this node also, so it can pass it on. |
| 4249 info->AddFromFollowing(node->info()); | 4259 info->AddFromFollowing(node->info()); |
| 4250 } | 4260 } |
| 4251 } | 4261 } |
| 4252 | 4262 |
| 4253 | 4263 |
| 4254 void Analysis::VisitLoopChoice(LoopChoiceNode* that) { | 4264 void Analysis::VisitLoopChoice(LoopChoiceNode* that) { |
| 4255 NodeInfo* info = that->info(); | 4265 NodeInfo* info = that->info(); |
| 4256 for (int i = 0; i < that->alternatives()->length(); i++) { | 4266 for (int i = 0; i < that->alternatives()->length(); i++) { |
| 4257 RegExpNode* node = that->alternatives()->at(i).node(); | 4267 RegExpNode* node = that->alternatives()->at(i).node(); |
| 4258 if (node != that->loop_node()) { | 4268 if (node != that->loop_node()) { |
| 4259 EnsureAnalyzed(node); | 4269 EnsureAnalyzed(node); |
| 4270 if (failed()) return; |
| 4260 info->AddFromFollowing(node->info()); | 4271 info->AddFromFollowing(node->info()); |
| 4261 } | 4272 } |
| 4262 } | 4273 } |
| 4263 // Check the loop last since it may need the value of this node | 4274 // Check the loop last since it may need the value of this node |
| 4264 // to get a correct result. | 4275 // to get a correct result. |
| 4265 EnsureAnalyzed(that->loop_node()); | 4276 EnsureAnalyzed(that->loop_node()); |
| 4266 info->AddFromFollowing(that->loop_node()->info()); | 4277 if (!failed()) { |
| 4278 info->AddFromFollowing(that->loop_node()->info()); |
| 4279 } |
| 4267 } | 4280 } |
| 4268 | 4281 |
| 4269 | 4282 |
| 4270 void Analysis::VisitBackReference(BackReferenceNode* that) { | 4283 void Analysis::VisitBackReference(BackReferenceNode* that) { |
| 4271 EnsureAnalyzed(that->on_success()); | 4284 EnsureAnalyzed(that->on_success()); |
| 4272 } | 4285 } |
| 4273 | 4286 |
| 4274 | 4287 |
| 4275 void Analysis::VisitAssertion(AssertionNode* that) { | 4288 void Analysis::VisitAssertion(AssertionNode* that) { |
| 4276 EnsureAnalyzed(that->on_success()); | 4289 EnsureAnalyzed(that->on_success()); |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4428 first_step_node->AddAlternative(GuardedAlternative( | 4441 first_step_node->AddAlternative(GuardedAlternative( |
| 4429 new TextNode(new RegExpCharacterClass('*'), loop_node))); | 4442 new TextNode(new RegExpCharacterClass('*'), loop_node))); |
| 4430 node = first_step_node; | 4443 node = first_step_node; |
| 4431 } else { | 4444 } else { |
| 4432 node = loop_node; | 4445 node = loop_node; |
| 4433 } | 4446 } |
| 4434 } | 4447 } |
| 4435 data->node = node; | 4448 data->node = node; |
| 4436 Analysis analysis(ignore_case); | 4449 Analysis analysis(ignore_case); |
| 4437 analysis.EnsureAnalyzed(node); | 4450 analysis.EnsureAnalyzed(node); |
| 4451 if (analysis.failed()) { |
| 4452 const char* error_message = analysis.error_message(); |
| 4453 return CompilationResult(error_message); |
| 4454 } |
| 4438 | 4455 |
| 4439 NodeInfo info = *node->info(); | 4456 NodeInfo info = *node->info(); |
| 4440 | 4457 |
| 4441 if (RegExpImpl::UseNativeRegexp()) { | 4458 if (RegExpImpl::UseNativeRegexp()) { |
| 4442 #ifdef V8_TARGET_ARCH_ARM | 4459 #ifdef V8_TARGET_ARCH_ARM |
| 4443 UNREACHABLE(); | 4460 UNREACHABLE(); |
| 4444 #endif | 4461 #endif |
| 4445 #ifdef V8_TARGET_ARCH_X64 | 4462 #ifdef V8_TARGET_ARCH_X64 |
| 4446 UNREACHABLE(); | 4463 UNREACHABLE(); |
| 4447 #endif | 4464 #endif |
| (...skipping 15 matching lines...) Expand all Loading... |
| 4463 EmbeddedVector<byte, 1024> codes; | 4480 EmbeddedVector<byte, 1024> codes; |
| 4464 RegExpMacroAssemblerIrregexp macro_assembler(codes); | 4481 RegExpMacroAssemblerIrregexp macro_assembler(codes); |
| 4465 return compiler.Assemble(¯o_assembler, | 4482 return compiler.Assemble(¯o_assembler, |
| 4466 node, | 4483 node, |
| 4467 data->capture_count, | 4484 data->capture_count, |
| 4468 pattern); | 4485 pattern); |
| 4469 } | 4486 } |
| 4470 | 4487 |
| 4471 | 4488 |
| 4472 }} // namespace v8::internal | 4489 }} // namespace v8::internal |
| OLD | NEW |