| 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 systems to generate | 6 """This module provides shared functionality for the systems to generate |
| 7 wrapping binding from the IDL database.""" | 7 wrapping binding from the IDL database.""" |
| 8 | 8 |
| 9 import os | 9 import os |
| 10 from generator import * | 10 from generator import * |
| (...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 447 if len(overloads) > 1: | 447 if len(overloads) > 1: |
| 448 raise Exception('Duplicate operations ' + str(overloads)) | 448 raise Exception('Duplicate operations ' + str(overloads)) |
| 449 operation = overloads[0] | 449 operation = overloads[0] |
| 450 self.GenerateSingleOperation(emitter, info, indent, operation) | 450 self.GenerateSingleOperation(emitter, info, indent, operation) |
| 451 return False | 451 return False |
| 452 | 452 |
| 453 # FIXME: Consider a simpler dispatch that iterates over the | 453 # FIXME: Consider a simpler dispatch that iterates over the |
| 454 # overloads and generates an overload specific check. Revisit | 454 # overloads and generates an overload specific check. Revisit |
| 455 # when we move to named optional arguments. | 455 # when we move to named optional arguments. |
| 456 | 456 |
| 457 if position == 0: |
| 458 # Optional callback arguments are special. C++ counterparts do not have p
roper optional |
| 459 # arguments (as in some cases C++ counterparts require ec) and thus 0 ref
ptrs are passed |
| 460 # instead of missing arguments. That means the only allowed form is a lis
t of |
| 461 # arguments with trailing optional callbacks and we don't need any dispatc
h at all. |
| 462 def IsOptionalCallback(arg): return arg.is_optional and 'Callback' in arg.
ext_attrs |
| 463 first_optional_callback = None |
| 464 for (i, arg) in enumerate(overloads[-1].arguments): |
| 465 if IsOptionalCallback(arg): |
| 466 first_optional_callback = i |
| 467 break |
| 468 if first_optional_callback is not None: |
| 469 for overload in overloads: |
| 470 for arg in overload.arguments[first_optional_callback:]: |
| 471 if not IsOptionalCallback(arg): |
| 472 raise Exception('Invalid overloading with optional callbacks') |
| 473 self.GenerateSingleOperation(emitter, info, indent, overloads[-1]) |
| 474 return False |
| 475 |
| 457 # Partition the overloads to divide and conquer on the dispatch. | 476 # Partition the overloads to divide and conquer on the dispatch. |
| 458 positive = [] | 477 positive = [] |
| 459 negative = [] | 478 negative = [] |
| 460 first_overload = overloads[0] | 479 first_overload = overloads[0] |
| 461 (param_name, param_type, param_default) = info.arg_infos[position] | 480 (param_name, param_type, param_default) = info.arg_infos[position] |
| 462 | 481 |
| 463 if position < len(first_overload.arguments): | 482 if position < len(first_overload.arguments): |
| 464 # FIXME: This will not work if the second overload has a more | 483 # FIXME: This will not work if the second overload has a more |
| 465 # precise type than the first. E.g., | 484 # precise type than the first. E.g., |
| 466 # void foo(Node x); | 485 # void foo(Node x); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 512 # dispatch has removed f(X), leaving only f(Y), but there is no guarantee | 531 # dispatch has removed f(X), leaving only f(Y), but there is no guarantee |
| 513 # that Y = Z-X, so we need to check for Y. | 532 # that Y = Z-X, so we need to check for Y. |
| 514 true_code = emitter.Emit( | 533 true_code = emitter.Emit( |
| 515 '$(INDENT)if ($COND) {\n' | 534 '$(INDENT)if ($COND) {\n' |
| 516 '$!TRUE' | 535 '$!TRUE' |
| 517 '$(INDENT)}\n', | 536 '$(INDENT)}\n', |
| 518 COND=test, INDENT=indent) | 537 COND=test, INDENT=indent) |
| 519 self.GenerateDispatch( | 538 self.GenerateDispatch( |
| 520 true_code, info, indent + ' ', position + 1, positive) | 539 true_code, info, indent + ' ', position + 1, positive) |
| 521 return True | 540 return True |
| OLD | NEW |