OLD | NEW |
---|---|
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #include <map> | 5 #include <map> |
6 #include <set> | 6 #include <set> |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "vm/kernel_to_il.h" | 9 #include "vm/kernel_to_il.h" |
10 | 10 |
(...skipping 13 matching lines...) Expand all Loading... | |
24 DECLARE_FLAG(bool, support_externalizable_strings); | 24 DECLARE_FLAG(bool, support_externalizable_strings); |
25 | 25 |
26 namespace kernel { | 26 namespace kernel { |
27 | 27 |
28 #define Z (zone_) | 28 #define Z (zone_) |
29 #define H (translation_helper_) | 29 #define H (translation_helper_) |
30 #define T (type_translator_) | 30 #define T (type_translator_) |
31 #define I Isolate::Current() | 31 #define I Isolate::Current() |
32 | 32 |
33 | 33 |
34 class NeedExprTempVisitor : public RecursiveVisitor { | |
35 public: | |
36 NeedExprTempVisitor() : need_expr_temp_(false) {} | |
37 | |
38 virtual void VisitConditionalExpression(ConditionalExpression* node) { | |
39 need_expr_temp_ = true; | |
40 } | |
41 | |
42 virtual void VisitLogicalExpression(LogicalExpression* node) { | |
43 need_expr_temp_ = true; | |
44 } | |
45 | |
46 bool NeedTemp() const { return need_expr_temp_; } | |
Vyacheslav Egorov (Google)
2017/03/27 14:31:46
nit: style guide suggests naming simple getters li
| |
47 | |
48 private: | |
49 bool need_expr_temp_; | |
Vyacheslav Egorov (Google)
2017/03/27 14:31:46
better name is needs_expr_temp_.
| |
50 }; | |
51 | |
52 | |
53 bool NeedExprTemp(TreeNode* node) { | |
Vyacheslav Egorov (Google)
2017/03/27 14:31:46
static bool NeedsExprTemp(...)
| |
54 NeedExprTempVisitor visitor; | |
55 node->AcceptVisitor(&visitor); | |
56 return visitor.NeedTemp(); | |
57 } | |
58 | |
59 | |
34 static void DiscoverEnclosingElements(Zone* zone, | 60 static void DiscoverEnclosingElements(Zone* zone, |
35 const Function& function, | 61 const Function& function, |
36 Function* outermost_function, | 62 Function* outermost_function, |
37 TreeNode** outermost_node, | 63 TreeNode** outermost_node, |
38 Class** klass) { | 64 Class** klass) { |
39 // Find out if there is an enclosing kernel class (which will be used to | 65 // Find out if there is an enclosing kernel class (which will be used to |
40 // resolve type parameters). | 66 // resolve type parameters). |
41 *outermost_function = function.raw(); | 67 *outermost_function = function.raw(); |
42 while (outermost_function->parent_function() != Object::null()) { | 68 while (outermost_function->parent_function() != Object::null()) { |
43 *outermost_function = outermost_function->parent_function(); | 69 *outermost_function = outermost_function->parent_function(); |
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
293 enclosing_scope = LocalScope::RestoreOuterScope( | 319 enclosing_scope = LocalScope::RestoreOuterScope( |
294 ContextScope::Handle(Z, function.context_scope())); | 320 ContextScope::Handle(Z, function.context_scope())); |
295 } | 321 } |
296 current_function_scope_ = scope_ = new (Z) LocalScope(enclosing_scope, 0, 0); | 322 current_function_scope_ = scope_ = new (Z) LocalScope(enclosing_scope, 0, 0); |
297 scope_->set_begin_token_pos(function.token_pos()); | 323 scope_->set_begin_token_pos(function.token_pos()); |
298 scope_->set_end_token_pos(function.end_token_pos()); | 324 scope_->set_end_token_pos(function.end_token_pos()); |
299 | 325 |
300 LocalVariable* context_var = parsed_function->current_context_var(); | 326 LocalVariable* context_var = parsed_function->current_context_var(); |
301 context_var->set_is_forced_stack(); | 327 context_var->set_is_forced_stack(); |
302 scope_->AddVariable(context_var); | 328 scope_->AddVariable(context_var); |
303 scope_->AddVariable(parsed_function->EnsureExpressionTemp()); | 329 bool has_expr_temp = false; |
330 if (node_ != NULL && NeedExprTemp(node_)) { | |
331 scope_->AddVariable(parsed_function->EnsureExpressionTemp()); | |
332 has_expr_temp = true; | |
333 } | |
304 | 334 |
305 parsed_function->SetNodeSequence( | 335 parsed_function->SetNodeSequence( |
306 new SequenceNode(TokenPosition::kNoSource, scope_)); | 336 new SequenceNode(TokenPosition::kNoSource, scope_)); |
307 | 337 |
308 switch (function.kind()) { | 338 switch (function.kind()) { |
309 case RawFunction::kClosureFunction: | 339 case RawFunction::kClosureFunction: |
310 case RawFunction::kRegularFunction: | 340 case RawFunction::kRegularFunction: |
311 case RawFunction::kGetterFunction: | 341 case RawFunction::kGetterFunction: |
312 case RawFunction::kSetterFunction: | 342 case RawFunction::kSetterFunction: |
313 case RawFunction::kConstructor: { | 343 case RawFunction::kConstructor: { |
(...skipping 27 matching lines...) Expand all Loading... | |
341 | 371 |
342 // We visit instance field initializers because they might contain | 372 // We visit instance field initializers because they might contain |
343 // [Let] expressions and we need to have a mapping. | 373 // [Let] expressions and we need to have a mapping. |
344 if (node_->IsConstructor()) { | 374 if (node_->IsConstructor()) { |
345 Class* klass = Class::Cast(Constructor::Cast(node_)->parent()); | 375 Class* klass = Class::Cast(Constructor::Cast(node_)->parent()); |
346 | 376 |
347 for (intptr_t i = 0; i < klass->fields().length(); i++) { | 377 for (intptr_t i = 0; i < klass->fields().length(); i++) { |
348 Field* field = klass->fields()[i]; | 378 Field* field = klass->fields()[i]; |
349 if (!field->IsStatic() && (field->initializer() != NULL)) { | 379 if (!field->IsStatic() && (field->initializer() != NULL)) { |
350 EnterScope(field, field->position()); | 380 EnterScope(field, field->position()); |
381 if (!has_expr_temp && NeedExprTemp(field->initializer())) { | |
382 scope_->AddVariable(parsed_function->EnsureExpressionTemp()); | |
383 has_expr_temp = true; | |
384 } | |
351 field->initializer()->AcceptExpressionVisitor(this); | 385 field->initializer()->AcceptExpressionVisitor(this); |
352 ExitScope(field->end_position()); | 386 ExitScope(field->end_position()); |
353 } | 387 } |
354 } | 388 } |
355 } | 389 } |
356 } else if (function.IsFactory()) { | 390 } else if (function.IsFactory()) { |
357 LocalVariable* variable = MakeVariable( | 391 LocalVariable* variable = MakeVariable( |
358 TokenPosition::kNoSource, TokenPosition::kNoSource, | 392 TokenPosition::kNoSource, TokenPosition::kNoSource, |
359 Symbols::TypeArgumentsParameter(), AbstractType::dynamic_type()); | 393 Symbols::TypeArgumentsParameter(), AbstractType::dynamic_type()); |
360 scope_->InsertParameterAt(pos++, variable); | 394 scope_->InsertParameterAt(pos++, variable); |
(...skipping 6095 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
6456 thread->clear_sticky_error(); | 6490 thread->clear_sticky_error(); |
6457 return error.raw(); | 6491 return error.raw(); |
6458 } | 6492 } |
6459 } | 6493 } |
6460 | 6494 |
6461 | 6495 |
6462 } // namespace kernel | 6496 } // namespace kernel |
6463 } // namespace dart | 6497 } // namespace dart |
6464 | 6498 |
6465 #endif // !defined(DART_PRECOMPILED_RUNTIME) | 6499 #endif // !defined(DART_PRECOMPILED_RUNTIME) |
OLD | NEW |