Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1524)

Side by Side Diff: tools/dom/scripts/systemnative.py

Issue 22694004: - Change access pattern to Native Arguments (make one call instead of two). (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | tools/dom/templates/html/dartium/cpp_callback_header.template » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 '
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)\n'
381 ' {\n'
382 ' // toNative accounts for Null objects also.\n'
383 ' return toNative(args, index, exception);\n'
369 ' }\n', 384 ' }\n',
370 RETURN_TYPE=return_type, 385 RETURN_TYPE=return_type,
371 TO_NATIVE_BODY=to_native_body, 386 TO_NATIVE_BODY=to_native_body,
387 TO_NATIVE_ARG_BODY=to_native_arg_body,
372 INTERFACE=self._interface.id) 388 INTERFACE=self._interface.id)
373 389
374 to_dart_emitter = emitter.Emitter() 390 to_dart_emitter = emitter.Emitter()
375 391
376 ext_attrs = self._interface.ext_attrs 392 ext_attrs = self._interface.ext_attrs
377 393
378 if ('CustomToV8' in ext_attrs or 394 if ('CustomToV8' in ext_attrs or
379 'PureInterface' in ext_attrs or 395 'PureInterface' in ext_attrs or
380 'CPPPureInterface' in ext_attrs or 396 'CPPPureInterface' in ext_attrs or
381 self._interface_type_info.custom_to_dart()): 397 self._interface_type_info.custom_to_dart()):
(...skipping 493 matching lines...) Expand 10 before | Expand all | Expand 10 after
875 891
876 return False 892 return False
877 893
878 if AllowsNull(): 894 if AllowsNull():
879 function += 'WithNullCheck' 895 function += 'WithNullCheck'
880 896
881 argument_name = DartDomNameOfAttribute(argument) 897 argument_name = DartDomNameOfAttribute(argument)
882 if type_info.pass_native_by_ref(): 898 if type_info.pass_native_by_ref():
883 invocation_template =\ 899 invocation_template =\
884 ' $TYPE $ARGUMENT_NAME;\n'\ 900 ' $TYPE $ARGUMENT_NAME;\n'\
885 ' $CLS::$FUNCTION(Dart_GetNativeArgument(args, $INDEX), $ARGU MENT_NAME, exception);\n' 901 ' $CLS::$FUNCTION(args, $INDEX, $ARGUMENT_NAME, exception);\n '
886 else: 902 else:
887 invocation_template =\ 903 invocation_template =\
888 ' $TYPE $ARGUMENT_NAME = $CLS::$FUNCTION(Dart_GetNativeArgume nt(args, $INDEX), exception);\n' 904 ' $TYPE $ARGUMENT_NAME = $CLS::$FUNCTION(args, $INDEX, except ion);\n'
889 body_emitter.Emit( 905 body_emitter.Emit(
890 '\n' + 906 '\n' +
891 invocation_template + 907 invocation_template +
892 ' if (exception)\n' 908 ' if (exception)\n'
893 ' goto fail;\n', 909 ' goto fail;\n',
894 TYPE=type, 910 TYPE=type,
895 ARGUMENT_NAME=argument_name, 911 ARGUMENT_NAME=argument_name,
896 CLS=cls, 912 CLS=cls,
897 FUNCTION=function, 913 FUNCTION=function,
898 INDEX=start_index + i) 914 INDEX=start_index + i)
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
948 else: 964 else:
949 value_expression = function_call 965 value_expression = function_call
950 966
951 # Generate to Dart conversion of C++ value. 967 # Generate to Dart conversion of C++ value.
952 if return_type_info.dart_type() == 'bool': 968 if return_type_info.dart_type() == 'bool':
953 set_return_value = 'Dart_SetBooleanReturnValue(args, %s)' % (value_expre ssion) 969 set_return_value = 'Dart_SetBooleanReturnValue(args, %s)' % (value_expre ssion)
954 elif return_type_info.dart_type() == 'int': 970 elif return_type_info.dart_type() == 'int':
955 set_return_value = 'Dart_SetIntegerReturnValue(args, %s)' % (value_expre ssion) 971 set_return_value = 'Dart_SetIntegerReturnValue(args, %s)' % (value_expre ssion)
956 elif return_type_info.dart_type() == 'double': 972 elif return_type_info.dart_type() == 'double':
957 set_return_value = 'Dart_SetDoubleReturnValue(args, %s)' % (value_expres sion) 973 set_return_value = 'Dart_SetDoubleReturnValue(args, %s)' % (value_expres sion)
974 elif return_type_info.dart_type() == 'String':
975 if ext_attrs and 'TreatReturnedNullStringAs' in ext_attrs:
976 set_return_value = 'DartUtilities::setDartStringReturnValueWithNullChe ck(args, %s)' % (value_expression)
977 else:
978 set_return_value = 'DartUtilities::setDartStringReturnValue(args, %s)' % (value_expression)
958 else: 979 else:
959 to_dart_conversion = return_type_info.to_dart_conversion(value_expressio n, self._interface.id, ext_attrs) 980 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 ) 981 set_return_value = 'Dart_SetReturnValue(args, %s)' % (to_dart_conversion )
961 invocation_emitter.Emit( 982 invocation_emitter.Emit(
962 ' $RETURN_VALUE;\n', 983 ' $RETURN_VALUE;\n',
963 RETURN_VALUE=set_return_value) 984 RETURN_VALUE=set_return_value)
964 985
965 def _GenerateNativeBinding(self, idl_name, argument_count, dart_declaration, 986 def _GenerateNativeBinding(self, idl_name, argument_count, dart_declaration,
966 native_suffix, is_custom, emit_metadata=True): 987 native_suffix, is_custom, emit_metadata=True):
967 metadata = [] 988 metadata = []
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
1095 ' if (Dart_NativeFunction func = $CLASS_NAME::resolver(name, argu mentCount))\n' 1116 ' if (Dart_NativeFunction func = $CLASS_NAME::resolver(name, argu mentCount))\n'
1096 ' return func;\n', 1117 ' return func;\n',
1097 CLASS_NAME=os.path.splitext(os.path.basename(path))[0]) 1118 CLASS_NAME=os.path.splitext(os.path.basename(path))[0])
1098 1119
1099 def _IsOptionalStringArgumentInInitEventMethod(interface, operation, argument): 1120 def _IsOptionalStringArgumentInInitEventMethod(interface, operation, argument):
1100 return ( 1121 return (
1101 interface.id.endswith('Event') and 1122 interface.id.endswith('Event') and
1102 operation.id.startswith('init') and 1123 operation.id.startswith('init') and
1103 argument.ext_attrs.get('Default') == 'Undefined' and 1124 argument.ext_attrs.get('Default') == 'Undefined' and
1104 argument.type.id == 'DOMString') 1125 argument.type.id == 'DOMString')
OLDNEW
« no previous file with comments | « no previous file | tools/dom/templates/html/dartium/cpp_callback_header.template » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698