Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(87)

Side by Side Diff: runtime/vm/kernel_reader.cc

Issue 2973943002: [kernel] Allow reflection on some fields; add metadata on fields too. (Closed)
Patch Set: Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | tests/co19/co19-kernel.status » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/kernel_binary.h" 10 #include "vm/kernel_binary.h"
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 field_helper.IsConst(), script_class, 276 field_helper.IsConst(), script_class,
277 field_helper.position_)); 277 field_helper.position_));
278 field.set_kernel_offset(field_offset); 278 field.set_kernel_offset(field_offset);
279 const AbstractType& type = T.BuildType(); // read type. 279 const AbstractType& type = T.BuildType(); // read type.
280 field.SetFieldType(type); 280 field.SetFieldType(type);
281 field_helper.SetJustRead(FieldHelper::kType); 281 field_helper.SetJustRead(FieldHelper::kType);
282 field_helper.ReadUntilExcluding(FieldHelper::kInitializer); 282 field_helper.ReadUntilExcluding(FieldHelper::kInitializer);
283 field.set_has_initializer(builder_.PeekTag() == kSomething); 283 field.set_has_initializer(builder_.PeekTag() == kSomething);
284 GenerateFieldAccessors(toplevel_class, field, &field_helper, field_offset); 284 GenerateFieldAccessors(toplevel_class, field, &field_helper, field_offset);
285 field_helper.ReadUntilExcluding(FieldHelper::kEnd); 285 field_helper.ReadUntilExcluding(FieldHelper::kEnd);
286 if (FLAG_enable_mirrors) {
287 library.AddFieldMetadata(field, TokenPosition::kNoSource, field_offset);
288 }
286 fields_.Add(&field); 289 fields_.Add(&field);
287 library.AddObject(field, name); 290 library.AddObject(field, name);
288 } 291 }
289 toplevel_class.AddFields(fields_); 292 toplevel_class.AddFields(fields_);
290 293
291 // Load toplevel procedures. 294 // Load toplevel procedures.
292 intptr_t procedure_count = builder_.ReadListLength(); // read list length. 295 intptr_t procedure_count = builder_.ReadListLength(); // read list length.
293 for (intptr_t i = 0; i < procedure_count; ++i) { 296 for (intptr_t i = 0; i < procedure_count; ++i) {
294 ReadProcedure(library, toplevel_class, false); 297 ReadProcedure(library, toplevel_class, false);
295 } 298 }
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
438 field_helper.ReadUntilExcluding(FieldHelper::kName); 441 field_helper.ReadUntilExcluding(FieldHelper::kName);
439 442
440 const dart::String& name = builder_.ReadNameAsFieldName(); 443 const dart::String& name = builder_.ReadNameAsFieldName();
441 field_helper.SetJustRead(FieldHelper::kName); 444 field_helper.SetJustRead(FieldHelper::kName);
442 field_helper.ReadUntilExcluding(FieldHelper::kType); 445 field_helper.ReadUntilExcluding(FieldHelper::kType);
443 const AbstractType& type = 446 const AbstractType& type =
444 T.BuildTypeWithoutFinalization(); // read type. 447 T.BuildTypeWithoutFinalization(); // read type.
445 field_helper.SetJustRead(FieldHelper::kType); 448 field_helper.SetJustRead(FieldHelper::kType);
446 const Object& script_class = 449 const Object& script_class =
447 ClassForScriptAt(klass, field_helper.source_uri_index_); 450 ClassForScriptAt(klass, field_helper.source_uri_index_);
451
452 const bool is_reflectable =
453 field_helper.position_.IsReal() &&
454 !(library.is_dart_scheme() && library.IsPrivate(name));
448 dart::Field& field = dart::Field::Handle( 455 dart::Field& field = dart::Field::Handle(
449 Z, 456 Z,
450 dart::Field::New(name, field_helper.IsStatic(), 457 dart::Field::New(name, field_helper.IsStatic(),
451 // In the VM all const fields are implicitly final 458 // In the VM all const fields are implicitly final
452 // whereas in Kernel they are not final because they 459 // whereas in Kernel they are not final because they
453 // are not explicitly declared that way. 460 // are not explicitly declared that way.
454 field_helper.IsFinal() || field_helper.IsConst(), 461 field_helper.IsFinal() || field_helper.IsConst(),
455 field_helper.IsConst(), 462 field_helper.IsConst(), is_reflectable, script_class,
456 false, // is_reflectable 463 type, field_helper.position_));
457 script_class, type, field_helper.position_));
458 field.set_kernel_offset(field_offset); 464 field.set_kernel_offset(field_offset);
459 field_helper.ReadUntilExcluding(FieldHelper::kInitializer); 465 field_helper.ReadUntilExcluding(FieldHelper::kInitializer);
460 field.set_has_initializer(builder_.PeekTag() == kSomething); 466 field.set_has_initializer(builder_.PeekTag() == kSomething);
461 GenerateFieldAccessors(klass, field, &field_helper, field_offset); 467 GenerateFieldAccessors(klass, field, &field_helper, field_offset);
462 field_helper.ReadUntilExcluding(FieldHelper::kEnd); 468 field_helper.ReadUntilExcluding(FieldHelper::kEnd);
469 if (FLAG_enable_mirrors) {
470 library.AddFieldMetadata(field, TokenPosition::kNoSource, field_offset);
471 }
463 fields_.Add(&field); 472 fields_.Add(&field);
464 } 473 }
465 klass.AddFields(fields_); 474 klass.AddFields(fields_);
466 class_helper.SetJustRead(ClassHelper::kFields); 475 class_helper.SetJustRead(ClassHelper::kFields);
467 } 476 }
468 477
469 class_helper.ReadUntilExcluding(ClassHelper::kConstructors); 478 class_helper.ReadUntilExcluding(ClassHelper::kConstructors);
470 int constructor_count = builder_.ReadListLength(); // read list length. 479 int constructor_count = builder_.ReadListLength(); // read list length.
471 for (intptr_t i = 0; i < constructor_count; ++i) { 480 for (intptr_t i = 0; i < constructor_count; ++i) {
472 intptr_t constructor_offset = builder_.ReaderOffset(); 481 intptr_t constructor_offset = builder_.ReaderOffset();
(...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after
906 initializer_fun.set_is_debuggable(false); 915 initializer_fun.set_is_debuggable(false);
907 initializer_fun.set_is_reflectable(false); 916 initializer_fun.set_is_reflectable(false);
908 initializer_fun.set_is_inlinable(false); 917 initializer_fun.set_is_inlinable(false);
909 return new (zone) ParsedFunction(thread, initializer_fun); 918 return new (zone) ParsedFunction(thread, initializer_fun);
910 } 919 }
911 920
912 921
913 } // namespace kernel 922 } // namespace kernel
914 } // namespace dart 923 } // namespace dart
915 #endif // !defined(DART_PRECOMPILED_RUNTIME) 924 #endif // !defined(DART_PRECOMPILED_RUNTIME)
OLDNEW
« no previous file with comments | « no previous file | tests/co19/co19-kernel.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698