Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(387)

Side by Side Diff: src/parser.cc

Issue 382893003: Implement basic code generation for arrow functions (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Test failures fixed, some minor corrections Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/parser.h ('k') | src/preparser.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/base/platform/platform.h" 9 #include "src/base/platform/platform.h"
10 #include "src/bootstrapper.h" 10 #include "src/bootstrapper.h"
(...skipping 597 matching lines...) Expand 10 before | Expand all | Expand 10 after
608 return result; 608 return result;
609 } 609 }
610 610
611 611
612 const AstRawString* ParserTraits::GetNextSymbol(Scanner* scanner) { 612 const AstRawString* ParserTraits::GetNextSymbol(Scanner* scanner) {
613 return parser_->scanner()->NextSymbol(parser_->ast_value_factory_); 613 return parser_->scanner()->NextSymbol(parser_->ast_value_factory_);
614 } 614 }
615 615
616 616
617 Expression* ParserTraits::ThisExpression( 617 Expression* ParserTraits::ThisExpression(
618 Scope* scope, 618 Scope* scope, AstNodeFactory<AstConstructionVisitor>* factory, int pos) {
619 AstNodeFactory<AstConstructionVisitor>* factory) { 619 return factory->NewVariableProxy(scope->receiver(), pos);
620 return factory->NewVariableProxy(scope->receiver());
621 } 620 }
622 621
623 622
624 Literal* ParserTraits::ExpressionFromLiteral( 623 Literal* ParserTraits::ExpressionFromLiteral(
625 Token::Value token, int pos, 624 Token::Value token, int pos,
626 Scanner* scanner, 625 Scanner* scanner,
627 AstNodeFactory<AstConstructionVisitor>* factory) { 626 AstNodeFactory<AstConstructionVisitor>* factory) {
628 switch (token) { 627 switch (token) {
629 case Token::NULL_LITERAL: 628 case Token::NULL_LITERAL:
630 return factory->NewNullLiteral(pos); 629 return factory->NewNullLiteral(pos);
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
847 !body->at(0)->AsExpressionStatement()-> 846 !body->at(0)->AsExpressionStatement()->
848 expression()->IsFunctionLiteral()) { 847 expression()->IsFunctionLiteral()) {
849 ReportMessage("single_function_literal"); 848 ReportMessage("single_function_literal");
850 ok = false; 849 ok = false;
851 } 850 }
852 } 851 }
853 852
854 ast_value_factory_->Internalize(isolate()); 853 ast_value_factory_->Internalize(isolate());
855 if (ok) { 854 if (ok) {
856 result = factory()->NewFunctionLiteral( 855 result = factory()->NewFunctionLiteral(
857 ast_value_factory_->empty_string(), 856 ast_value_factory_->empty_string(), ast_value_factory_, scope_, body,
858 ast_value_factory_,
859 scope_,
860 body,
861 function_state.materialized_literal_count(), 857 function_state.materialized_literal_count(),
862 function_state.expected_property_count(), 858 function_state.expected_property_count(),
863 function_state.handler_count(), 859 function_state.handler_count(), 0,
864 0,
865 FunctionLiteral::kNoDuplicateParameters, 860 FunctionLiteral::kNoDuplicateParameters,
866 FunctionLiteral::ANONYMOUS_EXPRESSION, 861 FunctionLiteral::ANONYMOUS_EXPRESSION, FunctionLiteral::kGlobalOrEval,
867 FunctionLiteral::kGlobalOrEval, 862 FunctionLiteral::kNotParenthesized, FunctionLiteral::kNormalFunction,
868 FunctionLiteral::kNotParenthesized,
869 FunctionLiteral::kNotGenerator,
870 0); 863 0);
871 result->set_ast_properties(factory()->visitor()->ast_properties()); 864 result->set_ast_properties(factory()->visitor()->ast_properties());
872 result->set_dont_optimize_reason( 865 result->set_dont_optimize_reason(
873 factory()->visitor()->dont_optimize_reason()); 866 factory()->visitor()->dont_optimize_reason());
874 } else if (stack_overflow()) { 867 } else if (stack_overflow()) {
875 isolate()->StackOverflow(); 868 isolate()->StackOverflow();
876 } else { 869 } else {
877 ThrowPendingError(); 870 ThrowPendingError();
878 } 871 }
879 } 872 }
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
949 FunctionState function_state(&function_state_, &scope_, scope, zone(), 942 FunctionState function_state(&function_state_, &scope_, scope, zone(),
950 ast_value_factory_); 943 ast_value_factory_);
951 ASSERT(scope->strict_mode() == SLOPPY || info()->strict_mode() == STRICT); 944 ASSERT(scope->strict_mode() == SLOPPY || info()->strict_mode() == STRICT);
952 ASSERT(info()->strict_mode() == shared_info->strict_mode()); 945 ASSERT(info()->strict_mode() == shared_info->strict_mode());
953 scope->SetStrictMode(shared_info->strict_mode()); 946 scope->SetStrictMode(shared_info->strict_mode());
954 FunctionLiteral::FunctionType function_type = shared_info->is_expression() 947 FunctionLiteral::FunctionType function_type = shared_info->is_expression()
955 ? (shared_info->is_anonymous() 948 ? (shared_info->is_anonymous()
956 ? FunctionLiteral::ANONYMOUS_EXPRESSION 949 ? FunctionLiteral::ANONYMOUS_EXPRESSION
957 : FunctionLiteral::NAMED_EXPRESSION) 950 : FunctionLiteral::NAMED_EXPRESSION)
958 : FunctionLiteral::DECLARATION; 951 : FunctionLiteral::DECLARATION;
952 bool is_generator = shared_info->is_generator();
959 bool ok = true; 953 bool ok = true;
960 result = ParseFunctionLiteral(raw_name, 954
961 Scanner::Location::invalid(), 955 if (shared_info->is_arrow()) {
962 false, // Strict mode name already checked. 956 ASSERT(!is_generator);
963 shared_info->is_generator(), 957 Expression* expression = ParseExpression(false, &ok);
964 RelocInfo::kNoPosition, 958 ASSERT(expression->IsFunctionLiteral());
965 function_type, 959 result = expression->AsFunctionLiteral();
966 FunctionLiteral::NORMAL_ARITY, 960 } else {
967 &ok); 961 result = ParseFunctionLiteral(raw_name, Scanner::Location::invalid(),
962 false, // Strict mode name already checked.
963 is_generator, RelocInfo::kNoPosition,
964 function_type,
965 FunctionLiteral::NORMAL_ARITY, &ok);
966 }
968 // Make sure the results agree. 967 // Make sure the results agree.
969 ASSERT(ok == (result != NULL)); 968 ASSERT(ok == (result != NULL));
970 } 969 }
971 970
972 // Make sure the target stack is empty. 971 // Make sure the target stack is empty.
973 ASSERT(target_stack_ == NULL); 972 ASSERT(target_stack_ == NULL);
974 973
975 ast_value_factory_->Internalize(isolate()); 974 ast_value_factory_->Internalize(isolate());
976 if (result == NULL) { 975 if (result == NULL) {
977 if (stack_overflow()) { 976 if (stack_overflow()) {
(...skipping 2592 matching lines...) Expand 10 before | Expand all | Expand 10 after
3570 CHECK_OK); 3569 CHECK_OK);
3571 } 3570 }
3572 ast_properties = *factory()->visitor()->ast_properties(); 3571 ast_properties = *factory()->visitor()->ast_properties();
3573 dont_optimize_reason = factory()->visitor()->dont_optimize_reason(); 3572 dont_optimize_reason = factory()->visitor()->dont_optimize_reason();
3574 3573
3575 if (allow_harmony_scoping() && strict_mode() == STRICT) { 3574 if (allow_harmony_scoping() && strict_mode() == STRICT) {
3576 CheckConflictingVarDeclarations(scope, CHECK_OK); 3575 CheckConflictingVarDeclarations(scope, CHECK_OK);
3577 } 3576 }
3578 } 3577 }
3579 3578
3580 FunctionLiteral::IsGeneratorFlag generator = is_generator 3579 FunctionLiteral::KindFlag kind = is_generator
3581 ? FunctionLiteral::kIsGenerator 3580 ? FunctionLiteral::kGeneratorFunction
3582 : FunctionLiteral::kNotGenerator; 3581 : FunctionLiteral::kNormalFunction;
3583 FunctionLiteral* function_literal = 3582 FunctionLiteral* function_literal = factory()->NewFunctionLiteral(
3584 factory()->NewFunctionLiteral(function_name, 3583 function_name, ast_value_factory_, scope, body,
3585 ast_value_factory_, 3584 materialized_literal_count, expected_property_count, handler_count,
3586 scope, 3585 num_parameters, duplicate_parameters, function_type,
3587 body, 3586 FunctionLiteral::kIsFunction, parenthesized, kind, pos);
3588 materialized_literal_count,
3589 expected_property_count,
3590 handler_count,
3591 num_parameters,
3592 duplicate_parameters,
3593 function_type,
3594 FunctionLiteral::kIsFunction,
3595 parenthesized,
3596 generator,
3597 pos);
3598 function_literal->set_function_token_position(function_token_pos); 3587 function_literal->set_function_token_position(function_token_pos);
3599 function_literal->set_ast_properties(&ast_properties); 3588 function_literal->set_ast_properties(&ast_properties);
3600 function_literal->set_dont_optimize_reason(dont_optimize_reason); 3589 function_literal->set_dont_optimize_reason(dont_optimize_reason);
3601 3590
3602 if (fni_ != NULL && should_infer_name) fni_->AddFunction(function_literal); 3591 if (fni_ != NULL && should_infer_name) fni_->AddFunction(function_literal);
3603 return function_literal; 3592 return function_literal;
3604 } 3593 }
3605 3594
3606 3595
3607 void Parser::SkipLazyFunctionBody(const AstRawString* function_name, 3596 void Parser::SkipLazyFunctionBody(const AstRawString* function_name,
(...skipping 1200 matching lines...) Expand 10 before | Expand all | Expand 10 after
4808 info()->SetAstValueFactory(ast_value_factory_); 4797 info()->SetAstValueFactory(ast_value_factory_);
4809 } 4798 }
4810 ast_value_factory_ = NULL; 4799 ast_value_factory_ = NULL;
4811 4800
4812 InternalizeUseCounts(); 4801 InternalizeUseCounts();
4813 4802
4814 return (result != NULL); 4803 return (result != NULL);
4815 } 4804 }
4816 4805
4817 } } // namespace v8::internal 4806 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/parser.h ('k') | src/preparser.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698