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 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
443 # name | 443 # name |
444 def TypeName(typeIds, interface): | 444 def TypeName(typeIds, interface): |
445 # Dynamically type this field for now. | 445 # Dynamically type this field for now. |
446 return 'var' | 446 return 'var' |
447 | 447 |
448 # ------------------------------------------------------------------------------ | 448 # ------------------------------------------------------------------------------ |
449 | 449 |
450 class IDLTypeInfo(object): | 450 class IDLTypeInfo(object): |
451 def __init__(self, idl_type, dart_type=None, native_type=None, ref_counted=Tru
e, | 451 def __init__(self, idl_type, dart_type=None, native_type=None, ref_counted=Tru
e, |
452 has_dart_wrapper=True, conversion_template=None, | 452 has_dart_wrapper=True, conversion_template=None, |
453 custom_to_dart=False): | 453 custom_to_dart=False, conversion_includes=[]): |
454 self._idl_type = idl_type | 454 self._idl_type = idl_type |
455 self._dart_type = dart_type | 455 self._dart_type = dart_type |
456 self._native_type = native_type | 456 self._native_type = native_type |
457 self._ref_counted = ref_counted | 457 self._ref_counted = ref_counted |
458 self._has_dart_wrapper = has_dart_wrapper | 458 self._has_dart_wrapper = has_dart_wrapper |
459 self._conversion_template = conversion_template | 459 self._conversion_template = conversion_template |
460 self._custom_to_dart = custom_to_dart | 460 self._custom_to_dart = custom_to_dart |
| 461 self._conversion_includes = conversion_includes |
461 | 462 |
462 def idl_type(self): | 463 def idl_type(self): |
463 return self._idl_type | 464 return self._idl_type |
464 | 465 |
465 def dart_type(self): | 466 def dart_type(self): |
466 if self._dart_type: | 467 if self._dart_type: |
467 return self._dart_type | 468 return self._dart_type |
468 return self._idl_type | 469 return self._idl_type |
469 | 470 |
470 def native_type(self): | 471 def native_type(self): |
471 if self._native_type: | 472 if self._native_type: |
472 return self._native_type | 473 return self._native_type |
473 return self._idl_type | 474 return self._idl_type |
474 | 475 |
475 def parameter_adapter_info(self): | 476 def parameter_adapter_info(self): |
476 native_type = self.native_type() | 477 native_type = self.native_type() |
477 if self._ref_counted: | 478 if self._ref_counted: |
478 native_type = 'RefPtr< %s >' % native_type | 479 native_type = 'RefPtr< %s >' % native_type |
479 if self._has_dart_wrapper: | 480 if self._has_dart_wrapper: |
480 wrapper_type = 'Dart%s' % self.idl_type() | 481 wrapper_type = 'Dart%s' % self.idl_type() |
481 adapter_type = 'ParameterAdapter<%s, %s>' % (native_type, wrapper_type) | 482 adapter_type = 'ParameterAdapter<%s, %s>' % (native_type, wrapper_type) |
482 return (adapter_type, wrapper_type) | 483 return (adapter_type, wrapper_type) |
483 return ('ParameterAdapter< %s >' % native_type, self._idl_type) | 484 return ('ParameterAdapter< %s >' % native_type, self._idl_type) |
484 | 485 |
485 def parameter_type(self): | 486 def parameter_type(self): |
486 return '%s*' % self.native_type() | 487 return '%s*' % self.native_type() |
487 | 488 |
488 def webcore_include(self): | 489 def webcore_includes(self): |
489 if self._idl_type == 'SVGNumber' or self._idl_type == 'SVGPoint': | 490 if not self._idl_type.startswith('SVG'): |
490 return None | 491 return [self._idl_type] |
| 492 |
| 493 if self._idl_type in ['SVGNumber', 'SVGPoint']: |
| 494 return [] |
491 if self._idl_type.startswith('SVGPathSeg'): | 495 if self._idl_type.startswith('SVGPathSeg'): |
492 return self._idl_type.replace('Abs', '').replace('Rel', '') | 496 include = self._idl_type.replace('Abs', '').replace('Rel', '') |
493 return self._idl_type | 497 else: |
| 498 include = self._idl_type |
| 499 return [include] + _svg_supplemental_includes |
494 | 500 |
495 def receiver(self): | 501 def receiver(self): |
496 return 'receiver->' | 502 return 'receiver->' |
497 | 503 |
498 def conversion_include(self): | 504 def conversion_includes(self): |
499 return 'Dart%s' % self._idl_type | 505 return ['Dart%s' % include for include in [self.dart_type()] + self._convers
ion_includes] |
500 | 506 |
501 def conversion_cast(self, expression): | 507 def conversion_cast(self, expression): |
502 if self._conversion_template: | 508 if self._conversion_template: |
503 return self._conversion_template % expression | 509 return self._conversion_template % expression |
504 return expression | 510 return expression |
505 | 511 |
506 def custom_to_dart(self): | 512 def custom_to_dart(self): |
507 return self._custom_to_dart | 513 return self._custom_to_dart |
508 | 514 |
509 class PrimitiveIDLTypeInfo(IDLTypeInfo): | 515 class PrimitiveIDLTypeInfo(IDLTypeInfo): |
(...skipping 11 matching lines...) Expand all Loading... |
521 native_type = self.native_type() | 527 native_type = self.native_type() |
522 if self._ref_counted: | 528 if self._ref_counted: |
523 native_type = 'RefPtr< %s >' % native_type | 529 native_type = 'RefPtr< %s >' % native_type |
524 return ('ParameterAdapter< %s >' % native_type, None) | 530 return ('ParameterAdapter< %s >' % native_type, None) |
525 | 531 |
526 def parameter_type(self): | 532 def parameter_type(self): |
527 if self.native_type() == 'String': | 533 if self.native_type() == 'String': |
528 return 'const String&' | 534 return 'const String&' |
529 return self.native_type() | 535 return self.native_type() |
530 | 536 |
531 def conversion_include(self): | 537 def conversion_includes(self): |
532 return None | 538 return [] |
533 | 539 |
534 def webcore_getter_name(self): | 540 def webcore_getter_name(self): |
535 return self._webcore_getter_name | 541 return self._webcore_getter_name |
536 | 542 |
537 def webcore_setter_name(self): | 543 def webcore_setter_name(self): |
538 return self._webcore_setter_name | 544 return self._webcore_setter_name |
539 | 545 |
540 class SVGTearOffIDLTypeInfo(IDLTypeInfo): | 546 class SVGTearOffIDLTypeInfo(IDLTypeInfo): |
541 def __init__(self, idl_type, native_type='', ref_counted=True): | 547 def __init__(self, idl_type, native_type='', ref_counted=True): |
542 super(SVGTearOffIDLTypeInfo, self).__init__(idl_type, | 548 super(SVGTearOffIDLTypeInfo, self).__init__(idl_type, |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
593 'DOMString': PrimitiveIDLTypeInfo('DOMString', dart_type='String', native_ty
pe='String'), | 599 'DOMString': PrimitiveIDLTypeInfo('DOMString', dart_type='String', native_ty
pe='String'), |
594 # TODO(sra): Flags is really a dictionary: {create:bool, exclusive:bool} | 600 # TODO(sra): Flags is really a dictionary: {create:bool, exclusive:bool} |
595 # http://dev.w3.org/2009/dap/file-system/file-dir-sys.html#the-flags-interfa
ce | 601 # http://dev.w3.org/2009/dap/file-system/file-dir-sys.html#the-flags-interfa
ce |
596 'Flags': PrimitiveIDLTypeInfo('Flags', dart_type='Object'), | 602 'Flags': PrimitiveIDLTypeInfo('Flags', dart_type='Object'), |
597 'List<String>': PrimitiveIDLTypeInfo('DOMStringList', dart_type='List<String
>'), | 603 'List<String>': PrimitiveIDLTypeInfo('DOMStringList', dart_type='List<String
>'), |
598 'DOMTimeStamp': PrimitiveIDLTypeInfo('DOMTimeStamp', dart_type='int'), | 604 'DOMTimeStamp': PrimitiveIDLTypeInfo('DOMTimeStamp', dart_type='int'), |
599 'object': PrimitiveIDLTypeInfo('object', dart_type='Object', native_type='Sc
riptValue'), | 605 'object': PrimitiveIDLTypeInfo('object', dart_type='Object', native_type='Sc
riptValue'), |
600 'SerializedScriptValue': PrimitiveIDLTypeInfo('SerializedScriptValue', dart_
type='Dynamic', ref_counted=True), | 606 'SerializedScriptValue': PrimitiveIDLTypeInfo('SerializedScriptValue', dart_
type='Dynamic', ref_counted=True), |
601 'WebKitFlags': PrimitiveIDLTypeInfo('WebKitFlags', dart_type='Object'), | 607 'WebKitFlags': PrimitiveIDLTypeInfo('WebKitFlags', dart_type='Object'), |
602 | 608 |
| 609 'CSSRule': IDLTypeInfo('CSSRule', conversion_includes=['CSSImportRule']), |
603 'DOMException': IDLTypeInfo('DOMCoreException', dart_type='DOMException'), | 610 'DOMException': IDLTypeInfo('DOMCoreException', dart_type='DOMException'), |
604 'DOMWindow': IDLTypeInfo('DOMWindow', custom_to_dart=True), | 611 'DOMWindow': IDLTypeInfo('DOMWindow', custom_to_dart=True), |
605 'Element': IDLTypeInfo('Element', custom_to_dart=True), | 612 'Element': IDLTypeInfo('Element', custom_to_dart=True), |
606 'EventListener': IDLTypeInfo('EventListener', has_dart_wrapper=False), | 613 'EventListener': IDLTypeInfo('EventListener', has_dart_wrapper=False), |
607 'EventTarget': IDLTypeInfo('EventTarget', has_dart_wrapper=False), | 614 'EventTarget': IDLTypeInfo('EventTarget', has_dart_wrapper=False), |
608 'HTMLElement': IDLTypeInfo('HTMLElement', custom_to_dart=True), | 615 'HTMLElement': IDLTypeInfo('HTMLElement', custom_to_dart=True), |
609 'MediaQueryListListener': IDLTypeInfo('MediaQueryListListener', has_dart_wra
pper=False), | 616 'MediaQueryListListener': IDLTypeInfo('MediaQueryListListener', has_dart_wra
pper=False), |
610 'OptionsObject': IDLTypeInfo('OptionsObject', has_dart_wrapper=False), | 617 'OptionsObject': IDLTypeInfo('OptionsObject', has_dart_wrapper=False), |
| 618 'StyleSheet': IDLTypeInfo('StyleSheet', conversion_includes=['CSSStyleSheet'
]), |
611 'SVGElement': IDLTypeInfo('SVGElement', custom_to_dart=True), | 619 'SVGElement': IDLTypeInfo('SVGElement', custom_to_dart=True), |
612 | 620 |
613 'SVGAngle': SVGTearOffIDLTypeInfo('SVGAngle'), | 621 'SVGAngle': SVGTearOffIDLTypeInfo('SVGAngle'), |
614 'SVGLength': SVGTearOffIDLTypeInfo('SVGLength'), | 622 'SVGLength': SVGTearOffIDLTypeInfo('SVGLength'), |
615 'SVGLengthList': SVGTearOffIDLTypeInfo('SVGLengthList', ref_counted=False), | 623 'SVGLengthList': SVGTearOffIDLTypeInfo('SVGLengthList', ref_counted=False), |
616 'SVGMatrix': SVGTearOffIDLTypeInfo('SVGMatrix'), | 624 'SVGMatrix': SVGTearOffIDLTypeInfo('SVGMatrix'), |
617 'SVGNumber': SVGTearOffIDLTypeInfo('SVGNumber', native_type='SVGPropertyTear
Off<float>'), | 625 'SVGNumber': SVGTearOffIDLTypeInfo('SVGNumber', native_type='SVGPropertyTear
Off<float>'), |
618 'SVGNumberList': SVGTearOffIDLTypeInfo('SVGNumberList', ref_counted=False), | 626 'SVGNumberList': SVGTearOffIDLTypeInfo('SVGNumberList', ref_counted=False), |
619 'SVGPathSegList': SVGTearOffIDLTypeInfo('SVGPathSegList', native_type='SVGPa
thSegListPropertyTearOff', ref_counted=False), | 627 'SVGPathSegList': SVGTearOffIDLTypeInfo('SVGPathSegList', native_type='SVGPa
thSegListPropertyTearOff', ref_counted=False), |
620 'SVGPoint': SVGTearOffIDLTypeInfo('SVGPoint', native_type='SVGPropertyTearOf
f<FloatPoint>'), | 628 'SVGPoint': SVGTearOffIDLTypeInfo('SVGPoint', native_type='SVGPropertyTearOf
f<FloatPoint>'), |
621 'SVGPointList': SVGTearOffIDLTypeInfo('SVGPointList', ref_counted=False), | 629 'SVGPointList': SVGTearOffIDLTypeInfo('SVGPointList', ref_counted=False), |
622 'SVGPreserveAspectRatio': SVGTearOffIDLTypeInfo('SVGPreserveAspectRatio'), | 630 'SVGPreserveAspectRatio': SVGTearOffIDLTypeInfo('SVGPreserveAspectRatio'), |
623 'SVGRect': SVGTearOffIDLTypeInfo('SVGRect', native_type='SVGPropertyTearOff<
FloatRect>'), | 631 'SVGRect': SVGTearOffIDLTypeInfo('SVGRect', native_type='SVGPropertyTearOff<
FloatRect>'), |
624 'SVGStringList': SVGTearOffIDLTypeInfo('SVGStringList', native_type='SVGStat
icListPropertyTearOff<SVGStringList>', ref_counted=False), | 632 'SVGStringList': SVGTearOffIDLTypeInfo('SVGStringList', native_type='SVGStat
icListPropertyTearOff<SVGStringList>', ref_counted=False), |
625 'SVGTransform': SVGTearOffIDLTypeInfo('SVGTransform'), | 633 'SVGTransform': SVGTearOffIDLTypeInfo('SVGTransform'), |
626 'SVGTransformList': SVGTearOffIDLTypeInfo('SVGTransformList', native_type='S
VGTransformListPropertyTearOff', ref_counted=False) | 634 'SVGTransformList': SVGTearOffIDLTypeInfo('SVGTransformList', native_type='S
VGTransformListPropertyTearOff', ref_counted=False) |
627 } | 635 } |
628 | 636 |
| 637 _svg_supplemental_includes = [ |
| 638 'SVGAnimatedPropertyTearOff', |
| 639 'SVGAnimatedListPropertyTearOff', |
| 640 'SVGStaticListPropertyTearOff', |
| 641 'SVGAnimatedListPropertyTearOff', |
| 642 'SVGTransformListPropertyTearOff', |
| 643 'SVGPathSegListPropertyTearOff', |
| 644 ] |
| 645 |
629 def GetIDLTypeInfo(idl_type): | 646 def GetIDLTypeInfo(idl_type): |
630 return GetIDLTypeInfoByName(idl_type.id) | 647 return GetIDLTypeInfoByName(idl_type.id) |
631 | 648 |
632 def GetIDLTypeInfoByName(idl_type_name): | 649 def GetIDLTypeInfoByName(idl_type_name): |
633 return _idl_type_registry.get(idl_type_name, IDLTypeInfo(idl_type_name)) | 650 return _idl_type_registry.get(idl_type_name, IDLTypeInfo(idl_type_name)) |
OLD | NEW |