| 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 HasCustomFactory(self): |
| 164 constructor_callback_id = self._interface.id + '_constructor_Callback' | 164 return False |
| 165 |
| 166 def IsConstructorArgumentOptional(self, argument): |
| 167 return False |
| 168 |
| 169 def EmitStaticFactoryOverload(self, constructor_info, name, arguments): |
| 170 constructor_callback_cpp_name = name + '_constructor_Callback' |
| 171 constructor_callback_id = self._interface.id + constructor_callback_cpp_name |
| 165 | 172 |
| 166 self._members_emitter.Emit( | 173 self._members_emitter.Emit( |
| 167 ' static $INTERFACE_NAME _create($PARAMETERS_DECLARATION) ' | 174 ' static $INTERFACE_NAME $NAME($PARAMETERS) ' |
| 168 'native "$CONSTRUCTOR_CALLBACK_ID";\n', | 175 'native "$CONSTRUCTOR_CALLBACK_ID";\n', |
| 169 INTERFACE_NAME=self._interface_type_info.interface_name(), | 176 INTERFACE_NAME=self._interface_type_info.interface_name(), |
| 170 PARAMETERS_DECLARATION=constructor_info.ParametersDeclaration( | 177 NAME=name, |
| 171 self._DartType), | 178 # TODO: add types to parameters. |
| 179 PARAMETERS=constructor_info.ParametersAsArgumentList(len(arguments)), |
| 172 CONSTRUCTOR_CALLBACK_ID=constructor_callback_id) | 180 CONSTRUCTOR_CALLBACK_ID=constructor_callback_id) |
| 173 | 181 |
| 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( | 182 self._cpp_resolver_emitter.Emit( |
| 177 ' if (name == "$CONSTRUCTOR_CALLBACK_ID")\n' | 183 ' if (name == "$CONSTRUCTOR_CALLBACK_ID")\n' |
| 178 ' return Dart$(WEBKIT_INTERFACE_NAME)Internal::constructorCallbac
k;\n', | 184 ' return Dart$(WEBKIT_INTERFACE_NAME)Internal::$NAME;\n', |
| 179 CONSTRUCTOR_CALLBACK_ID=constructor_callback_id, | 185 CONSTRUCTOR_CALLBACK_ID=constructor_callback_id, |
| 180 WEBKIT_INTERFACE_NAME=self._interface.id) | 186 WEBKIT_INTERFACE_NAME=self._interface.id, |
| 187 NAME=constructor_callback_cpp_name) |
| 181 | 188 |
| 182 ext_attrs = self._interface.ext_attrs | 189 ext_attrs = self._interface.ext_attrs |
| 183 | 190 |
| 184 if 'CustomConstructor' in ext_attrs: | 191 if 'CustomConstructor' in ext_attrs: |
| 185 # We have a custom implementation for it. | 192 # We have a custom implementation for it. |
| 186 self._cpp_declarations_emitter.Emit( | 193 self._cpp_declarations_emitter.Emit( |
| 187 '\n' | 194 '\n' |
| 188 'void constructorCallback(Dart_NativeArguments);\n') | 195 'void $NAME(Dart_NativeArguments);\n', |
| 196 NAME=constructor_callback_cpp_name) |
| 189 return | 197 return |
| 190 | 198 |
| 191 create_function = 'create' | 199 create_function = 'create' |
| 192 if 'NamedConstructor' in ext_attrs: | 200 if 'NamedConstructor' in ext_attrs: |
| 193 create_function = 'createForJSConstructor' | 201 create_function = 'createForJSConstructor' |
| 194 function_expression = '%s::%s' % (self._interface_type_info.native_type(), c
reate_function) | 202 function_expression = '%s::%s' % (self._interface_type_info.native_type(), c
reate_function) |
| 195 self._GenerateNativeCallback( | 203 self._GenerateNativeCallback( |
| 196 'constructorCallback', | 204 constructor_callback_cpp_name, |
| 197 False, | 205 False, |
| 198 function_expression, | 206 function_expression, |
| 199 self._interface, | 207 self._interface, |
| 200 constructor_info.idl_args, | 208 arguments, |
| 201 self._interface.id, | 209 self._interface.id, |
| 202 'ConstructorRaisesException' in ext_attrs) | 210 'ConstructorRaisesException' in ext_attrs) |
| 203 | 211 |
| 204 def HasSupportCheck(self): | 212 def HasSupportCheck(self): |
| 205 # Need to omit a support check if it is conditional in JS. | 213 # Need to omit a support check if it is conditional in JS. |
| 206 return self._interface.doc_js_name in js_support_checks | 214 return self._interface.doc_js_name in js_support_checks |
| 207 | 215 |
| 208 def GetSupportCheck(self): | 216 def GetSupportCheck(self): |
| 209 # Assume that everything is supported on Dartium. | 217 # Assume that everything is supported on Dartium. |
| 210 return 'true' | 218 return 'true' |
| (...skipping 641 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 852 LIBRARY_NAME=library_name) | 860 LIBRARY_NAME=library_name) |
| 853 | 861 |
| 854 headers = self._library_headers[library_name] | 862 headers = self._library_headers[library_name] |
| 855 for header_file in headers: | 863 for header_file in headers: |
| 856 path = os.path.relpath(header_file, output_dir) | 864 path = os.path.relpath(header_file, output_dir) |
| 857 includes_emitter.Emit('#include "$PATH"\n', PATH=path) | 865 includes_emitter.Emit('#include "$PATH"\n', PATH=path) |
| 858 body_emitter.Emit( | 866 body_emitter.Emit( |
| 859 ' if (Dart_NativeFunction func = $CLASS_NAME::resolver(name, argu
mentCount))\n' | 867 ' if (Dart_NativeFunction func = $CLASS_NAME::resolver(name, argu
mentCount))\n' |
| 860 ' return func;\n', | 868 ' return func;\n', |
| 861 CLASS_NAME=os.path.splitext(os.path.basename(path))[0]) | 869 CLASS_NAME=os.path.splitext(os.path.basename(path))[0]) |
| OLD | NEW |