| 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 systems to generate | 6 """This module provides shared functionality for the systems to generate |
| 7 native binding from the IDL database.""" | 7 native binding from the IDL database.""" |
| 8 | 8 |
| 9 import emitter | 9 import emitter |
| 10 import os | 10 import os |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 self._template_loader = options.templates | 21 self._template_loader = options.templates |
| 22 self._type_registry = options.type_registry | 22 self._type_registry = options.type_registry |
| 23 self._html_interface_name = options.renamer.RenameInterface(self._interface) | 23 self._html_interface_name = options.renamer.RenameInterface(self._interface) |
| 24 | 24 |
| 25 def HasImplementation(self): | 25 def HasImplementation(self): |
| 26 return not IsPureInterface(self._interface.id) | 26 return not IsPureInterface(self._interface.id) |
| 27 | 27 |
| 28 def ImplementationClassName(self): | 28 def ImplementationClassName(self): |
| 29 return self._ImplClassName(self._interface.id) | 29 return self._ImplClassName(self._interface.id) |
| 30 | 30 |
| 31 def SetImplementationEmitter(self, implementation_emitter): | |
| 32 self._dart_impl_emitter = implementation_emitter | |
| 33 | |
| 34 def ImplementsMergedMembers(self): | 31 def ImplementsMergedMembers(self): |
| 35 # We could not add merged functions to implementation class because | 32 # We could not add merged functions to implementation class because |
| 36 # underlying c++ object doesn't implement them. Merged functions are | 33 # underlying c++ object doesn't implement them. Merged functions are |
| 37 # generated on merged interface implementation instead. | 34 # generated on merged interface implementation instead. |
| 38 return False | 35 return False |
| 39 | 36 |
| 40 def CustomJSMembers(self): | 37 def CustomJSMembers(self): |
| 41 return {} | 38 return {} |
| 42 | 39 |
| 43 def GenerateCallback(self, info): | 40 def GenerateCallback(self, info): |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 INTERFACE=self._interface.id, | 90 INTERFACE=self._interface.id, |
| 94 HANDLERS=cpp_header_handlers_emitter.Fragments()) | 91 HANDLERS=cpp_header_handlers_emitter.Fragments()) |
| 95 | 92 |
| 96 cpp_impl_emitter = self._cpp_library_emitter.CreateSourceEmitter(self._inter
face.id) | 93 cpp_impl_emitter = self._cpp_library_emitter.CreateSourceEmitter(self._inter
face.id) |
| 97 cpp_impl_emitter.Emit( | 94 cpp_impl_emitter.Emit( |
| 98 self._template_loader.Load('cpp_callback_implementation.template'), | 95 self._template_loader.Load('cpp_callback_implementation.template'), |
| 99 INCLUDES=self._GenerateCPPIncludes(cpp_impl_includes), | 96 INCLUDES=self._GenerateCPPIncludes(cpp_impl_includes), |
| 100 INTERFACE=self._interface.id, | 97 INTERFACE=self._interface.id, |
| 101 HANDLERS=cpp_impl_handlers_emitter.Fragments()) | 98 HANDLERS=cpp_impl_handlers_emitter.Fragments()) |
| 102 | 99 |
| 103 def StartInterface(self): | 100 def ImplementationTemplate(self): |
| 101 template = None |
| 102 if self._html_interface_name == self._interface.id or not self._database.Has
Interface(self._html_interface_name): |
| 103 template_file = 'impl_%s.darttemplate' % self._html_interface_name |
| 104 template = self._template_loader.TryLoad(template_file) |
| 105 if not template: |
| 106 template = self._template_loader.Load('dart_implementation.darttemplate') |
| 107 return template |
| 108 |
| 109 def AdditionalImplementedInterfaces(self): |
| 110 return [] |
| 111 |
| 112 def NativeSpec(self): |
| 113 return '' |
| 114 |
| 115 def StartInterface(self, memebers_emitter): |
| 104 # Create emitters for c++ implementation. | 116 # Create emitters for c++ implementation. |
| 105 if self.HasImplementation(): | 117 if self.HasImplementation(): |
| 106 self._cpp_header_emitter = self._cpp_library_emitter.CreateHeaderEmitter(s
elf._interface.id) | 118 self._cpp_header_emitter = self._cpp_library_emitter.CreateHeaderEmitter(s
elf._interface.id) |
| 107 self._cpp_impl_emitter = self._cpp_library_emitter.CreateSourceEmitter(sel
f._interface.id) | 119 self._cpp_impl_emitter = self._cpp_library_emitter.CreateSourceEmitter(sel
f._interface.id) |
| 108 else: | 120 else: |
| 109 self._cpp_header_emitter = emitter.Emitter() | 121 self._cpp_header_emitter = emitter.Emitter() |
| 110 self._cpp_impl_emitter = emitter.Emitter() | 122 self._cpp_impl_emitter = emitter.Emitter() |
| 111 | 123 |
| 112 self._interface_type_info = self._TypeInfo(self._interface.id) | 124 self._interface_type_info = self._TypeInfo(self._interface.id) |
| 113 self._members_emitter = emitter.Emitter() | 125 self._members_emitter = memebers_emitter |
| 114 self._cpp_declarations_emitter = emitter.Emitter() | 126 self._cpp_declarations_emitter = emitter.Emitter() |
| 115 self._cpp_impl_includes = set() | 127 self._cpp_impl_includes = set() |
| 116 self._cpp_definitions_emitter = emitter.Emitter() | 128 self._cpp_definitions_emitter = emitter.Emitter() |
| 117 self._cpp_resolver_emitter = emitter.Emitter() | 129 self._cpp_resolver_emitter = emitter.Emitter() |
| 118 | 130 |
| 119 self._GenerateConstructors() | 131 self._GenerateConstructors() |
| 120 return self._members_emitter | |
| 121 | 132 |
| 122 def _GenerateConstructors(self): | 133 def _GenerateConstructors(self): |
| 123 if not self._IsConstructable(): | 134 if not self._IsConstructable(): |
| 124 return | 135 return |
| 125 | 136 |
| 126 # TODO(antonm): currently we don't have information about number of argument
s expected by | 137 # TODO(antonm): currently we don't have information about number of argument
s expected by |
| 127 # the constructor, so name only dispatch. | 138 # the constructor, so name only dispatch. |
| 128 self._cpp_resolver_emitter.Emit( | 139 self._cpp_resolver_emitter.Emit( |
| 129 ' if (name == "$(INTERFACE_NAME)_constructor_Callback")\n' | 140 ' if (name == "$(INTERFACE_NAME)_constructor_Callback")\n' |
| 130 ' return Dart$(INTERFACE_NAME)Internal::constructorCallback;\n', | 141 ' return Dart$(INTERFACE_NAME)Internal::constructorCallback;\n', |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 False, | 173 False, |
| 163 function_expression, | 174 function_expression, |
| 164 self._interface, | 175 self._interface, |
| 165 constructor_info.idl_args, | 176 constructor_info.idl_args, |
| 166 self._interface.id, | 177 self._interface.id, |
| 167 'ConstructorRaisesException' in ext_attrs) | 178 'ConstructorRaisesException' in ext_attrs) |
| 168 | 179 |
| 169 def _ImplClassName(self, interface_name): | 180 def _ImplClassName(self, interface_name): |
| 170 return '_%sImpl' % interface_name | 181 return '_%sImpl' % interface_name |
| 171 | 182 |
| 172 def _BaseClassName(self): | 183 def BaseClassName(self): |
| 173 root_class = 'NativeFieldWrapperClass1' | 184 root_class = 'NativeFieldWrapperClass1' |
| 174 | 185 |
| 175 if not self._interface.parents: | 186 if not self._interface.parents: |
| 176 return root_class | 187 return root_class |
| 177 | 188 |
| 178 supertype = self._interface.parents[0].type.id | 189 supertype = self._interface.parents[0].type.id |
| 179 | 190 |
| 180 if IsPureInterface(supertype): # The class is a root. | 191 if IsPureInterface(supertype): # The class is a root. |
| 181 return root_class | 192 return root_class |
| 182 | 193 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 native_binding = '%s_constructor_Callback' % self._interface.id | 228 native_binding = '%s_constructor_Callback' % self._interface.id |
| 218 emitter.Emit( | 229 emitter.Emit( |
| 219 template, | 230 template, |
| 220 FACTORYPROVIDER=factory_provider, | 231 FACTORYPROVIDER=factory_provider, |
| 221 INTERFACE=self._html_interface_name, | 232 INTERFACE=self._html_interface_name, |
| 222 PARAMETERS=constructor_info.ParametersImplementationDeclaration(self._Da
rtType), | 233 PARAMETERS=constructor_info.ParametersImplementationDeclaration(self._Da
rtType), |
| 223 ARGUMENTS=constructor_info.ParametersAsArgumentList(), | 234 ARGUMENTS=constructor_info.ParametersAsArgumentList(), |
| 224 NATIVE_NAME=native_binding) | 235 NATIVE_NAME=native_binding) |
| 225 | 236 |
| 226 def FinishInterface(self): | 237 def FinishInterface(self): |
| 227 template = None | |
| 228 if self._html_interface_name == self._interface.id or not self._database.Has
Interface(self._html_interface_name): | |
| 229 template_file = 'impl_%s.darttemplate' % self._html_interface_name | |
| 230 template = self._template_loader.TryLoad(template_file) | |
| 231 if not template: | |
| 232 template = self._template_loader.Load('dart_implementation.darttemplate') | |
| 233 | |
| 234 class_name = self._ImplClassName(self._interface.id) | |
| 235 members_emitter = self._dart_impl_emitter.Emit( | |
| 236 template, | |
| 237 CLASSNAME=class_name, | |
| 238 EXTENDS=' extends ' + self._BaseClassName(), | |
| 239 IMPLEMENTS=' implements ' + self._html_interface_name, | |
| 240 NATIVESPEC='') | |
| 241 members_emitter.Emit(''.join(self._members_emitter.Fragments())) | |
| 242 | |
| 243 self._GenerateCPPHeader() | 238 self._GenerateCPPHeader() |
| 244 | 239 |
| 245 self._cpp_impl_emitter.Emit( | 240 self._cpp_impl_emitter.Emit( |
| 246 self._template_loader.Load('cpp_implementation.template'), | 241 self._template_loader.Load('cpp_implementation.template'), |
| 247 INTERFACE=self._interface.id, | 242 INTERFACE=self._interface.id, |
| 248 INCLUDES=self._GenerateCPPIncludes(self._cpp_impl_includes), | 243 INCLUDES=self._GenerateCPPIncludes(self._cpp_impl_includes), |
| 249 CALLBACKS=self._cpp_definitions_emitter.Fragments(), | 244 CALLBACKS=self._cpp_definitions_emitter.Fragments(), |
| 250 RESOLVER=self._cpp_resolver_emitter.Fragments(), | 245 RESOLVER=self._cpp_resolver_emitter.Fragments(), |
| 251 DART_IMPLEMENTATION_CLASS=class_name) | 246 DART_IMPLEMENTATION_CLASS=self.ImplementationClassName()) |
| 252 | 247 |
| 253 def _GenerateCPPHeader(self): | 248 def _GenerateCPPHeader(self): |
| 254 to_native_emitter = emitter.Emitter() | 249 to_native_emitter = emitter.Emitter() |
| 255 if self._interface_type_info.custom_to_native(): | 250 if self._interface_type_info.custom_to_native(): |
| 256 to_native_emitter.Emit( | 251 to_native_emitter.Emit( |
| 257 ' static PassRefPtr<NativeType> toNative(Dart_Handle handle, Dart_H
andle& exception);\n') | 252 ' static PassRefPtr<NativeType> toNative(Dart_Handle handle, Dart_H
andle& exception);\n') |
| 258 else: | 253 else: |
| 259 to_native_emitter.Emit( | 254 to_native_emitter.Emit( |
| 260 ' static NativeType* toNative(Dart_Handle handle, Dart_Handle& exce
ption)\n' | 255 ' static NativeType* toNative(Dart_Handle handle, Dart_Handle& exce
ption)\n' |
| 261 ' {\n' | 256 ' {\n' |
| (...skipping 629 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 891 def EmitResolver(self, template, output_dir): | 886 def EmitResolver(self, template, output_dir): |
| 892 file_path = os.path.join(output_dir, 'DartResolver.cpp') | 887 file_path = os.path.join(output_dir, 'DartResolver.cpp') |
| 893 includes_emitter, body_emitter = self._emitters.FileEmitter(file_path).Emit(
template) | 888 includes_emitter, body_emitter = self._emitters.FileEmitter(file_path).Emit(
template) |
| 894 for header_file in self._headers_list: | 889 for header_file in self._headers_list: |
| 895 path = os.path.relpath(header_file, output_dir) | 890 path = os.path.relpath(header_file, output_dir) |
| 896 includes_emitter.Emit('#include "$PATH"\n', PATH=path) | 891 includes_emitter.Emit('#include "$PATH"\n', PATH=path) |
| 897 body_emitter.Emit( | 892 body_emitter.Emit( |
| 898 ' if (Dart_NativeFunction func = $CLASS_NAME::resolver(name, argume
ntCount))\n' | 893 ' if (Dart_NativeFunction func = $CLASS_NAME::resolver(name, argume
ntCount))\n' |
| 899 ' return func;\n', | 894 ' return func;\n', |
| 900 CLASS_NAME=os.path.splitext(os.path.basename(path))[0]) | 895 CLASS_NAME=os.path.splitext(os.path.basename(path))[0]) |
| OLD | NEW |