| 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 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 316 | 316 |
| 317 def DeriveQualifiedName(library_name, name): | 317 def DeriveQualifiedName(library_name, name): |
| 318 return library_name + "." + name | 318 return library_name + "." + name |
| 319 | 319 |
| 320 def DeriveNativeName(interface_name, name, suffix): | 320 def DeriveNativeName(interface_name, name, suffix): |
| 321 fields = ["Native", interface_name, name] | 321 fields = ["Native", interface_name, name] |
| 322 if suffix != "": | 322 if suffix != "": |
| 323 fields.append(suffix) | 323 fields.append(suffix) |
| 324 return "_".join(fields) | 324 return "_".join(fields) |
| 325 | 325 |
| 326 def DeriveResolverString(interface_id, operation_id, native_suffix, | 326 def DeriveResolverString(interface_id, operation_id, native_suffix, type_ids): |
| 327 argument_count, type_ids): | |
| 328 type_string = \ | 327 type_string = \ |
| 329 "_".join(type_ids[:argument_count]) | 328 "_".join(type_ids) |
| 330 if native_suffix: | 329 if native_suffix: |
| 331 operation_id = "%s_%s" % (operation_id, native_suffix) | 330 operation_id = "%s_%s" % (operation_id, native_suffix) |
| 332 components = \ | 331 components = \ |
| 333 [interface_id, operation_id, | 332 [interface_id, operation_id, |
| 334 "RESOLVER_STRING", str(argument_count), type_string] | 333 "RESOLVER_STRING", str(len(type_ids)), type_string] |
| 335 return "_".join(components) | 334 return "_".join(components) |
| 336 | 335 |
| 337 # FIXME(leafp) This should really go elsewhere. I think the right thing | 336 # FIXME(leafp) This should really go elsewhere. I think the right thing |
| 338 # to do is to add support in the DartLibraries objects in systemhtml | 337 # to do is to add support in the DartLibraries objects in systemhtml |
| 339 # for emitting top level code in libraries. This can then just be a | 338 # for emitting top level code in libraries. This can then just be a |
| 340 # normal use of that kind of object | 339 # normal use of that kind of object |
| 341 def GetNativeLibraryEmitter(emitters, template_loader, | 340 def GetNativeLibraryEmitter(emitters, template_loader, |
| 342 dartium_output_dir, dart_output_dir, | 341 dartium_output_dir, dart_output_dir, |
| 343 auxiliary_dir): | 342 auxiliary_dir): |
| 344 def massage_path(path): | 343 def massage_path(path): |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 571 else: | 570 else: |
| 572 argument_count = len(constructor_info.param_infos) | 571 argument_count = len(constructor_info.param_infos) |
| 573 else: | 572 else: |
| 574 argument_count = len(arguments) | 573 argument_count = len(arguments) |
| 575 | 574 |
| 576 typed_formals = constructor_info.ParametersAsArgumentList(argument_count) | 575 typed_formals = constructor_info.ParametersAsArgumentList(argument_count) |
| 577 parameters = constructor_info.ParametersAsStringOfVariables(argument_count) | 576 parameters = constructor_info.ParametersAsStringOfVariables(argument_count) |
| 578 interface_name = self._interface_type_info.interface_name() | 577 interface_name = self._interface_type_info.interface_name() |
| 579 | 578 |
| 580 if self._dart_use_blink: | 579 if self._dart_use_blink: |
| 581 type_ids = [p.type.id for p in arguments] | 580 type_ids = [p.type.id for p in arguments[:argument_count]] |
| 582 constructor_callback_id = \ | 581 constructor_callback_id = \ |
| 583 DeriveResolverString(self._interface.id, | 582 DeriveResolverString(self._interface.id, cpp_suffix, None, type_ids) |
| 584 cpp_suffix, None, | |
| 585 argument_count, type_ids) | |
| 586 else: | 583 else: |
| 587 constructor_callback_id = self._interface.id + '_' + constructor_callbac
k_cpp_name | 584 constructor_callback_id = self._interface.id + '_' + constructor_callbac
k_cpp_name |
| 588 | 585 |
| 589 if self._dart_use_blink: | 586 if self._dart_use_blink: |
| 590 # First we emit the toplevel function | 587 # First we emit the toplevel function |
| 591 dart_native_name = \ | 588 dart_native_name = \ |
| 592 DeriveNativeName(self._interface.id, constructor_callback_cpp_name,
"") | 589 DeriveNativeName(self._interface.id, constructor_callback_cpp_name,
"") |
| 593 self._native_library_emitter.Emit( | 590 self._native_library_emitter.Emit( |
| 594 '\n' | 591 '\n' |
| 595 '$FACTORY_METHOD_NAME($PARAMETERS) native "$ID";\n', | 592 '$FACTORY_METHOD_NAME($PARAMETERS) native "$ID";\n', |
| (...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1001 elif self._HasExplicitIndexedGetter(): | 998 elif self._HasExplicitIndexedGetter(): |
| 1002 self._EmitExplicitIndexedGetter(dart_element_type) | 999 self._EmitExplicitIndexedGetter(dart_element_type) |
| 1003 else: | 1000 else: |
| 1004 if self._dart_use_blink: | 1001 if self._dart_use_blink: |
| 1005 dart_native_name = \ | 1002 dart_native_name = \ |
| 1006 DeriveNativeName(self._interface.id, "NativeIndexed", "Getter") | 1003 DeriveNativeName(self._interface.id, "NativeIndexed", "Getter") |
| 1007 # First emit a toplevel function to do the native call | 1004 # First emit a toplevel function to do the native call |
| 1008 # Calls to this are emitted elsewhere, | 1005 # Calls to this are emitted elsewhere, |
| 1009 resolver_string = \ | 1006 resolver_string = \ |
| 1010 DeriveResolverString(self._interface.id, "item", "Callback", | 1007 DeriveResolverString(self._interface.id, "item", "Callback", |
| 1011 1, ["unsigned long"]) | 1008 ["unsigned long"]) |
| 1012 self._native_library_emitter.Emit( | 1009 self._native_library_emitter.Emit( |
| 1013 '\n' | 1010 '\n' |
| 1014 '$(DART_NATIVE_NAME)(mthis, index) ' | 1011 '$(DART_NATIVE_NAME)(mthis, index) ' |
| 1015 'native "$(RESOLVER_STRING)";\n', | 1012 'native "$(RESOLVER_STRING)";\n', |
| 1016 DART_NATIVE_NAME = dart_native_name, | 1013 DART_NATIVE_NAME = dart_native_name, |
| 1017 RESOLVER_STRING=resolver_string) | 1014 RESOLVER_STRING=resolver_string) |
| 1018 | 1015 |
| 1019 # Emit the method which calls the toplevel function, along with | 1016 # Emit the method which calls the toplevel function, along with |
| 1020 # the [] operator. | 1017 # the [] operator. |
| 1021 self._members_emitter.Emit( | 1018 self._members_emitter.Emit( |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1137 elif not needs_dispatcher: | 1134 elif not needs_dispatcher: |
| 1138 # Bind directly to native implementation | 1135 # Bind directly to native implementation |
| 1139 argument_count = (0 if info.IsStatic() else 1) + len(info.param_infos) | 1136 argument_count = (0 if info.IsStatic() else 1) + len(info.param_infos) |
| 1140 native_suffix = 'Callback' | 1137 native_suffix = 'Callback' |
| 1141 auto_scope_setup = self._GenerateAutoSetupScope(info.name, native_suffix) | 1138 auto_scope_setup = self._GenerateAutoSetupScope(info.name, native_suffix) |
| 1142 if self._dart_use_blink: | 1139 if self._dart_use_blink: |
| 1143 type_ids = [argument.type.id | 1140 type_ids = [argument.type.id |
| 1144 for argument in operation.arguments[:argument_count]] | 1141 for argument in operation.arguments[:argument_count]] |
| 1145 resolver_string = \ | 1142 resolver_string = \ |
| 1146 DeriveResolverString(self._interface.id, operation.id, | 1143 DeriveResolverString(self._interface.id, operation.id, |
| 1147 native_suffix, len(info.param_infos), | 1144 native_suffix, type_ids) |
| 1148 type_ids) | |
| 1149 else: | 1145 else: |
| 1150 resolver_string = None | 1146 resolver_string = None |
| 1151 cpp_callback_name = self._GenerateNativeBinding( | 1147 cpp_callback_name = self._GenerateNativeBinding( |
| 1152 info.name, argument_count, dart_declaration, | 1148 info.name, argument_count, dart_declaration, |
| 1153 info.IsStatic(), return_type, parameters, | 1149 info.IsStatic(), return_type, parameters, |
| 1154 native_suffix, is_custom, auto_scope_setup, | 1150 native_suffix, is_custom, auto_scope_setup, |
| 1155 resolver_string=resolver_string) | 1151 resolver_string=resolver_string) |
| 1156 if not is_custom: | 1152 if not is_custom: |
| 1157 self._GenerateOperationNativeCallback(operation, operation.arguments, cp
p_callback_name, auto_scope_setup) | 1153 self._GenerateOperationNativeCallback(operation, operation.arguments, cp
p_callback_name, auto_scope_setup) |
| 1158 else: | 1154 else: |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1173 static = True | 1169 static = True |
| 1174 if not operation.is_static: | 1170 if not operation.is_static: |
| 1175 actuals = ['mthis'] + actuals | 1171 actuals = ['mthis'] + actuals |
| 1176 actuals_s = ", ".join(actuals) | 1172 actuals_s = ", ".join(actuals) |
| 1177 dart_declaration = '%s(%s)' % ( | 1173 dart_declaration = '%s(%s)' % ( |
| 1178 base_name, actuals_s) | 1174 base_name, actuals_s) |
| 1179 type_ids = [argument.type.id | 1175 type_ids = [argument.type.id |
| 1180 for argument in operation.arguments[:argument_count]] | 1176 for argument in operation.arguments[:argument_count]] |
| 1181 resolver_string = \ | 1177 resolver_string = \ |
| 1182 DeriveResolverString(self._interface.id, operation.id, | 1178 DeriveResolverString(self._interface.id, operation.id, |
| 1183 native_suffix, argument_count, type_ids) | 1179 native_suffix, type_ids) |
| 1184 else: | 1180 else: |
| 1185 base_name = '_%s_%s' % (operation.id, version) | 1181 base_name = '_%s_%s' % (operation.id, version) |
| 1186 overload_name = base_name | 1182 overload_name = base_name |
| 1187 static = operation.is_static | 1183 static = operation.is_static |
| 1188 actuals_s = ", ".join(actuals) | 1184 actuals_s = ", ".join(actuals) |
| 1189 dart_declaration = '%s%s %s(%s)' % ( | 1185 dart_declaration = '%s%s %s(%s)' % ( |
| 1190 'static ' if static else '', | 1186 'static ' if static else '', |
| 1191 return_type, | 1187 return_type, |
| 1192 overload_name, actuals_s) | 1188 overload_name, actuals_s) |
| 1193 resolver_string = None | 1189 resolver_string = None |
| (...skipping 744 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1938 e.Emit("};\n"); | 1934 e.Emit("};\n"); |
| 1939 e.Emit('\n'); | 1935 e.Emit('\n'); |
| 1940 e.Emit('} // namespace WebCore\n'); | 1936 e.Emit('} // namespace WebCore\n'); |
| 1941 | 1937 |
| 1942 def _IsOptionalStringArgumentInInitEventMethod(interface, operation, argument): | 1938 def _IsOptionalStringArgumentInInitEventMethod(interface, operation, argument): |
| 1943 return ( | 1939 return ( |
| 1944 interface.id.endswith('Event') and | 1940 interface.id.endswith('Event') and |
| 1945 operation.id.startswith('init') and | 1941 operation.id.startswith('init') and |
| 1946 argument.ext_attrs.get('Default') == 'Undefined' and | 1942 argument.ext_attrs.get('Default') == 'Undefined' and |
| 1947 argument.type.id == 'DOMString') | 1943 argument.type.id == 'DOMString') |
| OLD | NEW |