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

Side by Side Diff: src/parsing/parser.cc

Issue 1567603005: Set up rewriting triggers (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Merge RewriteExpression and ValidateExpression Created 4 years, 11 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
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/parsing/parser.h" 5 #include "src/parsing/parser.h"
6 6
7 #include "src/api.h" 7 #include "src/api.h"
8 #include "src/ast/ast.h" 8 #include "src/ast/ast.h"
9 #include "src/ast/ast-expression-visitor.h" 9 #include "src/ast/ast-expression-visitor.h"
10 #include "src/ast/ast-literal-reindexer.h" 10 #include "src/ast/ast-literal-reindexer.h"
(...skipping 4732 matching lines...) Expand 10 before | Expand all | Expand 10 after
4743 proxy, CONST, block_scope, pos, is_class_declaration, 4743 proxy, CONST, block_scope, pos, is_class_declaration,
4744 scope_->class_declaration_group_start()); 4744 scope_->class_declaration_group_start());
4745 Declare(declaration, DeclarationDescriptor::NORMAL, true, CHECK_OK); 4745 Declare(declaration, DeclarationDescriptor::NORMAL, true, CHECK_OK);
4746 } 4746 }
4747 4747
4748 Expression* extends = NULL; 4748 Expression* extends = NULL;
4749 if (Check(Token::EXTENDS)) { 4749 if (Check(Token::EXTENDS)) {
4750 block_scope->set_start_position(scanner()->location().end_pos); 4750 block_scope->set_start_position(scanner()->location().end_pos);
4751 ExpressionClassifier classifier; 4751 ExpressionClassifier classifier;
4752 extends = ParseLeftHandSideExpression(&classifier, CHECK_OK); 4752 extends = ParseLeftHandSideExpression(&classifier, CHECK_OK);
4753 ValidateExpression(&classifier, CHECK_OK); 4753 extends = ParserTraits::RewriteExpression(extends, &classifier, CHECK_OK);
4754 extends = ParserTraits::RewriteExpression(extends);
4755 } else { 4754 } else {
4756 block_scope->set_start_position(scanner()->location().end_pos); 4755 block_scope->set_start_position(scanner()->location().end_pos);
4757 } 4756 }
4758 4757
4759 4758
4760 ClassLiteralChecker checker(this); 4759 ClassLiteralChecker checker(this);
4761 ZoneList<ObjectLiteral::Property*>* properties = NewPropertyList(4, zone()); 4760 ZoneList<ObjectLiteral::Property*>* properties = NewPropertyList(4, zone());
4762 FunctionLiteral* constructor = NULL; 4761 FunctionLiteral* constructor = NULL;
4763 bool has_seen_constructor = false; 4762 bool has_seen_constructor = false;
4764 4763
4765 Expect(Token::LBRACE, CHECK_OK); 4764 Expect(Token::LBRACE, CHECK_OK);
4766 4765
4767 const bool has_extends = extends != nullptr; 4766 const bool has_extends = extends != nullptr;
4768 while (peek() != Token::RBRACE) { 4767 while (peek() != Token::RBRACE) {
4769 if (Check(Token::SEMICOLON)) continue; 4768 if (Check(Token::SEMICOLON)) continue;
4770 FuncNameInferrer::State fni_state(fni_); 4769 FuncNameInferrer::State fni_state(fni_);
4771 const bool in_class = true; 4770 const bool in_class = true;
4772 const bool is_static = false; 4771 const bool is_static = false;
4773 bool is_computed_name = false; // Classes do not care about computed 4772 bool is_computed_name = false; // Classes do not care about computed
4774 // property names here. 4773 // property names here.
4775 ExpressionClassifier classifier; 4774 ExpressionClassifier classifier;
4776 const AstRawString* name = nullptr; 4775 const AstRawString* name = nullptr;
4777 ObjectLiteral::Property* property = ParsePropertyDefinition( 4776 ObjectLiteral::Property* property = ParsePropertyDefinition(
4778 &checker, in_class, has_extends, is_static, &is_computed_name, 4777 &checker, in_class, has_extends, is_static, &is_computed_name,
4779 &has_seen_constructor, &classifier, &name, CHECK_OK); 4778 &has_seen_constructor, &classifier, &name, CHECK_OK);
4780 ValidateExpression(&classifier, CHECK_OK); 4779 property = ParserTraits::RewriteObjectLiteralProperty(property, &classifier,
4781 property = ParserTraits::RewriteObjectLiteralProperty(property); 4780 CHECK_OK);
4782 4781
4783 if (has_seen_constructor && constructor == NULL) { 4782 if (has_seen_constructor && constructor == NULL) {
4784 constructor = GetPropertyValue(property)->AsFunctionLiteral(); 4783 constructor = GetPropertyValue(property)->AsFunctionLiteral();
4785 DCHECK_NOT_NULL(constructor); 4784 DCHECK_NOT_NULL(constructor);
4786 } else { 4785 } else {
4787 properties->Add(property, zone()); 4786 properties->Add(property, zone());
4788 } 4787 }
4789 4788
4790 if (fni_ != NULL) fni_->Infer(); 4789 if (fni_ != NULL) fni_->Infer();
4791 4790
(...skipping 594 matching lines...) Expand 10 before | Expand all | Expand 10 after
5386 SetLanguageMode(scope_, 5385 SetLanguageMode(scope_,
5387 static_cast<LanguageMode>(scope_->language_mode() | mode)); 5386 static_cast<LanguageMode>(scope_->language_mode() | mode));
5388 } 5387 }
5389 5388
5390 5389
5391 void ParserTraits::RewriteDestructuringAssignments() { 5390 void ParserTraits::RewriteDestructuringAssignments() {
5392 parser_->RewriteDestructuringAssignments(); 5391 parser_->RewriteDestructuringAssignments();
5393 } 5392 }
5394 5393
5395 5394
5396 Expression* ParserTraits::RewriteExpression(Expression* expr) { 5395 Expression* ParserTraits::RewriteExpression(
5397 return parser_->RewriteExpression(expr); 5396 Expression* expr, const ExpressionClassifier* classifier, bool* ok) {
5397 return parser_->RewriteExpression(expr, classifier, ok);
5398 } 5398 }
5399 5399
5400 5400
5401 ObjectLiteralProperty* ParserTraits::RewriteObjectLiteralProperty( 5401 ObjectLiteralProperty* ParserTraits::RewriteObjectLiteralProperty(
5402 ObjectLiteralProperty* property) { 5402 ObjectLiteralProperty* property, const ExpressionClassifier* classifier,
5403 return parser_->RewriteObjectLiteralProperty(property); 5403 bool* ok) {
5404 return parser_->RewriteObjectLiteralProperty(property, classifier, ok);
5404 } 5405 }
5405 5406
5406 5407
5407 Expression* Parser::RewriteExpression(Expression* expr) { 5408 Expression* Parser::RewriteExpression(Expression* expr,
5408 // TODO(nikolaos): For the time being, this does no rewriting at all. 5409 const ExpressionClassifier* classifier,
5410 bool* ok) {
5411 // For the time being, this does no rewriting at all.
5412 ValidateExpression(classifier, ok);
5409 return expr; 5413 return expr;
5410 } 5414 }
5411 5415
5412 5416
5413 ObjectLiteralProperty* Parser::RewriteObjectLiteralProperty( 5417 ObjectLiteralProperty* Parser::RewriteObjectLiteralProperty(
5414 ObjectLiteralProperty* property) { 5418 ObjectLiteralProperty* property, const ExpressionClassifier* classifier,
5419 bool* ok) {
5415 if (property != nullptr) { 5420 if (property != nullptr) {
5416 Expression* key = RewriteExpression(property->key()); 5421 Expression* key = RewriteExpression(property->key(), classifier, ok);
5417 property->set_key(key); 5422 property->set_key(key);
5418 Expression* value = RewriteExpression(property->value()); 5423 Expression* value = RewriteExpression(property->value(), classifier, ok);
5419 property->set_value(value); 5424 property->set_value(value);
5420 } 5425 }
5421 return property; 5426 return property;
5422 } 5427 }
5423 5428
5424 5429
5425 void Parser::RewriteDestructuringAssignments() { 5430 void Parser::RewriteDestructuringAssignments() {
5426 FunctionState* func = function_state_; 5431 FunctionState* func = function_state_;
5427 if (!allow_harmony_destructuring_assignment()) return; 5432 if (!allow_harmony_destructuring_assignment()) return;
5428 const List<DestructuringAssignment>& assignments = 5433 const List<DestructuringAssignment>& assignments =
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
5482 auto class_literal = value->AsClassLiteral(); 5487 auto class_literal = value->AsClassLiteral();
5483 if (class_literal->raw_name() == nullptr) { 5488 if (class_literal->raw_name() == nullptr) {
5484 class_literal->set_raw_name(name); 5489 class_literal->set_raw_name(name);
5485 } 5490 }
5486 } 5491 }
5487 } 5492 }
5488 5493
5489 5494
5490 } // namespace internal 5495 } // namespace internal
5491 } // namespace v8 5496 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698