OLD | NEW |
---|---|
1 // Copyright 2011 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 |
11 // with the distribution. | 11 // with the distribution. |
(...skipping 24 matching lines...) Expand all Loading... | |
36 namespace v8 { | 36 namespace v8 { |
37 namespace internal { | 37 namespace internal { |
38 | 38 |
39 class Processor: public AstVisitor { | 39 class Processor: public AstVisitor { |
40 public: | 40 public: |
41 explicit Processor(Variable* result) | 41 explicit Processor(Variable* result) |
42 : result_(result), | 42 : result_(result), |
43 result_assigned_(false), | 43 result_assigned_(false), |
44 is_set_(false), | 44 is_set_(false), |
45 in_try_(false) { | 45 in_try_(false) { |
46 factory_ = new AstNodeFactory(isolate()); | |
fschneider
2012/01/30 12:10:35
Why not just embed it in the instance? Then there
Jakob Kummerow
2012/02/01 14:46:09
Done.
| |
47 } | |
48 | |
49 virtual ~Processor() { | |
50 delete factory_; | |
46 } | 51 } |
47 | 52 |
48 void Process(ZoneList<Statement*>* statements); | 53 void Process(ZoneList<Statement*>* statements); |
49 bool result_assigned() const { return result_assigned_; } | 54 bool result_assigned() const { return result_assigned_; } |
50 | 55 |
56 AstNodeFactory* factory() { | |
57 return factory_; | |
fschneider
2012/01/30 12:10:35
return &factory_;
Jakob Kummerow
2012/02/01 14:46:09
Done.
| |
58 } | |
59 | |
51 private: | 60 private: |
52 Variable* result_; | 61 Variable* result_; |
53 | 62 |
54 // We are not tracking result usage via the result_'s use | 63 // We are not tracking result usage via the result_'s use |
55 // counts (we leave the accurate computation to the | 64 // counts (we leave the accurate computation to the |
56 // usage analyzer). Instead we simple remember if | 65 // usage analyzer). Instead we simple remember if |
57 // there was ever an assignment to result_. | 66 // there was ever an assignment to result_. |
58 bool result_assigned_; | 67 bool result_assigned_; |
59 | 68 |
60 // To avoid storing to .result all the time, we eliminate some of | 69 // To avoid storing to .result all the time, we eliminate some of |
61 // the stores by keeping track of whether or not we're sure .result | 70 // the stores by keeping track of whether or not we're sure .result |
62 // will be overwritten anyway. This is a bit more tricky than what I | 71 // will be overwritten anyway. This is a bit more tricky than what I |
63 // was hoping for | 72 // was hoping for |
64 bool is_set_; | 73 bool is_set_; |
65 bool in_try_; | 74 bool in_try_; |
66 | 75 |
76 AstNodeFactory* factory_; | |
fschneider
2012/01/30 12:10:35
AstNodeFactory factory_;
Jakob Kummerow
2012/02/01 14:46:09
Done.
| |
77 | |
67 Expression* SetResult(Expression* value) { | 78 Expression* SetResult(Expression* value) { |
68 result_assigned_ = true; | 79 result_assigned_ = true; |
69 Zone* zone = isolate()->zone(); | 80 VariableProxy* result_proxy = factory()->NewVariableProxy(result_); |
70 VariableProxy* result_proxy = new(zone) VariableProxy(isolate(), result_); | 81 return factory()->NewAssignment( |
71 return new(zone) Assignment(isolate(), | 82 Token::ASSIGN, result_proxy, value, RelocInfo::kNoPosition); |
72 Token::ASSIGN, | |
73 result_proxy, | |
74 value, | |
75 RelocInfo::kNoPosition); | |
76 } | 83 } |
77 | 84 |
78 // Node visitors. | 85 // Node visitors. |
79 #define DEF_VISIT(type) \ | 86 #define DEF_VISIT(type) \ |
80 virtual void Visit##type(type* node); | 87 virtual void Visit##type(type* node); |
81 AST_NODE_LIST(DEF_VISIT) | 88 AST_NODE_LIST(DEF_VISIT) |
82 #undef DEF_VISIT | 89 #undef DEF_VISIT |
83 | 90 |
84 void VisitIterationStatement(IterationStatement* stmt); | 91 void VisitIterationStatement(IterationStatement* stmt); |
85 }; | 92 }; |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
230 ZoneList<Statement*>* body = function->body(); | 237 ZoneList<Statement*>* body = function->body(); |
231 if (!body->is_empty()) { | 238 if (!body->is_empty()) { |
232 Variable* result = scope->NewTemporary( | 239 Variable* result = scope->NewTemporary( |
233 info->isolate()->factory()->result_symbol()); | 240 info->isolate()->factory()->result_symbol()); |
234 Processor processor(result); | 241 Processor processor(result); |
235 processor.Process(body); | 242 processor.Process(body); |
236 if (processor.HasStackOverflow()) return false; | 243 if (processor.HasStackOverflow()) return false; |
237 | 244 |
238 if (processor.result_assigned()) { | 245 if (processor.result_assigned()) { |
239 ASSERT(function->end_position() != RelocInfo::kNoPosition); | 246 ASSERT(function->end_position() != RelocInfo::kNoPosition); |
240 Isolate* isolate = info->isolate(); | |
241 Zone* zone = isolate->zone(); | |
242 // Set the position of the assignment statement one character past the | 247 // Set the position of the assignment statement one character past the |
243 // source code, such that it definitely is not in the source code range | 248 // source code, such that it definitely is not in the source code range |
244 // of an immediate inner scope. For example in | 249 // of an immediate inner scope. For example in |
245 // eval('with ({x:1}) x = 1'); | 250 // eval('with ({x:1}) x = 1'); |
246 // the end position of the function generated for executing the eval code | 251 // the end position of the function generated for executing the eval code |
247 // coincides with the end of the with scope which is the position of '1'. | 252 // coincides with the end of the with scope which is the position of '1'. |
248 int position = function->end_position(); | 253 int position = function->end_position(); |
249 VariableProxy* result_proxy = new(zone) VariableProxy( | 254 VariableProxy* result_proxy = processor.factory()->NewVariableProxy( |
250 isolate, result->name(), false, position); | 255 result->name(), false, position); |
251 result_proxy->BindTo(result); | 256 result_proxy->BindTo(result); |
252 Statement* result_statement = new(zone) ReturnStatement(result_proxy); | 257 Statement* result_statement = |
258 processor.factory()->NewReturnStatement(result_proxy); | |
253 result_statement->set_statement_pos(position); | 259 result_statement->set_statement_pos(position); |
254 body->Add(result_statement); | 260 body->Add(result_statement); |
255 } | 261 } |
256 } | 262 } |
257 | 263 |
258 return true; | 264 return true; |
259 } | 265 } |
260 | 266 |
261 | 267 |
262 } } // namespace v8::internal | 268 } } // namespace v8::internal |
OLD | NEW |