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

Side by Side Diff: src/parser.h

Issue 149913006: Traitify ParserBase and move functions there. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
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 | « no previous file | src/parser.cc » ('j') | src/parser.cc » ('J')
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 389 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 // Forward declaration.
408 class SingletonLogger; 408 class SingletonLogger;
409 409
410 class Parser : public ParserBase { 410
411 class Parser;
Michael Starzinger 2014/02/10 13:28:03 nit: Can we group this forward declaration togethe
marja 2014/02/10 15:02:07 Done.
412
413 class ParserTraits {
414 public:
415 // Return types for traversing functions.
416 typedef Handle<String> IdentifierType;
417
418 explicit ParserTraits(Parser* parser) : parser_(parser) { }
419
420 // Helper functions for recursive descent.
421 bool is_classic_mode() const;
422 bool is_generator() const;
423 bool IsEvalOrArguments(Handle<String> identifier) const;
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 // Identifiers:
435 static IdentifierType EmptyIdentifier() {
436 return Handle<String>();
437 }
438
439 IdentifierType GetSymbol();
440
441 private:
442 Parser* parser_;
443 };
444
445
446 class Parser : public ParserBase<ParserTraits> {
411 public: 447 public:
412 explicit Parser(CompilationInfo* info); 448 explicit Parser(CompilationInfo* info);
413 ~Parser() { 449 ~Parser() {
414 delete reusable_preparser_; 450 delete reusable_preparser_;
415 reusable_preparser_ = NULL; 451 reusable_preparser_ = NULL;
416 } 452 }
417 453
418 // Parses the source code represented by the compilation info and sets its 454 // Parses the source code represented by the compilation info and sets its
419 // function literal. Returns false (and deallocates any allocated AST 455 // function literal. Returns false (and deallocates any allocated AST
420 // nodes) if parsing failed. 456 // nodes) if parsing failed.
421 static bool Parse(CompilationInfo* info, 457 static bool Parse(CompilationInfo* info,
422 bool allow_lazy = false) { 458 bool allow_lazy = false) {
423 Parser parser(info); 459 Parser parser(info);
424 parser.set_allow_lazy(allow_lazy); 460 parser.set_allow_lazy(allow_lazy);
425 return parser.Parse(); 461 return parser.Parse();
426 } 462 }
427 bool Parse(); 463 bool Parse();
428 464
429 private: 465 private:
466 friend class ParserTraits;
467
430 static const int kMaxNumFunctionLocals = 131071; // 2^17-1 468 static const int kMaxNumFunctionLocals = 131071; // 2^17-1
431 469
432 enum Mode { 470 enum Mode {
433 PARSE_LAZILY, 471 PARSE_LAZILY,
434 PARSE_EAGERLY 472 PARSE_EAGERLY
435 }; 473 };
436 474
437 enum VariableDeclarationContext { 475 enum VariableDeclarationContext {
438 kModuleElement, 476 kModuleElement,
439 kBlockElement, 477 kBlockElement,
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
514 } 552 }
515 ~ParsingModeScope() { 553 ~ParsingModeScope() {
516 parser_->mode_ = old_mode_; 554 parser_->mode_ = old_mode_;
517 } 555 }
518 556
519 private: 557 private:
520 Parser* parser_; 558 Parser* parser_;
521 Mode old_mode_; 559 Mode old_mode_;
522 }; 560 };
523 561
524 virtual bool is_classic_mode() {
525 return top_scope_->is_classic_mode();
526 }
527
528 // Returns NULL if parsing failed. 562 // Returns NULL if parsing failed.
529 FunctionLiteral* ParseProgram(); 563 FunctionLiteral* ParseProgram();
530 564
531 FunctionLiteral* ParseLazy(); 565 FunctionLiteral* ParseLazy();
532 FunctionLiteral* ParseLazy(Utf16CharacterStream* source); 566 FunctionLiteral* ParseLazy(Utf16CharacterStream* source);
533 567
534 Isolate* isolate() { return isolate_; } 568 Isolate* isolate() { return isolate_; }
535 Zone* zone() const { return zone_; } 569 Zone* zone() const { return zone_; }
536 CompilationInfo* info() const { return info_; } 570 CompilationInfo* info() const { return info_; }
537 571
538 // Called by ParseProgram after setting up the scanner. 572 // Called by ParseProgram after setting up the scanner.
539 FunctionLiteral* DoParseProgram(CompilationInfo* info, 573 FunctionLiteral* DoParseProgram(CompilationInfo* info,
540 Handle<String> source); 574 Handle<String> source);
541 575
542 // Report syntax error 576 // Report syntax error
543 void ReportInvalidPreparseData(Handle<String> name, bool* ok); 577 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 578
556 void set_pre_parse_data(ScriptDataImpl *data) { 579 void set_pre_parse_data(ScriptDataImpl *data) {
557 pre_parse_data_ = data; 580 pre_parse_data_ = data;
558 symbol_cache_.Initialize(data ? data->symbol_count() : 0, zone()); 581 symbol_cache_.Initialize(data ? data->symbol_count() : 0, zone());
559 } 582 }
560 583
561 bool inside_with() const { return top_scope_->inside_with(); } 584 bool inside_with() const { return top_scope_->inside_with(); }
562 Scanner& scanner() { return scanner_; } 585 Scanner& scanner() { return scanner_; }
563 Mode mode() const { return mode_; } 586 Mode mode() const { return mode_; }
564 ScriptDataImpl* pre_parse_data() const { return pre_parse_data_; } 587 ScriptDataImpl* pre_parse_data() const { return pre_parse_data_; }
565 bool is_extended_mode() { 588 bool is_extended_mode() {
566 ASSERT(top_scope_ != NULL); 589 ASSERT(top_scope_ != NULL);
567 return top_scope_->is_extended_mode(); 590 return top_scope_->is_extended_mode();
568 } 591 }
569 Scope* DeclarationScope(VariableMode mode) { 592 Scope* DeclarationScope(VariableMode mode) {
570 return IsLexicalVariableMode(mode) 593 return IsLexicalVariableMode(mode)
571 ? top_scope_ : top_scope_->DeclarationScope(); 594 ? top_scope_ : top_scope_->DeclarationScope();
572 } 595 }
573 596
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 597 // All ParseXXX functions take as the last argument an *ok parameter
578 // which is set to false if parsing failed; it is unchanged otherwise. 598 // which is set to false if parsing failed; it is unchanged otherwise.
579 // By making the 'exception handling' explicit, we are forced to check 599 // By making the 'exception handling' explicit, we are forced to check
580 // for failure at the call sites. 600 // for failure at the call sites.
581 void* ParseSourceElements(ZoneList<Statement*>* processor, int end_token, 601 void* ParseSourceElements(ZoneList<Statement*>* processor, int end_token,
582 bool is_eval, bool is_global, bool* ok); 602 bool is_eval, bool is_global, bool* ok);
583 Statement* ParseModuleElement(ZoneStringList* labels, bool* ok); 603 Statement* ParseModuleElement(ZoneStringList* labels, bool* ok);
584 Statement* ParseModuleDeclaration(ZoneStringList* names, bool* ok); 604 Statement* ParseModuleDeclaration(ZoneStringList* names, bool* ok);
585 Module* ParseModule(bool* ok); 605 Module* ParseModule(bool* ok);
586 Module* ParseModuleLiteral(bool* ok); 606 Module* ParseModuleLiteral(bool* ok);
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
653 Scanner::Location function_name_location, 673 Scanner::Location function_name_location,
654 bool name_is_strict_reserved, 674 bool name_is_strict_reserved,
655 bool is_generator, 675 bool is_generator,
656 int function_token_position, 676 int function_token_position,
657 FunctionLiteral::FunctionType type, 677 FunctionLiteral::FunctionType type,
658 bool* ok); 678 bool* ok);
659 679
660 // Magical syntax support. 680 // Magical syntax support.
661 Expression* ParseV8Intrinsic(bool* ok); 681 Expression* ParseV8Intrinsic(bool* ok);
662 682
663 bool is_generator() const { return current_function_state_->is_generator(); }
664
665 bool CheckInOrOf(bool accept_OF, ForEachStatement::VisitMode* visit_mode); 683 bool CheckInOrOf(bool accept_OF, ForEachStatement::VisitMode* visit_mode);
666 684
667 Handle<String> LiteralString(PretenureFlag tenured) { 685 Handle<String> LiteralString(PretenureFlag tenured) {
668 if (scanner().is_literal_ascii()) { 686 if (scanner().is_literal_ascii()) {
669 return isolate_->factory()->NewStringFromAscii( 687 return isolate_->factory()->NewStringFromAscii(
670 scanner().literal_ascii_string(), tenured); 688 scanner().literal_ascii_string(), tenured);
671 } else { 689 } else {
672 return isolate_->factory()->NewStringFromTwoByte( 690 return isolate_->factory()->NewStringFromTwoByte(
673 scanner().literal_utf16_string(), tenured); 691 scanner().literal_utf16_string(), tenured);
674 } 692 }
675 } 693 }
676 694
677 Handle<String> NextLiteralString(PretenureFlag tenured) { 695 Handle<String> NextLiteralString(PretenureFlag tenured) {
678 if (scanner().is_next_literal_ascii()) { 696 if (scanner().is_next_literal_ascii()) {
679 return isolate_->factory()->NewStringFromAscii( 697 return isolate_->factory()->NewStringFromAscii(
680 scanner().next_literal_ascii_string(), tenured); 698 scanner().next_literal_ascii_string(), tenured);
681 } else { 699 } else {
682 return isolate_->factory()->NewStringFromTwoByte( 700 return isolate_->factory()->NewStringFromTwoByte(
683 scanner().next_literal_utf16_string(), tenured); 701 scanner().next_literal_utf16_string(), tenured);
684 } 702 }
685 } 703 }
686 704
687 Handle<String> GetSymbol();
688
689 // Get odd-ball literals. 705 // Get odd-ball literals.
690 Literal* GetLiteralUndefined(int position); 706 Literal* GetLiteralUndefined(int position);
691 Literal* GetLiteralTheHole(int position); 707 Literal* GetLiteralTheHole(int position);
692 708
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 709 // 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 710 // in an assignment or with a increment/decrement operator. This is currently
703 // used on for the statically checking assignments to harmony const bindings. 711 // used on for the statically checking assignments to harmony const bindings.
704 void MarkAsLValue(Expression* expression); 712 void MarkAsLValue(Expression* expression);
705 713
706 // Strict mode validation of LValue expressions 714 // Strict mode validation of LValue expressions
707 void CheckStrictModeLValue(Expression* expression, 715 void CheckStrictModeLValue(Expression* expression,
708 bool* ok); 716 bool* ok);
709 717
710 // For harmony block scoping mode: Check if the scope has conflicting var/let 718 // 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: 824 private:
817 static const int kLiteralTypeSlot = 0; 825 static const int kLiteralTypeSlot = 0;
818 static const int kElementsSlot = 1; 826 static const int kElementsSlot = 1;
819 827
820 DISALLOW_IMPLICIT_CONSTRUCTORS(CompileTimeValue); 828 DISALLOW_IMPLICIT_CONSTRUCTORS(CompileTimeValue);
821 }; 829 };
822 830
823 } } // namespace v8::internal 831 } } // namespace v8::internal
824 832
825 #endif // V8_PARSER_H_ 833 #endif // V8_PARSER_H_
OLDNEW
« no previous file with comments | « no previous file | src/parser.cc » ('j') | src/parser.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698