| 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" |
| 11 #include "vm/object_store.h" | 11 #include "vm/object_store.h" |
| 12 #include "vm/parser.h" | 12 #include "vm/parser.h" |
| 13 #include "vm/symbols.h" | 13 #include "vm/symbols.h" |
| 14 | 14 |
| 15 #if !defined(DART_PRECOMPILED_RUNTIME) | 15 #if !defined(DART_PRECOMPILED_RUNTIME) |
| 16 namespace dart { | 16 namespace dart { |
| 17 namespace kernel { | 17 namespace kernel { |
| 18 | 18 |
| 19 #define Z (zone_) | 19 #define Z (zone_) |
| 20 #define I (isolate_) | 20 #define I (isolate_) |
| 21 #define T (type_translator_) | 21 #define T (type_translator_) |
| 22 #define H (translation_helper_) | 22 #define H (translation_helper_) |
| 23 | 23 |
| 24 class SimpleExpressionConverter : public ExpressionVisitor { | 24 class SimpleExpressionConverter : public ExpressionVisitor { |
| 25 public: | 25 public: |
| 26 SimpleExpressionConverter(Thread* thread, Zone* zone) | 26 explicit SimpleExpressionConverter(Thread* thread) |
| 27 : translation_helper_(thread, zone, NULL), | 27 : translation_helper_(thread), |
| 28 zone_(zone), | 28 zone_(translation_helper_.zone()), |
| 29 is_simple_(false), | 29 is_simple_(false), |
| 30 simple_value_(NULL) {} | 30 simple_value_(NULL) {} |
| 31 | 31 |
| 32 virtual void VisitDefaultExpression(Expression* node) { is_simple_ = false; } | 32 virtual void VisitDefaultExpression(Expression* node) { is_simple_ = false; } |
| 33 | 33 |
| 34 virtual void VisitIntLiteral(IntLiteral* node) { | 34 virtual void VisitIntLiteral(IntLiteral* node) { |
| 35 is_simple_ = true; | 35 is_simple_ = true; |
| 36 simple_value_ = | 36 simple_value_ = |
| 37 &Integer::ZoneHandle(Z, Integer::New(node->value(), Heap::kOld)); | 37 &Integer::ZoneHandle(Z, Integer::New(node->value(), Heap::kOld)); |
| 38 *simple_value_ = H.Canonicalize(*simple_value_); | 38 *simple_value_ = H.Canonicalize(*simple_value_); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 RawClass* BuildingTranslationHelper::LookupClassByKernelClass(Class* klass) { | 92 RawClass* BuildingTranslationHelper::LookupClassByKernelClass(Class* klass) { |
| 93 return reader_->LookupClass(klass).raw(); | 93 return reader_->LookupClass(klass).raw(); |
| 94 } | 94 } |
| 95 | 95 |
| 96 KernelReader::KernelReader(Program* program) | 96 KernelReader::KernelReader(Program* program) |
| 97 : program_(program), | 97 : program_(program), |
| 98 thread_(dart::Thread::Current()), | 98 thread_(dart::Thread::Current()), |
| 99 zone_(thread_->zone()), | 99 zone_(thread_->zone()), |
| 100 isolate_(thread_->isolate()), | 100 isolate_(thread_->isolate()), |
| 101 scripts_(Array::ZoneHandle(zone_)), | 101 scripts_(Array::ZoneHandle(zone_)), |
| 102 translation_helper_(this, thread_, zone_, isolate_), | 102 translation_helper_(this, thread_), |
| 103 type_translator_(&translation_helper_, | 103 type_translator_(&translation_helper_, |
| 104 &active_class_, | 104 &active_class_, |
| 105 /*finalize=*/false) { | 105 /*finalize=*/false) { |
| 106 intptr_t source_file_count = program_->source_table().size(); | 106 intptr_t source_file_count = program_->source_table().size(); |
| 107 scripts_ = Array::New(source_file_count, Heap::kOld); | 107 scripts_ = Array::New(source_file_count, Heap::kOld); |
| 108 } | 108 } |
| 109 | 109 |
| 110 Object& KernelReader::ReadProgram() { | 110 Object& KernelReader::ReadProgram() { |
| 111 LongJumpScope jump; | 111 LongJumpScope jump; |
| 112 if (setjmp(*jump.Set()) == 0) { | 112 if (setjmp(*jump.Set()) == 0) { |
| (...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 466 return script; | 466 return script; |
| 467 } | 467 } |
| 468 | 468 |
| 469 void KernelReader::GenerateFieldAccessors(const dart::Class& klass, | 469 void KernelReader::GenerateFieldAccessors(const dart::Class& klass, |
| 470 const dart::Field& field, | 470 const dart::Field& field, |
| 471 Field* kernel_field) { | 471 Field* kernel_field) { |
| 472 if (kernel_field->IsStatic() && kernel_field->initializer() != NULL) { | 472 if (kernel_field->IsStatic() && kernel_field->initializer() != NULL) { |
| 473 // Static fields with initializers either have the static value set to the | 473 // Static fields with initializers either have the static value set to the |
| 474 // initializer value if it is simple enough or else set to an uninitialized | 474 // initializer value if it is simple enough or else set to an uninitialized |
| 475 // sentinel. | 475 // sentinel. |
| 476 SimpleExpressionConverter converter(H.thread(), Z); | 476 SimpleExpressionConverter converter(H.thread()); |
| 477 if (converter.IsSimple(kernel_field->initializer())) { | 477 if (converter.IsSimple(kernel_field->initializer())) { |
| 478 // We do not need a getter. | 478 // We do not need a getter. |
| 479 field.SetStaticValue(converter.SimpleValue(), true); | 479 field.SetStaticValue(converter.SimpleValue(), true); |
| 480 return; | 480 return; |
| 481 } | 481 } |
| 482 // We do need a getter that evaluates the initializer if necessary. | 482 // We do need a getter that evaluates the initializer if necessary. |
| 483 field.SetStaticValue(Object::sentinel(), true); | 483 field.SetStaticValue(Object::sentinel(), true); |
| 484 } | 484 } |
| 485 | 485 |
| 486 const dart::String& getter_name = H.DartGetterName(kernel_field->name()); | 486 const dart::String& getter_name = H.DartGetterName(kernel_field->name()); |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 722 initializer_fun.set_is_debuggable(false); | 722 initializer_fun.set_is_debuggable(false); |
| 723 initializer_fun.set_is_reflectable(false); | 723 initializer_fun.set_is_reflectable(false); |
| 724 initializer_fun.set_is_inlinable(false); | 724 initializer_fun.set_is_inlinable(false); |
| 725 return new (zone) ParsedFunction(thread, initializer_fun); | 725 return new (zone) ParsedFunction(thread, initializer_fun); |
| 726 } | 726 } |
| 727 | 727 |
| 728 | 728 |
| 729 } // namespace kernel | 729 } // namespace kernel |
| 730 } // namespace dart | 730 } // namespace dart |
| 731 #endif // !defined(DART_PRECOMPILED_RUNTIME) | 731 #endif // !defined(DART_PRECOMPILED_RUNTIME) |
| OLD | NEW |