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

Side by Side Diff: src/preparser.h

Issue 575083002: Cleanup class parsing a bit (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Git rebase Created 6 years, 3 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.cc ('k') | no next file » | 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 #ifndef V8_PREPARSER_H 5 #ifndef V8_PREPARSER_H
6 #define V8_PREPARSER_H 6 #define V8_PREPARSER_H
7 7
8 #include "src/v8.h" 8 #include "src/v8.h"
9 9
10 #include "src/func-name-inferrer.h" 10 #include "src/func-name-inferrer.h"
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 // // ... 57 // // ...
58 // }; 58 // };
59 59
60 template <typename Traits> 60 template <typename Traits>
61 class ParserBase : public Traits { 61 class ParserBase : public Traits {
62 public: 62 public:
63 // Shorten type names defined by Traits. 63 // Shorten type names defined by Traits.
64 typedef typename Traits::Type::Expression ExpressionT; 64 typedef typename Traits::Type::Expression ExpressionT;
65 typedef typename Traits::Type::Identifier IdentifierT; 65 typedef typename Traits::Type::Identifier IdentifierT;
66 typedef typename Traits::Type::FunctionLiteral FunctionLiteralT; 66 typedef typename Traits::Type::FunctionLiteral FunctionLiteralT;
67 typedef typename Traits::Type::ClassLiteral ClassLiteralT;
68 typedef typename Traits::Type::Literal LiteralT; 67 typedef typename Traits::Type::Literal LiteralT;
69 typedef typename Traits::Type::ObjectLiteralProperty ObjectLiteralPropertyT; 68 typedef typename Traits::Type::ObjectLiteralProperty ObjectLiteralPropertyT;
70 69
71 ParserBase(Scanner* scanner, uintptr_t stack_limit, v8::Extension* extension, 70 ParserBase(Scanner* scanner, uintptr_t stack_limit, v8::Extension* extension,
72 ParserRecorder* log, typename Traits::Type::Zone* zone, 71 ParserRecorder* log, typename Traits::Type::Zone* zone,
73 AstNode::IdGen* ast_node_id_gen, 72 AstNode::IdGen* ast_node_id_gen,
74 typename Traits::Type::Parser this_object) 73 typename Traits::Type::Parser this_object)
75 : Traits(this_object), 74 : Traits(this_object),
76 parenthesized_function_(false), 75 parenthesized_function_(false),
77 scope_(NULL), 76 scope_(NULL),
(...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after
495 ExpressionT ParseBinaryExpression(int prec, bool accept_IN, bool* ok); 494 ExpressionT ParseBinaryExpression(int prec, bool accept_IN, bool* ok);
496 ExpressionT ParseUnaryExpression(bool* ok); 495 ExpressionT ParseUnaryExpression(bool* ok);
497 ExpressionT ParsePostfixExpression(bool* ok); 496 ExpressionT ParsePostfixExpression(bool* ok);
498 ExpressionT ParseLeftHandSideExpression(bool* ok); 497 ExpressionT ParseLeftHandSideExpression(bool* ok);
499 ExpressionT ParseMemberWithNewPrefixesExpression(bool* ok); 498 ExpressionT ParseMemberWithNewPrefixesExpression(bool* ok);
500 ExpressionT ParseMemberExpression(bool* ok); 499 ExpressionT ParseMemberExpression(bool* ok);
501 ExpressionT ParseMemberExpressionContinuation(ExpressionT expression, 500 ExpressionT ParseMemberExpressionContinuation(ExpressionT expression,
502 bool* ok); 501 bool* ok);
503 ExpressionT ParseArrowFunctionLiteral(int start_pos, ExpressionT params_ast, 502 ExpressionT ParseArrowFunctionLiteral(int start_pos, ExpressionT params_ast,
504 bool* ok); 503 bool* ok);
505 ClassLiteralT ParseClassLiteral(IdentifierT name, 504 ExpressionT ParseClassLiteral(IdentifierT name,
506 Scanner::Location function_name_location, 505 Scanner::Location function_name_location,
507 bool name_is_strict_reserved, int pos, 506 bool name_is_strict_reserved, int pos,
508 bool* ok); 507 bool* ok);
509 508
510 // Checks if the expression is a valid reference expression (e.g., on the 509 // Checks if the expression is a valid reference expression (e.g., on the
511 // left-hand side of assignments). Although ruled out by ECMA as early errors, 510 // left-hand side of assignments). Although ruled out by ECMA as early errors,
512 // we allow calls for web compatibility and rewrite them to a runtime throw. 511 // we allow calls for web compatibility and rewrite them to a runtime throw.
513 ExpressionT CheckAndRewriteReferenceExpression( 512 ExpressionT CheckAndRewriteReferenceExpression(
514 ExpressionT expression, 513 ExpressionT expression,
515 Scanner::Location location, const char* message, bool* ok); 514 Scanner::Location location, const char* message, bool* ok);
516 515
517 // Used to detect duplicates in object literals. Each of the values 516 // Used to detect duplicates in object literals. Each of the values
518 // kGetterProperty, kSetterProperty and kValueProperty represents 517 // kGetterProperty, kSetterProperty and kValueProperty represents
(...skipping 561 matching lines...) Expand 10 before | Expand all | Expand 10 after
1080 FunctionLiteral::FunctionType function_type, 1079 FunctionLiteral::FunctionType function_type,
1081 FunctionLiteral::IsFunctionFlag is_function, 1080 FunctionLiteral::IsFunctionFlag is_function,
1082 FunctionLiteral::IsParenthesizedFlag is_parenthesized, FunctionKind kind, 1081 FunctionLiteral::IsParenthesizedFlag is_parenthesized, FunctionKind kind,
1083 int position) { 1082 int position) {
1084 return PreParserExpression::Default(); 1083 return PreParserExpression::Default();
1085 } 1084 }
1086 PreParserExpression NewClassLiteral(PreParserIdentifier name, 1085 PreParserExpression NewClassLiteral(PreParserIdentifier name,
1087 PreParserExpression extends, 1086 PreParserExpression extends,
1088 PreParserExpression constructor, 1087 PreParserExpression constructor,
1089 PreParserExpressionList properties, 1088 PreParserExpressionList properties,
1090 AstValueFactory* ast_value_factory,
1091 int position) { 1089 int position) {
1092 return PreParserExpression::Default(); 1090 return PreParserExpression::Default();
1093 } 1091 }
1094 1092
1095 // Return the object itself as AstVisitor and implement the needed 1093 // Return the object itself as AstVisitor and implement the needed
1096 // dummy method right in this class. 1094 // dummy method right in this class.
1097 PreParserFactory* visitor() { return this; } 1095 PreParserFactory* visitor() { return this; }
1098 BailoutReason dont_optimize_reason() { return kNoReason; } 1096 BailoutReason dont_optimize_reason() { return kNoReason; }
1099 int* ast_properties() { 1097 int* ast_properties() {
1100 static int dummy = 42; 1098 static int dummy = 42;
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
1280 } 1278 }
1281 static PreParserExpression EmptyLiteral() { 1279 static PreParserExpression EmptyLiteral() {
1282 return PreParserExpression::Default(); 1280 return PreParserExpression::Default();
1283 } 1281 }
1284 static PreParserExpression EmptyObjectLiteralProperty() { 1282 static PreParserExpression EmptyObjectLiteralProperty() {
1285 return PreParserExpression::Default(); 1283 return PreParserExpression::Default();
1286 } 1284 }
1287 static PreParserExpression EmptyFunctionLiteral() { 1285 static PreParserExpression EmptyFunctionLiteral() {
1288 return PreParserExpression::Default(); 1286 return PreParserExpression::Default();
1289 } 1287 }
1290 static PreParserExpression EmptyClassLiteral() {
1291 return PreParserExpression::Default();
1292 }
1293 static PreParserExpressionList NullExpressionList() { 1288 static PreParserExpressionList NullExpressionList() {
1294 return PreParserExpressionList(); 1289 return PreParserExpressionList();
1295 } 1290 }
1296 1291
1297 // Odd-ball literal creators. 1292 // Odd-ball literal creators.
1298 static PreParserExpression GetLiteralTheHole(int position, 1293 static PreParserExpression GetLiteralTheHole(int position,
1299 PreParserFactory* factory) { 1294 PreParserFactory* factory) {
1300 return PreParserExpression::Default(); 1295 return PreParserExpression::Default();
1301 } 1296 }
1302 1297
1303 // Producing data during the recursive descent. 1298 // Producing data during the recursive descent.
1304 PreParserIdentifier GetSymbol(Scanner* scanner); 1299 PreParserIdentifier GetSymbol(Scanner* scanner);
1305 PreParserIdentifier GetNumberAsSymbol(Scanner* scanner); 1300 PreParserIdentifier GetNumberAsSymbol(Scanner* scanner);
1306 1301
1307 static PreParserIdentifier GetNextSymbol(Scanner* scanner) { 1302 static PreParserIdentifier GetNextSymbol(Scanner* scanner) {
1308 return PreParserIdentifier::Default(); 1303 return PreParserIdentifier::Default();
1309 } 1304 }
1310 1305
1311 static PreParserExpression ThisExpression(PreParserScope* scope, 1306 static PreParserExpression ThisExpression(PreParserScope* scope,
1312 PreParserFactory* factory) { 1307 PreParserFactory* factory) {
1313 return PreParserExpression::This(); 1308 return PreParserExpression::This();
1314 } 1309 }
1315 1310
1316 static PreParserExpression SuperReference(PreParserScope* scope, 1311 static PreParserExpression SuperReference(PreParserScope* scope,
1317 PreParserFactory* factory) { 1312 PreParserFactory* factory) {
1318 return PreParserExpression::Super(); 1313 return PreParserExpression::Super();
1319 } 1314 }
1320 1315
1316 static PreParserExpression ClassLiteral(PreParserIdentifier name,
1317 PreParserExpression extends,
1318 PreParserExpression constructor,
1319 PreParserExpressionList properties,
1320 int position,
1321 PreParserFactory* factory) {
1322 return PreParserExpression::Default();
1323 }
1324
1321 static PreParserExpression ExpressionFromLiteral( 1325 static PreParserExpression ExpressionFromLiteral(
1322 Token::Value token, int pos, Scanner* scanner, 1326 Token::Value token, int pos, Scanner* scanner,
1323 PreParserFactory* factory) { 1327 PreParserFactory* factory) {
1324 return PreParserExpression::Default(); 1328 return PreParserExpression::Default();
1325 } 1329 }
1326 1330
1327 static PreParserExpression ExpressionFromIdentifier( 1331 static PreParserExpression ExpressionFromIdentifier(
1328 PreParserIdentifier name, int pos, PreParserScope* scope, 1332 PreParserIdentifier name, int pos, PreParserScope* scope,
1329 PreParserFactory* factory) { 1333 PreParserFactory* factory) {
1330 return PreParserExpression::FromIdentifier(name); 1334 return PreParserExpression::FromIdentifier(name);
(...skipping 1375 matching lines...) Expand 10 before | Expand all | Expand 10 after
2706 function_literal->set_ast_properties(&ast_properties); 2710 function_literal->set_ast_properties(&ast_properties);
2707 function_literal->set_dont_optimize_reason(dont_optimize_reason); 2711 function_literal->set_dont_optimize_reason(dont_optimize_reason);
2708 2712
2709 if (fni_ != NULL) this->InferFunctionName(fni_, function_literal); 2713 if (fni_ != NULL) this->InferFunctionName(fni_, function_literal);
2710 2714
2711 return function_literal; 2715 return function_literal;
2712 } 2716 }
2713 2717
2714 2718
2715 template <class Traits> 2719 template <class Traits>
2716 typename ParserBase<Traits>::ClassLiteralT 2720 typename ParserBase<Traits>::ExpressionT ParserBase<Traits>::ParseClassLiteral(
2717 ParserBase<Traits>::ParseClassLiteral(IdentifierT name, 2721 IdentifierT name, Scanner::Location class_name_location,
2718 Scanner::Location class_name_location, 2722 bool name_is_strict_reserved, int pos, bool* ok) {
2719 bool name_is_strict_reserved, int pos,
2720 bool* ok) {
2721 // All parts of a ClassDeclaration or a ClassExpression are strict code. 2723 // All parts of a ClassDeclaration or a ClassExpression are strict code.
2722 if (name_is_strict_reserved) { 2724 if (name_is_strict_reserved) {
2723 ReportMessageAt(class_name_location, "unexpected_strict_reserved"); 2725 ReportMessageAt(class_name_location, "unexpected_strict_reserved");
2724 *ok = false; 2726 *ok = false;
2725 return this->EmptyClassLiteral(); 2727 return this->EmptyExpression();
2726 } 2728 }
2727 if (this->IsEvalOrArguments(name)) { 2729 if (this->IsEvalOrArguments(name)) {
2728 ReportMessageAt(class_name_location, "strict_eval_arguments"); 2730 ReportMessageAt(class_name_location, "strict_eval_arguments");
2729 *ok = false; 2731 *ok = false;
2730 return this->EmptyClassLiteral(); 2732 return this->EmptyExpression();
2731 } 2733 }
2732 2734
2733 // TODO(arv): Implement scopes and name binding in class body only. 2735 // TODO(arv): Implement scopes and name binding in class body only.
2734 // TODO(arv): Maybe add CLASS_SCOPE? 2736 // TODO(arv): Maybe add CLASS_SCOPE?
2735 typename Traits::Type::ScopePtr extends_scope = 2737 typename Traits::Type::ScopePtr extends_scope =
2736 this->NewScope(scope_, BLOCK_SCOPE); 2738 this->NewScope(scope_, BLOCK_SCOPE);
2737 FunctionState extends_function_state( 2739 FunctionState extends_function_state(
2738 &function_state_, &scope_, &extends_scope, zone(), 2740 &function_state_, &scope_, &extends_scope, zone(),
2739 this->ast_value_factory(), ast_node_id_gen_); 2741 this->ast_value_factory(), ast_node_id_gen_);
2740 scope_->SetStrictMode(STRICT); 2742 scope_->SetStrictMode(STRICT);
2741 scope_->SetScopeName(name); 2743 scope_->SetScopeName(name);
2742 2744
2743 ExpressionT extends = this->EmptyExpression(); 2745 ExpressionT extends = this->EmptyExpression();
2744 if (Check(Token::EXTENDS)) { 2746 if (Check(Token::EXTENDS)) {
2745 extends = 2747 extends = this->ParseLeftHandSideExpression(CHECK_OK);
2746 this->ParseLeftHandSideExpression(CHECK_OK_CUSTOM(EmptyClassLiteral));
2747 } 2748 }
2748 2749
2749 ObjectLiteralChecker checker(this, STRICT); 2750 ObjectLiteralChecker checker(this, STRICT);
2750 typename Traits::Type::PropertyList properties = 2751 typename Traits::Type::PropertyList properties =
2751 this->NewPropertyList(4, zone_); 2752 this->NewPropertyList(4, zone_);
2752 FunctionLiteralT constructor = this->EmptyFunctionLiteral(); 2753 FunctionLiteralT constructor = this->EmptyFunctionLiteral();
2753 2754
2754 Expect(Token::LBRACE, CHECK_OK_CUSTOM(EmptyClassLiteral)); 2755 Expect(Token::LBRACE, CHECK_OK);
2755 while (peek() != Token::RBRACE) { 2756 while (peek() != Token::RBRACE) {
2756 if (Check(Token::SEMICOLON)) continue; 2757 if (Check(Token::SEMICOLON)) continue;
2757 if (fni_ != NULL) fni_->Enter(); 2758 if (fni_ != NULL) fni_->Enter();
2758 2759
2759 const bool in_class = true; 2760 const bool in_class = true;
2760 const bool is_static = false; 2761 const bool is_static = false;
2761 ObjectLiteralPropertyT property = this->ParsePropertyDefinition( 2762 ObjectLiteralPropertyT property =
2762 &checker, in_class, is_static, CHECK_OK_CUSTOM(EmptyClassLiteral)); 2763 this->ParsePropertyDefinition(&checker, in_class, is_static, CHECK_OK);
2763 2764
2764 properties->Add(property, zone()); 2765 properties->Add(property, zone());
2765 2766
2766 if (fni_ != NULL) { 2767 if (fni_ != NULL) {
2767 fni_->Infer(); 2768 fni_->Infer();
2768 fni_->Leave(); 2769 fni_->Leave();
2769 } 2770 }
2770 } 2771 }
2771 Expect(Token::RBRACE, CHECK_OK_CUSTOM(EmptyClassLiteral)); 2772 Expect(Token::RBRACE, CHECK_OK);
2772 2773
2773 return factory()->NewClassLiteral(name, extends, constructor, properties, 2774 return this->ClassLiteral(name, extends, constructor, properties, pos,
2774 this->ast_value_factory(), pos); 2775 factory());
2775 } 2776 }
2776 2777
2777 2778
2778 template <typename Traits> 2779 template <typename Traits>
2779 typename ParserBase<Traits>::ExpressionT 2780 typename ParserBase<Traits>::ExpressionT
2780 ParserBase<Traits>::CheckAndRewriteReferenceExpression( 2781 ParserBase<Traits>::CheckAndRewriteReferenceExpression(
2781 ExpressionT expression, 2782 ExpressionT expression,
2782 Scanner::Location location, const char* message, bool* ok) { 2783 Scanner::Location location, const char* message, bool* ok) {
2783 if (strict_mode() == STRICT && this->IsIdentifier(expression) && 2784 if (strict_mode() == STRICT && this->IsIdentifier(expression) &&
2784 this->IsEvalOrArguments(this->AsIdentifier(expression))) { 2785 this->IsEvalOrArguments(this->AsIdentifier(expression))) {
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
2827 DCHECK(IsAccessorAccessorConflict(old_type, type)); 2828 DCHECK(IsAccessorAccessorConflict(old_type, type));
2828 // Both accessors of the same type. 2829 // Both accessors of the same type.
2829 parser()->ReportMessage("accessor_get_set"); 2830 parser()->ReportMessage("accessor_get_set");
2830 } 2831 }
2831 *ok = false; 2832 *ok = false;
2832 } 2833 }
2833 } 2834 }
2834 } } // v8::internal 2835 } } // v8::internal
2835 2836
2836 #endif // V8_PREPARSER_H 2837 #endif // V8_PREPARSER_H
OLDNEW
« no previous file with comments | « src/parser.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698