| 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 systems to generate | 6 """This module provides shared functionality for systems to generate |
| 7 Dart APIs from the IDL database.""" | 7 Dart APIs from the IDL database.""" |
| 8 | 8 |
| 9 import copy | 9 import copy |
| 10 import re | 10 import re |
| (...skipping 515 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 526 | 526 |
| 527 def dart_type(self): | 527 def dart_type(self): |
| 528 return self._data.dart_type or self._idl_type | 528 return self._data.dart_type or self._idl_type |
| 529 | 529 |
| 530 def native_type(self): | 530 def native_type(self): |
| 531 return self._data.native_type or self._idl_type | 531 return self._data.native_type or self._idl_type |
| 532 | 532 |
| 533 def requires_v8_scope(self): | 533 def requires_v8_scope(self): |
| 534 return self._data.requires_v8_scope | 534 return self._data.requires_v8_scope |
| 535 | 535 |
| 536 def to_native_info(self, idl_node, accept_null, name, interface_name): | 536 def to_native_info(self, idl_node, interface_name): |
| 537 cls = 'Dart%s' % self.idl_type() | 537 cls = 'Dart%s' % self.idl_type() |
| 538 | 538 |
| 539 if 'Callback' in idl_node.ext_attrs: | 539 if 'Callback' in idl_node.ext_attrs: |
| 540 function_name = 'create' | 540 return '%s', 'RefPtr<%s>' % self.native_type(), cls, 'create' |
| 541 if accept_null: | |
| 542 function_name += 'WithNullCheck' | |
| 543 return name, 'RefPtr<%s>' % self.native_type(), cls, function_name | |
| 544 | 541 |
| 545 if self.custom_to_native(): | 542 if self.custom_to_native(): |
| 546 type = 'RefPtr<%s>' % self.native_type() | 543 type = 'RefPtr<%s>' % self.native_type() |
| 547 argument = '%s.get()' % name | 544 argument_expression_template = '%s.get()' |
| 548 else: | 545 else: |
| 549 type = '%s*' % self.native_type() | 546 type = '%s*' % self.native_type() |
| 550 if isinstance(self, SVGTearOffIDLTypeInfo) and not interface_name.endswith
('List'): | 547 if isinstance(self, SVGTearOffIDLTypeInfo) and not interface_name.endswith
('List'): |
| 551 argument = '%s->propertyReference()' % name | 548 argument_expression_template = '%s->propertyReference()' |
| 552 else: | 549 else: |
| 553 argument = name | 550 argument_expression_template = '%s' |
| 554 return argument, type, cls, 'toNative' | 551 return argument_expression_template, type, cls, 'toNative' |
| 555 | 552 |
| 556 def custom_to_native(self): | 553 def custom_to_native(self): |
| 557 return self._data.custom_to_native | 554 return self._data.custom_to_native |
| 558 | 555 |
| 559 def parameter_type(self): | 556 def parameter_type(self): |
| 560 return '%s*' % self.native_type() | 557 return '%s*' % self.native_type() |
| 561 | 558 |
| 562 def webcore_includes(self): | 559 def webcore_includes(self): |
| 563 WTF_INCLUDES = [ | 560 WTF_INCLUDES = [ |
| 564 'ArrayBuffer', | 561 'ArrayBuffer', |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 619 return 'DartDOMWrapper::vectorToDart<Dart%s>(%s)' % (self._item_info.native_
type(), value) | 616 return 'DartDOMWrapper::vectorToDart<Dart%s>(%s)' % (self._item_info.native_
type(), value) |
| 620 | 617 |
| 621 def conversion_includes(self): | 618 def conversion_includes(self): |
| 622 return self._item_info.conversion_includes() | 619 return self._item_info.conversion_includes() |
| 623 | 620 |
| 624 | 621 |
| 625 class DOMStringArrayTypeInfo(SequenceIDLTypeInfo): | 622 class DOMStringArrayTypeInfo(SequenceIDLTypeInfo): |
| 626 def __init__(self, data, item_info): | 623 def __init__(self, data, item_info): |
| 627 super(DOMStringArrayTypeInfo, self).__init__('DOMString[]', data, item_info) | 624 super(DOMStringArrayTypeInfo, self).__init__('DOMString[]', data, item_info) |
| 628 | 625 |
| 629 def to_native_info(self, idl_node, accept_null, name, interface_name): | 626 def to_native_info(self, idl_node, interface_name): |
| 630 assert not accept_null | 627 return '%s', 'RefPtr<DOMStringList>', 'DartDOMStringList', 'toNative' |
| 631 return name, 'RefPtr<DOMStringList>', 'DartDOMStringList', 'toNative' | |
| 632 | 628 |
| 633 | 629 |
| 634 class PrimitiveIDLTypeInfo(IDLTypeInfo): | 630 class PrimitiveIDLTypeInfo(IDLTypeInfo): |
| 635 def __init__(self, idl_type, data): | 631 def __init__(self, idl_type, data): |
| 636 super(PrimitiveIDLTypeInfo, self).__init__(idl_type, data) | 632 super(PrimitiveIDLTypeInfo, self).__init__(idl_type, data) |
| 637 | 633 |
| 638 def to_native_info(self, idl_node, accept_null, name, interface_name): | 634 def to_native_info(self, idl_node, interface_name): |
| 639 function_name = 'dartTo%s' % self._capitalized_native_type() | |
| 640 if accept_null: | |
| 641 function_name += 'WithNullCheck' | |
| 642 type = self.native_type() | 635 type = self.native_type() |
| 643 if type == 'SerializedScriptValue': | 636 if type == 'SerializedScriptValue': |
| 644 type = 'RefPtr<%s>' % type | 637 type = 'RefPtr<%s>' % type |
| 645 if type == 'String': | 638 if type == 'String': |
| 646 type = 'DartStringAdapter' | 639 type = 'DartStringAdapter' |
| 647 return name, type, 'DartUtilities', function_name | 640 return '%s', type, 'DartUtilities', 'dartTo%s' % self._capitalized_native_ty
pe() |
| 648 | 641 |
| 649 def parameter_type(self): | 642 def parameter_type(self): |
| 650 if self.native_type() == 'String': | 643 if self.native_type() == 'String': |
| 651 return 'const String&' | 644 return 'const String&' |
| 652 return self.native_type() | 645 return self.native_type() |
| 653 | 646 |
| 654 def conversion_includes(self): | 647 def conversion_includes(self): |
| 655 return [] | 648 return [] |
| 656 | 649 |
| 657 def to_dart_conversion(self, value, interface_name=None, attributes=None): | 650 def to_dart_conversion(self, value, interface_name=None, attributes=None): |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 847 if match: | 840 if match: |
| 848 if type_name == 'DOMString[]': | 841 if type_name == 'DOMString[]': |
| 849 return DOMStringArrayTypeInfo(TypeData('Sequence'), self.TypeInfo('DOMSt
ring')) | 842 return DOMStringArrayTypeInfo(TypeData('Sequence'), self.TypeInfo('DOMSt
ring')) |
| 850 item_info = self.TypeInfo(match.group(1) or match.group(2)) | 843 item_info = self.TypeInfo(match.group(1) or match.group(2)) |
| 851 return SequenceIDLTypeInfo(type_name, TypeData('Sequence'), item_info) | 844 return SequenceIDLTypeInfo(type_name, TypeData('Sequence'), item_info) |
| 852 if not type_name in _idl_type_registry: | 845 if not type_name in _idl_type_registry: |
| 853 return InterfaceIDLTypeInfo(type_name, TypeData('Interface')) | 846 return InterfaceIDLTypeInfo(type_name, TypeData('Interface')) |
| 854 type_data = _idl_type_registry.get(type_name) | 847 type_data = _idl_type_registry.get(type_name) |
| 855 class_name = '%sIDLTypeInfo' % type_data.clazz | 848 class_name = '%sIDLTypeInfo' % type_data.clazz |
| 856 return globals()[class_name](type_name, type_data) | 849 return globals()[class_name](type_name, type_data) |
| OLD | NEW |