| 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 779 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 790 '\n' | 790 '\n' |
| 791 ' Dart_Handle customArgument = Dart_GetNativeArgument(args, $IN
DEX);\n' | 791 ' Dart_Handle customArgument = Dart_GetNativeArgument(args, $IN
DEX);\n' |
| 792 ' RefPtr<ScriptArguments> scriptArguments(DartUtilities::create
ScriptArguments(customArgument, exception));\n' | 792 ' RefPtr<ScriptArguments> scriptArguments(DartUtilities::create
ScriptArguments(customArgument, exception));\n' |
| 793 ' if (!scriptArguments)\n' | 793 ' if (!scriptArguments)\n' |
| 794 ' goto fail;\n' | 794 ' goto fail;\n' |
| 795 ' RefPtr<ScriptCallStack> scriptCallStack(DartUtilities::create
ScriptCallStack());\n' | 795 ' RefPtr<ScriptCallStack> scriptCallStack(DartUtilities::create
ScriptCallStack());\n' |
| 796 ' if (!scriptCallStack->size())\n' | 796 ' if (!scriptCallStack->size())\n' |
| 797 ' return;\n', | 797 ' return;\n', |
| 798 INDEX=len(arguments) + 1) | 798 INDEX=len(arguments) + 1) |
| 799 | 799 |
| 800 # Process Dart cpp_arguments. | 800 # Emit arguments. |
| 801 start_index = 1 if needs_receiver else 0 | 801 start_index = 1 if needs_receiver else 0 |
| 802 for i, argument in enumerate(arguments): | 802 for i, argument in enumerate(arguments): |
| 803 argument_expression = self._GenerateToNative(body_emitter, argument, start
_index + i) | 803 type_info = self._TypeInfo(argument.type.id) |
| 804 cpp_arguments.append(argument_expression) | 804 self._cpp_impl_includes |= set(type_info.to_native_includes()) |
| 805 cpp_arguments.append(type_info.emit_to_native( |
| 806 body_emitter, |
| 807 argument, |
| 808 # TODO(antonm): all IDs should be renamed when database is generated. |
| 809 # That will allow to get rid of argument_name argument altogether. |
| 810 DartDomNameOfAttribute(argument), |
| 811 'Dart_GetNativeArgument(args, %i)' % (start_index + i), |
| 812 self._interface.id)) |
| 805 | 813 |
| 806 body_emitter.Emit('\n') | 814 body_emitter.Emit('\n') |
| 807 | 815 |
| 808 # FIXME: rework in IDLs. | 816 # FIXME: rework in IDLs. |
| 809 if node.id in ['addEventListener', 'removeEventListener']: | 817 if node.id in ['addEventListener', 'removeEventListener']: |
| 810 # addEventListener's and removeEventListener's last argument is marked | 818 # addEventListener's and removeEventListener's last argument is marked |
| 811 # as optional in idl, but is not optional in webcore implementation. | 819 # as optional in idl, but is not optional in webcore implementation. |
| 812 if len(arguments) == 2: | 820 if len(arguments) == 2: |
| 813 cpp_arguments.append('false') | 821 cpp_arguments.append('false') |
| 814 | 822 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 842 self._cpp_impl_includes |= set(return_type_info.conversion_includes()) | 850 self._cpp_impl_includes |= set(return_type_info.conversion_includes()) |
| 843 | 851 |
| 844 # Generate to Dart conversion of C++ value. | 852 # Generate to Dart conversion of C++ value. |
| 845 to_dart_conversion = return_type_info.to_dart_conversion(function_call, se
lf._interface.id, ext_attrs) | 853 to_dart_conversion = return_type_info.to_dart_conversion(function_call, se
lf._interface.id, ext_attrs) |
| 846 invocation_emitter.Emit( | 854 invocation_emitter.Emit( |
| 847 ' Dart_Handle returnValue = $TO_DART_CONVERSION;\n' | 855 ' Dart_Handle returnValue = $TO_DART_CONVERSION;\n' |
| 848 ' if (returnValue)\n' | 856 ' if (returnValue)\n' |
| 849 ' Dart_SetReturnValue(args, returnValue);\n', | 857 ' Dart_SetReturnValue(args, returnValue);\n', |
| 850 TO_DART_CONVERSION=to_dart_conversion) | 858 TO_DART_CONVERSION=to_dart_conversion) |
| 851 | 859 |
| 852 def _GenerateToNative(self, emitter, idl_node, index): | |
| 853 """idl_node is IDLArgument or IDLAttribute.""" | |
| 854 type_info = self._TypeInfo(idl_node.type.id) | |
| 855 self._cpp_impl_includes |= set(type_info.to_native_includes()) | |
| 856 argument_name = idl_node.id | |
| 857 # Rename to get rid of conflicts with C++ keywords. | |
| 858 if argument_name == 'default': | |
| 859 argument_name = 'value' | |
| 860 handle = 'Dart_GetNativeArgument(args, %i)' % index | |
| 861 argument_expression = type_info.emit_to_native( | |
| 862 emitter, idl_node, argument_name, handle, self._interface.id) | |
| 863 return argument_expression | |
| 864 | |
| 865 def _GenerateNativeBinding(self, idl_name, argument_count, dart_declaration, | 860 def _GenerateNativeBinding(self, idl_name, argument_count, dart_declaration, |
| 866 native_suffix, is_custom): | 861 native_suffix, is_custom): |
| 867 native_binding = '%s_%s_%s' % (self._interface.id, idl_name, native_suffix) | 862 native_binding = '%s_%s_%s' % (self._interface.id, idl_name, native_suffix) |
| 868 self._members_emitter.Emit( | 863 self._members_emitter.Emit( |
| 869 '\n' | 864 '\n' |
| 870 ' $DART_DECLARATION native "$NATIVE_BINDING";\n', | 865 ' $DART_DECLARATION native "$NATIVE_BINDING";\n', |
| 871 DART_DECLARATION=dart_declaration, NATIVE_BINDING=native_binding) | 866 DART_DECLARATION=dart_declaration, NATIVE_BINDING=native_binding) |
| 872 | 867 |
| 873 cpp_callback_name = '%s%s' % (idl_name, native_suffix) | 868 cpp_callback_name = '%s%s' % (idl_name, native_suffix) |
| 874 self._cpp_resolver_emitter.Emit( | 869 self._cpp_resolver_emitter.Emit( |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 927 | 922 |
| 928 def _IsArgumentOptionalInWebCore(argument): | 923 def _IsArgumentOptionalInWebCore(argument): |
| 929 return IsOptional(argument) and not 'Callback' in argument.ext_attrs | 924 return IsOptional(argument) and not 'Callback' in argument.ext_attrs |
| 930 | 925 |
| 931 def _ToWebKitName(name): | 926 def _ToWebKitName(name): |
| 932 name = name[0].lower() + name[1:] | 927 name = name[0].lower() + name[1:] |
| 933 name = re.sub(r'^(hTML|uRL|jS|xML|xSLT)', lambda s: s.group(1).lower(), | 928 name = re.sub(r'^(hTML|uRL|jS|xML|xSLT)', lambda s: s.group(1).lower(), |
| 934 name) | 929 name) |
| 935 return re.sub(r'^(create|exclusive)', lambda s: 'is' + s.group(1).capitalize()
, | 930 return re.sub(r'^(create|exclusive)', lambda s: 'is' + s.group(1).capitalize()
, |
| 936 name) | 931 name) |
| OLD | NEW |