| 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 765 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 776 return '%s::%s' % (idl_node.ext_attrs['ImplementedBy'], function_name) | 776 return '%s::%s' % (idl_node.ext_attrs['ImplementedBy'], function_name) |
| 777 return '%s%s' % (self._interface_type_info.receiver(), function_name) | 777 return '%s%s' % (self._interface_type_info.receiver(), function_name) |
| 778 | 778 |
| 779 def _GenerateWebCoreInvocation(self, function_expression, arguments, | 779 def _GenerateWebCoreInvocation(self, function_expression, arguments, |
| 780 idl_return_type, attributes, raises_dom_exceptions): | 780 idl_return_type, attributes, raises_dom_exceptions): |
| 781 invocation_template = ' $FUNCTION_CALL;\n' | 781 invocation_template = ' $FUNCTION_CALL;\n' |
| 782 if idl_return_type != 'void': | 782 if idl_return_type != 'void': |
| 783 return_type_info = GetIDLTypeInfo(idl_return_type) | 783 return_type_info = GetIDLTypeInfo(idl_return_type) |
| 784 self._cpp_impl_includes |= set(return_type_info.to_dart_includes()) | 784 self._cpp_impl_includes |= set(return_type_info.to_dart_includes()) |
| 785 | 785 |
| 786 # Generate C++ cast based on idl return type. | |
| 787 conversion_cast = return_type_info.conversion_cast('$FUNCTION_CALL') | |
| 788 if isinstance(return_type_info, SVGTearOffIDLTypeInfo): | |
| 789 svg_primitive_types = ['SVGAngle', 'SVGLength', 'SVGMatrix', | |
| 790 'SVGNumber', 'SVGPoint', 'SVGRect', 'SVGTransform'] | |
| 791 conversion_cast = '%s::create($FUNCTION_CALL)' | |
| 792 if self._interface.id.startswith('SVGAnimated'): | |
| 793 conversion_cast = 'static_cast<%s*>($FUNCTION_CALL)' | |
| 794 elif return_type_info.idl_type() == 'SVGStringList': | |
| 795 conversion_cast = '%s::create(receiver, $FUNCTION_CALL)' | |
| 796 elif self._interface.id.endswith('List'): | |
| 797 conversion_cast = 'static_cast<%s*>($FUNCTION_CALL.get())' | |
| 798 elif return_type_info.idl_type() in svg_primitive_types: | |
| 799 conversion_cast = '%s::create($FUNCTION_CALL)' | |
| 800 else: | |
| 801 conversion_cast = 'static_cast<%s*>($FUNCTION_CALL)' | |
| 802 conversion_cast = conversion_cast % return_type_info.native_type() | |
| 803 | |
| 804 # Generate to Dart conversion of C++ value. | 786 # Generate to Dart conversion of C++ value. |
| 805 conversion_arguments = [conversion_cast] | 787 to_dart_conversion = return_type_info.to_dart_conversion('$FUNCTION_CALL',
self._interface.id, attributes) |
| 806 if (return_type_info.idl_type() in ['DOMString', 'AtomicString'] and | |
| 807 'TreatReturnedNullStringAs' in attributes): | |
| 808 conversion_arguments.append('ConvertDefaultToNull') | |
| 809 | |
| 810 invocation_template = emitter.Format( | 788 invocation_template = emitter.Format( |
| 811 ' Dart_Handle returnValue = toDartValue($ARGUMENTS);\n' | 789 ' Dart_Handle returnValue = $TO_DART_CONVERSION;\n' |
| 812 ' if (returnValue)\n' | 790 ' if (returnValue)\n' |
| 813 ' Dart_SetReturnValue(args, returnValue);\n', | 791 ' Dart_SetReturnValue(args, returnValue);\n', |
| 814 ARGUMENTS=', '.join(conversion_arguments)) | 792 TO_DART_CONVERSION=to_dart_conversion) |
| 815 | 793 |
| 816 if raises_dom_exceptions: | 794 if raises_dom_exceptions: |
| 817 # Add 'ec' argument to WebCore invocation and convert DOM exception to Dar
t exception. | 795 # Add 'ec' argument to WebCore invocation and convert DOM exception to Dar
t exception. |
| 818 arguments.append('ec') | 796 arguments.append('ec') |
| 819 invocation_template = emitter.Format( | 797 invocation_template = emitter.Format( |
| 820 ' ExceptionCode ec = 0;\n' | 798 ' ExceptionCode ec = 0;\n' |
| 821 '$INVOCATION' | 799 '$INVOCATION' |
| 822 ' if (UNLIKELY(ec)) {\n' | 800 ' if (UNLIKELY(ec)) {\n' |
| 823 ' exception = DartDOMWrapper::exceptionCodeToDartException(
ec);\n' | 801 ' exception = DartDOMWrapper::exceptionCodeToDartException(
ec);\n' |
| 824 ' goto fail;\n' | 802 ' goto fail;\n' |
| (...skipping 18 matching lines...) Expand all Loading... |
| 843 def _InstanceOfNode(database, interface): | 821 def _InstanceOfNode(database, interface): |
| 844 if interface.id == 'Node': | 822 if interface.id == 'Node': |
| 845 return True | 823 return True |
| 846 for parent in interface.parents: | 824 for parent in interface.parents: |
| 847 if not database.HasInterface(parent.type.id): | 825 if not database.HasInterface(parent.type.id): |
| 848 continue | 826 continue |
| 849 parent_interface = database.GetInterface(parent.type.id) | 827 parent_interface = database.GetInterface(parent.type.id) |
| 850 if _InstanceOfNode(database, parent_interface): | 828 if _InstanceOfNode(database, parent_interface): |
| 851 return True | 829 return True |
| 852 return False | 830 return False |
| OLD | NEW |