| 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 systems to generate | 6 """This module provides shared functionality for systems to generate |
| 7 Dart APIs from the IDL database.""" | 7 Dart APIs from the IDL database.""" |
| 8 | 8 |
| 9 import copy | 9 import copy |
| 10 import re | 10 import re |
| (...skipping 637 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 648 class PrimitiveIDLTypeInfo(IDLTypeInfo): | 648 class PrimitiveIDLTypeInfo(IDLTypeInfo): |
| 649 def __init__(self, idl_type, dart_type, native_type=None, | 649 def __init__(self, idl_type, dart_type, native_type=None, |
| 650 webcore_getter_name='getAttribute', | 650 webcore_getter_name='getAttribute', |
| 651 webcore_setter_name='setAttribute'): | 651 webcore_setter_name='setAttribute'): |
| 652 super(PrimitiveIDLTypeInfo, self).__init__(idl_type, dart_type=dart_type, | 652 super(PrimitiveIDLTypeInfo, self).__init__(idl_type, dart_type=dart_type, |
| 653 native_type=native_type) | 653 native_type=native_type) |
| 654 self._webcore_getter_name = webcore_getter_name | 654 self._webcore_getter_name = webcore_getter_name |
| 655 self._webcore_setter_name = webcore_setter_name | 655 self._webcore_setter_name = webcore_setter_name |
| 656 | 656 |
| 657 def emit_to_native(self, emitter, idl_node, name, handle, interface_name): | 657 def emit_to_native(self, emitter, idl_node, name, handle, interface_name): |
| 658 arguments = [handle] | 658 if self.native_type() == 'String': |
| 659 if idl_node.ext_attrs.get('Optional') == 'DefaultIsNullString': | 659 arguments = [handle] |
| 660 arguments.append('DartUtilities::ConvertNullToDefaultValue') | 660 if idl_node.ext_attrs.get('Optional') == 'DefaultIsNullString': |
| 661 emitter.Emit( | 661 arguments.append('DartUtilities::ConvertNullToDefaultValue') |
| 662 '\n' | 662 emitter.Emit( |
| 663 ' const ParameterAdapter<$TYPE> $NAME($ARGUMENTS);\n' | 663 ' const ParameterAdapter<String> $NAME($ARGUMENTS);\n' |
| 664 ' if (!$NAME.conversionSuccessful()) {\n' | 664 ' if (!$NAME.conversionSuccessful()) {\n' |
| 665 ' exception = $NAME.exception();\n' | 665 ' exception = $NAME.exception();\n' |
| 666 ' goto fail;\n' | 666 ' goto fail;\n' |
| 667 ' }\n', | 667 ' }\n', |
| 668 TYPE=self.native_type(), | 668 NAME=name, |
| 669 NAME=name, | 669 ARGUMENTS=', '.join(arguments)) |
| 670 ARGUMENTS=', '.join(arguments)) | 670 else: |
| 671 type = self.native_type() |
| 672 if type == 'SerializedScriptValue': |
| 673 type = 'RefPtr<%s>' % type |
| 674 emitter.Emit( |
| 675 '\n' |
| 676 ' $TYPE $NAME = DartUtilities::dartTo$CAPITALIZED_TYPE($HANDLE,
exception);\n' |
| 677 ' if (exception)\n' |
| 678 ' goto fail;\n', |
| 679 TYPE=type, |
| 680 NAME=name, |
| 681 CAPITALIZED_TYPE=self._capitalized_native_type(), |
| 682 HANDLE=handle) |
| 671 return name | 683 return name |
| 672 | 684 |
| 673 def parameter_type(self): | 685 def parameter_type(self): |
| 674 if self.native_type() == 'String': | 686 if self.native_type() == 'String': |
| 675 return 'const String&' | 687 return 'const String&' |
| 676 return self.native_type() | 688 return self.native_type() |
| 677 | 689 |
| 678 def conversion_includes(self): | 690 def conversion_includes(self): |
| 679 return [] | 691 return [] |
| 680 | 692 |
| 681 def to_native_includes(sefl): | 693 def to_native_includes(sefl): |
| 682 return [] | 694 return [] |
| 683 | 695 |
| 684 def to_dart_conversion(self, value, interface_name=None, attributes=None): | 696 def to_dart_conversion(self, value, interface_name=None, attributes=None): |
| 685 conversion_arguments = [value] | 697 conversion_arguments = [value] |
| 686 if attributes and 'TreatReturnedNullStringAs' in attributes: | 698 if attributes and 'TreatReturnedNullStringAs' in attributes: |
| 687 conversion_arguments.append('DartUtilities::ConvertNullToDefaultValue') | 699 conversion_arguments.append('DartUtilities::ConvertNullToDefaultValue') |
| 688 function_name = re.sub(r' [a-z]', lambda x: x.group(0)[1:].upper(), self.nat
ive_type()) | 700 function_name = self._capitalized_native_type() |
| 689 function_name = function_name[0].lower() + function_name[1:] | 701 function_name = function_name[0].lower() + function_name[1:] |
| 690 function_name = 'DartUtilities::%sToDart' % function_name | 702 function_name = 'DartUtilities::%sToDart' % function_name |
| 691 return '%s(%s)' % (function_name, ', '.join(conversion_arguments)) | 703 return '%s(%s)' % (function_name, ', '.join(conversion_arguments)) |
| 692 | 704 |
| 693 def webcore_getter_name(self): | 705 def webcore_getter_name(self): |
| 694 return self._webcore_getter_name | 706 return self._webcore_getter_name |
| 695 | 707 |
| 696 def webcore_setter_name(self): | 708 def webcore_setter_name(self): |
| 697 return self._webcore_setter_name | 709 return self._webcore_setter_name |
| 698 | 710 |
| 711 def _capitalized_native_type(self): |
| 712 return re.sub(r'(^| )([a-z])', lambda x: x.group(2).upper(), self.native_typ
e()) |
| 713 |
| 714 |
| 699 class SVGTearOffIDLTypeInfo(IDLTypeInfo): | 715 class SVGTearOffIDLTypeInfo(IDLTypeInfo): |
| 700 def __init__(self, idl_type, native_type=''): | 716 def __init__(self, idl_type, native_type=''): |
| 701 super(SVGTearOffIDLTypeInfo, self).__init__(idl_type, | 717 super(SVGTearOffIDLTypeInfo, self).__init__(idl_type, |
| 702 native_type=native_type) | 718 native_type=native_type) |
| 703 | 719 |
| 704 def native_type(self): | 720 def native_type(self): |
| 705 if self._native_type: | 721 if self._native_type: |
| 706 return self._native_type | 722 return self._native_type |
| 707 tear_off_type = 'SVGPropertyTearOff' | 723 tear_off_type = 'SVGPropertyTearOff' |
| 708 if self._idl_type.endswith('List'): | 724 if self._idl_type.endswith('List'): |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 831 | 847 |
| 832 match = re.match(r'sequence<(\w+)>$', idl_type_name) | 848 match = re.match(r'sequence<(\w+)>$', idl_type_name) |
| 833 if match: | 849 if match: |
| 834 return SequenceIDLTypeInfo(idl_type_name, GetIDLTypeInfo(match.group(1))) | 850 return SequenceIDLTypeInfo(idl_type_name, GetIDLTypeInfo(match.group(1))) |
| 835 | 851 |
| 836 match = re.match(r'(\w+)\[\]$', idl_type_name) | 852 match = re.match(r'(\w+)\[\]$', idl_type_name) |
| 837 if match: | 853 if match: |
| 838 return SequenceIDLTypeInfo(idl_type_name, GetIDLTypeInfo(match.group(1))) | 854 return SequenceIDLTypeInfo(idl_type_name, GetIDLTypeInfo(match.group(1))) |
| 839 | 855 |
| 840 return IDLTypeInfo(idl_type_name) | 856 return IDLTypeInfo(idl_type_name) |
| OLD | NEW |