| 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 827 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 838 def _AddDirectNativeOperation(self, info, html_name): | 838 def _AddDirectNativeOperation(self, info, html_name): |
| 839 # Do we need a native body? | 839 # Do we need a native body? |
| 840 if html_name != info.declared_name: | 840 if html_name != info.declared_name: |
| 841 return_type = self._NarrowOutputType(info.type_name) | 841 return_type = self._NarrowOutputType(info.type_name) |
| 842 | 842 |
| 843 operation_emitter = self._members_emitter.Emit('$!SCOPE', | 843 operation_emitter = self._members_emitter.Emit('$!SCOPE', |
| 844 MODIFIERS='static ' if info.IsStatic() else '', | 844 MODIFIERS='static ' if info.IsStatic() else '', |
| 845 TYPE=return_type, | 845 TYPE=return_type, |
| 846 HTML_NAME=html_name, | 846 HTML_NAME=html_name, |
| 847 NAME=info.declared_name, | 847 NAME=info.declared_name, |
| 848 PARAMS=info.ParametersDeclaration( | 848 PARAMS=info.ParametersDeclaration(self._NarrowInputType)) |
| 849 lambda type_name: self._NarrowInputType(type_name))) | |
| 850 | 849 |
| 851 operation_emitter.Emit( | 850 operation_emitter.Emit( |
| 852 '\n' | 851 '\n' |
| 853 #' // @native("$NAME")\n;' | 852 #' // @native("$NAME")\n;' |
| 854 ' $MODIFIERS$TYPE $(HTML_NAME)($PARAMS) native "$NAME";\n') | 853 ' $MODIFIERS$TYPE $(HTML_NAME)($PARAMS) native "$NAME";\n') |
| 855 else: | 854 else: |
| 856 self._members_emitter.Emit( | 855 self._members_emitter.Emit( |
| 857 '\n' | 856 '\n' |
| 858 ' $MODIFIERS$TYPE $NAME($PARAMS) native;\n', | 857 ' $MODIFIERS$TYPE $NAME($PARAMS) native;\n', |
| 859 MODIFIERS='static ' if info.IsStatic() else '', | 858 MODIFIERS='static ' if info.IsStatic() else '', |
| 860 TYPE=self._NarrowOutputType(info.type_name), | 859 TYPE=self._NarrowOutputType(info.type_name), |
| 861 NAME=info.name, | 860 NAME=info.name, |
| 862 PARAMS=info.ParametersDeclaration( | 861 PARAMS=info.ParametersDeclaration(self._NarrowInputType)) |
| 863 lambda type_name: self._NarrowInputType(type_name))) | |
| 864 | 862 |
| 865 def _AddOperationWithConversions(self, info, html_name): | 863 def _AddOperationWithConversions(self, info, html_name): |
| 866 # Assert all operations have same return type. | 864 # Assert all operations have same return type. |
| 867 assert len(set([op.type.id for op in info.operations])) == 1 | 865 assert len(set([op.type.id for op in info.operations])) == 1 |
| 868 info = info.CopyAndWidenDefaultParameters() | 866 info = info.CopyAndWidenDefaultParameters() |
| 869 output_conversion = self._OutputConversion(info.type_name, | 867 output_conversion = self._OutputConversion(info.type_name, |
| 870 info.declared_name) | 868 info.declared_name) |
| 871 if output_conversion: | 869 if output_conversion: |
| 872 return_type = output_conversion.output_type | 870 return_type = output_conversion.output_type |
| 873 native_return_type = output_conversion.input_type | 871 native_return_type = output_conversion.input_type |
| (...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1114 | 1112 |
| 1115 library_emitter = self._multiemitter.FileEmitter(library_file_path) | 1113 library_emitter = self._multiemitter.FileEmitter(library_file_path) |
| 1116 library_file_dir = os.path.dirname(library_file_path) | 1114 library_file_dir = os.path.dirname(library_file_path) |
| 1117 auxiliary_dir = os.path.relpath(auxiliary_dir, library_file_dir) | 1115 auxiliary_dir = os.path.relpath(auxiliary_dir, library_file_dir) |
| 1118 imports_emitter = library_emitter.Emit( | 1116 imports_emitter = library_emitter.Emit( |
| 1119 self._template, AUXILIARY_DIR=massage_path(auxiliary_dir)) | 1117 self._template, AUXILIARY_DIR=massage_path(auxiliary_dir)) |
| 1120 for path in sorted(self._path_to_emitter.keys()): | 1118 for path in sorted(self._path_to_emitter.keys()): |
| 1121 relpath = os.path.relpath(path, library_file_dir) | 1119 relpath = os.path.relpath(path, library_file_dir) |
| 1122 imports_emitter.Emit( | 1120 imports_emitter.Emit( |
| 1123 "#source('$PATH');\n", PATH=massage_path(relpath)) | 1121 "#source('$PATH');\n", PATH=massage_path(relpath)) |
| OLD | NEW |