| 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 import string |
| (...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 469 'Int8Array', | 469 'Int8Array', |
| 470 'Int16Array', | 470 'Int16Array', |
| 471 'Int32Array', | 471 'Int32Array', |
| 472 'Uint8Array', | 472 'Uint8Array', |
| 473 'Uint16Array', | 473 'Uint16Array', |
| 474 'Uint32Array', | 474 'Uint32Array', |
| 475 'Uint8ClampedArray', | 475 'Uint8ClampedArray', |
| 476 ] | 476 ] |
| 477 | 477 |
| 478 if self._idl_type in WTF_INCLUDES: | 478 if self._idl_type in WTF_INCLUDES: |
| 479 return ['<wtf/%s.h>' % self._idl_type] | 479 return ['<wtf/%s.h>' % self.native_type()] |
| 480 | 480 |
| 481 if not self._idl_type.startswith('SVG'): | 481 if not self._idl_type.startswith('SVG'): |
| 482 return ['"%s.h"' % self._idl_type] | 482 return ['"%s.h"' % self.native_type()] |
| 483 | 483 |
| 484 if self._idl_type in ['SVGNumber', 'SVGPoint']: | 484 if self._idl_type in ['SVGNumber', 'SVGPoint']: |
| 485 return [] | 485 return [] |
| 486 if self._idl_type.startswith('SVGPathSeg'): | 486 if self._idl_type.startswith('SVGPathSeg'): |
| 487 include = self._idl_type.replace('Abs', '').replace('Rel', '') | 487 include = self._idl_type.replace('Abs', '').replace('Rel', '') |
| 488 else: | 488 else: |
| 489 include = self._idl_type | 489 include = self._idl_type |
| 490 return ['"%s.h"' % include] + _svg_supplemental_includes | 490 return ['"%s.h"' % include] + _svg_supplemental_includes |
| 491 | 491 |
| 492 def receiver(self): | 492 def receiver(self): |
| 493 return 'receiver->' | 493 return 'receiver->' |
| 494 | 494 |
| 495 def conversion_includes(self): | 495 def conversion_includes(self): |
| 496 return ['"Dart%s.h"' % include for include in self._conversion_includes] | 496 return ['"Dart%s.h"' % include for include in self._conversion_includes] |
| 497 | 497 |
| 498 def to_dart_conversion(self, value, interface_name=None, attributes=None): | 498 def to_dart_conversion(self, value, interface_name=None, attributes=None): |
| 499 return 'toDartValue(%s)' % value | 499 return 'Dart%s::toDart(%s)' % (self._idl_type, value) |
| 500 | 500 |
| 501 def custom_to_dart(self): | 501 def custom_to_dart(self): |
| 502 return self._custom_to_dart | 502 return self._custom_to_dart |
| 503 | 503 |
| 504 | 504 |
| 505 class SequenceIDLTypeInfo(IDLTypeInfo): | 505 class SequenceIDLTypeInfo(IDLTypeInfo): |
| 506 def __init__(self, idl_type, item_info): | 506 def __init__(self, idl_type, item_info): |
| 507 super(SequenceIDLTypeInfo, self).__init__(idl_type) | 507 super(SequenceIDLTypeInfo, self).__init__(idl_type) |
| 508 self._item_info = item_info | 508 self._item_info = item_info |
| 509 | 509 |
| 510 def dart_type(self): | 510 def dart_type(self): |
| 511 return 'List<%s>' % self._item_info.dart_type() | 511 return 'List<%s>' % self._item_info.dart_type() |
| 512 | 512 |
| 513 def to_dart_conversion(self, value, interface_name=None, attributes=None): |
| 514 return 'DartDOMWrapper::vectorToDart<Dart%s>(%s)' % (self._item_info.native_
type(), value) |
| 515 |
| 513 def conversion_includes(self): | 516 def conversion_includes(self): |
| 514 return self._item_info.conversion_includes() | 517 return self._item_info.conversion_includes() |
| 515 | 518 |
| 516 | 519 |
| 517 class PrimitiveIDLTypeInfo(IDLTypeInfo): | 520 class PrimitiveIDLTypeInfo(IDLTypeInfo): |
| 518 def __init__(self, idl_type, dart_type, native_type=None, ref_counted=False, | 521 def __init__(self, idl_type, dart_type, native_type=None, ref_counted=False, |
| 519 webcore_getter_name='getAttribute', | 522 webcore_getter_name='getAttribute', |
| 520 webcore_setter_name='setAttribute'): | 523 webcore_setter_name='setAttribute'): |
| 521 super(PrimitiveIDLTypeInfo, self).__init__(idl_type, dart_type=dart_type, | 524 super(PrimitiveIDLTypeInfo, self).__init__(idl_type, dart_type=dart_type, |
| 522 native_type=native_type, ref_counted=ref_counted) | 525 native_type=native_type, ref_counted=ref_counted) |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 583 conversion_cast = 'static_cast<%s*>(%s)' | 586 conversion_cast = 'static_cast<%s*>(%s)' |
| 584 elif self.idl_type() == 'SVGStringList': | 587 elif self.idl_type() == 'SVGStringList': |
| 585 conversion_cast = '%s::create(receiver, %s)' | 588 conversion_cast = '%s::create(receiver, %s)' |
| 586 elif interface_name.endswith('List'): | 589 elif interface_name.endswith('List'): |
| 587 conversion_cast = 'static_cast<%s*>(%s.get())' | 590 conversion_cast = 'static_cast<%s*>(%s.get())' |
| 588 elif self.idl_type() in svg_primitive_types: | 591 elif self.idl_type() in svg_primitive_types: |
| 589 conversion_cast = '%s::create(%s)' | 592 conversion_cast = '%s::create(%s)' |
| 590 else: | 593 else: |
| 591 conversion_cast = 'static_cast<%s*>(%s)' | 594 conversion_cast = 'static_cast<%s*>(%s)' |
| 592 conversion_cast = conversion_cast % (self.native_type(), value) | 595 conversion_cast = conversion_cast % (self.native_type(), value) |
| 593 return 'toDartValue(%s)' % conversion_cast | 596 return 'Dart%s::toDart(%s)' % (self._idl_type, conversion_cast) |
| 594 | 597 |
| 595 _idl_type_registry = { | 598 _idl_type_registry = { |
| 596 'boolean': PrimitiveIDLTypeInfo('boolean', dart_type='bool', native_type='bo
ol', | 599 'boolean': PrimitiveIDLTypeInfo('boolean', dart_type='bool', native_type='bo
ol', |
| 597 webcore_getter_name='hasAttribute', | 600 webcore_getter_name='hasAttribute', |
| 598 webcore_setter_name='setBooleanAttribute'), | 601 webcore_setter_name='setBooleanAttribute'), |
| 599 'short': PrimitiveIDLTypeInfo('short', dart_type='int', native_type='int'), | 602 'short': PrimitiveIDLTypeInfo('short', dart_type='int', native_type='int'), |
| 600 'unsigned short': PrimitiveIDLTypeInfo('unsigned short', dart_type='int', | 603 'unsigned short': PrimitiveIDLTypeInfo('unsigned short', dart_type='int', |
| 601 native_type='int'), | 604 native_type='int'), |
| 602 'int': PrimitiveIDLTypeInfo('int', dart_type='int'), | 605 'int': PrimitiveIDLTypeInfo('int', dart_type='int'), |
| 603 'unsigned int': PrimitiveIDLTypeInfo('unsigned int', dart_type='int', | 606 'unsigned int': PrimitiveIDLTypeInfo('unsigned int', dart_type='int', |
| (...skipping 28 matching lines...) Expand all Loading... |
| 632 'SerializedScriptValue': PrimitiveIDLTypeInfo('SerializedScriptValue', dart_
type='Dynamic', ref_counted=True), | 635 'SerializedScriptValue': PrimitiveIDLTypeInfo('SerializedScriptValue', dart_
type='Dynamic', ref_counted=True), |
| 633 # TODO(sra): Flags is really a dictionary: {create:bool, exclusive:bool} | 636 # 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 | 637 # http://dev.w3.org/2009/dap/file-system/file-dir-sys.html#the-flags-interfa
ce |
| 635 'WebKitFlags': PrimitiveIDLTypeInfo('WebKitFlags', dart_type='Object'), | 638 'WebKitFlags': PrimitiveIDLTypeInfo('WebKitFlags', dart_type='Object'), |
| 636 | 639 |
| 637 'DOMStringList': PrimitiveIDLTypeInfo('DOMStringList', dart_type='List<Strin
g>'), | 640 'DOMStringList': PrimitiveIDLTypeInfo('DOMStringList', dart_type='List<Strin
g>'), |
| 638 'sequence': PrimitiveIDLTypeInfo('sequence', dart_type='List'), | 641 'sequence': PrimitiveIDLTypeInfo('sequence', dart_type='List'), |
| 639 'void': PrimitiveIDLTypeInfo('void', dart_type='void'), | 642 'void': PrimitiveIDLTypeInfo('void', dart_type='void'), |
| 640 | 643 |
| 641 'CSSRule': IDLTypeInfo('CSSRule', conversion_includes=['CSSImportRule']), | 644 'CSSRule': IDLTypeInfo('CSSRule', conversion_includes=['CSSImportRule']), |
| 642 'DOMException': IDLTypeInfo('DOMCoreException', dart_type='DOMException'), | 645 'DOMException': IDLTypeInfo('DOMException', native_type='DOMCoreException'), |
| 643 'DOMStringMap': IDLTypeInfo('DOMStringMap', dart_type='Map<String, String>')
, | 646 'DOMStringMap': IDLTypeInfo('DOMStringMap', dart_type='Map<String, String>')
, |
| 644 'DOMWindow': IDLTypeInfo('DOMWindow', custom_to_dart=True), | 647 'DOMWindow': IDLTypeInfo('DOMWindow', custom_to_dart=True), |
| 645 'Element': IDLTypeInfo('Element', custom_to_dart=True), | 648 'Element': IDLTypeInfo('Element', custom_to_dart=True), |
| 646 'EventListener': IDLTypeInfo('EventListener', custom_to_native=True), | 649 'EventListener': IDLTypeInfo('EventListener', custom_to_native=True), |
| 647 'EventTarget': IDLTypeInfo('EventTarget', custom_to_native=True), | 650 'EventTarget': IDLTypeInfo('EventTarget', custom_to_native=True), |
| 648 'HTMLElement': IDLTypeInfo('HTMLElement', custom_to_dart=True), | 651 'HTMLElement': IDLTypeInfo('HTMLElement', custom_to_dart=True), |
| 649 'IDBAny': IDLTypeInfo('IDBAny', dart_type='Dynamic', custom_to_native=True), | 652 'IDBAny': IDLTypeInfo('IDBAny', dart_type='Dynamic', custom_to_native=True), |
| 650 'IDBKey': IDLTypeInfo('IDBKey', dart_type='Dynamic', custom_to_native=True), | 653 'IDBKey': IDLTypeInfo('IDBKey', dart_type='Dynamic', custom_to_native=True), |
| 651 'MediaQueryListListener': IDLTypeInfo('MediaQueryListListener', custom_to_na
tive=True), | 654 'MediaQueryListListener': IDLTypeInfo('MediaQueryListListener', custom_to_na
tive=True), |
| 652 'OptionsObject': IDLTypeInfo('OptionsObject', custom_to_native=True), | 655 'OptionsObject': IDLTypeInfo('OptionsObject', custom_to_native=True), |
| (...skipping 23 matching lines...) Expand all Loading... |
| 676 '"SVGAnimatedListPropertyTearOff.h"', | 679 '"SVGAnimatedListPropertyTearOff.h"', |
| 677 '"SVGTransformListPropertyTearOff.h"', | 680 '"SVGTransformListPropertyTearOff.h"', |
| 678 '"SVGPathSegListPropertyTearOff.h"', | 681 '"SVGPathSegListPropertyTearOff.h"', |
| 679 ] | 682 ] |
| 680 | 683 |
| 681 def GetIDLTypeInfo(idl_type_name): | 684 def GetIDLTypeInfo(idl_type_name): |
| 682 match = re.match(r'sequence<(\w+)>$', idl_type_name) | 685 match = re.match(r'sequence<(\w+)>$', idl_type_name) |
| 683 if match: | 686 if match: |
| 684 return SequenceIDLTypeInfo(idl_type_name, GetIDLTypeInfo(match.group(1))) | 687 return SequenceIDLTypeInfo(idl_type_name, GetIDLTypeInfo(match.group(1))) |
| 685 return _idl_type_registry.get(idl_type_name, IDLTypeInfo(idl_type_name)) | 688 return _idl_type_registry.get(idl_type_name, IDLTypeInfo(idl_type_name)) |
| OLD | NEW |