OLD | NEW |
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 # Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 2 # Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
3 # for details. All rights reserved. Use of this source code is governed by a | 3 # for details. All rights reserved. Use of this source code is governed by a |
4 # BSD-style license that can be found in the LICENSE file. | 4 # BSD-style license that can be found in the LICENSE file. |
5 | 5 |
6 """This module provides shared functionality for the systems to generate | 6 """This module provides shared functionality for the systems to generate |
7 native binding from the IDL database.""" | 7 native binding from the IDL database.""" |
8 | 8 |
9 import emitter | 9 import emitter |
10 import os | 10 import os |
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
292 parameter_definitions = '' | 292 parameter_definitions = '' |
293 if 'CallWith' in self._interface.ext_attrs: | 293 if 'CallWith' in self._interface.ext_attrs: |
294 call_with = self._interface.ext_attrs['CallWith'] | 294 call_with = self._interface.ext_attrs['CallWith'] |
295 if call_with == 'ScriptExecutionContext': | 295 if call_with == 'ScriptExecutionContext': |
296 raises_dart_exceptions = True | 296 raises_dart_exceptions = True |
297 parameter_definitions = ( | 297 parameter_definitions = ( |
298 ' ScriptExecutionContext* context = DartUtilities::scriptExec
utionContext();\n' | 298 ' ScriptExecutionContext* context = DartUtilities::scriptExec
utionContext();\n' |
299 ' if (!context) {\n' | 299 ' if (!context) {\n' |
300 ' exception = Dart_NewString("Failed to create an object"
);\n' | 300 ' exception = Dart_NewString("Failed to create an object"
);\n' |
301 ' goto fail;\n' | 301 ' goto fail;\n' |
302 ' }\n') | 302 ' }') |
303 arguments = ['context'] | 303 arguments = ['context'] |
304 else: | 304 else: |
305 raise Exception('Unsupported CallWith=%s attribute' % call_with) | 305 raise Exception('Unsupported CallWith=%s attribute' % call_with) |
306 | 306 |
307 self._GenerateNativeCallback( | 307 self._GenerateNativeCallback( |
308 callback_name='constructorCallback', | 308 callback_name='constructorCallback', |
309 idl_node=self._interface, | 309 idl_node=self._interface, |
310 parameter_definitions=parameter_definitions, | 310 parameter_definitions=parameter_definitions, |
311 needs_receiver=False, function_name='%s::create' % type_info.native_type
(), | 311 needs_receiver=False, function_name='%s::create' % type_info.native_type
(), |
312 arguments=arguments, | 312 arguments=arguments, |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
395 if (self._interface.id in classes_with_unsupported_custom_getters and | 395 if (self._interface.id in classes_with_unsupported_custom_getters and |
396 getter and set(['Custom', 'CustomGetter']) & set(getter.ext_attrs)): | 396 getter and set(['Custom', 'CustomGetter']) & set(getter.ext_attrs)): |
397 return | 397 return |
398 | 398 |
399 if getter: | 399 if getter: |
400 self._AddGetter(getter) | 400 self._AddGetter(getter) |
401 if setter: | 401 if setter: |
402 self._AddSetter(setter) | 402 self._AddSetter(setter) |
403 | 403 |
404 def _AddGetter(self, attr): | 404 def _AddGetter(self, attr): |
405 dart_declaration = '%s get %s()' % (attr.type.id, attr.id) | 405 type_info = GetIDLTypeInfo(attr.type) |
| 406 dart_declaration = '%s get %s()' % (type_info.dart_type(), attr.id) |
406 is_custom = 'Custom' in attr.ext_attrs or 'CustomGetter' in attr.ext_attrs | 407 is_custom = 'Custom' in attr.ext_attrs or 'CustomGetter' in attr.ext_attrs |
407 cpp_callback_name = self._GenerateNativeBinding(attr.id, 1, | 408 cpp_callback_name = self._GenerateNativeBinding(attr.id, 1, |
408 dart_declaration, 'Getter', is_custom) | 409 dart_declaration, 'Getter', is_custom) |
409 if is_custom: | 410 if is_custom: |
410 return | 411 return |
411 | 412 |
412 arguments = [] | 413 arguments = [] |
413 if 'Reflect' in attr.ext_attrs: | 414 if 'Reflect' in attr.ext_attrs: |
414 webcore_function_name = GetIDLTypeInfo(attr.type).webcore_getter_name() | 415 webcore_function_name = GetIDLTypeInfo(attr.type).webcore_getter_name() |
415 if 'URL' in attr.ext_attrs: | 416 if 'URL' in attr.ext_attrs: |
(...skipping 16 matching lines...) Expand all Loading... |
432 webcore_function_name) | 433 webcore_function_name) |
433 if attr.type.id.startswith('SVGAnimated'): | 434 if attr.type.id.startswith('SVGAnimated'): |
434 webcore_function_name += 'Animated' | 435 webcore_function_name += 'Animated' |
435 | 436 |
436 self._GenerateNativeCallback(cpp_callback_name, attr, '', | 437 self._GenerateNativeCallback(cpp_callback_name, attr, '', |
437 True, webcore_function_name, arguments, idl_return_type=attr.type, | 438 True, webcore_function_name, arguments, idl_return_type=attr.type, |
438 raises_dart_exceptions=attr.get_raises, | 439 raises_dart_exceptions=attr.get_raises, |
439 raises_dom_exceptions=attr.get_raises) | 440 raises_dom_exceptions=attr.get_raises) |
440 | 441 |
441 def _AddSetter(self, attr): | 442 def _AddSetter(self, attr): |
442 dart_declaration = 'void set %s(%s)' % (attr.id, attr.type.id) | 443 type_info = GetIDLTypeInfo(attr.type) |
| 444 dart_declaration = 'void set %s(%s)' % (attr.id, type_info.dart_type()) |
443 is_custom = set(['Custom', 'CustomSetter', 'V8CustomSetter']) & set(attr.ext
_attrs) | 445 is_custom = set(['Custom', 'CustomSetter', 'V8CustomSetter']) & set(attr.ext
_attrs) |
444 cpp_callback_name = self._GenerateNativeBinding(attr.id, 2, | 446 cpp_callback_name = self._GenerateNativeBinding(attr.id, 2, |
445 dart_declaration, 'Setter', is_custom) | 447 dart_declaration, 'Setter', is_custom) |
446 if is_custom: | 448 if is_custom: |
447 return | 449 return |
448 | 450 |
449 arguments = [] | 451 arguments = [] |
450 if 'Reflect' in attr.ext_attrs: | 452 if 'Reflect' in attr.ext_attrs: |
451 webcore_function_name = GetIDLTypeInfo(attr.type).webcore_setter_name() | 453 webcore_function_name = GetIDLTypeInfo(attr.type).webcore_setter_name() |
452 arguments.append(self._GenerateWebCoreReflectionAttributeName(attr)) | 454 arguments.append(self._GenerateWebCoreReflectionAttributeName(attr)) |
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
680 ' ExceptionCode ec = 0;\n' | 682 ' ExceptionCode ec = 0;\n' |
681 '$BODY' | 683 '$BODY' |
682 ' if (UNLIKELY(ec)) {\n' | 684 ' if (UNLIKELY(ec)) {\n' |
683 ' exception = DartDOMWrapper::exceptionCodeToDartException(
ec);\n' | 685 ' exception = DartDOMWrapper::exceptionCodeToDartException(
ec);\n' |
684 ' goto fail;\n' | 686 ' goto fail;\n' |
685 ' }\n') | 687 ' }\n') |
686 | 688 |
687 nested_templates.append( | 689 nested_templates.append( |
688 ' {\n' | 690 ' {\n' |
689 '$PARAMETER_DEFINITIONS' | 691 '$PARAMETER_DEFINITIONS' |
| 692 '\n' |
690 '$BODY' | 693 '$BODY' |
691 ' return;\n' | 694 ' return;\n' |
692 ' }\n') | 695 ' }\n') |
693 | 696 |
694 if raises_dart_exceptions: | 697 if raises_dart_exceptions: |
695 nested_templates.append( | 698 nested_templates.append( |
696 ' Dart_Handle exception;\n' | 699 ' Dart_Handle exception;\n' |
697 '$BODY' | 700 '$BODY' |
698 '\n' | 701 '\n' |
699 'fail:\n' | 702 'fail:\n' |
700 ' Dart_ThrowException(exception);\n' | 703 ' Dart_ThrowException(exception);\n' |
701 ' ASSERT_NOT_REACHED();\n') | 704 ' ASSERT_NOT_REACHED();\n') |
702 | 705 |
703 nested_templates.append( | 706 nested_templates.append( |
704 '\n' | 707 '\n' |
705 'static void $CALLBACK_NAME(Dart_NativeArguments args)\n' | 708 'static void $CALLBACK_NAME(Dart_NativeArguments args)\n' |
706 '{\n' | 709 '{\n' |
707 ' DartApiScope dartApiScope;\n' | 710 ' DartApiScope dartApiScope;\n' |
708 '$BODY' | 711 '$BODY' |
709 '}\n') | 712 '}\n') |
710 | 713 |
711 template_parameters = { | 714 template_parameters = { |
712 'CALLBACK_NAME': callback_name, | 715 'CALLBACK_NAME': callback_name, |
713 'WEBCORE_CLASS_NAME': self._interface_type_info.native_type(), | 716 'WEBCORE_CLASS_NAME': self._interface_type_info.native_type(), |
714 'PARAMETER_DEFINITIONS': parameter_definitions, | 717 'PARAMETER_DEFINITIONS': parameter_definitions, |
715 } | 718 } |
716 if needs_receiver: | 719 if needs_receiver: |
717 template_parameters['PARAMETER_DEFINITIONS'] = emitter.Format( | 720 template_parameters['PARAMETER_DEFINITIONS'] = emitter.Format( |
718 ' $WEBCORE_CLASS_NAME* receiver = DartDOMWrapper::receiver< $WE
BCORE_CLASS_NAME >(args);\n' | 721 ' $WEBCORE_CLASS_NAME* receiver = DartDOMWrapper::receiver< $WE
BCORE_CLASS_NAME >(args);\n' |
719 ' $PARAMETER_DEFINITIONS\n', | 722 '$PARAMETER_DEFINITIONS', |
720 **template_parameters) | 723 **template_parameters) |
721 | 724 |
722 for template in nested_templates: | 725 for template in nested_templates: |
723 template_parameters['BODY'] = callback | 726 template_parameters['BODY'] = callback |
724 callback = emitter.Format(template, **template_parameters) | 727 callback = emitter.Format(template, **template_parameters) |
725 | 728 |
726 self._cpp_definitions_emitter.Emit(callback) | 729 self._cpp_definitions_emitter.Emit(callback) |
727 | 730 |
728 def _GenerateParameterAdapter(self, emitter, idl_argument, index): | 731 def _GenerateParameterAdapter(self, emitter, idl_argument, index): |
729 type_info = GetIDLTypeInfo(idl_argument.type) | 732 type_info = GetIDLTypeInfo(idl_argument.type) |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
770 namespace = 'HTMLNames' | 773 namespace = 'HTMLNames' |
771 svg_exceptions = ['class', 'id', 'onabort', 'onclick', 'onerror', 'onload', | 774 svg_exceptions = ['class', 'id', 'onabort', 'onclick', 'onerror', 'onload', |
772 'onmousedown', 'onmousemove', 'onmouseout', 'onmouseover', | 775 'onmousedown', 'onmousemove', 'onmouseout', 'onmouseover', |
773 'onmouseup', 'onresize', 'onscroll', 'onunload'] | 776 'onmouseup', 'onresize', 'onscroll', 'onunload'] |
774 if self._interface.id.startswith('SVG') and not attr.id in svg_exceptions: | 777 if self._interface.id.startswith('SVG') and not attr.id in svg_exceptions: |
775 namespace = 'SVGNames' | 778 namespace = 'SVGNames' |
776 self._cpp_impl_includes[namespace] = 1 | 779 self._cpp_impl_includes[namespace] = 1 |
777 | 780 |
778 attribute_name = attr.ext_attrs['Reflect'] or attr.id.lower() | 781 attribute_name = attr.ext_attrs['Reflect'] or attr.id.lower() |
779 return 'WebCore::%s::%sAttr' % (namespace, attribute_name) | 782 return 'WebCore::%s::%sAttr' % (namespace, attribute_name) |
OLD | NEW |