OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
445 static void TearDownFunctionState(FunctionState* function_state) { | 445 static void TearDownFunctionState(FunctionState* function_state) { |
446 if (function_state->outer_function_state_ != NULL) { | 446 if (function_state->outer_function_state_ != NULL) { |
447 function_state->isolate_->set_ast_node_id( | 447 function_state->isolate_->set_ast_node_id( |
448 function_state->saved_ast_node_id_); | 448 function_state->saved_ast_node_id_); |
449 } | 449 } |
450 } | 450 } |
451 | 451 |
452 // Helper functions for recursive descent. | 452 // Helper functions for recursive descent. |
453 bool IsEvalOrArguments(Handle<String> identifier) const; | 453 bool IsEvalOrArguments(Handle<String> identifier) const; |
454 | 454 |
| 455 // Returns true if the expression is of type "this.foo". |
| 456 static bool IsThisProperty(Expression* expression); |
| 457 |
455 static bool IsBoilerplateProperty(ObjectLiteral::Property* property) { | 458 static bool IsBoilerplateProperty(ObjectLiteral::Property* property) { |
456 return ObjectLiteral::IsBoilerplateProperty(property); | 459 return ObjectLiteral::IsBoilerplateProperty(property); |
457 } | 460 } |
458 | 461 |
459 static bool IsArrayIndex(Handle<String> string, uint32_t* index) { | 462 static bool IsArrayIndex(Handle<String> string, uint32_t* index) { |
460 return !string.is_null() && string->AsArrayIndex(index); | 463 return !string.is_null() && string->AsArrayIndex(index); |
461 } | 464 } |
462 | 465 |
| 466 // Functions for encapsulating the differences between parsing and preparsing; |
| 467 // operations interleaved with the recursive descent. |
463 static void PushLiteralName(FuncNameInferrer* fni, Handle<String> id) { | 468 static void PushLiteralName(FuncNameInferrer* fni, Handle<String> id) { |
464 fni->PushLiteralName(id); | 469 fni->PushLiteralName(id); |
465 } | 470 } |
466 | 471 |
467 static void CheckFunctionLiteralInsideTopLevelObjectLiteral( | 472 static void CheckFunctionLiteralInsideTopLevelObjectLiteral( |
468 Scope* scope, Expression* value, bool* has_function) { | 473 Scope* scope, Expression* value, bool* has_function) { |
469 if (scope->DeclarationScope()->is_global_scope() && | 474 if (scope->DeclarationScope()->is_global_scope() && |
470 value->AsFunctionLiteral() != NULL) { | 475 value->AsFunctionLiteral() != NULL) { |
471 *has_function = true; | 476 *has_function = true; |
472 value->AsFunctionLiteral()->set_pretenure(); | 477 value->AsFunctionLiteral()->set_pretenure(); |
473 } | 478 } |
474 } | 479 } |
475 | 480 |
| 481 // If we assign a function literal to a property we pretenure the |
| 482 // literal so it can be added as a constant function property. |
| 483 static void CheckAssigningFunctionLiteralToProperty(Expression* left, |
| 484 Expression* right); |
| 485 |
| 486 // Signal a reference error if the expression is an invalid left-hand side |
| 487 // expression. We could report this as a syntax error but for compatibility |
| 488 // with JSC we choose to report the error at runtime. |
| 489 Expression* ValidateAssignmentLeftHandSide(Expression* expression) const; |
| 490 |
| 491 // Determine if the expression is a variable proxy and mark it as being used |
| 492 // in an assignment or with a increment/decrement operator. This is currently |
| 493 // used on for the statically checking assignments to harmony const bindings. |
| 494 static Expression* MarkExpressionAsLValue(Expression* expression); |
| 495 |
| 496 // Checks LHS expression for assignment and prefix/postfix increment/decrement |
| 497 // in strict mode. |
| 498 void CheckStrictModeLValue(Expression*expression, bool* ok); |
| 499 |
476 // Reporting errors. | 500 // Reporting errors. |
477 void ReportMessageAt(Scanner::Location source_location, | 501 void ReportMessageAt(Scanner::Location source_location, |
478 const char* message, | 502 const char* message, |
479 Vector<const char*> args); | 503 Vector<const char*> args); |
480 void ReportMessage(const char* message, Vector<Handle<String> > args); | 504 void ReportMessage(const char* message, Vector<Handle<String> > args); |
481 void ReportMessageAt(Scanner::Location source_location, | 505 void ReportMessageAt(Scanner::Location source_location, |
482 const char* message, | 506 const char* message, |
483 Vector<Handle<String> > args); | 507 Vector<Handle<String> > args); |
484 | 508 |
485 // "null" return type creators. | 509 // "null" return type creators. |
(...skipping 30 matching lines...) Expand all Loading... |
516 int pos, Scanner* scanner, | 540 int pos, Scanner* scanner, |
517 AstNodeFactory<AstConstructionVisitor>* factory); | 541 AstNodeFactory<AstConstructionVisitor>* factory); |
518 ZoneList<v8::internal::Expression*>* NewExpressionList(int size, Zone* zone) { | 542 ZoneList<v8::internal::Expression*>* NewExpressionList(int size, Zone* zone) { |
519 return new(zone) ZoneList<v8::internal::Expression*>(size, zone); | 543 return new(zone) ZoneList<v8::internal::Expression*>(size, zone); |
520 } | 544 } |
521 ZoneList<ObjectLiteral::Property*>* NewPropertyList(int size, Zone* zone) { | 545 ZoneList<ObjectLiteral::Property*>* NewPropertyList(int size, Zone* zone) { |
522 return new(zone) ZoneList<ObjectLiteral::Property*>(size, zone); | 546 return new(zone) ZoneList<ObjectLiteral::Property*>(size, zone); |
523 } | 547 } |
524 | 548 |
525 // Temporary glue; these functions will move to ParserBase. | 549 // Temporary glue; these functions will move to ParserBase. |
526 Expression* ParseAssignmentExpression(bool accept_IN, bool* ok); | |
527 Expression* ParseV8Intrinsic(bool* ok); | 550 Expression* ParseV8Intrinsic(bool* ok); |
528 FunctionLiteral* ParseFunctionLiteral( | 551 FunctionLiteral* ParseFunctionLiteral( |
529 Handle<String> name, | 552 Handle<String> name, |
530 Scanner::Location function_name_location, | 553 Scanner::Location function_name_location, |
531 bool name_is_strict_reserved, | 554 bool name_is_strict_reserved, |
532 bool is_generator, | 555 bool is_generator, |
533 int function_token_position, | 556 int function_token_position, |
534 FunctionLiteral::FunctionType type, | 557 FunctionLiteral::FunctionType type, |
535 bool* ok); | 558 bool* ok); |
| 559 Expression* ParseYieldExpression(bool* ok); |
| 560 Expression* ParseConditionalExpression(bool accept_IN, bool* ok); |
536 | 561 |
537 private: | 562 private: |
538 Parser* parser_; | 563 Parser* parser_; |
539 }; | 564 }; |
540 | 565 |
541 | 566 |
542 class Parser : public ParserBase<ParserTraits> { | 567 class Parser : public ParserBase<ParserTraits> { |
543 public: | 568 public: |
544 explicit Parser(CompilationInfo* info); | 569 explicit Parser(CompilationInfo* info); |
545 ~Parser() { | 570 ~Parser() { |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
668 WhileStatement* ParseWhileStatement(ZoneStringList* labels, bool* ok); | 693 WhileStatement* ParseWhileStatement(ZoneStringList* labels, bool* ok); |
669 Statement* ParseForStatement(ZoneStringList* labels, bool* ok); | 694 Statement* ParseForStatement(ZoneStringList* labels, bool* ok); |
670 Statement* ParseThrowStatement(bool* ok); | 695 Statement* ParseThrowStatement(bool* ok); |
671 Expression* MakeCatchContext(Handle<String> id, VariableProxy* value); | 696 Expression* MakeCatchContext(Handle<String> id, VariableProxy* value); |
672 TryStatement* ParseTryStatement(bool* ok); | 697 TryStatement* ParseTryStatement(bool* ok); |
673 DebuggerStatement* ParseDebuggerStatement(bool* ok); | 698 DebuggerStatement* ParseDebuggerStatement(bool* ok); |
674 | 699 |
675 // Support for hamony block scoped bindings. | 700 // Support for hamony block scoped bindings. |
676 Block* ParseScopedBlock(ZoneStringList* labels, bool* ok); | 701 Block* ParseScopedBlock(ZoneStringList* labels, bool* ok); |
677 | 702 |
678 Expression* ParseAssignmentExpression(bool accept_IN, bool* ok); | |
679 Expression* ParseYieldExpression(bool* ok); | 703 Expression* ParseYieldExpression(bool* ok); |
680 Expression* ParseConditionalExpression(bool accept_IN, bool* ok); | 704 Expression* ParseConditionalExpression(bool accept_IN, bool* ok); |
681 Expression* ParseBinaryExpression(int prec, bool accept_IN, bool* ok); | 705 Expression* ParseBinaryExpression(int prec, bool accept_IN, bool* ok); |
682 Expression* ParseUnaryExpression(bool* ok); | 706 Expression* ParseUnaryExpression(bool* ok); |
683 Expression* ParsePostfixExpression(bool* ok); | 707 Expression* ParsePostfixExpression(bool* ok); |
684 Expression* ParseLeftHandSideExpression(bool* ok); | 708 Expression* ParseLeftHandSideExpression(bool* ok); |
685 Expression* ParseMemberWithNewPrefixesExpression(bool* ok); | 709 Expression* ParseMemberWithNewPrefixesExpression(bool* ok); |
686 Expression* ParseMemberExpression(bool* ok); | 710 Expression* ParseMemberExpression(bool* ok); |
687 Expression* ParseMemberExpressionContinuation(Expression* expression, | 711 Expression* ParseMemberExpressionContinuation(Expression* expression, |
688 bool* ok); | 712 bool* ok); |
(...skipping 15 matching lines...) Expand all Loading... |
704 bool* ok); | 728 bool* ok); |
705 | 729 |
706 // Magical syntax support. | 730 // Magical syntax support. |
707 Expression* ParseV8Intrinsic(bool* ok); | 731 Expression* ParseV8Intrinsic(bool* ok); |
708 | 732 |
709 bool CheckInOrOf(bool accept_OF, ForEachStatement::VisitMode* visit_mode); | 733 bool CheckInOrOf(bool accept_OF, ForEachStatement::VisitMode* visit_mode); |
710 | 734 |
711 // Get odd-ball literals. | 735 // Get odd-ball literals. |
712 Literal* GetLiteralUndefined(int position); | 736 Literal* GetLiteralUndefined(int position); |
713 | 737 |
714 // Determine if the expression is a variable proxy and mark it as being used | |
715 // in an assignment or with a increment/decrement operator. This is currently | |
716 // used on for the statically checking assignments to harmony const bindings. | |
717 void MarkAsLValue(Expression* expression); | |
718 | |
719 // Strict mode validation of LValue expressions | |
720 void CheckStrictModeLValue(Expression* expression, | |
721 bool* ok); | |
722 | |
723 // For harmony block scoping mode: Check if the scope has conflicting var/let | 738 // For harmony block scoping mode: Check if the scope has conflicting var/let |
724 // declarations from different scopes. It covers for example | 739 // declarations from different scopes. It covers for example |
725 // | 740 // |
726 // function f() { { { var x; } let x; } } | 741 // function f() { { { var x; } let x; } } |
727 // function g() { { var x; let x; } } | 742 // function g() { { var x; let x; } } |
728 // | 743 // |
729 // The var declarations are hoisted to the function scope, but originate from | 744 // The var declarations are hoisted to the function scope, but originate from |
730 // a scope where the name has also been let bound or the var declaration is | 745 // a scope where the name has also been let bound or the var declaration is |
731 // hoisted over such a scope. | 746 // hoisted over such a scope. |
732 void CheckConflictingVarDeclarations(Scope* scope, bool* ok); | 747 void CheckConflictingVarDeclarations(Scope* scope, bool* ok); |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
813 private: | 828 private: |
814 static const int kLiteralTypeSlot = 0; | 829 static const int kLiteralTypeSlot = 0; |
815 static const int kElementsSlot = 1; | 830 static const int kElementsSlot = 1; |
816 | 831 |
817 DISALLOW_IMPLICIT_CONSTRUCTORS(CompileTimeValue); | 832 DISALLOW_IMPLICIT_CONSTRUCTORS(CompileTimeValue); |
818 }; | 833 }; |
819 | 834 |
820 } } // namespace v8::internal | 835 } } // namespace v8::internal |
821 | 836 |
822 #endif // V8_PARSER_H_ | 837 #endif // V8_PARSER_H_ |
OLD | NEW |