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

Side by Side Diff: src/rewriter.cc

Issue 1399893002: [es7] implement |do| expressions proposal (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: fix AST numbering issue + add simple TF impl 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
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 #include "src/rewriter.h" 5 #include "src/rewriter.h"
6 6
7 #include "src/ast.h" 7 #include "src/ast.h"
8 #include "src/parser.h" 8 #include "src/parser.h"
9 #include "src/scopes.h" 9 #include "src/scopes.h"
10 10
11 namespace v8 { 11 namespace v8 {
12 namespace internal { 12 namespace internal {
13 13
14 class Processor: public AstVisitor { 14 class Processor: public AstVisitor {
15 public: 15 public:
16 Processor(Isolate* isolate, Scope* scope, Variable* result, 16 Processor(Isolate* isolate, Scope* scope, Variable* result,
17 AstValueFactory* ast_value_factory) 17 AstValueFactory* ast_value_factory)
18 : result_(result), 18 : result_(result),
19 result_assigned_(false), 19 result_assigned_(false),
20 replacement_(nullptr), 20 replacement_(nullptr),
21 is_set_(false), 21 is_set_(false),
22 scope_(scope), 22 scope_(scope),
23 factory_(ast_value_factory) { 23 factory_(ast_value_factory) {
24 InitializeAstVisitor(isolate, ast_value_factory->zone()); 24 InitializeAstVisitor(isolate, ast_value_factory->zone());
25 } 25 }
26 26
27 Processor(Parser* parser, Scope* scope, Variable* result,
28 AstValueFactory* ast_value_factory)
29 : result_(result),
30 result_assigned_(false),
31 replacement_(nullptr),
32 is_set_(false),
33 scope_(scope),
34 factory_(ast_value_factory) {
35 InitializeAstVisitor(nullptr, ast_value_factory->zone());
36 parser_ = parser;
37 }
38
27 virtual ~Processor() { } 39 virtual ~Processor() { }
28 40
29 void Process(ZoneList<Statement*>* statements); 41 void Process(ZoneList<Statement*>* statements);
30 bool result_assigned() const { return result_assigned_; } 42 bool result_assigned() const { return result_assigned_; }
31 43
32 Scope* scope() { return scope_; } 44 Scope* scope() { return scope_; }
33 AstNodeFactory* factory() { return &factory_; } 45 AstNodeFactory* factory() { return &factory_; }
34 46
35 private: 47 private:
36 Variable* result_; 48 Variable* result_;
(...skipping 28 matching lines...) Expand all
65 // Inserts '.result = undefined' in front of the given statement. 77 // Inserts '.result = undefined' in front of the given statement.
66 Statement* AssignUndefinedBefore(Statement* s); 78 Statement* AssignUndefinedBefore(Statement* s);
67 79
68 // Node visitors. 80 // Node visitors.
69 #define DEF_VISIT(type) virtual void Visit##type(type* node) override; 81 #define DEF_VISIT(type) virtual void Visit##type(type* node) override;
70 AST_NODE_LIST(DEF_VISIT) 82 AST_NODE_LIST(DEF_VISIT)
71 #undef DEF_VISIT 83 #undef DEF_VISIT
72 84
73 void VisitIterationStatement(IterationStatement* stmt); 85 void VisitIterationStatement(IterationStatement* stmt);
74 86
75 DEFINE_AST_VISITOR_SUBCLASS_MEMBERS(); 87 public:
rossberg 2015/10/12 13:52:40 I think Adam is working on a refactoring for separ
caitp (gmail) 2015/10/12 18:23:00 If that lands first, that would be helpful.
adamk 2015/10/12 19:02:21 I was hoping to get some answers on my v8-dev thre
88 void Visit(AstNode* node) final {
89 if (!CheckStackOverflow()) node->Accept(this);
90 }
91
92 void SetStackOverflow() { stack_overflow_ = true; }
93 void ClearStackOverflow() { stack_overflow_ = false; }
94 bool HasStackOverflow() const { return stack_overflow_; }
95
96 bool CheckStackOverflow() {
97 if (stack_overflow_) return true;
98 if (isolate_) {
99 StackLimitCheck check(isolate_);
100 if (!check.HasOverflowed()) return false;
101 stack_overflow_ = true;
102 } else {
103 if (!parser_->CheckStackOverflow()) return false;
104 stack_overflow_ = true;
105 }
106 return true;
107 }
108
109 private:
110 void InitializeAstVisitor(Isolate* isolate, Zone* zone) {
111 isolate_ = isolate;
112 zone_ = zone;
113 stack_overflow_ = false;
114 }
115 Zone* zone() { return zone_; }
116 Isolate* isolate() { return isolate_; }
117
118 Isolate* isolate_;
119 Parser* parser_;
120 Zone* zone_;
121 bool stack_overflow_;
76 }; 122 };
77 123
78 124
79 Statement* Processor::AssignUndefinedBefore(Statement* s) { 125 Statement* Processor::AssignUndefinedBefore(Statement* s) {
80 Expression* result_proxy = factory()->NewVariableProxy(result_); 126 Expression* result_proxy = factory()->NewVariableProxy(result_);
81 Expression* undef = factory()->NewUndefinedLiteral(RelocInfo::kNoPosition); 127 Expression* undef = factory()->NewUndefinedLiteral(RelocInfo::kNoPosition);
82 Expression* assignment = factory()->NewAssignment( 128 Expression* assignment = factory()->NewAssignment(
83 Token::ASSIGN, result_proxy, undef, RelocInfo::kNoPosition); 129 Token::ASSIGN, result_proxy, undef, RelocInfo::kNoPosition);
84 Block* b = factory()->NewBlock(NULL, 2, false, RelocInfo::kNoPosition); 130 Block* b = factory()->NewBlock(NULL, 2, false, RelocInfo::kNoPosition);
85 b->statements()->Add( 131 b->statements()->Add(
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
352 Statement* result_statement = 398 Statement* result_statement =
353 processor.factory()->NewReturnStatement(result_proxy, pos); 399 processor.factory()->NewReturnStatement(result_proxy, pos);
354 body->Add(result_statement, info->zone()); 400 body->Add(result_statement, info->zone());
355 } 401 }
356 } 402 }
357 403
358 return true; 404 return true;
359 } 405 }
360 406
361 407
408 bool Rewriter::Rewrite(Parser* parser, DoExpression* expr,
409 AstValueFactory* factory) {
410 Scope* scope = expr->scope();
411 ZoneList<Statement*>* body = expr->statements();
412 VariableProxy* result = expr->result();
413 Variable* result_var = result->var();
414
415 if (!body->is_empty()) {
416 Processor processor(parser, scope, result_var, factory);
417 processor.Process(body);
418 if (processor.HasStackOverflow()) return false;
419
420 if (processor.result_assigned()) {
421 DCHECK(!result->is_assigned());
422 result->set_is_assigned();
423 }
424 }
425 return true;
426 }
427
428
362 } // namespace internal 429 } // namespace internal
363 } // namespace v8 430 } // namespace v8
OLDNEW
« src/preparser.h ('K') | « src/rewriter.h ('k') | src/typing.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698