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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 78 'IDBCursor.continueFunction': | 78 'IDBCursor.continueFunction': |
| 79 """ | 79 """ |
| 80 if (key == null) return this['continue'](); | 80 if (key == null) return this['continue'](); |
| 81 return this['continue'](key); | 81 return this['continue'](key); |
| 82 """, | 82 """, |
| 83 } | 83 } |
| 84 | 84 |
| 85 def IsPrimitiveType(type_name): | 85 def IsPrimitiveType(type_name): |
| 86 return isinstance(GetIDLTypeInfo(type_name), PrimitiveIDLTypeInfo) | 86 return isinstance(GetIDLTypeInfo(type_name), PrimitiveIDLTypeInfo) |
| 87 | 87 |
| 88 def ListImplementationInfo(interface, database): | |
| 89 """Returns a tuple (elment_type, requires_indexer). | |
| 90 If interface do not have to implement List, element_type is None. | |
| 91 Otherwise element_type is list element type and requires_indexer | |
| 92 is true iff this interface implementation must have indexer and | |
| 93 false otherwise. False means that interface implementation | |
| 94 inherits indexer and may just reuse it.""" | |
|
podivilov
2012/05/12 08:35:10
Maybe mention that it is needed to override indexe
Anton Muhin
2012/05/12 08:37:03
Not sure, let's keep it generic: I don't think tha
podivilov
2012/05/12 08:39:06
I just think that a note about why it is __really_
| |
| 95 element_type = MaybeListElementType(interface) | |
| 96 if element_type: | |
| 97 return (element_type, True) | |
| 98 | |
| 99 for parent in interface.parents: | |
| 100 if database.HasInterface(parent.type.id): | |
| 101 parent_interface = database.GetInterface(parent.type.id) | |
| 102 (element_type, _) = ListImplementationInfo(parent_interface, database) | |
| 103 if element_type: | |
| 104 return (element_type, False) | |
| 105 | |
| 106 return (None, None) | |
| 107 | |
| 108 | |
| 88 def MaybeListElementTypeName(type_name): | 109 def MaybeListElementTypeName(type_name): |
| 89 """Returns the List element type T from string of form "List<T>", or None.""" | 110 """Returns the List element type T from string of form "List<T>", or None.""" |
| 90 match = re.match(r'sequence<(\w*)>$', type_name) | 111 match = re.match(r'sequence<(\w*)>$', type_name) |
| 91 if match: | 112 if match: |
| 92 return match.group(1) | 113 return match.group(1) |
| 93 return None | 114 return None |
| 94 | 115 |
| 95 def MaybeListElementType(interface): | 116 def MaybeListElementType(interface): |
| 96 """Returns the List element type T, or None in interface does not implement | 117 """Returns the List element type T, or None in interface does not implement |
| 97 List<T>. | 118 List<T>. |
| 98 """ | 119 """ |
| 99 for parent in interface.parents: | 120 for parent in interface.parents: |
| 100 element_type = MaybeListElementTypeName(parent.type.id) | 121 element_type = MaybeListElementTypeName(parent.type.id) |
| 101 if element_type: | 122 if element_type: |
| 102 return element_type | 123 return element_type |
| 103 return None | 124 return None |
| 104 | 125 |
| 105 def MaybeTypedArrayElementType(interface): | 126 def MaybeTypedArrayElementType(interface): |
| 106 """Returns the typed array element type, or None in interface is not a | 127 """Returns the typed array element type, or None in interface is not a |
| 107 TypedArray. | 128 TypedArray. |
| 108 """ | 129 """ |
| 109 # Typed arrays implement ArrayBufferView and List<T>. | 130 # Typed arrays implement ArrayBufferView and List<T>. |
| 110 for parent in interface.parents: | 131 for parent in interface.parents: |
| 111 if parent.type.id == 'ArrayBufferView': | 132 if parent.type.id == 'ArrayBufferView': |
| 112 return MaybeListElementType(interface) | 133 return MaybeListElementType(interface) |
| 113 return None | 134 return None |
| 114 | 135 |
| 136 def MaybeTypedArrayElementTypeInHierarchy(interface, database): | |
| 137 """Returns the typed array element type, or None in interface is not a | |
| 138 TypedArray. Checks the whole parent hierarchy. | |
| 139 """ | |
| 140 element_type = MaybeTypedArrayElementType(interface) | |
| 141 if element_type: | |
| 142 return element_type | |
| 143 for parent in interface.parents: | |
| 144 if database.HasInterface(parent.type.id): | |
| 145 parent_interface = database.GetInterface(parent.type.id) | |
| 146 element_type = MaybeTypedArrayElementType(parent_interface) | |
| 147 if element_type: | |
| 148 return element_type | |
| 149 | |
| 150 return None | |
| 151 | |
| 115 def MakeNativeSpec(javascript_binding_name): | 152 def MakeNativeSpec(javascript_binding_name): |
| 116 if javascript_binding_name in _frog_dom_custom_native_specs: | 153 if javascript_binding_name in _frog_dom_custom_native_specs: |
| 117 return _frog_dom_custom_native_specs[javascript_binding_name] | 154 return _frog_dom_custom_native_specs[javascript_binding_name] |
| 118 else: | 155 else: |
| 119 # Make the class 'hidden' so it is dynamically patched at runtime. This | 156 # Make the class 'hidden' so it is dynamically patched at runtime. This |
| 120 # is useful not only for browser compat, but to allow code that links | 157 # is useful not only for browser compat, but to allow code that links |
| 121 # against dart:dom to load in a worker isolate. | 158 # against dart:dom to load in a worker isolate. |
| 122 return '*' + javascript_binding_name | 159 return '*' + javascript_binding_name |
| 123 | 160 |
| 124 | 161 |
| (...skipping 594 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 719 '"SVGAnimatedListPropertyTearOff.h"', | 756 '"SVGAnimatedListPropertyTearOff.h"', |
| 720 '"SVGTransformListPropertyTearOff.h"', | 757 '"SVGTransformListPropertyTearOff.h"', |
| 721 '"SVGPathSegListPropertyTearOff.h"', | 758 '"SVGPathSegListPropertyTearOff.h"', |
| 722 ] | 759 ] |
| 723 | 760 |
| 724 def GetIDLTypeInfo(idl_type_name): | 761 def GetIDLTypeInfo(idl_type_name): |
| 725 match = re.match(r'sequence<(\w+)>$', idl_type_name) | 762 match = re.match(r'sequence<(\w+)>$', idl_type_name) |
| 726 if match: | 763 if match: |
| 727 return SequenceIDLTypeInfo(idl_type_name, GetIDLTypeInfo(match.group(1))) | 764 return SequenceIDLTypeInfo(idl_type_name, GetIDLTypeInfo(match.group(1))) |
| 728 return _idl_type_registry.get(idl_type_name, IDLTypeInfo(idl_type_name)) | 765 return _idl_type_registry.get(idl_type_name, IDLTypeInfo(idl_type_name)) |
| OLD | NEW |