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

Side by Side Diff: src/ast.h

Issue 1399893002: [es7] implement |do| expressions proposal (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Less code duplication in Rewriter Created 5 years, 2 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
« no previous file with comments | « no previous file | src/ast-expression-visitor.cc » ('j') | src/ast-literal-reindexer.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 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef V8_AST_H_ 5 #ifndef V8_AST_H_
6 #define V8_AST_H_ 6 #define V8_AST_H_
7 7
8 #include "src/assembler.h" 8 #include "src/assembler.h"
9 #include "src/ast-value-factory.h" 9 #include "src/ast-value-factory.h"
10 #include "src/bailout-reason.h" 10 #include "src/bailout-reason.h"
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 V(CallRuntime) \ 83 V(CallRuntime) \
84 V(UnaryOperation) \ 84 V(UnaryOperation) \
85 V(CountOperation) \ 85 V(CountOperation) \
86 V(BinaryOperation) \ 86 V(BinaryOperation) \
87 V(CompareOperation) \ 87 V(CompareOperation) \
88 V(Spread) \ 88 V(Spread) \
89 V(ThisFunction) \ 89 V(ThisFunction) \
90 V(SuperPropertyReference) \ 90 V(SuperPropertyReference) \
91 V(SuperCallReference) \ 91 V(SuperCallReference) \
92 V(CaseClause) \ 92 V(CaseClause) \
93 V(EmptyParentheses) 93 V(EmptyParentheses) \
94 V(DoExpression)
94 95
95 #define AST_NODE_LIST(V) \ 96 #define AST_NODE_LIST(V) \
96 DECLARATION_NODE_LIST(V) \ 97 DECLARATION_NODE_LIST(V) \
97 STATEMENT_NODE_LIST(V) \ 98 STATEMENT_NODE_LIST(V) \
98 EXPRESSION_NODE_LIST(V) 99 EXPRESSION_NODE_LIST(V)
99 100
100 // Forward declarations 101 // Forward declarations
101 class AstNodeFactory; 102 class AstNodeFactory;
102 class AstVisitor; 103 class AstVisitor;
103 class Declaration; 104 class Declaration;
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after
483 484
484 private: 485 private:
485 int local_id(int n) const { return base_id() + parent_num_ids() + n; } 486 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
486 487
487 ZoneList<Statement*> statements_; 488 ZoneList<Statement*> statements_;
488 bool ignore_completion_value_; 489 bool ignore_completion_value_;
489 Scope* scope_; 490 Scope* scope_;
490 }; 491 };
491 492
492 493
494 class DoExpression final : public Expression {
495 public:
496 DECLARE_NODE_TYPE(DoExpression)
497
498 Block* block() { return block_; }
499 VariableProxy* result() { return result_; }
500
501 protected:
502 DoExpression(Zone* zone, Block* block, VariableProxy* result, int pos)
503 : Expression(zone, pos), block_(block), result_(result) {
504 DCHECK_NOT_NULL(block_);
505 DCHECK_NOT_NULL(result_);
506 }
507 static int parent_num_ids() { return Expression::num_ids(); }
508
509 private:
510 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
511
512 Block* block_;
513 VariableProxy* result_;
514 };
515
516
493 class Declaration : public AstNode { 517 class Declaration : public AstNode {
494 public: 518 public:
495 VariableProxy* proxy() const { return proxy_; } 519 VariableProxy* proxy() const { return proxy_; }
496 VariableMode mode() const { return mode_; } 520 VariableMode mode() const { return mode_; }
497 Scope* scope() const { return scope_; } 521 Scope* scope() const { return scope_; }
498 virtual InitializationFlag initialization() const = 0; 522 virtual InitializationFlag initialization() const = 0;
499 virtual bool IsInlineable() const; 523 virtual bool IsInlineable() const;
500 524
501 protected: 525 protected:
502 Declaration(Zone* zone, VariableProxy* proxy, VariableMode mode, Scope* scope, 526 Declaration(Zone* zone, VariableProxy* proxy, VariableMode mode, Scope* scope,
(...skipping 2660 matching lines...) Expand 10 before | Expand all | Expand 10 after
3163 virtual void VisitExpressions(ZoneList<Expression*>* expressions); 3187 virtual void VisitExpressions(ZoneList<Expression*>* expressions);
3164 3188
3165 // Individual AST nodes. 3189 // Individual AST nodes.
3166 #define DEF_VISIT(type) \ 3190 #define DEF_VISIT(type) \
3167 virtual void Visit##type(type* node) = 0; 3191 virtual void Visit##type(type* node) = 0;
3168 AST_NODE_LIST(DEF_VISIT) 3192 AST_NODE_LIST(DEF_VISIT)
3169 #undef DEF_VISIT 3193 #undef DEF_VISIT
3170 }; 3194 };
3171 3195
3172 3196
3173 #define DEFINE_AST_VISITOR_SUBCLASS_MEMBERS() \ 3197 #define DEFINE_AST_VISITOR_SUBCLASS_MEMBERS() \
3174 public: \ 3198 public: \
3175 void Visit(AstNode* node) final { \ 3199 void Visit(AstNode* node) final { \
3176 if (!CheckStackOverflow()) node->Accept(this); \ 3200 if (!CheckStackOverflow()) node->Accept(this); \
3177 } \ 3201 } \
3178 \ 3202 \
3179 void SetStackOverflow() { stack_overflow_ = true; } \ 3203 void SetStackOverflow() { stack_overflow_ = true; } \
3180 void ClearStackOverflow() { stack_overflow_ = false; } \ 3204 void ClearStackOverflow() { stack_overflow_ = false; } \
3181 bool HasStackOverflow() const { return stack_overflow_; } \ 3205 bool HasStackOverflow() const { return stack_overflow_; } \
3182 \ 3206 \
3183 bool CheckStackOverflow() { \ 3207 bool CheckStackOverflow() { \
3184 if (stack_overflow_) return true; \ 3208 if (stack_overflow_) return true; \
3185 if (GetCurrentStackPosition() < stack_limit_) { \ 3209 if (GetCurrentStackPosition() < stack_limit_) { \
3186 stack_overflow_ = true; \ 3210 stack_overflow_ = true; \
3187 return true; \ 3211 return true; \
3188 } \ 3212 } \
3189 return false; \ 3213 return false; \
3190 } \ 3214 } \
3191 \ 3215 \
3192 private: \ 3216 private: \
3193 void InitializeAstVisitor(Isolate* isolate, Zone* zone) { \ 3217 void InitializeAstVisitor(Isolate* isolate, Zone* zone) { \
3194 zone_ = zone; \ 3218 zone_ = zone; \
3195 stack_limit_ = isolate->stack_guard()->real_climit(); \ 3219 stack_limit_ = isolate->stack_guard()->real_climit(); \
3196 stack_overflow_ = false; \ 3220 stack_overflow_ = false; \
3197 } \ 3221 } \
3198 Zone* zone() { return zone_; } \ 3222 void InitializeAstVisitor(uintptr_t stack_limit, Zone* zone) { \
3199 \ 3223 zone_ = zone; \
3200 Zone* zone_; \ 3224 stack_limit_ = stack_limit; \
3201 uintptr_t stack_limit_; \ 3225 stack_overflow_ = false; \
3226 } \
3227 Zone* zone() { return zone_; } \
3228 \
3229 Zone* zone_; \
3230 uintptr_t stack_limit_; \
3202 bool stack_overflow_ 3231 bool stack_overflow_
3203 3232
3204 3233
3205 // ---------------------------------------------------------------------------- 3234 // ----------------------------------------------------------------------------
3206 // AstNode factory 3235 // AstNode factory
3207 3236
3208 class AstNodeFactory final BASE_EMBEDDED { 3237 class AstNodeFactory final BASE_EMBEDDED {
3209 public: 3238 public:
3210 explicit AstNodeFactory(AstValueFactory* ast_value_factory) 3239 explicit AstNodeFactory(AstValueFactory* ast_value_factory)
3211 : local_zone_(ast_value_factory->zone()), 3240 : local_zone_(ast_value_factory->zone()),
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after
3577 properties, start_position, end_position); 3606 properties, start_position, end_position);
3578 } 3607 }
3579 3608
3580 NativeFunctionLiteral* NewNativeFunctionLiteral(const AstRawString* name, 3609 NativeFunctionLiteral* NewNativeFunctionLiteral(const AstRawString* name,
3581 v8::Extension* extension, 3610 v8::Extension* extension,
3582 int pos) { 3611 int pos) {
3583 return new (parser_zone_) 3612 return new (parser_zone_)
3584 NativeFunctionLiteral(parser_zone_, name, extension, pos); 3613 NativeFunctionLiteral(parser_zone_, name, extension, pos);
3585 } 3614 }
3586 3615
3616 DoExpression* NewDoExpression(Block* block, Variable* result_var, int pos) {
3617 VariableProxy* result = NewVariableProxy(result_var, pos);
3618 return new (parser_zone_) DoExpression(parser_zone_, block, result, pos);
3619 }
3620
3587 ThisFunction* NewThisFunction(int pos) { 3621 ThisFunction* NewThisFunction(int pos) {
3588 return new (local_zone_) ThisFunction(local_zone_, pos); 3622 return new (local_zone_) ThisFunction(local_zone_, pos);
3589 } 3623 }
3590 3624
3591 SuperPropertyReference* NewSuperPropertyReference(VariableProxy* this_var, 3625 SuperPropertyReference* NewSuperPropertyReference(VariableProxy* this_var,
3592 Expression* home_object, 3626 Expression* home_object,
3593 int pos) { 3627 int pos) {
3594 return new (parser_zone_) 3628 return new (parser_zone_)
3595 SuperPropertyReference(parser_zone_, this_var, home_object, pos); 3629 SuperPropertyReference(parser_zone_, this_var, home_object, pos);
3596 } 3630 }
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
3636 // the parser-level zone. 3670 // the parser-level zone.
3637 Zone* parser_zone_; 3671 Zone* parser_zone_;
3638 AstValueFactory* ast_value_factory_; 3672 AstValueFactory* ast_value_factory_;
3639 }; 3673 };
3640 3674
3641 3675
3642 } // namespace internal 3676 } // namespace internal
3643 } // namespace v8 3677 } // namespace v8
3644 3678
3645 #endif // V8_AST_H_ 3679 #endif // V8_AST_H_
OLDNEW
« no previous file with comments | « no previous file | src/ast-expression-visitor.cc » ('j') | src/ast-literal-reindexer.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698