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

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

Issue 10662047: Remove ParameterAdapters for all types except for String. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 6 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 | « no previous file | 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 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
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':
Anton Muhin 2012/06/26 12:56:41 maybe introduce a separate typeinfo for String and
podivilov 2012/06/26 13:14:49 We need to refactor string conversions first. Then
Anton Muhin 2012/06/26 13:24:43 What do you mean be refactor string conversions?
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 def replace(match):
713 return match.group(2)[0].upper() + match.group(2)[1:]
714 return re.sub(r'(^| )([a-z]\w*)', replace, self.native_type())
Anton Muhin 2012/06/26 12:56:41 why it changed?
podivilov 2012/06/26 13:14:49 It's now used to generate both fooBarToDart and da
Anton Muhin 2012/06/26 13:24:43 What's the difference in semantics except for 1st
podivilov 2012/06/26 13:58:31 Done.
715
716
699 class SVGTearOffIDLTypeInfo(IDLTypeInfo): 717 class SVGTearOffIDLTypeInfo(IDLTypeInfo):
700 def __init__(self, idl_type, native_type=''): 718 def __init__(self, idl_type, native_type=''):
701 super(SVGTearOffIDLTypeInfo, self).__init__(idl_type, 719 super(SVGTearOffIDLTypeInfo, self).__init__(idl_type,
702 native_type=native_type) 720 native_type=native_type)
703 721
704 def native_type(self): 722 def native_type(self):
705 if self._native_type: 723 if self._native_type:
706 return self._native_type 724 return self._native_type
707 tear_off_type = 'SVGPropertyTearOff' 725 tear_off_type = 'SVGPropertyTearOff'
708 if self._idl_type.endswith('List'): 726 if self._idl_type.endswith('List'):
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
831 849
832 match = re.match(r'sequence<(\w+)>$', idl_type_name) 850 match = re.match(r'sequence<(\w+)>$', idl_type_name)
833 if match: 851 if match:
834 return SequenceIDLTypeInfo(idl_type_name, GetIDLTypeInfo(match.group(1))) 852 return SequenceIDLTypeInfo(idl_type_name, GetIDLTypeInfo(match.group(1)))
835 853
836 match = re.match(r'(\w+)\[\]$', idl_type_name) 854 match = re.match(r'(\w+)\[\]$', idl_type_name)
837 if match: 855 if match:
838 return SequenceIDLTypeInfo(idl_type_name, GetIDLTypeInfo(match.group(1))) 856 return SequenceIDLTypeInfo(idl_type_name, GetIDLTypeInfo(match.group(1)))
839 857
840 return IDLTypeInfo(idl_type_name) 858 return IDLTypeInfo(idl_type_name)
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698