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

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

Issue 11027033: Move Dart type narrowing to TypeRegistry. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 2 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 | lib/html/scripts/systemhtml.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 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
11 from htmlrenamer import html_interface_renames 11 from htmlrenamer import html_interface_renames
12 12
13 _pure_interfaces = set([ 13 _pure_interfaces = set([
14 # TODO(sra): DOMStringMap should be a class implementing Map<String,String>. 14 # TODO(sra): DOMStringMap should be a class implementing Map<String,String>.
15 'DOMStringMap', 15 'DOMStringMap',
16 'ElementTimeControl', 16 'ElementTimeControl',
17 'ElementTraversal', 17 'ElementTraversal',
18 'EventListener',
18 'MediaQueryListListener', 19 'MediaQueryListListener',
19 'NodeSelector', 20 'NodeSelector',
20 'SVGExternalResourcesRequired', 21 'SVGExternalResourcesRequired',
21 'SVGFilterPrimitiveStandardAttributes', 22 'SVGFilterPrimitiveStandardAttributes',
22 'SVGFitToViewBox', 23 'SVGFitToViewBox',
23 'SVGLangSpace', 24 'SVGLangSpace',
24 'SVGLocatable', 25 'SVGLocatable',
25 'SVGStylable', 26 'SVGStylable',
26 'SVGTests', 27 'SVGTests',
27 'SVGTransformable', 28 'SVGTransformable',
(...skipping 466 matching lines...) Expand 10 before | Expand all | Expand 10 after
494 else: 495 else:
495 return '\n' 496 return '\n'
496 return ''.join(FormatLine(line) for line in text.split('\n')) 497 return ''.join(FormatLine(line) for line in text.split('\n'))
497 498
498 # Given a sorted sequence of type identifiers, return an appropriate type 499 # Given a sorted sequence of type identifiers, return an appropriate type
499 # name 500 # name
500 def TypeName(type_ids, interface): 501 def TypeName(type_ids, interface):
501 # Dynamically type this field for now. 502 # Dynamically type this field for now.
502 return 'Dynamic' 503 return 'Dynamic'
503 504
505 def ImplementationClassName(interface_name):
506 return '_%sImpl' % interface_name
507
504 # ------------------------------------------------------------------------------ 508 # ------------------------------------------------------------------------------
505 509
506 class Conversion(object): 510 class Conversion(object):
507 """Represents a way of converting between types.""" 511 """Represents a way of converting between types."""
508 def __init__(self, name, input_type, output_type): 512 def __init__(self, name, input_type, output_type):
509 # input_type is the type of the API input (and the argument type of the 513 # input_type is the type of the API input (and the argument type of the
510 # conversion function) 514 # conversion function)
511 # output_type is the type of the API output (and the result type of the 515 # output_type is the type of the API output (and the result type of the
512 # conversion function) 516 # conversion function)
513 self.function_name = name 517 self.function_name = name
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
597 def __init__(self, idl_type, data): 601 def __init__(self, idl_type, data):
598 self._idl_type = idl_type 602 self._idl_type = idl_type
599 self._data = data 603 self._data = data
600 604
601 def idl_type(self): 605 def idl_type(self):
602 return self._idl_type 606 return self._idl_type
603 607
604 def dart_type(self): 608 def dart_type(self):
605 return self._data.dart_type or self._idl_type 609 return self._data.dart_type or self._idl_type
606 610
611 def narrow_dart_type(self):
612 return self.dart_type()
613
607 def native_type(self): 614 def native_type(self):
608 return self._data.native_type or self._idl_type 615 return self._data.native_type or self._idl_type
609 616
610 def bindings_class(self): 617 def bindings_class(self):
611 return 'Dart%s' % self.idl_type() 618 return 'Dart%s' % self.idl_type()
612 619
613 def vector_to_dart_template_parameter(self): 620 def vector_to_dart_template_parameter(self):
614 return self.bindings_class() 621 return self.bindings_class()
615 622
616 def requires_v8_scope(self): 623 def requires_v8_scope(self):
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
685 692
686 693
687 class InterfaceIDLTypeInfo(IDLTypeInfo): 694 class InterfaceIDLTypeInfo(IDLTypeInfo):
688 def __init__(self, idl_type, data, dart_interface_name): 695 def __init__(self, idl_type, data, dart_interface_name):
689 super(InterfaceIDLTypeInfo, self).__init__(idl_type, data) 696 super(InterfaceIDLTypeInfo, self).__init__(idl_type, data)
690 self._dart_interface_name = dart_interface_name 697 self._dart_interface_name = dart_interface_name
691 698
692 def dart_type(self): 699 def dart_type(self):
693 return self._data.dart_type or self._dart_interface_name 700 return self._data.dart_type or self._dart_interface_name
694 701
702 def narrow_dart_type(self):
703 # TODO(podivilov): introduce ListLikeIDLTypeInfo and remove this hack.
704 if self._data.suppress_public_interface:
705 return ImplementationClassName(self.idl_type())
706 # TODO(podivilov): only primitive and collection types should override
707 # dart_type.
708 if self._data.dart_type != None:
709 return self.dart_type()
710 if IsPureInterface(self.idl_type()):
711 return self.idl_type()
712 return ImplementationClassName(self._dart_interface_name)
713
714
715 class CallbackIDLTypeInfo(IDLTypeInfo):
716 def __init__(self, idl_type, data):
717 super(CallbackIDLTypeInfo, self).__init__(idl_type, data)
718
719 def narrow_dart_type(self):
Anton Muhin 2012/10/04 17:30:07 why this override?
podivilov1 2012/10/04 17:46:54 Done.
720 return self.dart_type()
721
695 722
696 class SequenceIDLTypeInfo(IDLTypeInfo): 723 class SequenceIDLTypeInfo(IDLTypeInfo):
697 def __init__(self, idl_type, data, item_info): 724 def __init__(self, idl_type, data, item_info):
698 super(SequenceIDLTypeInfo, self).__init__(idl_type, data) 725 super(SequenceIDLTypeInfo, self).__init__(idl_type, data)
699 self._item_info = item_info 726 self._item_info = item_info
700 727
701 def dart_type(self): 728 def dart_type(self):
702 return 'List<%s>' % self._item_info.dart_type() 729 return 'List<%s>' % self._item_info.dart_type()
703 730
704 def vector_to_dart_template_parameter(self): 731 def vector_to_dart_template_parameter(self):
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
764 def webcore_getter_name(self): 791 def webcore_getter_name(self):
765 return self._data.webcore_getter_name 792 return self._data.webcore_getter_name
766 793
767 def webcore_setter_name(self): 794 def webcore_setter_name(self):
768 return self._data.webcore_setter_name 795 return self._data.webcore_setter_name
769 796
770 def _capitalized_native_type(self): 797 def _capitalized_native_type(self):
771 return re.sub(r'(^| )([a-z])', lambda x: x.group(2).upper(), self.native_typ e()) 798 return re.sub(r'(^| )([a-z])', lambda x: x.group(2).upper(), self.native_typ e())
772 799
773 800
774 class SVGTearOffIDLTypeInfo(IDLTypeInfo): 801 class SVGTearOffIDLTypeInfo(InterfaceIDLTypeInfo):
775 def __init__(self, idl_type, data): 802 def __init__(self, idl_type, data):
776 super(SVGTearOffIDLTypeInfo, self).__init__(idl_type, data) 803 super(SVGTearOffIDLTypeInfo, self).__init__(idl_type, data, idl_type)
777 804
778 def native_type(self): 805 def native_type(self):
779 if self._data.native_type: 806 if self._data.native_type:
780 return self._data.native_type 807 return self._data.native_type
781 tear_off_type = 'SVGPropertyTearOff' 808 tear_off_type = 'SVGPropertyTearOff'
782 if self._idl_type.endswith('List'): 809 if self._idl_type.endswith('List'):
783 tear_off_type = 'SVGListPropertyTearOff' 810 tear_off_type = 'SVGListPropertyTearOff'
784 return '%s<%s>' % (tear_off_type, self._idl_type) 811 return '%s<%s>' % (tear_off_type, self._idl_type)
785 812
786 def receiver(self): 813 def receiver(self):
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
981 def _TypeInfo(self, type_name): 1008 def _TypeInfo(self, type_name):
982 match = re.match(r'(?:sequence<(\w+)>|(\w+)\[\])$', type_name) 1009 match = re.match(r'(?:sequence<(\w+)>|(\w+)\[\])$', type_name)
983 if match: 1010 if match:
984 if type_name == 'DOMString[]': 1011 if type_name == 'DOMString[]':
985 return DOMStringArrayTypeInfo(TypeData('Sequence'), self.TypeInfo('DOMSt ring')) 1012 return DOMStringArrayTypeInfo(TypeData('Sequence'), self.TypeInfo('DOMSt ring'))
986 item_info = self.TypeInfo(match.group(1) or match.group(2)) 1013 item_info = self.TypeInfo(match.group(1) or match.group(2))
987 return SequenceIDLTypeInfo(type_name, TypeData('Sequence'), item_info) 1014 return SequenceIDLTypeInfo(type_name, TypeData('Sequence'), item_info)
988 1015
989 if not type_name in _idl_type_registry: 1016 if not type_name in _idl_type_registry:
990 interface = self._database.GetInterface(type_name) 1017 interface = self._database.GetInterface(type_name)
1018 if 'Callback' in interface.ext_attrs:
1019 return CallbackIDLTypeInfo(type_name, TypeData('Callback'))
991 return InterfaceIDLTypeInfo( 1020 return InterfaceIDLTypeInfo(
992 type_name, 1021 type_name,
993 TypeData('Interface'), 1022 TypeData('Interface'),
994 self._renamer.RenameInterface(interface)) 1023 self._renamer.RenameInterface(interface))
995 1024
996 type_data = _idl_type_registry.get(type_name) 1025 type_data = _idl_type_registry.get(type_name)
997 if type_data.clazz == 'Interface': 1026 if type_data.clazz == 'Interface':
998 if self._database.HasInterface(type_name): 1027 if self._database.HasInterface(type_name):
999 dart_interface_name = self._renamer.RenameInterface( 1028 dart_interface_name = self._renamer.RenameInterface(
1000 self._database.GetInterface(type_name)) 1029 self._database.GetInterface(type_name))
1001 else: 1030 else:
1002 dart_interface_name = type_name 1031 dart_interface_name = type_name
1003 return InterfaceIDLTypeInfo(type_name, type_data, dart_interface_name) 1032 return InterfaceIDLTypeInfo(type_name, type_data, dart_interface_name)
1004 1033
1005 class_name = '%sIDLTypeInfo' % type_data.clazz 1034 class_name = '%sIDLTypeInfo' % type_data.clazz
1006 return globals()[class_name](type_name, type_data) 1035 return globals()[class_name](type_name, type_data)
OLDNEW
« no previous file with comments | « no previous file | lib/html/scripts/systemhtml.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698