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 generates Dart APIs from the IDL database.""" | 6 """This module generates Dart APIs from the IDL database.""" |
7 | 7 |
8 import emitter | 8 import emitter |
9 import idlnode | 9 import idlnode |
10 import logging | 10 import logging |
(...skipping 860 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
871 """Generates a typedef for the callback interface.""" | 871 """Generates a typedef for the callback interface.""" |
872 self._dart_callback_file_paths.append(file_path) | 872 self._dart_callback_file_paths.append(file_path) |
873 code = self._emitters.FileEmitter(file_path) | 873 code = self._emitters.FileEmitter(file_path) |
874 | 874 |
875 code.Emit(self._templates.Load('callback.darttemplate')) | 875 code.Emit(self._templates.Load('callback.darttemplate')) |
876 code.Emit('typedef $TYPE $NAME($PARAMS);\n', | 876 code.Emit('typedef $TYPE $NAME($PARAMS);\n', |
877 NAME=interface.id, | 877 NAME=interface.id, |
878 TYPE=info.type_name, | 878 TYPE=info.type_name, |
879 PARAMS=info.ParametersImplementationDeclaration()) | 879 PARAMS=info.ParametersImplementationDeclaration()) |
880 | 880 |
881 def _GenerateLibFile(self, lib_template, lib_file_path, file_paths): | 881 def _GenerateLibFile(self, lib_template, lib_file_path, file_paths, |
882 """Generates a lib file from a template and a list of files.""" | 882 **template_args): |
| 883 """Generates a lib file from a template and a list of files. |
| 884 |
| 885 Additional keyword arguments are passed to the template. |
| 886 """ |
883 # Load template. | 887 # Load template. |
884 template = self._templates.Load(lib_template) | 888 template = self._templates.Load(lib_template) |
885 # Generate the .lib file. | 889 # Generate the .lib file. |
886 lib_file_contents = self._emitters.FileEmitter(lib_file_path) | 890 lib_file_contents = self._emitters.FileEmitter(lib_file_path) |
887 | 891 |
888 # Emit the list of #source directives. | 892 # Emit the list of #source directives. |
889 list_emitter = lib_file_contents.Emit(template) | 893 list_emitter = lib_file_contents.Emit(template, **template_args) |
890 lib_file_dir = os.path.dirname(lib_file_path) | 894 lib_file_dir = os.path.dirname(lib_file_path) |
891 for path in sorted(file_paths): | 895 for path in sorted(file_paths): |
892 relpath = os.path.relpath(path, lib_file_dir) | 896 relpath = os.path.relpath(path, lib_file_dir) |
893 list_emitter.Emit("#source('$PATH');\n", PATH=relpath) | 897 list_emitter.Emit("#source('$PATH');\n", PATH=relpath) |
894 | 898 |
895 | 899 |
896 def _BaseDefines(self, interface): | 900 def _BaseDefines(self, interface): |
897 """Returns a set of names (strings) for members defined in a base class. | 901 """Returns a set of names (strings) for members defined in a base class. |
898 """ | 902 """ |
899 def WalkParentChain(interface): | 903 def WalkParentChain(interface): |
(...skipping 1203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2103 self._BaseDefines(interface), | 2107 self._BaseDefines(interface), |
2104 self._templates) | 2108 self._templates) |
2105 | 2109 |
2106 def ProcessCallback(self, interface, info): | 2110 def ProcessCallback(self, interface, info): |
2107 self._dom_public_files.append(self._FilePathForDartInterface(interface.id)) | 2111 self._dom_public_files.append(self._FilePathForDartInterface(interface.id)) |
2108 | 2112 |
2109 def GenerateLibraries(self, lib_dir): | 2113 def GenerateLibraries(self, lib_dir): |
2110 auxiliary_dir = os.path.relpath(self._auxiliary_dir, self._output_dir) | 2114 auxiliary_dir = os.path.relpath(self._auxiliary_dir, self._output_dir) |
2111 | 2115 |
2112 # Generate dom_public.dart. | 2116 # Generate dom_public.dart. |
2113 dom_public_path = os.path.join(self._output_dir, 'dom_public.dart') | 2117 self._GenerateLibFile( |
2114 | 2118 'dom_public.darttemplate', |
2115 dom_public_imports_emitter = emitter.Emitter() | 2119 os.path.join(self._output_dir, 'dom_public.dart'), |
2116 for file in self._dom_public_files: | 2120 self._dom_public_files, |
2117 path = os.path.relpath(file, os.path.dirname(dom_public_path)) | 2121 AUXILIARY_DIR=auxiliary_dir); |
2118 dom_public_imports_emitter.Emit('#source("$PATH");\n', PATH=path) | |
2119 | |
2120 dom_public_emitter = self._emitters.FileEmitter(dom_public_path) | |
2121 dom_public_emitter.Emit(self._templates.Load('dom_public.darttemplate'), | |
2122 AUXILIARY_DIR=auxiliary_dir, | |
2123 SOURCES=dom_public_imports_emitter.Fragments()) | |
2124 | 2122 |
2125 # Generate dom_impl.dart. | 2123 # Generate dom_impl.dart. |
2126 dom_impl_path = os.path.join(self._output_dir, 'dom_impl.dart') | 2124 self._GenerateLibFile( |
2127 | 2125 'dom_impl.darttemplate', |
2128 dom_impl_imports_emitter = emitter.Emitter() | 2126 os.path.join(self._output_dir, 'dom_impl.dart'), |
2129 for file in self._dom_impl_files: | 2127 self._dom_impl_files, |
2130 path = os.path.relpath(file, os.path.dirname(dom_impl_path)) | 2128 AUXILIARY_DIR=auxiliary_dir); |
2131 dom_impl_imports_emitter.Emit('#source("$PATH");\n', PATH=path) | |
2132 | |
2133 dom_impl_emitter = self._emitters.FileEmitter(dom_impl_path) | |
2134 dom_impl_emitter.Emit(self._templates.Load('dom_impl.darttemplate'), | |
2135 AUXILIARY_DIR=auxiliary_dir, | |
2136 SOURCES=dom_impl_imports_emitter.Fragments()) | |
2137 | 2129 |
2138 def Finish(self): | 2130 def Finish(self): |
2139 pass | 2131 pass |
2140 | 2132 |
2141 def _FilePathForDartInterface(self, interface_name): | 2133 def _FilePathForDartInterface(self, interface_name): |
2142 return os.path.join(self._output_dir, 'src', 'interface', | 2134 return os.path.join(self._output_dir, 'src', 'interface', |
2143 '%s.dart' % interface_name) | 2135 '%s.dart' % interface_name) |
2144 | 2136 |
2145 def _FilePathForDartImplementation(self, interface_name): | 2137 def _FilePathForDartImplementation(self, interface_name): |
2146 return os.path.join(self._output_dir, 'dart', | 2138 return os.path.join(self._output_dir, 'dart', |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2290 INDENT=indent, | 2282 INDENT=indent, |
2291 NATIVENAME=native_name, | 2283 NATIVENAME=native_name, |
2292 ARGS=argument_expressions) | 2284 ARGS=argument_expressions) |
2293 | 2285 |
2294 self._members_emitter.Emit(' $TYPE $NATIVE_NAME($PARAMS) native ' | 2286 self._members_emitter.Emit(' $TYPE $NATIVE_NAME($PARAMS) native ' |
2295 '"$(INTERFACE)$(NATIVE_NAME)_Callback";\n', | 2287 '"$(INTERFACE)$(NATIVE_NAME)_Callback";\n', |
2296 NATIVE_NAME=native_name, | 2288 NATIVE_NAME=native_name, |
2297 TYPE=info.type_name, | 2289 TYPE=info.type_name, |
2298 PARAMS=', '.join(arg_names), | 2290 PARAMS=', '.join(arg_names), |
2299 INTERFACE=self._interface.id) | 2291 INTERFACE=self._interface.id) |
OLD | NEW |