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

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

Issue 10334003: Rework static method support. (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/systeminterface.py ('k') | lib/dom/scripts/systemwrapping.py » ('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
11 import systemwrapping 11 import systemwrapping
12 from generator import * 12 from generator import *
13 from systembase import * 13 from systembase import *
14 from idlnode import IDLOperation
14 15
15 class NativeImplementationSystem(System): 16 class NativeImplementationSystem(System):
16 17
17 def __init__(self, templates, database, emitters, auxiliary_dir, output_dir): 18 def __init__(self, templates, database, emitters, auxiliary_dir, output_dir):
18 super(NativeImplementationSystem, self).__init__( 19 super(NativeImplementationSystem, self).__init__(
19 templates, database, emitters, output_dir) 20 templates, database, emitters, output_dir)
20 21
21 self._auxiliary_dir = auxiliary_dir 22 self._auxiliary_dir = auxiliary_dir
22 self._dom_public_files = [] 23 self._dom_public_files = []
23 self._dom_impl_files = [] 24 self._dom_impl_files = []
(...skipping 532 matching lines...) Expand 10 before | Expand all | Expand 10 after
556 def _EmitNativeIndexGetter(self, interface, element_type): 557 def _EmitNativeIndexGetter(self, interface, element_type):
557 dart_declaration = '%s operator[](int index)' % element_type 558 dart_declaration = '%s operator[](int index)' % element_type
558 self._GenerateNativeBinding('numericIndexGetter', 2, dart_declaration, 559 self._GenerateNativeBinding('numericIndexGetter', 2, dart_declaration,
559 'Callback', True) 560 'Callback', True)
560 561
561 def _EmitNativeIndexSetter(self, interface, element_type): 562 def _EmitNativeIndexSetter(self, interface, element_type):
562 dart_declaration = 'void operator[]=(int index, %s value)' % element_type 563 dart_declaration = 'void operator[]=(int index, %s value)' % element_type
563 self._GenerateNativeBinding('numericIndexSetter', 3, dart_declaration, 564 self._GenerateNativeBinding('numericIndexSetter', 3, dart_declaration,
564 'Callback', True) 565 'Callback', True)
565 566
566 def AddOperation(self, info): 567 def AddOperation(self, info):
sra1 2012/05/03 19:12:35 I think in many cases we will want to handle stati
Anton Muhin 2012/05/04 11:05:13 Done.
567 """ 568 """
568 Arguments: 569 Arguments:
569 info: An OperationInfo object. 570 info: An OperationInfo object.
570 """ 571 """
571 572
572 if 'CheckSecurityForNode' in info.overloads[0].ext_attrs: 573 if 'CheckSecurityForNode' in info.overloads[0].ext_attrs:
573 # FIXME: exclude from interface as well. 574 # FIXME: exclude from interface as well.
574 return 575 return
575 576
576 if 'Custom' in info.overloads[0].ext_attrs: 577 if 'Custom' in info.overloads[0].ext_attrs:
577 parameters = info.ParametersImplementationDeclaration() 578 parameters = info.ParametersImplementationDeclaration()
578 dart_declaration = '%s %s(%s)' % (info.type_name, info.name, parameters) 579 dart_declaration = '%s %s(%s)' % (info.type_name, info.name, parameters)
579 argument_count = 1 + len(info.param_infos) 580 argument_count = 1 + len(info.param_infos)
580 self._GenerateNativeBinding(info.name, argument_count, dart_declaration, 581 self._GenerateNativeBinding(info.name, argument_count, dart_declaration,
581 'Callback', True) 582 'Callback', True)
582 return 583 return
583 584
585 modifier = ''
586 if info.IsStatic():
587 modifier = 'static '
584 body = self._members_emitter.Emit( 588 body = self._members_emitter.Emit(
585 '\n' 589 '\n'
586 ' $TYPE $NAME($PARAMETERS) {\n' 590 ' $MODIFIER$TYPE $NAME($PARAMETERS) {\n'
587 '$!BODY' 591 '$!BODY'
588 ' }\n', 592 ' }\n',
593 MODIFIER=modifier,
589 TYPE=info.type_name, 594 TYPE=info.type_name,
590 NAME=info.name, 595 NAME=info.name,
591 PARAMETERS=info.ParametersImplementationDeclaration()) 596 PARAMETERS=info.ParametersImplementationDeclaration())
592 597
593 # Process in order of ascending number of arguments to ensure missing 598 # Process in order of ascending number of arguments to ensure missing
594 # optional arguments are processed early. 599 # optional arguments are processed early.
595 overloads = sorted(info.overloads, 600 overloads = sorted(info.overloads,
596 key=lambda overload: len(overload.arguments)) 601 key=lambda overload: len(overload.arguments))
597 self._native_version = 0 602 self._native_version = 0
598 fallthrough = self.GenerateDispatch(body, info, ' ', 0, overloads) 603 fallthrough = self.GenerateDispatch(body, info, ' ', 0, overloads)
(...skipping 23 matching lines...) Expand all
622 INDENT=indent, 627 INDENT=indent,
623 NATIVENAME=native_name, 628 NATIVENAME=native_name,
624 ARGS=argument_list) 629 ARGS=argument_list)
625 else: 630 else:
626 dispatch_emitter.Emit('$(INDENT)_$NATIVENAME($ARGS);\n' 631 dispatch_emitter.Emit('$(INDENT)_$NATIVENAME($ARGS);\n'
627 '$(INDENT)return;\n', 632 '$(INDENT)return;\n',
628 INDENT=indent, 633 INDENT=indent,
629 NATIVENAME=native_name, 634 NATIVENAME=native_name,
630 ARGS=argument_list) 635 ARGS=argument_list)
631 # Generate binding. 636 # Generate binding.
632 dart_declaration = '%s _%s(%s)' % (info.type_name, native_name, 637 modifier = ''
638 if operation.is_static:
639 modifier = 'static '
640 dart_declaration = '%s%s _%s(%s)' % (modifier, info.type_name, native_name,
633 argument_list) 641 argument_list)
634 is_custom = 'Custom' in operation.ext_attrs 642 is_custom = 'Custom' in operation.ext_attrs
635 cpp_callback_name = self._GenerateNativeBinding( 643 cpp_callback_name = self._GenerateNativeBinding(
636 native_name, 1 + len(operation.arguments), dart_declaration, 'Callback', 644 native_name, 1 + len(operation.arguments), dart_declaration, 'Callback',
637 is_custom) 645 is_custom)
638 if is_custom: 646 if is_custom:
639 return 647 return
640 648
641 # Generate callback. 649 # Generate callback.
642 webcore_function_name = operation.ext_attrs.get('ImplementedAs', operation.i d) 650 webcore_function_name = operation.ext_attrs.get('ImplementedAs', operation.i d)
643 651
644 parameter_definitions_emitter = emitter.Emitter() 652 parameter_definitions_emitter = emitter.Emitter()
645 arguments = [] 653 arguments = []
646 raises_exceptions = self._GenerateCallWithHandling( 654 raises_exceptions = self._GenerateCallWithHandling(
647 operation, parameter_definitions_emitter, arguments) 655 operation, parameter_definitions_emitter, arguments)
648 raises_exceptions = raises_exceptions or len(operation.arguments) > 0 or ope ration.raises 656 raises_exceptions = raises_exceptions or len(operation.arguments) > 0 or ope ration.raises
649 657
650 # Process Dart arguments. 658 # Process Dart arguments.
651 for (i, argument) in enumerate(operation.arguments): 659 start_index = 1
652 if (i == len(operation.arguments) - 1 and 660 if operation.is_static:
661 start_index = 0
662 for (i, argument) in enumerate(operation.arguments, start_index):
663 if (i - start_index == len(operation.arguments) - 1 and
653 self._interface.id == 'Console' and 664 self._interface.id == 'Console' and
654 argument.id == 'arg'): 665 argument.id == 'arg'):
655 # FIXME: we are skipping last argument here because it was added in 666 # FIXME: we are skipping last argument here because it was added in
656 # supplemental dart.idl. Cleanup dart.idl and remove this check. 667 # supplemental dart.idl. Cleanup dart.idl and remove this check.
657 break 668 break
658 self._GenerateParameterAdapter(parameter_definitions_emitter, argument, i) 669 self._GenerateParameterAdapter(parameter_definitions_emitter, argument, i)
podivilov 2012/05/03 09:05:42 Please add start_index here and let i be the index
659 arguments.append(argument.id) 670 arguments.append(argument.id)
660 671
661 if operation.id in ['addEventListener', 'removeEventListener']: 672 if operation.id in ['addEventListener', 'removeEventListener']:
662 # addEventListener's and removeEventListener's last argument is marked 673 # addEventListener's and removeEventListener's last argument is marked
663 # as optional in idl, but is not optional in webcore implementation. 674 # as optional in idl, but is not optional in webcore implementation.
664 if len(operation.arguments) == 2: 675 if len(operation.arguments) == 2:
665 arguments.append('false') 676 arguments.append('false')
666 677
667 if self._interface.id == 'CSSStyleDeclaration' and operation.id == 'setPrope rty': 678 if self._interface.id == 'CSSStyleDeclaration' and operation.id == 'setPrope rty':
668 # CSSStyleDeclaration.setProperty priority parameter is optional in Dart 679 # CSSStyleDeclaration.setProperty priority parameter is optional in Dart
669 # idl, but is not optional in webcore implementation. 680 # idl, but is not optional in webcore implementation.
670 if len(operation.arguments) == 2: 681 if len(operation.arguments) == 2:
671 arguments.append('String()') 682 arguments.append('String()')
672 683
673 if 'NeedsUserGestureCheck' in operation.ext_attrs: 684 if 'NeedsUserGestureCheck' in operation.ext_attrs:
674 arguments.append('DartUtilities::processingUserGesture') 685 arguments.append('DartUtilities::processingUserGesture')
675 686
676 function_expression = self._GenerateWebCoreFunctionExpression(webcore_functi on_name, operation) 687 function_expression = self._GenerateWebCoreFunctionExpression(webcore_functi on_name, operation)
677 invocation = self._GenerateWebCoreInvocation(function_expression, arguments, 688 invocation = self._GenerateWebCoreInvocation(function_expression, arguments,
678 operation.type.id, operation.ext_attrs, operation.raises) 689 operation.type.id, operation.ext_attrs, operation.raises)
679 self._GenerateNativeCallback(cpp_callback_name, 690 self._GenerateNativeCallback(cpp_callback_name,
680 parameter_definitions=parameter_definitions_emitter.Fragments(), 691 parameter_definitions=parameter_definitions_emitter.Fragments(),
681 needs_receiver=True, invocation=invocation, 692 needs_receiver=not operation.is_static, invocation=invocation,
682 raises_exceptions=raises_exceptions) 693 raises_exceptions=raises_exceptions)
683 694
684 def _GenerateNativeCallback(self, callback_name, parameter_definitions, 695 def _GenerateNativeCallback(self, callback_name, parameter_definitions,
685 needs_receiver, invocation, raises_exceptions): 696 needs_receiver, invocation, raises_exceptions):
686 697
687 if needs_receiver: 698 if needs_receiver:
688 parameter_definitions = emitter.Format( 699 parameter_definitions = emitter.Format(
689 ' $WEBCORE_CLASS_NAME* receiver = DartDOMWrapper::receiver< $WE BCORE_CLASS_NAME >(args);\n' 700 ' $WEBCORE_CLASS_NAME* receiver = DartDOMWrapper::receiver< $WE BCORE_CLASS_NAME >(args);\n'
690 ' $PARAMETER_DEFINITIONS\n', 701 ' $PARAMETER_DEFINITIONS\n',
691 WEBCORE_CLASS_NAME=self._interface_type_info.native_type(), 702 WEBCORE_CLASS_NAME=self._interface_type_info.native_type(),
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
733 flags = ', DartUtilities::ConvertNullToDefaultValue' 744 flags = ', DartUtilities::ConvertNullToDefaultValue'
734 emitter.Emit( 745 emitter.Emit(
735 '\n' 746 '\n'
736 ' const $ADAPTER_TYPE $NAME(Dart_GetNativeArgument(args, $INDEX)$ FLAGS);\n' 747 ' const $ADAPTER_TYPE $NAME(Dart_GetNativeArgument(args, $INDEX)$ FLAGS);\n'
737 ' if (!$NAME.conversionSuccessful()) {\n' 748 ' if (!$NAME.conversionSuccessful()) {\n'
738 ' exception = $NAME.exception();\n' 749 ' exception = $NAME.exception();\n'
739 ' goto fail;\n' 750 ' goto fail;\n'
740 ' }\n', 751 ' }\n',
741 ADAPTER_TYPE=adapter_type, 752 ADAPTER_TYPE=adapter_type,
742 NAME=adapter_name or idl_node.id, 753 NAME=adapter_name or idl_node.id,
743 INDEX=index + 1, 754 INDEX=index,
744 FLAGS=flags) 755 FLAGS=flags)
745 756
746 def _GenerateNativeBinding(self, idl_name, argument_count, dart_declaration, 757 def _GenerateNativeBinding(self, idl_name, argument_count, dart_declaration,
747 native_suffix, is_custom): 758 native_suffix, is_custom):
748 native_binding = '%s_%s_%s' % (self._interface.id, idl_name, native_suffix) 759 native_binding = '%s_%s_%s' % (self._interface.id, idl_name, native_suffix)
749 self._members_emitter.Emit( 760 self._members_emitter.Emit(
750 '\n' 761 '\n'
751 ' $DART_DECLARATION native "$NATIVE_BINDING";\n', 762 ' $DART_DECLARATION native "$NATIVE_BINDING";\n',
752 DART_DECLARATION=dart_declaration, NATIVE_BINDING=native_binding) 763 DART_DECLARATION=dart_declaration, NATIVE_BINDING=native_binding)
753 764
(...skipping 22 matching lines...) Expand all
776 if self._interface.id.startswith('SVG') and not attr.id in svg_exceptions: 787 if self._interface.id.startswith('SVG') and not attr.id in svg_exceptions:
777 namespace = 'SVGNames' 788 namespace = 'SVGNames'
778 self._cpp_impl_includes.add('"%s.h"' % namespace) 789 self._cpp_impl_includes.add('"%s.h"' % namespace)
779 790
780 attribute_name = attr.ext_attrs['Reflect'] or attr.id.lower() 791 attribute_name = attr.ext_attrs['Reflect'] or attr.id.lower()
781 return 'WebCore::%s::%sAttr' % (namespace, attribute_name) 792 return 'WebCore::%s::%sAttr' % (namespace, attribute_name)
782 793
783 def _GenerateWebCoreFunctionExpression(self, function_name, idl_node): 794 def _GenerateWebCoreFunctionExpression(self, function_name, idl_node):
784 if 'ImplementedBy' in idl_node.ext_attrs: 795 if 'ImplementedBy' in idl_node.ext_attrs:
785 return '%s::%s' % (idl_node.ext_attrs['ImplementedBy'], function_name) 796 return '%s::%s' % (idl_node.ext_attrs['ImplementedBy'], function_name)
797 if isinstance(idl_node, IDLOperation) and idl_node.is_static:
podivilov 2012/05/03 09:05:42 I doubt that static attributes will be accessible
798 return '%s::%s' % (self._interface_type_info.idl_type(), function_name)
786 return '%s%s' % (self._interface_type_info.receiver(), function_name) 799 return '%s%s' % (self._interface_type_info.receiver(), function_name)
787 800
788 def _GenerateWebCoreInvocation(self, function_expression, arguments, 801 def _GenerateWebCoreInvocation(self, function_expression, arguments,
789 idl_return_type, attributes, raises_dom_exceptions): 802 idl_return_type, attributes, raises_dom_exceptions):
790 invocation_template = ' $FUNCTION_CALL;\n' 803 invocation_template = ' $FUNCTION_CALL;\n'
791 if idl_return_type != 'void': 804 if idl_return_type != 'void':
792 return_type_info = GetIDLTypeInfo(idl_return_type) 805 return_type_info = GetIDLTypeInfo(idl_return_type)
793 self._cpp_impl_includes |= set(return_type_info.conversion_includes()) 806 self._cpp_impl_includes |= set(return_type_info.conversion_includes())
794 807
795 # Generate to Dart conversion of C++ value. 808 # Generate to Dart conversion of C++ value.
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
836 def _InstanceOfNode(database, interface): 849 def _InstanceOfNode(database, interface):
837 if interface.id == 'Node': 850 if interface.id == 'Node':
838 return True 851 return True
839 for parent in interface.parents: 852 for parent in interface.parents:
840 if not database.HasInterface(parent.type.id): 853 if not database.HasInterface(parent.type.id):
841 continue 854 continue
842 parent_interface = database.GetInterface(parent.type.id) 855 parent_interface = database.GetInterface(parent.type.id)
843 if _InstanceOfNode(database, parent_interface): 856 if _InstanceOfNode(database, parent_interface):
844 return True 857 return True
845 return False 858 return False
OLDNEW
« no previous file with comments | « lib/dom/scripts/systeminterface.py ('k') | lib/dom/scripts/systemwrapping.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698