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

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

Issue 10911307: Support sequence<T> as return type. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 3 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 533 matching lines...) Expand 10 before | Expand all | Expand 10 after
544 544
545 def idl_type(self): 545 def idl_type(self):
546 return self._idl_type 546 return self._idl_type
547 547
548 def dart_type(self): 548 def dart_type(self):
549 return self._data.dart_type or self._idl_type 549 return self._data.dart_type or self._idl_type
550 550
551 def native_type(self): 551 def native_type(self):
552 return self._data.native_type or self._idl_type 552 return self._data.native_type or self._idl_type
553 553
554 def bindings_class(self):
555 return 'Dart%s' % self.idl_type()
556
557 def vector_to_dart_template_parameter(self):
558 return self.bindings_class()
559
554 def requires_v8_scope(self): 560 def requires_v8_scope(self):
555 return self._data.requires_v8_scope 561 return self._data.requires_v8_scope
556 562
557 def to_native_info(self, idl_node, interface_name): 563 def to_native_info(self, idl_node, interface_name):
558 cls = 'Dart%s' % self.idl_type() 564 cls = self.bindings_class()
559 565
560 if 'Callback' in idl_node.ext_attrs: 566 if 'Callback' in idl_node.ext_attrs:
561 return '%s', 'RefPtr<%s>' % self.native_type(), cls, 'create' 567 return '%s', 'RefPtr<%s>' % self.native_type(), cls, 'create'
562 568
563 if self.custom_to_native(): 569 if self.custom_to_native():
564 type = 'RefPtr<%s>' % self.native_type() 570 type = 'RefPtr<%s>' % self.native_type()
565 argument_expression_template = '%s.get()' 571 argument_expression_template = '%s.get()'
566 else: 572 else:
567 type = '%s*' % self.native_type() 573 type = '%s*' % self.native_type()
568 if isinstance(self, SVGTearOffIDLTypeInfo) and not interface_name.endswith ('List'): 574 if isinstance(self, SVGTearOffIDLTypeInfo) and not interface_name.endswith ('List'):
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
628 634
629 635
630 class SequenceIDLTypeInfo(IDLTypeInfo): 636 class SequenceIDLTypeInfo(IDLTypeInfo):
631 def __init__(self, idl_type, data, item_info): 637 def __init__(self, idl_type, data, item_info):
632 super(SequenceIDLTypeInfo, self).__init__(idl_type, data) 638 super(SequenceIDLTypeInfo, self).__init__(idl_type, data)
633 self._item_info = item_info 639 self._item_info = item_info
634 640
635 def dart_type(self): 641 def dart_type(self):
636 return 'List<%s>' % self._item_info.dart_type() 642 return 'List<%s>' % self._item_info.dart_type()
637 643
644 def vector_to_dart_template_parameter(self):
645 raise Exception('sequences of sequences are not supported yet')
646
638 def to_native_info(self, idl_node, interface_name): 647 def to_native_info(self, idl_node, interface_name):
639 item_info = self._item_info 648 item_native_type = self._item_info.vector_to_dart_template_parameter()
640 item_native_type = item_info.native_type()
641 # Ugly hack. Usually IDLs floats are treated as C++ doubles, however
642 # sequence<float> should map to Vector<float>
643 if item_native_type == 'double' and item_info.idl_type() == 'float':
644 item_native_type = 'float'
645
646 return '%s', 'Vector<%s>' % item_native_type, 'DartUtilities', 'toNativeVect or<%s>' % item_native_type 649 return '%s', 'Vector<%s>' % item_native_type, 'DartUtilities', 'toNativeVect or<%s>' % item_native_type
647 650
648 def pass_native_by_ref(self): return True 651 def pass_native_by_ref(self): return True
649 652
650 def to_dart_conversion(self, value, interface_name=None, attributes=None): 653 def to_dart_conversion(self, value, interface_name=None, attributes=None):
651 return 'DartDOMWrapper::vectorToDart<Dart%s>(%s)' % (self._item_info.native_ type(), value) 654 return 'DartDOMWrapper::vectorToDart<%s>(%s)' % (self._item_info.vector_to_d art_template_parameter(), value)
652 655
653 def conversion_includes(self): 656 def conversion_includes(self):
654 return self._item_info.conversion_includes() 657 return self._item_info.conversion_includes()
655 658
656 659
657 class DOMStringArrayTypeInfo(SequenceIDLTypeInfo): 660 class DOMStringArrayTypeInfo(SequenceIDLTypeInfo):
658 def __init__(self, data, item_info): 661 def __init__(self, data, item_info):
659 super(DOMStringArrayTypeInfo, self).__init__('DOMString[]', data, item_info) 662 super(DOMStringArrayTypeInfo, self).__init__('DOMString[]', data, item_info)
660 663
661 def to_native_info(self, idl_node, interface_name): 664 def to_native_info(self, idl_node, interface_name):
662 return '%s', 'RefPtr<DOMStringList>', 'DartDOMStringList', 'toNative' 665 return '%s', 'RefPtr<DOMStringList>', 'DartDOMStringList', 'toNative'
663 666
664 def pass_native_by_ref(self): return False 667 def pass_native_by_ref(self): return False
665 668
666 669
667 class PrimitiveIDLTypeInfo(IDLTypeInfo): 670 class PrimitiveIDLTypeInfo(IDLTypeInfo):
668 def __init__(self, idl_type, data): 671 def __init__(self, idl_type, data):
669 super(PrimitiveIDLTypeInfo, self).__init__(idl_type, data) 672 super(PrimitiveIDLTypeInfo, self).__init__(idl_type, data)
670 673
674 def vector_to_dart_template_parameter(self):
675 # Ugly hack. Usually IDLs floats are treated as C++ doubles, however
676 # sequence<float> should map to Vector<float>
677 if self.idl_type() == 'float': return 'float'
678 return self.native_type()
679
671 def to_native_info(self, idl_node, interface_name): 680 def to_native_info(self, idl_node, interface_name):
672 type = self.native_type() 681 type = self.native_type()
673 if type == 'SerializedScriptValue': 682 if type == 'SerializedScriptValue':
674 type = 'RefPtr<%s>' % type 683 type = 'RefPtr<%s>' % type
675 if type == 'String': 684 if type == 'String':
676 type = 'DartStringAdapter' 685 type = 'DartStringAdapter'
677 return '%s', type, 'DartUtilities', 'dartTo%s' % self._capitalized_native_ty pe() 686 return '%s', type, 'DartUtilities', 'dartTo%s' % self._capitalized_native_ty pe()
678 687
679 def parameter_type(self): 688 def parameter_type(self):
680 if self.native_type() == 'String': 689 if self.native_type() == 'String':
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
877 if match: 886 if match:
878 if type_name == 'DOMString[]': 887 if type_name == 'DOMString[]':
879 return DOMStringArrayTypeInfo(TypeData('Sequence'), self.TypeInfo('DOMSt ring')) 888 return DOMStringArrayTypeInfo(TypeData('Sequence'), self.TypeInfo('DOMSt ring'))
880 item_info = self.TypeInfo(match.group(1) or match.group(2)) 889 item_info = self.TypeInfo(match.group(1) or match.group(2))
881 return SequenceIDLTypeInfo(type_name, TypeData('Sequence'), item_info) 890 return SequenceIDLTypeInfo(type_name, TypeData('Sequence'), item_info)
882 if not type_name in _idl_type_registry: 891 if not type_name in _idl_type_registry:
883 return InterfaceIDLTypeInfo(type_name, TypeData('Interface')) 892 return InterfaceIDLTypeInfo(type_name, TypeData('Interface'))
884 type_data = _idl_type_registry.get(type_name) 893 type_data = _idl_type_registry.get(type_name)
885 class_name = '%sIDLTypeInfo' % type_data.clazz 894 class_name = '%sIDLTypeInfo' % type_data.clazz
886 return globals()[class_name](type_name, type_data) 895 return globals()[class_name](type_name, type_data)
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