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 442 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
453 } | 453 } |
454 | 454 |
455 // Helper functions for recursive descent. | 455 // Helper functions for recursive descent. |
456 bool IsEvalOrArguments(Handle<String> identifier) const; | 456 bool IsEvalOrArguments(Handle<String> identifier) const; |
457 | 457 |
458 // Returns true if the expression is of type "this.foo". | 458 // Returns true if the expression is of type "this.foo". |
459 static bool IsThisProperty(Expression* expression); | 459 static bool IsThisProperty(Expression* expression); |
460 | 460 |
461 static bool IsIdentifier(Expression* expression); | 461 static bool IsIdentifier(Expression* expression); |
462 | 462 |
| 463 static Handle<String> AsIdentifier(Expression* expression) { |
| 464 ASSERT(IsIdentifier(expression)); |
| 465 return expression->AsVariableProxy()->name(); |
| 466 } |
| 467 |
463 static bool IsBoilerplateProperty(ObjectLiteral::Property* property) { | 468 static bool IsBoilerplateProperty(ObjectLiteral::Property* property) { |
464 return ObjectLiteral::IsBoilerplateProperty(property); | 469 return ObjectLiteral::IsBoilerplateProperty(property); |
465 } | 470 } |
466 | 471 |
467 static bool IsArrayIndex(Handle<String> string, uint32_t* index) { | 472 static bool IsArrayIndex(Handle<String> string, uint32_t* index) { |
468 return !string.is_null() && string->AsArrayIndex(index); | 473 return !string.is_null() && string->AsArrayIndex(index); |
469 } | 474 } |
470 | 475 |
471 // Functions for encapsulating the differences between parsing and preparsing; | 476 // Functions for encapsulating the differences between parsing and preparsing; |
472 // operations interleaved with the recursive descent. | 477 // operations interleaved with the recursive descent. |
(...skipping 19 matching lines...) Expand all Loading... |
492 // Keep track of eval() calls since they disable all local variable | 497 // Keep track of eval() calls since they disable all local variable |
493 // optimizations. This checks if expression is an eval call, and if yes, | 498 // optimizations. This checks if expression is an eval call, and if yes, |
494 // forwards the information to scope. | 499 // forwards the information to scope. |
495 void CheckPossibleEvalCall(Expression* expression, Scope* scope); | 500 void CheckPossibleEvalCall(Expression* expression, Scope* scope); |
496 | 501 |
497 // Determine if the expression is a variable proxy and mark it as being used | 502 // Determine if the expression is a variable proxy and mark it as being used |
498 // in an assignment or with a increment/decrement operator. This is currently | 503 // in an assignment or with a increment/decrement operator. This is currently |
499 // used on for the statically checking assignments to harmony const bindings. | 504 // used on for the statically checking assignments to harmony const bindings. |
500 static Expression* MarkExpressionAsLValue(Expression* expression); | 505 static Expression* MarkExpressionAsLValue(Expression* expression); |
501 | 506 |
502 // Checks LHS expression for assignment and prefix/postfix increment/decrement | |
503 // in strict mode. | |
504 void CheckStrictModeLValue(Expression* expression, bool* ok); | |
505 | |
506 // Returns true if we have a binary expression between two numeric | 507 // Returns true if we have a binary expression between two numeric |
507 // literals. In that case, *x will be changed to an expression which is the | 508 // literals. In that case, *x will be changed to an expression which is the |
508 // computed value. | 509 // computed value. |
509 bool ShortcutNumericLiteralBinaryExpression( | 510 bool ShortcutNumericLiteralBinaryExpression( |
510 Expression** x, Expression* y, Token::Value op, int pos, | 511 Expression** x, Expression* y, Token::Value op, int pos, |
511 AstNodeFactory<AstConstructionVisitor>* factory); | 512 AstNodeFactory<AstConstructionVisitor>* factory); |
512 | 513 |
513 // Rewrites the following types of unary expressions: | 514 // Rewrites the following types of unary expressions: |
514 // not <literal> -> true / false | 515 // not <literal> -> true / false |
515 // + <numeric literal> -> <numeric literal> | 516 // + <numeric literal> -> <numeric literal> |
516 // - <numeric literal> -> <numeric literal with value negated> | 517 // - <numeric literal> -> <numeric literal with value negated> |
517 // ! <literal> -> true / false | 518 // ! <literal> -> true / false |
518 // The following rewriting rules enable the collection of type feedback | 519 // The following rewriting rules enable the collection of type feedback |
519 // without any special stub and the multiplication is removed later in | 520 // without any special stub and the multiplication is removed later in |
520 // Crankshaft's canonicalization pass. | 521 // Crankshaft's canonicalization pass. |
521 // + foo -> foo * 1 | 522 // + foo -> foo * 1 |
522 // - foo -> foo * (-1) | 523 // - foo -> foo * (-1) |
523 // ~ foo -> foo ^(~0) | 524 // ~ foo -> foo ^(~0) |
524 Expression* BuildUnaryExpression( | 525 Expression* BuildUnaryExpression( |
525 Expression* expression, Token::Value op, int pos, | 526 Expression* expression, Token::Value op, int pos, |
526 AstNodeFactory<AstConstructionVisitor>* factory); | 527 AstNodeFactory<AstConstructionVisitor>* factory); |
527 | 528 |
| 529 // Generate AST node that throws a ReferenceError with the given type. |
| 530 Expression* NewThrowReferenceError(const char* type, int pos); |
| 531 |
| 532 // Generate AST node that throws a SyntaxError with the given |
| 533 // type. The first argument may be null (in the handle sense) in |
| 534 // which case no arguments are passed to the constructor. |
| 535 Expression* NewThrowSyntaxError( |
| 536 const char* type, Handle<Object> arg, int pos); |
| 537 |
| 538 // Generate AST node that throws a TypeError with the given |
| 539 // type. Both arguments must be non-null (in the handle sense). |
| 540 Expression* NewThrowTypeError( |
| 541 const char* type, Handle<Object> arg1, Handle<Object> arg2, int pos); |
| 542 |
| 543 // Generic AST generator for throwing errors from compiled code. |
| 544 Expression* NewThrowError( |
| 545 Handle<String> constructor, const char* type, |
| 546 Vector<Handle<Object> > arguments, int pos); |
| 547 |
528 // Reporting errors. | 548 // Reporting errors. |
529 void ReportMessageAt(Scanner::Location source_location, | 549 void ReportMessageAt(Scanner::Location source_location, |
530 const char* message, | 550 const char* message, |
531 Vector<const char*> args, | 551 Vector<const char*> args, |
532 bool is_reference_error = false); | 552 bool is_reference_error = false); |
533 void ReportMessage(const char* message, | 553 void ReportMessage(const char* message, |
534 Vector<Handle<String> > args, | 554 Vector<Handle<String> > args, |
535 bool is_reference_error = false); | 555 bool is_reference_error = false); |
536 void ReportMessageAt(Scanner::Location source_location, | 556 void ReportMessageAt(Scanner::Location source_location, |
537 const char* message, | 557 const char* message, |
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
769 IterationStatement* LookupContinueTarget(Handle<String> label, bool* ok); | 789 IterationStatement* LookupContinueTarget(Handle<String> label, bool* ok); |
770 | 790 |
771 void RegisterTargetUse(Label* target, Target* stop); | 791 void RegisterTargetUse(Label* target, Target* stop); |
772 | 792 |
773 // Factory methods. | 793 // Factory methods. |
774 | 794 |
775 Scope* NewScope(Scope* parent, ScopeType type); | 795 Scope* NewScope(Scope* parent, ScopeType type); |
776 | 796 |
777 Handle<String> LookupCachedSymbol(int symbol_id); | 797 Handle<String> LookupCachedSymbol(int symbol_id); |
778 | 798 |
779 // Generate AST node that throw a ReferenceError with the given type. | |
780 Expression* NewThrowReferenceError(Handle<String> type); | |
781 | |
782 // Generate AST node that throw a SyntaxError with the given | |
783 // type. The first argument may be null (in the handle sense) in | |
784 // which case no arguments are passed to the constructor. | |
785 Expression* NewThrowSyntaxError(Handle<String> type, Handle<Object> first); | |
786 | |
787 // Generate AST node that throw a TypeError with the given | |
788 // type. Both arguments must be non-null (in the handle sense). | |
789 Expression* NewThrowTypeError(Handle<String> type, | |
790 Handle<Object> first, | |
791 Handle<Object> second); | |
792 | |
793 // Generic AST generator for throwing errors from compiled code. | |
794 Expression* NewThrowError(Handle<String> constructor, | |
795 Handle<String> type, | |
796 Vector< Handle<Object> > arguments); | |
797 | |
798 PreParser::PreParseResult LazyParseFunctionLiteral( | 799 PreParser::PreParseResult LazyParseFunctionLiteral( |
799 SingletonLogger* logger); | 800 SingletonLogger* logger); |
800 | 801 |
801 Isolate* isolate_; | 802 Isolate* isolate_; |
802 ZoneList<Handle<String> > symbol_cache_; | 803 ZoneList<Handle<String> > symbol_cache_; |
803 | 804 |
804 Handle<Script> script_; | 805 Handle<Script> script_; |
805 Scanner scanner_; | 806 Scanner scanner_; |
806 PreParser* reusable_preparser_; | 807 PreParser* reusable_preparser_; |
807 Scope* original_scope_; // for ES5 function declarations in sloppy eval | 808 Scope* original_scope_; // for ES5 function declarations in sloppy eval |
(...skipping 29 matching lines...) Expand all Loading... |
837 private: | 838 private: |
838 static const int kLiteralTypeSlot = 0; | 839 static const int kLiteralTypeSlot = 0; |
839 static const int kElementsSlot = 1; | 840 static const int kElementsSlot = 1; |
840 | 841 |
841 DISALLOW_IMPLICIT_CONSTRUCTORS(CompileTimeValue); | 842 DISALLOW_IMPLICIT_CONSTRUCTORS(CompileTimeValue); |
842 }; | 843 }; |
843 | 844 |
844 } } // namespace v8::internal | 845 } } // namespace v8::internal |
845 | 846 |
846 #endif // V8_PARSER_H_ | 847 #endif // V8_PARSER_H_ |
OLD | NEW |