| OLD | NEW |
| 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 system to generate | 6 """This module provides shared functionality for the system to generate |
| 7 Dart:html APIs from the IDL database.""" | 7 Dart:html APIs from the IDL database.""" |
| 8 | 8 |
| 9 import emitter | 9 import emitter |
| 10 import os | 10 import os |
| (...skipping 530 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 541 | 541 |
| 542 # If the type has a conversion we need a getter or setter to contain the | 542 # If the type has a conversion we need a getter or setter to contain the |
| 543 # conversion code. | 543 # conversion code. |
| 544 if (self._OutputConversion(attribute.type.id, attribute.id) or | 544 if (self._OutputConversion(attribute.type.id, attribute.id) or |
| 545 self._InputConversion(attribute.type.id, attribute.id)): | 545 self._InputConversion(attribute.type.id, attribute.id)): |
| 546 self._AddAttributeUsingProperties(attribute, html_name, read_only) | 546 self._AddAttributeUsingProperties(attribute, html_name, read_only) |
| 547 return | 547 return |
| 548 | 548 |
| 549 output_type = self.SecureOutputType(attribute.type.id) | 549 output_type = self.SecureOutputType(attribute.type.id) |
| 550 input_type = self._NarrowInputType(attribute.type.id) | 550 input_type = self._NarrowInputType(attribute.type.id) |
| 551 annotations = self._Annotations(attribute.type.id, attribute.id) |
| 551 self.EmitAttributeDocumentation(attribute) | 552 self.EmitAttributeDocumentation(attribute) |
| 552 if not read_only: | 553 if not read_only: |
| 553 self._members_emitter.Emit( | 554 self._members_emitter.Emit( |
| 554 '\n $TYPE $NAME;' | 555 '\n $ANNOTATIONS$TYPE $NAME;' |
| 555 '\n', | 556 '\n', |
| 557 ANNOTATIONS=annotations, |
| 556 NAME=DartDomNameOfAttribute(attribute), | 558 NAME=DartDomNameOfAttribute(attribute), |
| 557 TYPE=output_type) | 559 TYPE=output_type) |
| 558 else: | 560 else: |
| 559 self._members_emitter.Emit( | 561 self._members_emitter.Emit( |
| 560 '\n final $TYPE $NAME;' | 562 '\n $(ANNOTATIONS)final $TYPE $NAME;' |
| 561 '\n', | 563 '\n', |
| 564 ANNOTATIONS=annotations, |
| 562 NAME=DartDomNameOfAttribute(attribute), | 565 NAME=DartDomNameOfAttribute(attribute), |
| 563 TYPE=output_type) | 566 TYPE=output_type) |
| 564 | 567 |
| 565 def _AddAttributeUsingProperties(self, attribute, html_name, read_only): | 568 def _AddAttributeUsingProperties(self, attribute, html_name, read_only): |
| 566 self._AddRenamingGetter(attribute, html_name) | 569 self._AddRenamingGetter(attribute, html_name) |
| 567 if not read_only: | 570 if not read_only: |
| 568 self._AddRenamingSetter(attribute, html_name) | 571 self._AddRenamingSetter(attribute, html_name) |
| 569 | 572 |
| 570 def _AddInterfaceAttribute(self, attribute): | 573 def _AddInterfaceAttribute(self, attribute): |
| 571 self._members_emitter.Emit( | 574 self._members_emitter.Emit( |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 653 # Any conversions needed? | 656 # Any conversions needed? |
| 654 self._AddOperationWithConversions(info, html_name) | 657 self._AddOperationWithConversions(info, html_name) |
| 655 else: | 658 else: |
| 656 self._AddDirectNativeOperation(info, html_name) | 659 self._AddDirectNativeOperation(info, html_name) |
| 657 | 660 |
| 658 def _AddDirectNativeOperation(self, info, html_name): | 661 def _AddDirectNativeOperation(self, info, html_name): |
| 659 # Do we need a native body? | 662 # Do we need a native body? |
| 660 if html_name != info.declared_name: | 663 if html_name != info.declared_name: |
| 661 return_type = self.SecureOutputType(info.type_name) | 664 return_type = self.SecureOutputType(info.type_name) |
| 662 | 665 |
| 663 operation_emitter = self._members_emitter.Emit('$!SCOPE', | 666 operation_emitter = self._members_emitter.Emit( |
| 667 '$!SCOPE', |
| 664 MODIFIERS='static ' if info.IsStatic() else '', | 668 MODIFIERS='static ' if info.IsStatic() else '', |
| 669 ANNOTATIONS=self._Annotations(info.type_name, info.declared_name), |
| 665 TYPE=return_type, | 670 TYPE=return_type, |
| 666 HTML_NAME=html_name, | 671 HTML_NAME=html_name, |
| 667 NAME=info.declared_name, | 672 NAME=info.declared_name, |
| 668 PARAMS=info.ParametersDeclaration(self._NarrowInputType)) | 673 PARAMS=info.ParametersDeclaration(self._NarrowInputType)) |
| 669 | 674 |
| 670 operation_emitter.Emit( | 675 operation_emitter.Emit( |
| 671 '\n' | 676 '\n' |
| 672 #' // @native("$NAME")\n;' | 677 ' $ANNOTATIONS' |
| 673 ' $MODIFIERS$TYPE $(HTML_NAME)($PARAMS) native "$NAME";\n') | 678 '$MODIFIERS$TYPE $(HTML_NAME)($PARAMS) native "$NAME";\n') |
| 674 else: | 679 else: |
| 675 self._members_emitter.Emit( | 680 self._members_emitter.Emit( |
| 676 '\n' | 681 '\n' |
| 677 ' $MODIFIERS$TYPE $NAME($PARAMS) native;\n', | 682 ' $ANNOTATIONS$MODIFIERS$TYPE $NAME($PARAMS) native;\n', |
| 678 MODIFIERS='static ' if info.IsStatic() else '', | 683 MODIFIERS='static ' if info.IsStatic() else '', |
| 684 ANNOTATIONS=self._Annotations(info.type_name, info.declared_name), |
| 679 TYPE=self.SecureOutputType(info.type_name), | 685 TYPE=self.SecureOutputType(info.type_name), |
| 680 NAME=info.name, | 686 NAME=info.name, |
| 681 PARAMS=info.ParametersDeclaration(self._NarrowInputType)) | 687 PARAMS=info.ParametersDeclaration(self._NarrowInputType)) |
| 682 | 688 |
| 683 def _AddOperationWithConversions(self, info, html_name): | 689 def _AddOperationWithConversions(self, info, html_name): |
| 684 # Assert all operations have same return type. | 690 # Assert all operations have same return type. |
| 685 assert len(set([op.type.id for op in info.operations])) == 1 | 691 assert len(set([op.type.id for op in info.operations])) == 1 |
| 686 output_conversion = self._OutputConversion(info.type_name, | 692 output_conversion = self._OutputConversion(info.type_name, |
| 687 info.declared_name) | 693 info.declared_name) |
| 688 if output_conversion: | 694 if output_conversion: |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 770 if output_conversion: | 776 if output_conversion: |
| 771 call = '%s(%s)' % (output_conversion.function_name, call) | 777 call = '%s(%s)' % (output_conversion.function_name, call) |
| 772 | 778 |
| 773 if operation.type.id == 'void': | 779 if operation.type.id == 'void': |
| 774 call_emitter.Emit('$(INDENT)$CALL;\n$(INDENT)return;\n', | 780 call_emitter.Emit('$(INDENT)$CALL;\n$(INDENT)return;\n', |
| 775 CALL=call) | 781 CALL=call) |
| 776 else: | 782 else: |
| 777 call_emitter.Emit('$(INDENT)return $CALL;\n', CALL=call) | 783 call_emitter.Emit('$(INDENT)return $CALL;\n', CALL=call) |
| 778 | 784 |
| 779 self._members_emitter.Emit( | 785 self._members_emitter.Emit( |
| 780 ' $MODIFIERS$TYPE$TARGET($PARAMS) native "$NATIVE";\n', | 786 ' $MODIFIERS$ANNOTATIONS$TYPE$TARGET($PARAMS) native "$NATIVE";\n', |
| 781 MODIFIERS='static ' if info.IsStatic() else '', | 787 MODIFIERS='static ' if info.IsStatic() else '', |
| 788 ANNOTATIONS=self._Annotations(info.type_name, info.declared_name), |
| 782 TYPE=TypeOrNothing(native_return_type), | 789 TYPE=TypeOrNothing(native_return_type), |
| 783 TARGET=target, | 790 TARGET=target, |
| 784 PARAMS=', '.join(target_parameters), | 791 PARAMS=', '.join(target_parameters), |
| 785 NATIVE=info.declared_name) | 792 NATIVE=info.declared_name) |
| 786 | 793 |
| 787 def GenerateChecksAndCall(operation, argument_count): | 794 def GenerateChecksAndCall(operation, argument_count): |
| 788 checks = [] | 795 checks = [] |
| 789 for i in range(0, argument_count): | 796 for i in range(0, argument_count): |
| 790 argument = operation.arguments[i] | 797 argument = operation.arguments[i] |
| 791 parameter_name = parameter_names[i] | 798 parameter_name = parameter_names[i] |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 855 return FindConversion(idl_type, 'get', self._interface.id, member) | 862 return FindConversion(idl_type, 'get', self._interface.id, member) |
| 856 | 863 |
| 857 def _InputConversion(self, idl_type, member): | 864 def _InputConversion(self, idl_type, member): |
| 858 return FindConversion(idl_type, 'set', self._interface.id, member) | 865 return FindConversion(idl_type, 'set', self._interface.id, member) |
| 859 | 866 |
| 860 def _HasCustomImplementation(self, member_name): | 867 def _HasCustomImplementation(self, member_name): |
| 861 member_name = '%s.%s' % (self._interface_type_info.interface_name(), | 868 member_name = '%s.%s' % (self._interface_type_info.interface_name(), |
| 862 member_name) | 869 member_name) |
| 863 return member_name in _js_custom_members | 870 return member_name in _js_custom_members |
| 864 | 871 |
| 872 def _Annotations(self, idl_type, member_name): |
| 873 annotations = FindAnnotations(idl_type, self._interface.id, member_name) |
| 874 if annotations: |
| 875 return '%s\n ' % annotations |
| 876 else: |
| 877 return '' |
| 878 |
| 865 def CustomJSMembers(self): | 879 def CustomJSMembers(self): |
| 866 return _js_custom_members | 880 return _js_custom_members |
| 867 | 881 |
| 868 def _NarrowToImplementationType(self, type_name): | 882 def _NarrowToImplementationType(self, type_name): |
| 869 return self._type_registry.TypeInfo(type_name).narrow_dart_type() | 883 return self._type_registry.TypeInfo(type_name).narrow_dart_type() |
| 870 | 884 |
| 871 def _NarrowInputType(self, type_name): | 885 def _NarrowInputType(self, type_name): |
| 872 return self._NarrowToImplementationType(type_name) | 886 return self._NarrowToImplementationType(type_name) |
| 873 | 887 |
| 874 def _FindShadowedAttribute(self, attr): | 888 def _FindShadowedAttribute(self, attr): |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 970 'svg': DartLibrary('svg', template_loader, library_type, output_dir), | 984 'svg': DartLibrary('svg', template_loader, library_type, output_dir), |
| 971 'html': DartLibrary('html', template_loader, library_type, output_dir), | 985 'html': DartLibrary('html', template_loader, library_type, output_dir), |
| 972 } | 986 } |
| 973 | 987 |
| 974 def AddFile(self, basename, library_name, path): | 988 def AddFile(self, basename, library_name, path): |
| 975 self._libraries[library_name].AddFile(path) | 989 self._libraries[library_name].AddFile(path) |
| 976 | 990 |
| 977 def Emit(self, emitter, auxiliary_dir): | 991 def Emit(self, emitter, auxiliary_dir): |
| 978 for lib in self._libraries.values(): | 992 for lib in self._libraries.values(): |
| 979 lib.Emit(emitter, auxiliary_dir) | 993 lib.Emit(emitter, auxiliary_dir) |
| OLD | NEW |