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

Side by Side Diff: src/parsing/rewriter.cc

Issue 2142233003: Templatize AstVisitor with its subclass (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Addressed comments Created 4 years, 5 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 | « src/parsing/preparser.h ('k') | no next file » | 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 // 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/parsing/rewriter.h" 5 #include "src/parsing/rewriter.h"
6 6
7 #include "src/ast/ast.h" 7 #include "src/ast/ast.h"
8 #include "src/ast/scopes.h" 8 #include "src/ast/scopes.h"
9 #include "src/parsing/parser.h" 9 #include "src/parsing/parser.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 final : public AstVisitor<Processor> {
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 zone_(ast_value_factory->zone()), 22 zone_(ast_value_factory->zone()),
23 scope_(scope), 23 scope_(scope),
24 factory_(ast_value_factory) { 24 factory_(ast_value_factory) {
25 InitializeAstVisitor(isolate); 25 InitializeAstVisitor(isolate);
26 } 26 }
27 27
28 Processor(Parser* parser, Scope* scope, Variable* result, 28 Processor(Parser* parser, Scope* scope, Variable* result,
29 AstValueFactory* ast_value_factory) 29 AstValueFactory* ast_value_factory)
30 : result_(result), 30 : result_(result),
31 result_assigned_(false), 31 result_assigned_(false),
32 replacement_(nullptr), 32 replacement_(nullptr),
33 is_set_(false), 33 is_set_(false),
34 zone_(ast_value_factory->zone()), 34 zone_(ast_value_factory->zone()),
35 scope_(scope), 35 scope_(scope),
36 factory_(ast_value_factory) { 36 factory_(ast_value_factory) {
37 InitializeAstVisitor(parser->stack_limit()); 37 InitializeAstVisitor(parser->stack_limit());
38 } 38 }
39 39
40 ~Processor() override {}
41
42 void Process(ZoneList<Statement*>* statements); 40 void Process(ZoneList<Statement*>* statements);
43 bool result_assigned() const { return result_assigned_; } 41 bool result_assigned() const { return result_assigned_; }
44 42
45 Zone* zone() { return zone_; } 43 Zone* zone() { return zone_; }
46 Scope* scope() { return scope_; } 44 Scope* scope() { return scope_; }
47 AstNodeFactory* factory() { return &factory_; } 45 AstNodeFactory* factory() { return &factory_; }
48 46
49 // Returns ".result = value" 47 // Returns ".result = value"
50 Expression* SetResult(Expression* value) { 48 Expression* SetResult(Expression* value) {
51 result_assigned_ = true; 49 result_assigned_ = true;
(...skipping 22 matching lines...) Expand all
74 // the stores by keeping track of whether or not we're sure .result 72 // the stores by keeping track of whether or not we're sure .result
75 // will be overwritten anyway. This is a bit more tricky than what I 73 // will be overwritten anyway. This is a bit more tricky than what I
76 // was hoping for. 74 // was hoping for.
77 bool is_set_; 75 bool is_set_;
78 76
79 Zone* zone_; 77 Zone* zone_;
80 Scope* scope_; 78 Scope* scope_;
81 AstNodeFactory factory_; 79 AstNodeFactory factory_;
82 80
83 // Node visitors. 81 // Node visitors.
84 #define DEF_VISIT(type) void Visit##type(type* node) override; 82 #define DEF_VISIT(type) void Visit##type(type* node);
85 AST_NODE_LIST(DEF_VISIT) 83 AST_NODE_LIST(DEF_VISIT)
86 #undef DEF_VISIT 84 #undef DEF_VISIT
87 85
88 void VisitIterationStatement(IterationStatement* stmt); 86 void VisitIterationStatement(IterationStatement* stmt);
89 87
90 DEFINE_AST_VISITOR_SUBCLASS_MEMBERS(); 88 DEFINE_AST_VISITOR_SUBCLASS_MEMBERS();
91 }; 89 };
92 90
93 91
94 Statement* Processor::AssignUndefinedBefore(Statement* s) { 92 Statement* Processor::AssignUndefinedBefore(Statement* s) {
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 processor.SetResult(undef), expr->position()); 383 processor.SetResult(undef), expr->position());
386 body->Add(completion, factory->zone()); 384 body->Add(completion, factory->zone());
387 } 385 }
388 } 386 }
389 return true; 387 return true;
390 } 388 }
391 389
392 390
393 } // namespace internal 391 } // namespace internal
394 } // namespace v8 392 } // namespace v8
OLDNEW
« no previous file with comments | « src/parsing/preparser.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698