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

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
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 = DartDOMWrapper::lookupWrappe r(isNode, value);\n'
420 ' if (result)\n'
421 ' return Dart_HandleFromWeakPersistent(result);\n'
422 ' return createWrapper(value);\n'
423 ' }\n'
424 ' static void returnToDart(Dart_NativeArguments args, NativeType* val ue)\n'
425 ' {\n'
426 ' if (value) {\n'
427 ' Dart_WeakPersistentHandle result = DartDOMWrapper::lookupWr apper(isNode, value);\n'
428 ' if (result)\n'
429 ' Dart_SetWeakHandleReturnValue(args, result);\n'
430 ' else\n'
431 ' Dart_SetReturnValue(args, createWrapper(value));\n'
432 ' }\n'
433 ' }\n',
434 )
435
414 if ('CustomToV8' in ext_attrs or 436 if ('CustomToV8' in ext_attrs or
415 'PureInterface' in ext_attrs or 437 'PureInterface' in ext_attrs or
416 'CPPPureInterface' in ext_attrs or 438 'CPPPureInterface' in ext_attrs or
417 self._interface_type_info.custom_to_dart()): 439 self._interface_type_info.custom_to_dart()):
418 to_dart_emitter.Emit( 440 to_dart_emitter.Emit(
419 ' static Dart_Handle toDart(NativeType* value);\n') 441 ' static Dart_Handle createWrapper(NativeType* value);\n')
420 else: 442 else:
421 to_dart_emitter.Emit( 443 to_dart_emitter.Emit(
422 ' static Dart_Handle toDart(NativeType* value)\n' 444 ' static Dart_Handle createWrapper(NativeType* value)\n'
423 ' {\n' 445 ' {\n'
424 ' return DartDOMWrapper::toDart<Dart$(INTERFACE)>(value);\n' 446 ' return DartDOMWrapper::createWrapper<Dart$(INTERFACE)>(value) ;\n'
425 ' }\n', 447 ' }\n',
426 INTERFACE=self._interface.id) 448 INTERFACE=self._interface.id)
427 449
428 webcore_includes = self._GenerateCPPIncludes( 450 webcore_includes = self._GenerateCPPIncludes(
429 self._interface_type_info.webcore_includes()) 451 self._interface_type_info.webcore_includes())
430 452
431 is_node_test = lambda interface: interface.id == 'Node' 453 is_node_test = lambda interface: interface.id == 'Node'
432 is_active_test = lambda interface: 'ActiveDOMObject' in interface.ext_attrs 454 is_active_test = lambda interface: 'ActiveDOMObject' in interface.ext_attrs
433 is_event_target_test = lambda interface: 'EventTarget' in interface.ext_attr s 455 is_event_target_test = lambda interface: 'EventTarget' in interface.ext_attr s
456
434 def TypeCheckHelper(test): 457 def TypeCheckHelper(test):
435 return 'true' if any(map(test, self._database.Hierarchy(self._interface))) else 'false' 458 return 'true' if any(map(test, self._database.Hierarchy(self._interface))) else 'false'
436 459
437 self._cpp_header_emitter.Emit( 460 self._cpp_header_emitter.Emit(
438 self._template_loader.Load('cpp_header.template'), 461 self._template_loader.Load('cpp_header.template'),
439 INTERFACE=self._interface.id, 462 INTERFACE=self._interface.id,
440 WEBCORE_INCLUDES=webcore_includes, 463 WEBCORE_INCLUDES=webcore_includes,
441 WEBCORE_CLASS_NAME=self._interface_type_info.native_type(), 464 WEBCORE_CLASS_NAME=self._interface_type_info.native_type(),
442 WEBCORE_CLASS_NAME_ESCAPED= 465 WEBCORE_CLASS_NAME_ESCAPED=
443 self._interface_type_info.native_type().replace('<', '_').replace('>', ' _'), 466 self._interface_type_info.native_type().replace('<', '_').replace('>', ' _'),
(...skipping 554 matching lines...) Expand 10 before | Expand all | Expand 10 after
998 else: 1021 else:
999 assert (return_type_info.native_type() == 'int' or return_type_info.na tive_type() == 'long long') 1022 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) 1023 set_return_value = 'DartUtilities::setDartIntegerReturnValue(args, %s) ' % (value_expression)
1001 elif return_type_info.dart_type() == 'double': 1024 elif return_type_info.dart_type() == 'double':
1002 set_return_value = 'Dart_SetDoubleReturnValue(args, %s)' % (value_expres sion) 1025 set_return_value = 'Dart_SetDoubleReturnValue(args, %s)' % (value_expres sion)
1003 elif return_type_info.dart_type() == 'String': 1026 elif return_type_info.dart_type() == 'String':
1004 if ext_attrs and 'TreatReturnedNullStringAs' in ext_attrs: 1027 if ext_attrs and 'TreatReturnedNullStringAs' in ext_attrs:
1005 set_return_value = 'DartUtilities::setDartStringReturnValueWithNullChe ck(args, %s)' % (value_expression) 1028 set_return_value = 'DartUtilities::setDartStringReturnValueWithNullChe ck(args, %s)' % (value_expression)
1006 else: 1029 else:
1007 set_return_value = 'DartUtilities::setDartStringReturnValue(args, %s)' % (value_expression) 1030 set_return_value = 'DartUtilities::setDartStringReturnValue(args, %s)' % (value_expression)
1031 elif return_type_info.dart_type() == 'num' and return_type_info.native_typ e() == 'double':
1032 set_return_value = 'Dart_SetDoubleReturnValue(args, %s)' % (value_expres sion)
1008 else: 1033 else:
1009 to_dart_conversion = return_type_info.to_dart_conversion(value_expressio n, self._interface.id, ext_attrs) 1034 return_to_dart_conversion = return_type_info.return_to_dart_conversion(v alue_expression, self._interface.id, ext_attrs)
1010 set_return_value = 'Dart_SetReturnValue(args, %s)' % (to_dart_conversion ) 1035 set_return_value = '%s' % (return_to_dart_conversion)
1011 invocation_emitter.Emit( 1036 invocation_emitter.Emit(
1012 ' $RETURN_VALUE;\n', 1037 ' $RETURN_VALUE;\n',
1013 RETURN_VALUE=set_return_value) 1038 RETURN_VALUE=set_return_value)
1014 1039
1015 def _GenerateNativeBinding(self, idl_name, argument_count, dart_declaration, 1040 def _GenerateNativeBinding(self, idl_name, argument_count, dart_declaration,
1016 native_suffix, is_custom, emit_metadata=True): 1041 native_suffix, is_custom, emit_metadata=True):
1017 metadata = [] 1042 metadata = []
1018 if emit_metadata: 1043 if emit_metadata:
1019 metadata = self._metadata.GetFormattedMetadata( 1044 metadata = self._metadata.GetFormattedMetadata(
1020 self._renamer.GetLibraryName(self._interface), 1045 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' 1163 ' if (Dart_NativeFunction func = $CLASS_NAME::resolver(name, argu mentCount))\n'
1139 ' return func;\n', 1164 ' return func;\n',
1140 CLASS_NAME=os.path.splitext(os.path.basename(path))[0]) 1165 CLASS_NAME=os.path.splitext(os.path.basename(path))[0])
1141 1166
1142 def _IsOptionalStringArgumentInInitEventMethod(interface, operation, argument): 1167 def _IsOptionalStringArgumentInInitEventMethod(interface, operation, argument):
1143 return ( 1168 return (
1144 interface.id.endswith('Event') and 1169 interface.id.endswith('Event') and
1145 operation.id.startswith('init') and 1170 operation.id.startswith('init') and
1146 argument.ext_attrs.get('Default') == 'Undefined' and 1171 argument.ext_attrs.get('Default') == 'Undefined' and
1147 argument.type.id == 'DOMString') 1172 argument.type.id == 'DOMString')
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698