| 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 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 '\n' | 178 '\n' |
| 179 ' static $RETURN_TYPE $CONSTRUCTOR($PARAMS) {\n' | 179 ' static $RETURN_TYPE $CONSTRUCTOR($PARAMS) {\n' |
| 180 ' $CLASS _e = _document.$dom_createElement("$TAG");\n' | 180 ' $CLASS _e = _document.$dom_createElement("$TAG");\n' |
| 181 '$!INITS' | 181 '$!INITS' |
| 182 ' return _e;\n' | 182 ' return _e;\n' |
| 183 ' }\n', | 183 ' }\n', |
| 184 RETURN_TYPE=rename_type(constructor_info.type_name), | 184 RETURN_TYPE=rename_type(constructor_info.type_name), |
| 185 CONSTRUCTOR=constructor_info.ConstructorFactoryName(rename_type), | 185 CONSTRUCTOR=constructor_info.ConstructorFactoryName(rename_type), |
| 186 CLASS=class_name, | 186 CLASS=class_name, |
| 187 TAG=info.tag, | 187 TAG=info.tag, |
| 188 PARAMS=constructor_info.ParametersInterfaceDeclaration(rename_type)) | 188 PARAMS=constructor_info.ParametersDeclaration(rename_type)) |
| 189 for param in constructor_info.param_infos: | 189 for param in constructor_info.param_infos: |
| 190 inits.Emit(' if ($E != null) _e.$E = $E;\n', E=param.name) | 190 inits.Emit(' if ($E != null) _e.$E = $E;\n', E=param.name) |
| 191 | 191 |
| 192 # ------------------------------------------------------------------------------ | 192 # ------------------------------------------------------------------------------ |
| 193 | 193 |
| 194 class HtmlDartInterfaceGenerator(object): | 194 class HtmlDartInterfaceGenerator(object): |
| 195 """Generates dart interface and implementation for the DOM IDL interface.""" | 195 """Generates dart interface and implementation for the DOM IDL interface.""" |
| 196 | 196 |
| 197 def __init__(self, options, library_emitter, event_generator, interface, | 197 def __init__(self, options, library_emitter, event_generator, interface, |
| 198 backend): | 198 backend): |
| (...skipping 17 matching lines...) Expand all Loading... |
| 216 def GenerateCallback(self): | 216 def GenerateCallback(self): |
| 217 """Generates a typedef for the callback interface.""" | 217 """Generates a typedef for the callback interface.""" |
| 218 handlers = [operation for operation in self._interface.operations | 218 handlers = [operation for operation in self._interface.operations |
| 219 if operation.id == 'handleEvent'] | 219 if operation.id == 'handleEvent'] |
| 220 info = AnalyzeOperation(self._interface, handlers) | 220 info = AnalyzeOperation(self._interface, handlers) |
| 221 code = self._library_emitter.FileEmitter(self._interface.id) | 221 code = self._library_emitter.FileEmitter(self._interface.id) |
| 222 code.Emit(self._template_loader.Load('callback.darttemplate')) | 222 code.Emit(self._template_loader.Load('callback.darttemplate')) |
| 223 code.Emit('typedef $TYPE $NAME($PARAMS);\n', | 223 code.Emit('typedef $TYPE $NAME($PARAMS);\n', |
| 224 NAME=self._interface.id, | 224 NAME=self._interface.id, |
| 225 TYPE=self._DartType(info.type_name), | 225 TYPE=self._DartType(info.type_name), |
| 226 PARAMS=info.ParametersImplementationDeclaration(self._DartType)) | 226 PARAMS=info.ParametersDeclaration(self._DartType)) |
| 227 self._backend.GenerateCallback(info) | 227 self._backend.GenerateCallback(info) |
| 228 | 228 |
| 229 def GenerateInterface(self): | 229 def GenerateInterface(self): |
| 230 if (self._interface_type_info.has_generated_interface() and | 230 if (self._interface_type_info.has_generated_interface() and |
| 231 not self._interface_type_info.merged_into()): | 231 not self._interface_type_info.merged_into()): |
| 232 interface_emitter = self._library_emitter.FileEmitter( | 232 interface_emitter = self._library_emitter.FileEmitter( |
| 233 self._html_interface_name) | 233 self._html_interface_name) |
| 234 else: | 234 else: |
| 235 interface_emitter = emitter.Emitter() | 235 interface_emitter = emitter.Emitter() |
| 236 | 236 |
| (...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 486 # FIXME: provide a type. | 486 # FIXME: provide a type. |
| 487 self._members_emitter.Emit('\n' | 487 self._members_emitter.Emit('\n' |
| 488 ' static final $NAME = $IMPL_CLASS_NAME.$NAME
;\n', | 488 ' static final $NAME = $IMPL_CLASS_NAME.$NAME
;\n', |
| 489 IMPL_CLASS_NAME=self._backend.ImplementationCl
assName(), | 489 IMPL_CLASS_NAME=self._backend.ImplementationCl
assName(), |
| 490 NAME=html_name) | 490 NAME=html_name) |
| 491 else: | 491 else: |
| 492 self._members_emitter.Emit('\n' | 492 self._members_emitter.Emit('\n' |
| 493 ' $TYPE $NAME($PARAMS);\n', | 493 ' $TYPE $NAME($PARAMS);\n', |
| 494 TYPE=SecureOutputType(self, info.type_name), | 494 TYPE=SecureOutputType(self, info.type_name), |
| 495 NAME=html_name, | 495 NAME=html_name, |
| 496 PARAMS=info.ParametersInterfaceDeclaration(sel
f._DartType)) | 496 PARAMS=info.ParametersDeclaration(self._DartTy
pe)) |
| 497 self._backend.AddOperation(info, html_name) | 497 self._backend.AddOperation(info, html_name) |
| 498 | 498 |
| 499 def AddSecondaryOperation(self, interface, info): | 499 def AddSecondaryOperation(self, interface, info): |
| 500 self._backend.SecondaryContext(interface) | 500 self._backend.SecondaryContext(interface) |
| 501 self.AddOperation(info, True) | 501 self.AddOperation(info, True) |
| 502 | 502 |
| 503 def AddConstant(self, constant): | 503 def AddConstant(self, constant): |
| 504 type = TypeOrNothing(self._DartType(constant.type.id), constant.type.id) | 504 type = TypeOrNothing(self._DartType(constant.type.id), constant.type.id) |
| 505 self._members_emitter.Emit('\n static const $TYPE$NAME = $VALUE;\n', | 505 self._members_emitter.Emit('\n static const $TYPE$NAME = $VALUE;\n', |
| 506 NAME=constant.id, | 506 NAME=constant.id, |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 644 template = self._template_loader.TryLoad(template_file) | 644 template = self._template_loader.TryLoad(template_file) |
| 645 if not template: | 645 if not template: |
| 646 template = self._template_loader.Load('factoryprovider.darttemplate') | 646 template = self._template_loader.Load('factoryprovider.darttemplate') |
| 647 | 647 |
| 648 arguments = constructor_info.ParametersAsArgumentList() | 648 arguments = constructor_info.ParametersAsArgumentList() |
| 649 comma = ',' if arguments else '' | 649 comma = ',' if arguments else '' |
| 650 emitter.Emit( | 650 emitter.Emit( |
| 651 template, | 651 template, |
| 652 FACTORYPROVIDER=factory_provider, | 652 FACTORYPROVIDER=factory_provider, |
| 653 CONSTRUCTOR=self._html_interface_name, | 653 CONSTRUCTOR=self._html_interface_name, |
| 654 PARAMETERS=constructor_info.ParametersImplementationDeclaration(self._Da
rtType), | 654 PARAMETERS=constructor_info.ParametersDeclaration(self._DartType), |
| 655 NAMED_CONSTRUCTOR=constructor_info.name or self._html_interface_name, | 655 NAMED_CONSTRUCTOR=constructor_info.name or self._html_interface_name, |
| 656 ARGUMENTS=arguments, | 656 ARGUMENTS=arguments, |
| 657 PRE_ARGUMENTS_COMMA=comma, | 657 PRE_ARGUMENTS_COMMA=comma, |
| 658 ARGUMENTS_PATTERN=','.join(['#'] * len(constructor_info.param_infos))) | 658 ARGUMENTS_PATTERN=','.join(['#'] * len(constructor_info.param_infos))) |
| 659 | 659 |
| 660 def SecondaryContext(self, interface): | 660 def SecondaryContext(self, interface): |
| 661 if interface is not self._current_secondary_parent: | 661 if interface is not self._current_secondary_parent: |
| 662 self._current_secondary_parent = interface | 662 self._current_secondary_parent = interface |
| 663 self._members_emitter.Emit('\n // From $WHERE\n', WHERE=interface.id) | 663 self._members_emitter.Emit('\n // From $WHERE\n', WHERE=interface.id) |
| 664 | 664 |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 847 def _AddDirectNativeOperation(self, info, html_name): | 847 def _AddDirectNativeOperation(self, info, html_name): |
| 848 # Do we need a native body? | 848 # Do we need a native body? |
| 849 if html_name != info.declared_name: | 849 if html_name != info.declared_name: |
| 850 return_type = self._NarrowOutputType(info.type_name) | 850 return_type = self._NarrowOutputType(info.type_name) |
| 851 | 851 |
| 852 operation_emitter = self._members_emitter.Emit('$!SCOPE', | 852 operation_emitter = self._members_emitter.Emit('$!SCOPE', |
| 853 MODIFIERS='static ' if info.IsStatic() else '', | 853 MODIFIERS='static ' if info.IsStatic() else '', |
| 854 TYPE=return_type, | 854 TYPE=return_type, |
| 855 HTML_NAME=html_name, | 855 HTML_NAME=html_name, |
| 856 NAME=info.declared_name, | 856 NAME=info.declared_name, |
| 857 PARAMS=info.ParametersImplementationDeclaration( | 857 PARAMS=info.ParametersDeclaration( |
| 858 lambda type_name: self._NarrowInputType(type_name))) | 858 lambda type_name: self._NarrowInputType(type_name))) |
| 859 | 859 |
| 860 operation_emitter.Emit( | 860 operation_emitter.Emit( |
| 861 '\n' | 861 '\n' |
| 862 #' // @native("$NAME")\n;' | 862 #' // @native("$NAME")\n;' |
| 863 ' $MODIFIERS$TYPE $(HTML_NAME)($PARAMS) native "$NAME";\n') | 863 ' $MODIFIERS$TYPE $(HTML_NAME)($PARAMS) native "$NAME";\n') |
| 864 else: | 864 else: |
| 865 self._members_emitter.Emit( | 865 self._members_emitter.Emit( |
| 866 '\n' | 866 '\n' |
| 867 ' $MODIFIERS$TYPE $NAME($PARAMS) native;\n', | 867 ' $MODIFIERS$TYPE $NAME($PARAMS) native;\n', |
| 868 MODIFIERS='static ' if info.IsStatic() else '', | 868 MODIFIERS='static ' if info.IsStatic() else '', |
| 869 TYPE=self._NarrowOutputType(info.type_name), | 869 TYPE=self._NarrowOutputType(info.type_name), |
| 870 NAME=info.name, | 870 NAME=info.name, |
| 871 PARAMS=info.ParametersImplementationDeclaration( | 871 PARAMS=info.ParametersDeclaration( |
| 872 lambda type_name: self._NarrowInputType(type_name))) | 872 lambda type_name: self._NarrowInputType(type_name))) |
| 873 | 873 |
| 874 def _AddOperationWithConversions(self, info, html_name): | 874 def _AddOperationWithConversions(self, info, html_name): |
| 875 # Assert all operations have same return type. | 875 # Assert all operations have same return type. |
| 876 assert len(set([op.type.id for op in info.operations])) == 1 | 876 assert len(set([op.type.id for op in info.operations])) == 1 |
| 877 info = info.CopyAndWidenDefaultParameters() | 877 info = info.CopyAndWidenDefaultParameters() |
| 878 output_conversion = self._OutputConversion(info.type_name, | 878 output_conversion = self._OutputConversion(info.type_name, |
| 879 info.declared_name) | 879 info.declared_name) |
| 880 if output_conversion: | 880 if output_conversion: |
| 881 return_type = output_conversion.output_type | 881 return_type = output_conversion.output_type |
| (...skipping 10 matching lines...) Expand all Loading... |
| 892 return self._NarrowInputType(type_name) if type_name else 'Dynamic' | 892 return self._NarrowInputType(type_name) if type_name else 'Dynamic' |
| 893 | 893 |
| 894 body = self._members_emitter.Emit( | 894 body = self._members_emitter.Emit( |
| 895 '\n' | 895 '\n' |
| 896 ' $MODIFIERS$TYPE $(HTML_NAME)($PARAMS) {\n' | 896 ' $MODIFIERS$TYPE $(HTML_NAME)($PARAMS) {\n' |
| 897 '$!BODY' | 897 '$!BODY' |
| 898 ' }\n', | 898 ' }\n', |
| 899 MODIFIERS='static ' if info.IsStatic() else '', | 899 MODIFIERS='static ' if info.IsStatic() else '', |
| 900 TYPE=return_type, | 900 TYPE=return_type, |
| 901 HTML_NAME=html_name, | 901 HTML_NAME=html_name, |
| 902 PARAMS=info.ParametersImplementationDeclaration(InputType)) | 902 PARAMS=info.ParametersDeclaration(InputType)) |
| 903 | 903 |
| 904 parameter_names = [param_info.name for param_info in info.param_infos] | 904 parameter_names = [param_info.name for param_info in info.param_infos] |
| 905 parameter_types = [InputType(param_info.type_id) | 905 parameter_types = [InputType(param_info.type_id) |
| 906 for param_info in info.param_infos] | 906 for param_info in info.param_infos] |
| 907 operations = info.operations | 907 operations = info.operations |
| 908 | 908 |
| 909 method_version = [0] | 909 method_version = [0] |
| 910 temp_version = [0] | 910 temp_version = [0] |
| 911 | 911 |
| 912 def GenerateCall(operation, argument_count, checks): | 912 def GenerateCall(operation, argument_count, checks): |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1122 | 1122 |
| 1123 library_emitter = self._multiemitter.FileEmitter(library_file_path) | 1123 library_emitter = self._multiemitter.FileEmitter(library_file_path) |
| 1124 library_file_dir = os.path.dirname(library_file_path) | 1124 library_file_dir = os.path.dirname(library_file_path) |
| 1125 auxiliary_dir = os.path.relpath(auxiliary_dir, library_file_dir) | 1125 auxiliary_dir = os.path.relpath(auxiliary_dir, library_file_dir) |
| 1126 imports_emitter = library_emitter.Emit( | 1126 imports_emitter = library_emitter.Emit( |
| 1127 self._template, AUXILIARY_DIR=massage_path(auxiliary_dir)) | 1127 self._template, AUXILIARY_DIR=massage_path(auxiliary_dir)) |
| 1128 for path in sorted(self._path_to_emitter.keys()): | 1128 for path in sorted(self._path_to_emitter.keys()): |
| 1129 relpath = os.path.relpath(path, library_file_dir) | 1129 relpath = os.path.relpath(path, library_file_dir) |
| 1130 imports_emitter.Emit( | 1130 imports_emitter.Emit( |
| 1131 "#source('$PATH');\n", PATH=massage_path(relpath)) | 1131 "#source('$PATH');\n", PATH=massage_path(relpath)) |
| OLD | NEW |