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

Side by Side Diff: src/parser.h

Issue 159933002: A64: Synchronize with r19289. (Closed) Base URL: https://v8.googlecode.com/svn/branches/experimental/a64
Patch Set: Created 6 years, 10 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
« no previous file with comments | « src/objects-visiting-inl.h ('k') | src/parser.cc » ('j') | 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 // 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 386 matching lines...) Expand 10 before | Expand all | Expand 10 after
397 bool multiline_; 397 bool multiline_;
398 bool simple_; 398 bool simple_;
399 bool contains_anchor_; 399 bool contains_anchor_;
400 bool is_scanned_for_captures_; 400 bool is_scanned_for_captures_;
401 bool failed_; 401 bool failed_;
402 }; 402 };
403 403
404 // ---------------------------------------------------------------------------- 404 // ----------------------------------------------------------------------------
405 // JAVASCRIPT PARSING 405 // JAVASCRIPT PARSING
406 406
407 // Forward declaration. 407 class Parser;
408 class SingletonLogger; 408 class SingletonLogger;
409 409
410 class Parser : public ParserBase { 410 class ParserTraits {
411 public:
412 typedef Parser* ParserType;
413 // Return types for traversing functions.
414 typedef Handle<String> IdentifierType;
415 typedef Expression* ExpressionType;
416
417 explicit ParserTraits(Parser* parser) : parser_(parser) {}
418
419 // Helper functions for recursive descent.
420 bool is_classic_mode() const;
421 bool is_generator() const;
422 bool IsEvalOrArguments(Handle<String> identifier) const;
423 int NextMaterializedLiteralIndex();
424
425 // Reporting errors.
426 void ReportMessageAt(Scanner::Location source_location,
427 const char* message,
428 Vector<const char*> args);
429 void ReportMessage(const char* message, Vector<Handle<String> > args);
430 void ReportMessageAt(Scanner::Location source_location,
431 const char* message,
432 Vector<Handle<String> > args);
433
434 // "null" return type creators.
435 static IdentifierType EmptyIdentifier() {
436 return Handle<String>();
437 }
438 static ExpressionType EmptyExpression() {
439 return NULL;
440 }
441
442 // Producing data during the recursive descent.
443 IdentifierType GetSymbol();
444 IdentifierType NextLiteralString(PretenureFlag tenured);
445 ExpressionType NewRegExpLiteral(IdentifierType js_pattern,
446 IdentifierType js_flags,
447 int literal_index,
448 int pos);
449
450 private:
451 Parser* parser_;
452 };
453
454
455 class Parser : public ParserBase<ParserTraits> {
411 public: 456 public:
412 explicit Parser(CompilationInfo* info); 457 explicit Parser(CompilationInfo* info);
413 ~Parser() { 458 ~Parser() {
414 delete reusable_preparser_; 459 delete reusable_preparser_;
415 reusable_preparser_ = NULL; 460 reusable_preparser_ = NULL;
416 } 461 }
417 462
418 // Parses the source code represented by the compilation info and sets its 463 // Parses the source code represented by the compilation info and sets its
419 // function literal. Returns false (and deallocates any allocated AST 464 // function literal. Returns false (and deallocates any allocated AST
420 // nodes) if parsing failed. 465 // nodes) if parsing failed.
421 static bool Parse(CompilationInfo* info, 466 static bool Parse(CompilationInfo* info,
422 bool allow_lazy = false) { 467 bool allow_lazy = false) {
423 Parser parser(info); 468 Parser parser(info);
424 parser.set_allow_lazy(allow_lazy); 469 parser.set_allow_lazy(allow_lazy);
425 return parser.Parse(); 470 return parser.Parse();
426 } 471 }
427 bool Parse(); 472 bool Parse();
428 473
429 private: 474 private:
475 friend class ParserTraits;
476
430 static const int kMaxNumFunctionLocals = 131071; // 2^17-1 477 static const int kMaxNumFunctionLocals = 131071; // 2^17-1
431 478
432 enum Mode { 479 enum Mode {
433 PARSE_LAZILY, 480 PARSE_LAZILY,
434 PARSE_EAGERLY 481 PARSE_EAGERLY
435 }; 482 };
436 483
437 enum VariableDeclarationContext { 484 enum VariableDeclarationContext {
438 kModuleElement, 485 kModuleElement,
439 kBlockElement, 486 kBlockElement,
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
514 } 561 }
515 ~ParsingModeScope() { 562 ~ParsingModeScope() {
516 parser_->mode_ = old_mode_; 563 parser_->mode_ = old_mode_;
517 } 564 }
518 565
519 private: 566 private:
520 Parser* parser_; 567 Parser* parser_;
521 Mode old_mode_; 568 Mode old_mode_;
522 }; 569 };
523 570
524 virtual bool is_classic_mode() {
525 return top_scope_->is_classic_mode();
526 }
527
528 // Returns NULL if parsing failed. 571 // Returns NULL if parsing failed.
529 FunctionLiteral* ParseProgram(); 572 FunctionLiteral* ParseProgram();
530 573
531 FunctionLiteral* ParseLazy(); 574 FunctionLiteral* ParseLazy();
532 FunctionLiteral* ParseLazy(Utf16CharacterStream* source); 575 FunctionLiteral* ParseLazy(Utf16CharacterStream* source);
533 576
534 Isolate* isolate() { return isolate_; } 577 Isolate* isolate() { return isolate_; }
535 Zone* zone() const { return zone_; } 578 Zone* zone() const { return zone_; }
536 CompilationInfo* info() const { return info_; } 579 CompilationInfo* info() const { return info_; }
537 580
538 // Called by ParseProgram after setting up the scanner. 581 // Called by ParseProgram after setting up the scanner.
539 FunctionLiteral* DoParseProgram(CompilationInfo* info, 582 FunctionLiteral* DoParseProgram(CompilationInfo* info,
540 Handle<String> source); 583 Handle<String> source);
541 584
542 // Report syntax error 585 // Report syntax error
543 void ReportInvalidPreparseData(Handle<String> name, bool* ok); 586 void ReportInvalidPreparseData(Handle<String> name, bool* ok);
544 void ReportMessage(const char* message, Vector<const char*> args);
545 void ReportMessage(const char* message, Vector<Handle<String> > args);
546 void ReportMessageAt(Scanner::Location location, const char* type) {
547 ReportMessageAt(location, type, Vector<const char*>::empty());
548 }
549 void ReportMessageAt(Scanner::Location loc,
550 const char* message,
551 Vector<const char*> args);
552 void ReportMessageAt(Scanner::Location loc,
553 const char* message,
554 Vector<Handle<String> > args);
555 587
556 void set_pre_parse_data(ScriptDataImpl *data) { 588 void set_pre_parse_data(ScriptDataImpl *data) {
557 pre_parse_data_ = data; 589 pre_parse_data_ = data;
558 symbol_cache_.Initialize(data ? data->symbol_count() : 0, zone()); 590 symbol_cache_.Initialize(data ? data->symbol_count() : 0, zone());
559 } 591 }
560 592
561 bool inside_with() const { return top_scope_->inside_with(); } 593 bool inside_with() const { return top_scope_->inside_with(); }
562 Scanner& scanner() { return scanner_; } 594 Scanner& scanner() { return scanner_; }
563 Mode mode() const { return mode_; } 595 Mode mode() const { return mode_; }
564 ScriptDataImpl* pre_parse_data() const { return pre_parse_data_; } 596 ScriptDataImpl* pre_parse_data() const { return pre_parse_data_; }
565 bool is_extended_mode() { 597 bool is_extended_mode() {
566 ASSERT(top_scope_ != NULL); 598 ASSERT(top_scope_ != NULL);
567 return top_scope_->is_extended_mode(); 599 return top_scope_->is_extended_mode();
568 } 600 }
569 Scope* DeclarationScope(VariableMode mode) { 601 Scope* DeclarationScope(VariableMode mode) {
570 return IsLexicalVariableMode(mode) 602 return IsLexicalVariableMode(mode)
571 ? top_scope_ : top_scope_->DeclarationScope(); 603 ? top_scope_ : top_scope_->DeclarationScope();
572 } 604 }
573 605
574 // Check if the given string is 'eval' or 'arguments'.
575 bool IsEvalOrArguments(Handle<String> string);
576
577 // All ParseXXX functions take as the last argument an *ok parameter 606 // All ParseXXX functions take as the last argument an *ok parameter
578 // which is set to false if parsing failed; it is unchanged otherwise. 607 // which is set to false if parsing failed; it is unchanged otherwise.
579 // By making the 'exception handling' explicit, we are forced to check 608 // By making the 'exception handling' explicit, we are forced to check
580 // for failure at the call sites. 609 // for failure at the call sites.
581 void* ParseSourceElements(ZoneList<Statement*>* processor, int end_token, 610 void* ParseSourceElements(ZoneList<Statement*>* processor, int end_token,
582 bool is_eval, bool is_global, bool* ok); 611 bool is_eval, bool is_global, bool* ok);
583 Statement* ParseModuleElement(ZoneStringList* labels, bool* ok); 612 Statement* ParseModuleElement(ZoneStringList* labels, bool* ok);
584 Statement* ParseModuleDeclaration(ZoneStringList* names, bool* ok); 613 Statement* ParseModuleDeclaration(ZoneStringList* names, bool* ok);
585 Module* ParseModule(bool* ok); 614 Module* ParseModule(bool* ok);
586 Module* ParseModuleLiteral(bool* ok); 615 Module* ParseModuleLiteral(bool* ok);
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
632 Expression* ParsePostfixExpression(bool* ok); 661 Expression* ParsePostfixExpression(bool* ok);
633 Expression* ParseLeftHandSideExpression(bool* ok); 662 Expression* ParseLeftHandSideExpression(bool* ok);
634 Expression* ParseNewExpression(bool* ok); 663 Expression* ParseNewExpression(bool* ok);
635 Expression* ParseMemberExpression(bool* ok); 664 Expression* ParseMemberExpression(bool* ok);
636 Expression* ParseNewPrefix(PositionStack* stack, bool* ok); 665 Expression* ParseNewPrefix(PositionStack* stack, bool* ok);
637 Expression* ParseMemberWithNewPrefixesExpression(PositionStack* stack, 666 Expression* ParseMemberWithNewPrefixesExpression(PositionStack* stack,
638 bool* ok); 667 bool* ok);
639 Expression* ParsePrimaryExpression(bool* ok); 668 Expression* ParsePrimaryExpression(bool* ok);
640 Expression* ParseArrayLiteral(bool* ok); 669 Expression* ParseArrayLiteral(bool* ok);
641 Expression* ParseObjectLiteral(bool* ok); 670 Expression* ParseObjectLiteral(bool* ok);
642 Expression* ParseRegExpLiteral(bool seen_equal, bool* ok);
643 671
644 // Initialize the components of a for-in / for-of statement. 672 // Initialize the components of a for-in / for-of statement.
645 void InitializeForEachStatement(ForEachStatement* stmt, 673 void InitializeForEachStatement(ForEachStatement* stmt,
646 Expression* each, 674 Expression* each,
647 Expression* subject, 675 Expression* subject,
648 Statement* body); 676 Statement* body);
649 677
650 ZoneList<Expression*>* ParseArguments(bool* ok); 678 ZoneList<Expression*>* ParseArguments(bool* ok);
651 FunctionLiteral* ParseFunctionLiteral( 679 FunctionLiteral* ParseFunctionLiteral(
652 Handle<String> name, 680 Handle<String> name,
653 Scanner::Location function_name_location, 681 Scanner::Location function_name_location,
654 bool name_is_strict_reserved, 682 bool name_is_strict_reserved,
655 bool is_generator, 683 bool is_generator,
656 int function_token_position, 684 int function_token_position,
657 FunctionLiteral::FunctionType type, 685 FunctionLiteral::FunctionType type,
658 bool* ok); 686 bool* ok);
659 687
660 // Magical syntax support. 688 // Magical syntax support.
661 Expression* ParseV8Intrinsic(bool* ok); 689 Expression* ParseV8Intrinsic(bool* ok);
662 690
663 bool is_generator() const { return current_function_state_->is_generator(); }
664
665 bool CheckInOrOf(bool accept_OF, ForEachStatement::VisitMode* visit_mode); 691 bool CheckInOrOf(bool accept_OF, ForEachStatement::VisitMode* visit_mode);
666 692
667 Handle<String> LiteralString(PretenureFlag tenured) { 693 Handle<String> LiteralString(PretenureFlag tenured) {
668 if (scanner().is_literal_ascii()) { 694 if (scanner().is_literal_ascii()) {
669 return isolate_->factory()->NewStringFromAscii( 695 return isolate_->factory()->NewStringFromAscii(
670 scanner().literal_ascii_string(), tenured); 696 scanner().literal_ascii_string(), tenured);
671 } else { 697 } else {
672 return isolate_->factory()->NewStringFromTwoByte( 698 return isolate_->factory()->NewStringFromTwoByte(
673 scanner().literal_utf16_string(), tenured); 699 scanner().literal_utf16_string(), tenured);
674 } 700 }
675 } 701 }
676 702
677 Handle<String> NextLiteralString(PretenureFlag tenured) {
678 if (scanner().is_next_literal_ascii()) {
679 return isolate_->factory()->NewStringFromAscii(
680 scanner().next_literal_ascii_string(), tenured);
681 } else {
682 return isolate_->factory()->NewStringFromTwoByte(
683 scanner().next_literal_utf16_string(), tenured);
684 }
685 }
686
687 Handle<String> GetSymbol();
688
689 // Get odd-ball literals. 703 // Get odd-ball literals.
690 Literal* GetLiteralUndefined(int position); 704 Literal* GetLiteralUndefined(int position);
691 Literal* GetLiteralTheHole(int position); 705 Literal* GetLiteralTheHole(int position);
692 706
693 Handle<String> ParseIdentifier(AllowEvalOrArgumentsAsIdentifier, bool* ok);
694 Handle<String> ParseIdentifierOrStrictReservedWord(
695 bool* is_strict_reserved, bool* ok);
696 Handle<String> ParseIdentifierName(bool* ok);
697 Handle<String> ParseIdentifierNameOrGetOrSet(bool* is_get,
698 bool* is_set,
699 bool* ok);
700
701 // Determine if the expression is a variable proxy and mark it as being used 707 // Determine if the expression is a variable proxy and mark it as being used
702 // in an assignment or with a increment/decrement operator. This is currently 708 // in an assignment or with a increment/decrement operator. This is currently
703 // used on for the statically checking assignments to harmony const bindings. 709 // used on for the statically checking assignments to harmony const bindings.
704 void MarkAsLValue(Expression* expression); 710 void MarkAsLValue(Expression* expression);
705 711
706 // Strict mode validation of LValue expressions 712 // Strict mode validation of LValue expressions
707 void CheckStrictModeLValue(Expression* expression, 713 void CheckStrictModeLValue(Expression* expression,
708 bool* ok); 714 bool* ok);
709 715
710 // For harmony block scoping mode: Check if the scope has conflicting var/let 716 // For harmony block scoping mode: Check if the scope has conflicting var/let
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
816 private: 822 private:
817 static const int kLiteralTypeSlot = 0; 823 static const int kLiteralTypeSlot = 0;
818 static const int kElementsSlot = 1; 824 static const int kElementsSlot = 1;
819 825
820 DISALLOW_IMPLICIT_CONSTRUCTORS(CompileTimeValue); 826 DISALLOW_IMPLICIT_CONSTRUCTORS(CompileTimeValue);
821 }; 827 };
822 828
823 } } // namespace v8::internal 829 } } // namespace v8::internal
824 830
825 #endif // V8_PARSER_H_ 831 #endif // V8_PARSER_H_
OLDNEW
« no previous file with comments | « src/objects-visiting-inl.h ('k') | src/parser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698