| 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 re | 9 import re |
| 10 import string |
| 10 | 11 |
| 11 _pure_interfaces = set([ | 12 _pure_interfaces = set([ |
| 12 'DOMStringList', | 13 'DOMStringList', |
| 13 'DOMStringMap', | 14 'DOMStringMap', |
| 14 'ElementTimeControl', | 15 'ElementTimeControl', |
| 15 'ElementTraversal', | 16 'ElementTraversal', |
| 16 'MediaQueryListListener', | 17 'MediaQueryListListener', |
| 17 'NodeSelector', | 18 'NodeSelector', |
| 18 'SVGExternalResourcesRequired', | 19 'SVGExternalResourcesRequired', |
| 19 'SVGFilterPrimitiveStandardAttributes', | 20 'SVGFilterPrimitiveStandardAttributes', |
| (...skipping 466 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 486 else: | 487 else: |
| 487 include = self._idl_type | 488 include = self._idl_type |
| 488 return ['"%s.h"' % include] + _svg_supplemental_includes | 489 return ['"%s.h"' % include] + _svg_supplemental_includes |
| 489 | 490 |
| 490 def receiver(self): | 491 def receiver(self): |
| 491 return 'receiver->' | 492 return 'receiver->' |
| 492 | 493 |
| 493 def conversion_includes(self): | 494 def conversion_includes(self): |
| 494 return ['"Dart%s.h"' % include for include in self._conversion_includes] | 495 return ['"Dart%s.h"' % include for include in self._conversion_includes] |
| 495 | 496 |
| 496 def to_dart_conversion(self, value, interface_name, attributes): | 497 def to_dart_conversion(self, value, interface_name=None, attributes=None): |
| 497 return 'toDartValue(%s)' % value | 498 return 'toDartValue(%s)' % value |
| 498 | 499 |
| 499 def custom_to_dart(self): | 500 def custom_to_dart(self): |
| 500 return self._custom_to_dart | 501 return self._custom_to_dart |
| 501 | 502 |
| 502 | 503 |
| 503 class SequenceIDLTypeInfo(IDLTypeInfo): | 504 class SequenceIDLTypeInfo(IDLTypeInfo): |
| 504 def __init__(self, idl_type, item_info): | 505 def __init__(self, idl_type, item_info): |
| 505 super(SequenceIDLTypeInfo, self).__init__(idl_type) | 506 super(SequenceIDLTypeInfo, self).__init__(idl_type) |
| 506 self._item_info = item_info | 507 self._item_info = item_info |
| 507 | 508 |
| 508 def dart_type(self): | 509 def dart_type(self): |
| 509 return 'List<%s>' % self._item_info.dart_type() | 510 return 'List<%s>' % self._item_info.dart_type() |
| 510 | 511 |
| 511 def conversion_includes(self): | 512 def conversion_includes(self): |
| 512 return self._item_info.conversion_includes() | 513 return self._item_info.conversion_includes() |
| 513 | 514 |
| 514 | 515 |
| 515 class PrimitiveIDLTypeInfo(IDLTypeInfo): | 516 class PrimitiveIDLTypeInfo(IDLTypeInfo): |
| 516 def __init__(self, idl_type, dart_type, native_type=None, ref_counted=False, | 517 def __init__(self, idl_type, dart_type, native_type=None, ref_counted=False, |
| 517 needs_static_cast=False, | |
| 518 webcore_getter_name='getAttribute', | 518 webcore_getter_name='getAttribute', |
| 519 webcore_setter_name='setAttribute'): | 519 webcore_setter_name='setAttribute'): |
| 520 super(PrimitiveIDLTypeInfo, self).__init__(idl_type, dart_type=dart_type, | 520 super(PrimitiveIDLTypeInfo, self).__init__(idl_type, dart_type=dart_type, |
| 521 native_type=native_type, ref_counted=ref_counted) | 521 native_type=native_type, ref_counted=ref_counted) |
| 522 self._needs_static_cast = needs_static_cast | |
| 523 self._webcore_getter_name = webcore_getter_name | 522 self._webcore_getter_name = webcore_getter_name |
| 524 self._webcore_setter_name = webcore_setter_name | 523 self._webcore_setter_name = webcore_setter_name |
| 525 | 524 |
| 526 def parameter_adapter_info(self): | 525 def parameter_adapter_info(self): |
| 527 native_type = self.native_type() | 526 native_type = self.native_type() |
| 528 if self._ref_counted: | 527 if self._ref_counted: |
| 529 native_type = 'RefPtr< %s >' % native_type | 528 native_type = 'RefPtr< %s >' % native_type |
| 530 return ('ParameterAdapter< %s >' % native_type, None) | 529 return ('ParameterAdapter< %s >' % native_type, None) |
| 531 | 530 |
| 532 def parameter_type(self): | 531 def parameter_type(self): |
| 533 if self.native_type() == 'String': | 532 if self.native_type() == 'String': |
| 534 return 'const String&' | 533 return 'const String&' |
| 535 return self.native_type() | 534 return self.native_type() |
| 536 | 535 |
| 537 def conversion_includes(self): | 536 def conversion_includes(self): |
| 538 return [] | 537 return [] |
| 539 | 538 |
| 540 def to_dart_conversion(self, value, interface_name, attributes): | 539 def to_dart_conversion(self, value, interface_name=None, attributes=None): |
| 541 if self._needs_static_cast: | |
| 542 value = 'static_cast<%s>(%s)' % (self.native_type(), value) | |
| 543 conversion_arguments = [value] | 540 conversion_arguments = [value] |
| 544 if 'TreatReturnedNullStringAs' in attributes: | 541 if attributes and 'TreatReturnedNullStringAs' in attributes: |
| 545 conversion_arguments.append('ConvertDefaultToNull') | 542 conversion_arguments.append('DartUtilities::ConvertNullToDefaultValue') |
| 546 return 'toDartValue(%s)' % ', '.join(conversion_arguments) | 543 function_name = 'toDartValue' |
| 544 # FIXME: implement DartUtilities::toDart for other primitive types and |
| 545 # remove this list. |
| 546 if self.native_type() in ['String', 'bool', 'int', 'unsigned', 'long long',
'unsigned long long', 'double']: |
| 547 function_name = string.capwords(self.native_type()).replace(' ', '') |
| 548 function_name = function_name[0].lower() + function_name[1:] |
| 549 function_name = 'DartUtilities::%sToDart' % function_name |
| 550 return '%s(%s)' % (function_name, ', '.join(conversion_arguments)) |
| 547 | 551 |
| 548 def webcore_getter_name(self): | 552 def webcore_getter_name(self): |
| 549 return self._webcore_getter_name | 553 return self._webcore_getter_name |
| 550 | 554 |
| 551 def webcore_setter_name(self): | 555 def webcore_setter_name(self): |
| 552 return self._webcore_setter_name | 556 return self._webcore_setter_name |
| 553 | 557 |
| 554 class SVGTearOffIDLTypeInfo(IDLTypeInfo): | 558 class SVGTearOffIDLTypeInfo(IDLTypeInfo): |
| 555 def __init__(self, idl_type, native_type='', ref_counted=True): | 559 def __init__(self, idl_type, native_type='', ref_counted=True): |
| 556 super(SVGTearOffIDLTypeInfo, self).__init__(idl_type, | 560 super(SVGTearOffIDLTypeInfo, self).__init__(idl_type, |
| (...skipping 24 matching lines...) Expand all Loading... |
| 581 elif interface_name.endswith('List'): | 585 elif interface_name.endswith('List'): |
| 582 conversion_cast = 'static_cast<%s*>(%s.get())' | 586 conversion_cast = 'static_cast<%s*>(%s.get())' |
| 583 elif self.idl_type() in svg_primitive_types: | 587 elif self.idl_type() in svg_primitive_types: |
| 584 conversion_cast = '%s::create(%s)' | 588 conversion_cast = '%s::create(%s)' |
| 585 else: | 589 else: |
| 586 conversion_cast = 'static_cast<%s*>(%s)' | 590 conversion_cast = 'static_cast<%s*>(%s)' |
| 587 conversion_cast = conversion_cast % (self.native_type(), value) | 591 conversion_cast = conversion_cast % (self.native_type(), value) |
| 588 return 'toDartValue(%s)' % conversion_cast | 592 return 'toDartValue(%s)' % conversion_cast |
| 589 | 593 |
| 590 _idl_type_registry = { | 594 _idl_type_registry = { |
| 591 # There is GC3Dboolean which is not a bool, but unsigned char for OpenGL com
patibility. | |
| 592 'boolean': PrimitiveIDLTypeInfo('boolean', dart_type='bool', native_type='bo
ol', | 595 'boolean': PrimitiveIDLTypeInfo('boolean', dart_type='bool', native_type='bo
ol', |
| 593 needs_static_cast=True, | |
| 594 webcore_getter_name='hasAttribute', | 596 webcore_getter_name='hasAttribute', |
| 595 webcore_setter_name='setBooleanAttribute'), | 597 webcore_setter_name='setBooleanAttribute'), |
| 596 # Some IDL's unsigned shorts/shorts are mapped to WebCore C++ enums, so we | 598 'short': PrimitiveIDLTypeInfo('short', dart_type='int', native_type='int'), |
| 597 # use a static_cast<int> here not to provide overloads for all enums. | |
| 598 'short': PrimitiveIDLTypeInfo('short', dart_type='int', native_type='int', | |
| 599 needs_static_cast=True), | |
| 600 'unsigned short': PrimitiveIDLTypeInfo('unsigned short', dart_type='int', | 599 'unsigned short': PrimitiveIDLTypeInfo('unsigned short', dart_type='int', |
| 601 native_type='int', needs_static_cast=True,), | 600 native_type='int'), |
| 602 'int': PrimitiveIDLTypeInfo('int', dart_type='int'), | 601 'int': PrimitiveIDLTypeInfo('int', dart_type='int'), |
| 603 'unsigned int': PrimitiveIDLTypeInfo('unsigned int', dart_type='int', | 602 'unsigned int': PrimitiveIDLTypeInfo('unsigned int', dart_type='int', |
| 604 native_type='unsigned'), | 603 native_type='unsigned'), |
| 605 'long': PrimitiveIDLTypeInfo('long', dart_type='int', native_type='int', | 604 'long': PrimitiveIDLTypeInfo('long', dart_type='int', native_type='int', |
| 606 webcore_getter_name='getIntegralAttribute', | 605 webcore_getter_name='getIntegralAttribute', |
| 607 webcore_setter_name='setIntegralAttribute'), | 606 webcore_setter_name='setIntegralAttribute'), |
| 608 'unsigned long': PrimitiveIDLTypeInfo('unsigned long', dart_type='int', | 607 'unsigned long': PrimitiveIDLTypeInfo('unsigned long', dart_type='int', |
| 609 native_type='unsigned', | 608 native_type='unsigned', |
| 610 webcore_getter_name='getUnsignedIntegralAttribute', | 609 webcore_getter_name='getUnsignedIntegralAttribute', |
| 611 webcore_setter_name='setUnsignedIntegralAttribute'), | 610 webcore_setter_name='setUnsignedIntegralAttribute'), |
| 612 'long long': PrimitiveIDLTypeInfo('long long', dart_type='int'), | 611 'long long': PrimitiveIDLTypeInfo('long long', dart_type='int'), |
| 613 'unsigned long long': PrimitiveIDLTypeInfo('unsigned long long', dart_type='
int'), | 612 'unsigned long long': PrimitiveIDLTypeInfo('unsigned long long', dart_type='
int'), |
| 614 'float': PrimitiveIDLTypeInfo('float', dart_type='num', native_type='double'
), | 613 'float': PrimitiveIDLTypeInfo('float', dart_type='num', native_type='double'
), |
| 615 'double': PrimitiveIDLTypeInfo('double', dart_type='num'), | 614 'double': PrimitiveIDLTypeInfo('double', dart_type='num'), |
| 616 | 615 |
| 617 'any': PrimitiveIDLTypeInfo('any', dart_type='Object'), | 616 'any': PrimitiveIDLTypeInfo('any', dart_type='Object'), |
| 618 'any[]': PrimitiveIDLTypeInfo('any[]', dart_type='List'), | 617 'any[]': PrimitiveIDLTypeInfo('any[]', dart_type='List'), |
| 619 'Array': PrimitiveIDLTypeInfo('Array', dart_type='List'), | 618 'Array': PrimitiveIDLTypeInfo('Array', dart_type='List'), |
| 620 'custom': PrimitiveIDLTypeInfo('custom', dart_type='Dynamic'), | 619 'custom': PrimitiveIDLTypeInfo('custom', dart_type='Dynamic'), |
| 621 'Date': PrimitiveIDLTypeInfo('Date', dart_type='Date', native_type='double')
, | 620 'Date': PrimitiveIDLTypeInfo('Date', dart_type='Date', native_type='double')
, |
| 622 'DOMObject': PrimitiveIDLTypeInfo('DOMObject', dart_type='Object', native_ty
pe='ScriptValue'), | 621 'DOMObject': PrimitiveIDLTypeInfo('DOMObject', dart_type='Object', native_ty
pe='ScriptValue'), |
| 623 'DOMString': PrimitiveIDLTypeInfo('DOMString', dart_type='String', native_ty
pe='String'), | 622 'DOMString': PrimitiveIDLTypeInfo('DOMString', dart_type='String', native_ty
pe='String'), |
| 624 # TODO(sra): Flags is really a dictionary: {create:bool, exclusive:bool} | 623 # TODO(sra): Flags is really a dictionary: {create:bool, exclusive:bool} |
| 625 # http://dev.w3.org/2009/dap/file-system/file-dir-sys.html#the-flags-interfa
ce | 624 # http://dev.w3.org/2009/dap/file-system/file-dir-sys.html#the-flags-interfa
ce |
| 626 'Flags': PrimitiveIDLTypeInfo('Flags', dart_type='Object'), | 625 'Flags': PrimitiveIDLTypeInfo('Flags', dart_type='Object'), |
| 627 'DOMTimeStamp': PrimitiveIDLTypeInfo('DOMTimeStamp', dart_type='int'), | 626 'DOMTimeStamp': PrimitiveIDLTypeInfo('DOMTimeStamp', dart_type='int', native
_type='unsigned long long'), |
| 628 'object': PrimitiveIDLTypeInfo('object', dart_type='Object', native_type='Sc
riptValue'), | 627 'object': PrimitiveIDLTypeInfo('object', dart_type='Object', native_type='Sc
riptValue'), |
| 629 # TODO(sra): Come up with some meaningful name so that where this appears in | 628 # TODO(sra): Come up with some meaningful name so that where this appears in |
| 630 # the documentation, the user is made aware that only a limited subset of | 629 # the documentation, the user is made aware that only a limited subset of |
| 631 # serializable types are actually permitted. | 630 # serializable types are actually permitted. |
| 632 'SerializedScriptValue': PrimitiveIDLTypeInfo('SerializedScriptValue', dart_
type='Dynamic', ref_counted=True), | 631 'SerializedScriptValue': PrimitiveIDLTypeInfo('SerializedScriptValue', dart_
type='Dynamic', ref_counted=True), |
| 633 # TODO(sra): Flags is really a dictionary: {create:bool, exclusive:bool} | 632 # TODO(sra): Flags is really a dictionary: {create:bool, exclusive:bool} |
| 634 # http://dev.w3.org/2009/dap/file-system/file-dir-sys.html#the-flags-interfa
ce | 633 # http://dev.w3.org/2009/dap/file-system/file-dir-sys.html#the-flags-interfa
ce |
| 635 'WebKitFlags': PrimitiveIDLTypeInfo('WebKitFlags', dart_type='Object'), | 634 'WebKitFlags': PrimitiveIDLTypeInfo('WebKitFlags', dart_type='Object'), |
| 636 | 635 |
| 637 'DOMStringList': PrimitiveIDLTypeInfo('DOMStringList', dart_type='List<Strin
g>'), | 636 'DOMStringList': PrimitiveIDLTypeInfo('DOMStringList', dart_type='List<Strin
g>'), |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 676 '"SVGAnimatedListPropertyTearOff.h"', | 675 '"SVGAnimatedListPropertyTearOff.h"', |
| 677 '"SVGTransformListPropertyTearOff.h"', | 676 '"SVGTransformListPropertyTearOff.h"', |
| 678 '"SVGPathSegListPropertyTearOff.h"', | 677 '"SVGPathSegListPropertyTearOff.h"', |
| 679 ] | 678 ] |
| 680 | 679 |
| 681 def GetIDLTypeInfo(idl_type_name): | 680 def GetIDLTypeInfo(idl_type_name): |
| 682 match = re.match(r'sequence<(\w+)>$', idl_type_name) | 681 match = re.match(r'sequence<(\w+)>$', idl_type_name) |
| 683 if match: | 682 if match: |
| 684 return SequenceIDLTypeInfo(idl_type_name, GetIDLTypeInfo(match.group(1))) | 683 return SequenceIDLTypeInfo(idl_type_name, GetIDLTypeInfo(match.group(1))) |
| 685 return _idl_type_registry.get(idl_type_name, IDLTypeInfo(idl_type_name)) | 684 return _idl_type_registry.get(idl_type_name, IDLTypeInfo(idl_type_name)) |
| OLD | NEW |