Chromium Code Reviews| 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 459 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 470 include = self._idl_type.replace('Abs', '').replace('Rel', '') | 470 include = self._idl_type.replace('Abs', '').replace('Rel', '') |
| 471 else: | 471 else: |
| 472 include = self._idl_type | 472 include = self._idl_type |
| 473 return ['"%s.h"' % include] + _svg_supplemental_includes | 473 return ['"%s.h"' % include] + _svg_supplemental_includes |
| 474 | 474 |
| 475 def receiver(self): | 475 def receiver(self): |
| 476 return 'receiver->' | 476 return 'receiver->' |
| 477 | 477 |
| 478 def conversion_includes(self): | 478 def conversion_includes(self): |
| 479 def NeededDartTypes(type_name): | 479 def NeededDartTypes(type_name): |
| 480 if type_name == 'Map<String, String>': | |
| 481 return ['DOMStringMap'] | |
| 482 match = re.match(r'List<(\w*)>$', type_name) | 480 match = re.match(r'List<(\w*)>$', type_name) |
| 483 if match: | 481 if match: |
| 484 return NeededDartTypes(match.group(1)) | 482 return NeededDartTypes(match.group(1)) |
| 485 match = re.match(r'Map<(\w*), (\w*)>$', type_name) | |
|
Anton Muhin
2012/04/11 12:41:28
why this is removed? and if you remove it, there
podivilov
2012/04/11 13:17:24
There is no such idl type as Map<String, String>.
| |
| 486 if match: | |
| 487 return NeededDartTypes(match.group(1)) + NeededDartTypes(match.group(2)) | |
| 488 if IsPrimitiveType(type_name): | |
| 489 return [] | |
| 490 return [type_name] | 483 return [type_name] |
| 491 | 484 |
| 492 return ['"Dart%s.h"' % include for include in NeededDartTypes(self.dart_type ()) + self._conversion_includes] | 485 return ['"Dart%s.h"' % include for include in NeededDartTypes(self.dart_type ()) + self._conversion_includes] |
| 493 | 486 |
| 494 def conversion_cast(self, expression): | 487 def conversion_cast(self, expression): |
| 495 if self._conversion_template: | 488 if self._conversion_template: |
| 496 return self._conversion_template % expression | 489 return self._conversion_template % expression |
| 497 return expression | 490 return expression |
| 498 | 491 |
| 499 def custom_to_dart(self): | 492 def custom_to_dart(self): |
| 500 return self._custom_to_dart | 493 return self._custom_to_dart |
| 501 | 494 |
| 502 class PrimitiveIDLTypeInfo(IDLTypeInfo): | 495 class PrimitiveIDLTypeInfo(IDLTypeInfo): |
| 503 def __init__(self, idl_type, dart_type, native_type=None, ref_counted=False, | 496 def __init__(self, idl_type, dart_type, native_type=None, ref_counted=False, |
| 504 conversion_template=None, | 497 conversion_template=None, conversion_includes=[], |
| 505 webcore_getter_name='getAttribute', | 498 webcore_getter_name='getAttribute', |
| 506 webcore_setter_name='setAttribute'): | 499 webcore_setter_name='setAttribute'): |
| 507 super(PrimitiveIDLTypeInfo, self).__init__(idl_type, dart_type=dart_type, | 500 super(PrimitiveIDLTypeInfo, self).__init__(idl_type, dart_type=dart_type, |
| 508 native_type=native_type, ref_counted=ref_counted, | 501 native_type=native_type, ref_counted=ref_counted, |
| 509 conversion_template=conversion_template) | 502 conversion_template=conversion_template, |
| 503 conversion_includes=conversion_includes) | |
| 510 self._webcore_getter_name = webcore_getter_name | 504 self._webcore_getter_name = webcore_getter_name |
| 511 self._webcore_setter_name = webcore_setter_name | 505 self._webcore_setter_name = webcore_setter_name |
| 512 | 506 |
| 513 def parameter_adapter_info(self): | 507 def parameter_adapter_info(self): |
| 514 native_type = self.native_type() | 508 native_type = self.native_type() |
| 515 if self._ref_counted: | 509 if self._ref_counted: |
| 516 native_type = 'RefPtr< %s >' % native_type | 510 native_type = 'RefPtr< %s >' % native_type |
| 517 return ('ParameterAdapter< %s >' % native_type, None) | 511 return ('ParameterAdapter< %s >' % native_type, None) |
| 518 | 512 |
| 519 def parameter_type(self): | 513 def parameter_type(self): |
| 520 if self.native_type() == 'String': | 514 if self.native_type() == 'String': |
| 521 return 'const String&' | 515 return 'const String&' |
| 522 return self.native_type() | 516 return self.native_type() |
| 523 | 517 |
| 524 def conversion_includes(self): | 518 def conversion_includes(self): |
| 525 return [] | 519 return ['"Dart%s.h"' % include for include in self._conversion_includes] |
| 526 | 520 |
| 527 def webcore_getter_name(self): | 521 def webcore_getter_name(self): |
| 528 return self._webcore_getter_name | 522 return self._webcore_getter_name |
| 529 | 523 |
| 530 def webcore_setter_name(self): | 524 def webcore_setter_name(self): |
| 531 return self._webcore_setter_name | 525 return self._webcore_setter_name |
| 532 | 526 |
| 533 class SVGTearOffIDLTypeInfo(IDLTypeInfo): | 527 class SVGTearOffIDLTypeInfo(IDLTypeInfo): |
| 534 def __init__(self, idl_type, native_type='', ref_counted=True): | 528 def __init__(self, idl_type, native_type='', ref_counted=True): |
| 535 super(SVGTearOffIDLTypeInfo, self).__init__(idl_type, | 529 super(SVGTearOffIDLTypeInfo, self).__init__(idl_type, |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 581 'any[]': PrimitiveIDLTypeInfo('any[]', dart_type='List'), | 575 'any[]': PrimitiveIDLTypeInfo('any[]', dart_type='List'), |
| 582 'Array': PrimitiveIDLTypeInfo('Array', dart_type='List'), | 576 'Array': PrimitiveIDLTypeInfo('Array', dart_type='List'), |
| 583 'custom': PrimitiveIDLTypeInfo('custom', dart_type='Dynamic'), | 577 'custom': PrimitiveIDLTypeInfo('custom', dart_type='Dynamic'), |
| 584 'Date': PrimitiveIDLTypeInfo('Date', dart_type='Date', native_type='double') , | 578 'Date': PrimitiveIDLTypeInfo('Date', dart_type='Date', native_type='double') , |
| 585 'DOMObject': PrimitiveIDLTypeInfo('DOMObject', dart_type='Object'), | 579 'DOMObject': PrimitiveIDLTypeInfo('DOMObject', dart_type='Object'), |
| 586 'DOMString': PrimitiveIDLTypeInfo('DOMString', dart_type='String', native_ty pe='String'), | 580 'DOMString': PrimitiveIDLTypeInfo('DOMString', dart_type='String', native_ty pe='String'), |
| 587 # TODO(sra): Flags is really a dictionary: {create:bool, exclusive:bool} | 581 # TODO(sra): Flags is really a dictionary: {create:bool, exclusive:bool} |
| 588 # http://dev.w3.org/2009/dap/file-system/file-dir-sys.html#the-flags-interfa ce | 582 # http://dev.w3.org/2009/dap/file-system/file-dir-sys.html#the-flags-interfa ce |
| 589 'Flags': PrimitiveIDLTypeInfo('Flags', dart_type='Object'), | 583 'Flags': PrimitiveIDLTypeInfo('Flags', dart_type='Object'), |
| 590 'List<String>': PrimitiveIDLTypeInfo('DOMStringList', dart_type='List<String >'), | 584 'List<String>': PrimitiveIDLTypeInfo('DOMStringList', dart_type='List<String >'), |
| 591 'Map<String, String>': PrimitiveIDLTypeInfo('DOMStringMap', dart_type='Map<S tring, String>'), | 585 'Map<String, String>': PrimitiveIDLTypeInfo('DOMStringMap', dart_type='Map<S tring, String>', |
| 586 conversion_includes=['DOMStringMap']), | |
| 592 'DOMTimeStamp': PrimitiveIDLTypeInfo('DOMTimeStamp', dart_type='int'), | 587 'DOMTimeStamp': PrimitiveIDLTypeInfo('DOMTimeStamp', dart_type='int'), |
| 593 'object': PrimitiveIDLTypeInfo('object', dart_type='Object', native_type='Sc riptValue'), | 588 'object': PrimitiveIDLTypeInfo('object', dart_type='Object', native_type='Sc riptValue'), |
| 594 # TODO(sra): Come up with some meaningful name so that where this appears in | 589 # TODO(sra): Come up with some meaningful name so that where this appears in |
| 595 # the documentation, the user is made aware that only a limited subset of | 590 # the documentation, the user is made aware that only a limited subset of |
| 596 # serializable types are actually permitted. | 591 # serializable types are actually permitted. |
| 597 'SerializedScriptValue': PrimitiveIDLTypeInfo('SerializedScriptValue', dart_ type='Dynamic', ref_counted=True), | 592 'SerializedScriptValue': PrimitiveIDLTypeInfo('SerializedScriptValue', dart_ type='Dynamic', ref_counted=True), |
| 598 # TODO(sra): Flags is really a dictionary: {create:bool, exclusive:bool} | 593 # TODO(sra): Flags is really a dictionary: {create:bool, exclusive:bool} |
| 599 # http://dev.w3.org/2009/dap/file-system/file-dir-sys.html#the-flags-interfa ce | 594 # http://dev.w3.org/2009/dap/file-system/file-dir-sys.html#the-flags-interfa ce |
| 600 'WebKitFlags': PrimitiveIDLTypeInfo('WebKitFlags', dart_type='Object'), | 595 'WebKitFlags': PrimitiveIDLTypeInfo('WebKitFlags', dart_type='Object'), |
| 601 | 596 |
| 602 'DOMStringList': PrimitiveIDLTypeInfo('DOMStringList', dart_type='List<Strin g>'), | 597 'DOMStringList': PrimitiveIDLTypeInfo('DOMStringList', dart_type='List<Strin g>'), |
| 603 'DOMStringMap': PrimitiveIDLTypeInfo('DOMStringMap', dart_type='Map<String, String>'), | 598 'DOMStringMap': PrimitiveIDLTypeInfo('DOMStringMap', dart_type='Map<String, String>', |
| 599 conversion_includes=['DOMStringMap']), | |
| 604 'sequence': PrimitiveIDLTypeInfo('sequence', dart_type='List'), | 600 'sequence': PrimitiveIDLTypeInfo('sequence', dart_type='List'), |
| 605 'void': PrimitiveIDLTypeInfo('void', dart_type='void'), | 601 'void': PrimitiveIDLTypeInfo('void', dart_type='void'), |
| 606 | 602 |
| 607 'CSSRule': IDLTypeInfo('CSSRule', conversion_includes=['CSSImportRule']), | 603 'CSSRule': IDLTypeInfo('CSSRule', conversion_includes=['CSSImportRule']), |
| 608 'DOMException': IDLTypeInfo('DOMCoreException', dart_type='DOMException'), | 604 'DOMException': IDLTypeInfo('DOMCoreException', dart_type='DOMException'), |
| 609 'DOMWindow': IDLTypeInfo('DOMWindow', custom_to_dart=True), | 605 'DOMWindow': IDLTypeInfo('DOMWindow', custom_to_dart=True), |
| 610 'Element': IDLTypeInfo('Element', custom_to_dart=True), | 606 'Element': IDLTypeInfo('Element', custom_to_dart=True), |
| 611 'EventListener': IDLTypeInfo('EventListener', has_dart_wrapper=False), | 607 'EventListener': IDLTypeInfo('EventListener', has_dart_wrapper=False), |
| 612 'EventTarget': IDLTypeInfo('EventTarget', has_dart_wrapper=False), | 608 'EventTarget': IDLTypeInfo('EventTarget', has_dart_wrapper=False), |
| 613 'HTMLElement': IDLTypeInfo('HTMLElement', custom_to_dart=True), | 609 'HTMLElement': IDLTypeInfo('HTMLElement', custom_to_dart=True), |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 637 '"SVGAnimatedPropertyTearOff.h"', | 633 '"SVGAnimatedPropertyTearOff.h"', |
| 638 '"SVGAnimatedListPropertyTearOff.h"', | 634 '"SVGAnimatedListPropertyTearOff.h"', |
| 639 '"SVGStaticListPropertyTearOff.h"', | 635 '"SVGStaticListPropertyTearOff.h"', |
| 640 '"SVGAnimatedListPropertyTearOff.h"', | 636 '"SVGAnimatedListPropertyTearOff.h"', |
| 641 '"SVGTransformListPropertyTearOff.h"', | 637 '"SVGTransformListPropertyTearOff.h"', |
| 642 '"SVGPathSegListPropertyTearOff.h"', | 638 '"SVGPathSegListPropertyTearOff.h"', |
| 643 ] | 639 ] |
| 644 | 640 |
| 645 def GetIDLTypeInfo(idl_type_name): | 641 def GetIDLTypeInfo(idl_type_name): |
| 646 return _idl_type_registry.get(idl_type_name, IDLTypeInfo(idl_type_name)) | 642 return _idl_type_registry.get(idl_type_name, IDLTypeInfo(idl_type_name)) |
| OLD | NEW |