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 |
11 from generator import * | 11 from generator import * |
12 from systemhtml import SecureOutputType | |
13 from htmldartgenerator import * | 12 from htmldartgenerator import * |
14 | 13 |
15 class DartiumBackend(HtmlDartGenerator): | 14 class DartiumBackend(HtmlDartGenerator): |
16 """Generates Dart implementation for one DOM IDL interface.""" | 15 """Generates Dart implementation for one DOM IDL interface.""" |
17 | 16 |
18 def __init__(self, interface, cpp_library_emitter, options): | 17 def __init__(self, interface, cpp_library_emitter, options): |
19 super(DartiumBackend, self).__init__(interface, options) | 18 super(DartiumBackend, self).__init__(interface, options) |
20 | 19 |
21 self._interface = interface | 20 self._interface = interface |
22 self._cpp_library_emitter = cpp_library_emitter | 21 self._cpp_library_emitter = cpp_library_emitter |
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
280 INTERFACE=self._interface.id, | 279 INTERFACE=self._interface.id, |
281 WEBCORE_INCLUDES=webcore_includes, | 280 WEBCORE_INCLUDES=webcore_includes, |
282 WEBCORE_CLASS_NAME=self._interface_type_info.native_type(), | 281 WEBCORE_CLASS_NAME=self._interface_type_info.native_type(), |
283 DECLARATIONS=self._cpp_declarations_emitter.Fragments(), | 282 DECLARATIONS=self._cpp_declarations_emitter.Fragments(), |
284 IS_NODE=TypeCheckHelper(is_node_test), | 283 IS_NODE=TypeCheckHelper(is_node_test), |
285 IS_ACTIVE=TypeCheckHelper(is_active_test), | 284 IS_ACTIVE=TypeCheckHelper(is_active_test), |
286 IS_EVENT_TARGET=TypeCheckHelper(is_event_target_test), | 285 IS_EVENT_TARGET=TypeCheckHelper(is_event_target_test), |
287 TO_NATIVE=to_native_emitter.Fragments(), | 286 TO_NATIVE=to_native_emitter.Fragments(), |
288 TO_DART=to_dart_emitter.Fragments()) | 287 TO_DART=to_dart_emitter.Fragments()) |
289 | 288 |
290 def AddAttribute(self, attribute, html_name, read_only): | 289 def EmitAttribute(self, attribute, html_name, read_only): |
291 self._AddGetter(attribute, html_name) | 290 self._AddGetter(attribute, html_name) |
292 if not read_only: | 291 if not read_only: |
293 self._AddSetter(attribute, html_name) | 292 self._AddSetter(attribute, html_name) |
294 | 293 |
295 def _AddGetter(self, attr, html_name): | 294 def _AddGetter(self, attr, html_name): |
296 type_info = self._TypeInfo(attr.type.id) | 295 type_info = self._TypeInfo(attr.type.id) |
297 dart_declaration = '%s get %s' % (SecureOutputType(self, attr.type.id), html _name) | 296 dart_declaration = '%s get %s' % (self.SecureOutputType(attr.type.id), html_ name) |
vsm
2012/11/07 22:31:28
length
blois
2012/11/08 00:08:34
Done.
| |
298 is_custom = 'Custom' in attr.ext_attrs or 'CustomGetter' in attr.ext_attrs | 297 is_custom = 'Custom' in attr.ext_attrs or 'CustomGetter' in attr.ext_attrs |
299 cpp_callback_name = self._GenerateNativeBinding(attr.id, 1, | 298 cpp_callback_name = self._GenerateNativeBinding(attr.id, 1, |
300 dart_declaration, 'Getter', is_custom) | 299 dart_declaration, 'Getter', is_custom) |
301 if is_custom: | 300 if is_custom: |
302 return | 301 return |
303 | 302 |
304 if 'Reflect' in attr.ext_attrs: | 303 if 'Reflect' in attr.ext_attrs: |
305 webcore_function_name = self._TypeInfo(attr.type.id).webcore_getter_name() | 304 webcore_function_name = self._TypeInfo(attr.type.id).webcore_getter_name() |
306 if 'URL' in attr.ext_attrs: | 305 if 'URL' in attr.ext_attrs: |
307 if 'NonEmpty' in attr.ext_attrs: | 306 if 'NonEmpty' in attr.ext_attrs: |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
378 # | 377 # |
379 # class YImpl extends ListBase<T> { copies of transitive XImpl methods; } | 378 # class YImpl extends ListBase<T> { copies of transitive XImpl methods; } |
380 # | 379 # |
381 dart_element_type = self._DartType(element_type) | 380 dart_element_type = self._DartType(element_type) |
382 if self._HasNativeIndexGetter(): | 381 if self._HasNativeIndexGetter(): |
383 self._EmitNativeIndexGetter(dart_element_type) | 382 self._EmitNativeIndexGetter(dart_element_type) |
384 else: | 383 else: |
385 self._members_emitter.Emit( | 384 self._members_emitter.Emit( |
386 '\n' | 385 '\n' |
387 ' $TYPE operator[](int index) native "$(INTERFACE)_item_Callback";\n' , | 386 ' $TYPE operator[](int index) native "$(INTERFACE)_item_Callback";\n' , |
388 TYPE=SecureOutputType(self, element_type), INTERFACE=self._interface.i d) | 387 TYPE=self.SecureOutputType(element_type), INTERFACE=self._interface.id ) |
vsm
2012/11/07 22:31:28
length
blois
2012/11/08 00:08:34
Done.
| |
389 | 388 |
390 if self._HasNativeIndexSetter(): | 389 if self._HasNativeIndexSetter(): |
391 self._EmitNativeIndexSetter(dart_element_type) | 390 self._EmitNativeIndexSetter(dart_element_type) |
392 else: | 391 else: |
393 # The HTML library implementation of NodeList has a custom indexed setter | 392 # The HTML library implementation of NodeList has a custom indexed setter |
394 # implementation that uses the parent node the NodeList is associated | 393 # implementation that uses the parent node the NodeList is associated |
395 # with if one is available. | 394 # with if one is available. |
396 if self._interface.id != 'NodeList': | 395 if self._interface.id != 'NodeList': |
397 self._members_emitter.Emit( | 396 self._members_emitter.Emit( |
398 '\n' | 397 '\n' |
(...skipping 29 matching lines...) Expand all Loading... | |
428 self._EmitNativeIndexGetter(dart_element_type) | 427 self._EmitNativeIndexGetter(dart_element_type) |
429 if self._HasNativeIndexSetter(): | 428 if self._HasNativeIndexSetter(): |
430 self._EmitNativeIndexSetter(dart_element_type) | 429 self._EmitNativeIndexSetter(dart_element_type) |
431 | 430 |
432 def _HasNativeIndexGetter(self): | 431 def _HasNativeIndexGetter(self): |
433 ext_attrs = self._interface.ext_attrs | 432 ext_attrs = self._interface.ext_attrs |
434 return ('CustomIndexedGetter' in ext_attrs or | 433 return ('CustomIndexedGetter' in ext_attrs or |
435 'NumericIndexedGetter' in ext_attrs) | 434 'NumericIndexedGetter' in ext_attrs) |
436 | 435 |
437 def _EmitNativeIndexGetter(self, element_type): | 436 def _EmitNativeIndexGetter(self, element_type): |
438 dart_declaration = '%s operator[](int index)' % SecureOutputType(self, eleme nt_type, True) | 437 dart_declaration = '%s operator[](int index)' % self.SecureOutputType(elemen t_type, True) |
vsm
2012/11/07 22:31:28
length
blois
2012/11/08 00:08:34
Done.
| |
439 self._GenerateNativeBinding('numericIndexGetter', 2, dart_declaration, | 438 self._GenerateNativeBinding('numericIndexGetter', 2, dart_declaration, |
440 'Callback', True) | 439 'Callback', True) |
441 | 440 |
442 def _HasNativeIndexSetter(self): | 441 def _HasNativeIndexSetter(self): |
443 return 'CustomIndexedSetter' in self._interface.ext_attrs | 442 return 'CustomIndexedSetter' in self._interface.ext_attrs |
444 | 443 |
445 def _EmitNativeIndexSetter(self, element_type): | 444 def _EmitNativeIndexSetter(self, element_type): |
446 dart_declaration = 'void operator[]=(int index, %s value)' % element_type | 445 dart_declaration = 'void operator[]=(int index, %s value)' % element_type |
447 self._GenerateNativeBinding('numericIndexSetter', 3, dart_declaration, | 446 self._GenerateNativeBinding('numericIndexSetter', 3, dart_declaration, |
448 'Callback', True) | 447 'Callback', True) |
449 | 448 |
450 def AddOperation(self, info, html_name): | 449 def EmitOperation(self, info, html_name): |
451 """ | 450 """ |
452 Arguments: | 451 Arguments: |
453 info: An OperationInfo object. | 452 info: An OperationInfo object. |
454 """ | 453 """ |
455 | 454 |
456 operation = info.operations[0] | 455 operation = info.operations[0] |
457 | 456 |
458 is_custom = 'Custom' in operation.ext_attrs | 457 is_custom = 'Custom' in operation.ext_attrs |
459 has_optional_arguments = any(self._IsArgumentOptionalInWebCore(operation, ar gument) for argument in operation.arguments) | 458 has_optional_arguments = any(self._IsArgumentOptionalInWebCore(operation, ar gument) for argument in operation.arguments) |
460 needs_dispatcher = not is_custom and (len(info.operations) > 1 or has_option al_arguments) | 459 needs_dispatcher = not is_custom and (len(info.operations) > 1 or has_option al_arguments) |
461 | 460 |
462 dart_declaration = '%s%s %s(%s)' % ( | 461 dart_declaration = '%s%s %s(%s)' % ( |
463 'static ' if info.IsStatic() else '', | 462 'static ' if info.IsStatic() else '', |
464 SecureOutputType(self, info.type_name), | 463 self.SecureOutputType(info.type_name), |
465 html_name, | 464 html_name, |
466 info.ParametersDeclaration( | 465 info.ParametersDeclaration( |
467 (lambda x: 'dynamic') if needs_dispatcher else self._DartType)) | 466 (lambda x: 'dynamic') if needs_dispatcher else self._DartType)) |
468 | 467 |
469 if not needs_dispatcher: | 468 if not needs_dispatcher: |
470 # Bind directly to native implementation | 469 # Bind directly to native implementation |
471 argument_count = (0 if info.IsStatic() else 1) + len(info.param_infos) | 470 argument_count = (0 if info.IsStatic() else 1) + len(info.param_infos) |
472 cpp_callback_name = self._GenerateNativeBinding( | 471 cpp_callback_name = self._GenerateNativeBinding( |
473 info.name, argument_count, dart_declaration, 'Callback', is_custom) | 472 info.name, argument_count, dart_declaration, 'Callback', is_custom) |
474 if not is_custom: | 473 if not is_custom: |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
506 template = ' $CALL;\n' | 505 template = ' $CALL;\n' |
507 | 506 |
508 overload_name = '%s_%s' % (operation.id, version[0]) | 507 overload_name = '%s_%s' % (operation.id, version[0]) |
509 version[0] += 1 | 508 version[0] += 1 |
510 argument_list = ', '.join(argument_names[:argument_count]) | 509 argument_list = ', '.join(argument_names[:argument_count]) |
511 call = '_%s(%s)' % (overload_name, argument_list) | 510 call = '_%s(%s)' % (overload_name, argument_list) |
512 body.Emit(template, CHECKS=' && '.join(checks), CALL=call) | 511 body.Emit(template, CHECKS=' && '.join(checks), CALL=call) |
513 | 512 |
514 dart_declaration = '%s%s _%s(%s)' % ( | 513 dart_declaration = '%s%s _%s(%s)' % ( |
515 'static ' if operation.is_static else '', | 514 'static ' if operation.is_static else '', |
516 SecureOutputType(self, operation.type.id), overload_name, argument_lis t) | 515 self.SecureOutputType(operation.type.id), overload_name, argument_list ) |
vsm
2012/11/07 22:31:28
length
blois
2012/11/08 00:08:34
Done.
| |
517 cpp_callback_name = self._GenerateNativeBinding( | 516 cpp_callback_name = self._GenerateNativeBinding( |
518 overload_name, (0 if operation.is_static else 1) + argument_count, | 517 overload_name, (0 if operation.is_static else 1) + argument_count, |
519 dart_declaration, 'Callback', False) | 518 dart_declaration, 'Callback', False) |
520 self._GenerateOperationNativeCallback(operation, operation.arguments[:argu ment_count], cpp_callback_name) | 519 self._GenerateOperationNativeCallback(operation, operation.arguments[:argu ment_count], cpp_callback_name) |
521 | 520 |
522 def GenerateChecksAndCall(operation, argument_count): | 521 def GenerateChecksAndCall(operation, argument_count): |
523 checks = [] | 522 checks = [] |
524 for i in range(0, argument_count): | 523 for i in range(0, argument_count): |
525 argument = operation.arguments[i] | 524 argument = operation.arguments[i] |
526 argument_name = argument_names[i] | 525 argument_name = argument_names[i] |
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
885 def EmitResolver(self, template, output_dir): | 884 def EmitResolver(self, template, output_dir): |
886 file_path = os.path.join(output_dir, 'DartResolver.cpp') | 885 file_path = os.path.join(output_dir, 'DartResolver.cpp') |
887 includes_emitter, body_emitter = self._emitters.FileEmitter(file_path).Emit( template) | 886 includes_emitter, body_emitter = self._emitters.FileEmitter(file_path).Emit( template) |
888 for header_file in self._headers_list: | 887 for header_file in self._headers_list: |
889 path = os.path.relpath(header_file, output_dir) | 888 path = os.path.relpath(header_file, output_dir) |
890 includes_emitter.Emit('#include "$PATH"\n', PATH=path) | 889 includes_emitter.Emit('#include "$PATH"\n', PATH=path) |
891 body_emitter.Emit( | 890 body_emitter.Emit( |
892 ' if (Dart_NativeFunction func = $CLASS_NAME::resolver(name, argume ntCount))\n' | 891 ' if (Dart_NativeFunction func = $CLASS_NAME::resolver(name, argume ntCount))\n' |
893 ' return func;\n', | 892 ' return func;\n', |
894 CLASS_NAME=os.path.splitext(os.path.basename(path))[0]) | 893 CLASS_NAME=os.path.splitext(os.path.basename(path))[0]) |
OLD | NEW |