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

Side by Side Diff: src/parser.cc

Issue 918203002: Get rid of PreParserIdentifier. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: . Created 5 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
« 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/bailout-reason.h" 9 #include "src/bailout-reason.h"
10 #include "src/base/platform/platform.h" 10 #include "src/base/platform/platform.h"
(...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 385
386 #define CHECK_FAILED /**/); \ 386 #define CHECK_FAILED /**/); \
387 if (failed_) return NULL; \ 387 if (failed_) return NULL; \
388 ((void)0 388 ((void)0
389 #define DUMMY ) // to make indentation work 389 #define DUMMY ) // to make indentation work
390 #undef DUMMY 390 #undef DUMMY
391 391
392 // ---------------------------------------------------------------------------- 392 // ----------------------------------------------------------------------------
393 // Implementation of Parser 393 // Implementation of Parser
394 394
395 bool ParserTraits::IsEvalOrArguments(const AstRawString* identifier) const {
396 return identifier == parser_->ast_value_factory()->eval_string() ||
397 identifier == parser_->ast_value_factory()->arguments_string();
398 }
399
400
401 bool ParserTraits::IsPrototype(const AstRawString* identifier) const {
402 return identifier == parser_->ast_value_factory()->prototype_string();
403 }
404
405
406 bool ParserTraits::IsConstructor(const AstRawString* identifier) const {
407 return identifier == parser_->ast_value_factory()->constructor_string();
408 }
409
410
411 bool ParserTraits::IsThisProperty(Expression* expression) { 395 bool ParserTraits::IsThisProperty(Expression* expression) {
412 DCHECK(expression != NULL); 396 DCHECK(expression != NULL);
413 Property* property = expression->AsProperty(); 397 Property* property = expression->AsProperty();
414 return property != NULL && property->obj()->IsVariableProxy() && 398 return property != NULL && property->obj()->IsVariableProxy() &&
415 property->obj()->AsVariableProxy()->is_this(); 399 property->obj()->AsVariableProxy()->is_this();
416 } 400 }
417 401
418 402
419 bool ParserTraits::IsIdentifier(Expression* expression) { 403 bool ParserTraits::IsIdentifier(Expression* expression) {
420 VariableProxy* operand = expression->AsVariableProxy(); 404 VariableProxy* operand = expression->AsVariableProxy();
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
647 } 631 }
648 parser_->has_pending_error_ = true; 632 parser_->has_pending_error_ = true;
649 parser_->pending_error_location_ = source_location; 633 parser_->pending_error_location_ = source_location;
650 parser_->pending_error_message_ = message; 634 parser_->pending_error_message_ = message;
651 parser_->pending_error_char_arg_ = NULL; 635 parser_->pending_error_char_arg_ = NULL;
652 parser_->pending_error_arg_ = arg; 636 parser_->pending_error_arg_ = arg;
653 parser_->pending_error_is_reference_error_ = is_reference_error; 637 parser_->pending_error_is_reference_error_ = is_reference_error;
654 } 638 }
655 639
656 640
657 const AstRawString* ParserTraits::GetSymbol(Scanner* scanner) {
658 const AstRawString* result =
659 parser_->scanner()->CurrentSymbol(parser_->ast_value_factory());
660 DCHECK(result != NULL);
661 return result;
662 }
663
664
665 const AstRawString* ParserTraits::GetNumberAsSymbol(Scanner* scanner) {
666 double double_value = parser_->scanner()->DoubleValue();
667 char array[100];
668 const char* string =
669 DoubleToCString(double_value, Vector<char>(array, arraysize(array)));
670 return parser_->ast_value_factory()->GetOneByteString(string);
671 }
672
673
674 const AstRawString* ParserTraits::GetNextSymbol(Scanner* scanner) {
675 return parser_->scanner()->NextSymbol(parser_->ast_value_factory());
676 }
677
678
679 Expression* ParserTraits::ThisExpression(Scope* scope, AstNodeFactory* factory, 641 Expression* ParserTraits::ThisExpression(Scope* scope, AstNodeFactory* factory,
680 int pos) { 642 int pos) {
681 return factory->NewVariableProxy(scope->receiver(), pos); 643 return factory->NewVariableProxy(scope->receiver(), pos);
682 } 644 }
683 645
684 Expression* ParserTraits::SuperReference(Scope* scope, AstNodeFactory* factory, 646 Expression* ParserTraits::SuperReference(Scope* scope, AstNodeFactory* factory,
685 int pos) { 647 int pos) {
686 return factory->NewSuperReference( 648 return factory->NewSuperReference(
687 ThisExpression(scope, factory, pos)->AsVariableProxy(), 649 ThisExpression(scope, factory, pos)->AsVariableProxy(),
688 pos); 650 pos);
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
732 // for Traits::DeclareArrowParametersFromExpression() to be able to 694 // for Traits::DeclareArrowParametersFromExpression() to be able to
733 // pick the names of the parameters. 695 // pick the names of the parameters.
734 return parser_->parsing_lazy_arrow_parameters_ 696 return parser_->parsing_lazy_arrow_parameters_
735 ? factory->NewVariableProxy(name, false, interface, pos) 697 ? factory->NewVariableProxy(name, false, interface, pos)
736 : scope->NewUnresolved(factory, name, interface, pos); 698 : scope->NewUnresolved(factory, name, interface, pos);
737 } 699 }
738 700
739 701
740 Expression* ParserTraits::ExpressionFromString(int pos, Scanner* scanner, 702 Expression* ParserTraits::ExpressionFromString(int pos, Scanner* scanner,
741 AstNodeFactory* factory) { 703 AstNodeFactory* factory) {
742 const AstRawString* symbol = GetSymbol(scanner); 704 const AstRawString* symbol = parser_->GetSymbol(scanner);
743 if (parser_->fni_ != NULL) parser_->fni_->PushLiteralName(symbol); 705 if (parser_->fni_ != NULL) parser_->fni_->PushLiteralName(symbol);
744 return factory->NewStringLiteral(symbol, pos); 706 return factory->NewStringLiteral(symbol, pos);
745 } 707 }
746 708
747 709
748 Expression* ParserTraits::GetIterator(Expression* iterable, 710 Expression* ParserTraits::GetIterator(Expression* iterable,
749 AstNodeFactory* factory) { 711 AstNodeFactory* factory) {
750 Expression* iterator_symbol_literal = 712 Expression* iterator_symbol_literal =
751 factory->NewSymbolLiteral("iterator_symbol", RelocInfo::kNoPosition); 713 factory->NewSymbolLiteral("iterator_symbol", RelocInfo::kNoPosition);
752 int pos = iterable->position(); 714 int pos = iterable->position();
(...skipping 2742 matching lines...) Expand 10 before | Expand all | Expand 10 after
3495 Smi* literal_type = Smi::cast(value->get(kLiteralTypeSlot)); 3457 Smi* literal_type = Smi::cast(value->get(kLiteralTypeSlot));
3496 return static_cast<LiteralType>(literal_type->value()); 3458 return static_cast<LiteralType>(literal_type->value());
3497 } 3459 }
3498 3460
3499 3461
3500 Handle<FixedArray> CompileTimeValue::GetElements(Handle<FixedArray> value) { 3462 Handle<FixedArray> CompileTimeValue::GetElements(Handle<FixedArray> value) {
3501 return Handle<FixedArray>(FixedArray::cast(value->get(kElementsSlot))); 3463 return Handle<FixedArray>(FixedArray::cast(value->get(kElementsSlot)));
3502 } 3464 }
3503 3465
3504 3466
3505 bool CheckAndDeclareArrowParameter(ParserTraits* traits, Expression* expression, 3467 bool CheckAndDeclareArrowParameter(AstValueFactory* ast_value_factory,
3468 Scanner* scanner, Expression* expression,
3506 Scope* scope, int* num_params, 3469 Scope* scope, int* num_params,
3507 Scanner::Location* dupe_loc) { 3470 Scanner::Location* dupe_loc) {
3508 // Case for empty parameter lists: 3471 // Case for empty parameter lists:
3509 // () => ... 3472 // () => ...
3510 if (expression == NULL) return true; 3473 if (expression == NULL) return true;
3511 3474
3512 // Too many parentheses around expression: 3475 // Too many parentheses around expression:
3513 // (( ... )) => ... 3476 // (( ... )) => ...
3514 if (expression->is_multi_parenthesized()) return false; 3477 if (expression->is_multi_parenthesized()) return false;
3515 3478
3516 // Case for a single parameter: 3479 // Case for a single parameter:
3517 // (foo) => ... 3480 // (foo) => ...
3518 // foo => ... 3481 // foo => ...
3519 if (expression->IsVariableProxy()) { 3482 if (expression->IsVariableProxy()) {
3520 if (expression->AsVariableProxy()->is_this()) return false; 3483 if (expression->AsVariableProxy()->is_this()) return false;
3521 3484
3522 const AstRawString* raw_name = expression->AsVariableProxy()->raw_name(); 3485 const AstRawString* raw_name = expression->AsVariableProxy()->raw_name();
3523 if (traits->IsEvalOrArguments(raw_name) || 3486 if (raw_name == ast_value_factory->eval_string() ||
3524 traits->IsFutureStrictReserved(raw_name)) 3487 raw_name == ast_value_factory->arguments_string() ||
3488 scanner->IdentifierIsFutureStrictReserved(raw_name))
3525 return false; 3489 return false;
3526 3490
3527 if (scope->IsDeclared(raw_name)) { 3491 if (scope->IsDeclared(raw_name)) {
3528 *dupe_loc = Scanner::Location( 3492 *dupe_loc = Scanner::Location(
3529 expression->position(), expression->position() + raw_name->length()); 3493 expression->position(), expression->position() + raw_name->length());
3530 return false; 3494 return false;
3531 } 3495 }
3532 3496
3533 scope->DeclareParameter(raw_name, VAR); 3497 scope->DeclareParameter(raw_name, VAR);
3534 ++(*num_params); 3498 ++(*num_params);
3535 return true; 3499 return true;
3536 } 3500 }
3537 3501
3538 // Case for more than one parameter: 3502 // Case for more than one parameter:
3539 // (foo, bar [, ...]) => ... 3503 // (foo, bar [, ...]) => ...
3540 if (expression->IsBinaryOperation()) { 3504 if (expression->IsBinaryOperation()) {
3541 BinaryOperation* binop = expression->AsBinaryOperation(); 3505 BinaryOperation* binop = expression->AsBinaryOperation();
3542 if (binop->op() != Token::COMMA || binop->left()->is_parenthesized() || 3506 if (binop->op() != Token::COMMA || binop->left()->is_parenthesized() ||
3543 binop->right()->is_parenthesized()) 3507 binop->right()->is_parenthesized())
3544 return false; 3508 return false;
3545 3509
3546 return CheckAndDeclareArrowParameter(traits, binop->left(), scope, 3510 return CheckAndDeclareArrowParameter(ast_value_factory, scanner,
3547 num_params, dupe_loc) && 3511 binop->left(), scope, num_params,
3548 CheckAndDeclareArrowParameter(traits, binop->right(), scope, 3512 dupe_loc) &&
3549 num_params, dupe_loc); 3513 CheckAndDeclareArrowParameter(ast_value_factory, scanner,
3514 binop->right(), scope, num_params,
3515 dupe_loc);
3550 } 3516 }
3551 3517
3552 // Any other kind of expression is not a valid parameter list. 3518 // Any other kind of expression is not a valid parameter list.
3553 return false; 3519 return false;
3554 } 3520 }
3555 3521
3556 3522
3557 int ParserTraits::DeclareArrowParametersFromExpression( 3523 int ParserTraits::DeclareArrowParametersFromExpression(
3558 Expression* expression, Scope* scope, Scanner::Location* dupe_loc, 3524 Expression* expression, Scope* scope, Scanner::Location* dupe_loc,
3559 bool* ok) { 3525 bool* ok) {
3560 int num_params = 0; 3526 int num_params = 0;
3561 // Always reset the flag: It only needs to be set for the first expression 3527 // Always reset the flag: It only needs to be set for the first expression
3562 // parsed as arrow function parameter list, becauseonly top-level functions 3528 // parsed as arrow function parameter list, becauseonly top-level functions
3563 // are parsed lazily. 3529 // are parsed lazily.
3564 parser_->parsing_lazy_arrow_parameters_ = false; 3530 parser_->parsing_lazy_arrow_parameters_ = false;
3565 *ok = CheckAndDeclareArrowParameter(this, expression, scope, &num_params, 3531 *ok = CheckAndDeclareArrowParameter(parser_->ast_value_factory(),
3566 dupe_loc); 3532 parser_->scanner(), expression, scope,
3533 &num_params, dupe_loc);
3567 return num_params; 3534 return num_params;
3568 } 3535 }
3569 3536
3570 3537
3571 FunctionLiteral* Parser::ParseFunctionLiteral( 3538 FunctionLiteral* Parser::ParseFunctionLiteral(
3572 const AstRawString* function_name, Scanner::Location function_name_location, 3539 const AstRawString* function_name, Scanner::Location function_name_location,
3573 bool name_is_strict_reserved, FunctionKind kind, int function_token_pos, 3540 bool name_is_strict_reserved, FunctionKind kind, int function_token_pos,
3574 FunctionLiteral::FunctionType function_type, 3541 FunctionLiteral::FunctionType function_type,
3575 FunctionLiteral::ArityRestriction arity_restriction, bool* ok) { 3542 FunctionLiteral::ArityRestriction arity_restriction, bool* ok) {
3576 // Function :: 3543 // Function ::
(...skipping 1872 matching lines...) Expand 10 before | Expand all | Expand 10 after
5449 } else { 5416 } else {
5450 const uc16* data = reinterpret_cast<const uc16*>(raw_string->raw_data()); 5417 const uc16* data = reinterpret_cast<const uc16*>(raw_string->raw_data());
5451 running_hash = StringHasher::ComputeRunningHash(running_hash, data, 5418 running_hash = StringHasher::ComputeRunningHash(running_hash, data,
5452 raw_string->length()); 5419 raw_string->length());
5453 } 5420 }
5454 } 5421 }
5455 5422
5456 return running_hash; 5423 return running_hash;
5457 } 5424 }
5458 } } // namespace v8::internal 5425 } } // 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