| 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 473 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 484 | 484 |
| 485 def idl_type(self): | 485 def idl_type(self): |
| 486 return self._idl_type | 486 return self._idl_type |
| 487 | 487 |
| 488 def dart_type(self): | 488 def dart_type(self): |
| 489 return self._data.dart_type or self._idl_type | 489 return self._data.dart_type or self._idl_type |
| 490 | 490 |
| 491 def native_type(self): | 491 def native_type(self): |
| 492 return self._data.native_type or self._idl_type | 492 return self._data.native_type or self._idl_type |
| 493 | 493 |
| 494 def requires_v8_scope(self): |
| 495 return self._data.requires_v8_scope |
| 496 |
| 494 def emit_to_native(self, emitter, idl_node, name, handle, interface_name): | 497 def emit_to_native(self, emitter, idl_node, name, handle, interface_name): |
| 495 if 'Callback' in idl_node.ext_attrs: | 498 if 'Callback' in idl_node.ext_attrs: |
| 496 if set(['Optional', 'Callback']).issubset(idl_node.ext_attrs.keys()): | 499 if set(['Optional', 'Callback']).issubset(idl_node.ext_attrs.keys()): |
| 497 flag = 'DartUtilities::ConvertNullToDefaultValue' | 500 flag = 'DartUtilities::ConvertNullToDefaultValue' |
| 498 else: | 501 else: |
| 499 flag = 'DartUtilities::ConvertNone' | 502 flag = 'DartUtilities::ConvertNone' |
| 500 emitter.Emit( | 503 emitter.Emit( |
| 501 '\n' | 504 '\n' |
| 502 ' RefPtr<$TYPE> $NAME = Dart$IDL_TYPE::create($HANDLE, $FLAG, exc
eption);\n' | 505 ' RefPtr<$TYPE> $NAME = Dart$IDL_TYPE::create($HANDLE, $FLAG, exc
eption);\n' |
| 503 ' if (exception)\n' | 506 ' if (exception)\n' |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 579 def custom_to_dart(self): | 582 def custom_to_dart(self): |
| 580 return self._data.custom_to_dart | 583 return self._data.custom_to_dart |
| 581 | 584 |
| 582 | 585 |
| 583 class InterfaceIDLTypeInfo(IDLTypeInfo): | 586 class InterfaceIDLTypeInfo(IDLTypeInfo): |
| 584 def __init__(self, idl_type, data): | 587 def __init__(self, idl_type, data): |
| 585 super(InterfaceIDLTypeInfo, self).__init__(idl_type, data) | 588 super(InterfaceIDLTypeInfo, self).__init__(idl_type, data) |
| 586 | 589 |
| 587 | 590 |
| 588 class SequenceIDLTypeInfo(IDLTypeInfo): | 591 class SequenceIDLTypeInfo(IDLTypeInfo): |
| 589 def __init__(self, idl_type, item_info): | 592 def __init__(self, idl_type, data, item_info): |
| 590 super(SequenceIDLTypeInfo, self).__init__(idl_type, {}) | 593 super(SequenceIDLTypeInfo, self).__init__(idl_type, data) |
| 591 self._item_info = item_info | 594 self._item_info = item_info |
| 592 | 595 |
| 593 def dart_type(self): | 596 def dart_type(self): |
| 594 return 'List<%s>' % self._item_info.dart_type() | 597 return 'List<%s>' % self._item_info.dart_type() |
| 595 | 598 |
| 596 def to_dart_conversion(self, value, interface_name=None, attributes=None): | 599 def to_dart_conversion(self, value, interface_name=None, attributes=None): |
| 597 return 'DartDOMWrapper::vectorToDart<Dart%s>(%s)' % (self._item_info.native_
type(), value) | 600 return 'DartDOMWrapper::vectorToDart<Dart%s>(%s)' % (self._item_info.native_
type(), value) |
| 598 | 601 |
| 599 def conversion_includes(self): | 602 def conversion_includes(self): |
| 600 return self._item_info.conversion_includes() | 603 return self._item_info.conversion_includes() |
| 601 | 604 |
| 602 | 605 |
| 603 class DOMStringArrayTypeInfo(SequenceIDLTypeInfo): | 606 class DOMStringArrayTypeInfo(SequenceIDLTypeInfo): |
| 604 def __init__(self, item_info): | 607 def __init__(self, data, item_info): |
| 605 super(DOMStringArrayTypeInfo, self).__init__('DOMString[]', item_info) | 608 super(DOMStringArrayTypeInfo, self).__init__('DOMString[]', data, item_info) |
| 606 | 609 |
| 607 def emit_to_native(self, emitter, idl_node, name, handle, interface_name): | 610 def emit_to_native(self, emitter, idl_node, name, handle, interface_name): |
| 608 emitter.Emit( | 611 emitter.Emit( |
| 609 '\n' | 612 '\n' |
| 610 ' RefPtr<DOMStringList> $NAME = DartDOMStringList::toNative($HAND
LE, exception);\n' | 613 ' RefPtr<DOMStringList> $NAME = DartDOMStringList::toNative($HAND
LE, exception);\n' |
| 611 ' if (exception)\n' | 614 ' if (exception)\n' |
| 612 ' goto fail;\n', | 615 ' goto fail;\n', |
| 613 NAME=name, | 616 NAME=name, |
| 614 HANDLE=handle) | 617 HANDLE=handle) |
| 615 return name | 618 return name |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 705 conversion_cast = 'static_cast<%s*>(%s)' | 708 conversion_cast = 'static_cast<%s*>(%s)' |
| 706 conversion_cast = conversion_cast % (self.native_type(), value) | 709 conversion_cast = conversion_cast % (self.native_type(), value) |
| 707 return 'Dart%s::toDart(%s)' % (self._idl_type, conversion_cast) | 710 return 'Dart%s::toDart(%s)' % (self._idl_type, conversion_cast) |
| 708 | 711 |
| 709 | 712 |
| 710 class TypeData(object): | 713 class TypeData(object): |
| 711 def __init__(self, clazz, dart_type=None, native_type=None, | 714 def __init__(self, clazz, dart_type=None, native_type=None, |
| 712 custom_to_dart=None, custom_to_native=None, | 715 custom_to_dart=None, custom_to_native=None, |
| 713 conversion_includes=None, | 716 conversion_includes=None, |
| 714 webcore_getter_name='getAttribute', | 717 webcore_getter_name='getAttribute', |
| 715 webcore_setter_name='setAttribute'): | 718 webcore_setter_name='setAttribute', |
| 719 requires_v8_scope=False): |
| 716 self.clazz = clazz | 720 self.clazz = clazz |
| 717 self.dart_type = dart_type | 721 self.dart_type = dart_type |
| 718 self.native_type = native_type | 722 self.native_type = native_type |
| 719 self.custom_to_dart = custom_to_dart | 723 self.custom_to_dart = custom_to_dart |
| 720 self.custom_to_native = custom_to_native | 724 self.custom_to_native = custom_to_native |
| 721 self.conversion_includes = conversion_includes | 725 self.conversion_includes = conversion_includes |
| 722 self.webcore_getter_name = webcore_getter_name | 726 self.webcore_getter_name = webcore_getter_name |
| 723 self.webcore_setter_name = webcore_setter_name | 727 self.webcore_setter_name = webcore_setter_name |
| 728 self.requires_v8_scope = requires_v8_scope |
| 724 | 729 |
| 725 | 730 |
| 726 _idl_type_registry = { | 731 _idl_type_registry = { |
| 727 'boolean': TypeData(clazz='Primitive', dart_type='bool', native_type='bool', | 732 'boolean': TypeData(clazz='Primitive', dart_type='bool', native_type='bool', |
| 728 webcore_getter_name='hasAttribute', | 733 webcore_getter_name='hasAttribute', |
| 729 webcore_setter_name='setBooleanAttribute'), | 734 webcore_setter_name='setBooleanAttribute'), |
| 730 'byte': TypeData(clazz='Primitive', dart_type='int', native_type='int'), | 735 'byte': TypeData(clazz='Primitive', dart_type='int', native_type='int'), |
| 731 'octet': TypeData(clazz='Primitive', dart_type='int', native_type='int'), | 736 'octet': TypeData(clazz='Primitive', dart_type='int', native_type='int'), |
| 732 'short': TypeData(clazz='Primitive', dart_type='int', native_type='int'), | 737 'short': TypeData(clazz='Primitive', dart_type='int', native_type='int'), |
| 733 'unsigned short': TypeData(clazz='Primitive', dart_type='int', | 738 'unsigned short': TypeData(clazz='Primitive', dart_type='int', |
| (...skipping 14 matching lines...) Expand all Loading... |
| 748 'double': TypeData(clazz='Primitive', dart_type='num'), | 753 'double': TypeData(clazz='Primitive', dart_type='num'), |
| 749 | 754 |
| 750 'any': TypeData(clazz='Primitive', dart_type='Object'), | 755 'any': TypeData(clazz='Primitive', dart_type='Object'), |
| 751 'Array': TypeData(clazz='Primitive', dart_type='List'), | 756 'Array': TypeData(clazz='Primitive', dart_type='List'), |
| 752 'custom': TypeData(clazz='Primitive', dart_type='Dynamic'), | 757 'custom': TypeData(clazz='Primitive', dart_type='Dynamic'), |
| 753 'Date': TypeData(clazz='Primitive', dart_type='Date', native_type='double'), | 758 'Date': TypeData(clazz='Primitive', dart_type='Date', native_type='double'), |
| 754 'DOMObject': TypeData(clazz='Primitive', dart_type='Object', native_type='Sc
riptValue'), | 759 'DOMObject': TypeData(clazz='Primitive', dart_type='Object', native_type='Sc
riptValue'), |
| 755 'DOMString': TypeData(clazz='Primitive', dart_type='String', native_type='St
ring'), | 760 'DOMString': TypeData(clazz='Primitive', dart_type='String', native_type='St
ring'), |
| 756 # TODO(vsm): This won't actually work until we convert the Map to | 761 # TODO(vsm): This won't actually work until we convert the Map to |
| 757 # a native JS Map for JS DOM. | 762 # a native JS Map for JS DOM. |
| 758 'Dictionary': TypeData(clazz='Primitive', dart_type='Map'), | 763 'Dictionary': TypeData(clazz='Primitive', dart_type='Map', requires_v8_scope
=True), |
| 759 # TODO(sra): Flags is really a dictionary: {create:bool, exclusive:bool} | 764 # TODO(sra): Flags is really a dictionary: {create:bool, exclusive:bool} |
| 760 # http://dev.w3.org/2009/dap/file-system/file-dir-sys.html#the-flags-interfa
ce | 765 # http://dev.w3.org/2009/dap/file-system/file-dir-sys.html#the-flags-interfa
ce |
| 761 'Flags': TypeData(clazz='Primitive', dart_type='Object'), | 766 'Flags': TypeData(clazz='Primitive', dart_type='Object'), |
| 762 'DOMTimeStamp': TypeData(clazz='Primitive', dart_type='int', native_type='un
signed long long'), | 767 'DOMTimeStamp': TypeData(clazz='Primitive', dart_type='int', native_type='un
signed long long'), |
| 763 'object': TypeData(clazz='Primitive', dart_type='Object', native_type='Scrip
tValue'), | 768 'object': TypeData(clazz='Primitive', dart_type='Object', native_type='Scrip
tValue'), |
| 764 'PositionOptions': TypeData(clazz='Primitive', dart_type='Object'), | 769 'PositionOptions': TypeData(clazz='Primitive', dart_type='Object'), |
| 765 # TODO(sra): Come up with some meaningful name so that where this appears in | 770 # TODO(sra): Come up with some meaningful name so that where this appears in |
| 766 # the documentation, the user is made aware that only a limited subset of | 771 # the documentation, the user is made aware that only a limited subset of |
| 767 # serializable types are actually permitted. | 772 # serializable types are actually permitted. |
| 768 'SerializedScriptValue': TypeData(clazz='Primitive', dart_type='Dynamic'), | 773 'SerializedScriptValue': TypeData(clazz='Primitive', dart_type='Dynamic'), |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 833 if self._renamer: | 838 if self._renamer: |
| 834 return self._renamer.RenameInterface(interface) | 839 return self._renamer.RenameInterface(interface) |
| 835 else: | 840 else: |
| 836 return interface.id | 841 return interface.id |
| 837 return dart_type | 842 return dart_type |
| 838 | 843 |
| 839 def _TypeInfo(self, type_name): | 844 def _TypeInfo(self, type_name): |
| 840 match = re.match(r'(?:sequence<(\w+)>|(\w+)\[\])$', type_name) | 845 match = re.match(r'(?:sequence<(\w+)>|(\w+)\[\])$', type_name) |
| 841 if match: | 846 if match: |
| 842 if type_name == 'DOMString[]': | 847 if type_name == 'DOMString[]': |
| 843 return DOMStringArrayTypeInfo(self.TypeInfo('DOMString')) | 848 return DOMStringArrayTypeInfo(TypeData('Sequence'), self.TypeInfo('DOMSt
ring')) |
| 844 return SequenceIDLTypeInfo(type_name, self.TypeInfo(match.group(1) or matc
h.group(2))) | 849 item_info = self.TypeInfo(match.group(1) or match.group(2)) |
| 850 return SequenceIDLTypeInfo(type_name, TypeData('Sequence'), item_info) |
| 845 if not type_name in _idl_type_registry: | 851 if not type_name in _idl_type_registry: |
| 846 return InterfaceIDLTypeInfo(type_name, TypeData('Interface')) | 852 return InterfaceIDLTypeInfo(type_name, TypeData('Interface')) |
| 847 type_data = _idl_type_registry.get(type_name) | 853 type_data = _idl_type_registry.get(type_name) |
| 848 class_name = '%sIDLTypeInfo' % type_data.clazz | 854 class_name = '%sIDLTypeInfo' % type_data.clazz |
| 849 return globals()[class_name](type_name, type_data) | 855 return globals()[class_name](type_name, type_data) |
| OLD | NEW |