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

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: 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
« src/ast.h ('K') | « 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 1365 matching lines...) Expand 10 before | Expand all | Expand 10 after
2696 function_literal->set_ast_properties(&ast_properties); 2700 function_literal->set_ast_properties(&ast_properties);
2697 function_literal->set_dont_optimize_reason(dont_optimize_reason); 2701 function_literal->set_dont_optimize_reason(dont_optimize_reason);
2698 2702
2699 if (fni_ != NULL) this->InferFunctionName(fni_, function_literal); 2703 if (fni_ != NULL) this->InferFunctionName(fni_, function_literal);
2700 2704
2701 return function_literal; 2705 return function_literal;
2702 } 2706 }
2703 2707
2704 2708
2705 template <class Traits> 2709 template <class Traits>
2706 typename ParserBase<Traits>::ClassLiteralT 2710 typename ParserBase<Traits>::ExpressionT ParserBase<Traits>::ParseClassLiteral(
2707 ParserBase<Traits>::ParseClassLiteral(IdentifierT name, 2711 IdentifierT name, Scanner::Location class_name_location,
2708 Scanner::Location class_name_location, 2712 bool name_is_strict_reserved, int pos, bool* ok) {
2709 bool name_is_strict_reserved, int pos,
2710 bool* ok) {
2711 // All parts of a ClassDeclaration or a ClassExpression are strict code. 2713 // All parts of a ClassDeclaration or a ClassExpression are strict code.
2712 if (name_is_strict_reserved) { 2714 if (name_is_strict_reserved) {
2713 ReportMessageAt(class_name_location, "unexpected_strict_reserved"); 2715 ReportMessageAt(class_name_location, "unexpected_strict_reserved");
2714 *ok = false; 2716 *ok = false;
2715 return this->EmptyClassLiteral(); 2717 return this->EmptyExpression();
2716 } 2718 }
2717 if (this->IsEvalOrArguments(name)) { 2719 if (this->IsEvalOrArguments(name)) {
2718 ReportMessageAt(class_name_location, "strict_eval_arguments"); 2720 ReportMessageAt(class_name_location, "strict_eval_arguments");
2719 *ok = false; 2721 *ok = false;
2720 return this->EmptyClassLiteral(); 2722 return this->EmptyExpression();
2721 } 2723 }
2722 2724
2723 // TODO(arv): Implement scopes and name binding in class body only. 2725 // TODO(arv): Implement scopes and name binding in class body only.
2724 // TODO(arv): Maybe add CLASS_SCOPE? 2726 // TODO(arv): Maybe add CLASS_SCOPE?
2725 typename Traits::Type::ScopePtr extends_scope = 2727 typename Traits::Type::ScopePtr extends_scope =
2726 this->NewScope(scope_, BLOCK_SCOPE); 2728 this->NewScope(scope_, BLOCK_SCOPE);
2727 FunctionState extends_function_state( 2729 FunctionState extends_function_state(
2728 &function_state_, &scope_, &extends_scope, zone(), 2730 &function_state_, &scope_, &extends_scope, zone(),
2729 this->ast_value_factory(), ast_node_id_gen_); 2731 this->ast_value_factory(), ast_node_id_gen_);
2730 scope_->SetStrictMode(STRICT); 2732 scope_->SetStrictMode(STRICT);
2731 scope_->SetScopeName(name); 2733 scope_->SetScopeName(name);
2732 2734
2733 ExpressionT extends = this->EmptyExpression(); 2735 ExpressionT extends = this->EmptyExpression();
2734 if (Check(Token::EXTENDS)) { 2736 if (Check(Token::EXTENDS)) {
2735 extends = 2737 extends = this->ParseLeftHandSideExpression(CHECK_OK);
2736 this->ParseLeftHandSideExpression(CHECK_OK_CUSTOM(EmptyClassLiteral));
2737 } 2738 }
2738 2739
2739 ObjectLiteralChecker checker(this, STRICT); 2740 ObjectLiteralChecker checker(this, STRICT);
2740 typename Traits::Type::PropertyList properties = 2741 typename Traits::Type::PropertyList properties =
2741 this->NewPropertyList(4, zone_); 2742 this->NewPropertyList(4, zone_);
2742 FunctionLiteralT constructor = this->EmptyFunctionLiteral(); 2743 FunctionLiteralT constructor = this->EmptyFunctionLiteral();
2743 2744
2744 Expect(Token::LBRACE, CHECK_OK_CUSTOM(EmptyClassLiteral)); 2745 Expect(Token::LBRACE, CHECK_OK);
2745 while (peek() != Token::RBRACE) { 2746 while (peek() != Token::RBRACE) {
2746 if (Check(Token::SEMICOLON)) continue; 2747 if (Check(Token::SEMICOLON)) continue;
2747 if (fni_ != NULL) fni_->Enter(); 2748 if (fni_ != NULL) fni_->Enter();
2748 2749
2749 const bool in_class = true; 2750 const bool in_class = true;
2750 const bool is_static = false; 2751 const bool is_static = false;
2751 ObjectLiteralPropertyT property = this->ParsePropertyDefinition( 2752 ObjectLiteralPropertyT property =
2752 &checker, in_class, is_static, CHECK_OK_CUSTOM(EmptyClassLiteral)); 2753 this->ParsePropertyDefinition(&checker, in_class, is_static, CHECK_OK);
2753 2754
2754 properties->Add(property, zone()); 2755 properties->Add(property, zone());
2755 2756
2756 if (fni_ != NULL) { 2757 if (fni_ != NULL) {
2757 fni_->Infer(); 2758 fni_->Infer();
2758 fni_->Leave(); 2759 fni_->Leave();
2759 } 2760 }
2760 } 2761 }
2761 Expect(Token::RBRACE, CHECK_OK_CUSTOM(EmptyClassLiteral)); 2762 Expect(Token::RBRACE, CHECK_OK);
2762 2763
2763 return factory()->NewClassLiteral(name, extends, constructor, properties, 2764 return this->ClassLiteral(name, extends, constructor, properties, pos,
2764 this->ast_value_factory(), pos); 2765 factory());
2765 } 2766 }
2766 2767
2767 2768
2768 template <typename Traits> 2769 template <typename Traits>
2769 typename ParserBase<Traits>::ExpressionT 2770 typename ParserBase<Traits>::ExpressionT
2770 ParserBase<Traits>::CheckAndRewriteReferenceExpression( 2771 ParserBase<Traits>::CheckAndRewriteReferenceExpression(
2771 ExpressionT expression, 2772 ExpressionT expression,
2772 Scanner::Location location, const char* message, bool* ok) { 2773 Scanner::Location location, const char* message, bool* ok) {
2773 if (strict_mode() == STRICT && this->IsIdentifier(expression) && 2774 if (strict_mode() == STRICT && this->IsIdentifier(expression) &&
2774 this->IsEvalOrArguments(this->AsIdentifier(expression))) { 2775 this->IsEvalOrArguments(this->AsIdentifier(expression))) {
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
2817 DCHECK(IsAccessorAccessorConflict(old_type, type)); 2818 DCHECK(IsAccessorAccessorConflict(old_type, type));
2818 // Both accessors of the same type. 2819 // Both accessors of the same type.
2819 parser()->ReportMessage("accessor_get_set"); 2820 parser()->ReportMessage("accessor_get_set");
2820 } 2821 }
2821 *ok = false; 2822 *ok = false;
2822 } 2823 }
2823 } 2824 }
2824 } } // v8::internal 2825 } } // v8::internal
2825 2826
2826 #endif // V8_PREPARSER_H 2827 #endif // V8_PREPARSER_H
OLDNEW
« src/ast.h ('K') | « src/parser.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698