| 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 | 10 |
| (...skipping 644 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 655 if info.name == 'item': | 655 if info.name == 'item': |
| 656 # FIXME: item should be renamed to operator[], not removed. | 656 # FIXME: item should be renamed to operator[], not removed. |
| 657 self._backend.AddOperation(info, '_item') | 657 self._backend.AddOperation(info, '_item') |
| 658 return | 658 return |
| 659 | 659 |
| 660 if not self._shared.IsPrivate(html_name) and not skip_declaration: | 660 if not self._shared.IsPrivate(html_name) and not skip_declaration: |
| 661 self._members_emitter.Emit('\n /** @domName $DOMINTERFACE.$DOMNAME */', | 661 self._members_emitter.Emit('\n /** @domName $DOMINTERFACE.$DOMNAME */', |
| 662 DOMINTERFACE=info.overloads[0].doc_js_interface_name, | 662 DOMINTERFACE=info.overloads[0].doc_js_interface_name, |
| 663 DOMNAME=info.name) | 663 DOMNAME=info.name) |
| 664 | 664 |
| 665 self._members_emitter.Emit('\n' | 665 if info.IsStatic(): |
| 666 ' $TYPE $NAME($PARAMS);\n', | 666 # FIXME: provide a type. |
| 667 TYPE=self._DartType(info.type_name), | 667 self._members_emitter.Emit('\n' |
| 668 NAME=html_name, | 668 ' static final $NAME = $IMPL_CLASS_NAME.$NAME
;\n', |
| 669 PARAMS=info.ParametersInterfaceDeclaration(self
._DartType)) | 669 IMPL_CLASS_NAME=self._backend.ImplementationCl
assName(), |
| 670 NAME=html_name) |
| 671 else: |
| 672 self._members_emitter.Emit('\n' |
| 673 ' $TYPE $NAME($PARAMS);\n', |
| 674 TYPE=self._DartType(info.type_name), |
| 675 NAME=html_name, |
| 676 PARAMS=info.ParametersInterfaceDeclaration(sel
f._DartType)) |
| 670 self._backend.AddOperation(info, html_name) | 677 self._backend.AddOperation(info, html_name) |
| 671 | 678 |
| 672 def AddStaticOperation(self, info): | |
| 673 self.AddOperation(info, True) | |
| 674 | |
| 675 def AddSecondaryOperation(self, interface, info): | 679 def AddSecondaryOperation(self, interface, info): |
| 676 self._backend.SecondaryContext(interface) | 680 self._backend.SecondaryContext(interface) |
| 677 self.AddOperation(info, True) | 681 self.AddOperation(info, True) |
| 678 | 682 |
| 679 def FinishInterface(self): | 683 def FinishInterface(self): |
| 680 self._backend.FinishInterface() | 684 self._backend.FinishInterface() |
| 681 | 685 |
| 682 def AddConstant(self, constant): | 686 def AddConstant(self, constant): |
| 683 type = TypeOrNothing(self._DartType(constant.type.id), constant.type.id) | 687 type = TypeOrNothing(self._DartType(constant.type.id), constant.type.id) |
| 684 self._members_emitter.Emit('\n static const $TYPE$NAME = $VALUE;\n', | 688 self._members_emitter.Emit('\n static const $TYPE$NAME = $VALUE;\n', |
| (...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1002 | 1006 |
| 1003 | 1007 |
| 1004 def AddOperation(self, info, html_name): | 1008 def AddOperation(self, info, html_name): |
| 1005 """ | 1009 """ |
| 1006 Arguments: | 1010 Arguments: |
| 1007 info: An OperationInfo object. | 1011 info: An OperationInfo object. |
| 1008 """ | 1012 """ |
| 1009 if self._HasCustomImplementation(info.name): | 1013 if self._HasCustomImplementation(info.name): |
| 1010 return | 1014 return |
| 1011 | 1015 |
| 1012 # FIXME: support static operations. | |
| 1013 if info.IsStatic(): | |
| 1014 return | |
| 1015 | |
| 1016 # Any conversions needed? | 1016 # Any conversions needed? |
| 1017 if any(self._OperationRequiresConversions(op) for op in info.overloads): | 1017 if any(self._OperationRequiresConversions(op) for op in info.overloads): |
| 1018 self._AddOperationWithConversions(info, html_name) | 1018 self._AddOperationWithConversions(info, html_name) |
| 1019 else: | 1019 else: |
| 1020 self._AddDirectNativeOperation(info, html_name) | 1020 self._AddDirectNativeOperation(info, html_name) |
| 1021 | 1021 |
| 1022 def _AddDirectNativeOperation(self, info, html_name): | 1022 def _AddDirectNativeOperation(self, info, html_name): |
| 1023 # Do we need a native body? | 1023 # Do we need a native body? |
| 1024 if html_name != info.declared_name: | 1024 if html_name != info.declared_name: |
| 1025 return_type = self._NarrowOutputType(info.type_name) | 1025 return_type = self._NarrowOutputType(info.type_name) |
| 1026 | 1026 |
| 1027 operation_emitter = self._members_emitter.Emit('$!SCOPE', | 1027 operation_emitter = self._members_emitter.Emit('$!SCOPE', |
| 1028 MODIFIERS='static ' if info.IsStatic() else '', |
| 1028 TYPE=return_type, | 1029 TYPE=return_type, |
| 1029 HTML_NAME=html_name, | 1030 HTML_NAME=html_name, |
| 1030 NAME=info.declared_name, | 1031 NAME=info.declared_name, |
| 1031 PARAMS=info.ParametersImplementationDeclaration( | 1032 PARAMS=info.ParametersImplementationDeclaration( |
| 1032 lambda type_name: self._NarrowInputType(type_name))) | 1033 lambda type_name: self._NarrowInputType(type_name))) |
| 1033 | 1034 |
| 1034 operation_emitter.Emit( | 1035 operation_emitter.Emit( |
| 1035 '\n' | 1036 '\n' |
| 1036 #' // @native("$NAME")\n;' | 1037 #' // @native("$NAME")\n;' |
| 1037 ' $TYPE $(HTML_NAME)($PARAMS) native "$NAME";\n') | 1038 ' $MODIFIERS$TYPE $(HTML_NAME)($PARAMS) native "$NAME";\n') |
| 1038 else: | 1039 else: |
| 1039 self._members_emitter.Emit( | 1040 self._members_emitter.Emit( |
| 1040 '\n' | 1041 '\n' |
| 1041 ' $TYPE $NAME($PARAMS) native;\n', | 1042 ' $MODIFIERS$TYPE $NAME($PARAMS) native;\n', |
| 1043 MODIFIERS='static ' if info.IsStatic() else '', |
| 1042 TYPE=self._NarrowOutputType(info.type_name), | 1044 TYPE=self._NarrowOutputType(info.type_name), |
| 1043 NAME=info.name, | 1045 NAME=info.name, |
| 1044 PARAMS=info.ParametersImplementationDeclaration( | 1046 PARAMS=info.ParametersImplementationDeclaration( |
| 1045 lambda type_name: self._NarrowInputType(type_name))) | 1047 lambda type_name: self._NarrowInputType(type_name))) |
| 1046 | 1048 |
| 1047 def _AddOperationWithConversions(self, info, html_name): | 1049 def _AddOperationWithConversions(self, info, html_name): |
| 1048 # Assert all operations have same return type. | 1050 # Assert all operations have same return type. |
| 1049 assert len(set([op.type.id for op in info.operations])) == 1 | 1051 assert len(set([op.type.id for op in info.operations])) == 1 |
| 1050 info = info.CopyAndWidenDefaultParameters() | 1052 info = info.CopyAndWidenDefaultParameters() |
| 1051 output_conversion = self._OutputConversion(info.type_name, | 1053 output_conversion = self._OutputConversion(info.type_name, |
| 1052 info.declared_name) | 1054 info.declared_name) |
| 1053 if output_conversion: | 1055 if output_conversion: |
| 1054 return_type = output_conversion.output_type | 1056 return_type = output_conversion.output_type |
| 1055 native_return_type = output_conversion.input_type | 1057 native_return_type = output_conversion.input_type |
| 1056 else: | 1058 else: |
| 1057 return_type = self._NarrowInputType(info.type_name) | 1059 return_type = self._NarrowInputType(info.type_name) |
| 1058 native_return_type = return_type | 1060 native_return_type = return_type |
| 1059 | 1061 |
| 1060 def InputType(type_name): | 1062 def InputType(type_name): |
| 1061 conversion = self._InputConversion(type_name, info.declared_name) | 1063 conversion = self._InputConversion(type_name, info.declared_name) |
| 1062 if conversion: | 1064 if conversion: |
| 1063 return conversion.input_type | 1065 return conversion.input_type |
| 1064 else: | 1066 else: |
| 1065 return self._NarrowInputType(type_name) | 1067 return self._NarrowInputType(type_name) |
| 1066 | 1068 |
| 1067 body = self._members_emitter.Emit( | 1069 body = self._members_emitter.Emit( |
| 1068 '\n' | 1070 '\n' |
| 1069 ' $TYPE $(HTML_NAME)($PARAMS) {\n' | 1071 ' $MODIFIERS$TYPE $(HTML_NAME)($PARAMS) {\n' |
| 1070 '$!BODY' | 1072 '$!BODY' |
| 1071 ' }\n', | 1073 ' }\n', |
| 1074 MODIFIERS='static ' if info.IsStatic() else '', |
| 1072 TYPE=return_type, | 1075 TYPE=return_type, |
| 1073 HTML_NAME=html_name, | 1076 HTML_NAME=html_name, |
| 1074 PARAMS=info.ParametersImplementationDeclaration(InputType)) | 1077 PARAMS=info.ParametersImplementationDeclaration(InputType)) |
| 1075 | 1078 |
| 1076 parameter_names = [param_info.name for param_info in info.param_infos] | 1079 parameter_names = [param_info.name for param_info in info.param_infos] |
| 1077 parameter_types = [InputType(param_info.dart_type) | 1080 parameter_types = [InputType(param_info.dart_type) |
| 1078 for param_info in info.param_infos] | 1081 for param_info in info.param_infos] |
| 1079 operations = info.operations | 1082 operations = info.operations |
| 1080 | 1083 |
| 1081 method_version = [0] | 1084 method_version = [0] |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1230 def GenerateLibraries(self, dart_files): | 1233 def GenerateLibraries(self, dart_files): |
| 1231 auxiliary_dir = os.path.relpath(self._auxiliary_dir, self._output_dir) | 1234 auxiliary_dir = os.path.relpath(self._auxiliary_dir, self._output_dir) |
| 1232 self._GenerateLibFile( | 1235 self._GenerateLibFile( |
| 1233 'html_dart2js.darttemplate', | 1236 'html_dart2js.darttemplate', |
| 1234 os.path.join(self._output_dir, 'html_dart2js.dart'), | 1237 os.path.join(self._output_dir, 'html_dart2js.dart'), |
| 1235 dart_files, | 1238 dart_files, |
| 1236 AUXILIARY_DIR=systembase.MassagePath(auxiliary_dir)) | 1239 AUXILIARY_DIR=systembase.MassagePath(auxiliary_dir)) |
| 1237 | 1240 |
| 1238 def Finish(self): | 1241 def Finish(self): |
| 1239 pass | 1242 pass |
| OLD | NEW |