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

Side by Side Diff: src/preparser.h

Issue 722793005: Classes: Implement correct name binding (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: git rebase Created 6 years, 1 month 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
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/bailout-reason.h" 10 #include "src/bailout-reason.h"
(...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after
483 ExpressionT ParseBinaryExpression(int prec, bool accept_IN, bool* ok); 483 ExpressionT ParseBinaryExpression(int prec, bool accept_IN, bool* ok);
484 ExpressionT ParseUnaryExpression(bool* ok); 484 ExpressionT ParseUnaryExpression(bool* ok);
485 ExpressionT ParsePostfixExpression(bool* ok); 485 ExpressionT ParsePostfixExpression(bool* ok);
486 ExpressionT ParseLeftHandSideExpression(bool* ok); 486 ExpressionT ParseLeftHandSideExpression(bool* ok);
487 ExpressionT ParseMemberWithNewPrefixesExpression(bool* ok); 487 ExpressionT ParseMemberWithNewPrefixesExpression(bool* ok);
488 ExpressionT ParseMemberExpression(bool* ok); 488 ExpressionT ParseMemberExpression(bool* ok);
489 ExpressionT ParseMemberExpressionContinuation(ExpressionT expression, 489 ExpressionT ParseMemberExpressionContinuation(ExpressionT expression,
490 bool* ok); 490 bool* ok);
491 ExpressionT ParseArrowFunctionLiteral(int start_pos, ExpressionT params_ast, 491 ExpressionT ParseArrowFunctionLiteral(int start_pos, ExpressionT params_ast,
492 bool* ok); 492 bool* ok);
493 ExpressionT ParseClassLiteral(IdentifierT name,
494 Scanner::Location function_name_location,
495 bool name_is_strict_reserved, int pos,
496 bool* ok);
497 493
498 // Checks if the expression is a valid reference expression (e.g., on the 494 // Checks if the expression is a valid reference expression (e.g., on the
499 // left-hand side of assignments). Although ruled out by ECMA as early errors, 495 // left-hand side of assignments). Although ruled out by ECMA as early errors,
500 // we allow calls for web compatibility and rewrite them to a runtime throw. 496 // we allow calls for web compatibility and rewrite them to a runtime throw.
501 ExpressionT CheckAndRewriteReferenceExpression( 497 ExpressionT CheckAndRewriteReferenceExpression(
502 ExpressionT expression, 498 ExpressionT expression,
503 Scanner::Location location, const char* message, bool* ok); 499 Scanner::Location location, const char* message, bool* ok);
504 500
505 // Used to detect duplicates in object literals. Each of the values 501 // Used to detect duplicates in object literals. Each of the values
506 // kGetterProperty, kSetterProperty and kValueProperty represents 502 // kGetterProperty, kSetterProperty and kValueProperty represents
(...skipping 576 matching lines...) Expand 10 before | Expand all | Expand 10 after
1083 const PreParserScope& scope, PreParserStatementList body, 1079 const PreParserScope& scope, PreParserStatementList body,
1084 int materialized_literal_count, int expected_property_count, 1080 int materialized_literal_count, int expected_property_count,
1085 int handler_count, int parameter_count, 1081 int handler_count, int parameter_count,
1086 FunctionLiteral::ParameterFlag has_duplicate_parameters, 1082 FunctionLiteral::ParameterFlag has_duplicate_parameters,
1087 FunctionLiteral::FunctionType function_type, 1083 FunctionLiteral::FunctionType function_type,
1088 FunctionLiteral::IsFunctionFlag is_function, 1084 FunctionLiteral::IsFunctionFlag is_function,
1089 FunctionLiteral::IsParenthesizedFlag is_parenthesized, FunctionKind kind, 1085 FunctionLiteral::IsParenthesizedFlag is_parenthesized, FunctionKind kind,
1090 int position) { 1086 int position) {
1091 return PreParserExpression::Default(); 1087 return PreParserExpression::Default();
1092 } 1088 }
1093 PreParserExpression NewClassLiteral(PreParserIdentifier name, 1089
1094 PreParserExpression extends, 1090 // Return the object itself as AstVisitor and implement the needed
1095 PreParserExpression constructor, 1091 // dummy method right in this class.
1096 PreParserExpressionList properties, 1092 PreParserFactory* visitor() { return this; }
1097 int start_position, int end_position) { 1093 int* ast_properties() {
1098 return PreParserExpression::Default(); 1094 static int dummy = 42;
1095 return &dummy;
1099 } 1096 }
1100 }; 1097 };
1101 1098
1102 1099
1103 class PreParser; 1100 class PreParser;
1104 1101
1105 class PreParserTraits { 1102 class PreParserTraits {
1106 public: 1103 public:
1107 struct Type { 1104 struct Type {
1108 // TODO(marja): To be removed. The Traits object should contain all the data 1105 // TODO(marja): To be removed. The Traits object should contain all the data
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
1301 static PreParserExpression ThisExpression(PreParserScope* scope, 1298 static PreParserExpression ThisExpression(PreParserScope* scope,
1302 PreParserFactory* factory) { 1299 PreParserFactory* factory) {
1303 return PreParserExpression::This(); 1300 return PreParserExpression::This();
1304 } 1301 }
1305 1302
1306 static PreParserExpression SuperReference(PreParserScope* scope, 1303 static PreParserExpression SuperReference(PreParserScope* scope,
1307 PreParserFactory* factory) { 1304 PreParserFactory* factory) {
1308 return PreParserExpression::Super(); 1305 return PreParserExpression::Super();
1309 } 1306 }
1310 1307
1311 static PreParserExpression ClassExpression(
1312 PreParserIdentifier name, PreParserExpression extends,
1313 PreParserExpression constructor, PreParserExpressionList properties,
1314 int start_position, int end_position, PreParserFactory* factory) {
1315 return PreParserExpression::Default();
1316 }
1317
1318 static PreParserExpression DefaultConstructor(bool call_super, 1308 static PreParserExpression DefaultConstructor(bool call_super,
1319 PreParserScope* scope, int pos, 1309 PreParserScope* scope, int pos,
1320 int end_pos) { 1310 int end_pos) {
1321 return PreParserExpression::Default(); 1311 return PreParserExpression::Default();
1322 } 1312 }
1323 1313
1324 static PreParserExpression ExpressionFromLiteral( 1314 static PreParserExpression ExpressionFromLiteral(
1325 Token::Value token, int pos, Scanner* scanner, 1315 Token::Value token, int pos, Scanner* scanner,
1326 PreParserFactory* factory) { 1316 PreParserFactory* factory) {
1327 return PreParserExpression::Default(); 1317 return PreParserExpression::Default();
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
1380 void CheckConflictingVarDeclarations(PreParserScope scope, bool* ok) {} 1370 void CheckConflictingVarDeclarations(PreParserScope scope, bool* ok) {}
1381 1371
1382 // Temporary glue; these functions will move to ParserBase. 1372 // Temporary glue; these functions will move to ParserBase.
1383 PreParserExpression ParseV8Intrinsic(bool* ok); 1373 PreParserExpression ParseV8Intrinsic(bool* ok);
1384 PreParserExpression ParseFunctionLiteral( 1374 PreParserExpression ParseFunctionLiteral(
1385 PreParserIdentifier name, Scanner::Location function_name_location, 1375 PreParserIdentifier name, Scanner::Location function_name_location,
1386 bool name_is_strict_reserved, FunctionKind kind, 1376 bool name_is_strict_reserved, FunctionKind kind,
1387 int function_token_position, FunctionLiteral::FunctionType type, 1377 int function_token_position, FunctionLiteral::FunctionType type,
1388 FunctionLiteral::ArityRestriction arity_restriction, bool* ok); 1378 FunctionLiteral::ArityRestriction arity_restriction, bool* ok);
1389 1379
1380 PreParserExpression ParseClassLiteral(PreParserIdentifier name,
1381 Scanner::Location class_name_location,
1382 bool name_is_strict_reserved, int pos,
1383 bool* ok);
1384
1390 private: 1385 private:
1391 PreParser* pre_parser_; 1386 PreParser* pre_parser_;
1392 }; 1387 };
1393 1388
1394 1389
1395 // Preparsing checks a JavaScript program and emits preparse-data that helps 1390 // Preparsing checks a JavaScript program and emits preparse-data that helps
1396 // a later parsing to be faster. 1391 // a later parsing to be faster.
1397 // See preparse-data-format.h for the data format. 1392 // See preparse-data-format.h for the data format.
1398 1393
1399 // The PreParser checks that the syntax follows the grammar for JavaScript, 1394 // The PreParser checks that the syntax follows the grammar for JavaScript,
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
1517 Variable* fvar, Token::Value fvar_init_op, 1512 Variable* fvar, Token::Value fvar_init_op,
1518 bool is_generator, bool* ok); 1513 bool is_generator, bool* ok);
1519 1514
1520 Expression ParseFunctionLiteral( 1515 Expression ParseFunctionLiteral(
1521 Identifier name, Scanner::Location function_name_location, 1516 Identifier name, Scanner::Location function_name_location,
1522 bool name_is_strict_reserved, FunctionKind kind, int function_token_pos, 1517 bool name_is_strict_reserved, FunctionKind kind, int function_token_pos,
1523 FunctionLiteral::FunctionType function_type, 1518 FunctionLiteral::FunctionType function_type,
1524 FunctionLiteral::ArityRestriction arity_restriction, bool* ok); 1519 FunctionLiteral::ArityRestriction arity_restriction, bool* ok);
1525 void ParseLazyFunctionLiteralBody(bool* ok); 1520 void ParseLazyFunctionLiteralBody(bool* ok);
1526 1521
1522 PreParserExpression ParseClassLiteral(PreParserIdentifier name,
1523 Scanner::Location class_name_location,
1524 bool name_is_strict_reserved, int pos,
1525 bool* ok);
1526
1527 bool CheckInOrOf(bool accept_OF); 1527 bool CheckInOrOf(bool accept_OF);
1528 }; 1528 };
1529 1529
1530 1530
1531 PreParserStatementList PreParser::ParseEagerFunctionBody( 1531 PreParserStatementList PreParser::ParseEagerFunctionBody(
1532 PreParserIdentifier function_name, int pos, Variable* fvar, 1532 PreParserIdentifier function_name, int pos, Variable* fvar,
1533 Token::Value fvar_init_op, bool is_generator, bool* ok) { 1533 Token::Value fvar_init_op, bool is_generator, bool* ok) {
1534 ParsingModeScope parsing_mode(this, PARSE_EAGERLY); 1534 ParsingModeScope parsing_mode(this, PARSE_EAGERLY);
1535 1535
1536 ParseSourceElements(Token::RBRACE, ok); 1536 ParseSourceElements(Token::RBRACE, ok);
(...skipping 1178 matching lines...) Expand 10 before | Expand all | Expand 10 after
2715 start_pos); 2715 start_pos);
2716 2716
2717 function_literal->set_function_token_position(start_pos); 2717 function_literal->set_function_token_position(start_pos);
2718 2718
2719 if (fni_ != NULL) this->InferFunctionName(fni_, function_literal); 2719 if (fni_ != NULL) this->InferFunctionName(fni_, function_literal);
2720 2720
2721 return function_literal; 2721 return function_literal;
2722 } 2722 }
2723 2723
2724 2724
2725 template <class Traits>
2726 typename ParserBase<Traits>::ExpressionT ParserBase<Traits>::ParseClassLiteral(
2727 IdentifierT name, Scanner::Location class_name_location,
2728 bool name_is_strict_reserved, int pos, bool* ok) {
2729 // All parts of a ClassDeclaration or a ClassExpression are strict code.
2730 if (name_is_strict_reserved) {
2731 ReportMessageAt(class_name_location, "unexpected_strict_reserved");
2732 *ok = false;
2733 return this->EmptyExpression();
2734 }
2735 if (this->IsEvalOrArguments(name)) {
2736 ReportMessageAt(class_name_location, "strict_eval_arguments");
2737 *ok = false;
2738 return this->EmptyExpression();
2739 }
2740
2741 bool has_extends = false;
2742 ExpressionT extends = this->EmptyExpression();
2743 if (Check(Token::EXTENDS)) {
2744 typename Traits::Type::ScopePtr scope = this->NewScope(scope_, BLOCK_SCOPE);
2745 BlockState block_state(&scope_, Traits::Type::ptr_to_scope(scope));
2746 scope_->SetStrictMode(STRICT);
2747 extends = this->ParseLeftHandSideExpression(CHECK_OK);
2748 has_extends = true;
2749 }
2750
2751 // TODO(arv): Implement scopes and name binding in class body only.
2752 typename Traits::Type::ScopePtr scope = this->NewScope(scope_, BLOCK_SCOPE);
2753 BlockState block_state(&scope_, Traits::Type::ptr_to_scope(scope));
2754 scope_->SetStrictMode(STRICT);
2755 scope_->SetScopeName(name);
2756
2757 typename Traits::Type::PropertyList properties =
2758 this->NewPropertyList(4, zone_);
2759 ExpressionT constructor = this->EmptyExpression();
2760 bool has_seen_constructor = false;
2761
2762 Expect(Token::LBRACE, CHECK_OK);
2763 while (peek() != Token::RBRACE) {
2764 if (Check(Token::SEMICOLON)) continue;
2765 if (fni_ != NULL) fni_->Enter();
2766 const bool in_class = true;
2767 const bool is_static = false;
2768 bool old_has_seen_constructor = has_seen_constructor;
2769 ObjectLiteralPropertyT property = this->ParsePropertyDefinition(
2770 NULL, in_class, is_static, &has_seen_constructor, CHECK_OK);
2771
2772 if (has_seen_constructor != old_has_seen_constructor) {
2773 constructor = this->GetPropertyValue(property);
2774 } else {
2775 properties->Add(property, zone());
2776 }
2777
2778 if (fni_ != NULL) {
2779 fni_->Infer();
2780 fni_->Leave();
2781 }
2782 }
2783
2784 int end_pos = peek_position();
2785 Expect(Token::RBRACE, CHECK_OK);
2786
2787 if (!has_seen_constructor) {
2788 constructor =
2789 this->DefaultConstructor(has_extends, scope_, pos, end_pos + 1);
2790 }
2791
2792 return this->ClassExpression(name, extends, constructor, properties, pos,
2793 end_pos + 1, factory());
2794 }
2795
2796
2797 template <typename Traits> 2725 template <typename Traits>
2798 typename ParserBase<Traits>::ExpressionT 2726 typename ParserBase<Traits>::ExpressionT
2799 ParserBase<Traits>::CheckAndRewriteReferenceExpression( 2727 ParserBase<Traits>::CheckAndRewriteReferenceExpression(
2800 ExpressionT expression, 2728 ExpressionT expression,
2801 Scanner::Location location, const char* message, bool* ok) { 2729 Scanner::Location location, const char* message, bool* ok) {
2802 if (strict_mode() == STRICT && this->IsIdentifier(expression) && 2730 if (strict_mode() == STRICT && this->IsIdentifier(expression) &&
2803 this->IsEvalOrArguments(this->AsIdentifier(expression))) { 2731 this->IsEvalOrArguments(this->AsIdentifier(expression))) {
2804 this->ReportMessageAt(location, "strict_eval_arguments", false); 2732 this->ReportMessageAt(location, "strict_eval_arguments", false);
2805 *ok = false; 2733 *ok = false;
2806 return this->EmptyExpression(); 2734 return this->EmptyExpression();
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
2846 DCHECK(IsAccessorAccessorConflict(old_type, type)); 2774 DCHECK(IsAccessorAccessorConflict(old_type, type));
2847 // Both accessors of the same type. 2775 // Both accessors of the same type.
2848 parser()->ReportMessage("accessor_get_set"); 2776 parser()->ReportMessage("accessor_get_set");
2849 } 2777 }
2850 *ok = false; 2778 *ok = false;
2851 } 2779 }
2852 } 2780 }
2853 } } // v8::internal 2781 } } // v8::internal
2854 2782
2855 #endif // V8_PREPARSER_H 2783 #endif // V8_PREPARSER_H
OLDNEW
« src/parser.cc ('K') | « src/parser.cc ('k') | src/preparser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698