| 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 copy | 9 import copy |
| 10 import re | 10 import re |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 for parent in interface.parents: | 84 for parent in interface.parents: |
| 85 if database.HasInterface(parent.type.id): | 85 if database.HasInterface(parent.type.id): |
| 86 parent_interface = database.GetInterface(parent.type.id) | 86 parent_interface = database.GetInterface(parent.type.id) |
| 87 (element_type, _) = ListImplementationInfo(parent_interface, database) | 87 (element_type, _) = ListImplementationInfo(parent_interface, database) |
| 88 if element_type: | 88 if element_type: |
| 89 return (element_type, False) | 89 return (element_type, False) |
| 90 | 90 |
| 91 return (None, None) | 91 return (None, None) |
| 92 | 92 |
| 93 | 93 |
| 94 def MaybeListElementTypeName(type_name): | |
| 95 """Returns the List element type T from string of form "List<T>", or None.""" | |
| 96 match = re.match(r'sequence<(\w*)>$', type_name) | |
| 97 if match: | |
| 98 return match.group(1) | |
| 99 return None | |
| 100 | |
| 101 def MaybeListElementType(interface): | 94 def MaybeListElementType(interface): |
| 102 """Returns the List element type T, or None in interface does not implement | 95 """Returns the List element type T, or None in interface does not implement |
| 103 List<T>. | 96 List<T>. |
| 104 """ | 97 """ |
| 105 for parent in interface.parents: | 98 for parent in interface.parents: |
| 106 element_type = MaybeListElementTypeName(parent.type.id) | 99 match = re.match(r'sequence<(\w*)>$', parent.type.id) |
| 107 if element_type: | 100 if match: |
| 108 return element_type | 101 return match.group(1) |
| 109 return None | 102 return None |
| 110 | 103 |
| 111 def MaybeTypedArrayElementType(interface): | 104 def MaybeTypedArrayElementType(interface): |
| 112 """Returns the typed array element type, or None in interface is not a | 105 """Returns the typed array element type, or None in interface is not a |
| 113 TypedArray. | 106 TypedArray. |
| 114 """ | 107 """ |
| 115 # Typed arrays implement ArrayBufferView and List<T>. | 108 # Typed arrays implement ArrayBufferView and List<T>. |
| 116 for parent in interface.parents: | 109 for parent in interface.parents: |
| 117 if parent.type.id == 'ArrayBufferView': | 110 if parent.type.id == 'ArrayBufferView': |
| 118 return MaybeListElementType(interface) | 111 return MaybeListElementType(interface) |
| (...skipping 749 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 868 if match: | 861 if match: |
| 869 if type_name == 'DOMString[]': | 862 if type_name == 'DOMString[]': |
| 870 return DOMStringArrayTypeInfo(TypeData('Sequence'), self.TypeInfo('DOMSt
ring')) | 863 return DOMStringArrayTypeInfo(TypeData('Sequence'), self.TypeInfo('DOMSt
ring')) |
| 871 item_info = self.TypeInfo(match.group(1) or match.group(2)) | 864 item_info = self.TypeInfo(match.group(1) or match.group(2)) |
| 872 return SequenceIDLTypeInfo(type_name, TypeData('Sequence'), item_info) | 865 return SequenceIDLTypeInfo(type_name, TypeData('Sequence'), item_info) |
| 873 if not type_name in _idl_type_registry: | 866 if not type_name in _idl_type_registry: |
| 874 return InterfaceIDLTypeInfo(type_name, TypeData('Interface')) | 867 return InterfaceIDLTypeInfo(type_name, TypeData('Interface')) |
| 875 type_data = _idl_type_registry.get(type_name) | 868 type_data = _idl_type_registry.get(type_name) |
| 876 class_name = '%sIDLTypeInfo' % type_data.clazz | 869 class_name = '%sIDLTypeInfo' % type_data.clazz |
| 877 return globals()[class_name](type_name, type_data) | 870 return globals()[class_name](type_name, type_data) |
| OLD | NEW |