OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 552 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
563 | 563 |
564 Expression* ParserTraits::ExpressionFromString( | 564 Expression* ParserTraits::ExpressionFromString( |
565 int pos, Scanner* scanner, | 565 int pos, Scanner* scanner, |
566 AstNodeFactory<AstConstructionVisitor>* factory) { | 566 AstNodeFactory<AstConstructionVisitor>* factory) { |
567 Handle<String> symbol = GetSymbol(scanner); | 567 Handle<String> symbol = GetSymbol(scanner); |
568 if (parser_->fni_ != NULL) parser_->fni_->PushLiteralName(symbol); | 568 if (parser_->fni_ != NULL) parser_->fni_->PushLiteralName(symbol); |
569 return factory->NewLiteral(symbol, pos); | 569 return factory->NewLiteral(symbol, pos); |
570 } | 570 } |
571 | 571 |
572 | 572 |
573 Expression* ParserTraits::ParseArrayLiteral(bool* ok) { | 573 Literal* ParserTraits::GetLiteralTheHole( |
574 return parser_->ParseArrayLiteral(ok); | 574 int position, AstNodeFactory<AstConstructionVisitor>* factory) { |
| 575 return factory->NewLiteral(parser_->isolate()->factory()->the_hole_value(), |
| 576 RelocInfo::kNoPosition); |
575 } | 577 } |
576 | 578 |
577 | 579 |
578 Expression* ParserTraits::ParseObjectLiteral(bool* ok) { | 580 Expression* ParserTraits::ParseObjectLiteral(bool* ok) { |
579 return parser_->ParseObjectLiteral(ok); | 581 return parser_->ParseObjectLiteral(ok); |
580 } | 582 } |
581 | 583 |
582 | 584 |
583 Expression* ParserTraits::ParseExpression(bool accept_IN, bool* ok) { | 585 Expression* ParserTraits::ParseAssignmentExpression(bool accept_IN, bool* ok) { |
584 return parser_->ParseExpression(accept_IN, ok); | 586 return parser_->ParseAssignmentExpression(accept_IN, ok); |
585 } | 587 } |
586 | 588 |
587 | 589 |
588 Expression* ParserTraits::ParseV8Intrinsic(bool* ok) { | 590 Expression* ParserTraits::ParseV8Intrinsic(bool* ok) { |
589 return parser_->ParseV8Intrinsic(ok); | 591 return parser_->ParseV8Intrinsic(ok); |
590 } | 592 } |
591 | 593 |
592 | 594 |
593 Parser::Parser(CompilationInfo* info) | 595 Parser::Parser(CompilationInfo* info) |
594 : ParserBase<ParserTraits>(&scanner_, | 596 : ParserBase<ParserTraits>(&scanner_, |
595 info->isolate()->stack_guard()->real_climit(), | 597 info->isolate()->stack_guard()->real_climit(), |
596 info->extension(), | 598 info->extension(), |
| 599 info->zone(), |
597 this), | 600 this), |
598 isolate_(info->isolate()), | 601 isolate_(info->isolate()), |
599 symbol_cache_(0, info->zone()), | 602 symbol_cache_(0, info->zone()), |
600 script_(info->script()), | 603 script_(info->script()), |
601 scanner_(isolate_->unicode_cache()), | 604 scanner_(isolate_->unicode_cache()), |
602 reusable_preparser_(NULL), | 605 reusable_preparser_(NULL), |
603 original_scope_(NULL), | 606 original_scope_(NULL), |
604 target_stack_(NULL), | 607 target_stack_(NULL), |
605 pre_parse_data_(NULL), | 608 pre_parse_data_(NULL), |
606 fni_(NULL), | 609 fni_(NULL), |
607 zone_(info->zone()), | |
608 info_(info) { | 610 info_(info) { |
609 ASSERT(!script_.is_null()); | 611 ASSERT(!script_.is_null()); |
610 isolate_->set_ast_node_id(0); | 612 isolate_->set_ast_node_id(0); |
611 set_allow_harmony_scoping(!info->is_native() && FLAG_harmony_scoping); | 613 set_allow_harmony_scoping(!info->is_native() && FLAG_harmony_scoping); |
612 set_allow_modules(!info->is_native() && FLAG_harmony_modules); | 614 set_allow_modules(!info->is_native() && FLAG_harmony_modules); |
613 set_allow_natives_syntax(FLAG_allow_natives_syntax || info->is_native()); | 615 set_allow_natives_syntax(FLAG_allow_natives_syntax || info->is_native()); |
614 set_allow_lazy(false); // Must be explicitly enabled. | 616 set_allow_lazy(false); // Must be explicitly enabled. |
615 set_allow_generators(FLAG_harmony_generators); | 617 set_allow_generators(FLAG_harmony_generators); |
616 set_allow_for_of(FLAG_harmony_iteration); | 618 set_allow_for_of(FLAG_harmony_iteration); |
617 set_allow_harmony_numeric_literals(FLAG_harmony_numeric_literals); | 619 set_allow_harmony_numeric_literals(FLAG_harmony_numeric_literals); |
(...skipping 2249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2867 result->set_scope(for_scope); | 2869 result->set_scope(for_scope); |
2868 loop->Initialize(NULL, cond, next, body); | 2870 loop->Initialize(NULL, cond, next, body); |
2869 return result; | 2871 return result; |
2870 } else { | 2872 } else { |
2871 loop->Initialize(init, cond, next, body); | 2873 loop->Initialize(init, cond, next, body); |
2872 return loop; | 2874 return loop; |
2873 } | 2875 } |
2874 } | 2876 } |
2875 | 2877 |
2876 | 2878 |
2877 // Precedence = 1 | |
2878 Expression* Parser::ParseExpression(bool accept_IN, bool* ok) { | |
2879 // Expression :: | |
2880 // AssignmentExpression | |
2881 // Expression ',' AssignmentExpression | |
2882 | |
2883 Expression* result = ParseAssignmentExpression(accept_IN, CHECK_OK); | |
2884 while (peek() == Token::COMMA) { | |
2885 Expect(Token::COMMA, CHECK_OK); | |
2886 int pos = position(); | |
2887 Expression* right = ParseAssignmentExpression(accept_IN, CHECK_OK); | |
2888 result = factory()->NewBinaryOperation(Token::COMMA, result, right, pos); | |
2889 } | |
2890 return result; | |
2891 } | |
2892 | |
2893 | |
2894 // Precedence = 2 | 2879 // Precedence = 2 |
2895 Expression* Parser::ParseAssignmentExpression(bool accept_IN, bool* ok) { | 2880 Expression* Parser::ParseAssignmentExpression(bool accept_IN, bool* ok) { |
2896 // AssignmentExpression :: | 2881 // AssignmentExpression :: |
2897 // ConditionalExpression | 2882 // ConditionalExpression |
2898 // YieldExpression | 2883 // YieldExpression |
2899 // LeftHandSideExpression AssignmentOperator AssignmentExpression | 2884 // LeftHandSideExpression AssignmentOperator AssignmentExpression |
2900 | 2885 |
2901 if (peek() == Token::YIELD && is_generator()) { | 2886 if (peek() == Token::YIELD && is_generator()) { |
2902 return ParseYieldExpression(ok); | 2887 return ParseYieldExpression(ok); |
2903 } | 2888 } |
(...skipping 551 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3455 | 3440 |
3456 void Parser::ReportInvalidPreparseData(Handle<String> name, bool* ok) { | 3441 void Parser::ReportInvalidPreparseData(Handle<String> name, bool* ok) { |
3457 SmartArrayPointer<char> name_string = name->ToCString(DISALLOW_NULLS); | 3442 SmartArrayPointer<char> name_string = name->ToCString(DISALLOW_NULLS); |
3458 const char* element[1] = { name_string.get() }; | 3443 const char* element[1] = { name_string.get() }; |
3459 ReportMessage("invalid_preparser_data", | 3444 ReportMessage("invalid_preparser_data", |
3460 Vector<const char*>(element, 1)); | 3445 Vector<const char*>(element, 1)); |
3461 *ok = false; | 3446 *ok = false; |
3462 } | 3447 } |
3463 | 3448 |
3464 | 3449 |
3465 Expression* Parser::ParseArrayLiteral(bool* ok) { | |
3466 // ArrayLiteral :: | |
3467 // '[' Expression? (',' Expression?)* ']' | |
3468 | |
3469 int pos = peek_position(); | |
3470 ZoneList<Expression*>* values = new(zone()) ZoneList<Expression*>(4, zone()); | |
3471 Expect(Token::LBRACK, CHECK_OK); | |
3472 while (peek() != Token::RBRACK) { | |
3473 Expression* elem; | |
3474 if (peek() == Token::COMMA) { | |
3475 elem = GetLiteralTheHole(peek_position()); | |
3476 } else { | |
3477 elem = ParseAssignmentExpression(true, CHECK_OK); | |
3478 } | |
3479 values->Add(elem, zone()); | |
3480 if (peek() != Token::RBRACK) { | |
3481 Expect(Token::COMMA, CHECK_OK); | |
3482 } | |
3483 } | |
3484 Expect(Token::RBRACK, CHECK_OK); | |
3485 | |
3486 // Update the scope information before the pre-parsing bailout. | |
3487 int literal_index = function_state_->NextMaterializedLiteralIndex(); | |
3488 | |
3489 return factory()->NewArrayLiteral(values, literal_index, pos); | |
3490 } | |
3491 | |
3492 | |
3493 bool CompileTimeValue::IsCompileTimeValue(Expression* expression) { | 3450 bool CompileTimeValue::IsCompileTimeValue(Expression* expression) { |
3494 if (expression->AsLiteral() != NULL) return true; | 3451 if (expression->AsLiteral() != NULL) return true; |
3495 MaterializedLiteral* lit = expression->AsMaterializedLiteral(); | 3452 MaterializedLiteral* lit = expression->AsMaterializedLiteral(); |
3496 return lit != NULL && lit->is_simple(); | 3453 return lit != NULL && lit->is_simple(); |
3497 } | 3454 } |
3498 | 3455 |
3499 | 3456 |
3500 Handle<FixedArray> CompileTimeValue::GetValue(Isolate* isolate, | 3457 Handle<FixedArray> CompileTimeValue::GetValue(Isolate* isolate, |
3501 Expression* expression) { | 3458 Expression* expression) { |
3502 Factory* factory = isolate->factory(); | 3459 Factory* factory = isolate->factory(); |
(...skipping 748 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4251 return factory()->NewCallRuntime(name, function, args, pos); | 4208 return factory()->NewCallRuntime(name, function, args, pos); |
4252 } | 4209 } |
4253 | 4210 |
4254 | 4211 |
4255 Literal* Parser::GetLiteralUndefined(int position) { | 4212 Literal* Parser::GetLiteralUndefined(int position) { |
4256 return factory()->NewLiteral( | 4213 return factory()->NewLiteral( |
4257 isolate()->factory()->undefined_value(), position); | 4214 isolate()->factory()->undefined_value(), position); |
4258 } | 4215 } |
4259 | 4216 |
4260 | 4217 |
4261 Literal* Parser::GetLiteralTheHole(int position) { | |
4262 return factory()->NewLiteral( | |
4263 isolate()->factory()->the_hole_value(), RelocInfo::kNoPosition); | |
4264 } | |
4265 | |
4266 | |
4267 void Parser::MarkAsLValue(Expression* expression) { | 4218 void Parser::MarkAsLValue(Expression* expression) { |
4268 VariableProxy* proxy = expression != NULL | 4219 VariableProxy* proxy = expression != NULL |
4269 ? expression->AsVariableProxy() | 4220 ? expression->AsVariableProxy() |
4270 : NULL; | 4221 : NULL; |
4271 | 4222 |
4272 if (proxy != NULL) proxy->MarkAsLValue(); | 4223 if (proxy != NULL) proxy->MarkAsLValue(); |
4273 } | 4224 } |
4274 | 4225 |
4275 | 4226 |
4276 // Checks LHS expression for assignment and prefix/postfix increment/decrement | 4227 // Checks LHS expression for assignment and prefix/postfix increment/decrement |
(...skipping 1088 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5365 ASSERT(info()->isolate()->has_pending_exception()); | 5316 ASSERT(info()->isolate()->has_pending_exception()); |
5366 } else { | 5317 } else { |
5367 result = ParseProgram(); | 5318 result = ParseProgram(); |
5368 } | 5319 } |
5369 } | 5320 } |
5370 info()->SetFunction(result); | 5321 info()->SetFunction(result); |
5371 return (result != NULL); | 5322 return (result != NULL); |
5372 } | 5323 } |
5373 | 5324 |
5374 } } // namespace v8::internal | 5325 } } // namespace v8::internal |
OLD | NEW |