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

Side by Side Diff: src/parser.cc

Issue 156423005: Move ParseRegexpLiteral to ParserBase. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Code review (ulan) Created 6 years, 10 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 // 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 533 matching lines...) Expand 10 before | Expand all | Expand 10 after
544 544
545 545
546 bool ParserTraits::IsEvalOrArguments(Handle<String> identifier) const { 546 bool ParserTraits::IsEvalOrArguments(Handle<String> identifier) const {
547 return identifier.is_identical_to( 547 return identifier.is_identical_to(
548 parser_->isolate()->factory()->eval_string()) || 548 parser_->isolate()->factory()->eval_string()) ||
549 identifier.is_identical_to( 549 identifier.is_identical_to(
550 parser_->isolate()->factory()->arguments_string()); 550 parser_->isolate()->factory()->arguments_string());
551 } 551 }
552 552
553 553
554 int ParserTraits::NextMaterializedLiteralIndex() {
555 return parser_->current_function_state_->NextMaterializedLiteralIndex();
556 }
557
558
554 void ParserTraits::ReportMessageAt(Scanner::Location source_location, 559 void ParserTraits::ReportMessageAt(Scanner::Location source_location,
555 const char* message, 560 const char* message,
556 Vector<const char*> args) { 561 Vector<const char*> args) {
557 MessageLocation location(parser_->script_, 562 MessageLocation location(parser_->script_,
558 source_location.beg_pos, 563 source_location.beg_pos,
559 source_location.end_pos); 564 source_location.end_pos);
560 Factory* factory = parser_->isolate()->factory(); 565 Factory* factory = parser_->isolate()->factory();
561 Handle<FixedArray> elements = factory->NewFixedArray(args.length()); 566 Handle<FixedArray> elements = factory->NewFixedArray(args.length());
562 for (int i = 0; i < args.length(); i++) { 567 for (int i = 0; i < args.length(); i++) {
563 Handle<String> arg_string = factory->NewStringFromUtf8(CStrVector(args[i])); 568 Handle<String> arg_string = factory->NewStringFromUtf8(CStrVector(args[i]));
(...skipping 30 matching lines...) Expand all
594 599
595 600
596 Handle<String> ParserTraits::GetSymbol() { 601 Handle<String> ParserTraits::GetSymbol() {
597 int symbol_id = -1; 602 int symbol_id = -1;
598 if (parser_->pre_parse_data() != NULL) { 603 if (parser_->pre_parse_data() != NULL) {
599 symbol_id = parser_->pre_parse_data()->GetSymbolIdentifier(); 604 symbol_id = parser_->pre_parse_data()->GetSymbolIdentifier();
600 } 605 }
601 return parser_->LookupSymbol(symbol_id); 606 return parser_->LookupSymbol(symbol_id);
602 } 607 }
603 608
609
610 Handle<String> ParserTraits::NextLiteralString(PretenureFlag tenured) {
611 Scanner& scanner = parser_->scanner();
612 if (scanner.is_next_literal_ascii()) {
613 return parser_->isolate_->factory()->NewStringFromAscii(
614 scanner.next_literal_ascii_string(), tenured);
615 } else {
616 return parser_->isolate_->factory()->NewStringFromTwoByte(
617 scanner.next_literal_utf16_string(), tenured);
618 }
619 }
620
621
622 Expression* ParserTraits::NewRegExpLiteral(Handle<String> js_pattern,
623 Handle<String> js_flags,
624 int literal_index,
625 int pos) {
626 return parser_->factory()->NewRegExpLiteral(
627 js_pattern, js_flags, literal_index, pos);
628 }
629
604 Parser::Parser(CompilationInfo* info) 630 Parser::Parser(CompilationInfo* info)
605 : ParserBase<ParserTraits>(&scanner_, 631 : ParserBase<ParserTraits>(&scanner_,
606 info->isolate()->stack_guard()->real_climit(), 632 info->isolate()->stack_guard()->real_climit(),
607 this), 633 this),
608 isolate_(info->isolate()), 634 isolate_(info->isolate()),
609 symbol_cache_(0, info->zone()), 635 symbol_cache_(0, info->zone()),
610 script_(info->script()), 636 script_(info->script()),
611 scanner_(isolate_->unicode_cache()), 637 scanner_(isolate_->unicode_cache()),
612 reusable_preparser_(NULL), 638 reusable_preparser_(NULL),
613 top_scope_(NULL), 639 top_scope_(NULL),
(...skipping 3213 matching lines...) Expand 10 before | Expand all | Expand 10 after
3827 int literal_index = current_function_state_->NextMaterializedLiteralIndex(); 3853 int literal_index = current_function_state_->NextMaterializedLiteralIndex();
3828 3854
3829 return factory()->NewObjectLiteral(properties, 3855 return factory()->NewObjectLiteral(properties,
3830 literal_index, 3856 literal_index,
3831 number_of_boilerplate_properties, 3857 number_of_boilerplate_properties,
3832 has_function, 3858 has_function,
3833 pos); 3859 pos);
3834 } 3860 }
3835 3861
3836 3862
3837 Expression* Parser::ParseRegExpLiteral(bool seen_equal, bool* ok) {
3838 int pos = peek_position();
3839 if (!scanner().ScanRegExpPattern(seen_equal)) {
3840 Next();
3841 ReportMessage("unterminated_regexp", Vector<const char*>::empty());
3842 *ok = false;
3843 return NULL;
3844 }
3845
3846 int literal_index = current_function_state_->NextMaterializedLiteralIndex();
3847
3848 Handle<String> js_pattern = NextLiteralString(TENURED);
3849 scanner().ScanRegExpFlags();
3850 Handle<String> js_flags = NextLiteralString(TENURED);
3851 Next();
3852
3853 return factory()->NewRegExpLiteral(js_pattern, js_flags, literal_index, pos);
3854 }
3855
3856
3857 ZoneList<Expression*>* Parser::ParseArguments(bool* ok) { 3863 ZoneList<Expression*>* Parser::ParseArguments(bool* ok) {
3858 // Arguments :: 3864 // Arguments ::
3859 // '(' (AssignmentExpression)*[','] ')' 3865 // '(' (AssignmentExpression)*[','] ')'
3860 3866
3861 ZoneList<Expression*>* result = new(zone()) ZoneList<Expression*>(4, zone()); 3867 ZoneList<Expression*>* result = new(zone()) ZoneList<Expression*>(4, zone());
3862 Expect(Token::LPAREN, CHECK_OK); 3868 Expect(Token::LPAREN, CHECK_OK);
3863 bool done = (peek() == Token::RPAREN); 3869 bool done = (peek() == Token::RPAREN);
3864 while (!done) { 3870 while (!done) {
3865 Expression* argument = ParseAssignmentExpression(true, CHECK_OK); 3871 Expression* argument = ParseAssignmentExpression(true, CHECK_OK);
3866 result->Add(argument, zone()); 3872 result->Add(argument, zone());
(...skipping 1653 matching lines...) Expand 10 before | Expand all | Expand 10 after
5520 ASSERT(info()->isolate()->has_pending_exception()); 5526 ASSERT(info()->isolate()->has_pending_exception());
5521 } else { 5527 } else {
5522 result = ParseProgram(); 5528 result = ParseProgram();
5523 } 5529 }
5524 } 5530 }
5525 info()->SetFunction(result); 5531 info()->SetFunction(result);
5526 return (result != NULL); 5532 return (result != NULL);
5527 } 5533 }
5528 5534
5529 } } // namespace v8::internal 5535 } } // 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