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

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

Issue 10331015: Remove ParameterAdapters for bindings classes. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 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 | « lib/dom/scripts/generator.py ('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 369 matching lines...) Expand 10 before | Expand all | Expand 10 after
380 CALLBACKS=self._cpp_definitions_emitter.Fragments(), 380 CALLBACKS=self._cpp_definitions_emitter.Fragments(),
381 RESOLVER=self._cpp_resolver_emitter.Fragments()) 381 RESOLVER=self._cpp_resolver_emitter.Fragments())
382 382
383 def _GenerateCppHeader(self): 383 def _GenerateCppHeader(self):
384 to_native_emitter = emitter.Emitter() 384 to_native_emitter = emitter.Emitter()
385 if self._interface_type_info.custom_to_native(): 385 if self._interface_type_info.custom_to_native():
386 to_native_emitter.Emit( 386 to_native_emitter.Emit(
387 ' static PassRefPtr<NativeType> toNative(Dart_Handle handle, Dart_H andle& exception);\n') 387 ' static PassRefPtr<NativeType> toNative(Dart_Handle handle, Dart_H andle& exception);\n')
388 else: 388 else:
389 to_native_emitter.Emit( 389 to_native_emitter.Emit(
390 ' static PassRefPtr<NativeType> toNative(Dart_Handle handle, Dart_H andle& exception)\n' 390 ' static NativeType* toNative(Dart_Handle handle, Dart_Handle& exce ption)\n'
391 ' {\n' 391 ' {\n'
392 ' return DartDOMWrapper::unwrapDartWrapper<Dart$INTERFACE>(hand le, exception);\n' 392 ' return DartDOMWrapper::unwrapDartWrapper<Dart$INTERFACE>(hand le, exception);\n'
393 ' }\n', 393 ' }\n',
394 INTERFACE=self._interface.id) 394 INTERFACE=self._interface.id)
395 395
396 to_dart_emitter = emitter.Emitter() 396 to_dart_emitter = emitter.Emitter()
397 if ('CustomToJS' in self._interface.ext_attrs or 397 if ('CustomToJS' in self._interface.ext_attrs or
398 'CustomToJSObject' in self._interface.ext_attrs or 398 'CustomToJSObject' in self._interface.ext_attrs or
399 'PureInterface' in self._interface.ext_attrs or 399 'PureInterface' in self._interface.ext_attrs or
400 'CPPPureInterface' in self._interface.ext_attrs or 400 'CPPPureInterface' in self._interface.ext_attrs or
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
531 arguments.append(self._GenerateWebCoreReflectionAttributeName(attr)) 531 arguments.append(self._GenerateWebCoreReflectionAttributeName(attr))
532 else: 532 else:
533 webcore_function_name = re.sub(r'^(xml(?=[A-Z])|\w)', 533 webcore_function_name = re.sub(r'^(xml(?=[A-Z])|\w)',
534 lambda s: s.group(1).upper(), 534 lambda s: s.group(1).upper(),
535 attr.id) 535 attr.id)
536 webcore_function_name = 'set%s' % webcore_function_name 536 webcore_function_name = 'set%s' % webcore_function_name
537 if attr.type.id.startswith('SVGAnimated'): 537 if attr.type.id.startswith('SVGAnimated'):
538 webcore_function_name += 'Animated' 538 webcore_function_name += 'Animated'
539 539
540 argument_expression = self._GenerateParameterAdapter( 540 argument_expression = self._GenerateParameterAdapter(
541 parameter_definitions_emitter, attr, 0, adapter_name='value') 541 parameter_definitions_emitter, attr, 0, argument_name='value')
542 arguments.append(argument_expression) 542 arguments.append(argument_expression)
543 543
544 parameter_definitions = parameter_definitions_emitter.Fragments() 544 parameter_definitions = parameter_definitions_emitter.Fragments()
545 function_expression = self._GenerateWebCoreFunctionExpression(webcore_functi on_name, attr) 545 function_expression = self._GenerateWebCoreFunctionExpression(webcore_functi on_name, attr)
546 invocation = self._GenerateWebCoreInvocation(function_expression, 546 invocation = self._GenerateWebCoreInvocation(function_expression,
547 arguments, 'void', attr.ext_attrs, attr.set_raises) 547 arguments, 'void', attr.ext_attrs, attr.set_raises)
548 548
549 self._GenerateNativeCallback(cpp_callback_name, parameter_definitions_emitte r.Fragments(), 549 self._GenerateNativeCallback(cpp_callback_name, parameter_definitions_emitte r.Fragments(),
550 True, invocation, raises_exceptions=True) 550 True, invocation, raises_exceptions=True)
551 551
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
696 ' {\n' 696 ' {\n'
697 '$PARAMETER_DEFINITIONS' 697 '$PARAMETER_DEFINITIONS'
698 '$INVOCATION' 698 '$INVOCATION'
699 ' return;\n' 699 ' return;\n'
700 ' }\n', 700 ' }\n',
701 PARAMETER_DEFINITIONS=parameter_definitions, 701 PARAMETER_DEFINITIONS=parameter_definitions,
702 INVOCATION=invocation) 702 INVOCATION=invocation)
703 703
704 if raises_exceptions: 704 if raises_exceptions:
705 body = emitter.Format( 705 body = emitter.Format(
706 ' Dart_Handle exception;\n' 706 ' Dart_Handle exception = 0;\n'
707 '$BODY' 707 '$BODY'
708 '\n' 708 '\n'
709 'fail:\n' 709 'fail:\n'
710 ' Dart_ThrowException(exception);\n' 710 ' Dart_ThrowException(exception);\n'
711 ' ASSERT_NOT_REACHED();\n', 711 ' ASSERT_NOT_REACHED();\n',
712 BODY=body) 712 BODY=body)
713 713
714 self._cpp_definitions_emitter.Emit( 714 self._cpp_definitions_emitter.Emit(
715 '\n' 715 '\n'
716 'static void $CALLBACK_NAME(Dart_NativeArguments args)\n' 716 'static void $CALLBACK_NAME(Dart_NativeArguments args)\n'
717 '{\n' 717 '{\n'
718 ' DartApiScope dartApiScope;\n' 718 ' DartApiScope dartApiScope;\n'
719 '$BODY' 719 '$BODY'
720 '}\n', 720 '}\n',
721 CALLBACK_NAME=callback_name, 721 CALLBACK_NAME=callback_name,
722 BODY=body) 722 BODY=body)
723 723
724 def _GenerateParameterAdapter(self, emitter, idl_node, index, 724 def _GenerateParameterAdapter(self, emitter, idl_node, index,
725 adapter_name=None): 725 argument_name=None):
726 """idl_node is IDLArgument or IDLAttribute.""" 726 """idl_node is IDLArgument or IDLAttribute."""
727 type_info = GetIDLTypeInfo(idl_node.type.id) 727 type_info = GetIDLTypeInfo(idl_node.type.id)
728 (adapter_type, include_name) = type_info.parameter_adapter_info() 728 (adapter_type, include_name) = type_info.parameter_adapter_info()
729 if include_name: 729 if include_name:
730 self._cpp_impl_includes.add(include_name) 730 self._cpp_impl_includes.add(include_name)
731 adapter_name = adapter_name or idl_node.id 731 argument_name = argument_name or idl_node.id
732 flags = '' 732 flags = ''
733 if (idl_node.ext_attrs.get('Optional') == 'DefaultIsNullString' or 733 if (idl_node.ext_attrs.get('Optional') == 'DefaultIsNullString' or
734 'RequiredCppParameter' in idl_node.ext_attrs): 734 'RequiredCppParameter' in idl_node.ext_attrs):
735 flags = ', DartUtilities::ConvertNullToDefaultValue' 735 flags = ', DartUtilities::ConvertNullToDefaultValue'
736
737 if isinstance(type_info, PrimitiveIDLTypeInfo):
738 emitter.Emit(
Anton Muhin 2012/05/03 18:27:50 shouldn't it be a polymorphic method or something?
podivilov 2012/05/03 18:44:19 Probably not, because it uses too much of a contex
739 '\n'
740 ' const $ADAPTER_TYPE $NAME(Dart_GetNativeArgument(args, $INDEX )$FLAGS);\n'
741 ' if (!$NAME.conversionSuccessful()) {\n'
742 ' exception = $NAME.exception();\n'
743 ' goto fail;\n'
744 ' }\n',
745 ADAPTER_TYPE=adapter_type,
746 NAME=argument_name,
747 INDEX=index + 1,
748 FLAGS=flags)
749 return argument_name
750
751 if 'Callback' in idl_node.ext_attrs:
752 type = 'RefPtr<%s>' % type_info.native_type()
753 conversion = '%s'
754 elif type_info.custom_to_native():
755 type = 'RefPtr<%s>' % type_info.native_type()
756 conversion = '%s.get()'
757 else:
758 type = '%s*' % type_info.native_type()
759 if isinstance(type_info, SVGTearOffIDLTypeInfo) and not self._interface.id .endswith('List'):
760 conversion = '%s->propertyReference()'
761 else:#if type_info.idl_type() == 'SVGMatrix' and self._interface.id == 'SV GTransformList':
762 conversion = '%s'
763
736 emitter.Emit( 764 emitter.Emit(
737 '\n' 765 '\n'
738 ' const $ADAPTER_TYPE $NAME(Dart_GetNativeArgument(args, $INDEX)$ FLAGS);\n' 766 ' $TYPE $NAME = Dart$IDL_TYPE::toNative(Dart_GetNativeArgument(ar gs, $INDEX), exception);\n'
739 ' if (!$NAME.conversionSuccessful()) {\n' 767 ' if (exception)\n'
740 ' exception = $NAME.exception();\n' 768 ' goto fail;\n',
741 ' goto fail;\n' 769 TYPE=type,
742 ' }\n', 770 NAME=argument_name,
743 ADAPTER_TYPE=adapter_type, 771 IDL_TYPE=type_info.idl_type(),
744 NAME=adapter_name, 772 INDEX=index + 1)
745 INDEX=index + 1, 773 return conversion % argument_name
746 FLAGS=flags)
747
748 conversion = '%s'
749 if isinstance(type_info, SVGTearOffIDLTypeInfo) and not self._interface.id.e ndswith('List'):
750 conversion = '%s.get()->propertyReference()'
751 elif type_info.idl_type() == 'SVGMatrix' and self._interface.id == 'SVGTrans formList':
752 conversion = '%s.get()'
753 return conversion % adapter_name
754 774
755 def _GenerateNativeBinding(self, idl_name, argument_count, dart_declaration, 775 def _GenerateNativeBinding(self, idl_name, argument_count, dart_declaration,
756 native_suffix, is_custom): 776 native_suffix, is_custom):
757 native_binding = '%s_%s_%s' % (self._interface.id, idl_name, native_suffix) 777 native_binding = '%s_%s_%s' % (self._interface.id, idl_name, native_suffix)
758 self._members_emitter.Emit( 778 self._members_emitter.Emit(
759 '\n' 779 '\n'
760 ' $DART_DECLARATION native "$NATIVE_BINDING";\n', 780 ' $DART_DECLARATION native "$NATIVE_BINDING";\n',
761 DART_DECLARATION=dart_declaration, NATIVE_BINDING=native_binding) 781 DART_DECLARATION=dart_declaration, NATIVE_BINDING=native_binding)
762 782
763 cpp_callback_name = '%s%s' % (idl_name, native_suffix) 783 cpp_callback_name = '%s%s' % (idl_name, native_suffix)
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
845 def _InstanceOfNode(database, interface): 865 def _InstanceOfNode(database, interface):
846 if interface.id == 'Node': 866 if interface.id == 'Node':
847 return True 867 return True
848 for parent in interface.parents: 868 for parent in interface.parents:
849 if not database.HasInterface(parent.type.id): 869 if not database.HasInterface(parent.type.id):
850 continue 870 continue
851 parent_interface = database.GetInterface(parent.type.id) 871 parent_interface = database.GetInterface(parent.type.id)
852 if _InstanceOfNode(database, parent_interface): 872 if _InstanceOfNode(database, parent_interface):
853 return True 873 return True
854 return False 874 return False
OLDNEW
« no previous file with comments | « lib/dom/scripts/generator.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698