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 import os | 10 import os |
(...skipping 784 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
795 self._members_emitter.Emit( | 795 self._members_emitter.Emit( |
796 ' $RENAME$ANNOTATIONS$MODIFIERS$TYPE$TARGET($PARAMS) native;\n', | 796 ' $RENAME$ANNOTATIONS$MODIFIERS$TYPE$TARGET($PARAMS) native;\n', |
797 RENAME=self._RenamingAnnotation(info.declared_name, target), | 797 RENAME=self._RenamingAnnotation(info.declared_name, target), |
798 ANNOTATIONS=self._Annotations(info.type_name, info.declared_name), | 798 ANNOTATIONS=self._Annotations(info.type_name, info.declared_name), |
799 MODIFIERS='static ' if info.IsStatic() else '', | 799 MODIFIERS='static ' if info.IsStatic() else '', |
800 TYPE=TypeOrNothing(native_return_type), | 800 TYPE=TypeOrNothing(native_return_type), |
801 TARGET=target, | 801 TARGET=target, |
802 PARAMS=', '.join(target_parameters)) | 802 PARAMS=', '.join(target_parameters)) |
803 | 803 |
804 def GenerateChecksAndCall(operation, argument_count): | 804 def GenerateChecksAndCall(operation, argument_count): |
805 checks = [] | 805 GenerateCall(operation, argument_count, |
806 for i in range(0, argument_count): | 806 self._OverloadChecks( |
podivilov
2012/12/28 16:17:16
maybe introduce a local?
Anton Muhin
2012/12/29 12:02:12
Let's see how the things will unfold.
| |
807 argument = operation.arguments[i] | 807 operation, |
808 parameter_name = parameter_names[i] | 808 parameter_names, |
809 test_type = self._DartType(argument.type.id) | 809 argument_count, |
810 if test_type in ['dynamic', 'Object']: | 810 can_omit_type_check=lambda type, pos: type == parameter_types[pos])) |
811 checks.append('?%s' % parameter_name) | |
812 elif test_type != parameter_types[i]: | |
813 checks.append('(?%s && (%s is %s || %s == null))' % ( | |
814 parameter_name, parameter_name, test_type, parameter_name)) | |
815 | |
816 checks.extend(['!?%s' % name for name in parameter_names[argument_count:]] ) | |
817 # There can be multiple presence checks. We need them all since a later | |
818 # optional argument could have been passed by name, leaving 'holes'. | |
819 GenerateCall(operation, argument_count, checks) | |
820 | 811 |
821 # TODO: Optimize the dispatch to avoid repeated checks. | 812 # TODO: Optimize the dispatch to avoid repeated checks. |
822 if len(operations) > 1: | 813 if len(operations) > 1: |
823 for operation in operations: | 814 for operation in operations: |
824 for position, argument in enumerate(operation.arguments): | 815 for position, argument in enumerate(operation.arguments): |
825 if self._IsOptional(operation, argument): | 816 if self._IsOptional(operation, argument): |
826 GenerateChecksAndCall(operation, position) | 817 GenerateChecksAndCall(operation, position) |
827 GenerateChecksAndCall(operation, len(operation.arguments)) | 818 GenerateChecksAndCall(operation, len(operation.arguments)) |
828 body.Emit( | 819 body.Emit( |
829 ' throw new ArgumentError("Incorrect number or type of arguments"); ' | 820 ' throw new ArgumentError("Incorrect number or type of arguments"); ' |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
995 for library_name in libraries: | 986 for library_name in libraries: |
996 self._libraries[library_name] = DartLibrary( | 987 self._libraries[library_name] = DartLibrary( |
997 library_name, template_loader, library_type, output_dir) | 988 library_name, template_loader, library_type, output_dir) |
998 | 989 |
999 def AddFile(self, basename, library_name, path): | 990 def AddFile(self, basename, library_name, path): |
1000 self._libraries[library_name].AddFile(path) | 991 self._libraries[library_name].AddFile(path) |
1001 | 992 |
1002 def Emit(self, emitter, auxiliary_dir): | 993 def Emit(self, emitter, auxiliary_dir): |
1003 for lib in self._libraries.values(): | 994 for lib in self._libraries.values(): |
1004 lib.Emit(emitter, auxiliary_dir) | 995 lib.Emit(emitter, auxiliary_dir) |
OLD | NEW |