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 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 # FIXME: item should be renamed to operator[], not removed. | 186 # FIXME: item should be renamed to operator[], not removed. |
187 self.EmitOperation(info, '_item') | 187 self.EmitOperation(info, '_item') |
188 return | 188 return |
189 | 189 |
190 if declare_only: | 190 if declare_only: |
191 self.DeclareOperation(info, | 191 self.DeclareOperation(info, |
192 self.SecureOutputType(info.type_name), method_name) | 192 self.SecureOutputType(info.type_name), method_name) |
193 else: | 193 else: |
194 self.EmitOperation(info, method_name) | 194 self.EmitOperation(info, method_name) |
195 | 195 |
| 196 def _OverloadChecks(self, |
| 197 operation, |
| 198 parameter_names, |
| 199 argument_count, |
| 200 can_omit_type_check=lambda type, pos: False): |
| 201 checks = [] |
| 202 for i in range(0, argument_count): |
| 203 argument = operation.arguments[i] |
| 204 parameter_name = parameter_names[i] |
| 205 test_type = self._DartType(argument.type.id) |
| 206 if test_type in ['dynamic', 'Object']: |
| 207 checks.append('?%s' % parameter_name) |
| 208 elif not can_omit_type_check(test_type, i): |
| 209 checks.append('(%s is %s || %s == null)' % ( |
| 210 parameter_name, test_type, parameter_name)) |
| 211 # There can be multiple presence checks. We need them all since a later |
| 212 # optional argument could have been passed by name, leaving 'holes'. |
| 213 checks.extend(['!?%s' % name for name in parameter_names[argument_count:]]) |
| 214 return checks |
| 215 |
196 def AdditionalImplementedInterfaces(self): | 216 def AdditionalImplementedInterfaces(self): |
197 # TODO: Include all implemented interfaces, including other Lists. | 217 # TODO: Include all implemented interfaces, including other Lists. |
198 implements = [] | 218 implements = [] |
199 if self._interface_type_info.is_typed_array(): | 219 if self._interface_type_info.is_typed_array(): |
200 element_type = self._interface_type_info.list_item_type() | 220 element_type = self._interface_type_info.list_item_type() |
201 implements.append('List<%s>' % self._DartType(element_type)) | 221 implements.append('List<%s>' % self._DartType(element_type)) |
202 if self._interface_type_info.list_item_type(): | 222 if self._interface_type_info.list_item_type(): |
203 item_type_info = self._type_registry.TypeInfo( | 223 item_type_info = self._type_registry.TypeInfo( |
204 self._interface_type_info.list_item_type()) | 224 self._interface_type_info.list_item_type()) |
205 implements.append('List<%s>' % item_type_info.dart_type()) | 225 implements.append('List<%s>' % item_type_info.dart_type()) |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
419 walk(interface.parents) | 439 walk(interface.parents) |
420 else: | 440 else: |
421 walk(interface.parents[1:]) | 441 walk(interface.parents[1:]) |
422 return result | 442 return result |
423 | 443 |
424 def _DartType(self, type_name): | 444 def _DartType(self, type_name): |
425 return self._type_registry.DartType(type_name) | 445 return self._type_registry.DartType(type_name) |
426 | 446 |
427 def _IsPrivate(self, name): | 447 def _IsPrivate(self, name): |
428 return name.startswith('_') | 448 return name.startswith('_') |
OLD | NEW |