Chromium Code Reviews| 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 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 233 version[0] += 1 | 233 version[0] += 1 |
| 234 generate_call(stmts_emitter, call_emitter, | 234 generate_call(stmts_emitter, call_emitter, |
| 235 version[0], signature_index, argument_count) | 235 version[0], signature_index, argument_count) |
| 236 | 236 |
| 237 def GenerateChecksAndCall(signature_index, argument_count): | 237 def GenerateChecksAndCall(signature_index, argument_count): |
| 238 checks = [] | 238 checks = [] |
| 239 for i in range(0, argument_count): | 239 for i in range(0, argument_count): |
| 240 argument = signatures[signature_index][i] | 240 argument = signatures[signature_index][i] |
| 241 parameter_name = parameter_names[i] | 241 parameter_name = parameter_names[i] |
| 242 test_type = self._DartType(argument.type.id) | 242 test_type = self._DartType(argument.type.id) |
| 243 | |
| 243 if test_type in ['dynamic', 'Object']: | 244 if test_type in ['dynamic', 'Object']: |
| 244 checks.append('?%s' % parameter_name) | 245 checks.append('?%s' % parameter_name) |
| 245 elif not can_omit_type_check(test_type, i): | 246 elif not can_omit_type_check(test_type, i): |
| 246 checks.append('(%s is %s || %s == null)' % ( | 247 checks.append('(%s is %s || %s == null)' % ( |
| 247 parameter_name, test_type, parameter_name)) | 248 parameter_name, test_type, parameter_name)) |
| 249 | |
| 250 if can_omit_type_check(test_type, i): | |
|
Anton Muhin
2013/05/14 06:17:34
why if, looks like it should be rather else:, see
| |
| 251 for signature in signatures: | |
| 252 if argument not in signature: | |
|
Anton Muhin
2013/05/14 06:17:34
this check looks incorrect: you most probably want
Andrei Mouravski
2013/05/21 09:38:49
Done.
This check wasn't here before because... no
| |
| 253 checks.append('%s != null' % parameter_name) | |
| 254 break | |
| 255 | |
| 248 # There can be multiple presence checks. We need them all since a later | 256 # There can be multiple presence checks. We need them all since a later |
| 249 # optional argument could have been passed by name, leaving 'holes'. | 257 # optional argument could have been passed by name, leaving 'holes'. |
| 250 checks.extend(['!?%s' % name for name in parameter_names[argument_count:]] ) | 258 checks.extend(['!?%s' % name for name in parameter_names[argument_count:]] ) |
| 251 | 259 |
| 252 GenerateCall(signature_index, argument_count, checks) | 260 GenerateCall(signature_index, argument_count, checks) |
| 253 | 261 |
| 254 # TODO: Optimize the dispatch to avoid repeated checks. | 262 # TODO: Optimize the dispatch to avoid repeated checks. |
| 255 if len(signatures) > 1: | 263 if len(signatures) > 1: |
| 256 index_swaps = {} | 264 index_swaps = {} |
| 257 for signature_index, signature in enumerate(signatures): | 265 for signature_index, signature in enumerate(signatures): |
| (...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 580 if interface.parents: | 588 if interface.parents: |
| 581 parent = interface.parents[0] | 589 parent = interface.parents[0] |
| 582 if IsPureInterface(parent.type.id): | 590 if IsPureInterface(parent.type.id): |
| 583 walk(interface.parents) | 591 walk(interface.parents) |
| 584 else: | 592 else: |
| 585 walk(interface.parents[1:]) | 593 walk(interface.parents[1:]) |
| 586 return result | 594 return result |
| 587 | 595 |
| 588 def _DartType(self, type_name): | 596 def _DartType(self, type_name): |
| 589 return self._type_registry.DartType(type_name) | 597 return self._type_registry.DartType(type_name) |
| OLD | NEW |