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

Side by Side Diff: src/ast.h

Issue 9460064: Further refactoring of declarations in the AST: (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 8 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/ast.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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
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(FunctionDeclaration) \
64 V(ModuleDeclaration) \ 65 V(ModuleDeclaration) \
65 66
66 #define MODULE_NODE_LIST(V) \ 67 #define MODULE_NODE_LIST(V) \
67 V(ModuleLiteral) \ 68 V(ModuleLiteral) \
68 V(ModuleVariable) \ 69 V(ModuleVariable) \
69 V(ModulePath) \ 70 V(ModulePath) \
70 V(ModuleUrl) 71 V(ModuleUrl)
71 72
72 #define STATEMENT_NODE_LIST(V) \ 73 #define STATEMENT_NODE_LIST(V) \
73 V(Block) \ 74 V(Block) \
(...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after
437 bool is_initializer_block_; 438 bool is_initializer_block_;
438 Scope* block_scope_; 439 Scope* block_scope_;
439 }; 440 };
440 441
441 442
442 class Declaration: public AstNode { 443 class Declaration: public AstNode {
443 public: 444 public:
444 VariableProxy* proxy() const { return proxy_; } 445 VariableProxy* proxy() const { return proxy_; }
445 VariableMode mode() const { return mode_; } 446 VariableMode mode() const { return mode_; }
446 Scope* scope() const { return scope_; } 447 Scope* scope() const { return scope_; }
448 virtual InitializationFlag initialization() const = 0;
447 virtual bool IsInlineable() const; 449 virtual bool IsInlineable() const;
448 450
449 virtual Declaration* AsDeclaration() { return this; } 451 virtual Declaration* AsDeclaration() { return this; }
450 virtual VariableDeclaration* AsVariableDeclaration() { return NULL; }
451 452
452 protected: 453 protected:
453 Declaration(VariableProxy* proxy, 454 Declaration(VariableProxy* proxy,
454 VariableMode mode, 455 VariableMode mode,
455 Scope* scope) 456 Scope* scope)
456 : proxy_(proxy), 457 : proxy_(proxy),
457 mode_(mode), 458 mode_(mode),
458 scope_(scope) { 459 scope_(scope) {
459 ASSERT(mode == VAR || 460 ASSERT(mode == VAR ||
460 mode == CONST || 461 mode == CONST ||
461 mode == CONST_HARMONY || 462 mode == CONST_HARMONY ||
462 mode == LET); 463 mode == LET);
463 } 464 }
464 465
465 private: 466 private:
466 VariableProxy* proxy_; 467 VariableProxy* proxy_;
467 VariableMode mode_; 468 VariableMode mode_;
468 469
469 // Nested scope from which the declaration originated. 470 // Nested scope from which the declaration originated.
470 Scope* scope_; 471 Scope* scope_;
471 }; 472 };
472 473
473 474
474 class VariableDeclaration: public Declaration { 475 class VariableDeclaration: public Declaration {
475 public: 476 public:
476 DECLARE_NODE_TYPE(VariableDeclaration) 477 DECLARE_NODE_TYPE(VariableDeclaration)
477 478
478 virtual VariableDeclaration* AsVariableDeclaration() { return this; } 479 virtual InitializationFlag initialization() const {
479 480 return mode() == VAR ? kCreatedInitialized : kNeedsInitialization;
480 FunctionLiteral* fun() const { return fun_; } // may be NULL 481 }
481 virtual bool IsInlineable() const;
482 482
483 protected: 483 protected:
484 template<class> friend class AstNodeFactory; 484 template<class> friend class AstNodeFactory;
485 485
486 VariableDeclaration(VariableProxy* proxy, 486 VariableDeclaration(VariableProxy* proxy,
487 VariableMode mode, 487 VariableMode mode,
488 Scope* scope)
489 : Declaration(proxy, mode, scope) {
490 }
491 };
492
493
494 class FunctionDeclaration: public Declaration {
495 public:
496 DECLARE_NODE_TYPE(FunctionDeclaration)
497
498 FunctionLiteral* fun() const { return fun_; }
499 virtual InitializationFlag initialization() const {
500 return kCreatedInitialized;
501 }
502 virtual bool IsInlineable() const;
503
504 protected:
505 template<class> friend class AstNodeFactory;
506
507 FunctionDeclaration(VariableProxy* proxy,
508 VariableMode mode,
488 FunctionLiteral* fun, 509 FunctionLiteral* fun,
489 Scope* scope) 510 Scope* scope)
490 : Declaration(proxy, mode, scope), 511 : Declaration(proxy, mode, scope),
491 fun_(fun) { 512 fun_(fun) {
492 // At the moment there are no "const functions"'s in JavaScript... 513 // At the moment there are no "const functions"'s in JavaScript...
Jakob Kummerow 2012/02/27 14:22:18 nit: while you're at it, please s/'s//.
493 ASSERT(fun == NULL || mode == VAR || mode == LET); 514 ASSERT(mode == VAR || mode == LET);
515 ASSERT(fun != NULL);
494 } 516 }
495 517
496 private: 518 private:
497 FunctionLiteral* fun_; 519 FunctionLiteral* fun_;
498 }; 520 };
499 521
500 522
501 class ModuleDeclaration: public Declaration { 523 class ModuleDeclaration: public Declaration {
502 public: 524 public:
503 DECLARE_NODE_TYPE(ModuleDeclaration) 525 DECLARE_NODE_TYPE(ModuleDeclaration)
504 526
505 Module* module() const { return module_; } 527 Module* module() const { return module_; }
528 virtual InitializationFlag initialization() const {
529 return kCreatedInitialized;
530 }
506 531
507 protected: 532 protected:
508 template<class> friend class AstNodeFactory; 533 template<class> friend class AstNodeFactory;
509 534
510 ModuleDeclaration(VariableProxy* proxy, 535 ModuleDeclaration(VariableProxy* proxy,
511 Module* module, 536 Module* module,
512 Scope* scope) 537 Scope* scope)
513 : Declaration(proxy, LET, scope), 538 : Declaration(proxy, LET, scope),
514 module_(module) { 539 module_(module) {
515 } 540 }
(...skipping 1995 matching lines...) Expand 10 before | Expand all | Expand 10 after
2511 zone_(isolate_->zone()) { } 2536 zone_(isolate_->zone()) { }
2512 2537
2513 Visitor* visitor() { return &visitor_; } 2538 Visitor* visitor() { return &visitor_; }
2514 2539
2515 #define VISIT_AND_RETURN(NodeType, node) \ 2540 #define VISIT_AND_RETURN(NodeType, node) \
2516 visitor_.Visit##NodeType((node)); \ 2541 visitor_.Visit##NodeType((node)); \
2517 return node; 2542 return node;
2518 2543
2519 VariableDeclaration* NewVariableDeclaration(VariableProxy* proxy, 2544 VariableDeclaration* NewVariableDeclaration(VariableProxy* proxy,
2520 VariableMode mode, 2545 VariableMode mode,
2546 Scope* scope) {
2547 VariableDeclaration* decl =
2548 new(zone_) VariableDeclaration(proxy, mode, scope);
2549 VISIT_AND_RETURN(VariableDeclaration, decl)
2550 }
2551
2552 FunctionDeclaration* NewFunctionDeclaration(VariableProxy* proxy,
2553 VariableMode mode,
2521 FunctionLiteral* fun, 2554 FunctionLiteral* fun,
2522 Scope* scope) { 2555 Scope* scope) {
2523 VariableDeclaration* decl = 2556 FunctionDeclaration* decl =
2524 new(zone_) VariableDeclaration(proxy, mode, fun, scope); 2557 new(zone_) FunctionDeclaration(proxy, mode, fun, scope);
2525 VISIT_AND_RETURN(VariableDeclaration, decl) 2558 VISIT_AND_RETURN(FunctionDeclaration, decl)
2526 } 2559 }
2527 2560
2528 ModuleDeclaration* NewModuleDeclaration(VariableProxy* proxy, 2561 ModuleDeclaration* NewModuleDeclaration(VariableProxy* proxy,
2529 Module* module, 2562 Module* module,
2530 Scope* scope) { 2563 Scope* scope) {
2531 ModuleDeclaration* decl = 2564 ModuleDeclaration* decl =
2532 new(zone_) ModuleDeclaration(proxy, module, scope); 2565 new(zone_) ModuleDeclaration(proxy, module, scope);
2533 VISIT_AND_RETURN(ModuleDeclaration, decl) 2566 VISIT_AND_RETURN(ModuleDeclaration, decl)
2534 } 2567 }
2535 2568
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after
2826 private: 2859 private:
2827 Isolate* isolate_; 2860 Isolate* isolate_;
2828 Zone* zone_; 2861 Zone* zone_;
2829 Visitor visitor_; 2862 Visitor visitor_;
2830 }; 2863 };
2831 2864
2832 2865
2833 } } // namespace v8::internal 2866 } } // namespace v8::internal
2834 2867
2835 #endif // V8_AST_H_ 2868 #endif // V8_AST_H_
OLDNEW
« no previous file with comments | « no previous file | src/ast.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698