5"""This module provides shared functionality for the systems to generate
6native binding from the IDL database."""
11from generator
import *
12from htmldartgenerator
import *
13from idlnode
import IDLArgument, IDLAttribute, IDLEnum, IDLMember
14from systemhtml
import js_support_checks, GetCallbackInfo, HTML_LIBRARY_NAMES
16_logger = logging.getLogger(
'systemnative')
21 'hash',
'host',
'hostname',
'origin',
'password',
'pathname',
'port',
22 'protocol',
'search',
'username'
25_promise_to_future = Conversion(
'promiseToFuture',
'dynamic',
'Future')
29 matched = re.match(
r'([\w\d_\s]+)\[\]', data_type)
32 return matched.group(1)
35_sequence_matcher = re.compile(
'sequence<(.+)>')
40 if database.HasEnum(interface_id):
43 seq_match = _sequence_matcher.match(interface_id)
44 if seq_match
is not None:
46 return "sequence<%s>" % t
49 if arr_match
is not None:
57 return library_name +
"." + name
66 'unsigned long':
"ul",
67 'unsigned long long':
"ull",
68 'unsigned short':
"us",
74 seq_match = _sequence_matcher.match(t)
75 if seq_match
is not None:
81 if arr_match
is not None:
85 return _type_encoding_map.get(t)
or t
89 """Generates Dart implementation for one DOM IDL interface."""
91 def __init__(self, interface, cpp_library_emitter, options, loggerParent):
92 super(DartiumBackend, self).
__init__(interface, options,
True,
112 _logger.setLevel(loggerParent.level)
123 def _OutputConversion(self, idl_type, member):
126 if idl_type ==
'Promise':
127 return _promise_to_future
129 if conversion.function_name
in (
'convertNativeToDart_DateTime',
130 'convertNativeToDart_ImageData'):
134 def _InputConversion(self, idl_type, member):
145 template_file =
'impl_%s.darttemplate' % interface_name
149 'dart_implementation.darttemplate')
153 return 'DartHtmlDomObject'
163 tag =
"%s_Getter" % name
165 elif kind ==
'Setter':
166 tag =
"%s_Setter" % name
168 elif kind ==
'Constructor':
169 tag =
"constructorCallback"
171 elif kind ==
'Method':
172 tag =
"%s_Callback" % name
178 if s.startswith(
"_")
or s.startswith(
"$"):
182 if count
is not None:
184 dart_name = mkPublic(
"_".
join([tag, arity]))
186 dart_name = mkPublic(tag)
187 resolver_string =
"_".
join([interface_id, tag])
189 return (dart_name, resolver_string)
192 fields = [
'$' + name]
194 fields.append(suffix)
195 return "_".
join(fields)
236 ' if (name == "$(INTERFACE_NAME)_constructor_Callback")\n'
237 ' return Dart$(INTERFACE_NAME)Internal::constructorCallback;\n',
243 'static void constructorCallback(Dart_NativeArguments args)\n'
245 ' WebCore::DartArrayBufferViewInternal::constructWebGLArray<Dart$(INTERFACE_NAME)>(args);\n'
249 def _EmitConstructorInfrastructure(self,
255 emit_to_native=False,
258 constructor_callback_cpp_name = cpp_prefix + cpp_suffix
260 if arguments
is None:
261 arguments = constructor_info.idl_args[0]
262 argument_count =
len(arguments)
264 argument_count =
len(arguments)
266 typed_formals = constructor_info.ParametersAsArgumentList(
268 parameters = constructor_info.ParametersAsStringOfVariables(
272 dart_native_name, constructor_callback_id = \
277 if not emit_to_native:
282 ' static $INTERFACE_NAME $FACTORY_METHOD_NAME($PARAMETERS) => '
283 '$TOPLEVEL_NAME($OUTPARAMETERS);\n',
285 FACTORY_METHOD_NAME=factory_method_name,
286 PARAMETERS=typed_formals,
287 TOPLEVEL_NAME=toplevel_name,
288 OUTPARAMETERS=parameters)
291 ' if (name == "$ID")\n'
292 ' return Dart$(WEBKIT_INTERFACE_NAME)Internal::$CPP_CALLBACK;\n',
293 ID=constructor_callback_id,
295 CPP_CALLBACK=constructor_callback_cpp_name)
305 '\n $(ANNOTATIONS)factory $CTOR($PARAMS) => _create($FACTORY_PARAMS);\n',
306 ANNOTATIONS=annotations,
307 CTOR=constructor_info._ConstructorFullName(self.
_DartType),
308 PARAMS=constructor_info.ParametersAsDeclaration(self.
_DartType),
310 constructor_info.ParametersAsArgumentList())
314 constructor_callback_cpp_name =
'constructorCallback'
318 constructor_callback_cpp_name,
324 'void $CPP_CALLBACK(Dart_NativeArguments);\n',
325 CPP_CALLBACK=constructor_callback_cpp_name)
330 return IsOptional(argument)
333 return emitter.Format(
334 '$FACTORY.$METHOD($ARGUMENTS)',
340 constructor_callback_cpp_name = name +
'constructorCallback'
344 'constructorCallback',
352 create_function =
'create'
353 if 'NamedConstructor' in ext_attrs:
354 create_function =
'createForJSConstructor'
355 function_expression =
'%s::%s' % (
365 if type(value) == tuple:
366 return (value[0],
'true')
372 if interface.parents:
373 supertype =
'%sClassId' % interface.parents[0].type.id
382 SUPER_INTERFACE=supertype,
388 replace(
'<',
'_').replace(
'>',
'_'),
390 implementation_name(),
391 DART_IMPLEMENTATION_LIBRARY_ID=
'Dart%sLibraryId' %
394 def _GenerateCPPHeader(self):
397 return_type =
'PassRefPtr<NativeType>'
399 to_native_arg_body =
';'
401 return_type =
'NativeType*'
402 to_native_body = emitter.Format(
405 ' DartDOMData* domData = DartDOMData::current();\n'
406 ' return DartDOMWrapper::unwrapDartWrapper<Dart$INTERFACE>(domData, handle, exception);\n'
409 to_native_arg_body = emitter.Format(
412 ' return DartDOMWrapper::unwrapDartWrapper<Dart$INTERFACE>(args, index, exception);\n'
416 to_native_emitter.Emit(
417 ' static $RETURN_TYPE toNative(Dart_Handle handle, Dart_Handle& exception)$TO_NATIVE_BODY\n'
419 ' static $RETURN_TYPE toNativeWithNullCheck(Dart_Handle handle, Dart_Handle& exception)\n'
421 ' return Dart_IsNull(handle) ? 0 : toNative(handle, exception);\n'
424 ' static $RETURN_TYPE toNative(Dart_NativeArguments args, int index, Dart_Handle& exception)$TO_NATIVE_ARG_BODY\n'
426 ' static $RETURN_TYPE toNativeWithNullCheck(Dart_NativeArguments args, int index, Dart_Handle& exception)\n'
428 ' // toNative accounts for Null objects also.\n'
429 ' return toNative(args, index, exception);\n'
431 RETURN_TYPE=return_type,
432 TO_NATIVE_BODY=to_native_body,
433 TO_NATIVE_ARG_BODY=to_native_arg_body,
440 to_dart_emitter.Emit(
441 ' static Dart_Handle toDart(NativeType* value)\n'
444 ' return Dart_Null();\n'
445 ' DartDOMData* domData = DartDOMData::current();\n'
446 ' Dart_WeakPersistentHandle result =\n'
447 ' DartDOMWrapper::lookupWrapper<Dart$(INTERFACE)>(domData, value);\n'
449 ' return Dart_HandleFromWeakPersistent(result);\n'
450 ' return createWrapper(domData, value);\n'
452 ' static void returnToDart(Dart_NativeArguments args,\n'
453 ' NativeType* value,\n'
454 ' bool autoDartScope = true)\n'
457 ' DartDOMData* domData = static_cast<DartDOMData*>(\n'
458 ' Dart_GetNativeIsolateData(args));\n'
459 ' Dart_WeakPersistentHandle result =\n'
460 ' DartDOMWrapper::lookupWrapper<Dart$(INTERFACE)>(domData, value);\n'
462 ' Dart_SetWeakHandleReturnValue(args, result);\n'
464 ' if (autoDartScope) {\n'
465 ' Dart_SetReturnValue(args, createWrapper(domData, value));\n'
467 ' DartApiScope apiScope;\n'
468 ' Dart_SetReturnValue(args, createWrapper(domData, value));\n'
475 if (
'CustomToV8' in ext_attrs
or 'PureInterface' in ext_attrs
or
476 'CPPPureInterface' in ext_attrs
or
477 'SpecialWrapFor' in ext_attrs
or
478 (
'Custom' in ext_attrs
and ext_attrs[
'Custom'] ==
'Wrap')
or
479 (
'Custom' in ext_attrs
and ext_attrs[
'Custom'] ==
'ToV8')
or
481 to_dart_emitter.Emit(
482 ' static Dart_Handle createWrapper(DartDOMData* domData, NativeType* value);\n'
485 to_dart_emitter.Emit(
486 ' static Dart_Handle createWrapper(DartDOMData* domData, NativeType* value)\n'
488 ' return DartDOMWrapper::createWrapper<Dart$(INTERFACE)>(domData, value, Dart$(INTERFACE)::dartClassId);\n'
495 is_node_test =
lambda interface: interface.id ==
'Node'
496 is_active_test =
lambda interface:
'ActiveDOMObject' in interface.ext_attrs
497 is_event_target_test =
lambda interface:
'EventTarget' in interface.ext_attrs
499 def TypeCheckHelper(test):
500 return 'true' if any(
508 if (
any(
map(is_active_test,
510 to_active_emitter.Emit(
'return toNative(value);')
512 to_active_emitter.Emit(
'return 0;')
515 to_node_emitter.Emit(
'return toNative(value);')
517 to_node_emitter.Emit(
'return 0;')
520 map(is_event_target_test,
522 to_event_target_emitter.Emit(
'return toNative(value);')
524 to_event_target_emitter.Emit(
'return 0;')
526 v8_interface_include =
''
535 WEBCORE_INCLUDES=webcore_includes,
536 V8_INTERFACE_INCLUDE=v8_interface_include,
539 replace(
'<',
'_').replace(
'>',
'_'),
541 IS_NODE=TypeCheckHelper(is_node_test),
542 IS_ACTIVE=TypeCheckHelper(is_active_test),
543 IS_EVENT_TARGET=TypeCheckHelper(is_event_target_test),
544 TO_NODE=to_node_emitter.Fragments(),
545 TO_ACTIVE=to_active_emitter.Fragments(),
546 TO_EVENT_TARGET=to_event_target_emitter.Fragments(),
547 TO_NATIVE=to_native_emitter.Fragments(),
548 TO_DART=to_dart_emitter.Fragments())
551 self.
_AddGetter(attribute, html_name, read_only)
555 def _GenerateAutoSetupScope(self, idl_name, native_suffix):
558 def _AddGetter(self, attr, html_name, read_only):
567 dictionary_returned =
False
569 if attr.type.id ==
'Dictionary':
571 dictionary_returned =
True
574 dart_declaration =
'%s get %s' % (return_type, html_name)
575 is_custom = _IsCustom(attr)
and (_IsCustomValue(attr,
None)
or
576 _IsCustomValue(attr,
'Getter'))
579 wrap_unwrap_list = []
580 return_wrap_jso =
False
590 return_wrap_jso = wrap_return_type_blink(return_type, attr.type.id,
592 wrap_unwrap_list.append(return_wrap_jso)
597 assert (
not (
'CustomGetter' in attr.ext_attrs))
598 native_suffix =
'Getter'
614 native_entry=native_entry,
615 wrap_unwrap_list=wrap_unwrap_list,
616 dictionary_return=dictionary_returned,
617 output_conversion=output_conversion)
621 if 'Reflect' in attr.ext_attrs:
623 attr.type.id).webcore_getter_name()
624 if 'URL' in attr.ext_attrs:
625 if 'NonEmpty' in attr.ext_attrs:
626 webcore_function_name =
'getNonEmptyURLAttribute'
628 webcore_function_name =
'getURLAttribute'
629 elif 'ImplementedAs' in attr.ext_attrs:
630 webcore_function_name = attr.ext_attrs[
'ImplementedAs']
632 if attr.id ==
'operator':
633 webcore_function_name =
'_operator'
634 elif attr.id ==
'target' and attr.type.id ==
'SVGAnimatedString':
635 webcore_function_name =
'svgTarget'
636 elif attr.id ==
'CSS':
637 webcore_function_name =
'css'
642 webcore_function_name, attr)
643 raises = (
'RaisesException' in attr.ext_attrs
and
644 attr.ext_attrs[
'RaisesException'] !=
'Setter')
646 def _AddSetter(self, attr, html_name):
654 parameters = [
'value']
656 dart_declaration =
'set %s(%s value)' % (html_name, ptype)
657 is_custom = _IsCustom(attr)
and (_IsCustomValue(attr,
None)
or
658 _IsCustomValue(attr,
'Setter'))
661 assert (
not (
'CustomSetter' in attr.ext_attrs))
662 assert (
not (
'V8CustomSetter' in attr.ext_attrs))
663 native_suffix =
'Setter'
681 native_entry=native_entry,
682 wrap_unwrap_list=wrap_unwrap_list)
686 if 'Reflect' in attr.ext_attrs:
688 attr.type.id).webcore_setter_name()
690 if 'ImplementedAs' in attr.ext_attrs:
691 attr_name = attr.ext_attrs[
'ImplementedAs']
694 webcore_function_name = re.sub(
r'^(xml|css|(?=[A-Z])|\w)',
695 lambda s: s.group(1).upper(),
697 webcore_function_name =
'set%s' % webcore_function_name
700 webcore_function_name, attr)
701 raises = (
'RaisesException' in attr.ext_attrs
and
702 attr.ext_attrs[
'RaisesException'] !=
'Getter')
705 """Adds all the methods required to complete implementation of List."""
723 dart_element_type = self.
_DartType(element_type)
729 is_custom =
any((op.id ==
'item' and _IsCustom(op))
734 if output_conversion:
735 conversion_name = output_conversion.function_name
739 dart_native_name, resolver_string = \
744 dart_qualified_name = \
749 blinkNativeIndexed =
"""
750 $TYPE operator[](int index) {
751 if (index < 0 || index >= length)
752 throw new IndexError.withLength(index, length, indexable: this);
753 return _nativeIndexedGetter(index);
756 $TYPE _nativeIndexedGetter(int index) => $(CONVERSION_NAME)($(DART_NATIVE_NAME)(this, index));
758 blinkNativeIndexedGetter = \
759 ' $(DART_NATIVE_NAME)(this, index);\n'
762 DART_NATIVE_NAME=dart_qualified_name,
765 CONVERSION_NAME=conversion_name)
772 ' void operator[]=(int index, $TYPE value) {\n'
773 ' throw new UnsupportedError("Cannot assign element of immutable List.");\n'
775 TYPE=dart_element_type)
787 dart_element_type = self.
_DartType(element_type)
794 def _HasNativeIndexGetter(self):
797 def _EmitNativeIndexGetter(self, element_type):
799 parameters = [
'index']
800 dart_declaration =
'%s operator[](int index)' % return_type
802 False, return_type, parameters,
'Callback',
805 def _HasExplicitIndexedGetter(self):
808 def _EmitExplicitIndexedGetter(self, dart_element_type):
810 indexed_getter =
'getItem'
814 ' $TYPE operator[](int index) {\n'
815 ' if (index < 0 || index >= length)\n'
816 ' throw new IndexError.withLength(index, length, indexable: this);\n'
817 ' return $INDEXED_GETTER(index);\n'
819 TYPE=dart_element_type,
820 INDEXED_GETTER=indexed_getter)
822 def _HasNativeIndexSetter(self):
825 def _EmitNativeIndexSetter(self, element_type):
827 formals =
', '.
join([
'int index',
'%s value' % element_type])
828 parameters = [
'index',
'value']
829 dart_declaration =
'void operator[]=(%s)' % formals
831 False, return_type, parameters,
'Callback',
834 def _ChangePrivateOpMapArgToAny(self, operations):
839 for operation
in operations:
840 for arg
in operation.arguments:
842 if type.id ==
'Dictionary':
848 info: An OperationInfo object.
857 False if dart_js_interop
else True)
859 formals = info.ParametersAsDeclaration(self.
_DartType)
861 parameters = info.ParametersAsListOfVariables(
863 dart_js_interop, self)
865 operation = info.operations[0]
870 dictionary_returned =
False
872 if operation.type.id ==
'Dictionary':
874 dictionary_returned =
True
876 dart_declaration =
'%s%s %s(%s)' % (
'static ' if info.IsStatic()
else
877 '', return_type, html_name, formals)
879 is_custom = _IsCustom(operation)
880 has_optional_arguments =
any(
881 IsOptional(argument)
for argument
in operation.arguments)
882 needs_dispatcher =
not is_custom
and (
len(info.operations) > 1
or
883 has_optional_arguments)
886 wrap_unwrap_list = []
887 return_wrap_jso =
False
896 return_wrap_jso = wrap_return_type_blink(
900 wrap_unwrap_list.append(return_wrap_jso)
903 if info.callback_args:
905 elif not needs_dispatcher:
907 argument_count = (0
if info.IsStatic()
else 1) +
len(
909 native_suffix =
'Callback'
911 info.name, native_suffix)
924 native_entry=native_entry,
925 wrap_unwrap_list=wrap_unwrap_list,
926 dictionary_return=dictionary_returned,
927 output_conversion=output_conversion)
930 operation, operation.arguments, cpp_callback_name,
936 def _GenerateDispatcher(self, info, operations, dart_declaration,
939 def GenerateCall(stmts_emitter, call_emitter, version, operation,
941 native_suffix =
'Callback'
942 actuals = info.ParametersAsListOfVariables(
946 actuals_s =
", ".
join(actuals)
950 return_wrap_jso =
False
952 return_wrap_jso = wrap_return_type_blink(
955 native_suffix =
'Callback'
956 is_custom = _IsCustom(operation)
957 base_name =
'_%s_%s' % (operation.id, version)
959 if not operation.is_static:
960 actuals = [
'this'] + actuals
961 formals = [
'mthis'] + formals
962 actuals_s =
", ".
join(actuals)
963 formals_s =
", ".
join(formals)
964 dart_declaration =
'%s(%s)' % (base_name, formals_s)
967 overload_base_name = native_entry[0]
972 '$NAME($ARGS)', NAME=overload_name, ARGS=actuals_s)
976 base_name, (0
if static
else 1) + argument_count,
986 native_entry=native_entry)
989 operation, operation.arguments[:argument_count],
990 cpp_callback_name, auto_scope_setup)
993 GenerateCall, IsOptional)
998 def _GenerateOperationNativeCallback(self,
1002 auto_scope_setup=True):
1003 webcore_function_name = operation.ext_attrs.get(
'ImplementedAs',
1006 function_expression = self._GenerateWebCoreFunctionExpression(
1007 webcore_function_name, operation, cpp_callback_name)
1009 def _GenerateNativeBinding(self,
1018 auto_scope_setup=True,
1020 emit_to_native=False,
1022 wrap_unwrap_list=[],
1023 dictionary_return=False,
1024 output_conversion=None):
1027 metadata = self._metadata.GetFormattedMetadata(
1028 self._renamer.GetLibraryName(self._interface), self._interface,
1032 dart_native_name, native_binding = native_entry
1034 dart_native_name = \
1035 self.DeriveNativeName(idl_name, native_suffix)
1036 native_binding_id = self._interface.id
1040 '%s_%s_%s' % (native_binding_id, idl_name, native_suffix)
1043 formals =
", ".
join([
'mthis'] + parameters)
1044 actuals =
", ".
join([
'this'] + parameters)
1046 formals =
", ".
join(parameters)
1047 actuals =
", ".
join(parameters)
1049 if not emit_to_native:
1050 caller_emitter = self._members_emitter
1052 self.DeriveQualifiedBlinkName(self._interface.id,
1054 if IsPureInterface(self._interface.id, self._database):
1055 caller_emitter.Emit(
'\n'
1056 ' $METADATA$DART_DECLARATION;\n',
1058 DART_DECLARATION=dart_declaration)
1061 $METADATA$DART_DECLARATION => $DART_NAME($ACTUALS);
1063 if output_conversion
and not dictionary_return:
1064 conversion_template =
'''
1065 $METADATA$DART_DECLARATION => %s($DART_NAME($ACTUALS));
1067 emit_template = conversion_template % output_conversion.function_name
1069 elif wrap_unwrap_list
and wrap_unwrap_list[0]:
1070 if return_type ==
'Rectangle':
1071 jso_util_method =
'make_dart_rectangle'
1072 elif wrap_unwrap_list[0]:
1073 jso_util_method =
''
1075 if dictionary_return:
1076 emit_jso_template =
'''
1077 $METADATA$DART_DECLARATION => convertNativeDictionaryToDartDictionary(%s($DART_NAME($ACTUALS)));
1080 emit_jso_template =
'''
1081 $METADATA$DART_DECLARATION => %s($DART_NAME($ACTUALS));
1083 emit_template = emit_jso_template % jso_util_method
1086 caller_emitter.Emit(
1089 DART_DECLARATION=dart_declaration,
1090 DART_NAME=full_dart_name,
1092 cpp_callback_name =
'%s%s' % (idl_name, native_suffix)
1094 self._cpp_resolver_emitter.Emit(
1095 ' if (argumentCount == $ARGC && name == "$NATIVE_BINDING") {\n'
1096 ' *autoSetupScope = $AUTO_SCOPE_SETUP;\n'
1097 ' return Dart$(INTERFACE_NAME)Internal::$CPP_CALLBACK_NAME;\n'
1099 ARGC=argument_count,
1100 NATIVE_BINDING=native_binding,
1101 INTERFACE_NAME=self._interface.id,
1102 AUTO_SCOPE_SETUP=
'true' if auto_scope_setup
else 'false',
1103 CPP_CALLBACK_NAME=cpp_callback_name)
1106 self._cpp_declarations_emitter.Emit(
1108 'void $CPP_CALLBACK_NAME(Dart_NativeArguments);\n',
1109 CPP_CALLBACK_NAME=cpp_callback_name)
1111 return cpp_callback_name
1113 def _GenerateWebCoreReflectionAttributeName(self, attr):
1114 namespace =
'HTMLNames'
1116 'class',
'id',
'onabort',
'onclick',
'onerror',
'onload',
1117 'onmousedown',
'onmousemove',
'onmouseout',
'onmouseover',
1118 'onmouseup',
'onresize',
'onscroll',
'onunload'
1120 if self._interface.id.startswith(
1121 'SVG')
and not attr.id
in svg_exceptions:
1122 namespace =
'SVGNames'
1123 self._cpp_impl_includes.add(
'"%s.h"' % namespace)
1125 attribute_name = attr.ext_attrs[
'Reflect']
or attr.id.lower()
1126 return 'WebCore::%s::%sAttr' % (namespace, attribute_name)
1128 def _IsStatic(self, attribute_name):
1131 def _GenerateWebCoreFunctionExpression(self,
1134 cpp_callback_name=None):
1137 def _IsArgumentOptionalInWebCore(self, operation, argument):
1138 if not IsOptional(argument):
1140 if 'Callback' in argument.ext_attrs:
1142 if operation.id
in [
'addEventListener',
'removeEventListener'
1143 ]
and argument.id ==
'useCapture':
1145 if 'DartForceOptional' in argument.ext_attrs:
1147 if argument.type.id ==
'Dictionary':
1151 def _GenerateCPPIncludes(self, includes):
1154 def _ToWebKitName(self, name):
1155 name = name[0].
lower() + name[1:]
1156 name = re.sub(
r'^(hTML|uRL|jS|xML|xSLT)',
lambda s: s.group(1).
lower(),
1158 return re.sub(
r'^(create|exclusive)',
1159 lambda s:
'is' + s.group(1).
capitalize(), name)
1181 'Dart%s.cpp' % interface_name)
1188 for i
in range(0, partitions):
1189 file_path = os.path.join(output_dir,
1190 'DartDerivedSources%02i.cpp' % (i + 1))
1191 includes_emitter = self.
_emitters.FileEmitter(file_path).Emit(
1194 path = os.path.relpath(source_file, output_dir)
1195 includes_emitter.Emit(
'#include "$PATH"\n', PATH=path)
1199 file_path = os.path.join(output_dir,
1200 '%s_DartResolver.cpp' % library_name)
1201 includes_emitter, body_emitter = self.
_emitters.FileEmitter(
1203 template, LIBRARY_NAME=library_name)
1206 for header_file
in headers:
1207 path = os.path.relpath(header_file, output_dir)
1208 includes_emitter.Emit(
'#include "$PATH"\n', PATH=path)
1210 ' if (Dart_NativeFunction func = $CLASS_NAME::resolver(name, argumentCount, autoSetupScope))\n'
1212 CLASS_NAME=os.path.splitext(os.path.basename(path))[0])
1216 def HasConverters(interface):
1217 is_node_test =
lambda interface: interface.id ==
'Node'
1218 is_active_test =
lambda interface:
'ActiveDOMObject' in interface.ext_attrs
1219 is_event_target_test =
lambda interface:
'EventTarget' in interface.ext_attrs
1222 any(
map(is_node_test, database.Hierarchy(interface)))
or
1223 any(
map(is_active_test, database.Hierarchy(interface)))
or
1224 any(
map(is_event_target_test, database.Hierarchy(interface))))
1226 path = os.path.join(output_dir,
'DartWebkitClassIds.h')
1229 '// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file\n'
1232 '// for details. All rights reserved. Use of this source code is governed by a\n'
1234 e.Emit(
'// BSD-style license that can be found in the LICENSE file.\n')
1235 e.Emit(
'// WARNING: Do not edit - generated code.\n')
1236 e.Emit(
'// See dart/tools/dom/scripts/systemnative.py\n')
1238 e.Emit(
'#ifndef DartWebkitClassIds_h\n')
1239 e.Emit(
'#define DartWebkitClassIds_h\n')
1241 e.Emit(
'namespace WebCore {\n')
1244 e.Emit(
' _InvalidClassId = 0,\n')
1245 e.Emit(
' _HistoryCrossFrameClassId,\n')
1246 e.Emit(
' _LocationCrossFrameClassId,\n')
1247 e.Emit(
' _DOMWindowCrossFrameClassId,\n')
1248 e.Emit(
' _DateTimeClassId,\n')
1249 e.Emit(
' _JsObjectClassId,\n')
1250 e.Emit(
' _JsFunctionClassId,\n')
1251 e.Emit(
' _JsArrayClassId,\n')
1253 ' // New types that are not auto-generated should be added here.\n'
1256 for interface
in database.GetInterfaces():
1257 e.Emit(
' %sClassId,\n' % interface.id)
1258 e.Emit(
' NumWebkitClassIds\n')
1261 'class ActiveDOMObject;\n'
1262 'class EventTarget;\n'
1264 'typedef ActiveDOMObject* (*ToActiveDOMObject)(void* value);\n'
1265 'typedef EventTarget* (*ToEventTarget)(void* value);\n'
1266 'typedef Node* (*ToNode)(void* value);\n'
1267 'typedef struct {\n'
1268 ' const char* class_name;\n'
1269 ' int library_id;\n'
1270 ' int base_class_id;\n'
1271 ' ToActiveDOMObject toActiveDOMObject;\n'
1272 ' ToEventTarget toEventTarget;\n'
1274 '} DartWrapperTypeInfo;\n'
1275 'typedef DartWrapperTypeInfo _DartWebkitClassInfo[NumWebkitClassIds];\n'
1277 'extern _DartWebkitClassInfo DartWebkitClassInfo;\n'
1279 '} // namespace WebCore\n'
1280 '#endif // DartWebkitClassIds_h\n')
1282 path = os.path.join(output_dir,
'DartWebkitClassIds.cpp')
1285 '// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file\n'
1288 '// for details. All rights reserved. Use of this source code is governed by a\n'
1290 e.Emit(
'// BSD-style license that can be found in the LICENSE file.\n')
1291 e.Emit(
'// WARNING: Do not edit - generated code.\n')
1292 e.Emit(
'// See dart/tools/dom/scripts/systemnative.py\n')
1294 e.Emit(
'#include "config.h"\n')
1295 e.Emit(
'#include "DartWebkitClassIds.h"\n')
1297 e.Emit(
'#include "bindings/dart/DartLibraryIds.h"\n')
1298 for interface
in database.GetInterfaces():
1299 if HasConverters(interface):
1300 e.Emit(
'#include "Dart%s.h"\n' % interface.id)
1303 e.Emit(
'namespace WebCore {\n')
1308 'ActiveDOMObject* toNullActiveDOMObject(void* value) { return 0; }\n'
1310 e.Emit(
'EventTarget* toNullEventTarget(void* value) { return 0; }\n')
1311 e.Emit(
'Node* toNullNode(void* value) { return 0; }\n')
1313 e.Emit(
"_DartWebkitClassInfo DartWebkitClassInfo = {\n")
1316 ' "_InvalidClassId", -1, -1,\n'
1317 ' toNullActiveDOMObject, toNullEventTarget, toNullNode\n'
1320 ' "_HistoryCrossFrame", DartHtmlLibraryId, -1,\n'
1321 ' toNullActiveDOMObject, toNullEventTarget, toNullNode\n'
1324 ' "_LocationCrossFrame", DartHtmlLibraryId, -1,\n'
1325 ' toNullActiveDOMObject, toNullEventTarget, toNullNode\n'
1328 ' "_DOMWindowCrossFrame", DartHtmlLibraryId, -1,\n'
1329 ' toNullActiveDOMObject, toNullEventTarget, toNullNode\n'
1332 ' "DateTime", DartCoreLibraryId, -1,\n'
1333 ' toNullActiveDOMObject, toNullEventTarget, toNullNode\n'
1336 ' "JsObject", DartJsLibraryId, -1,\n'
1337 ' toNullActiveDOMObject, toNullEventTarget, toNullNode\n'
1340 ' "JsFunction", DartJsLibraryId, _JsObjectClassId,\n'
1341 ' toNullActiveDOMObject, toNullEventTarget, toNullNode\n'
1344 ' "JsArray", DartJsLibraryId, _JsObjectClassId,\n'
1345 ' toNullActiveDOMObject, toNullEventTarget, toNullNode\n'
1348 ' // New types that are not auto-generated should be added here.\n'
1350 for interface
in database.GetInterfaces():
1352 type_info = type_registry.TypeInfo(name)
1353 type_info.native_type().replace(
'<',
'_').replace(
'>',
'_')
1355 e.Emit(
' "%s", ' % type_info.implementation_name())
1356 e.Emit(
'Dart%sLibraryId, ' % renamer.GetLibraryId(interface))
1357 if interface.parents:
1358 supertype = interface.parents[0].type.id
1359 e.Emit(
'%sClassId,\n' % supertype)
1362 if HasConverters(interface):
1364 ' Dart%s::toActiveDOMObject, Dart%s::toEventTarget,'
1365 ' Dart%s::toNode\n' % (name, name, name))
1368 ' toNullActiveDOMObject, toNullEventTarget, toNullNode\n'
1374 e.Emit(
'} // namespace WebCore\n')
1377def _IsOptionalStringArgumentInInitEventMethod(interface, operation, argument):
1378 return (interface.id.endswith(
'Event')
and
1379 operation.id.startswith(
'init')
and
1380 argument.default_value ==
'Undefined' and
1381 argument.type.id ==
'DOMString')
1384def _IsCustom(op_or_attr):
1385 assert (isinstance(op_or_attr, IDLMember))
1386 return 'Custom' in op_or_attr.ext_attrs
or 'DartCustom' in op_or_attr.ext_attrs
1389def _IsCustomValue(op_or_attr, value):
1390 if _IsCustom(op_or_attr):
1391 return op_or_attr.ext_attrs.get(
'Custom') == value \
1392 or op_or_attr.ext_attrs.get(
'DartCustom') == value
def SecureOutputType(self, type_name, is_dart_type=False, can_narrow_type=False, nullable=False)
def _GenerateDispatcherBody(self, info, operations, declaration, generate_call, is_optional, can_omit_type_check=lambda type, False pos)
def _DartType(self, type_name)
def _TypeInfo(self, type_name)
def EmitListMixin(self, element_name, nullable)
def _AddFutureifiedOperation(self, info, html_name)
def EmitDerivedSources(self, template, output_dir)
def CreateSourceEmitter(self, interface_name)
def CreateHeaderEmitter(self, interface_name, library_name, is_callback=False)
def EmitResolver(self, template, output_dir)
def __init__(self, emitters, cpp_sources_dir)
def EmitClassIdTable(self, database, output_dir, type_registry, renamer)
def FinishInterface(self)
def GenerateCustomFactory(self, constructor_info)
def __init__(self, interface, cpp_library_emitter, options, loggerParent)
def _EmitExplicitIndexedGetter(self, dart_element_type)
def _ToWebKitName(self, name)
def GetSupportCheck(self)
def _EmitConstructorInfrastructure(self, constructor_info, cpp_prefix, cpp_suffix, factory_method_name, arguments=None, emit_to_native=False, is_custom=False)
_cpp_declarations_emitter
def _OutputConversion(self, idl_type, member)
def _GenerateAutoSetupScope(self, idl_name, native_suffix)
def EmitStaticFactoryOverload(self, constructor_info, name, arguments)
def _GenerateCPPHeader(self)
def _GenerateWebCoreFunctionExpression(self, function_name, idl_node, cpp_callback_name=None)
def _GenerateCPPIncludes(self, includes)
def _EmitNativeIndexSetter(self, element_type)
def DeriveNativeEntry(self, name, kind, count)
def _AddSetter(self, attr, html_name)
def _GenerateDispatcher(self, info, operations, dart_declaration, html_name)
def HasSupportCheck(self)
def _HasNativeIndexGetter(self)
def EmitOperation(self, info, html_name, dart_js_interop=False)
def _HasNativeIndexSetter(self)
def _EmitNativeIndexGetter(self, element_type)
def MakeFactoryCall(self, factory, method, arguments, constructor_info)
def AddIndexer(self, element_type, nullable)
def ImplementationTemplate(self)
def _AddGetter(self, attr, html_name, read_only)
def GenerateCallback(self, info)
def _ChangePrivateOpMapArgToAny(self, operations)
def DeriveNativeName(self, name, suffix="")
def _GenerateNativeBinding(self, idl_name, argument_count, dart_declaration, static, return_type, parameters, native_suffix, is_custom, auto_scope_setup=True, emit_metadata=True, emit_to_native=False, native_entry=None, wrap_unwrap_list=[], dictionary_return=False, output_conversion=None)
def CustomJSMembers(self)
def _HasExplicitIndexedGetter(self)
def ImplementsMergedMembers(self)
def _GenerateOperationNativeCallback(self, operation, arguments, cpp_callback_name, auto_scope_setup=True)
def EmitAttribute(self, attribute, html_name, read_only)
def DeriveQualifiedBlinkName(self, interface_name, name)
def SecondaryContext(self, interface)
def StartInterface(self, members_emitter)
def AmendIndexer(self, element_type)
def IsConstructorArgumentOptional(self, argument)
static void append(char **dst, size_t *count, const char *src, size_t n)
def DeriveQualifiedName(library_name, name)
def array_type(data_type)
def TypeIdToBlinkName(interface_id, database)
def DeriveBlinkClassName(name)
SI auto map(std::index_sequence< I... >, Fn &&fn, const Args &... args) -> skvx::Vec< sizeof...(I), decltype(fn(args[0]...))>
SIT bool any(const Vec< 1, T > &x)
static SkString join(const CommandLineFlags::StringArray &)