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

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: Emit to native conversion in virtual method. 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') | lib/dom/templates/dom/native/cpp_callback_header.template » ('j') | 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,
Anton Muhin 2012/05/04 12:30:50 should it still be named _GenerateParameterAdapter
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 if not IsPrimitiveType(idl_node.type.id):
729 if include_name: 729 self._cpp_impl_includes.add('"Dart%s.h"' % type_info.idl_type())
730 self._cpp_impl_includes.add(include_name) 730 argument_name = argument_name or idl_node.id
731 adapter_name = adapter_name or idl_node.id 731 handle = 'Dart_GetNativeArgument(args, %i)' % (index + 1)
Anton Muhin 2012/05/04 12:30:50 I've submitted a change already, so you shouldn't
732 flags = '' 732 return type_info.emit_to_native(emitter, idl_node, argument_name, handle, se lf._interface.id)
733 if (idl_node.ext_attrs.get('Optional') == 'DefaultIsNullString' or
734 'RequiredCppParameter' in idl_node.ext_attrs):
735 flags = ', DartUtilities::ConvertNullToDefaultValue'
736 emitter.Emit(
737 '\n'
738 ' const $ADAPTER_TYPE $NAME(Dart_GetNativeArgument(args, $INDEX)$ FLAGS);\n'
739 ' if (!$NAME.conversionSuccessful()) {\n'
740 ' exception = $NAME.exception();\n'
741 ' goto fail;\n'
742 ' }\n',
743 ADAPTER_TYPE=adapter_type,
744 NAME=adapter_name,
745 INDEX=index + 1,
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 733
755 def _GenerateNativeBinding(self, idl_name, argument_count, dart_declaration, 734 def _GenerateNativeBinding(self, idl_name, argument_count, dart_declaration,
756 native_suffix, is_custom): 735 native_suffix, is_custom):
757 native_binding = '%s_%s_%s' % (self._interface.id, idl_name, native_suffix) 736 native_binding = '%s_%s_%s' % (self._interface.id, idl_name, native_suffix)
758 self._members_emitter.Emit( 737 self._members_emitter.Emit(
759 '\n' 738 '\n'
760 ' $DART_DECLARATION native "$NATIVE_BINDING";\n', 739 ' $DART_DECLARATION native "$NATIVE_BINDING";\n',
761 DART_DECLARATION=dart_declaration, NATIVE_BINDING=native_binding) 740 DART_DECLARATION=dart_declaration, NATIVE_BINDING=native_binding)
762 741
763 cpp_callback_name = '%s%s' % (idl_name, native_suffix) 742 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): 824 def _InstanceOfNode(database, interface):
846 if interface.id == 'Node': 825 if interface.id == 'Node':
847 return True 826 return True
848 for parent in interface.parents: 827 for parent in interface.parents:
849 if not database.HasInterface(parent.type.id): 828 if not database.HasInterface(parent.type.id):
850 continue 829 continue
851 parent_interface = database.GetInterface(parent.type.id) 830 parent_interface = database.GetInterface(parent.type.id)
852 if _InstanceOfNode(database, parent_interface): 831 if _InstanceOfNode(database, parent_interface):
853 return True 832 return True
854 return False 833 return False
OLDNEW
« no previous file with comments | « lib/dom/scripts/generator.py ('k') | lib/dom/templates/dom/native/cpp_callback_header.template » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698