| 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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 self.factory_provider_name = factory_provider_name | 75 self.factory_provider_name = factory_provider_name |
| 76 | 76 |
| 77 def ConstructorInfo(self, interface_name): | 77 def ConstructorInfo(self, interface_name): |
| 78 info = OperationInfo() | 78 info = OperationInfo() |
| 79 info.overloads = None | 79 info.overloads = None |
| 80 info.declared_name = interface_name | 80 info.declared_name = interface_name |
| 81 info.name = interface_name | 81 info.name = interface_name |
| 82 info.constructor_name = self.name | 82 info.constructor_name = self.name |
| 83 info.js_name = None | 83 info.js_name = None |
| 84 info.type_name = interface_name | 84 info.type_name = interface_name |
| 85 info.param_infos = map(lambda tXn: ParamInfo(tXn[1], None, tXn[0], 'null'), | 85 info.param_infos = map(lambda tXn: ParamInfo(tXn[1], tXn[0], 'null'), |
| 86 self.opt_params) | 86 self.opt_params) |
| 87 return info | 87 return info |
| 88 | 88 |
| 89 _html_element_constructors = { | 89 _html_element_constructors = { |
| 90 'AnchorElement' : | 90 'AnchorElement' : |
| 91 ElementConstructorInfo(tag='a', opt_params=[('DOMString', 'href')]), | 91 ElementConstructorInfo(tag='a', opt_params=[('DOMString', 'href')]), |
| 92 'AreaElement': 'area', | 92 'AreaElement': 'area', |
| 93 'ButtonElement': 'button', | 93 'ButtonElement': 'button', |
| 94 'BRElement': 'br', | 94 'BRElement': 'br', |
| 95 'BaseElement': 'base', | 95 'BaseElement': 'base', |
| (...skipping 763 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 859 native_return_type = output_conversion.input_type | 859 native_return_type = output_conversion.input_type |
| 860 else: | 860 else: |
| 861 return_type = self._NarrowInputType(info.type_name) | 861 return_type = self._NarrowInputType(info.type_name) |
| 862 native_return_type = return_type | 862 native_return_type = return_type |
| 863 | 863 |
| 864 def InputType(type_name): | 864 def InputType(type_name): |
| 865 conversion = self._InputConversion(type_name, info.declared_name) | 865 conversion = self._InputConversion(type_name, info.declared_name) |
| 866 if conversion: | 866 if conversion: |
| 867 return conversion.input_type | 867 return conversion.input_type |
| 868 else: | 868 else: |
| 869 return self._NarrowInputType(type_name) | 869 return self._NarrowInputType(type_name) if type_name else 'Dynamic' |
| 870 | 870 |
| 871 body = self._members_emitter.Emit( | 871 body = self._members_emitter.Emit( |
| 872 '\n' | 872 '\n' |
| 873 ' $MODIFIERS$TYPE $(HTML_NAME)($PARAMS) {\n' | 873 ' $MODIFIERS$TYPE $(HTML_NAME)($PARAMS) {\n' |
| 874 '$!BODY' | 874 '$!BODY' |
| 875 ' }\n', | 875 ' }\n', |
| 876 MODIFIERS='static ' if info.IsStatic() else '', | 876 MODIFIERS='static ' if info.IsStatic() else '', |
| 877 TYPE=return_type, | 877 TYPE=return_type, |
| 878 HTML_NAME=html_name, | 878 HTML_NAME=html_name, |
| 879 PARAMS=info.ParametersImplementationDeclaration(InputType)) | 879 PARAMS=info.ParametersImplementationDeclaration(InputType)) |
| 880 | 880 |
| 881 parameter_names = [param_info.name for param_info in info.param_infos] | 881 parameter_names = [param_info.name for param_info in info.param_infos] |
| 882 parameter_types = [InputType(param_info.dart_type) | 882 parameter_types = [InputType(param_info.type_id) |
| 883 for param_info in info.param_infos] | 883 for param_info in info.param_infos] |
| 884 operations = info.operations | 884 operations = info.operations |
| 885 | 885 |
| 886 method_version = [0] | 886 method_version = [0] |
| 887 temp_version = [0] | 887 temp_version = [0] |
| 888 | 888 |
| 889 def GenerateCall(operation, argument_count, checks): | 889 def GenerateCall(operation, argument_count, checks): |
| 890 checks = filter(lambda e: e != 'true', checks) | 890 checks = filter(lambda e: e != 'true', checks) |
| 891 if checks: | 891 if checks: |
| 892 (stmts_emitter, call_emitter) = body.Emit( | 892 (stmts_emitter, call_emitter) = body.Emit( |
| (...skipping 20 matching lines...) Expand all Loading... |
| 913 NAME=temp_name, | 913 NAME=temp_name, |
| 914 CONVERT=conversion.function_name, | 914 CONVERT=conversion.function_name, |
| 915 ARG=parameter_names[position]) | 915 ARG=parameter_names[position]) |
| 916 arguments.append(temp_name) | 916 arguments.append(temp_name) |
| 917 param_type = temp_type | 917 param_type = temp_type |
| 918 verified_type = temp_type # verified by assignment in checked mode. | 918 verified_type = temp_type # verified by assignment in checked mode. |
| 919 else: | 919 else: |
| 920 arguments.append(parameter_names[position]) | 920 arguments.append(parameter_names[position]) |
| 921 param_type = self._NarrowInputType(arg.type.id) | 921 param_type = self._NarrowInputType(arg.type.id) |
| 922 # Verified by argument checking on entry to the dispatcher. | 922 # Verified by argument checking on entry to the dispatcher. |
| 923 verified_type = InputType(info.param_infos[position].dart_type) | 923 verified_type = InputType(info.param_infos[position].type_id) |
| 924 | 924 |
| 925 # The native method does not need an argument type if we know the type. | 925 # The native method does not need an argument type if we know the type. |
| 926 # But we do need the native methods to have correct function types, so | 926 # But we do need the native methods to have correct function types, so |
| 927 # be conservative. | 927 # be conservative. |
| 928 if param_type == verified_type: | 928 if param_type == verified_type: |
| 929 if param_type in ['String', 'num', 'int', 'double', 'bool', 'Object']: | 929 if param_type in ['String', 'num', 'int', 'double', 'bool', 'Object']: |
| 930 param_type = 'Dynamic' | 930 param_type = 'Dynamic' |
| 931 target_parameters.append( | 931 target_parameters.append( |
| 932 '%s%s' % (TypeOrNothing(param_type), param_name)) | 932 '%s%s' % (TypeOrNothing(param_type), param_name)) |
| 933 | 933 |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1020 return _js_custom_members | 1020 return _js_custom_members |
| 1021 | 1021 |
| 1022 def _HasJavaScriptIndexingBehaviour(self): | 1022 def _HasJavaScriptIndexingBehaviour(self): |
| 1023 """Returns True if the native object has an indexer and length property.""" | 1023 """Returns True if the native object has an indexer and length property.""" |
| 1024 (element_type, requires_indexer) = ListImplementationInfo( | 1024 (element_type, requires_indexer) = ListImplementationInfo( |
| 1025 self._interface, self._database) | 1025 self._interface, self._database) |
| 1026 if element_type and requires_indexer: return True | 1026 if element_type and requires_indexer: return True |
| 1027 return False | 1027 return False |
| 1028 | 1028 |
| 1029 def _NarrowToImplementationType(self, type_name): | 1029 def _NarrowToImplementationType(self, type_name): |
| 1030 if type_name == 'Dynamic': | |
| 1031 return type_name | |
| 1032 return self._type_registry.TypeInfo(type_name).narrow_dart_type() | 1030 return self._type_registry.TypeInfo(type_name).narrow_dart_type() |
| 1033 | 1031 |
| 1034 def _NarrowInputType(self, type_name): | 1032 def _NarrowInputType(self, type_name): |
| 1035 return self._NarrowToImplementationType(type_name) | 1033 return self._NarrowToImplementationType(type_name) |
| 1036 | 1034 |
| 1037 def _NarrowOutputType(self, type_name): | 1035 def _NarrowOutputType(self, type_name): |
| 1038 secure_name = SecureOutputType(self, type_name, True) | 1036 secure_name = SecureOutputType(self, type_name, True) |
| 1039 return self._NarrowToImplementationType(secure_name) | 1037 return self._NarrowToImplementationType(secure_name) |
| 1040 | 1038 |
| 1041 def _FindShadowedAttribute(self, attr): | 1039 def _FindShadowedAttribute(self, attr): |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1102 | 1100 |
| 1103 library_emitter = self._multiemitter.FileEmitter(library_file_path) | 1101 library_emitter = self._multiemitter.FileEmitter(library_file_path) |
| 1104 library_file_dir = os.path.dirname(library_file_path) | 1102 library_file_dir = os.path.dirname(library_file_path) |
| 1105 auxiliary_dir = os.path.relpath(auxiliary_dir, library_file_dir) | 1103 auxiliary_dir = os.path.relpath(auxiliary_dir, library_file_dir) |
| 1106 imports_emitter = library_emitter.Emit( | 1104 imports_emitter = library_emitter.Emit( |
| 1107 self._template, AUXILIARY_DIR=massage_path(auxiliary_dir)) | 1105 self._template, AUXILIARY_DIR=massage_path(auxiliary_dir)) |
| 1108 for path in sorted(self._path_to_emitter.keys()): | 1106 for path in sorted(self._path_to_emitter.keys()): |
| 1109 relpath = os.path.relpath(path, library_file_dir) | 1107 relpath = os.path.relpath(path, library_file_dir) |
| 1110 imports_emitter.Emit( | 1108 imports_emitter.Emit( |
| 1111 "#source('$PATH');\n", PATH=massage_path(relpath)) | 1109 "#source('$PATH');\n", PATH=massage_path(relpath)) |
| OLD | NEW |