OLD | NEW |
1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2010 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 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
381 // Linked list implementation of stack of states. | 381 // Linked list implementation of stack of states. |
382 RegExpParserState* previous_state_; | 382 RegExpParserState* previous_state_; |
383 // Builder for the stored disjunction. | 383 // Builder for the stored disjunction. |
384 RegExpBuilder* builder_; | 384 RegExpBuilder* builder_; |
385 // Stored disjunction type (capture, look-ahead or grouping), if any. | 385 // Stored disjunction type (capture, look-ahead or grouping), if any. |
386 SubexpressionType group_type_; | 386 SubexpressionType group_type_; |
387 // Stored disjunction's capture index (if any). | 387 // Stored disjunction's capture index (if any). |
388 int disjunction_capture_index_; | 388 int disjunction_capture_index_; |
389 }; | 389 }; |
390 | 390 |
| 391 Isolate* isolate() { return isolate_; } |
| 392 |
391 uc32 current() { return current_; } | 393 uc32 current() { return current_; } |
392 bool has_more() { return has_more_; } | 394 bool has_more() { return has_more_; } |
393 bool has_next() { return next_pos_ < in()->length(); } | 395 bool has_next() { return next_pos_ < in()->length(); } |
394 uc32 Next(); | 396 uc32 Next(); |
395 FlatStringReader* in() { return in_; } | 397 FlatStringReader* in() { return in_; } |
396 void ScanForCaptures(); | 398 void ScanForCaptures(); |
397 | 399 |
| 400 Isolate* isolate_; |
398 Handle<String>* error_; | 401 Handle<String>* error_; |
399 ZoneList<RegExpCapture*>* captures_; | 402 ZoneList<RegExpCapture*>* captures_; |
400 FlatStringReader* in_; | 403 FlatStringReader* in_; |
401 uc32 current_; | 404 uc32 current_; |
402 int next_pos_; | 405 int next_pos_; |
403 // The capture count is only valid after we have scanned for captures. | 406 // The capture count is only valid after we have scanned for captures. |
404 int capture_count_; | 407 int capture_count_; |
405 bool has_more_; | 408 bool has_more_; |
406 bool multiline_; | 409 bool multiline_; |
407 bool simple_; | 410 bool simple_; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
442 // should be checked. | 445 // should be checked. |
443 static const int kMaxNumFunctionParameters = 32766; | 446 static const int kMaxNumFunctionParameters = 32766; |
444 FunctionLiteral* ParseLazy(CompilationInfo* info, | 447 FunctionLiteral* ParseLazy(CompilationInfo* info, |
445 UC16CharacterStream* source, | 448 UC16CharacterStream* source, |
446 ZoneScope* zone_scope); | 449 ZoneScope* zone_scope); |
447 enum Mode { | 450 enum Mode { |
448 PARSE_LAZILY, | 451 PARSE_LAZILY, |
449 PARSE_EAGERLY | 452 PARSE_EAGERLY |
450 }; | 453 }; |
451 | 454 |
| 455 Isolate* isolate() { return isolate_; } |
| 456 |
452 // Called by ParseProgram after setting up the scanner. | 457 // Called by ParseProgram after setting up the scanner. |
453 FunctionLiteral* DoParseProgram(Handle<String> source, | 458 FunctionLiteral* DoParseProgram(Handle<String> source, |
454 bool in_global_context, | 459 bool in_global_context, |
455 StrictModeFlag strict_mode, | 460 StrictModeFlag strict_mode, |
456 ZoneScope* zone_scope); | 461 ZoneScope* zone_scope); |
457 | 462 |
458 // Report syntax error | 463 // Report syntax error |
459 void ReportUnexpectedToken(Token::Value token); | 464 void ReportUnexpectedToken(Token::Value token); |
460 void ReportInvalidPreparseData(Handle<String> name, bool* ok); | 465 void ReportInvalidPreparseData(Handle<String> name, bool* ok); |
461 void ReportMessage(const char* message, Vector<const char*> args); | 466 void ReportMessage(const char* message, Vector<const char*> args); |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
567 return scanner().peek(); | 572 return scanner().peek(); |
568 } | 573 } |
569 | 574 |
570 INLINE(Token::Value Next()) { | 575 INLINE(Token::Value Next()) { |
571 // BUG 1215673: Find a thread safe way to set a stack limit in | 576 // BUG 1215673: Find a thread safe way to set a stack limit in |
572 // pre-parse mode. Otherwise, we cannot safely pre-parse from other | 577 // pre-parse mode. Otherwise, we cannot safely pre-parse from other |
573 // threads. | 578 // threads. |
574 if (stack_overflow_) { | 579 if (stack_overflow_) { |
575 return Token::ILLEGAL; | 580 return Token::ILLEGAL; |
576 } | 581 } |
577 if (StackLimitCheck().HasOverflowed()) { | 582 if (StackLimitCheck(isolate()).HasOverflowed()) { |
578 // Any further calls to Next or peek will return the illegal token. | 583 // Any further calls to Next or peek will return the illegal token. |
579 // The current call must return the next token, which might already | 584 // The current call must return the next token, which might already |
580 // have been peek'ed. | 585 // have been peek'ed. |
581 stack_overflow_ = true; | 586 stack_overflow_ = true; |
582 } | 587 } |
583 return scanner().Next(); | 588 return scanner().Next(); |
584 } | 589 } |
585 | 590 |
586 bool peek_any_identifier(); | 591 bool peek_any_identifier(); |
587 | 592 |
588 INLINE(void Consume(Token::Value token)); | 593 INLINE(void Consume(Token::Value token)); |
589 void Expect(Token::Value token, bool* ok); | 594 void Expect(Token::Value token, bool* ok); |
590 bool Check(Token::Value token); | 595 bool Check(Token::Value token); |
591 void ExpectSemicolon(bool* ok); | 596 void ExpectSemicolon(bool* ok); |
592 | 597 |
593 Handle<String> LiteralString(PretenureFlag tenured) { | 598 Handle<String> LiteralString(PretenureFlag tenured) { |
594 if (scanner().is_literal_ascii()) { | 599 if (scanner().is_literal_ascii()) { |
595 return Factory::NewStringFromAscii(scanner().literal_ascii_string(), | 600 return isolate_->factory()->NewStringFromAscii( |
596 tenured); | 601 scanner().literal_ascii_string(), tenured); |
597 } else { | 602 } else { |
598 return Factory::NewStringFromTwoByte(scanner().literal_uc16_string(), | 603 return isolate_->factory()->NewStringFromTwoByte( |
599 tenured); | 604 scanner().literal_uc16_string(), tenured); |
600 } | 605 } |
601 } | 606 } |
602 | 607 |
603 Handle<String> NextLiteralString(PretenureFlag tenured) { | 608 Handle<String> NextLiteralString(PretenureFlag tenured) { |
604 if (scanner().is_next_literal_ascii()) { | 609 if (scanner().is_next_literal_ascii()) { |
605 return Factory::NewStringFromAscii(scanner().next_literal_ascii_string(), | 610 return isolate_->factory()->NewStringFromAscii( |
606 tenured); | 611 scanner().next_literal_ascii_string(), tenured); |
607 } else { | 612 } else { |
608 return Factory::NewStringFromTwoByte(scanner().next_literal_uc16_string(), | 613 return isolate_->factory()->NewStringFromTwoByte( |
609 tenured); | 614 scanner().next_literal_uc16_string(), tenured); |
610 } | 615 } |
611 } | 616 } |
612 | 617 |
613 Handle<String> GetSymbol(bool* ok); | 618 Handle<String> GetSymbol(bool* ok); |
614 | 619 |
615 // Get odd-ball literals. | 620 // Get odd-ball literals. |
616 Literal* GetLiteralUndefined(); | 621 Literal* GetLiteralUndefined(); |
617 Literal* GetLiteralTheHole(); | 622 Literal* GetLiteralTheHole(); |
618 Literal* GetLiteralNumber(double value); | 623 Literal* GetLiteralNumber(double value); |
619 | 624 |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
679 // type. Both arguments must be non-null (in the handle sense). | 684 // type. Both arguments must be non-null (in the handle sense). |
680 Expression* NewThrowTypeError(Handle<String> type, | 685 Expression* NewThrowTypeError(Handle<String> type, |
681 Handle<Object> first, | 686 Handle<Object> first, |
682 Handle<Object> second); | 687 Handle<Object> second); |
683 | 688 |
684 // Generic AST generator for throwing errors from compiled code. | 689 // Generic AST generator for throwing errors from compiled code. |
685 Expression* NewThrowError(Handle<String> constructor, | 690 Expression* NewThrowError(Handle<String> constructor, |
686 Handle<String> type, | 691 Handle<String> type, |
687 Vector< Handle<Object> > arguments); | 692 Vector< Handle<Object> > arguments); |
688 | 693 |
| 694 Isolate* isolate_; |
689 ZoneList<Handle<String> > symbol_cache_; | 695 ZoneList<Handle<String> > symbol_cache_; |
690 | 696 |
691 Handle<Script> script_; | 697 Handle<Script> script_; |
692 V8JavaScriptScanner scanner_; | 698 V8JavaScriptScanner scanner_; |
693 | 699 |
694 Scope* top_scope_; | 700 Scope* top_scope_; |
695 int with_nesting_level_; | 701 int with_nesting_level_; |
696 | 702 |
697 TemporaryScope* temp_scope_; | 703 TemporaryScope* temp_scope_; |
698 Mode mode_; | 704 Mode mode_; |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
758 ExternalTwoByteStringUC16CharacterStream stream( | 764 ExternalTwoByteStringUC16CharacterStream stream( |
759 Handle<ExternalTwoByteString>::cast(source), 0, source->length()); | 765 Handle<ExternalTwoByteString>::cast(source), 0, source->length()); |
760 return JsonParser().ParseJson(source, &stream); | 766 return JsonParser().ParseJson(source, &stream); |
761 } else { | 767 } else { |
762 GenericStringUC16CharacterStream stream(source, 0, source->length()); | 768 GenericStringUC16CharacterStream stream(source, 0, source->length()); |
763 return JsonParser().ParseJson(source, &stream); | 769 return JsonParser().ParseJson(source, &stream); |
764 } | 770 } |
765 } | 771 } |
766 | 772 |
767 private: | 773 private: |
768 JsonParser() { } | 774 JsonParser() : isolate_(Isolate::Current()), scanner_(isolate_) { } |
769 ~JsonParser() { } | 775 ~JsonParser() { } |
770 | 776 |
| 777 Isolate* isolate() { return isolate_; } |
| 778 |
771 // Parse a string containing a single JSON value. | 779 // Parse a string containing a single JSON value. |
772 Handle<Object> ParseJson(Handle<String> script, UC16CharacterStream* source); | 780 Handle<Object> ParseJson(Handle<String> script, UC16CharacterStream* source); |
773 // Parse a single JSON value from input (grammar production JSONValue). | 781 // Parse a single JSON value from input (grammar production JSONValue). |
774 // A JSON value is either a (double-quoted) string literal, a number literal, | 782 // A JSON value is either a (double-quoted) string literal, a number literal, |
775 // one of "true", "false", or "null", or an object or array literal. | 783 // one of "true", "false", or "null", or an object or array literal. |
776 Handle<Object> ParseJsonValue(); | 784 Handle<Object> ParseJsonValue(); |
777 // Parse a JSON object literal (grammar production JSONObject). | 785 // Parse a JSON object literal (grammar production JSONObject). |
778 // An object literal is a squiggly-braced and comma separated sequence | 786 // An object literal is a squiggly-braced and comma separated sequence |
779 // (possibly empty) of key/value pairs, where the key is a JSON string | 787 // (possibly empty) of key/value pairs, where the key is a JSON string |
780 // literal, the value is a JSON value, and the two are separated by a colon. | 788 // literal, the value is a JSON value, and the two are separated by a colon. |
781 // A JSON array dosn't allow numbers and identifiers as keys, like a | 789 // A JSON array dosn't allow numbers and identifiers as keys, like a |
782 // JavaScript array. | 790 // JavaScript array. |
783 Handle<Object> ParseJsonObject(); | 791 Handle<Object> ParseJsonObject(); |
784 // Parses a JSON array literal (grammar production JSONArray). An array | 792 // Parses a JSON array literal (grammar production JSONArray). An array |
785 // literal is a square-bracketed and comma separated sequence (possibly empty) | 793 // literal is a square-bracketed and comma separated sequence (possibly empty) |
786 // of JSON values. | 794 // of JSON values. |
787 // A JSON array doesn't allow leaving out values from the sequence, nor does | 795 // A JSON array doesn't allow leaving out values from the sequence, nor does |
788 // it allow a terminal comma, like a JavaScript array does. | 796 // it allow a terminal comma, like a JavaScript array does. |
789 Handle<Object> ParseJsonArray(); | 797 Handle<Object> ParseJsonArray(); |
790 | 798 |
791 // Mark that a parsing error has happened at the current token, and | 799 // Mark that a parsing error has happened at the current token, and |
792 // return a null handle. Primarily for readability. | 800 // return a null handle. Primarily for readability. |
793 Handle<Object> ReportUnexpectedToken() { return Handle<Object>::null(); } | 801 Handle<Object> ReportUnexpectedToken() { return Handle<Object>::null(); } |
794 // Converts the currently parsed literal to a JavaScript String. | 802 // Converts the currently parsed literal to a JavaScript String. |
795 Handle<String> GetString(); | 803 Handle<String> GetString(); |
796 | 804 |
| 805 Isolate* isolate_; |
797 JsonScanner scanner_; | 806 JsonScanner scanner_; |
798 bool stack_overflow_; | 807 bool stack_overflow_; |
799 }; | 808 }; |
800 } } // namespace v8::internal | 809 } } // namespace v8::internal |
801 | 810 |
802 #endif // V8_PARSER_H_ | 811 #endif // V8_PARSER_H_ |
OLD | NEW |