| 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 |
| 11 from generator import * | 11 from generator import * |
| 12 from systemhtml import SecureOutputType | 12 from systemhtml import SecureOutputType |
| 13 | 13 |
| 14 class DartiumBackend(object): | 14 class DartiumBackend(object): |
| 15 """Generates Dart implementation for one DOM IDL interface.""" | 15 """Generates Dart implementation for one DOM IDL interface.""" |
| 16 | 16 |
| 17 def __init__(self, interface, cpp_library_emitter, options): | 17 def __init__(self, interface, cpp_library_emitter, options): |
| 18 self._interface = interface | 18 self._interface = interface |
| 19 self._cpp_library_emitter = cpp_library_emitter | 19 self._cpp_library_emitter = cpp_library_emitter |
| 20 self._database = options.database | 20 self._database = options.database |
| 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._interface_type_info = self._type_registry.TypeInfo(self._interface.id) | 23 self._interface_type_info = self._type_registry.TypeInfo(self._interface.id) |
| 24 | 24 |
| 25 def ImplementationClassName(self): | |
| 26 return self._ImplClassName(self._interface.id) | |
| 27 | |
| 28 def ImplementsMergedMembers(self): | 25 def ImplementsMergedMembers(self): |
| 29 # We could not add merged functions to implementation class because | 26 # We could not add merged functions to implementation class because |
| 30 # underlying c++ object doesn't implement them. Merged functions are | 27 # underlying c++ object doesn't implement them. Merged functions are |
| 31 # generated on merged interface implementation instead. | 28 # generated on merged interface implementation instead. |
| 32 return False | 29 return False |
| 33 | 30 |
| 34 def CustomJSMembers(self): | 31 def CustomJSMembers(self): |
| 35 return {} | 32 return {} |
| 36 | 33 |
| 37 def GenerateCallback(self, info): | 34 def GenerateCallback(self, info): |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 function_expression = '%s::%s' % (self._interface_type_info.native_type(), c
reate_function) | 165 function_expression = '%s::%s' % (self._interface_type_info.native_type(), c
reate_function) |
| 169 self._GenerateNativeCallback( | 166 self._GenerateNativeCallback( |
| 170 'constructorCallback', | 167 'constructorCallback', |
| 171 False, | 168 False, |
| 172 function_expression, | 169 function_expression, |
| 173 self._interface, | 170 self._interface, |
| 174 constructor_info.idl_args, | 171 constructor_info.idl_args, |
| 175 self._interface.id, | 172 self._interface.id, |
| 176 'ConstructorRaisesException' in ext_attrs) | 173 'ConstructorRaisesException' in ext_attrs) |
| 177 | 174 |
| 178 def _ImplClassName(self, interface_name): | |
| 179 return '_%sImpl' % interface_name | |
| 180 | |
| 181 def BaseClassName(self): | 175 def BaseClassName(self): |
| 182 root_class = 'NativeFieldWrapperClass1' | 176 root_class = 'NativeFieldWrapperClass1' |
| 183 | 177 |
| 184 if not self._interface.parents: | 178 if not self._interface.parents: |
| 185 return root_class | 179 return root_class |
| 186 | 180 |
| 187 supertype = self._interface.parents[0].type.id | 181 supertype = self._interface.parents[0].type.id |
| 188 | 182 |
| 189 if IsPureInterface(supertype): # The class is a root. | 183 if IsPureInterface(supertype): # The class is a root. |
| 190 return root_class | 184 return root_class |
| 191 | 185 |
| 192 # FIXME: We're currently injecting List<..> and EventTarget as | 186 # FIXME: We're currently injecting List<..> and EventTarget as |
| 193 # supertypes in dart.idl. We should annotate/preserve as | 187 # supertypes in dart.idl. We should annotate/preserve as |
| 194 # attributes instead. For now, this hack lets the self._interfaces | 188 # attributes instead. For now, this hack lets the self._interfaces |
| 195 # inherit, but not the classes. | 189 # inherit, but not the classes. |
| 196 # List methods are injected in AddIndexer. | 190 # List methods are injected in AddIndexer. |
| 197 if IsDartListType(supertype) or IsDartCollectionType(supertype): | 191 if IsDartListType(supertype) or IsDartCollectionType(supertype): |
| 198 return root_class | 192 return root_class |
| 199 | 193 |
| 200 return self._ImplClassName(supertype) | 194 return self._type_registry.TypeInfo(supertype).implementation_name() |
| 201 | 195 |
| 202 ATTRIBUTES_OF_CONSTRUCTABLE = set([ | 196 ATTRIBUTES_OF_CONSTRUCTABLE = set([ |
| 203 'CustomConstructor', | 197 'CustomConstructor', |
| 204 'V8CustomConstructor', | 198 'V8CustomConstructor', |
| 205 'Constructor', | 199 'Constructor', |
| 206 'NamedConstructor']) | 200 'NamedConstructor']) |
| 207 | 201 |
| 208 def _IsConstructable(self): | 202 def _IsConstructable(self): |
| 209 ext_attrs = self._interface.ext_attrs | 203 ext_attrs = self._interface.ext_attrs |
| 210 | 204 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 235 | 229 |
| 236 def FinishInterface(self): | 230 def FinishInterface(self): |
| 237 self._GenerateCPPHeader() | 231 self._GenerateCPPHeader() |
| 238 | 232 |
| 239 self._cpp_impl_emitter.Emit( | 233 self._cpp_impl_emitter.Emit( |
| 240 self._template_loader.Load('cpp_implementation.template'), | 234 self._template_loader.Load('cpp_implementation.template'), |
| 241 INTERFACE=self._interface.id, | 235 INTERFACE=self._interface.id, |
| 242 INCLUDES=self._GenerateCPPIncludes(self._cpp_impl_includes), | 236 INCLUDES=self._GenerateCPPIncludes(self._cpp_impl_includes), |
| 243 CALLBACKS=self._cpp_definitions_emitter.Fragments(), | 237 CALLBACKS=self._cpp_definitions_emitter.Fragments(), |
| 244 RESOLVER=self._cpp_resolver_emitter.Fragments(), | 238 RESOLVER=self._cpp_resolver_emitter.Fragments(), |
| 245 DART_IMPLEMENTATION_CLASS=self.ImplementationClassName()) | 239 DART_IMPLEMENTATION_CLASS=self._interface_type_info.implementation_name(
)) |
| 246 | 240 |
| 247 def _GenerateCPPHeader(self): | 241 def _GenerateCPPHeader(self): |
| 248 to_native_emitter = emitter.Emitter() | 242 to_native_emitter = emitter.Emitter() |
| 249 if self._interface_type_info.custom_to_native(): | 243 if self._interface_type_info.custom_to_native(): |
| 250 to_native_emitter.Emit( | 244 to_native_emitter.Emit( |
| 251 ' static PassRefPtr<NativeType> toNative(Dart_Handle handle, Dart_H
andle& exception);\n') | 245 ' static PassRefPtr<NativeType> toNative(Dart_Handle handle, Dart_H
andle& exception);\n') |
| 252 else: | 246 else: |
| 253 to_native_emitter.Emit( | 247 to_native_emitter.Emit( |
| 254 ' static NativeType* toNative(Dart_Handle handle, Dart_Handle& exce
ption)\n' | 248 ' static NativeType* toNative(Dart_Handle handle, Dart_Handle& exce
ption)\n' |
| 255 ' {\n' | 249 ' {\n' |
| (...skipping 629 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 885 def EmitResolver(self, template, output_dir): | 879 def EmitResolver(self, template, output_dir): |
| 886 file_path = os.path.join(output_dir, 'DartResolver.cpp') | 880 file_path = os.path.join(output_dir, 'DartResolver.cpp') |
| 887 includes_emitter, body_emitter = self._emitters.FileEmitter(file_path).Emit(
template) | 881 includes_emitter, body_emitter = self._emitters.FileEmitter(file_path).Emit(
template) |
| 888 for header_file in self._headers_list: | 882 for header_file in self._headers_list: |
| 889 path = os.path.relpath(header_file, output_dir) | 883 path = os.path.relpath(header_file, output_dir) |
| 890 includes_emitter.Emit('#include "$PATH"\n', PATH=path) | 884 includes_emitter.Emit('#include "$PATH"\n', PATH=path) |
| 891 body_emitter.Emit( | 885 body_emitter.Emit( |
| 892 ' if (Dart_NativeFunction func = $CLASS_NAME::resolver(name, argume
ntCount))\n' | 886 ' if (Dart_NativeFunction func = $CLASS_NAME::resolver(name, argume
ntCount))\n' |
| 893 ' return func;\n', | 887 ' return func;\n', |
| 894 CLASS_NAME=os.path.splitext(os.path.basename(path))[0]) | 888 CLASS_NAME=os.path.splitext(os.path.basename(path))[0]) |
| OLD | NEW |