Chromium Code Reviews| 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 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 344 WEBCORE_CLASS_NAME_ESCAPED= | 344 WEBCORE_CLASS_NAME_ESCAPED= |
| 345 self._interface_type_info.native_type().replace('<', '_').replace('>', ' _'), | 345 self._interface_type_info.native_type().replace('<', '_').replace('>', ' _'), |
| 346 DART_IMPLEMENTATION_CLASS=self._interface_type_info.implementation_name( ), | 346 DART_IMPLEMENTATION_CLASS=self._interface_type_info.implementation_name( ), |
| 347 DART_IMPLEMENTATION_LIBRARY='dart:%s' % self._renamer.GetLibraryName(sel f._interface)) | 347 DART_IMPLEMENTATION_LIBRARY='dart:%s' % self._renamer.GetLibraryName(sel f._interface)) |
| 348 | 348 |
| 349 def _GenerateCPPHeader(self): | 349 def _GenerateCPPHeader(self): |
| 350 to_native_emitter = emitter.Emitter() | 350 to_native_emitter = emitter.Emitter() |
| 351 if self._interface_type_info.custom_to_native(): | 351 if self._interface_type_info.custom_to_native(): |
| 352 return_type = 'PassRefPtr<NativeType>' | 352 return_type = 'PassRefPtr<NativeType>' |
| 353 to_native_body = ';' | 353 to_native_body = ';' |
| 354 to_native_arg_body = ';' | |
| 354 else: | 355 else: |
| 355 return_type = 'NativeType*' | 356 return_type = 'NativeType*' |
| 356 to_native_body = emitter.Format( | 357 to_native_body = emitter.Format( |
| 357 '\n' | 358 '\n' |
| 358 ' {\n' | 359 ' {\n' |
| 359 ' return DartDOMWrapper::unwrapDartWrapper<Dart$INTERFACE>(hand le, exception);\n' | 360 ' return DartDOMWrapper::unwrapDartWrapper<Dart$INTERFACE>(hand le, exception);\n' |
| 360 ' }', | 361 ' }', |
| 361 INTERFACE=self._interface.id) | 362 INTERFACE=self._interface.id) |
| 363 to_native_arg_body = emitter.Format( | |
| 364 '\n' | |
| 365 ' {\n' | |
| 366 ' return DartDOMWrapper::unwrapDartWrapper<Dart$INTERFACE>(args , index, exception);\n' | |
| 367 ' }', | |
| 368 INTERFACE=self._interface.id) | |
| 362 | 369 |
| 363 to_native_emitter.Emit( | 370 to_native_emitter.Emit( |
| 364 ' static $RETURN_TYPE toNative(Dart_Handle handle, Dart_Handle& excep tion)$TO_NATIVE_BODY\n' | 371 ' static $RETURN_TYPE toNative(Dart_Handle handle, Dart_Handle& excep tion)$TO_NATIVE_BODY\n' |
| 365 '\n' | 372 '\n' |
| 366 ' static $RETURN_TYPE toNativeWithNullCheck(Dart_Handle handle, Dart_ Handle& exception)\n' | 373 ' static $RETURN_TYPE toNativeWithNullCheck(Dart_Handle handle, Dart_ Handle& exception)\n' |
| 367 ' {\n' | 374 ' {\n' |
| 368 ' return Dart_IsNull(handle) ? 0 : toNative(handle, exception);\n ' | 375 ' return Dart_IsNull(handle) ? 0 : toNative(handle, exception);\n ' |
| 369 ' }\n', | 376 ' }\n' |
| 377 '\n' | |
| 378 ' static $RETURN_TYPE toNative(Dart_NativeArguments args, int index, Dart_Handle& exception)$TO_NATIVE_ARG_BODY\n' | |
| 379 '\n' | |
| 380 ' static $RETURN_TYPE toNativeWithNullCheck(Dart_NativeArguments args , int index, Dart_Handle& exception)$TO_NATIVE_ARG_BODY\n', | |
|
vsm
2013/08/12 20:42:07
Why do we have both of these with the same impleme
siva
2013/08/13 17:52:52
toNativeNullCheck wants to protect against Null be
| |
| 370 RETURN_TYPE=return_type, | 381 RETURN_TYPE=return_type, |
| 371 TO_NATIVE_BODY=to_native_body, | 382 TO_NATIVE_BODY=to_native_body, |
| 383 TO_NATIVE_ARG_BODY=to_native_arg_body, | |
| 372 INTERFACE=self._interface.id) | 384 INTERFACE=self._interface.id) |
| 373 | 385 |
| 374 to_dart_emitter = emitter.Emitter() | 386 to_dart_emitter = emitter.Emitter() |
| 375 | 387 |
| 376 ext_attrs = self._interface.ext_attrs | 388 ext_attrs = self._interface.ext_attrs |
| 377 | 389 |
| 378 if ('CustomToV8' in ext_attrs or | 390 if ('CustomToV8' in ext_attrs or |
| 379 'PureInterface' in ext_attrs or | 391 'PureInterface' in ext_attrs or |
| 380 'CPPPureInterface' in ext_attrs or | 392 'CPPPureInterface' in ext_attrs or |
| 381 self._interface_type_info.custom_to_dart()): | 393 self._interface_type_info.custom_to_dart()): |
| (...skipping 493 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 875 | 887 |
| 876 return False | 888 return False |
| 877 | 889 |
| 878 if AllowsNull(): | 890 if AllowsNull(): |
| 879 function += 'WithNullCheck' | 891 function += 'WithNullCheck' |
| 880 | 892 |
| 881 argument_name = DartDomNameOfAttribute(argument) | 893 argument_name = DartDomNameOfAttribute(argument) |
| 882 if type_info.pass_native_by_ref(): | 894 if type_info.pass_native_by_ref(): |
| 883 invocation_template =\ | 895 invocation_template =\ |
| 884 ' $TYPE $ARGUMENT_NAME;\n'\ | 896 ' $TYPE $ARGUMENT_NAME;\n'\ |
| 885 ' $CLS::$FUNCTION(Dart_GetNativeArgument(args, $INDEX), $ARGU MENT_NAME, exception);\n' | 897 ' $CLS::$FUNCTION(args, $INDEX, $ARGUMENT_NAME, exception);\n ' |
| 886 else: | 898 else: |
| 887 invocation_template =\ | 899 invocation_template =\ |
| 888 ' $TYPE $ARGUMENT_NAME = $CLS::$FUNCTION(Dart_GetNativeArgume nt(args, $INDEX), exception);\n' | 900 ' $TYPE $ARGUMENT_NAME = $CLS::$FUNCTION(args, $INDEX, except ion);\n' |
| 889 body_emitter.Emit( | 901 body_emitter.Emit( |
| 890 '\n' + | 902 '\n' + |
| 891 invocation_template + | 903 invocation_template + |
| 892 ' if (exception)\n' | 904 ' if (exception)\n' |
| 893 ' goto fail;\n', | 905 ' goto fail;\n', |
| 894 TYPE=type, | 906 TYPE=type, |
| 895 ARGUMENT_NAME=argument_name, | 907 ARGUMENT_NAME=argument_name, |
| 896 CLS=cls, | 908 CLS=cls, |
| 897 FUNCTION=function, | 909 FUNCTION=function, |
| 898 INDEX=start_index + i) | 910 INDEX=start_index + i) |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 948 else: | 960 else: |
| 949 value_expression = function_call | 961 value_expression = function_call |
| 950 | 962 |
| 951 # Generate to Dart conversion of C++ value. | 963 # Generate to Dart conversion of C++ value. |
| 952 if return_type_info.dart_type() == 'bool': | 964 if return_type_info.dart_type() == 'bool': |
| 953 set_return_value = 'Dart_SetBooleanReturnValue(args, %s)' % (value_expre ssion) | 965 set_return_value = 'Dart_SetBooleanReturnValue(args, %s)' % (value_expre ssion) |
| 954 elif return_type_info.dart_type() == 'int': | 966 elif return_type_info.dart_type() == 'int': |
| 955 set_return_value = 'Dart_SetIntegerReturnValue(args, %s)' % (value_expre ssion) | 967 set_return_value = 'Dart_SetIntegerReturnValue(args, %s)' % (value_expre ssion) |
| 956 elif return_type_info.dart_type() == 'double': | 968 elif return_type_info.dart_type() == 'double': |
| 957 set_return_value = 'Dart_SetDoubleReturnValue(args, %s)' % (value_expres sion) | 969 set_return_value = 'Dart_SetDoubleReturnValue(args, %s)' % (value_expres sion) |
| 970 elif return_type_info.dart_type() == 'string': | |
| 971 set_return_value = 'DartUtilities::setDartStringReturnValue(args, %s)' % (value_expression) | |
| 958 else: | 972 else: |
| 959 to_dart_conversion = return_type_info.to_dart_conversion(value_expressio n, self._interface.id, ext_attrs) | 973 to_dart_conversion = return_type_info.to_dart_conversion(value_expressio n, self._interface.id, ext_attrs) |
| 960 set_return_value = 'Dart_SetReturnValue(args, %s)' % (to_dart_conversion ) | 974 set_return_value = 'Dart_SetReturnValue(args, %s)' % (to_dart_conversion ) |
| 961 invocation_emitter.Emit( | 975 invocation_emitter.Emit( |
| 962 ' $RETURN_VALUE;\n', | 976 ' $RETURN_VALUE;\n', |
| 963 RETURN_VALUE=set_return_value) | 977 RETURN_VALUE=set_return_value) |
| 964 | 978 |
| 965 def _GenerateNativeBinding(self, idl_name, argument_count, dart_declaration, | 979 def _GenerateNativeBinding(self, idl_name, argument_count, dart_declaration, |
| 966 native_suffix, is_custom, emit_metadata=True): | 980 native_suffix, is_custom, emit_metadata=True): |
| 967 metadata = [] | 981 metadata = [] |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1095 ' if (Dart_NativeFunction func = $CLASS_NAME::resolver(name, argu mentCount))\n' | 1109 ' if (Dart_NativeFunction func = $CLASS_NAME::resolver(name, argu mentCount))\n' |
| 1096 ' return func;\n', | 1110 ' return func;\n', |
| 1097 CLASS_NAME=os.path.splitext(os.path.basename(path))[0]) | 1111 CLASS_NAME=os.path.splitext(os.path.basename(path))[0]) |
| 1098 | 1112 |
| 1099 def _IsOptionalStringArgumentInInitEventMethod(interface, operation, argument): | 1113 def _IsOptionalStringArgumentInInitEventMethod(interface, operation, argument): |
| 1100 return ( | 1114 return ( |
| 1101 interface.id.endswith('Event') and | 1115 interface.id.endswith('Event') and |
| 1102 operation.id.startswith('init') and | 1116 operation.id.startswith('init') and |
| 1103 argument.ext_attrs.get('Default') == 'Undefined' and | 1117 argument.ext_attrs.get('Default') == 'Undefined' and |
| 1104 argument.type.id == 'DOMString') | 1118 argument.type.id == 'DOMString') |
| OLD | NEW |