Chromium Code Reviews| 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 "vm/kernel_reader.h" | 5 #include "vm/kernel_reader.h" |
| 6 | 6 |
| 7 #include <string.h> | 7 #include <string.h> |
| 8 | 8 |
| 9 #include "vm/dart_api_impl.h" | 9 #include "vm/dart_api_impl.h" |
| 10 #include "vm/longjump.h" | 10 #include "vm/longjump.h" |
| (...skipping 544 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 555 array_object ^= AsSortedDuplicateFreeArray( | 555 array_object ^= AsSortedDuplicateFreeArray( |
| 556 source_uri_index, &program_->yield_token_positions); | 556 source_uri_index, &program_->yield_token_positions); |
| 557 script.set_yield_positions(array_object); | 557 script.set_yield_positions(array_object); |
| 558 } | 558 } |
| 559 return script; | 559 return script; |
| 560 } | 560 } |
| 561 | 561 |
| 562 void KernelReader::GenerateFieldAccessors(const dart::Class& klass, | 562 void KernelReader::GenerateFieldAccessors(const dart::Class& klass, |
| 563 const dart::Field& field, | 563 const dart::Field& field, |
| 564 Field* kernel_field) { | 564 Field* kernel_field) { |
| 565 if (kernel_field->IsStatic() && kernel_field->initializer() != NULL) { | 565 if (kernel_field->initializer() != NULL) { |
| 566 // Static fields with initializers either have the static value set to the | |
| 567 // initializer value if it is simple enough or else set to an uninitialized | |
| 568 // sentinel. | |
| 569 SimpleExpressionConverter converter(H.thread()); | 566 SimpleExpressionConverter converter(H.thread()); |
| 570 if (converter.IsSimple(kernel_field->initializer())) { | 567 const bool has_simple_initializer = |
| 571 // We do not need a getter. | 568 converter.IsSimple(kernel_field->initializer()); |
| 572 field.SetStaticValue(converter.SimpleValue(), true); | 569 if (kernel_field->IsStatic()) { |
| 573 return; | 570 // Static fields with initializers either have the static value set to the |
| 571 // initializer value if it is simple enough or else set to an | |
| 572 // uninitialized sentinel. | |
| 573 if (has_simple_initializer) { | |
| 574 // We do not need a getter. | |
| 575 field.SetStaticValue(converter.SimpleValue(), true); | |
| 576 return; | |
| 577 } | |
| 578 // We do need a getter that evaluates the initializer if necessary. | |
| 579 field.SetStaticValue(Object::sentinel(), true); | |
| 580 } else if (has_simple_initializer) { | |
| 581 field.RecordStore(converter.SimpleValue()); | |
| 582 if (!converter.SimpleValue().IsNull() && | |
| 583 converter.SimpleValue().IsDouble()) { | |
| 584 field.set_is_double_initialized(true); | |
|
erikcorry
2017/03/07 12:32:50
Comment suggestion:
The field is initialized with
Vyacheslav Egorov (Google)
2017/03/07 13:44:25
Added a comment
| |
| 585 } | |
| 574 } | 586 } |
| 575 // We do need a getter that evaluates the initializer if necessary. | |
| 576 field.SetStaticValue(Object::sentinel(), true); | |
| 577 } | 587 } |
| 578 | 588 |
| 579 const dart::String& getter_name = H.DartGetterName(kernel_field->name()); | 589 const dart::String& getter_name = H.DartGetterName(kernel_field->name()); |
| 580 const Object& script_class = | 590 const Object& script_class = |
| 581 ClassForScriptAt(klass, kernel_field->source_uri_index()); | 591 ClassForScriptAt(klass, kernel_field->source_uri_index()); |
| 582 Function& getter = Function::ZoneHandle( | 592 Function& getter = Function::ZoneHandle( |
| 583 Z, | 593 Z, |
| 584 Function::New( | 594 Function::New( |
| 585 getter_name, | 595 getter_name, |
| 586 kernel_field->IsStatic() ? RawFunction::kImplicitStaticFinalGetter | 596 kernel_field->IsStatic() ? RawFunction::kImplicitStaticFinalGetter |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 818 initializer_fun.set_is_debuggable(false); | 828 initializer_fun.set_is_debuggable(false); |
| 819 initializer_fun.set_is_reflectable(false); | 829 initializer_fun.set_is_reflectable(false); |
| 820 initializer_fun.set_is_inlinable(false); | 830 initializer_fun.set_is_inlinable(false); |
| 821 return new (zone) ParsedFunction(thread, initializer_fun); | 831 return new (zone) ParsedFunction(thread, initializer_fun); |
| 822 } | 832 } |
| 823 | 833 |
| 824 | 834 |
| 825 } // namespace kernel | 835 } // namespace kernel |
| 826 } // namespace dart | 836 } // namespace dart |
| 827 #endif // !defined(DART_PRECOMPILED_RUNTIME) | 837 #endif // !defined(DART_PRECOMPILED_RUNTIME) |
| OLD | NEW |