| 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 import emitter | 9 import emitter |
| 10 from generator import AnalyzeOperation, ConstantOutputOrder, \ | 10 from generator import AnalyzeOperation, ConstantOutputOrder, \ |
| (...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 checks.append('(%s is %s || %s == null)' % ( | 256 checks.append('(%s is %s || %s == null)' % ( |
| 257 parameter_name, test_type, parameter_name)) | 257 parameter_name, test_type, parameter_name)) |
| 258 # There can be multiple presence checks. We need them all since a later | 258 # There can be multiple presence checks. We need them all since a later |
| 259 # optional argument could have been passed by name, leaving 'holes'. | 259 # optional argument could have been passed by name, leaving 'holes'. |
| 260 checks.extend(['!?%s' % name for name in parameter_names[argument_count:]]
) | 260 checks.extend(['!?%s' % name for name in parameter_names[argument_count:]]
) |
| 261 | 261 |
| 262 GenerateCall(signature_index, argument_count, checks) | 262 GenerateCall(signature_index, argument_count, checks) |
| 263 | 263 |
| 264 # TODO: Optimize the dispatch to avoid repeated checks. | 264 # TODO: Optimize the dispatch to avoid repeated checks. |
| 265 if len(signatures) > 1: | 265 if len(signatures) > 1: |
| 266 swapped = False | 266 index_swaps = {} |
| 267 for signature_index, signature in enumerate(signatures): | 267 for signature_index, signature in enumerate(signatures): |
| 268 for argument_position, argument in enumerate(signature): | 268 for argument_position, argument in enumerate(signature): |
| 269 if argument.type.id != 'ArrayBuffer': | 269 if argument.type.id != 'ArrayBuffer': |
| 270 continue | 270 continue |
| 271 candidates = enumerate( | 271 candidates = enumerate( |
| 272 signatures[signature_index + 1:], signature_index + 1) | 272 signatures[signature_index + 1:], signature_index + 1) |
| 273 for candidate_index, candidate in candidates: | 273 for candidate_index, candidate in candidates: |
| 274 if len(candidate) <= argument_position: | 274 if len(candidate) <= argument_position: |
| 275 continue | 275 continue |
| 276 if candidate[argument_position].type.id != 'ArrayBufferView': | 276 if candidate[argument_position].type.id != 'ArrayBufferView': |
| 277 continue | 277 continue |
| 278 if swapped: | 278 if len(index_swaps): |
| 279 raise Exception('Cannot deal with more than a single swap') | 279 raise Exception('Cannot deal with more than a single swap') |
| 280 swapped = True | 280 index_swaps[candidate_index] = signature_index |
| 281 signatures = signatures[:] | 281 index_swaps[signature_index] = candidate_index |
| 282 signatures[candidate_index], signatures[signature_index] =\ | |
| 283 signature, candidate | |
| 284 | 282 |
| 285 for signature_index, signature in enumerate(signatures): | 283 for signature_index in range(len(signatures)): |
| 284 signature_index = index_swaps.get(signature_index, signature_index) |
| 285 signature = signatures[signature_index] |
| 286 for argument_position, argument in enumerate(signature): | 286 for argument_position, argument in enumerate(signature): |
| 287 if is_optional(signature_index, argument): | 287 if is_optional(signature_index, argument): |
| 288 GenerateChecksAndCall(signature_index, argument_position) | 288 GenerateChecksAndCall(signature_index, argument_position) |
| 289 GenerateChecksAndCall(signature_index, len(signature)) | 289 GenerateChecksAndCall(signature_index, len(signature)) |
| 290 body_emitter.Emit( | 290 body_emitter.Emit( |
| 291 ' throw new ArgumentError("Incorrect number or type of arguments");
' | 291 ' throw new ArgumentError("Incorrect number or type of arguments");
' |
| 292 '\n'); | 292 '\n'); |
| 293 else: | 293 else: |
| 294 signature = signatures[0] | 294 signature = signatures[0] |
| 295 argument_count = len(signature) | 295 argument_count = len(signature) |
| (...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 641 walk(interface.parents) | 641 walk(interface.parents) |
| 642 else: | 642 else: |
| 643 walk(interface.parents[1:]) | 643 walk(interface.parents[1:]) |
| 644 return result | 644 return result |
| 645 | 645 |
| 646 def _DartType(self, type_name): | 646 def _DartType(self, type_name): |
| 647 return self._type_registry.DartType(type_name) | 647 return self._type_registry.DartType(type_name) |
| 648 | 648 |
| 649 def _IsPrivate(self, name): | 649 def _IsPrivate(self, name): |
| 650 return name.startswith('_') | 650 return name.startswith('_') |
| OLD | NEW |