Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(175)

Side by Side Diff: tools/dom/scripts/systemnative.py

Issue 284263002: Make resolver strings match up better (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « sdk/lib/_blink/dartium/_blink_dartium.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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,
327 argument_count, type_ids):
328 type_string = \
329 "_".join(type_ids[:argument_count])
330 if native_suffix:
331 operation_id = "%s_%s" % (operation_id, native_suffix)
332 components = \
333 [interface_id, operation_id,
334 "RESOLVER_STRING", str(argument_count), type_string]
335 return "_".join(components)
336
326 # FIXME(leafp) This should really go elsewhere. I think the right thing 337 # FIXME(leafp) This should really go elsewhere. I think the right thing
327 # to do is to add support in the DartLibraries objects in systemhtml 338 # to do is to add support in the DartLibraries objects in systemhtml
328 # for emitting top level code in libraries. This can then just be a 339 # for emitting top level code in libraries. This can then just be a
329 # normal use of that kind of object 340 # normal use of that kind of object
330 def GetNativeLibraryEmitter(emitters, template_loader, 341 def GetNativeLibraryEmitter(emitters, template_loader,
331 dartium_output_dir, dart_output_dir, 342 dartium_output_dir, dart_output_dir,
332 auxiliary_dir): 343 auxiliary_dir):
333 def massage_path(path): 344 def massage_path(path):
334 # The most robust way to emit path separators is to use / always. 345 # The most robust way to emit path separators is to use / always.
335 return path.replace('\\', '/') 346 return path.replace('\\', '/')
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
542 self._cpp_definitions_emitter.Emit( 553 self._cpp_definitions_emitter.Emit(
543 '\n' 554 '\n'
544 'static void constructorCallback(Dart_NativeArguments args)\n' 555 'static void constructorCallback(Dart_NativeArguments args)\n'
545 '{\n' 556 '{\n'
546 ' WebCore::DartArrayBufferViewInternal::constructWebGLArray<Dart$(INT ERFACE_NAME)>(args);\n' 557 ' WebCore::DartArrayBufferViewInternal::constructWebGLArray<Dart$(INT ERFACE_NAME)>(args);\n'
547 '}\n', 558 '}\n',
548 INTERFACE_NAME=self._interface.id); 559 INTERFACE_NAME=self._interface.id);
549 560
550 def _EmitConstructorInfrastructure(self, 561 def _EmitConstructorInfrastructure(self,
551 constructor_info, constructor_callback_cpp_name, factory_method_name, 562 constructor_info, constructor_callback_cpp_name, factory_method_name,
552 argument_count=None, emit_to_native=False): 563 arguments=None, emit_to_native=False):
553 constructor_callback_id = self._interface.id + '_' + constructor_callback_cp p_name 564
554 if argument_count is None: 565 if arguments is None:
555 argument_count = len(constructor_info.param_infos) 566 argument_count = len(constructor_info.param_infos)
567 else:
568 argument_count = len(arguments)
556 569
557 typed_formals = constructor_info.ParametersAsArgumentList(argument_count) 570 typed_formals = constructor_info.ParametersAsArgumentList(argument_count)
558 parameters = constructor_info.ParametersAsStringOfVariables(argument_count) 571 parameters = constructor_info.ParametersAsStringOfVariables(argument_count)
559 interface_name = self._interface_type_info.interface_name() 572 interface_name = self._interface_type_info.interface_name()
560 573
574 if self._dart_use_blink and arguments:
575 type_ids = [p.type.id for p in arguments]
576 constructor_callback_id = \
577 DeriveResolverString(self._interface.id,
578 constructor_callback_cpp_name, None,
579 argument_count, type_ids)
580 else:
581 constructor_callback_id = self._interface.id + '_' + constructor_callbac k_cpp_name
582
561 if self._dart_use_blink: 583 if self._dart_use_blink:
562 # First we emit the toplevel function 584 # First we emit the toplevel function
563 dart_native_name = \ 585 dart_native_name = \
564 DeriveNativeName(self._interface.id, constructor_callback_cpp_name, "") 586 DeriveNativeName(self._interface.id, constructor_callback_cpp_name, "")
565 self._native_library_emitter.Emit( 587 self._native_library_emitter.Emit(
566 '\n' 588 '\n'
567 '$FACTORY_METHOD_NAME($PARAMETERS) native "$ID";\n', 589 '$FACTORY_METHOD_NAME($PARAMETERS) native "$ID";\n',
568 FACTORY_METHOD_NAME=dart_native_name, 590 FACTORY_METHOD_NAME=dart_native_name,
569 PARAMETERS=parameters, 591 PARAMETERS=parameters,
570 ID=constructor_callback_id) 592 ID=constructor_callback_id)
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
622 '\n' 644 '\n'
623 'void $CPP_CALLBACK(Dart_NativeArguments);\n', 645 'void $CPP_CALLBACK(Dart_NativeArguments);\n',
624 CPP_CALLBACK=constructor_callback_cpp_name) 646 CPP_CALLBACK=constructor_callback_cpp_name)
625 647
626 return True 648 return True
627 649
628 def IsConstructorArgumentOptional(self, argument): 650 def IsConstructorArgumentOptional(self, argument):
629 return False 651 return False
630 652
631 def EmitStaticFactoryOverload(self, constructor_info, name, arguments): 653 def EmitStaticFactoryOverload(self, constructor_info, name, arguments):
632 constructor_callback_cpp_name = name + 'constructorCallback' 654 if self._dart_use_blink:
655 constructor_callback_cpp_name = 'constructorCallback'
656 else:
657 constructor_callback_cpp_name = name + 'constructorCallback'
633 self._EmitConstructorInfrastructure( 658 self._EmitConstructorInfrastructure(
634 constructor_info, constructor_callback_cpp_name, name, len(arguments), 659 constructor_info, constructor_callback_cpp_name, name, arguments,
635 emit_to_native=self._dart_use_blink) 660 emit_to_native=self._dart_use_blink)
636 661
637 ext_attrs = self._interface.ext_attrs 662 ext_attrs = self._interface.ext_attrs
638 663
639 create_function = 'create' 664 create_function = 'create'
640 if 'NamedConstructor' in ext_attrs: 665 if 'NamedConstructor' in ext_attrs:
641 create_function = 'createForJSConstructor' 666 create_function = 'createForJSConstructor'
642 function_expression = '%s::%s' % (self._interface_type_info.native_type(), c reate_function) 667 function_expression = '%s::%s' % (self._interface_type_info.native_type(), c reate_function)
643 self._GenerateNativeCallback( 668 self._GenerateNativeCallback(
644 constructor_callback_cpp_name, 669 constructor_callback_cpp_name,
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after
971 if self._HasNativeIndexGetter(): 996 if self._HasNativeIndexGetter():
972 self._EmitNativeIndexGetter(dart_element_type) 997 self._EmitNativeIndexGetter(dart_element_type)
973 elif self._HasExplicitIndexedGetter(): 998 elif self._HasExplicitIndexedGetter():
974 self._EmitExplicitIndexedGetter(dart_element_type) 999 self._EmitExplicitIndexedGetter(dart_element_type)
975 else: 1000 else:
976 if self._dart_use_blink: 1001 if self._dart_use_blink:
977 dart_native_name = \ 1002 dart_native_name = \
978 DeriveNativeName(self._interface.id, "NativeIndexed", "Getter") 1003 DeriveNativeName(self._interface.id, "NativeIndexed", "Getter")
979 # First emit a toplevel function to do the native call 1004 # First emit a toplevel function to do the native call
980 # Calls to this are emitted elsewhere, 1005 # Calls to this are emitted elsewhere,
1006 resolver_string = \
1007 DeriveResolverString(self._interface.id, "item", "Callback",
1008 1, ["unsigned long"])
981 self._native_library_emitter.Emit( 1009 self._native_library_emitter.Emit(
982 '\n' 1010 '\n'
983 '$(DART_NATIVE_NAME)(mthis, index) ' 1011 '$(DART_NATIVE_NAME)(mthis, index) '
984 'native "$(INTERFACE)_item_Callback";\n', 1012 'native "$(RESOLVER_STRING)";\n',
985 DART_NATIVE_NAME = dart_native_name, 1013 DART_NATIVE_NAME = dart_native_name,
986 INTERFACE=self._interface.id) 1014 RESOLVER_STRING=resolver_string)
987 1015
988 # Emit the method which calls the toplevel function, along with 1016 # Emit the method which calls the toplevel function, along with
989 # the [] operator. 1017 # the [] operator.
990 self._members_emitter.Emit( 1018 self._members_emitter.Emit(
991 '\n' 1019 '\n'
992 ' $TYPE operator[](int index) {\n' 1020 ' $TYPE operator[](int index) {\n'
993 ' if (index < 0 || index >= length)\n' 1021 ' if (index < 0 || index >= length)\n'
994 ' throw new RangeError.range(index, 0, length);\n' 1022 ' throw new RangeError.range(index, 0, length);\n'
995 ' return $(DART_NATIVE_NAME)(this, index);\n' 1023 ' return $(DART_NATIVE_NAME)(this, index);\n'
996 ' }\n\n' 1024 ' }\n\n'
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
1101 has_optional_arguments = any(self._IsArgumentOptionalInWebCore(operation, ar gument) for argument in operation.arguments) 1129 has_optional_arguments = any(self._IsArgumentOptionalInWebCore(operation, ar gument) for argument in operation.arguments)
1102 needs_dispatcher = not is_custom and (len(info.operations) > 1 or has_option al_arguments) 1130 needs_dispatcher = not is_custom and (len(info.operations) > 1 or has_option al_arguments)
1103 1131
1104 if info.callback_args: 1132 if info.callback_args:
1105 self._AddFutureifiedOperation(info, html_name) 1133 self._AddFutureifiedOperation(info, html_name)
1106 elif not needs_dispatcher: 1134 elif not needs_dispatcher:
1107 # Bind directly to native implementation 1135 # Bind directly to native implementation
1108 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)
1109 native_suffix = 'Callback' 1137 native_suffix = 'Callback'
1110 auto_scope_setup = self._GenerateAutoSetupScope(info.name, native_suffix) 1138 auto_scope_setup = self._GenerateAutoSetupScope(info.name, native_suffix)
1139 if self._dart_use_blink:
1140 type_ids = [argument.type.id
1141 for argument in operation.arguments[:argument_count]]
1142 resolver_string = \
1143 DeriveResolverString(self._interface.id, operation.id,
1144 native_suffix, len(info.param_infos),
1145 type_ids)
1146 else:
1147 resolver_string = None
1111 cpp_callback_name = self._GenerateNativeBinding( 1148 cpp_callback_name = self._GenerateNativeBinding(
1112 info.name, argument_count, dart_declaration, 1149 info.name, argument_count, dart_declaration,
1113 info.IsStatic(), return_type, parameters, 1150 info.IsStatic(), return_type, parameters,
1114 native_suffix, is_custom, auto_scope_setup) 1151 native_suffix, is_custom, auto_scope_setup,
1152 resolver_string=resolver_string)
1115 if not is_custom: 1153 if not is_custom:
1116 self._GenerateOperationNativeCallback(operation, operation.arguments, cp p_callback_name, auto_scope_setup) 1154 self._GenerateOperationNativeCallback(operation, operation.arguments, cp p_callback_name, auto_scope_setup)
1117 else: 1155 else:
1118 self._GenerateDispatcher(info, info.operations, dart_declaration, html_nam e) 1156 self._GenerateDispatcher(info, info.operations, dart_declaration, html_nam e)
1119 1157
1120 def _GenerateDispatcher(self, info, operations, dart_declaration, html_name): 1158 def _GenerateDispatcher(self, info, operations, dart_declaration, html_name):
1121 1159
1122 def GenerateCall( 1160 def GenerateCall(
1123 stmts_emitter, call_emitter, version, operation, argument_count): 1161 stmts_emitter, call_emitter, version, operation, argument_count):
1124 native_suffix = 'Callback' 1162 native_suffix = 'Callback'
1125 actuals = info.ParametersAsListOfVariables(argument_count) 1163 actuals = info.ParametersAsListOfVariables(argument_count)
1126 return_type = self.SecureOutputType(operation.type.id) 1164 return_type = self.SecureOutputType(operation.type.id)
1127 native_suffix = 'Callback' 1165 native_suffix = 'Callback'
1128 if self._dart_use_blink: 1166 if self._dart_use_blink:
1129 base_name = '_%s_%s' % (operation.id, version) 1167 base_name = '_%s_%s' % (operation.id, version)
1130 cpp_base_name = '%s' % operation.id
1131 overload_name = \ 1168 overload_name = \
1132 DeriveNativeName(self._interface.id, base_name, native_suffix) 1169 DeriveNativeName(self._interface.id, base_name, native_suffix)
1133 static = True 1170 static = True
1134 if not operation.is_static: 1171 if not operation.is_static:
1135 actuals = ['mthis'] + actuals 1172 actuals = ['mthis'] + actuals
1136 actuals_s = ", ".join(actuals) 1173 actuals_s = ", ".join(actuals)
1137 dart_declaration = '%s(%s)' % ( 1174 dart_declaration = '%s(%s)' % (
1138 base_name, actuals_s) 1175 base_name, actuals_s)
1139 type_string = \ 1176 type_ids = [argument.type.id
1140 "_".join([argument.type.id 1177 for argument in operation.arguments[:argument_count]]
1141 for argument in operation.arguments[:argument_count]]) 1178 resolver_string = \
1142 components = \ 1179 DeriveResolverString(self._interface.id, operation.id,
1143 [self._interface.id, cpp_base_name, native_suffix, 1180 native_suffix, argument_count, type_ids)
1144 str(argument_count), type_string]
1145 resolver_string = "_".join(components)
1146 else: 1181 else:
1147 base_name = '_%s_%s' % (operation.id, version) 1182 base_name = '_%s_%s' % (operation.id, version)
1148 cpp_base_name = base_name
1149 overload_name = base_name 1183 overload_name = base_name
1150 static = operation.is_static 1184 static = operation.is_static
1151 actuals_s = ", ".join(actuals) 1185 actuals_s = ", ".join(actuals)
1152 dart_declaration = '%s%s %s(%s)' % ( 1186 dart_declaration = '%s%s %s(%s)' % (
1153 'static ' if static else '', 1187 'static ' if static else '',
1154 return_type, 1188 return_type,
1155 overload_name, actuals_s) 1189 overload_name, actuals_s)
1156 resolver_string = None 1190 resolver_string = None
1157 1191
1158 call_emitter.Emit('$NAME($ARGS)', NAME=overload_name, ARGS=actuals_s) 1192 call_emitter.Emit('$NAME($ARGS)', NAME=overload_name, ARGS=actuals_s)
(...skipping 742 matching lines...) Expand 10 before | Expand all | Expand 10 after
1901 e.Emit("};\n"); 1935 e.Emit("};\n");
1902 e.Emit('\n'); 1936 e.Emit('\n');
1903 e.Emit('} // namespace WebCore\n'); 1937 e.Emit('} // namespace WebCore\n');
1904 1938
1905 def _IsOptionalStringArgumentInInitEventMethod(interface, operation, argument): 1939 def _IsOptionalStringArgumentInInitEventMethod(interface, operation, argument):
1906 return ( 1940 return (
1907 interface.id.endswith('Event') and 1941 interface.id.endswith('Event') and
1908 operation.id.startswith('init') and 1942 operation.id.startswith('init') and
1909 argument.ext_attrs.get('Default') == 'Undefined' and 1943 argument.ext_attrs.get('Default') == 'Undefined' and
1910 argument.type.id == 'DOMString') 1944 argument.type.id == 'DOMString')
OLDNEW
« no previous file with comments | « sdk/lib/_blink/dartium/_blink_dartium.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698