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 the system to generate | 6 """This module provides shared functionality for the system to generate |
7 dart:html APIs from the IDL database.""" | 7 dart:html APIs from the IDL database.""" |
8 | 8 |
9 from generator import AnalyzeOperation, ConstantOutputOrder, \ | 9 from generator import AnalyzeOperation, ConstantOutputOrder, \ |
10 DartDomNameOfAttribute, FindMatchingAttribute, IsDartCollectionType, \ | 10 DartDomNameOfAttribute, FindMatchingAttribute, IsDartCollectionType, \ |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 # FIXME: item should be renamed to operator[], not removed. | 175 # FIXME: item should be renamed to operator[], not removed. |
176 self.EmitOperation(info, '_item') | 176 self.EmitOperation(info, '_item') |
177 return | 177 return |
178 | 178 |
179 if declare_only: | 179 if declare_only: |
180 self.DeclareOperation(info, | 180 self.DeclareOperation(info, |
181 self.SecureOutputType(info.type_name), method_name) | 181 self.SecureOutputType(info.type_name), method_name) |
182 else: | 182 else: |
183 self.EmitOperation(info, method_name) | 183 self.EmitOperation(info, method_name) |
184 | 184 |
| 185 def _OverloadChecks(self, |
| 186 operation, |
| 187 parameter_names, |
| 188 argument_count, |
| 189 can_omit_type_check=lambda type, pos: False): |
| 190 checks = [] |
| 191 for i in range(0, argument_count): |
| 192 argument = operation.arguments[i] |
| 193 parameter_name = parameter_names[i] |
| 194 test_type = self._DartType(argument.type.id) |
| 195 if test_type in ['dynamic', 'Object']: |
| 196 checks.append('?%s' % parameter_name) |
| 197 elif not can_omit_type_check(test_type, i): |
| 198 checks.append('(%s is %s || %s == null)' % ( |
| 199 parameter_name, test_type, parameter_name)) |
| 200 # There can be multiple presence checks. We need them all since a later |
| 201 # optional argument could have been passed by name, leaving 'holes'. |
| 202 checks.extend(['!?%s' % name for name in parameter_names[argument_count:]]) |
| 203 return checks |
| 204 |
185 def AdditionalImplementedInterfaces(self): | 205 def AdditionalImplementedInterfaces(self): |
186 # TODO: Include all implemented interfaces, including other Lists. | 206 # TODO: Include all implemented interfaces, including other Lists. |
187 implements = [] | 207 implements = [] |
188 if self._interface_type_info.is_typed_array(): | 208 if self._interface_type_info.is_typed_array(): |
189 element_type = self._interface_type_info.list_item_type() | 209 element_type = self._interface_type_info.list_item_type() |
190 implements.append('List<%s>' % self._DartType(element_type)) | 210 implements.append('List<%s>' % self._DartType(element_type)) |
191 if self._interface_type_info.list_item_type(): | 211 if self._interface_type_info.list_item_type(): |
192 item_type_info = self._type_registry.TypeInfo( | 212 item_type_info = self._type_registry.TypeInfo( |
193 self._interface_type_info.list_item_type()) | 213 self._interface_type_info.list_item_type()) |
194 implements.append('List<%s>' % item_type_info.dart_type()) | 214 implements.append('List<%s>' % item_type_info.dart_type()) |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
351 walk(interface.parents) | 371 walk(interface.parents) |
352 else: | 372 else: |
353 walk(interface.parents[1:]) | 373 walk(interface.parents[1:]) |
354 return result | 374 return result |
355 | 375 |
356 def _DartType(self, type_name): | 376 def _DartType(self, type_name): |
357 return self._type_registry.DartType(type_name) | 377 return self._type_registry.DartType(type_name) |
358 | 378 |
359 def _IsPrivate(self, name): | 379 def _IsPrivate(self, name): |
360 return name.startswith('_') | 380 return name.startswith('_') |
OLD | NEW |