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

Side by Side Diff: src/parser.cc

Issue 12646003: Add parser support for generators. (Closed) Base URL: git://github.com/v8/v8.git@bleeding_edge
Patch Set: Created 7 years, 9 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
« no previous file with comments | « src/parser.h ('k') | src/preparser.h » ('j') | src/preparser.cc » ('J')
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 // 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 3576 matching lines...) Expand 10 before | Expand all | Expand 10 after
3587 Consume(Token::TRUE_LITERAL); 3587 Consume(Token::TRUE_LITERAL);
3588 result = factory()->NewLiteral(isolate()->factory()->true_value()); 3588 result = factory()->NewLiteral(isolate()->factory()->true_value());
3589 break; 3589 break;
3590 3590
3591 case Token::FALSE_LITERAL: 3591 case Token::FALSE_LITERAL:
3592 Consume(Token::FALSE_LITERAL); 3592 Consume(Token::FALSE_LITERAL);
3593 result = factory()->NewLiteral(isolate()->factory()->false_value()); 3593 result = factory()->NewLiteral(isolate()->factory()->false_value());
3594 break; 3594 break;
3595 3595
3596 case Token::IDENTIFIER: 3596 case Token::IDENTIFIER:
3597 case Token::YIELD:
3597 case Token::FUTURE_STRICT_RESERVED_WORD: { 3598 case Token::FUTURE_STRICT_RESERVED_WORD: {
3598 Handle<String> name = ParseIdentifier(CHECK_OK); 3599 Handle<String> name = ParseIdentifier(CHECK_OK);
3599 if (fni_ != NULL) fni_->PushVariableName(name); 3600 if (fni_ != NULL) fni_->PushVariableName(name);
3600 // The name may refer to a module instance object, so its type is unknown. 3601 // The name may refer to a module instance object, so its type is unknown.
3601 #ifdef DEBUG 3602 #ifdef DEBUG
3602 if (FLAG_print_interface_details) 3603 if (FLAG_print_interface_details)
3603 PrintF("# Variable %s ", name->ToAsciiArray()); 3604 PrintF("# Variable %s ", name->ToAsciiArray());
3604 #endif 3605 #endif
3605 Interface* interface = Interface::NewUnknown(zone()); 3606 Interface* interface = Interface::NewUnknown(zone());
3606 result = top_scope_->NewUnresolved( 3607 result = top_scope_->NewUnresolved(
(...skipping 1048 matching lines...) Expand 10 before | Expand all | Expand 10 after
4655 4656
4656 // We have a valid intrinsics call or a call to a builtin. 4657 // We have a valid intrinsics call or a call to a builtin.
4657 return factory()->NewCallRuntime(name, function, args); 4658 return factory()->NewCallRuntime(name, function, args);
4658 } 4659 }
4659 4660
4660 4661
4661 bool Parser::peek_any_identifier() { 4662 bool Parser::peek_any_identifier() {
4662 Token::Value next = peek(); 4663 Token::Value next = peek();
4663 return next == Token::IDENTIFIER || 4664 return next == Token::IDENTIFIER ||
4664 next == Token::FUTURE_RESERVED_WORD || 4665 next == Token::FUTURE_RESERVED_WORD ||
4665 next == Token::FUTURE_STRICT_RESERVED_WORD; 4666 next == Token::FUTURE_STRICT_RESERVED_WORD ||
4667 next == Token::YIELD;
4666 } 4668 }
4667 4669
4668 4670
4669 void Parser::Consume(Token::Value token) { 4671 void Parser::Consume(Token::Value token) {
4670 Token::Value next = Next(); 4672 Token::Value next = Next();
4671 USE(next); 4673 USE(next);
4672 USE(token); 4674 USE(token);
4673 ASSERT(next == token); 4675 ASSERT(next == token);
4674 } 4676 }
4675 4677
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
4730 return factory()->NewLiteral(isolate()->factory()->the_hole_value()); 4732 return factory()->NewLiteral(isolate()->factory()->the_hole_value());
4731 } 4733 }
4732 4734
4733 4735
4734 // Parses an identifier that is valid for the current scope, in particular it 4736 // Parses an identifier that is valid for the current scope, in particular it
4735 // fails on strict mode future reserved keywords in a strict scope. 4737 // fails on strict mode future reserved keywords in a strict scope.
4736 Handle<String> Parser::ParseIdentifier(bool* ok) { 4738 Handle<String> Parser::ParseIdentifier(bool* ok) {
4737 if (!top_scope_->is_classic_mode()) { 4739 if (!top_scope_->is_classic_mode()) {
4738 Expect(Token::IDENTIFIER, ok); 4740 Expect(Token::IDENTIFIER, ok);
4739 } else if (!Check(Token::IDENTIFIER)) { 4741 } else if (!Check(Token::IDENTIFIER)) {
4740 Expect(Token::FUTURE_STRICT_RESERVED_WORD, ok); 4742 if (Check(Token::YIELD))
4743 *ok = !inside_generator();
4744 else
4745 Expect(Token::FUTURE_STRICT_RESERVED_WORD, ok);
4741 } 4746 }
4742 if (!*ok) return Handle<String>(); 4747 if (!*ok) return Handle<String>();
4743 return GetSymbol(ok); 4748 return GetSymbol(ok);
4744 } 4749 }
4745 4750
4746 4751
4747 // Parses and identifier or a strict mode future reserved word, and indicate 4752 // Parses and identifier or a strict mode future reserved word, and indicate
4748 // whether it is strict mode future reserved. 4753 // whether it is strict mode future reserved.
4749 Handle<String> Parser::ParseIdentifierOrStrictReservedWord( 4754 Handle<String> Parser::ParseIdentifierOrStrictReservedWord(
4750 bool* is_strict_reserved, bool* ok) { 4755 bool* is_strict_reserved, bool* ok) {
4751 *is_strict_reserved = false; 4756 *is_strict_reserved = false;
4752 if (!Check(Token::IDENTIFIER)) { 4757 if (!Check(Token::IDENTIFIER)) {
4753 Expect(Token::FUTURE_STRICT_RESERVED_WORD, ok); 4758 if (Check(Token::YIELD)) {
4754 *is_strict_reserved = true; 4759 if (inside_generator())
4760 *ok = false;
4761 else
4762 *is_strict_reserved = true;
4763 } else {
4764 Expect(Token::FUTURE_STRICT_RESERVED_WORD, ok);
4765 *is_strict_reserved = true;
4766 }
4755 } 4767 }
4756 if (!*ok) return Handle<String>(); 4768 if (!*ok) return Handle<String>();
4757 return GetSymbol(ok); 4769 return GetSymbol(ok);
4758 } 4770 }
4759 4771
4760 4772
4761 Handle<String> Parser::ParseIdentifierName(bool* ok) { 4773 Handle<String> Parser::ParseIdentifierName(bool* ok) {
4762 Token::Value next = Next(); 4774 Token::Value next = Next();
4763 if (next != Token::IDENTIFIER && 4775 if (next != Token::IDENTIFIER &&
4764 next != Token::FUTURE_RESERVED_WORD && 4776 next != Token::FUTURE_RESERVED_WORD &&
(...skipping 1167 matching lines...) Expand 10 before | Expand all | Expand 10 after
5932 ASSERT(info->isolate()->has_pending_exception()); 5944 ASSERT(info->isolate()->has_pending_exception());
5933 } else { 5945 } else {
5934 result = parser.ParseProgram(); 5946 result = parser.ParseProgram();
5935 } 5947 }
5936 } 5948 }
5937 info->SetFunction(result); 5949 info->SetFunction(result);
5938 return (result != NULL); 5950 return (result != NULL);
5939 } 5951 }
5940 5952
5941 } } // namespace v8::internal 5953 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/parser.h ('k') | src/preparser.h » ('j') | src/preparser.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698