13#define H (translation_helper_)
23 translation_helper_(helper->translation_helper_),
24 active_class_(active_class),
25 result_(
Object::Handle(zone_)) {}
28 intptr_t constant_index,
29 intptr_t* pragma_name_constant_index,
30 intptr_t* pragma_options_constant_index) {
32 NavigateToIndex(&reader, constant_index);
36 if (
H.IsRoot(index) ||
37 !
H.StringEquals(
H.CanonicalNameString(index),
"pragma")) {
40 index =
H.CanonicalNameParent(index);
41 if (
H.IsRoot(index) ||
42 !
H.StringEquals(
H.CanonicalNameString(index),
"dart:core")) {
45 const intptr_t num_type_args = reader.
ReadUInt();
46 if (num_type_args != 0)
return false;
48 const intptr_t num_fields = reader.
ReadUInt();
49 if (num_fields != 2)
return false;
52 if (
H.IsRoot(field0_name) ||
53 !
H.StringEquals(
H.CanonicalNameString(field0_name),
"name")) {
56 const intptr_t name_index = reader.
ReadUInt();
57 if (pragma_name_constant_index !=
nullptr) {
58 *pragma_name_constant_index = name_index;
62 if (
H.IsRoot(field1_name) ||
63 !
H.StringEquals(
H.CanonicalNameString(field1_name),
"options")) {
66 const intptr_t options_index = reader.
ReadUInt();
67 if (pragma_options_constant_index !=
nullptr) {
68 *pragma_options_constant_index = options_index;
78 NavigateToIndex(&reader, constant_index);
82 return H.StringEquals(index,
name);
90 NavigateToIndex(&reader, constant_index);
94 *out_value =
H.DartSymbolPlain(index).ptr();
107 H.ReportError(
script, TokenPosition::kNoSource,
108 "Not a constant expression: unexpected kernel tag %s (%d)",
117 case kConstantExpression:
122 case kFileUriConstantExpression:
128 case kInvalidExpression: {
134 H.ReportError(
script, TokenPosition::kNoSource,
"%s",
140 H.ReportError(
script, TokenPosition::kNoSource,
141 "Not a constant expression: unexpected kernel tag %s (%d)",
149 const auto& metadata_values =
152 for (intptr_t
i = 0;
i < list_length; ++
i) {
155 metadata_values.SetAt(
i,
value);
157 return H.Canonicalize(metadata_values);
161 ASSERT(!
H.constants().IsNull());
162 ASSERT(!
H.constants_table().IsNull());
172 H.thread()->isolate_group()->kernel_constants_mutex());
173 const auto& constants_array =
175 ASSERT(constant_index < constants_array.Length());
176 result_ = constants_array.At(constant_index);
180 if (result_.
ptr() == Object::sentinel().ptr()) {
182 result_ = ReadConstantInternal(constant_index);
184 H.thread()->isolate_group()->kernel_constants_mutex());
185 const auto& constants_array =
187 ASSERT(constant_index < constants_array.Length());
188 constants_array.SetAt(constant_index, result_);
194 const Class& clazz) {
197 NavigateToIndex(&reader, constant_index);
202 return H.LookupClassByKernelClass(index) == clazz.
ptr();
208 ASSERT(!
H.constants_table().IsNull());
220intptr_t ConstantReader::NavigateToIndex(KernelReaderHelper* reader,
221 intptr_t constant_index) {
225 reader->SetOffset(reader->ReaderSize() - 4 - (num_constants * 4) +
226 (constant_index * 4));
227 const intptr_t constant_offset = reader->ReadUInt32();
229 reader->SetOffset(constant_offset);
231 return constant_offset;
234InstancePtr ConstantReader::ReadConstantInternal(intptr_t constant_index) {
236 KernelReaderHelper reader(
Z, &
H,
H.constants_table(), 0);
237 const intptr_t constant_offset = NavigateToIndex(&reader, constant_index);
241 ActiveEnclosingFunctionScope scope(active_class_,
nullptr);
244 const intptr_t constant_tag = reader.ReadByte();
245 switch (constant_tag) {
250 instance = reader.ReadByte() == 1 ? Object::bool_true().ptr()
251 : Object::bool_false().ptr();
255 Tag integer_tag = reader.ReadTag(&payload);
256 switch (integer_tag) {
257 case kBigIntLiteral: {
258 reader.ReadPosition();
259 const String&
value =
H.DartString(reader.ReadStringReference());
263 case kSpecializedIntLiteral: {
264 reader.ReadPosition();
265 const int64_t
value =
270 case kNegativeIntLiteral: {
271 reader.ReadPosition();
272 const int64_t
value = -
static_cast<int64_t
>(reader.ReadUInt());
276 case kPositiveIntLiteral: {
277 reader.ReadPosition();
278 const int64_t
value = reader.ReadUInt();
285 script, TokenPosition::kNoSource,
286 "Cannot lazily read integer: unexpected kernel tag %s (%d)",
295 instance =
H.DartSymbolPlain(reader.ReadStringReference()).ptr();
300 const auto& symbol_class =
304 ASSERT(!symbol_name_field.IsNull());
305 const NameIndex index = reader.ReadCanonicalNameReference();
309 library =
H.LookupLibraryByKernelLibrary(index);
311 const String& symbol =
312 H.DartIdentifier(library, reader.ReadStringReference());
314 instance.SetField(symbol_name_field, symbol);
319 Z,
H.isolate_group()->object_store()->immutable_array_class());
320 ASSERT(!list_class.IsNull());
321 ASSERT(list_class.is_finalized());
323 TypeTranslator type_translator(&reader,
this, active_class_,
326 auto& type_arguments =
328 AbstractType&
type = type_translator.BuildType();
329 type_arguments.SetTypeAt(0,
type);
332 list_class.GetInstanceTypeArguments(
H.thread(), type_arguments);
334 const intptr_t
length = reader.ReadUInt();
337 array.SetTypeArguments(type_arguments);
339 for (intptr_t j = 0; j <
length; ++j) {
342 const intptr_t entry_index = reader.ReadUInt();
343 ASSERT(entry_index < constant_offset);
345 array.SetAt(j, constant);
352 Z,
H.isolate_group()->object_store()->const_map_impl_class());
353 ASSERT(!map_class.IsNull());
354 ASSERT(map_class.is_finalized());
357 TypeTranslator type_translator(&reader,
this, active_class_,
360 auto& type_arguments =
362 AbstractType&
type = type_translator.BuildType();
363 type_arguments.SetTypeAt(0,
type);
364 type = type_translator.BuildType().ptr();
365 type_arguments.SetTypeAt(1,
type);
369 map_class.GetInstanceTypeArguments(
H.thread(), type_arguments);
374 map.SetTypeArguments(type_arguments);
375 const intptr_t
length = reader.ReadUInt();
376 const intptr_t used_data = (
length << 1);
377 map.set_used_data(used_data);
382 map.set_deleted_keys(0);
383 map.ComputeAndSetHashMask();
386 for (intptr_t j = 0; j < used_data; ++j) {
389 const intptr_t entry_index = reader.ReadUInt();
390 ASSERT(entry_index < constant_offset);
392 data.SetAt(j, constant);
399 const intptr_t num_positional = reader.ReadListLength();
400 intptr_t num_named = 0;
401 const Array* field_names = &Array::empty_array();
403 AlternativeReadingScope alt(&reader.reader_);
404 for (intptr_t j = 0; j < num_positional; ++j) {
407 num_named = reader.ReadListLength();
410 for (intptr_t j = 0; j < num_named; ++j) {
411 String&
name =
H.DartSymbolObfuscate(reader.ReadStringReference());
415 names.MakeImmutable();
416 field_names = &
names;
419 const intptr_t num_fields = num_positional + num_named;
420 const RecordShape shape =
424 for (intptr_t j = 0; j < num_positional; ++j) {
425 const intptr_t entry_index = reader.ReadUInt();
426 ASSERT(entry_index < constant_offset);
430 reader.ReadListLength();
431 for (intptr_t j = 0; j < num_named; ++j) {
432 reader.ReadStringReference();
433 const intptr_t entry_index = reader.ReadUInt();
434 ASSERT(entry_index < constant_offset);
443 Z,
H.isolate_group()->object_store()->const_set_impl_class());
444 ASSERT(!set_class.IsNull());
445 ASSERT(set_class.is_finalized());
448 TypeTranslator type_translator(&reader,
this, active_class_,
451 auto& type_arguments =
453 AbstractType&
type = type_translator.BuildType();
454 type_arguments.SetTypeAt(0,
type);
458 set_class.GetInstanceTypeArguments(
H.thread(), type_arguments);
463 set.SetTypeArguments(type_arguments);
464 const intptr_t
length = reader.ReadUInt();
465 const intptr_t used_data =
length;
466 set.set_used_data(used_data);
471 set.set_deleted_keys(0);
472 set.ComputeAndSetHashMask();
475 for (intptr_t j = 0; j < used_data; ++j) {
478 const intptr_t entry_index = reader.ReadUInt();
479 ASSERT(entry_index < constant_offset);
481 data.SetAt(j, constant);
488 const NameIndex index = reader.ReadCanonicalNameReference();
489 const auto& klass =
Class::Handle(
Z,
H.LookupClassByKernelClass(index));
490 if (!klass.is_declaration_loaded()) {
492 "Trying to evaluate an instance constant whose references class "
493 "%s is not loaded yet.",
499 ASSERT(klass.is_enum_class() || klass.is_const());
502 TypeTranslator type_translator(&reader,
this, active_class_,
505 const intptr_t number_of_type_arguments = reader.ReadUInt();
506 if (klass.NumTypeArguments() > 0) {
509 for (intptr_t j = 0; j < number_of_type_arguments; ++j) {
510 type_arguments.SetTypeAt(j, type_translator.BuildType());
514 klass.GetInstanceTypeArguments(
H.thread(), type_arguments);
515 instance.SetTypeArguments(type_arguments);
517 ASSERT(number_of_type_arguments == 0);
520 const intptr_t number_of_fields = reader.ReadUInt();
523 for (intptr_t j = 0; j < number_of_fields; ++j) {
524 field =
H.LookupFieldByKernelField(reader.ReadCanonicalNameReference());
527 const intptr_t entry_index = reader.ReadUInt();
528 ASSERT(entry_index < constant_offset);
537 const intptr_t entry_index = reader.ReadUInt();
538 ASSERT(entry_index < constant_offset);
540 ASSERT(!constant.IsNull());
543 TypeTranslator type_translator(&reader,
this, active_class_,
546 const intptr_t number_of_type_arguments = reader.ReadUInt();
547 ASSERT(number_of_type_arguments > 0);
550 for (intptr_t j = 0; j < number_of_type_arguments; ++j) {
551 type_arguments.SetTypeAt(j, type_translator.BuildType());
557 const auto& type_arguments2 =
571 const NameIndex index = reader.ReadCanonicalNameReference();
573 if (
H.IsConstructor(index)) {
574 function =
H.LookupConstructorByKernelConstructor(index);
576 function =
H.LookupStaticMethodByKernelProcedure(index);
589 TypeTranslator type_translator(&reader,
this, active_class_,
592 instance = type_translator.BuildType().ptr();
600 H.ReportError(
script, TokenPosition::kNoSource,
601 "Cannot lazily read constant: unexpected kernel tag (%" Pd
#define ASSERT_EQUAL(expected, actual)
static ArrayPtr New(intptr_t len, Heap::Space space=Heap::kNew)
static ClosurePtr New(const TypeArguments &instantiator_type_arguments, const TypeArguments &function_type_arguments, const Function &function, const Object &context, Heap::Space space=Heap::kNew)
static ConstMapPtr NewUninitialized(Heap::Space space=Heap::kNew)
static ConstSetPtr NewUninitialized(Heap::Space space=Heap::kNew)
static DoublePtr New(double d, Heap::Space space=Heap::kNew)
static ImmutableArrayPtr New(intptr_t len, Heap::Space space=Heap::kNew)
static InstancePtr New(const Class &cls, Heap::Space space=Heap::kNew)
static IntegerPtr New(const String &str, Heap::Space space=Heap::kNew)
static LibraryPtr InternalLibrary()
static ObjectPtr RawCast(ObjectPtr obj)
static RecordShape Register(Thread *thread, intptr_t num_fields, const Array &field_names)
static RecordPtr New(RecordShape shape, Heap::Space space=Heap::kNew)
static const String & Symbol(intptr_t index)
static Thread * Current()
static TypeArgumentsPtr New(intptr_t len, Heap::Space space=Heap::kOld)
bool IsStringConstant(intptr_t constant_index, const char *name)
ConstantReader(KernelReaderHelper *helper, ActiveClass *active_class)
InstancePtr ReadConstantExpression()
bool IsInstanceConstant(intptr_t constant_index, const Class &clazz)
ObjectPtr ReadAnnotations()
InstancePtr ReadConstant(intptr_t constant_index)
InstancePtr ReadConstantInitializer()
bool GetStringConstant(intptr_t constant_index, String *out_value)
bool IsPragmaInstanceConstant(intptr_t constant_index, intptr_t *pragma_name_constant_index, intptr_t *pragma_options_constant_index)
intptr_t ReaderSize() const
void SetOffset(intptr_t offset)
intptr_t ReadListLength()
TokenPosition ReadPosition()
Tag ReadTag(uint8_t *payload=nullptr)
NameIndex ReadCanonicalNameReference()
StringIndex ReadStringReference()
static const char * TagName(Tag tag)
Dart_NativeFunction function
@ kConstructorTearOffConstant
@ kRedirectingFactoryTearOffConstant
static constexpr int SpecializedIntLiteralBias
static const char *const names[]
static int8_t data[kExtLength]
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not set
std::function< void()> closure
SI auto map(std::index_sequence< I... >, Fn &&fn, const Args &... args) -> skvx::Vec< sizeof...(I), decltype(fn(args[0]...))>