| 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 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 # TODO(sra): Handle multiple and named constructors. | 157 # TODO(sra): Handle multiple and named constructors. |
| 158 if typename not in _html_element_constructors: | 158 if typename not in _html_element_constructors: |
| 159 return [] | 159 return [] |
| 160 infos = _html_element_constructors[typename] | 160 infos = _html_element_constructors[typename] |
| 161 if isinstance(infos, str): | 161 if isinstance(infos, str): |
| 162 infos = ElementConstructorInfo(tag=infos) | 162 infos = ElementConstructorInfo(tag=infos) |
| 163 if not isinstance(infos, list): | 163 if not isinstance(infos, list): |
| 164 infos = [infos] | 164 infos = [infos] |
| 165 return infos | 165 return infos |
| 166 | 166 |
| 167 def EmitHtmlElementFactoryConstructors(emitter, infos, typename, class_name): | 167 def EmitHtmlElementFactoryConstructors(emitter, infos, typename, class_name, |
| 168 dart_type): |
| 168 for info in infos: | 169 for info in infos: |
| 169 constructor_info = info.ConstructorInfo(typename) | 170 constructor_info = info.ConstructorInfo(typename) |
| 170 | 171 |
| 171 inits = emitter.Emit( | 172 inits = emitter.Emit( |
| 172 '\n' | 173 '\n' |
| 173 ' static $RETURN_TYPE $CONSTRUCTOR($PARAMS) {\n' | 174 ' static $RETURN_TYPE $CONSTRUCTOR($PARAMS) {\n' |
| 174 ' $CLASS _e = _document.$dom_createElement("$TAG");\n' | 175 ' $CLASS _e = _document.$dom_createElement("$TAG");\n' |
| 175 '$!INITS' | 176 '$!INITS' |
| 176 ' return _e;\n' | 177 ' return _e;\n' |
| 177 ' }\n', | 178 ' }\n', |
| 178 RETURN_TYPE=constructor_info.type_name, | 179 RETURN_TYPE=constructor_info.type_name, |
| 179 CONSTRUCTOR=constructor_info.ConstructorFactoryName(DartType), | 180 CONSTRUCTOR=constructor_info.ConstructorFactoryName(dart_type), |
| 180 CLASS=class_name, | 181 CLASS=class_name, |
| 181 TAG=info.tag, | 182 TAG=info.tag, |
| 182 PARAMS=constructor_info.ParametersInterfaceDeclaration(DartType)) | 183 PARAMS=constructor_info.ParametersInterfaceDeclaration(dart_type)) |
| 183 for param in constructor_info.param_infos: | 184 for param in constructor_info.param_infos: |
| 184 inits.Emit(' if ($E != null) _e.$E = $E;\n', E=param.name) | 185 inits.Emit(' if ($E != null) _e.$E = $E;\n', E=param.name) |
| 185 | 186 |
| 186 # ------------------------------------------------------------------------------ | 187 # ------------------------------------------------------------------------------ |
| 187 | 188 |
| 188 class HtmlDartInterfaceGenerator(object): | 189 class HtmlDartInterfaceGenerator(object): |
| 189 """Generates dart interface and implementation for the DOM IDL interface.""" | 190 """Generates dart interface and implementation for the DOM IDL interface.""" |
| 190 | 191 |
| 191 def __init__(self, options, library_emitter, event_generator, interface, | 192 def __init__(self, options, library_emitter, event_generator, interface, |
| 192 backend): | 193 backend): |
| (...skipping 15 matching lines...) Expand all Loading... |
| 208 | 209 |
| 209 def GenerateCallback(self): | 210 def GenerateCallback(self): |
| 210 """Generates a typedef for the callback interface.""" | 211 """Generates a typedef for the callback interface.""" |
| 211 handlers = [operation for operation in self._interface.operations | 212 handlers = [operation for operation in self._interface.operations |
| 212 if operation.id == 'handleEvent'] | 213 if operation.id == 'handleEvent'] |
| 213 info = AnalyzeOperation(self._interface, handlers) | 214 info = AnalyzeOperation(self._interface, handlers) |
| 214 code = self._library_emitter.FileEmitter(self._interface.id) | 215 code = self._library_emitter.FileEmitter(self._interface.id) |
| 215 code.Emit(self._template_loader.Load('callback.darttemplate')) | 216 code.Emit(self._template_loader.Load('callback.darttemplate')) |
| 216 code.Emit('typedef $TYPE $NAME($PARAMS);\n', | 217 code.Emit('typedef $TYPE $NAME($PARAMS);\n', |
| 217 NAME=self._interface.id, | 218 NAME=self._interface.id, |
| 218 TYPE=DartType(info.type_name), | 219 TYPE=self._DartType(info.type_name), |
| 219 PARAMS=info.ParametersImplementationDeclaration(DartType)) | 220 PARAMS=info.ParametersImplementationDeclaration(self._DartType)) |
| 220 self._backend.GenerateCallback(info) | 221 self._backend.GenerateCallback(info) |
| 221 | 222 |
| 222 def GenerateInterface(self): | 223 def GenerateInterface(self): |
| 223 if (not self._interface.id in _merged_html_interfaces and | 224 if (not self._interface.id in _merged_html_interfaces and |
| 224 # Don't re-generate types that have been converted to native dart types. | 225 # Don't re-generate types that have been converted to native dart types. |
| 225 self._html_interface_name not in nativified_classes): | 226 self._html_interface_name not in nativified_classes): |
| 226 interface_emitter = self._library_emitter.FileEmitter( | 227 interface_emitter = self._library_emitter.FileEmitter( |
| 227 self._html_interface_name) | 228 self._html_interface_name) |
| 228 else: | 229 else: |
| 229 interface_emitter = emitter.Emitter() | 230 interface_emitter = emitter.Emitter() |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 constructor_info, factory_provider, factory_provider_emitter) | 275 constructor_info, factory_provider, factory_provider_emitter) |
| 275 | 276 |
| 276 infos = HtmlElementConstructorInfos(typename) | 277 infos = HtmlElementConstructorInfos(typename) |
| 277 if infos: | 278 if infos: |
| 278 template = self._template_loader.Load( | 279 template = self._template_loader.Load( |
| 279 'factoryprovider_Elements.darttemplate') | 280 'factoryprovider_Elements.darttemplate') |
| 280 EmitHtmlElementFactoryConstructors( | 281 EmitHtmlElementFactoryConstructors( |
| 281 self._library_emitter.FileEmitter('_Elements', template), | 282 self._library_emitter.FileEmitter('_Elements', template), |
| 282 infos, | 283 infos, |
| 283 self._html_interface_name, | 284 self._html_interface_name, |
| 284 self._backend.ImplementationClassName()) | 285 self._backend.ImplementationClassName(), |
| 286 self._DartType) |
| 285 | 287 |
| 286 for info in infos: | 288 for info in infos: |
| 287 constructors.append(info.ConstructorInfo(typename)) | 289 constructors.append(info.ConstructorInfo(typename)) |
| 288 if factory_provider: | 290 if factory_provider: |
| 289 assert factory_provider == info.factory_provider_name | 291 assert factory_provider == info.factory_provider_name |
| 290 else: | 292 else: |
| 291 factory_provider = info.factory_provider_name | 293 factory_provider = info.factory_provider_name |
| 292 | 294 |
| 293 # TODO(vsm): Add appropriate package / namespace syntax. | 295 # TODO(vsm): Add appropriate package / namespace syntax. |
| 294 (self._type_comment_emitter, | 296 (self._type_comment_emitter, |
| (...skipping 616 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 911 '$(INDENT)$TYPE $NAME = $CONVERT($ARG);\n', | 913 '$(INDENT)$TYPE $NAME = $CONVERT($ARG);\n', |
| 912 TYPE=TypeOrVar(temp_type), | 914 TYPE=TypeOrVar(temp_type), |
| 913 NAME=temp_name, | 915 NAME=temp_name, |
| 914 CONVERT=conversion.function_name, | 916 CONVERT=conversion.function_name, |
| 915 ARG=parameter_names[position]) | 917 ARG=parameter_names[position]) |
| 916 arguments.append(temp_name) | 918 arguments.append(temp_name) |
| 917 param_type = temp_type | 919 param_type = temp_type |
| 918 verified_type = temp_type # verified by assignment in checked mode. | 920 verified_type = temp_type # verified by assignment in checked mode. |
| 919 else: | 921 else: |
| 920 arguments.append(parameter_names[position]) | 922 arguments.append(parameter_names[position]) |
| 921 param_type = self._NarrowInputType(DartType(arg.type.id)) | 923 param_type = self._NarrowInputType(arg.type.id) |
| 922 # Verified by argument checking on entry to the dispatcher. | 924 # Verified by argument checking on entry to the dispatcher. |
| 923 verified_type = InputType(info.param_infos[position].dart_type) | 925 verified_type = InputType(info.param_infos[position].dart_type) |
| 924 | 926 |
| 925 # The native method does not need an argument type if we know the type. | 927 # 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 | 928 # But we do need the native methods to have correct function types, so |
| 927 # be conservative. | 929 # be conservative. |
| 928 if param_type == verified_type: | 930 if param_type == verified_type: |
| 929 if param_type in ['String', 'num', 'int', 'double', 'bool', 'Object']: | 931 if param_type in ['String', 'num', 'int', 'double', 'bool', 'Object']: |
| 930 param_type = 'Dynamic' | 932 param_type = 'Dynamic' |
| 931 target_parameters.append( | 933 target_parameters.append( |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1115 | 1117 |
| 1116 library_emitter = self._multiemitter.FileEmitter(library_file_path) | 1118 library_emitter = self._multiemitter.FileEmitter(library_file_path) |
| 1117 library_file_dir = os.path.dirname(library_file_path) | 1119 library_file_dir = os.path.dirname(library_file_path) |
| 1118 auxiliary_dir = os.path.relpath(auxiliary_dir, library_file_dir) | 1120 auxiliary_dir = os.path.relpath(auxiliary_dir, library_file_dir) |
| 1119 imports_emitter = library_emitter.Emit( | 1121 imports_emitter = library_emitter.Emit( |
| 1120 self._template, AUXILIARY_DIR=massage_path(auxiliary_dir)) | 1122 self._template, AUXILIARY_DIR=massage_path(auxiliary_dir)) |
| 1121 for path in sorted(self._path_to_emitter.keys()): | 1123 for path in sorted(self._path_to_emitter.keys()): |
| 1122 relpath = os.path.relpath(path, library_file_dir) | 1124 relpath = os.path.relpath(path, library_file_dir) |
| 1123 imports_emitter.Emit( | 1125 imports_emitter.Emit( |
| 1124 "#source('$PATH');\n", PATH=massage_path(relpath)) | 1126 "#source('$PATH');\n", PATH=massage_path(relpath)) |
| OLD | NEW |