af5fc2d4d2
See https://github.com/tc39/proposal-regexp-named-groups for a high-level description of the feature and examples. This is one of the features requested in https://github.com/dart-lang/sdk/issues/34935. This is a partial implementation because while there is a way to retrieve groups via Dart by name, it requires casting the returned Match to the new RegExpMatch interface to avoid changing the RegExp interface. Changing the RegExp interface will happen in a future update, since there are other planned changes to the RegExp interface coming soon and that way we only change it once. See https://github.com/dart-lang/sdk/issues/36171 for more details on the planned changes. Also, since only BMP regular expressions are supported, not full Unicode ones (i.e., those with the /u flag in ECMAscript), \k<NAME> will only be parsed as a named back reference if there are named captures in the string. Otherwise, the \k will be parsed as the identity escape for backwards compatibility. The new tests illustrate this difference. Change-Id: Ieeb0374813db78924c9aa8ac3e652dfb6d4a5934 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/95461 Commit-Queue: Stevie Strickland <sstrickl@google.com> Reviewed-by: Lasse R.H. Nielsen <lrn@google.com> Reviewed-by: Martin Kustermann <kustermann@google.com> Reviewed-by: Jenny Messerly <jmesserly@google.com> Reviewed-by: Johnni Winther <johnniwinther@google.com>
223 lines
16 KiB
C++
223 lines
16 KiB
C++
// Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file
|
|
// for details. All rights reserved. Use of this source code is governed by a
|
|
// BSD-style license that can be found in the LICENSE file.
|
|
|
|
#include "vm/raw_object_fields.h"
|
|
|
|
namespace dart {
|
|
|
|
#if defined(DART_PRECOMPILER)
|
|
|
|
#define RAW_CLASSES_AND_FIELDS(F) \
|
|
F(Class, name_) \
|
|
F(Class, user_name_) \
|
|
F(Class, functions_) \
|
|
F(Class, functions_hash_table_) \
|
|
F(Class, fields_) \
|
|
F(Class, offset_in_words_to_field_) \
|
|
F(Class, interfaces_) \
|
|
F(Class, script_) \
|
|
F(Class, library_) \
|
|
F(Class, type_parameters_) \
|
|
F(Class, super_type_) \
|
|
F(Class, signature_function_) \
|
|
F(Class, constants_) \
|
|
F(Class, declaration_type_) \
|
|
F(Class, invocation_dispatcher_cache_) \
|
|
F(Class, allocation_stub_) \
|
|
F(Class, direct_implementors_) \
|
|
F(Class, direct_subclasses_) \
|
|
F(Class, dependent_code_) \
|
|
F(PatchClass, patched_class_) \
|
|
F(PatchClass, origin_class_) \
|
|
F(PatchClass, script_) \
|
|
F(PatchClass, library_kernel_data_) \
|
|
F(Function, name_) \
|
|
F(Function, owner_) \
|
|
F(Function, result_type_) \
|
|
F(Function, parameter_types_) \
|
|
F(Function, parameter_names_) \
|
|
F(Function, type_parameters_) \
|
|
F(Function, data_) \
|
|
F(Function, ic_data_array_) \
|
|
F(Function, code_) \
|
|
F(ClosureData, context_scope_) \
|
|
F(ClosureData, parent_function_) \
|
|
F(ClosureData, signature_type_) \
|
|
F(ClosureData, closure_) \
|
|
F(SignatureData, parent_function_) \
|
|
F(SignatureData, signature_type_) \
|
|
F(RedirectionData, type_) \
|
|
F(RedirectionData, identifier_) \
|
|
F(RedirectionData, target_) \
|
|
F(Field, name_) \
|
|
F(Field, owner_) \
|
|
F(Field, type_) \
|
|
F(Field, guarded_list_length_) \
|
|
F(Field, dependent_code_) \
|
|
F(Field, type_test_cache_) \
|
|
F(Field, initializer_function_) \
|
|
F(Script, url_) \
|
|
F(Script, resolved_url_) \
|
|
F(Script, compile_time_constants_) \
|
|
F(Script, line_starts_) \
|
|
F(Script, debug_positions_) \
|
|
F(Script, yield_positions_) \
|
|
F(Script, kernel_program_info_) \
|
|
F(Script, source_) \
|
|
F(Library, name_) \
|
|
F(Library, url_) \
|
|
F(Library, private_key_) \
|
|
F(Library, dictionary_) \
|
|
F(Library, metadata_) \
|
|
F(Library, toplevel_class_) \
|
|
F(Library, patch_classes_) \
|
|
F(Library, imports_) \
|
|
F(Library, exports_) \
|
|
F(Library, load_error_) \
|
|
F(Library, kernel_data_) \
|
|
F(Library, resolved_names_) \
|
|
F(Library, exported_names_) \
|
|
F(Library, loaded_scripts_) \
|
|
F(Namespace, library_) \
|
|
F(Namespace, show_names_) \
|
|
F(Namespace, hide_names_) \
|
|
F(Namespace, metadata_field_) \
|
|
F(KernelProgramInfo, string_offsets_) \
|
|
F(KernelProgramInfo, string_data_) \
|
|
F(KernelProgramInfo, canonical_names_) \
|
|
F(KernelProgramInfo, metadata_payloads_) \
|
|
F(KernelProgramInfo, metadata_mappings_) \
|
|
F(KernelProgramInfo, scripts_) \
|
|
F(KernelProgramInfo, constants_) \
|
|
F(KernelProgramInfo, bytecode_component_) \
|
|
F(KernelProgramInfo, potential_natives_) \
|
|
F(KernelProgramInfo, potential_pragma_functions_) \
|
|
F(KernelProgramInfo, constants_table_) \
|
|
F(KernelProgramInfo, libraries_cache_) \
|
|
F(KernelProgramInfo, classes_cache_) \
|
|
F(Code, object_pool_) \
|
|
F(Code, instructions_) \
|
|
F(Code, owner_) \
|
|
F(Code, exception_handlers_) \
|
|
F(Code, pc_descriptors_) \
|
|
F(Code, stackmaps_) \
|
|
F(Code, inlined_id_to_function_) \
|
|
F(Code, code_source_map_) \
|
|
F(Bytecode, object_pool_) \
|
|
F(Bytecode, instructions_) \
|
|
F(Bytecode, function_) \
|
|
F(Bytecode, exception_handlers_) \
|
|
F(Bytecode, pc_descriptors_) \
|
|
F(ExceptionHandlers, handled_types_data_) \
|
|
F(Context, parent_) \
|
|
F(SingleTargetCache, target_) \
|
|
F(UnlinkedCall, target_name_) \
|
|
F(UnlinkedCall, args_descriptor_) \
|
|
F(ICData, entries_) \
|
|
F(ICData, target_name_) \
|
|
F(ICData, args_descriptor_) \
|
|
F(ICData, owner_) \
|
|
F(MegamorphicCache, buckets_) \
|
|
F(MegamorphicCache, mask_) \
|
|
F(MegamorphicCache, target_name_) \
|
|
F(MegamorphicCache, args_descriptor_) \
|
|
F(SubtypeTestCache, cache_) \
|
|
F(ApiError, message_) \
|
|
F(LanguageError, previous_error_) \
|
|
F(LanguageError, script_) \
|
|
F(LanguageError, message_) \
|
|
F(LanguageError, formatted_message_) \
|
|
F(UnhandledException, exception_) \
|
|
F(UnhandledException, stacktrace_) \
|
|
F(UnwindError, message_) \
|
|
F(LibraryPrefix, name_) \
|
|
F(LibraryPrefix, importer_) \
|
|
F(LibraryPrefix, imports_) \
|
|
F(LibraryPrefix, dependent_code_) \
|
|
F(TypeArguments, instantiations_) \
|
|
F(TypeArguments, length_) \
|
|
F(TypeArguments, hash_) \
|
|
F(AbstractType, type_test_stub_) \
|
|
F(Type, type_test_stub_) \
|
|
F(Type, type_class_id_) \
|
|
F(Type, arguments_) \
|
|
F(Type, hash_) \
|
|
F(Type, signature_) \
|
|
F(TypeRef, type_test_stub_) \
|
|
F(TypeRef, type_) \
|
|
F(TypeParameter, type_test_stub_) \
|
|
F(TypeParameter, name_) \
|
|
F(TypeParameter, hash_) \
|
|
F(TypeParameter, bound_) \
|
|
F(TypeParameter, parameterized_function_) \
|
|
F(Closure, instantiator_type_arguments_) \
|
|
F(Closure, function_type_arguments_) \
|
|
F(Closure, delayed_type_arguments_) \
|
|
F(Closure, function_) \
|
|
F(Closure, context_) \
|
|
F(Closure, hash_) \
|
|
F(String, length_) \
|
|
F(String, hash_) \
|
|
F(Array, type_arguments_) \
|
|
F(Array, length_) \
|
|
F(GrowableObjectArray, type_arguments_) \
|
|
F(GrowableObjectArray, length_) \
|
|
F(GrowableObjectArray, data_) \
|
|
F(LinkedHashMap, type_arguments_) \
|
|
F(LinkedHashMap, index_) \
|
|
F(LinkedHashMap, hash_mask_) \
|
|
F(LinkedHashMap, data_) \
|
|
F(LinkedHashMap, used_data_) \
|
|
F(LinkedHashMap, deleted_keys_) \
|
|
F(TypedData, length_) \
|
|
F(ExternalTypedData, length_) \
|
|
F(ReceivePort, send_port_) \
|
|
F(ReceivePort, handler_) \
|
|
F(StackTrace, async_link_) \
|
|
F(StackTrace, code_array_) \
|
|
F(StackTrace, pc_offset_array_) \
|
|
F(RegExp, num_bracket_expressions_) \
|
|
F(RegExp, capture_name_map_) \
|
|
F(RegExp, pattern_) \
|
|
F(RegExp, external_one_byte_function_) \
|
|
F(RegExp, external_two_byte_function_) \
|
|
F(RegExp, external_one_byte_sticky_function_) \
|
|
F(RegExp, external_two_byte_sticky_function_) \
|
|
F(WeakProperty, key_) \
|
|
F(WeakProperty, value_) \
|
|
F(MirrorReference, referent_) \
|
|
F(UserTag, label_) \
|
|
F(Pointer, type_arguments_) \
|
|
F(Pointer, c_memory_address_) \
|
|
F(DynamicLibrary, handle_) \
|
|
F(FfiTrampolineData, signature_type_)
|
|
|
|
OffsetsTable::OffsetsTable(Zone* zone) : cached_offsets_(zone) {
|
|
for (intptr_t i = 0; offsets_table[i].class_id != -1; ++i) {
|
|
OffsetsTableEntry entry = offsets_table[i];
|
|
cached_offsets_.Insert({{entry.class_id, entry.offset}, entry.field_name});
|
|
}
|
|
}
|
|
|
|
const char* OffsetsTable::FieldNameForOffset(intptr_t class_id,
|
|
intptr_t offset) {
|
|
return cached_offsets_.LookupValue({class_id, offset});
|
|
}
|
|
|
|
#define DEFINE_OFFSETS_TABLE_ENTRY(class_name, field_name) \
|
|
{class_name::kClassId, #field_name, OFFSET_OF(Raw##class_name, field_name)},
|
|
|
|
// clang-format off
|
|
OffsetsTable::OffsetsTableEntry OffsetsTable::offsets_table[] = {
|
|
RAW_CLASSES_AND_FIELDS(DEFINE_OFFSETS_TABLE_ENTRY)
|
|
{-1, nullptr, -1}
|
|
};
|
|
// clang-format on
|
|
|
|
#undef DEFINE_OFFSETS_TABLE_ENTRY
|
|
|
|
#endif
|
|
|
|
} // namespace dart
|