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

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

Issue 10314005: Cleanup ParameterAdapter 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 284 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 ' ScriptExecutionContext* context = DartUtilities::scriptExec utionContext();\n' 295 ' ScriptExecutionContext* context = DartUtilities::scriptExec utionContext();\n'
296 ' if (!context) {\n' 296 ' if (!context) {\n'
297 ' exception = Dart_NewString("Failed to create an object" );\n' 297 ' exception = Dart_NewString("Failed to create an object" );\n'
298 ' goto fail;\n' 298 ' goto fail;\n'
299 ' }\n') 299 ' }\n')
300 arguments.append('context') 300 arguments.append('context')
301 else: 301 else:
302 raise Exception('Unsupported CallWith=%s attribute' % call_with) 302 raise Exception('Unsupported CallWith=%s attribute' % call_with)
303 303
304 # Process constructor arguments. 304 # Process constructor arguments.
305 for (i, arg) in enumerate(constructor_info.idl_args): 305 for (i, argument) in enumerate(constructor_info.idl_args):
306 self._GenerateParameterAdapter(parameter_definitions_emitter, arg, i - 1) 306 argument_expression = self._GenerateParameterAdapter(
307 arguments.append(arg.id) 307 parameter_definitions_emitter, argument, i - 1)
308 arguments.append(argument_expression)
308 309
309 function_expression = '%s::%s' % (self._interface_type_info.native_type(), c reate_function) 310 function_expression = '%s::%s' % (self._interface_type_info.native_type(), c reate_function)
310 invocation = self._GenerateWebCoreInvocation(function_expression, arguments, 311 invocation = self._GenerateWebCoreInvocation(function_expression, arguments,
311 self._interface.id, self._interface.ext_attrs, raises_dom_exceptions) 312 self._interface.id, self._interface.ext_attrs, raises_dom_exceptions)
312 self._GenerateNativeCallback(callback_name='constructorCallback', 313 self._GenerateNativeCallback(callback_name='constructorCallback',
313 parameter_definitions=parameter_definitions_emitter.Fragments(), 314 parameter_definitions=parameter_definitions_emitter.Fragments(),
314 needs_receiver=False, invocation=invocation, 315 needs_receiver=False, invocation=invocation,
315 raises_exceptions=raises_exceptions) 316 raises_exceptions=raises_exceptions)
316 317
317 def _ImplClassName(self, interface_name): 318 def _ImplClassName(self, interface_name):
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
529 webcore_function_name = GetIDLTypeInfo(attr.type.id).webcore_setter_name() 530 webcore_function_name = GetIDLTypeInfo(attr.type.id).webcore_setter_name()
530 arguments.append(self._GenerateWebCoreReflectionAttributeName(attr)) 531 arguments.append(self._GenerateWebCoreReflectionAttributeName(attr))
531 else: 532 else:
532 webcore_function_name = re.sub(r'^(xml(?=[A-Z])|\w)', 533 webcore_function_name = re.sub(r'^(xml(?=[A-Z])|\w)',
533 lambda s: s.group(1).upper(), 534 lambda s: s.group(1).upper(),
534 attr.id) 535 attr.id)
535 webcore_function_name = 'set%s' % webcore_function_name 536 webcore_function_name = 'set%s' % webcore_function_name
536 if attr.type.id.startswith('SVGAnimated'): 537 if attr.type.id.startswith('SVGAnimated'):
537 webcore_function_name += 'Animated' 538 webcore_function_name += 'Animated'
538 539
539 arguments.append('value') 540 argument_expression = self._GenerateParameterAdapter(
541 parameter_definitions_emitter, attr, 0, adapter_name='value')
542 arguments.append(argument_expression)
540 543
541 self._GenerateParameterAdapter(
542 parameter_definitions_emitter, attr, 0, adapter_name='value')
543 parameter_definitions = parameter_definitions_emitter.Fragments() 544 parameter_definitions = parameter_definitions_emitter.Fragments()
544
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
552 def _HasNativeIndexGetter(self, interface): 552 def _HasNativeIndexGetter(self, interface):
553 return ('CustomIndexedGetter' in interface.ext_attrs or 553 return ('CustomIndexedGetter' in interface.ext_attrs or
554 'NumericIndexedGetter' in interface.ext_attrs) 554 'NumericIndexedGetter' in interface.ext_attrs)
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
648 raises_exceptions = raises_exceptions or len(operation.arguments) > 0 or ope ration.raises 648 raises_exceptions = raises_exceptions or len(operation.arguments) > 0 or ope ration.raises
649 649
650 # Process Dart arguments. 650 # Process Dart arguments.
651 for (i, argument) in enumerate(operation.arguments): 651 for (i, argument) in enumerate(operation.arguments):
652 if (i == len(operation.arguments) - 1 and 652 if (i == len(operation.arguments) - 1 and
653 self._interface.id == 'Console' and 653 self._interface.id == 'Console' and
654 argument.id == 'arg'): 654 argument.id == 'arg'):
655 # FIXME: we are skipping last argument here because it was added in 655 # FIXME: we are skipping last argument here because it was added in
656 # supplemental dart.idl. Cleanup dart.idl and remove this check. 656 # supplemental dart.idl. Cleanup dart.idl and remove this check.
657 break 657 break
658 self._GenerateParameterAdapter(parameter_definitions_emitter, argument, i) 658 argument_expression = self._GenerateParameterAdapter(
659 arguments.append(argument.id) 659 parameter_definitions_emitter, argument, i)
660 arguments.append(argument_expression)
660 661
661 if operation.id in ['addEventListener', 'removeEventListener']: 662 if operation.id in ['addEventListener', 'removeEventListener']:
662 # addEventListener's and removeEventListener's last argument is marked 663 # addEventListener's and removeEventListener's last argument is marked
663 # as optional in idl, but is not optional in webcore implementation. 664 # as optional in idl, but is not optional in webcore implementation.
664 if len(operation.arguments) == 2: 665 if len(operation.arguments) == 2:
665 arguments.append('false') 666 arguments.append('false')
666 667
667 if self._interface.id == 'CSSStyleDeclaration' and operation.id == 'setPrope rty': 668 if self._interface.id == 'CSSStyleDeclaration' and operation.id == 'setPrope rty':
668 # CSSStyleDeclaration.setProperty priority parameter is optional in Dart 669 # CSSStyleDeclaration.setProperty priority parameter is optional in Dart
669 # idl, but is not optional in webcore implementation. 670 # idl, but is not optional in webcore implementation.
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
720 CALLBACK_NAME=callback_name, 721 CALLBACK_NAME=callback_name,
721 BODY=body) 722 BODY=body)
722 723
723 def _GenerateParameterAdapter(self, emitter, idl_node, index, 724 def _GenerateParameterAdapter(self, emitter, idl_node, index,
724 adapter_name=None): 725 adapter_name=None):
725 """idl_node is IDLArgument or IDLAttribute.""" 726 """idl_node is IDLArgument or IDLAttribute."""
726 type_info = GetIDLTypeInfo(idl_node.type.id) 727 type_info = GetIDLTypeInfo(idl_node.type.id)
727 (adapter_type, include_name) = type_info.parameter_adapter_info() 728 (adapter_type, include_name) = type_info.parameter_adapter_info()
728 if include_name: 729 if include_name:
729 self._cpp_impl_includes.add(include_name) 730 self._cpp_impl_includes.add(include_name)
731 adapter_name = adapter_name or idl_node.id
730 flags = '' 732 flags = ''
731 if (idl_node.ext_attrs.get('Optional') == 'DefaultIsNullString' or 733 if (idl_node.ext_attrs.get('Optional') == 'DefaultIsNullString' or
732 'RequiredCppParameter' in idl_node.ext_attrs): 734 'RequiredCppParameter' in idl_node.ext_attrs):
733 flags = ', DartUtilities::ConvertNullToDefaultValue' 735 flags = ', DartUtilities::ConvertNullToDefaultValue'
734 emitter.Emit( 736 emitter.Emit(
735 '\n' 737 '\n'
736 ' const $ADAPTER_TYPE $NAME(Dart_GetNativeArgument(args, $INDEX)$ FLAGS);\n' 738 ' const $ADAPTER_TYPE $NAME(Dart_GetNativeArgument(args, $INDEX)$ FLAGS);\n'
737 ' if (!$NAME.conversionSuccessful()) {\n' 739 ' if (!$NAME.conversionSuccessful()) {\n'
738 ' exception = $NAME.exception();\n' 740 ' exception = $NAME.exception();\n'
739 ' goto fail;\n' 741 ' goto fail;\n'
740 ' }\n', 742 ' }\n',
741 ADAPTER_TYPE=adapter_type, 743 ADAPTER_TYPE=adapter_type,
742 NAME=adapter_name or idl_node.id, 744 NAME=adapter_name,
743 INDEX=index + 1, 745 INDEX=index + 1,
744 FLAGS=flags) 746 FLAGS=flags)
745 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
746 def _GenerateNativeBinding(self, idl_name, argument_count, dart_declaration, 755 def _GenerateNativeBinding(self, idl_name, argument_count, dart_declaration,
747 native_suffix, is_custom): 756 native_suffix, is_custom):
748 native_binding = '%s_%s_%s' % (self._interface.id, idl_name, native_suffix) 757 native_binding = '%s_%s_%s' % (self._interface.id, idl_name, native_suffix)
749 self._members_emitter.Emit( 758 self._members_emitter.Emit(
750 '\n' 759 '\n'
751 ' $DART_DECLARATION native "$NATIVE_BINDING";\n', 760 ' $DART_DECLARATION native "$NATIVE_BINDING";\n',
752 DART_DECLARATION=dart_declaration, NATIVE_BINDING=native_binding) 761 DART_DECLARATION=dart_declaration, NATIVE_BINDING=native_binding)
753 762
754 cpp_callback_name = '%s%s' % (idl_name, native_suffix) 763 cpp_callback_name = '%s%s' % (idl_name, native_suffix)
755 self._cpp_resolver_emitter.Emit( 764 self._cpp_resolver_emitter.Emit(
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
836 def _InstanceOfNode(database, interface): 845 def _InstanceOfNode(database, interface):
837 if interface.id == 'Node': 846 if interface.id == 'Node':
838 return True 847 return True
839 for parent in interface.parents: 848 for parent in interface.parents:
840 if not database.HasInterface(parent.type.id): 849 if not database.HasInterface(parent.type.id):
841 continue 850 continue
842 parent_interface = database.GetInterface(parent.type.id) 851 parent_interface = database.GetInterface(parent.type.id)
843 if _InstanceOfNode(database, parent_interface): 852 if _InstanceOfNode(database, parent_interface):
844 return True 853 return True
845 return False 854 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