| 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 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 else: | 134 else: |
| 135 # Make the class 'hidden' so it is dynamically patched at runtime. This | 135 # Make the class 'hidden' so it is dynamically patched at runtime. This |
| 136 # is useful for browser compat. | 136 # is useful for browser compat. |
| 137 return '*' + javascript_binding_name | 137 return '*' + javascript_binding_name |
| 138 | 138 |
| 139 | 139 |
| 140 def MatchSourceFilter(thing): | 140 def MatchSourceFilter(thing): |
| 141 return 'WebKit' in thing.annotations or 'Dart' in thing.annotations | 141 return 'WebKit' in thing.annotations or 'Dart' in thing.annotations |
| 142 | 142 |
| 143 | 143 |
| 144 def DartType(idl_type_name): | |
| 145 if idl_type_name in _idl_type_registry: | |
| 146 return _idl_type_registry[idl_type_name].dart_type or idl_type_name | |
| 147 return idl_type_name | |
| 148 | |
| 149 | |
| 150 class ParamInfo(object): | 144 class ParamInfo(object): |
| 151 """Holder for various information about a parameter of a Dart operation. | 145 """Holder for various information about a parameter of a Dart operation. |
| 152 | 146 |
| 153 Attributes: | 147 Attributes: |
| 154 name: Name of parameter. | 148 name: Name of parameter. |
| 155 type_id: Original type id. None for merged types. | 149 type_id: Original type id. None for merged types. |
| 156 dart_type: DartType of parameter. | 150 dart_type: DartType of parameter. |
| 157 is_optional: Parameter optionality. | 151 is_optional: Parameter optionality. |
| 158 """ | 152 """ |
| 159 def __init__(self, name, type_id, dart_type, is_optional): | 153 def __init__(self, name, type_id, dart_type, is_optional): |
| (...skipping 20 matching lines...) Expand all Loading... |
| 180 if constructor: | 174 if constructor: |
| 181 # FIXME: Constructors with 'Optional=XXX' shouldn't be treated as | 175 # FIXME: Constructors with 'Optional=XXX' shouldn't be treated as |
| 182 # optional arguments. | 176 # optional arguments. |
| 183 return 'Optional' in argument.ext_attrs | 177 return 'Optional' in argument.ext_attrs |
| 184 return False | 178 return False |
| 185 | 179 |
| 186 # Given a list of overloaded arguments, choose a suitable name. | 180 # Given a list of overloaded arguments, choose a suitable name. |
| 187 def OverloadedName(args): | 181 def OverloadedName(args): |
| 188 return '_OR_'.join(sorted(set(arg.id for arg in args))) | 182 return '_OR_'.join(sorted(set(arg.id for arg in args))) |
| 189 | 183 |
| 184 def DartType(idl_type_name): |
| 185 if idl_type_name in _idl_type_registry: |
| 186 return _idl_type_registry[idl_type_name].dart_type or idl_type_name |
| 187 return idl_type_name |
| 188 |
| 190 # Given a list of overloaded arguments, choose a suitable type. | 189 # Given a list of overloaded arguments, choose a suitable type. |
| 191 def OverloadedType(args): | 190 def OverloadedType(args): |
| 192 type_ids = sorted(set(arg.type.id for arg in args)) | 191 type_ids = sorted(set(arg.type.id for arg in args)) |
| 193 dart_types = sorted(set(DartType(arg.type.id) for arg in args)) | 192 if len(set(DartType(arg.type.id) for arg in args)) == 1: |
| 194 if len(dart_types) == 1: | |
| 195 if len(type_ids) == 1: | 193 if len(type_ids) == 1: |
| 196 return (type_ids[0], type_ids[0]) | 194 return (type_ids[0], type_ids[0]) |
| 197 else: | 195 else: |
| 198 return (None, type_ids[0]) | 196 return (None, type_ids[0]) |
| 199 else: | 197 else: |
| 200 return (None, TypeName(type_ids, interface)) | 198 return (None, TypeName(type_ids, interface)) |
| 201 | 199 |
| 202 result = [] | 200 result = [] |
| 203 | 201 |
| 204 is_optional = False | 202 is_optional = False |
| (...skipping 779 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 984 if match: | 982 if match: |
| 985 if type_name == 'DOMString[]': | 983 if type_name == 'DOMString[]': |
| 986 return DOMStringArrayTypeInfo(TypeData('Sequence'), self.TypeInfo('DOMSt
ring')) | 984 return DOMStringArrayTypeInfo(TypeData('Sequence'), self.TypeInfo('DOMSt
ring')) |
| 987 item_info = self.TypeInfo(match.group(1) or match.group(2)) | 985 item_info = self.TypeInfo(match.group(1) or match.group(2)) |
| 988 return SequenceIDLTypeInfo(type_name, TypeData('Sequence'), item_info) | 986 return SequenceIDLTypeInfo(type_name, TypeData('Sequence'), item_info) |
| 989 if not type_name in _idl_type_registry: | 987 if not type_name in _idl_type_registry: |
| 990 return InterfaceIDLTypeInfo(type_name, TypeData('Interface')) | 988 return InterfaceIDLTypeInfo(type_name, TypeData('Interface')) |
| 991 type_data = _idl_type_registry.get(type_name) | 989 type_data = _idl_type_registry.get(type_name) |
| 992 class_name = '%sIDLTypeInfo' % type_data.clazz | 990 class_name = '%sIDLTypeInfo' % type_data.clazz |
| 993 return globals()[class_name](type_name, type_data) | 991 return globals()[class_name](type_name, type_data) |
| OLD | NEW |