OLD | NEW |
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/v8.h" | 5 #include "src/v8.h" |
6 | 6 |
7 #include "src/rewriter.h" | 7 #include "src/rewriter.h" |
8 | 8 |
9 #include "src/ast.h" | 9 #include "src/ast.h" |
10 #include "src/compiler.h" | 10 #include "src/compiler.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 in_try_(false), | 22 in_try_(false), |
23 factory_(ast_value_factory) { | 23 factory_(ast_value_factory) { |
24 InitializeAstVisitor(ast_value_factory->zone()); | 24 InitializeAstVisitor(ast_value_factory->zone()); |
25 } | 25 } |
26 | 26 |
27 virtual ~Processor() { } | 27 virtual ~Processor() { } |
28 | 28 |
29 void Process(ZoneList<Statement*>* statements); | 29 void Process(ZoneList<Statement*>* statements); |
30 bool result_assigned() const { return result_assigned_; } | 30 bool result_assigned() const { return result_assigned_; } |
31 | 31 |
32 AstNodeFactory<AstNullVisitor>* factory() { | 32 AstNodeFactory* factory() { return &factory_; } |
33 return &factory_; | |
34 } | |
35 | 33 |
36 private: | 34 private: |
37 Variable* result_; | 35 Variable* result_; |
38 | 36 |
39 // We are not tracking result usage via the result_'s use | 37 // We are not tracking result usage via the result_'s use |
40 // counts (we leave the accurate computation to the | 38 // counts (we leave the accurate computation to the |
41 // usage analyzer). Instead we simple remember if | 39 // usage analyzer). Instead we simple remember if |
42 // there was ever an assignment to result_. | 40 // there was ever an assignment to result_. |
43 bool result_assigned_; | 41 bool result_assigned_; |
44 | 42 |
45 // To avoid storing to .result all the time, we eliminate some of | 43 // To avoid storing to .result all the time, we eliminate some of |
46 // the stores by keeping track of whether or not we're sure .result | 44 // the stores by keeping track of whether or not we're sure .result |
47 // will be overwritten anyway. This is a bit more tricky than what I | 45 // will be overwritten anyway. This is a bit more tricky than what I |
48 // was hoping for | 46 // was hoping for |
49 bool is_set_; | 47 bool is_set_; |
50 bool in_try_; | 48 bool in_try_; |
51 | 49 |
52 AstNodeFactory<AstNullVisitor> factory_; | 50 AstNodeFactory factory_; |
53 | 51 |
54 Expression* SetResult(Expression* value) { | 52 Expression* SetResult(Expression* value) { |
55 result_assigned_ = true; | 53 result_assigned_ = true; |
56 VariableProxy* result_proxy = factory()->NewVariableProxy(result_); | 54 VariableProxy* result_proxy = factory()->NewVariableProxy(result_); |
57 return factory()->NewAssignment( | 55 return factory()->NewAssignment( |
58 Token::ASSIGN, result_proxy, value, RelocInfo::kNoPosition); | 56 Token::ASSIGN, result_proxy, value, RelocInfo::kNoPosition); |
59 } | 57 } |
60 | 58 |
61 // Node visitors. | 59 // Node visitors. |
62 #define DEF_VISIT(type) \ | 60 #define DEF_VISIT(type) \ |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
257 processor.factory()->NewReturnStatement(result_proxy, pos); | 255 processor.factory()->NewReturnStatement(result_proxy, pos); |
258 body->Add(result_statement, info->zone()); | 256 body->Add(result_statement, info->zone()); |
259 } | 257 } |
260 } | 258 } |
261 | 259 |
262 return true; | 260 return true; |
263 } | 261 } |
264 | 262 |
265 | 263 |
266 } } // namespace v8::internal | 264 } } // namespace v8::internal |
OLD | NEW |