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

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

Issue 23681014: - Modify toDart to first do a simple lookup in the appropriate table before going down the templati… (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 3 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 | « tools/dom/scripts/generator.py ('k') | tools/dom/templates/html/dartium/cpp_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 393 matching lines...) Expand 10 before | Expand all | Expand 10 after
404 ' }\n', 404 ' }\n',
405 RETURN_TYPE=return_type, 405 RETURN_TYPE=return_type,
406 TO_NATIVE_BODY=to_native_body, 406 TO_NATIVE_BODY=to_native_body,
407 TO_NATIVE_ARG_BODY=to_native_arg_body, 407 TO_NATIVE_ARG_BODY=to_native_arg_body,
408 INTERFACE=self._interface.id) 408 INTERFACE=self._interface.id)
409 409
410 to_dart_emitter = emitter.Emitter() 410 to_dart_emitter = emitter.Emitter()
411 411
412 ext_attrs = self._interface.ext_attrs 412 ext_attrs = self._interface.ext_attrs
413 413
414 to_dart_emitter.Emit(
415 ' static Dart_Handle toDart(NativeType* value)\n'
416 ' {\n'
417 ' if (!value)\n'
418 ' return Dart_Null();\n'
419 ' Dart_WeakPersistentHandle result = '
420 ' DartDOMWrapper::lookupWrapper(isNode, value);\n'
421 ' if (result)\n'
422 ' return Dart_HandleFromWeakPersistent(result);\n'
423 ' return createWrapper(value);\n'
424 ' }\n'
425 ' static void returnToDart(Dart_NativeArguments args,'
426 ' NativeType* value)\n'
427 ' {\n'
428 ' if (value) {\n'
429 ' Dart_WeakPersistentHandle result = '
430 ' DartDOMWrapper::lookupWrapper(isNode, value);\n'
431 ' if (result)\n'
432 ' Dart_SetWeakHandleReturnValue(args, result);\n'
433 ' else\n'
434 ' Dart_SetReturnValue(args, createWrapper(value));\n'
435 ' }\n'
436 ' }\n',
437 )
438
414 if ('CustomToV8' in ext_attrs or 439 if ('CustomToV8' in ext_attrs or
415 'PureInterface' in ext_attrs or 440 'PureInterface' in ext_attrs or
416 'CPPPureInterface' in ext_attrs or 441 'CPPPureInterface' in ext_attrs or
417 self._interface_type_info.custom_to_dart()): 442 self._interface_type_info.custom_to_dart()):
418 to_dart_emitter.Emit( 443 to_dart_emitter.Emit(
419 ' static Dart_Handle toDart(NativeType* value);\n') 444 ' static Dart_Handle createWrapper(NativeType* value);\n')
420 else: 445 else:
421 to_dart_emitter.Emit( 446 to_dart_emitter.Emit(
422 ' static Dart_Handle toDart(NativeType* value)\n' 447 ' static Dart_Handle createWrapper(NativeType* value)\n'
423 ' {\n' 448 ' {\n'
424 ' return DartDOMWrapper::toDart<Dart$(INTERFACE)>(value);\n' 449 ' return DartDOMWrapper::createWrapper<Dart$(INTERFACE)>(value) ;\n'
425 ' }\n', 450 ' }\n',
426 INTERFACE=self._interface.id) 451 INTERFACE=self._interface.id)
427 452
428 webcore_includes = self._GenerateCPPIncludes( 453 webcore_includes = self._GenerateCPPIncludes(
429 self._interface_type_info.webcore_includes()) 454 self._interface_type_info.webcore_includes())
430 455
431 is_node_test = lambda interface: interface.id == 'Node' 456 is_node_test = lambda interface: interface.id == 'Node'
432 is_active_test = lambda interface: 'ActiveDOMObject' in interface.ext_attrs 457 is_active_test = lambda interface: 'ActiveDOMObject' in interface.ext_attrs
433 is_event_target_test = lambda interface: 'EventTarget' in interface.ext_attr s 458 is_event_target_test = lambda interface: 'EventTarget' in interface.ext_attr s
434 def TypeCheckHelper(test): 459 def TypeCheckHelper(test):
(...skipping 563 matching lines...) Expand 10 before | Expand all | Expand 10 after
998 else: 1023 else:
999 assert (return_type_info.native_type() == 'int' or return_type_info.na tive_type() == 'long long') 1024 assert (return_type_info.native_type() == 'int' or return_type_info.na tive_type() == 'long long')
1000 set_return_value = 'DartUtilities::setDartIntegerReturnValue(args, %s) ' % (value_expression) 1025 set_return_value = 'DartUtilities::setDartIntegerReturnValue(args, %s) ' % (value_expression)
1001 elif return_type_info.dart_type() == 'double': 1026 elif return_type_info.dart_type() == 'double':
1002 set_return_value = 'Dart_SetDoubleReturnValue(args, %s)' % (value_expres sion) 1027 set_return_value = 'Dart_SetDoubleReturnValue(args, %s)' % (value_expres sion)
1003 elif return_type_info.dart_type() == 'String': 1028 elif return_type_info.dart_type() == 'String':
1004 if ext_attrs and 'TreatReturnedNullStringAs' in ext_attrs: 1029 if ext_attrs and 'TreatReturnedNullStringAs' in ext_attrs:
1005 set_return_value = 'DartUtilities::setDartStringReturnValueWithNullChe ck(args, %s)' % (value_expression) 1030 set_return_value = 'DartUtilities::setDartStringReturnValueWithNullChe ck(args, %s)' % (value_expression)
1006 else: 1031 else:
1007 set_return_value = 'DartUtilities::setDartStringReturnValue(args, %s)' % (value_expression) 1032 set_return_value = 'DartUtilities::setDartStringReturnValue(args, %s)' % (value_expression)
1033 elif return_type_info.dart_type() == 'num' and return_type_info.native_typ e() == 'double':
1034 set_return_value = 'Dart_SetDoubleReturnValue(args, %s)' % (value_expres sion)
1008 else: 1035 else:
1009 to_dart_conversion = return_type_info.to_dart_conversion(value_expressio n, self._interface.id, ext_attrs) 1036 return_to_dart_conversion = return_type_info.return_to_dart_conversion(
1010 set_return_value = 'Dart_SetReturnValue(args, %s)' % (to_dart_conversion ) 1037 value_expression,
1038 self._interface.id,
1039 ext_attrs)
1040 set_return_value = '%s' % (return_to_dart_conversion)
1011 invocation_emitter.Emit( 1041 invocation_emitter.Emit(
1012 ' $RETURN_VALUE;\n', 1042 ' $RETURN_VALUE;\n',
1013 RETURN_VALUE=set_return_value) 1043 RETURN_VALUE=set_return_value)
1014 1044
1015 def _GenerateNativeBinding(self, idl_name, argument_count, dart_declaration, 1045 def _GenerateNativeBinding(self, idl_name, argument_count, dart_declaration,
1016 native_suffix, is_custom, emit_metadata=True): 1046 native_suffix, is_custom, emit_metadata=True):
1017 metadata = [] 1047 metadata = []
1018 if emit_metadata: 1048 if emit_metadata:
1019 metadata = self._metadata.GetFormattedMetadata( 1049 metadata = self._metadata.GetFormattedMetadata(
1020 self._renamer.GetLibraryName(self._interface), 1050 self._renamer.GetLibraryName(self._interface),
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
1138 ' if (Dart_NativeFunction func = $CLASS_NAME::resolver(name, argu mentCount))\n' 1168 ' if (Dart_NativeFunction func = $CLASS_NAME::resolver(name, argu mentCount))\n'
1139 ' return func;\n', 1169 ' return func;\n',
1140 CLASS_NAME=os.path.splitext(os.path.basename(path))[0]) 1170 CLASS_NAME=os.path.splitext(os.path.basename(path))[0])
1141 1171
1142 def _IsOptionalStringArgumentInInitEventMethod(interface, operation, argument): 1172 def _IsOptionalStringArgumentInInitEventMethod(interface, operation, argument):
1143 return ( 1173 return (
1144 interface.id.endswith('Event') and 1174 interface.id.endswith('Event') and
1145 operation.id.startswith('init') and 1175 operation.id.startswith('init') and
1146 argument.ext_attrs.get('Default') == 'Undefined' and 1176 argument.ext_attrs.get('Default') == 'Undefined' and
1147 argument.type.id == 'DOMString') 1177 argument.type.id == 'DOMString')
OLDNEW
« no previous file with comments | « tools/dom/scripts/generator.py ('k') | tools/dom/templates/html/dartium/cpp_header.template » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698