| 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 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 # to construct wrappers from C++. Eventually it should go away | 153 # to construct wrappers from C++. Eventually it should go away |
| 154 # once it is possible to construct such an instance directly. | 154 # once it is possible to construct such an instance directly. |
| 155 super_constructor = '' | 155 super_constructor = '' |
| 156 if base_class and base_class != 'NativeFieldWrapperClass1': | 156 if base_class and base_class != 'NativeFieldWrapperClass1': |
| 157 super_constructor = ' : super.internal()' | 157 super_constructor = ' : super.internal()' |
| 158 self._members_emitter.Emit( | 158 self._members_emitter.Emit( |
| 159 ' $CLASSNAME.internal()$SUPERCONSTRUCTOR;\n', | 159 ' $CLASSNAME.internal()$SUPERCONSTRUCTOR;\n', |
| 160 CLASSNAME=self._interface_type_info.implementation_name(), | 160 CLASSNAME=self._interface_type_info.implementation_name(), |
| 161 SUPERCONSTRUCTOR=super_constructor) | 161 SUPERCONSTRUCTOR=super_constructor) |
| 162 | 162 |
| 163 def EmitStaticFactory(self, constructor_info): | 163 def _EmitConstructorInfrastructure(self, |
| 164 constructor_callback_id = self._interface.id + '_constructor_Callback' | 164 constructor_info, constructor_callback_cpp_name, factory_method_name, |
| 165 argument_count=None): |
| 166 constructor_callback_id = self._interface.id + '_' + constructor_callback_cp
p_name |
| 167 if argument_count is None: |
| 168 argument_count = len(constructor_info.param_infos) |
| 165 | 169 |
| 166 self._members_emitter.Emit( | 170 self._members_emitter.Emit( |
| 167 ' static $INTERFACE_NAME _create($PARAMETERS_DECLARATION) ' | 171 '\n @DocsEditable\n' |
| 168 'native "$CONSTRUCTOR_CALLBACK_ID";\n', | 172 ' static $INTERFACE_NAME $FACTORY_METHOD_NAME($PARAMETERS) ' |
| 173 'native "$ID";\n', |
| 169 INTERFACE_NAME=self._interface_type_info.interface_name(), | 174 INTERFACE_NAME=self._interface_type_info.interface_name(), |
| 170 PARAMETERS_DECLARATION=constructor_info.ParametersDeclaration( | 175 FACTORY_METHOD_NAME=factory_method_name, |
| 171 self._DartType), | 176 # TODO: add types to parameters. |
| 172 CONSTRUCTOR_CALLBACK_ID=constructor_callback_id) | 177 PARAMETERS=constructor_info.ParametersAsArgumentList(argument_count), |
| 178 ID=constructor_callback_id) |
| 173 | 179 |
| 174 # TODO(antonm): currently we don't have information about number of argument
s expected by | |
| 175 # the constructor, so name only dispatch. | |
| 176 self._cpp_resolver_emitter.Emit( | 180 self._cpp_resolver_emitter.Emit( |
| 177 ' if (name == "$CONSTRUCTOR_CALLBACK_ID")\n' | 181 ' if (name == "$ID")\n' |
| 178 ' return Dart$(WEBKIT_INTERFACE_NAME)Internal::constructorCallbac
k;\n', | 182 ' return Dart$(WEBKIT_INTERFACE_NAME)Internal::$CPP_CALLBACK;\n', |
| 179 CONSTRUCTOR_CALLBACK_ID=constructor_callback_id, | 183 ID=constructor_callback_id, |
| 180 WEBKIT_INTERFACE_NAME=self._interface.id) | 184 WEBKIT_INTERFACE_NAME=self._interface.id, |
| 185 CPP_CALLBACK=constructor_callback_cpp_name) |
| 186 |
| 187 def GenerateCustomFactory(self, constructor_info): |
| 188 if 'CustomConstructor' not in self._interface.ext_attrs: |
| 189 return False |
| 190 |
| 191 self._members_emitter.Emit( |
| 192 ' factory $CTOR($PARAMS) => _create($FACTORY_PARAMS);\n', |
| 193 CTOR=constructor_info._ConstructorFullName(self._DartType), |
| 194 PARAMS=constructor_info.ParametersDeclaration(self._DartType), |
| 195 FACTORY_PARAMS= \ |
| 196 constructor_info.ParametersAsArgumentList()) |
| 197 |
| 198 constructor_callback_cpp_name = 'constructorCallback' |
| 199 self._EmitConstructorInfrastructure( |
| 200 constructor_info, constructor_callback_cpp_name, '_create') |
| 201 |
| 202 self._cpp_declarations_emitter.Emit( |
| 203 '\n' |
| 204 'void $CPP_CALLBACK(Dart_NativeArguments);\n', |
| 205 CPP_CALLBACK=constructor_callback_cpp_name) |
| 206 |
| 207 return True |
| 208 |
| 209 def IsConstructorArgumentOptional(self, argument): |
| 210 return False |
| 211 |
| 212 def EmitStaticFactoryOverload(self, constructor_info, name, arguments): |
| 213 constructor_callback_cpp_name = name + 'constructorCallback' |
| 214 self._EmitConstructorInfrastructure( |
| 215 constructor_info, constructor_callback_cpp_name, name, len(arguments)) |
| 181 | 216 |
| 182 ext_attrs = self._interface.ext_attrs | 217 ext_attrs = self._interface.ext_attrs |
| 183 | 218 |
| 184 if 'CustomConstructor' in ext_attrs: | |
| 185 # We have a custom implementation for it. | |
| 186 self._cpp_declarations_emitter.Emit( | |
| 187 '\n' | |
| 188 'void constructorCallback(Dart_NativeArguments);\n') | |
| 189 return | |
| 190 | |
| 191 create_function = 'create' | 219 create_function = 'create' |
| 192 if 'NamedConstructor' in ext_attrs: | 220 if 'NamedConstructor' in ext_attrs: |
| 193 create_function = 'createForJSConstructor' | 221 create_function = 'createForJSConstructor' |
| 194 function_expression = '%s::%s' % (self._interface_type_info.native_type(), c
reate_function) | 222 function_expression = '%s::%s' % (self._interface_type_info.native_type(), c
reate_function) |
| 195 self._GenerateNativeCallback( | 223 self._GenerateNativeCallback( |
| 196 'constructorCallback', | 224 constructor_callback_cpp_name, |
| 197 False, | 225 False, |
| 198 function_expression, | 226 function_expression, |
| 199 self._interface, | 227 self._interface, |
| 200 constructor_info.idl_args, | 228 arguments, |
| 201 self._interface.id, | 229 self._interface.id, |
| 202 'ConstructorRaisesException' in ext_attrs) | 230 'ConstructorRaisesException' in ext_attrs) |
| 203 | 231 |
| 204 def HasSupportCheck(self): | 232 def HasSupportCheck(self): |
| 205 # Need to omit a support check if it is conditional in JS. | 233 # Need to omit a support check if it is conditional in JS. |
| 206 return self._interface.doc_js_name in js_support_checks | 234 return self._interface.doc_js_name in js_support_checks |
| 207 | 235 |
| 208 def GetSupportCheck(self): | 236 def GetSupportCheck(self): |
| 209 # Assume that everything is supported on Dartium. | 237 # Assume that everything is supported on Dartium. |
| 210 return 'true' | 238 return 'true' |
| (...skipping 644 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 855 LIBRARY_NAME=library_name) | 883 LIBRARY_NAME=library_name) |
| 856 | 884 |
| 857 headers = self._library_headers[library_name] | 885 headers = self._library_headers[library_name] |
| 858 for header_file in headers: | 886 for header_file in headers: |
| 859 path = os.path.relpath(header_file, output_dir) | 887 path = os.path.relpath(header_file, output_dir) |
| 860 includes_emitter.Emit('#include "$PATH"\n', PATH=path) | 888 includes_emitter.Emit('#include "$PATH"\n', PATH=path) |
| 861 body_emitter.Emit( | 889 body_emitter.Emit( |
| 862 ' if (Dart_NativeFunction func = $CLASS_NAME::resolver(name, argu
mentCount))\n' | 890 ' if (Dart_NativeFunction func = $CLASS_NAME::resolver(name, argu
mentCount))\n' |
| 863 ' return func;\n', | 891 ' return func;\n', |
| 864 CLASS_NAME=os.path.splitext(os.path.basename(path))[0]) | 892 CLASS_NAME=os.path.splitext(os.path.basename(path))[0]) |
| OLD | NEW |