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

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

Issue 287163008: Fix custom constructor bindings (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, type_ids): 326 def DeriveResolverString(interface_id, operation_id, native_suffix, type_ids,
327 is_custom):
327 type_string = \ 328 type_string = \
328 "_".join(type_ids) 329 "_".join(type_ids)
329 if native_suffix: 330 if native_suffix:
330 operation_id = "%s_%s" % (operation_id, native_suffix) 331 operation_id = "%s_%s" % (operation_id, native_suffix)
331 components = \ 332 if is_custom:
332 [interface_id, operation_id, 333 components = \
333 "RESOLVER_STRING", str(len(type_ids)), type_string] 334 [interface_id, operation_id,
335 "RESOLVER_STRING"]
336 else:
337 components = \
338 [interface_id, operation_id,
339 "RESOLVER_STRING", str(len(type_ids)), type_string]
334 return "_".join(components) 340 return "_".join(components)
335 341
336 # FIXME(leafp) This should really go elsewhere. I think the right thing 342 # FIXME(leafp) This should really go elsewhere. I think the right thing
337 # to do is to add support in the DartLibraries objects in systemhtml 343 # to do is to add support in the DartLibraries objects in systemhtml
338 # for emitting top level code in libraries. This can then just be a 344 # for emitting top level code in libraries. This can then just be a
339 # normal use of that kind of object 345 # normal use of that kind of object
340 def GetNativeLibraryEmitter(emitters, template_loader, 346 def GetNativeLibraryEmitter(emitters, template_loader,
341 dartium_output_dir, dart_output_dir, 347 dartium_output_dir, dart_output_dir,
342 auxiliary_dir): 348 auxiliary_dir):
343 def massage_path(path): 349 def massage_path(path):
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
552 self._cpp_definitions_emitter.Emit( 558 self._cpp_definitions_emitter.Emit(
553 '\n' 559 '\n'
554 'static void constructorCallback(Dart_NativeArguments args)\n' 560 'static void constructorCallback(Dart_NativeArguments args)\n'
555 '{\n' 561 '{\n'
556 ' WebCore::DartArrayBufferViewInternal::constructWebGLArray<Dart$(INT ERFACE_NAME)>(args);\n' 562 ' WebCore::DartArrayBufferViewInternal::constructWebGLArray<Dart$(INT ERFACE_NAME)>(args);\n'
557 '}\n', 563 '}\n',
558 INTERFACE_NAME=self._interface.id); 564 INTERFACE_NAME=self._interface.id);
559 565
560 def _EmitConstructorInfrastructure(self, 566 def _EmitConstructorInfrastructure(self,
561 constructor_info, cpp_prefix, cpp_suffix, factory_method_name, 567 constructor_info, cpp_prefix, cpp_suffix, factory_method_name,
562 arguments=None, emit_to_native=False): 568 arguments=None, emit_to_native=False, is_custom=False):
563 569
564 constructor_callback_cpp_name = cpp_prefix + cpp_suffix 570 constructor_callback_cpp_name = cpp_prefix + cpp_suffix
565 571
566 if arguments is None: 572 if arguments is None:
567 if self._dart_use_blink: 573 if self._dart_use_blink:
568 arguments = constructor_info.idl_args[0] 574 arguments = constructor_info.idl_args[0]
569 argument_count = len(arguments) 575 argument_count = len(arguments)
570 else: 576 else:
571 argument_count = len(constructor_info.param_infos) 577 argument_count = len(constructor_info.param_infos)
572 else: 578 else:
573 argument_count = len(arguments) 579 argument_count = len(arguments)
574 580
575 typed_formals = constructor_info.ParametersAsArgumentList(argument_count) 581 typed_formals = constructor_info.ParametersAsArgumentList(argument_count)
576 parameters = constructor_info.ParametersAsStringOfVariables(argument_count) 582 parameters = constructor_info.ParametersAsStringOfVariables(argument_count)
577 interface_name = self._interface_type_info.interface_name() 583 interface_name = self._interface_type_info.interface_name()
578 584
579 if self._dart_use_blink: 585 if self._dart_use_blink:
580 type_ids = [p.type.id for p in arguments[:argument_count]] 586 type_ids = [p.type.id for p in arguments[:argument_count]]
581 constructor_callback_id = \ 587 constructor_callback_id = \
582 DeriveResolverString(self._interface.id, cpp_suffix, None, type_ids) 588 DeriveResolverString(self._interface.id, cpp_suffix, None, type_ids,
589 is_custom)
583 else: 590 else:
584 constructor_callback_id = self._interface.id + '_' + constructor_callbac k_cpp_name 591 constructor_callback_id = self._interface.id + '_' + constructor_callbac k_cpp_name
585 592
586 if self._dart_use_blink: 593 if self._dart_use_blink:
587 # First we emit the toplevel function 594 # First we emit the toplevel function
588 dart_native_name = \ 595 dart_native_name = \
589 DeriveNativeName(self._interface.id, constructor_callback_cpp_name, "") 596 DeriveNativeName(self._interface.id, constructor_callback_cpp_name, "")
590 self._native_library_emitter.Emit( 597 self._native_library_emitter.Emit(
591 '\n' 598 '\n'
592 '$FACTORY_METHOD_NAME($PARAMETERS) native "$ID";\n', 599 '$FACTORY_METHOD_NAME($PARAMETERS) native "$ID";\n',
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
634 self._members_emitter.Emit( 641 self._members_emitter.Emit(
635 '\n $(ANNOTATIONS)factory $CTOR($PARAMS) => _create($FACTORY_PARAMS);\n ', 642 '\n $(ANNOTATIONS)factory $CTOR($PARAMS) => _create($FACTORY_PARAMS);\n ',
636 ANNOTATIONS=annotations, 643 ANNOTATIONS=annotations,
637 CTOR=constructor_info._ConstructorFullName(self._DartType), 644 CTOR=constructor_info._ConstructorFullName(self._DartType),
638 PARAMS=constructor_info.ParametersAsDeclaration(self._DartType), 645 PARAMS=constructor_info.ParametersAsDeclaration(self._DartType),
639 FACTORY_PARAMS= \ 646 FACTORY_PARAMS= \
640 constructor_info.ParametersAsArgumentList()) 647 constructor_info.ParametersAsArgumentList())
641 648
642 constructor_callback_cpp_name = 'constructorCallback' 649 constructor_callback_cpp_name = 'constructorCallback'
643 self._EmitConstructorInfrastructure( 650 self._EmitConstructorInfrastructure(
644 constructor_info, "", constructor_callback_cpp_name, '_create') 651 constructor_info, "", constructor_callback_cpp_name, '_create',
652 is_custom=True)
645 653
646 self._cpp_declarations_emitter.Emit( 654 self._cpp_declarations_emitter.Emit(
647 '\n' 655 '\n'
648 'void $CPP_CALLBACK(Dart_NativeArguments);\n', 656 'void $CPP_CALLBACK(Dart_NativeArguments);\n',
649 CPP_CALLBACK=constructor_callback_cpp_name) 657 CPP_CALLBACK=constructor_callback_cpp_name)
650 658
651 return True 659 return True
652 660
653 def IsConstructorArgumentOptional(self, argument): 661 def IsConstructorArgumentOptional(self, argument):
654 return False 662 return False
655 663
656 def EmitStaticFactoryOverload(self, constructor_info, name, arguments): 664 def EmitStaticFactoryOverload(self, constructor_info, name, arguments):
657 constructor_callback_cpp_name = name + 'constructorCallback' 665 constructor_callback_cpp_name = name + 'constructorCallback'
658 self._EmitConstructorInfrastructure( 666 self._EmitConstructorInfrastructure(
659 constructor_info, name, 'constructorCallback', name, arguments, 667 constructor_info, name, 'constructorCallback', name, arguments,
660 emit_to_native=self._dart_use_blink) 668 emit_to_native=self._dart_use_blink,
669 is_custom=False)
661 670
662 ext_attrs = self._interface.ext_attrs 671 ext_attrs = self._interface.ext_attrs
663 672
664 create_function = 'create' 673 create_function = 'create'
665 if 'NamedConstructor' in ext_attrs: 674 if 'NamedConstructor' in ext_attrs:
666 create_function = 'createForJSConstructor' 675 create_function = 'createForJSConstructor'
667 function_expression = '%s::%s' % (self._interface_type_info.native_type(), c reate_function) 676 function_expression = '%s::%s' % (self._interface_type_info.native_type(), c reate_function)
668 self._GenerateNativeCallback( 677 self._GenerateNativeCallback(
669 constructor_callback_cpp_name, 678 constructor_callback_cpp_name,
670 False, 679 False,
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after
998 elif self._HasExplicitIndexedGetter(): 1007 elif self._HasExplicitIndexedGetter():
999 self._EmitExplicitIndexedGetter(dart_element_type) 1008 self._EmitExplicitIndexedGetter(dart_element_type)
1000 else: 1009 else:
1001 if self._dart_use_blink: 1010 if self._dart_use_blink:
1002 dart_native_name = \ 1011 dart_native_name = \
1003 DeriveNativeName(self._interface.id, "NativeIndexed", "Getter") 1012 DeriveNativeName(self._interface.id, "NativeIndexed", "Getter")
1004 # First emit a toplevel function to do the native call 1013 # First emit a toplevel function to do the native call
1005 # Calls to this are emitted elsewhere, 1014 # Calls to this are emitted elsewhere,
1006 resolver_string = \ 1015 resolver_string = \
1007 DeriveResolverString(self._interface.id, "item", "Callback", 1016 DeriveResolverString(self._interface.id, "item", "Callback",
1008 ["unsigned long"]) 1017 ["unsigned long"], False)
1009 self._native_library_emitter.Emit( 1018 self._native_library_emitter.Emit(
1010 '\n' 1019 '\n'
1011 '$(DART_NATIVE_NAME)(mthis, index) ' 1020 '$(DART_NATIVE_NAME)(mthis, index) '
1012 'native "$(RESOLVER_STRING)";\n', 1021 'native "$(RESOLVER_STRING)";\n',
1013 DART_NATIVE_NAME = dart_native_name, 1022 DART_NATIVE_NAME = dart_native_name,
1014 RESOLVER_STRING=resolver_string) 1023 RESOLVER_STRING=resolver_string)
1015 1024
1016 # Emit the method which calls the toplevel function, along with 1025 # Emit the method which calls the toplevel function, along with
1017 # the [] operator. 1026 # the [] operator.
1018 self._members_emitter.Emit( 1027 self._members_emitter.Emit(
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
1134 elif not needs_dispatcher: 1143 elif not needs_dispatcher:
1135 # Bind directly to native implementation 1144 # Bind directly to native implementation
1136 argument_count = (0 if info.IsStatic() else 1) + len(info.param_infos) 1145 argument_count = (0 if info.IsStatic() else 1) + len(info.param_infos)
1137 native_suffix = 'Callback' 1146 native_suffix = 'Callback'
1138 auto_scope_setup = self._GenerateAutoSetupScope(info.name, native_suffix) 1147 auto_scope_setup = self._GenerateAutoSetupScope(info.name, native_suffix)
1139 if self._dart_use_blink: 1148 if self._dart_use_blink:
1140 type_ids = [argument.type.id 1149 type_ids = [argument.type.id
1141 for argument in operation.arguments[:argument_count]] 1150 for argument in operation.arguments[:argument_count]]
1142 resolver_string = \ 1151 resolver_string = \
1143 DeriveResolverString(self._interface.id, operation.id, 1152 DeriveResolverString(self._interface.id, operation.id,
1144 native_suffix, type_ids) 1153 native_suffix, type_ids, is_custom)
1145 else: 1154 else:
1146 resolver_string = None 1155 resolver_string = None
1147 cpp_callback_name = self._GenerateNativeBinding( 1156 cpp_callback_name = self._GenerateNativeBinding(
1148 info.name, argument_count, dart_declaration, 1157 info.name, argument_count, dart_declaration,
1149 info.IsStatic(), return_type, parameters, 1158 info.IsStatic(), return_type, parameters,
1150 native_suffix, is_custom, auto_scope_setup, 1159 native_suffix, is_custom, auto_scope_setup,
1151 resolver_string=resolver_string) 1160 resolver_string=resolver_string)
1152 if not is_custom: 1161 if not is_custom:
1153 self._GenerateOperationNativeCallback(operation, operation.arguments, cp p_callback_name, auto_scope_setup) 1162 self._GenerateOperationNativeCallback(operation, operation.arguments, cp p_callback_name, auto_scope_setup)
1154 else: 1163 else:
1155 self._GenerateDispatcher(info, info.operations, dart_declaration, html_nam e) 1164 self._GenerateDispatcher(info, info.operations, dart_declaration, html_nam e)
1156 1165
1157 def _GenerateDispatcher(self, info, operations, dart_declaration, html_name): 1166 def _GenerateDispatcher(self, info, operations, dart_declaration, html_name):
1158 1167
1159 def GenerateCall( 1168 def GenerateCall(
1160 stmts_emitter, call_emitter, version, operation, argument_count): 1169 stmts_emitter, call_emitter, version, operation, argument_count):
1161 native_suffix = 'Callback' 1170 native_suffix = 'Callback'
1162 actuals = info.ParametersAsListOfVariables(argument_count) 1171 actuals = info.ParametersAsListOfVariables(argument_count)
1163 return_type = self.SecureOutputType(operation.type.id) 1172 return_type = self.SecureOutputType(operation.type.id)
1164 native_suffix = 'Callback' 1173 native_suffix = 'Callback'
1174 is_custom = 'Custom' in operation.ext_attrs
1165 if self._dart_use_blink: 1175 if self._dart_use_blink:
1166 base_name = '_%s_%s' % (operation.id, version) 1176 base_name = '_%s_%s' % (operation.id, version)
1167 overload_name = \ 1177 overload_name = \
1168 DeriveNativeName(self._interface.id, base_name, native_suffix) 1178 DeriveNativeName(self._interface.id, base_name, native_suffix)
1169 static = True 1179 static = True
1170 if not operation.is_static: 1180 if not operation.is_static:
1171 actuals = ['mthis'] + actuals 1181 actuals = ['mthis'] + actuals
1172 actuals_s = ", ".join(actuals) 1182 actuals_s = ", ".join(actuals)
1173 dart_declaration = '%s(%s)' % ( 1183 dart_declaration = '%s(%s)' % (
1174 base_name, actuals_s) 1184 base_name, actuals_s)
1175 type_ids = [argument.type.id 1185 type_ids = [argument.type.id
1176 for argument in operation.arguments[:argument_count]] 1186 for argument in operation.arguments[:argument_count]]
1177 resolver_string = \ 1187 resolver_string = \
1178 DeriveResolverString(self._interface.id, operation.id, 1188 DeriveResolverString(self._interface.id, operation.id,
1179 native_suffix, type_ids) 1189 native_suffix, type_ids, is_custom)
1180 else: 1190 else:
1181 base_name = '_%s_%s' % (operation.id, version) 1191 base_name = '_%s_%s' % (operation.id, version)
1182 overload_name = base_name 1192 overload_name = base_name
1183 static = operation.is_static 1193 static = operation.is_static
1184 actuals_s = ", ".join(actuals) 1194 actuals_s = ", ".join(actuals)
1185 dart_declaration = '%s%s %s(%s)' % ( 1195 dart_declaration = '%s%s %s(%s)' % (
1186 'static ' if static else '', 1196 'static ' if static else '',
1187 return_type, 1197 return_type,
1188 overload_name, actuals_s) 1198 overload_name, actuals_s)
1189 resolver_string = None 1199 resolver_string = None
1190 1200
1191 call_emitter.Emit('$NAME($ARGS)', NAME=overload_name, ARGS=actuals_s) 1201 call_emitter.Emit('$NAME($ARGS)', NAME=overload_name, ARGS=actuals_s)
1192 is_custom = 'Custom' in operation.ext_attrs
1193 auto_scope_setup = \ 1202 auto_scope_setup = \
1194 self._GenerateAutoSetupScope(base_name, native_suffix) 1203 self._GenerateAutoSetupScope(base_name, native_suffix)
1195 cpp_callback_name = self._GenerateNativeBinding( 1204 cpp_callback_name = self._GenerateNativeBinding(
1196 base_name, (0 if static else 1) + argument_count, 1205 base_name, (0 if static else 1) + argument_count,
1197 dart_declaration, static, return_type, actuals, 1206 dart_declaration, static, return_type, actuals,
1198 native_suffix, is_custom, auto_scope_setup, emit_metadata=False, 1207 native_suffix, is_custom, auto_scope_setup, emit_metadata=False,
1199 emit_to_native=self._dart_use_blink, resolver_string=resolver_string) 1208 emit_to_native=self._dart_use_blink, resolver_string=resolver_string)
1200 if not is_custom: 1209 if not is_custom:
1201 self._GenerateOperationNativeCallback(operation, 1210 self._GenerateOperationNativeCallback(operation,
1202 operation.arguments[:argument_count], cpp_callback_name, 1211 operation.arguments[:argument_count], cpp_callback_name,
(...skipping 731 matching lines...) Expand 10 before | Expand all | Expand 10 after
1934 e.Emit("};\n"); 1943 e.Emit("};\n");
1935 e.Emit('\n'); 1944 e.Emit('\n');
1936 e.Emit('} // namespace WebCore\n'); 1945 e.Emit('} // namespace WebCore\n');
1937 1946
1938 def _IsOptionalStringArgumentInInitEventMethod(interface, operation, argument): 1947 def _IsOptionalStringArgumentInInitEventMethod(interface, operation, argument):
1939 return ( 1948 return (
1940 interface.id.endswith('Event') and 1949 interface.id.endswith('Event') and
1941 operation.id.startswith('init') and 1950 operation.id.startswith('init') and
1942 argument.ext_attrs.get('Default') == 'Undefined' and 1951 argument.ext_attrs.get('Default') == 'Undefined' and
1943 argument.type.id == 'DOMString') 1952 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