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

Side by Side Diff: src/parser.h

Issue 192993002: Move ParseObjectLiteral to ParserBase. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: rebased on top of rossberg@s changes Created 6 years, 9 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/func-name-inferrer.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 21 matching lines...) Expand all
32 #include "ast.h" 32 #include "ast.h"
33 #include "preparse-data-format.h" 33 #include "preparse-data-format.h"
34 #include "preparse-data.h" 34 #include "preparse-data.h"
35 #include "scopes.h" 35 #include "scopes.h"
36 #include "preparser.h" 36 #include "preparser.h"
37 37
38 namespace v8 { 38 namespace v8 {
39 namespace internal { 39 namespace internal {
40 40
41 class CompilationInfo; 41 class CompilationInfo;
42 class FuncNameInferrer;
43 class ParserLog; 42 class ParserLog;
44 class PositionStack; 43 class PositionStack;
45 class Target; 44 class Target;
46 45
47 template <typename T> class ZoneListWrapper; 46 template <typename T> class ZoneListWrapper;
48 47
49 48
50 class FunctionEntry BASE_EMBEDDED { 49 class FunctionEntry BASE_EMBEDDED {
51 public: 50 public:
52 enum { 51 enum {
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after
413 412
414 // Types used by FunctionState and BlockState. 413 // Types used by FunctionState and BlockState.
415 typedef v8::internal::Scope Scope; 414 typedef v8::internal::Scope Scope;
416 typedef AstNodeFactory<AstConstructionVisitor> Factory; 415 typedef AstNodeFactory<AstConstructionVisitor> Factory;
417 typedef Variable GeneratorVariable; 416 typedef Variable GeneratorVariable;
418 typedef v8::internal::Zone Zone; 417 typedef v8::internal::Zone Zone;
419 418
420 // Return types for traversing functions. 419 // Return types for traversing functions.
421 typedef Handle<String> Identifier; 420 typedef Handle<String> Identifier;
422 typedef v8::internal::Expression* Expression; 421 typedef v8::internal::Expression* Expression;
422 typedef v8::internal::FunctionLiteral* FunctionLiteral;
423 typedef v8::internal::Literal* Literal;
424 typedef ObjectLiteral::Property* ObjectLiteralProperty;
423 typedef ZoneList<v8::internal::Expression*>* ExpressionList; 425 typedef ZoneList<v8::internal::Expression*>* ExpressionList;
426 typedef ZoneList<ObjectLiteral::Property*>* PropertyList;
424 }; 427 };
425 428
426 explicit ParserTraits(Parser* parser) : parser_(parser) {} 429 explicit ParserTraits(Parser* parser) : parser_(parser) {}
427 430
428 // Custom operations executed when FunctionStates are created and destructed. 431 // Custom operations executed when FunctionStates are created and destructed.
429 template<typename FunctionState> 432 template<typename FunctionState>
430 static void SetUpFunctionState(FunctionState* function_state, Zone* zone) { 433 static void SetUpFunctionState(FunctionState* function_state, Zone* zone) {
431 Isolate* isolate = zone->isolate(); 434 Isolate* isolate = zone->isolate();
432 function_state->isolate_ = isolate; 435 function_state->isolate_ = isolate;
433 function_state->saved_ast_node_id_ = isolate->ast_node_id(); 436 function_state->saved_ast_node_id_ = isolate->ast_node_id();
434 isolate->set_ast_node_id(BailoutId::FirstUsable().ToInt()); 437 isolate->set_ast_node_id(BailoutId::FirstUsable().ToInt());
435 } 438 }
436 439
437 template<typename FunctionState> 440 template<typename FunctionState>
438 static void TearDownFunctionState(FunctionState* function_state) { 441 static void TearDownFunctionState(FunctionState* function_state) {
439 if (function_state->outer_function_state_ != NULL) { 442 if (function_state->outer_function_state_ != NULL) {
440 function_state->isolate_->set_ast_node_id( 443 function_state->isolate_->set_ast_node_id(
441 function_state->saved_ast_node_id_); 444 function_state->saved_ast_node_id_);
442 } 445 }
443 } 446 }
444 447
445 // Helper functions for recursive descent. 448 // Helper functions for recursive descent.
446 bool IsEvalOrArguments(Handle<String> identifier) const; 449 bool IsEvalOrArguments(Handle<String> identifier) const;
447 450
451 static bool IsBoilerplateProperty(ObjectLiteral::Property* property) {
452 return ObjectLiteral::IsBoilerplateProperty(property);
453 }
454
455 static bool IsArrayIndex(Handle<String> string, uint32_t* index) {
456 return !string.is_null() && string->AsArrayIndex(index);
457 }
458
459 static void PushLiteralName(FuncNameInferrer* fni, Handle<String> id) {
460 fni->PushLiteralName(id);
461 }
462
463 static void CheckFunctionLiteralInsideTopLevelObjectLiteral(
464 Scope* scope, Expression* value, bool* has_function) {
465 if (scope->DeclarationScope()->is_global_scope() &&
466 value->AsFunctionLiteral() != NULL) {
467 *has_function = true;
468 value->AsFunctionLiteral()->set_pretenure();
469 }
470 }
471
448 // Reporting errors. 472 // Reporting errors.
449 void ReportMessageAt(Scanner::Location source_location, 473 void ReportMessageAt(Scanner::Location source_location,
450 const char* message, 474 const char* message,
451 Vector<const char*> args); 475 Vector<const char*> args);
452 void ReportMessage(const char* message, Vector<Handle<String> > args); 476 void ReportMessage(const char* message, Vector<Handle<String> > args);
453 void ReportMessageAt(Scanner::Location source_location, 477 void ReportMessageAt(Scanner::Location source_location,
454 const char* message, 478 const char* message,
455 Vector<Handle<String> > args); 479 Vector<Handle<String> > args);
456 480
457 // "null" return type creators. 481 // "null" return type creators.
458 static Handle<String> EmptyIdentifier() { 482 static Handle<String> EmptyIdentifier() {
459 return Handle<String>(); 483 return Handle<String>();
460 } 484 }
461 static Expression* EmptyExpression() { 485 static Expression* EmptyExpression() {
462 return NULL; 486 return NULL;
463 } 487 }
488 static Literal* EmptyLiteral() {
489 return NULL;
490 }
464 491
465 // Odd-ball literal creators. 492 // Odd-ball literal creators.
466 Literal* GetLiteralTheHole(int position, 493 Literal* GetLiteralTheHole(int position,
467 AstNodeFactory<AstConstructionVisitor>* factory); 494 AstNodeFactory<AstConstructionVisitor>* factory);
468 495
469 // Producing data during the recursive descent. 496 // Producing data during the recursive descent.
470 Handle<String> GetSymbol(Scanner* scanner = NULL); 497 Handle<String> GetSymbol(Scanner* scanner = NULL);
471 Handle<String> NextLiteralString(Scanner* scanner, 498 Handle<String> NextLiteralString(Scanner* scanner,
472 PretenureFlag tenured); 499 PretenureFlag tenured);
473 Expression* ThisExpression(Scope* scope, 500 Expression* ThisExpression(Scope* scope,
474 AstNodeFactory<AstConstructionVisitor>* factory); 501 AstNodeFactory<AstConstructionVisitor>* factory);
475 Expression* ExpressionFromLiteral( 502 Literal* ExpressionFromLiteral(
476 Token::Value token, int pos, Scanner* scanner, 503 Token::Value token, int pos, Scanner* scanner,
477 AstNodeFactory<AstConstructionVisitor>* factory); 504 AstNodeFactory<AstConstructionVisitor>* factory);
478 Expression* ExpressionFromIdentifier( 505 Expression* ExpressionFromIdentifier(
479 Handle<String> name, int pos, Scope* scope, 506 Handle<String> name, int pos, Scope* scope,
480 AstNodeFactory<AstConstructionVisitor>* factory); 507 AstNodeFactory<AstConstructionVisitor>* factory);
481 Expression* ExpressionFromString( 508 Expression* ExpressionFromString(
482 int pos, Scanner* scanner, 509 int pos, Scanner* scanner,
483 AstNodeFactory<AstConstructionVisitor>* factory); 510 AstNodeFactory<AstConstructionVisitor>* factory);
484 ZoneList<v8::internal::Expression*>* NewExpressionList(int size, Zone* zone) { 511 ZoneList<v8::internal::Expression*>* NewExpressionList(int size, Zone* zone) {
485 return new(zone) ZoneList<v8::internal::Expression*>(size, zone); 512 return new(zone) ZoneList<v8::internal::Expression*>(size, zone);
486 } 513 }
514 ZoneList<ObjectLiteral::Property*>* NewPropertyList(int size, Zone* zone) {
515 return new(zone) ZoneList<ObjectLiteral::Property*>(size, zone);
516 }
487 517
488 // Temporary glue; these functions will move to ParserBase. 518 // Temporary glue; these functions will move to ParserBase.
489 Expression* ParseObjectLiteral(bool* ok);
490 Expression* ParseAssignmentExpression(bool accept_IN, bool* ok); 519 Expression* ParseAssignmentExpression(bool accept_IN, bool* ok);
491 Expression* ParseV8Intrinsic(bool* ok); 520 Expression* ParseV8Intrinsic(bool* ok);
521 FunctionLiteral* ParseFunctionLiteral(
522 Handle<String> name,
523 Scanner::Location function_name_location,
524 bool name_is_strict_reserved,
525 bool is_generator,
526 int function_token_position,
527 FunctionLiteral::FunctionType type,
528 bool* ok);
492 529
493 private: 530 private:
494 Parser* parser_; 531 Parser* parser_;
495 }; 532 };
496 533
497 534
498 class Parser : public ParserBase<ParserTraits> { 535 class Parser : public ParserBase<ParserTraits> {
499 public: 536 public:
500 explicit Parser(CompilationInfo* info); 537 explicit Parser(CompilationInfo* info);
501 ~Parser() { 538 ~Parser() {
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
742 779
743 Isolate* isolate_; 780 Isolate* isolate_;
744 ZoneList<Handle<String> > symbol_cache_; 781 ZoneList<Handle<String> > symbol_cache_;
745 782
746 Handle<Script> script_; 783 Handle<Script> script_;
747 Scanner scanner_; 784 Scanner scanner_;
748 PreParser* reusable_preparser_; 785 PreParser* reusable_preparser_;
749 Scope* original_scope_; // for ES5 function declarations in sloppy eval 786 Scope* original_scope_; // for ES5 function declarations in sloppy eval
750 Target* target_stack_; // for break, continue statements 787 Target* target_stack_; // for break, continue statements
751 ScriptDataImpl* pre_parse_data_; 788 ScriptDataImpl* pre_parse_data_;
752 FuncNameInferrer* fni_;
753 789
754 Mode mode_; 790 Mode mode_;
755 791
756 CompilationInfo* info_; 792 CompilationInfo* info_;
757 }; 793 };
758 794
759 795
760 // Support for handling complex values (array and object literals) that 796 // Support for handling complex values (array and object literals) that
761 // can be fully handled at compile time. 797 // can be fully handled at compile time.
762 class CompileTimeValue: public AllStatic { 798 class CompileTimeValue: public AllStatic {
(...skipping 18 matching lines...) Expand all
781 private: 817 private:
782 static const int kLiteralTypeSlot = 0; 818 static const int kLiteralTypeSlot = 0;
783 static const int kElementsSlot = 1; 819 static const int kElementsSlot = 1;
784 820
785 DISALLOW_IMPLICIT_CONSTRUCTORS(CompileTimeValue); 821 DISALLOW_IMPLICIT_CONSTRUCTORS(CompileTimeValue);
786 }; 822 };
787 823
788 } } // namespace v8::internal 824 } } // namespace v8::internal
789 825
790 #endif // V8_PARSER_H_ 826 #endif // V8_PARSER_H_
OLDNEW
« no previous file with comments | « src/func-name-inferrer.h ('k') | src/parser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698