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 |
| 11 # IDL->Dart primitive types conversion. | |
| 12 _idl_to_dart_type_conversions = { | |
| 13 'any': 'Object', | |
| 14 'any[]': 'List', | |
| 15 'custom': 'Dynamic', | |
| 16 'boolean': 'bool', | |
| 17 'DOMObject': 'Object', | |
| 18 'DOMString': 'String', | |
| 19 'DOMStringList': 'List<String>', | |
| 20 'DOMStringMap': 'Map<String, String>', | |
| 21 'DOMTimeStamp': 'int', | |
| 22 'Date': 'Date', | |
| 23 # Map to num to enable callers to pass in Dart int, rational | |
| 24 # types. Our implementations will need to convert these to | |
| 25 # doubles or floats as needed. | |
| 26 'double': 'num', | |
| 27 'float': 'num', | |
| 28 'int': 'int', | |
| 29 # Map to extra precision - int is a bignum in Dart. | |
| 30 'long': 'int', | |
| 31 'long long': 'int', | |
| 32 'object': 'Object', | |
| 33 # Map to extra precision - int is a bignum in Dart. | |
| 34 'short': 'int', | |
| 35 'string': 'String', | |
| 36 'void': 'void', | |
| 37 'Array': 'List', | |
| 38 'sequence': 'List', | |
| 39 # TODO(sra): Come up with some meaningful name so that where this appears in | |
| 40 # the documentation, the user is made aware that only a limited subset of | |
| 41 # serializable types are actually permitted. | |
| 42 'SerializedScriptValue': 'Dynamic', | |
| 43 # TODO(vsm): Automatically recognize types defined in src. | |
| 44 'TimeoutHandler': 'TimeoutHandler', | |
| 45 'RequestAnimationFrameCallback': 'RequestAnimationFrameCallback', | |
| 46 | |
| 47 # TODO(sra): Flags is really a dictionary: {create:bool, exclusive:bool} | |
| 48 # http://dev.w3.org/2009/dap/file-system/file-dir-sys.html#the-flags-interfa ce | |
| 49 'WebKitFlags': 'Object', | |
| 50 } | |
| 51 | |
| 52 _dart_to_idl_type_conversions = dict((v,k) for k, v in | |
| 53 _idl_to_dart_type_conversions.iteritems()) | |
| 54 | |
| 55 _pure_interfaces = set([ | 11 _pure_interfaces = set([ |
| 56 'ElementTimeControl', | 12 'ElementTimeControl', |
| 57 'ElementTraversal', | 13 'ElementTraversal', |
| 58 'MediaQueryListListener', | 14 'MediaQueryListListener', |
| 59 'NodeSelector', | 15 'NodeSelector', |
| 60 'SVGExternalResourcesRequired', | 16 'SVGExternalResourcesRequired', |
| 61 'SVGFilterPrimitiveStandardAttributes', | 17 'SVGFilterPrimitiveStandardAttributes', |
| 62 'SVGFitToViewBox', | 18 'SVGFitToViewBox', |
| 63 'SVGLangSpace', | 19 'SVGLangSpace', |
| 64 'SVGLocatable', | 20 'SVGLocatable', |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 156 dom_frog_native_bodies = { | 112 dom_frog_native_bodies = { |
| 157 # Some JavaScript processors, especially tools like yuicompress and | 113 # Some JavaScript processors, especially tools like yuicompress and |
| 158 # JSCompiler, choke on 'this.continue' | 114 # JSCompiler, choke on 'this.continue' |
| 159 'IDBCursor.continueFunction': | 115 'IDBCursor.continueFunction': |
| 160 """ | 116 """ |
| 161 if (key == null) return this['continue'](); | 117 if (key == null) return this['continue'](); |
| 162 return this['continue'](key); | 118 return this['continue'](key); |
| 163 """, | 119 """, |
| 164 } | 120 } |
| 165 | 121 |
| 166 | |
| 167 def ConvertPrimitiveType(type_name): | |
| 168 if type_name.startswith('unsigned '): | |
| 169 type_name = type_name[len('unsigned '):] | |
| 170 | |
| 171 if type_name in _idl_to_dart_type_conversions: | |
| 172 # Primitive type conversion | |
| 173 return _idl_to_dart_type_conversions[type_name] | |
| 174 return None | |
| 175 | |
| 176 def IsPrimitiveType(type_name): | 122 def IsPrimitiveType(type_name): |
| 177 return (ConvertPrimitiveType(type_name) is not None or | 123 return isinstance(GetIDLTypeInfo(type_name), PrimitiveIDLTypeInfo) |
| 178 type_name in _dart_to_idl_type_conversions) | |
| 179 | 124 |
| 180 def MaybeListElementTypeName(type_name): | 125 def MaybeListElementTypeName(type_name): |
| 181 """Returns the List element type T from string of form "List<T>", or None.""" | 126 """Returns the List element type T from string of form "List<T>", or None.""" |
| 182 match = re.match(r'sequence<(\w*)>$', type_name) | 127 match = re.match(r'sequence<(\w*)>$', type_name) |
| 183 if match: | 128 if match: |
| 184 return match.group(1) | 129 return match.group(1) |
| 185 return None | 130 return None |
| 186 | 131 |
| 187 def MaybeListElementType(interface): | 132 def MaybeListElementType(interface): |
| 188 """Returns the List element type T, or None in interface does not implement | 133 """Returns the List element type T, or None in interface does not implement |
| (...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 636 'any[]': PrimitiveIDLTypeInfo('any[]', dart_type='List'), | 581 'any[]': PrimitiveIDLTypeInfo('any[]', dart_type='List'), |
| 637 'Array': PrimitiveIDLTypeInfo('Array', dart_type='List'), | 582 'Array': PrimitiveIDLTypeInfo('Array', dart_type='List'), |
| 638 'custom': PrimitiveIDLTypeInfo('custom', dart_type='Dynamic'), | 583 'custom': PrimitiveIDLTypeInfo('custom', dart_type='Dynamic'), |
| 639 'Date': PrimitiveIDLTypeInfo('Date', dart_type='Date', native_type='double') , | 584 'Date': PrimitiveIDLTypeInfo('Date', dart_type='Date', native_type='double') , |
| 640 'DOMObject': PrimitiveIDLTypeInfo('DOMObject', dart_type='Object'), | 585 'DOMObject': PrimitiveIDLTypeInfo('DOMObject', dart_type='Object'), |
| 641 'DOMString': PrimitiveIDLTypeInfo('DOMString', dart_type='String', native_ty pe='String'), | 586 'DOMString': PrimitiveIDLTypeInfo('DOMString', dart_type='String', native_ty pe='String'), |
| 642 # TODO(sra): Flags is really a dictionary: {create:bool, exclusive:bool} | 587 # TODO(sra): Flags is really a dictionary: {create:bool, exclusive:bool} |
| 643 # http://dev.w3.org/2009/dap/file-system/file-dir-sys.html#the-flags-interfa ce | 588 # http://dev.w3.org/2009/dap/file-system/file-dir-sys.html#the-flags-interfa ce |
| 644 'Flags': PrimitiveIDLTypeInfo('Flags', dart_type='Object'), | 589 'Flags': PrimitiveIDLTypeInfo('Flags', dart_type='Object'), |
| 645 'List<String>': PrimitiveIDLTypeInfo('DOMStringList', dart_type='List<String >'), | 590 'List<String>': PrimitiveIDLTypeInfo('DOMStringList', dart_type='List<String >'), |
| 591 'Map<String, String>': PrimitiveIDLTypeInfo('DOMStringMap', dart_type='Map<S tring, String>'), | |
| 646 'DOMTimeStamp': PrimitiveIDLTypeInfo('DOMTimeStamp', dart_type='int'), | 592 'DOMTimeStamp': PrimitiveIDLTypeInfo('DOMTimeStamp', dart_type='int'), |
| 647 'object': PrimitiveIDLTypeInfo('object', dart_type='Object', native_type='Sc riptValue'), | 593 '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 | |
| 595 # the documentation, the user is made aware that only a limited subset of | |
| 596 # serializable types are actually permitted. | |
| 648 'SerializedScriptValue': PrimitiveIDLTypeInfo('SerializedScriptValue', dart_ type='Dynamic', ref_counted=True), | 597 'SerializedScriptValue': PrimitiveIDLTypeInfo('SerializedScriptValue', dart_ type='Dynamic', ref_counted=True), |
| 598 # 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 | |
| 649 'WebKitFlags': PrimitiveIDLTypeInfo('WebKitFlags', dart_type='Object'), | 600 'WebKitFlags': PrimitiveIDLTypeInfo('WebKitFlags', dart_type='Object'), |
| 650 | 601 |
| 602 'DOMStringList': PrimitiveIDLTypeInfo('DOMStringList', dart_type='List<Strin g>'), | |
| 603 'DOMStringMap': PrimitiveIDLTypeInfo('DOMStringMap', dart_type='Map<String, String>'), | |
|
Anton Muhin
2012/04/09 14:20:47
hmm, we have it for both DOMStringMap and Map<Stri
podivilov
2012/04/09 14:45:53
Please note that both are mapped to DOMStringMap.
| |
| 604 'sequence': PrimitiveIDLTypeInfo('sequence', dart_type='List'), | |
| 605 'void': PrimitiveIDLTypeInfo('void', dart_type='void'), | |
| 606 | |
| 651 'CSSRule': IDLTypeInfo('CSSRule', conversion_includes=['CSSImportRule']), | 607 'CSSRule': IDLTypeInfo('CSSRule', conversion_includes=['CSSImportRule']), |
| 652 'DOMException': IDLTypeInfo('DOMCoreException', dart_type='DOMException'), | 608 'DOMException': IDLTypeInfo('DOMCoreException', dart_type='DOMException'), |
| 653 'DOMWindow': IDLTypeInfo('DOMWindow', custom_to_dart=True), | 609 'DOMWindow': IDLTypeInfo('DOMWindow', custom_to_dart=True), |
| 654 'Element': IDLTypeInfo('Element', custom_to_dart=True), | 610 'Element': IDLTypeInfo('Element', custom_to_dart=True), |
| 655 'EventListener': IDLTypeInfo('EventListener', has_dart_wrapper=False), | 611 'EventListener': IDLTypeInfo('EventListener', has_dart_wrapper=False), |
| 656 'EventTarget': IDLTypeInfo('EventTarget', has_dart_wrapper=False), | 612 'EventTarget': IDLTypeInfo('EventTarget', has_dart_wrapper=False), |
| 657 'HTMLElement': IDLTypeInfo('HTMLElement', custom_to_dart=True), | 613 'HTMLElement': IDLTypeInfo('HTMLElement', custom_to_dart=True), |
| 658 'IDBKey': IDLTypeInfo('IDBKey', has_dart_wrapper=False), | 614 'IDBKey': IDLTypeInfo('IDBKey', has_dart_wrapper=False), |
| 659 'MediaQueryListListener': IDLTypeInfo('MediaQueryListListener', has_dart_wra pper=False), | 615 'MediaQueryListListener': IDLTypeInfo('MediaQueryListListener', has_dart_wra pper=False), |
| 660 'OptionsObject': IDLTypeInfo('OptionsObject', has_dart_wrapper=False), | 616 'OptionsObject': IDLTypeInfo('OptionsObject', has_dart_wrapper=False), |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 681 '"SVGAnimatedPropertyTearOff.h"', | 637 '"SVGAnimatedPropertyTearOff.h"', |
| 682 '"SVGAnimatedListPropertyTearOff.h"', | 638 '"SVGAnimatedListPropertyTearOff.h"', |
| 683 '"SVGStaticListPropertyTearOff.h"', | 639 '"SVGStaticListPropertyTearOff.h"', |
| 684 '"SVGAnimatedListPropertyTearOff.h"', | 640 '"SVGAnimatedListPropertyTearOff.h"', |
| 685 '"SVGTransformListPropertyTearOff.h"', | 641 '"SVGTransformListPropertyTearOff.h"', |
| 686 '"SVGPathSegListPropertyTearOff.h"', | 642 '"SVGPathSegListPropertyTearOff.h"', |
| 687 ] | 643 ] |
| 688 | 644 |
| 689 def GetIDLTypeInfo(idl_type_name): | 645 def GetIDLTypeInfo(idl_type_name): |
| 690 return _idl_type_registry.get(idl_type_name, IDLTypeInfo(idl_type_name)) | 646 return _idl_type_registry.get(idl_type_name, IDLTypeInfo(idl_type_name)) |
| OLD | NEW |