| 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 | 10 |
| (...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 417 # Given a sorted sequence of type identifiers, return an appropriate type | 417 # Given a sorted sequence of type identifiers, return an appropriate type |
| 418 # name | 418 # name |
| 419 def TypeName(type_ids, interface): | 419 def TypeName(type_ids, interface): |
| 420 # Dynamically type this field for now. | 420 # Dynamically type this field for now. |
| 421 return 'Dynamic' | 421 return 'Dynamic' |
| 422 | 422 |
| 423 # ------------------------------------------------------------------------------ | 423 # ------------------------------------------------------------------------------ |
| 424 | 424 |
| 425 class IDLTypeInfo(object): | 425 class IDLTypeInfo(object): |
| 426 def __init__(self, idl_type, dart_type=None, | 426 def __init__(self, idl_type, dart_type=None, |
| 427 native_type=None, ref_counted=True, | 427 native_type=None, |
| 428 custom_to_native=False, | 428 custom_to_native=False, |
| 429 custom_to_dart=False, conversion_includes=[]): | 429 custom_to_dart=False, conversion_includes=[]): |
| 430 self._idl_type = idl_type | 430 self._idl_type = idl_type |
| 431 self._dart_type = dart_type | 431 self._dart_type = dart_type |
| 432 self._native_type = native_type | 432 self._native_type = native_type |
| 433 self._ref_counted = ref_counted | |
| 434 self._custom_to_native = custom_to_native | 433 self._custom_to_native = custom_to_native |
| 435 self._custom_to_dart = custom_to_dart | 434 self._custom_to_dart = custom_to_dart |
| 436 self._conversion_includes = conversion_includes + [idl_type] | 435 self._conversion_includes = conversion_includes + [idl_type] |
| 437 | 436 |
| 438 def idl_type(self): | 437 def idl_type(self): |
| 439 return self._idl_type | 438 return self._idl_type |
| 440 | 439 |
| 441 def dart_type(self): | 440 def dart_type(self): |
| 442 return self._dart_type or self._idl_type | 441 return self._dart_type or self._idl_type |
| 443 | 442 |
| 444 def native_type(self): | 443 def native_type(self): |
| 445 return self._native_type or self._idl_type | 444 return self._native_type or self._idl_type |
| 446 | 445 |
| 447 def parameter_adapter_info(self): | 446 def parameter_adapter_info(self): |
| 448 native_type = self.native_type() | 447 adapter_type = 'ParameterAdapter<Dart%s>' % self._idl_type |
| 449 if self._ref_counted: | 448 include = '"Dart%s.h"' % self._idl_type |
| 450 native_type = 'RefPtr< %s >' % native_type | 449 return (adapter_type, include) |
| 451 wrapper_type = 'Dart%s' % self.idl_type() | |
| 452 adapter_type = 'ParameterAdapter<%s, %s>' % (native_type, wrapper_type) | |
| 453 return (adapter_type, '"%s.h"' % wrapper_type) | |
| 454 | 450 |
| 455 def custom_to_native(self): | 451 def custom_to_native(self): |
| 456 return self._custom_to_native | 452 return self._custom_to_native |
| 457 | 453 |
| 458 def parameter_type(self): | 454 def parameter_type(self): |
| 459 return '%s*' % self.native_type() | 455 return '%s*' % self.native_type() |
| 460 | 456 |
| 461 def webcore_includes(self): | 457 def webcore_includes(self): |
| 462 WTF_INCLUDES = [ | 458 WTF_INCLUDES = [ |
| 463 'ArrayBuffer', | 459 'ArrayBuffer', |
| 464 'ArrayBufferView', | 460 'ArrayBufferView', |
| 465 'Float32Array', | 461 'Float32Array', |
| 466 'Float64Array', | 462 'Float64Array', |
| 467 'Int8Array', | 463 'Int8Array', |
| 468 'Int16Array', | 464 'Int16Array', |
| 469 'Int32Array', | 465 'Int32Array', |
| 470 'Uint8Array', | 466 'Uint8Array', |
| 471 'Uint16Array', | 467 'Uint16Array', |
| 472 'Uint32Array', | 468 'Uint32Array', |
| 473 'Uint8ClampedArray', | 469 'Uint8ClampedArray', |
| 474 ] | 470 ] |
| 475 | 471 |
| 476 if self._idl_type in WTF_INCLUDES: | 472 if self._idl_type in WTF_INCLUDES: |
| 477 return ['<wtf/%s.h>' % self.native_type()] | 473 return ['<wtf/%s.h>' % self.native_type()] |
| 478 | 474 |
| 479 if not self._idl_type.startswith('SVG'): | 475 if not self._idl_type.startswith('SVG'): |
| 480 return ['"%s.h"' % self.native_type()] | 476 return ['"%s.h"' % self.native_type()] |
| 481 | 477 |
| 482 if self._idl_type in ['SVGNumber', 'SVGPoint']: | 478 if self._idl_type in ['SVGNumber', 'SVGPoint']: |
| 483 return [] | 479 return ['"SVGPropertyTearOff.h"'] |
| 484 if self._idl_type.startswith('SVGPathSeg'): | 480 if self._idl_type.startswith('SVGPathSeg'): |
| 485 include = self._idl_type.replace('Abs', '').replace('Rel', '') | 481 include = self._idl_type.replace('Abs', '').replace('Rel', '') |
| 486 else: | 482 else: |
| 487 include = self._idl_type | 483 include = self._idl_type |
| 488 return ['"%s.h"' % include] + _svg_supplemental_includes | 484 return ['"%s.h"' % include] + _svg_supplemental_includes |
| 489 | 485 |
| 490 def receiver(self): | 486 def receiver(self): |
| 491 return 'receiver->' | 487 return 'receiver->' |
| 492 | 488 |
| 493 def conversion_includes(self): | 489 def conversion_includes(self): |
| (...skipping 15 matching lines...) Expand all Loading... |
| 509 return 'List<%s>' % self._item_info.dart_type() | 505 return 'List<%s>' % self._item_info.dart_type() |
| 510 | 506 |
| 511 def to_dart_conversion(self, value, interface_name=None, attributes=None): | 507 def to_dart_conversion(self, value, interface_name=None, attributes=None): |
| 512 return 'DartDOMWrapper::vectorToDart<Dart%s>(%s)' % (self._item_info.native_
type(), value) | 508 return 'DartDOMWrapper::vectorToDart<Dart%s>(%s)' % (self._item_info.native_
type(), value) |
| 513 | 509 |
| 514 def conversion_includes(self): | 510 def conversion_includes(self): |
| 515 return self._item_info.conversion_includes() | 511 return self._item_info.conversion_includes() |
| 516 | 512 |
| 517 | 513 |
| 518 class PrimitiveIDLTypeInfo(IDLTypeInfo): | 514 class PrimitiveIDLTypeInfo(IDLTypeInfo): |
| 519 def __init__(self, idl_type, dart_type, native_type=None, ref_counted=False, | 515 def __init__(self, idl_type, dart_type, native_type=None, |
| 520 webcore_getter_name='getAttribute', | 516 webcore_getter_name='getAttribute', |
| 521 webcore_setter_name='setAttribute'): | 517 webcore_setter_name='setAttribute'): |
| 522 super(PrimitiveIDLTypeInfo, self).__init__(idl_type, dart_type=dart_type, | 518 super(PrimitiveIDLTypeInfo, self).__init__(idl_type, dart_type=dart_type, |
| 523 native_type=native_type, ref_counted=ref_counted) | 519 native_type=native_type) |
| 524 self._webcore_getter_name = webcore_getter_name | 520 self._webcore_getter_name = webcore_getter_name |
| 525 self._webcore_setter_name = webcore_setter_name | 521 self._webcore_setter_name = webcore_setter_name |
| 526 | 522 |
| 527 def parameter_adapter_info(self): | 523 def parameter_adapter_info(self): |
| 528 native_type = self.native_type() | 524 adapter_type = 'ParameterAdapter<%s>' % self.native_type() |
| 529 if self._ref_counted: | 525 return (adapter_type, None) |
| 530 native_type = 'RefPtr< %s >' % native_type | |
| 531 return ('ParameterAdapter< %s >' % native_type, None) | |
| 532 | 526 |
| 533 def parameter_type(self): | 527 def parameter_type(self): |
| 534 if self.native_type() == 'String': | 528 if self.native_type() == 'String': |
| 535 return 'const String&' | 529 return 'const String&' |
| 536 return self.native_type() | 530 return self.native_type() |
| 537 | 531 |
| 538 def conversion_includes(self): | 532 def conversion_includes(self): |
| 539 return [] | 533 return [] |
| 540 | 534 |
| 541 def to_dart_conversion(self, value, interface_name=None, attributes=None): | 535 def to_dart_conversion(self, value, interface_name=None, attributes=None): |
| 542 conversion_arguments = [value] | 536 conversion_arguments = [value] |
| 543 if attributes and 'TreatReturnedNullStringAs' in attributes: | 537 if attributes and 'TreatReturnedNullStringAs' in attributes: |
| 544 conversion_arguments.append('DartUtilities::ConvertNullToDefaultValue') | 538 conversion_arguments.append('DartUtilities::ConvertNullToDefaultValue') |
| 545 function_name = re.sub(r' [a-z]', lambda x: x.group(0)[1:].upper(), self.nat
ive_type()) | 539 function_name = re.sub(r' [a-z]', lambda x: x.group(0)[1:].upper(), self.nat
ive_type()) |
| 546 function_name = function_name[0].lower() + function_name[1:] | 540 function_name = function_name[0].lower() + function_name[1:] |
| 547 function_name = 'DartUtilities::%sToDart' % function_name | 541 function_name = 'DartUtilities::%sToDart' % function_name |
| 548 return '%s(%s)' % (function_name, ', '.join(conversion_arguments)) | 542 return '%s(%s)' % (function_name, ', '.join(conversion_arguments)) |
| 549 | 543 |
| 550 def webcore_getter_name(self): | 544 def webcore_getter_name(self): |
| 551 return self._webcore_getter_name | 545 return self._webcore_getter_name |
| 552 | 546 |
| 553 def webcore_setter_name(self): | 547 def webcore_setter_name(self): |
| 554 return self._webcore_setter_name | 548 return self._webcore_setter_name |
| 555 | 549 |
| 556 class SVGTearOffIDLTypeInfo(IDLTypeInfo): | 550 class SVGTearOffIDLTypeInfo(IDLTypeInfo): |
| 557 def __init__(self, idl_type, native_type='', ref_counted=True): | 551 def __init__(self, idl_type, native_type=''): |
| 558 super(SVGTearOffIDLTypeInfo, self).__init__(idl_type, | 552 super(SVGTearOffIDLTypeInfo, self).__init__(idl_type, |
| 559 native_type=native_type, | 553 native_type=native_type) |
| 560 ref_counted=ref_counted) | |
| 561 | 554 |
| 562 def native_type(self): | 555 def native_type(self): |
| 563 if self._native_type: | 556 if self._native_type: |
| 564 return self._native_type | 557 return self._native_type |
| 565 tear_off_type = 'SVGPropertyTearOff' | 558 tear_off_type = 'SVGPropertyTearOff' |
| 566 if self._idl_type.endswith('List'): | 559 if self._idl_type.endswith('List'): |
| 567 tear_off_type = 'SVGListPropertyTearOff' | 560 tear_off_type = 'SVGListPropertyTearOff' |
| 568 return '%s<%s>' % (tear_off_type, self._idl_type) | 561 return '%s<%s>' % (tear_off_type, self._idl_type) |
| 569 | 562 |
| 570 def receiver(self): | 563 def receiver(self): |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 622 # a native JS Map for JS DOM. | 615 # a native JS Map for JS DOM. |
| 623 'Dictionary': PrimitiveIDLTypeInfo('Dictionary', dart_type='Map'), | 616 'Dictionary': PrimitiveIDLTypeInfo('Dictionary', dart_type='Map'), |
| 624 # TODO(sra): Flags is really a dictionary: {create:bool, exclusive:bool} | 617 # 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 | 618 # http://dev.w3.org/2009/dap/file-system/file-dir-sys.html#the-flags-interfa
ce |
| 626 'Flags': PrimitiveIDLTypeInfo('Flags', dart_type='Object'), | 619 'Flags': PrimitiveIDLTypeInfo('Flags', dart_type='Object'), |
| 627 'DOMTimeStamp': PrimitiveIDLTypeInfo('DOMTimeStamp', dart_type='int', native
_type='unsigned long long'), | 620 'DOMTimeStamp': PrimitiveIDLTypeInfo('DOMTimeStamp', dart_type='int', native
_type='unsigned long long'), |
| 628 'object': PrimitiveIDLTypeInfo('object', dart_type='Object', native_type='Sc
riptValue'), | 621 '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 | 622 # 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 | 623 # the documentation, the user is made aware that only a limited subset of |
| 631 # serializable types are actually permitted. | 624 # serializable types are actually permitted. |
| 632 'SerializedScriptValue': PrimitiveIDLTypeInfo('SerializedScriptValue', dart_
type='Dynamic', ref_counted=True), | 625 'SerializedScriptValue': PrimitiveIDLTypeInfo('SerializedScriptValue', dart_
type='Dynamic'), |
| 633 # TODO(sra): Flags is really a dictionary: {create:bool, exclusive:bool} | 626 # 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 | 627 # http://dev.w3.org/2009/dap/file-system/file-dir-sys.html#the-flags-interfa
ce |
| 635 'WebKitFlags': PrimitiveIDLTypeInfo('WebKitFlags', dart_type='Object'), | 628 'WebKitFlags': PrimitiveIDLTypeInfo('WebKitFlags', dart_type='Object'), |
| 636 | 629 |
| 637 'sequence': PrimitiveIDLTypeInfo('sequence', dart_type='List'), | 630 'sequence': PrimitiveIDLTypeInfo('sequence', dart_type='List'), |
| 638 'void': PrimitiveIDLTypeInfo('void', dart_type='void'), | 631 'void': PrimitiveIDLTypeInfo('void', dart_type='void'), |
| 639 | 632 |
| 640 'CSSRule': IDLTypeInfo('CSSRule', conversion_includes=['CSSImportRule']), | 633 'CSSRule': IDLTypeInfo('CSSRule', conversion_includes=['CSSImportRule']), |
| 641 'DOMException': IDLTypeInfo('DOMException', native_type='DOMCoreException'), | 634 'DOMException': IDLTypeInfo('DOMException', native_type='DOMCoreException'), |
| 642 'DOMStringList': IDLTypeInfo('DOMStringList', dart_type='List<String>', cust
om_to_native=True), | 635 'DOMStringList': IDLTypeInfo('DOMStringList', dart_type='List<String>', cust
om_to_native=True), |
| 643 'DOMStringMap': IDLTypeInfo('DOMStringMap', dart_type='Map<String, String>')
, | 636 'DOMStringMap': IDLTypeInfo('DOMStringMap', dart_type='Map<String, String>')
, |
| 644 'DOMWindow': IDLTypeInfo('DOMWindow', custom_to_dart=True), | 637 'DOMWindow': IDLTypeInfo('DOMWindow', custom_to_dart=True), |
| 645 'Element': IDLTypeInfo('Element', custom_to_dart=True), | 638 'Element': IDLTypeInfo('Element', custom_to_dart=True), |
| 646 'EventListener': IDLTypeInfo('EventListener', custom_to_native=True), | 639 'EventListener': IDLTypeInfo('EventListener', custom_to_native=True), |
| 647 'EventTarget': IDLTypeInfo('EventTarget', custom_to_native=True), | 640 'EventTarget': IDLTypeInfo('EventTarget', custom_to_native=True), |
| 648 'HTMLElement': IDLTypeInfo('HTMLElement', custom_to_dart=True), | 641 'HTMLElement': IDLTypeInfo('HTMLElement', custom_to_dart=True), |
| 649 'IDBAny': IDLTypeInfo('IDBAny', dart_type='Dynamic', custom_to_native=True), | 642 'IDBAny': IDLTypeInfo('IDBAny', dart_type='Dynamic', custom_to_native=True), |
| 650 'IDBKey': IDLTypeInfo('IDBKey', dart_type='Dynamic', custom_to_native=True), | 643 'IDBKey': IDLTypeInfo('IDBKey', dart_type='Dynamic', custom_to_native=True), |
| 651 'MediaQueryListListener': IDLTypeInfo('MediaQueryListListener', custom_to_na
tive=True), | 644 'MediaQueryListListener': IDLTypeInfo('MediaQueryListListener', custom_to_na
tive=True), |
| 652 'StyleSheet': IDLTypeInfo('StyleSheet', conversion_includes=['CSSStyleSheet'
]), | 645 'StyleSheet': IDLTypeInfo('StyleSheet', conversion_includes=['CSSStyleSheet'
]), |
| 653 'SVGElement': IDLTypeInfo('SVGElement', custom_to_dart=True), | 646 'SVGElement': IDLTypeInfo('SVGElement', custom_to_dart=True), |
| 654 | 647 |
| 655 'SVGAngle': SVGTearOffIDLTypeInfo('SVGAngle'), | 648 'SVGAngle': SVGTearOffIDLTypeInfo('SVGAngle'), |
| 656 'SVGLength': SVGTearOffIDLTypeInfo('SVGLength'), | 649 'SVGLength': SVGTearOffIDLTypeInfo('SVGLength'), |
| 657 'SVGLengthList': SVGTearOffIDLTypeInfo('SVGLengthList', ref_counted=False), | 650 'SVGLengthList': SVGTearOffIDLTypeInfo('SVGLengthList'), |
| 658 'SVGMatrix': SVGTearOffIDLTypeInfo('SVGMatrix'), | 651 'SVGMatrix': SVGTearOffIDLTypeInfo('SVGMatrix'), |
| 659 'SVGNumber': SVGTearOffIDLTypeInfo('SVGNumber', native_type='SVGPropertyTear
Off<float>'), | 652 'SVGNumber': SVGTearOffIDLTypeInfo('SVGNumber', native_type='SVGPropertyTear
Off<float>'), |
| 660 'SVGNumberList': SVGTearOffIDLTypeInfo('SVGNumberList', ref_counted=False), | 653 'SVGNumberList': SVGTearOffIDLTypeInfo('SVGNumberList'), |
| 661 'SVGPathSegList': SVGTearOffIDLTypeInfo('SVGPathSegList', native_type='SVGPa
thSegListPropertyTearOff', ref_counted=False), | 654 'SVGPathSegList': SVGTearOffIDLTypeInfo('SVGPathSegList', native_type='SVGPa
thSegListPropertyTearOff'), |
| 662 'SVGPoint': SVGTearOffIDLTypeInfo('SVGPoint', native_type='SVGPropertyTearOf
f<FloatPoint>'), | 655 'SVGPoint': SVGTearOffIDLTypeInfo('SVGPoint', native_type='SVGPropertyTearOf
f<FloatPoint>'), |
| 663 'SVGPointList': SVGTearOffIDLTypeInfo('SVGPointList', ref_counted=False), | 656 'SVGPointList': SVGTearOffIDLTypeInfo('SVGPointList'), |
| 664 'SVGPreserveAspectRatio': SVGTearOffIDLTypeInfo('SVGPreserveAspectRatio'), | 657 'SVGPreserveAspectRatio': SVGTearOffIDLTypeInfo('SVGPreserveAspectRatio'), |
| 665 'SVGRect': SVGTearOffIDLTypeInfo('SVGRect', native_type='SVGPropertyTearOff<
FloatRect>'), | 658 'SVGRect': SVGTearOffIDLTypeInfo('SVGRect', native_type='SVGPropertyTearOff<
FloatRect>'), |
| 666 'SVGStringList': SVGTearOffIDLTypeInfo('SVGStringList', native_type='SVGStat
icListPropertyTearOff<SVGStringList>', ref_counted=False), | 659 'SVGStringList': SVGTearOffIDLTypeInfo('SVGStringList', native_type='SVGStat
icListPropertyTearOff<SVGStringList>'), |
| 667 'SVGTransform': SVGTearOffIDLTypeInfo('SVGTransform'), | 660 'SVGTransform': SVGTearOffIDLTypeInfo('SVGTransform'), |
| 668 'SVGTransformList': SVGTearOffIDLTypeInfo('SVGTransformList', native_type='S
VGTransformListPropertyTearOff', ref_counted=False) | 661 'SVGTransformList': SVGTearOffIDLTypeInfo('SVGTransformList', native_type='S
VGTransformListPropertyTearOff') |
| 669 } | 662 } |
| 670 | 663 |
| 671 _svg_supplemental_includes = [ | 664 _svg_supplemental_includes = [ |
| 672 '"SVGAnimatedPropertyTearOff.h"', | 665 '"SVGAnimatedPropertyTearOff.h"', |
| 673 '"SVGAnimatedListPropertyTearOff.h"', | 666 '"SVGAnimatedListPropertyTearOff.h"', |
| 674 '"SVGStaticListPropertyTearOff.h"', | 667 '"SVGStaticListPropertyTearOff.h"', |
| 675 '"SVGAnimatedListPropertyTearOff.h"', | 668 '"SVGAnimatedListPropertyTearOff.h"', |
| 676 '"SVGTransformListPropertyTearOff.h"', | 669 '"SVGTransformListPropertyTearOff.h"', |
| 677 '"SVGPathSegListPropertyTearOff.h"', | 670 '"SVGPathSegListPropertyTearOff.h"', |
| 678 ] | 671 ] |
| 679 | 672 |
| 680 def GetIDLTypeInfo(idl_type_name): | 673 def GetIDLTypeInfo(idl_type_name): |
| 681 match = re.match(r'sequence<(\w+)>$', idl_type_name) | 674 match = re.match(r'sequence<(\w+)>$', idl_type_name) |
| 682 if match: | 675 if match: |
| 683 return SequenceIDLTypeInfo(idl_type_name, GetIDLTypeInfo(match.group(1))) | 676 return SequenceIDLTypeInfo(idl_type_name, GetIDLTypeInfo(match.group(1))) |
| 684 return _idl_type_registry.get(idl_type_name, IDLTypeInfo(idl_type_name)) | 677 return _idl_type_registry.get(idl_type_name, IDLTypeInfo(idl_type_name)) |
| OLD | NEW |