| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "src/v8.h" | 5 #include "src/v8.h" |
| 6 | 6 |
| 7 #include "src/api.h" | 7 #include "src/api.h" |
| 8 #include "src/ast.h" | 8 #include "src/ast.h" |
| 9 #include "src/bailout-reason.h" | 9 #include "src/bailout-reason.h" |
| 10 #include "src/base/platform/platform.h" | 10 #include "src/base/platform/platform.h" |
| (...skipping 5460 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5471 TemplateLiteral* lit = *state; | 5471 TemplateLiteral* lit = *state; |
| 5472 int pos = lit->position(); | 5472 int pos = lit->position(); |
| 5473 const ZoneList<Expression*>* cooked_strings = lit->cooked(); | 5473 const ZoneList<Expression*>* cooked_strings = lit->cooked(); |
| 5474 const ZoneList<Expression*>* raw_strings = lit->raw(); | 5474 const ZoneList<Expression*>* raw_strings = lit->raw(); |
| 5475 const ZoneList<Expression*>* expressions = lit->expressions(); | 5475 const ZoneList<Expression*>* expressions = lit->expressions(); |
| 5476 DCHECK_EQ(cooked_strings->length(), raw_strings->length()); | 5476 DCHECK_EQ(cooked_strings->length(), raw_strings->length()); |
| 5477 DCHECK_EQ(cooked_strings->length(), expressions->length() + 1); | 5477 DCHECK_EQ(cooked_strings->length(), expressions->length() + 1); |
| 5478 | 5478 |
| 5479 if (!tag) { | 5479 if (!tag) { |
| 5480 // Build tree of BinaryOps to simplify code-generation | 5480 // Build tree of BinaryOps to simplify code-generation |
| 5481 Expression* expr = NULL; | 5481 Expression* expr = cooked_strings->at(0); |
| 5482 int i = 0; |
| 5483 while (i < expressions->length()) { |
| 5484 Expression* sub = expressions->at(i++); |
| 5485 Expression* cooked_str = cooked_strings->at(i); |
| 5482 | 5486 |
| 5483 if (expressions->length() == 0) { | 5487 // Let middle be ToString(sub). |
| 5484 // Simple case: treat as string literal | 5488 ZoneList<Expression*>* args = |
| 5485 expr = cooked_strings->at(0); | 5489 new (zone()) ZoneList<Expression*>(1, zone()); |
| 5486 } else { | 5490 args->Add(sub, zone()); |
| 5487 int i; | 5491 Expression* middle = factory()->NewCallRuntime( |
| 5488 Expression* cooked_str = cooked_strings->at(0); | 5492 ast_value_factory()->to_string_string(), NULL, args, |
| 5493 sub->position()); |
| 5494 |
| 5489 expr = factory()->NewBinaryOperation( | 5495 expr = factory()->NewBinaryOperation( |
| 5490 Token::ADD, cooked_str, expressions->at(0), cooked_str->position()); | 5496 Token::ADD, factory()->NewBinaryOperation( |
| 5491 for (i = 1; i < expressions->length(); ++i) { | 5497 Token::ADD, expr, middle, expr->position()), |
| 5492 cooked_str = cooked_strings->at(i); | 5498 cooked_str, sub->position()); |
| 5493 expr = factory()->NewBinaryOperation( | |
| 5494 Token::ADD, expr, factory()->NewBinaryOperation( | |
| 5495 Token::ADD, cooked_str, expressions->at(i), | |
| 5496 cooked_str->position()), | |
| 5497 cooked_str->position()); | |
| 5498 } | |
| 5499 cooked_str = cooked_strings->at(i); | |
| 5500 expr = factory()->NewBinaryOperation(Token::ADD, expr, cooked_str, | |
| 5501 cooked_str->position()); | |
| 5502 } | 5499 } |
| 5503 return expr; | 5500 return expr; |
| 5504 } else { | 5501 } else { |
| 5505 uint32_t hash = ComputeTemplateLiteralHash(lit); | 5502 uint32_t hash = ComputeTemplateLiteralHash(lit); |
| 5506 | 5503 |
| 5507 int cooked_idx = function_state_->NextMaterializedLiteralIndex(); | 5504 int cooked_idx = function_state_->NextMaterializedLiteralIndex(); |
| 5508 int raw_idx = function_state_->NextMaterializedLiteralIndex(); | 5505 int raw_idx = function_state_->NextMaterializedLiteralIndex(); |
| 5509 | 5506 |
| 5510 // GetTemplateCallSite | 5507 // GetTemplateCallSite |
| 5511 ZoneList<Expression*>* args = new (zone()) ZoneList<Expression*>(4, zone()); | 5508 ZoneList<Expression*>* args = new (zone()) ZoneList<Expression*>(4, zone()); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5558 } else { | 5555 } else { |
| 5559 const uc16* data = reinterpret_cast<const uc16*>(raw_string->raw_data()); | 5556 const uc16* data = reinterpret_cast<const uc16*>(raw_string->raw_data()); |
| 5560 running_hash = StringHasher::ComputeRunningHash(running_hash, data, | 5557 running_hash = StringHasher::ComputeRunningHash(running_hash, data, |
| 5561 raw_string->length()); | 5558 raw_string->length()); |
| 5562 } | 5559 } |
| 5563 } | 5560 } |
| 5564 | 5561 |
| 5565 return running_hash; | 5562 return running_hash; |
| 5566 } | 5563 } |
| 5567 } } // namespace v8::internal | 5564 } } // namespace v8::internal |
| OLD | NEW |