Chromium Code Reviews| 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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 54 // allocation and constant-time deallocation of the entire syntax | 54 // allocation and constant-time deallocation of the entire syntax |
| 55 // tree. | 55 // tree. |
| 56 | 56 |
| 57 | 57 |
| 58 // ---------------------------------------------------------------------------- | 58 // ---------------------------------------------------------------------------- |
| 59 // Nodes of the abstract syntax tree. Only concrete classes are | 59 // Nodes of the abstract syntax tree. Only concrete classes are |
| 60 // enumerated here. | 60 // enumerated here. |
| 61 | 61 |
| 62 #define DECLARATION_NODE_LIST(V) \ | 62 #define DECLARATION_NODE_LIST(V) \ |
| 63 V(VariableDeclaration) \ | 63 V(VariableDeclaration) \ |
| 64 V(ModuleDeclaration) \ | |
| 65 | |
| 66 #define MODULE_NODE_LIST(V) \ | |
| 67 V(ModuleLiteral) \ | |
| 68 V(ModuleVariable) \ | |
| 69 V(ModulePath) \ | |
| 70 V(ModuleUrl) | |
| 64 | 71 |
| 65 #define STATEMENT_NODE_LIST(V) \ | 72 #define STATEMENT_NODE_LIST(V) \ |
| 66 V(Block) \ | 73 V(Block) \ |
| 67 V(ExpressionStatement) \ | 74 V(ExpressionStatement) \ |
| 68 V(EmptyStatement) \ | 75 V(EmptyStatement) \ |
| 69 V(IfStatement) \ | 76 V(IfStatement) \ |
| 70 V(ContinueStatement) \ | 77 V(ContinueStatement) \ |
| 71 V(BreakStatement) \ | 78 V(BreakStatement) \ |
| 72 V(ReturnStatement) \ | 79 V(ReturnStatement) \ |
| 73 V(WithStatement) \ | 80 V(WithStatement) \ |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 96 V(CallNew) \ | 103 V(CallNew) \ |
| 97 V(CallRuntime) \ | 104 V(CallRuntime) \ |
| 98 V(UnaryOperation) \ | 105 V(UnaryOperation) \ |
| 99 V(CountOperation) \ | 106 V(CountOperation) \ |
| 100 V(BinaryOperation) \ | 107 V(BinaryOperation) \ |
| 101 V(CompareOperation) \ | 108 V(CompareOperation) \ |
| 102 V(ThisFunction) | 109 V(ThisFunction) |
| 103 | 110 |
| 104 #define AST_NODE_LIST(V) \ | 111 #define AST_NODE_LIST(V) \ |
| 105 DECLARATION_NODE_LIST(V) \ | 112 DECLARATION_NODE_LIST(V) \ |
| 113 MODULE_NODE_LIST(V) \ | |
| 106 STATEMENT_NODE_LIST(V) \ | 114 STATEMENT_NODE_LIST(V) \ |
| 107 EXPRESSION_NODE_LIST(V) | 115 EXPRESSION_NODE_LIST(V) |
| 108 | 116 |
| 109 // Forward declarations | 117 // Forward declarations |
| 110 class AstConstructionVisitor; | 118 class AstConstructionVisitor; |
| 111 template<class> class AstNodeFactory; | 119 template<class> class AstNodeFactory; |
| 112 class AstVisitor; | 120 class AstVisitor; |
| 113 class Declaration; | 121 class Declaration; |
| 122 class Module; | |
| 114 class BreakableStatement; | 123 class BreakableStatement; |
| 115 class Expression; | 124 class Expression; |
| 116 class IterationStatement; | 125 class IterationStatement; |
| 117 class MaterializedLiteral; | 126 class MaterializedLiteral; |
| 118 class Statement; | 127 class Statement; |
| 119 class TargetCollector; | 128 class TargetCollector; |
| 120 class TypeFeedbackOracle; | 129 class TypeFeedbackOracle; |
| 121 | 130 |
| 122 class RegExpAlternative; | 131 class RegExpAlternative; |
| 123 class RegExpAssertion; | 132 class RegExpAssertion; |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 294 // code generation. | 303 // code generation. |
| 295 kUninitialized, | 304 kUninitialized, |
| 296 // Evaluated for its side effects. | 305 // Evaluated for its side effects. |
| 297 kEffect, | 306 kEffect, |
| 298 // Evaluated for its value (and side effects). | 307 // Evaluated for its value (and side effects). |
| 299 kValue, | 308 kValue, |
| 300 // Evaluated for control flow (and side effects). | 309 // Evaluated for control flow (and side effects). |
| 301 kTest | 310 kTest |
| 302 }; | 311 }; |
| 303 | 312 |
| 304 explicit Expression(Isolate* isolate) | |
| 305 : id_(GetNextId(isolate)), | |
| 306 test_id_(GetNextId(isolate)) {} | |
| 307 | |
| 308 virtual int position() const { | 313 virtual int position() const { |
| 309 UNREACHABLE(); | 314 UNREACHABLE(); |
| 310 return 0; | 315 return 0; |
| 311 } | 316 } |
| 312 | 317 |
| 313 virtual Expression* AsExpression() { return this; } | 318 virtual Expression* AsExpression() { return this; } |
| 314 | 319 |
| 315 virtual bool IsValidLeftHandSide() { return false; } | 320 virtual bool IsValidLeftHandSide() { return false; } |
| 316 | 321 |
| 317 // Helpers for ToBoolean conversion. | 322 // Helpers for ToBoolean conversion. |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 348 Handle<Map> GetMonomorphicReceiverType() { | 353 Handle<Map> GetMonomorphicReceiverType() { |
| 349 ASSERT(IsMonomorphic()); | 354 ASSERT(IsMonomorphic()); |
| 350 SmallMapList* types = GetReceiverTypes(); | 355 SmallMapList* types = GetReceiverTypes(); |
| 351 ASSERT(types != NULL && types->length() == 1); | 356 ASSERT(types != NULL && types->length() == 1); |
| 352 return types->at(0); | 357 return types->at(0); |
| 353 } | 358 } |
| 354 | 359 |
| 355 unsigned id() const { return id_; } | 360 unsigned id() const { return id_; } |
| 356 unsigned test_id() const { return test_id_; } | 361 unsigned test_id() const { return test_id_; } |
| 357 | 362 |
| 363 protected: | |
| 364 explicit Expression(Isolate* isolate) | |
| 365 : id_(GetNextId(isolate)), | |
| 366 test_id_(GetNextId(isolate)) {} | |
| 367 | |
| 358 private: | 368 private: |
| 359 int id_; | 369 int id_; |
| 360 int test_id_; | 370 int test_id_; |
| 361 }; | 371 }; |
| 362 | 372 |
| 363 | 373 |
| 364 class BreakableStatement: public Statement { | 374 class BreakableStatement: public Statement { |
| 365 public: | 375 public: |
| 366 enum Type { | 376 enum Type { |
| 367 TARGET_FOR_ANONYMOUS, | 377 TARGET_FOR_ANONYMOUS, |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 488 fun_(fun) { | 498 fun_(fun) { |
| 489 // At the moment there are no "const functions"'s in JavaScript... | 499 // At the moment there are no "const functions"'s in JavaScript... |
| 490 ASSERT(fun == NULL || mode == VAR || mode == LET); | 500 ASSERT(fun == NULL || mode == VAR || mode == LET); |
| 491 } | 501 } |
| 492 | 502 |
| 493 private: | 503 private: |
| 494 FunctionLiteral* fun_; | 504 FunctionLiteral* fun_; |
| 495 }; | 505 }; |
| 496 | 506 |
| 497 | 507 |
| 508 class ModuleDeclaration: public Declaration { | |
| 509 public: | |
| 510 DECLARE_NODE_TYPE(ModuleDeclaration) | |
| 511 | |
| 512 Module* module() const { return module_; } | |
| 513 | |
| 514 protected: | |
| 515 template<class> friend class AstNodeFactory; | |
| 516 | |
| 517 ModuleDeclaration(VariableProxy* proxy, | |
| 518 Module* module, | |
| 519 Scope* scope) | |
| 520 : Declaration(proxy, LET, scope), | |
| 521 module_(module) { | |
| 522 } | |
| 523 | |
| 524 private: | |
| 525 Module* module_; | |
| 526 }; | |
| 527 | |
| 528 | |
| 529 class Module: public AstNode { | |
| 530 // TODO(rossberg): stuff to come... | |
| 531 protected: | |
| 532 Module() {} | |
| 533 }; | |
| 534 | |
| 535 | |
| 536 class ModuleLiteral: public Module { | |
| 537 public: | |
| 538 DECLARE_NODE_TYPE(ModuleLiteral) | |
| 539 | |
| 540 Block* body() const { return body_; } | |
| 541 | |
| 542 protected: | |
| 543 template<class> friend class AstNodeFactory; | |
| 544 | |
| 545 ModuleLiteral(Block* body) | |
| 546 : body_(body) { | |
| 547 } | |
| 548 | |
| 549 private: | |
| 550 Block* body_; | |
| 551 }; | |
| 552 | |
| 553 | |
| 554 class ModuleVariable: public Module { | |
| 555 public: | |
| 556 DECLARE_NODE_TYPE(ModuleVariable) | |
| 557 | |
| 558 Variable* var() const { return var_; } | |
| 559 | |
| 560 protected: | |
| 561 template<class> friend class AstNodeFactory; | |
| 562 | |
| 563 ModuleVariable(Variable* var) | |
| 564 : var_(var) { | |
| 565 } | |
| 566 | |
| 567 private: | |
| 568 Variable* var_; | |
| 569 }; | |
| 570 | |
| 571 | |
| 572 class ModulePath: public Module { | |
| 573 public: | |
| 574 DECLARE_NODE_TYPE(ModulePath) | |
| 575 | |
| 576 Module* module() const { return module_; } | |
| 577 Handle<String> name() const { return name_; } | |
| 578 | |
| 579 protected: | |
| 580 template<class> friend class AstNodeFactory; | |
| 581 | |
| 582 ModulePath(Module* module, Handle<String> name) | |
| 583 : module_(module), | |
| 584 name_(name) { | |
| 585 } | |
| 586 | |
| 587 private: | |
| 588 Module* module_; | |
| 589 Handle<String> name_; | |
| 590 }; | |
| 591 | |
| 592 | |
| 593 class ModuleUrl: public Module { | |
| 594 public: | |
| 595 DECLARE_NODE_TYPE(ModuleUrl) | |
| 596 | |
| 597 Handle<String> url() const { return url_; } | |
| 598 | |
| 599 protected: | |
| 600 template<class> friend class AstNodeFactory; | |
| 601 | |
| 602 ModuleUrl(Handle<String> url) : url_(url) { | |
| 603 } | |
| 604 | |
| 605 private: | |
| 606 Handle<String> url_; | |
| 607 }; | |
| 608 | |
| 609 | |
| 498 class IterationStatement: public BreakableStatement { | 610 class IterationStatement: public BreakableStatement { |
| 499 public: | 611 public: |
| 500 // Type testing & conversion. | 612 // Type testing & conversion. |
| 501 virtual IterationStatement* AsIterationStatement() { return this; } | 613 virtual IterationStatement* AsIterationStatement() { return this; } |
| 502 | 614 |
| 503 Statement* body() const { return body_; } | 615 Statement* body() const { return body_; } |
| 504 | 616 |
| 505 // Bailout support. | 617 // Bailout support. |
| 506 int OsrEntryId() const { return osr_entry_id_; } | 618 int OsrEntryId() const { return osr_entry_id_; } |
| 507 virtual int ContinueId() const = 0; | 619 virtual int ContinueId() const = 0; |
| (...skipping 1885 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2393 | 2505 |
| 2394 VariableDeclaration* NewVariableDeclaration(VariableProxy* proxy, | 2506 VariableDeclaration* NewVariableDeclaration(VariableProxy* proxy, |
| 2395 VariableMode mode, | 2507 VariableMode mode, |
| 2396 FunctionLiteral* fun, | 2508 FunctionLiteral* fun, |
| 2397 Scope* scope) { | 2509 Scope* scope) { |
| 2398 VariableDeclaration* decl = | 2510 VariableDeclaration* decl = |
| 2399 new(zone_) VariableDeclaration(proxy, mode, fun, scope); | 2511 new(zone_) VariableDeclaration(proxy, mode, fun, scope); |
| 2400 VISIT_AND_RETURN(VariableDeclaration, decl) | 2512 VISIT_AND_RETURN(VariableDeclaration, decl) |
| 2401 } | 2513 } |
| 2402 | 2514 |
| 2515 ModuleDeclaration* NewModuleDeclaration(VariableProxy* proxy, | |
| 2516 Module* module, | |
| 2517 Scope* scope) { | |
| 2518 ModuleDeclaration* decl = | |
| 2519 new(zone_) ModuleDeclaration(proxy, module, scope); | |
| 2520 VISIT_AND_RETURN(ModuleDeclaration, decl) | |
|
Jakob Kummerow
2012/02/09 13:18:35
You'll want to implement the matching Visit____ me
rossberg
2012/02/09 13:26:31
Done.
| |
| 2521 } | |
| 2522 | |
| 2523 ModuleLiteral* NewModuleLiteral(Block* body) { | |
| 2524 ModuleLiteral* module = new(zone_) ModuleLiteral(body); | |
| 2525 VISIT_AND_RETURN(ModuleLiteral, module) | |
| 2526 } | |
| 2527 | |
| 2528 ModuleVariable* NewModuleVariable(Variable* var) { | |
| 2529 ModuleVariable* module = new(zone_) ModuleVariable(var); | |
| 2530 VISIT_AND_RETURN(ModuleLiteral, module) | |
| 2531 } | |
| 2532 | |
| 2533 ModulePath* NewModulePath(Module* origin, Handle<String> name) { | |
| 2534 ModulePath* module = new(zone_) ModulePath(origin, name); | |
| 2535 VISIT_AND_RETURN(ModuleLiteral, module) | |
| 2536 } | |
| 2537 | |
| 2538 ModuleUrl* NewModuleUrl(Handle<String> url) { | |
| 2539 ModuleUrl* module = new(zone_) ModuleUrl(url); | |
| 2540 VISIT_AND_RETURN(ModuleLiteral, module) | |
| 2541 } | |
| 2542 | |
| 2403 Block* NewBlock(ZoneStringList* labels, | 2543 Block* NewBlock(ZoneStringList* labels, |
| 2404 int capacity, | 2544 int capacity, |
| 2405 bool is_initializer_block) { | 2545 bool is_initializer_block) { |
| 2406 Block* block = new(zone_) Block( | 2546 Block* block = new(zone_) Block( |
| 2407 isolate_, labels, capacity, is_initializer_block); | 2547 isolate_, labels, capacity, is_initializer_block); |
| 2408 VISIT_AND_RETURN(Block, block) | 2548 VISIT_AND_RETURN(Block, block) |
| 2409 } | 2549 } |
| 2410 | 2550 |
| 2411 #define STATEMENT_WITH_LABELS(NodeType) \ | 2551 #define STATEMENT_WITH_LABELS(NodeType) \ |
| 2412 NodeType* New##NodeType(ZoneStringList* labels) { \ | 2552 NodeType* New##NodeType(ZoneStringList* labels) { \ |
| (...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2672 private: | 2812 private: |
| 2673 Isolate* isolate_; | 2813 Isolate* isolate_; |
| 2674 Zone* zone_; | 2814 Zone* zone_; |
| 2675 Visitor visitor_; | 2815 Visitor visitor_; |
| 2676 }; | 2816 }; |
| 2677 | 2817 |
| 2678 | 2818 |
| 2679 } } // namespace v8::internal | 2819 } } // namespace v8::internal |
| 2680 | 2820 |
| 2681 #endif // V8_AST_H_ | 2821 #endif // V8_AST_H_ |
| OLD | NEW |