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

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

Issue 11040059: Add interface_name and implementation_name to IDLTypeInfo class and use them instead of dart_type. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Rename ImplementationClassName to ImplementationClassNameForInterfaceName. 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 | « lib/html/dartium/html_dartium.dart ('k') | 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
(...skipping 488 matching lines...) Expand 10 before | Expand all | Expand 10 after
499 else: 499 else:
500 return '\n' 500 return '\n'
501 return ''.join(FormatLine(line) for line in text.split('\n')) 501 return ''.join(FormatLine(line) for line in text.split('\n'))
502 502
503 # Given a sorted sequence of type identifiers, return an appropriate type 503 # Given a sorted sequence of type identifiers, return an appropriate type
504 # name 504 # name
505 def TypeName(type_ids, interface): 505 def TypeName(type_ids, interface):
506 # Dynamically type this field for now. 506 # Dynamically type this field for now.
507 return 'Dynamic' 507 return 'Dynamic'
508 508
509 def ImplementationClassName(interface_name): 509 def ImplementationClassNameForInterfaceName(interface_name):
510 return '_%sImpl' % interface_name 510 return '_%sImpl' % interface_name
511 511
512 # ------------------------------------------------------------------------------ 512 # ------------------------------------------------------------------------------
513 513
514 class Conversion(object): 514 class Conversion(object):
515 """Represents a way of converting between types.""" 515 """Represents a way of converting between types."""
516 def __init__(self, name, input_type, output_type): 516 def __init__(self, name, input_type, output_type):
517 # input_type is the type of the API input (and the argument type of the 517 # input_type is the type of the API input (and the argument type of the
518 # conversion function) 518 # conversion function)
519 # output_type is the type of the API output (and the result type of the 519 # output_type is the type of the API output (and the result type of the
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
608 608
609 def idl_type(self): 609 def idl_type(self):
610 return self._idl_type 610 return self._idl_type
611 611
612 def dart_type(self): 612 def dart_type(self):
613 return self._data.dart_type or self._idl_type 613 return self._data.dart_type or self._idl_type
614 614
615 def narrow_dart_type(self): 615 def narrow_dart_type(self):
616 return self.dart_type() 616 return self.dart_type()
617 617
618 def interface_name(self):
619 raise NotImplementedError()
620
621 def implementation_name(self):
622 raise NotImplementedError()
623
618 def native_type(self): 624 def native_type(self):
619 return self._data.native_type or self._idl_type 625 return self._data.native_type or self._idl_type
620 626
621 def bindings_class(self): 627 def bindings_class(self):
622 return 'Dart%s' % self.idl_type() 628 return 'Dart%s' % self.idl_type()
623 629
624 def vector_to_dart_template_parameter(self): 630 def vector_to_dart_template_parameter(self):
625 return self.bindings_class() 631 return self.bindings_class()
626 632
627 def requires_v8_scope(self): 633 def requires_v8_scope(self):
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
699 def __init__(self, idl_type, data, dart_interface_name): 705 def __init__(self, idl_type, data, dart_interface_name):
700 super(InterfaceIDLTypeInfo, self).__init__(idl_type, data) 706 super(InterfaceIDLTypeInfo, self).__init__(idl_type, data)
701 self._dart_interface_name = dart_interface_name 707 self._dart_interface_name = dart_interface_name
702 708
703 def dart_type(self): 709 def dart_type(self):
704 return self._data.dart_type or self._dart_interface_name 710 return self._data.dart_type or self._dart_interface_name
705 711
706 def narrow_dart_type(self): 712 def narrow_dart_type(self):
707 # TODO(podivilov): introduce ListLikeIDLTypeInfo and remove this hack. 713 # TODO(podivilov): introduce ListLikeIDLTypeInfo and remove this hack.
708 if self._data.suppress_public_interface: 714 if self._data.suppress_public_interface:
709 return ImplementationClassName(self.idl_type()) 715 return ImplementationClassNameForInterfaceName(self.idl_type())
710 # TODO(podivilov): only primitive and collection types should override 716 # TODO(podivilov): only primitive and collection types should override
711 # dart_type. 717 # dart_type.
712 if self._data.dart_type != None: 718 if self._data.dart_type != None:
713 return self.dart_type() 719 return self.dart_type()
714 if IsPureInterface(self.idl_type()): 720 if IsPureInterface(self.idl_type()):
715 return self.idl_type() 721 return self.idl_type()
716 return ImplementationClassName(self._dart_interface_name) 722 return self.implementation_name()
723
724 def interface_name(self):
725 return self._dart_interface_name
726
727 def implementation_name(self):
728 # TODO(podivilov): introduce ListLikeIDLTypeInfo and remove this hack.
729 if self._data.suppress_public_interface:
730 return ImplementationClassNameForInterfaceName(self.idl_type())
731 return ImplementationClassNameForInterfaceName(self._dart_interface_name)
717 732
718 733
719 class CallbackIDLTypeInfo(IDLTypeInfo): 734 class CallbackIDLTypeInfo(IDLTypeInfo):
720 def __init__(self, idl_type, data): 735 def __init__(self, idl_type, data):
721 super(CallbackIDLTypeInfo, self).__init__(idl_type, data) 736 super(CallbackIDLTypeInfo, self).__init__(idl_type, data)
722 737
723 738
724 class SequenceIDLTypeInfo(IDLTypeInfo): 739 class SequenceIDLTypeInfo(IDLTypeInfo):
725 def __init__(self, idl_type, data, item_info): 740 def __init__(self, idl_type, data, item_info):
726 super(SequenceIDLTypeInfo, self).__init__(idl_type, data) 741 super(SequenceIDLTypeInfo, self).__init__(idl_type, data)
727 self._item_info = item_info 742 self._item_info = item_info
728 743
729 def dart_type(self): 744 def dart_type(self):
730 return 'List<%s>' % self._item_info.dart_type() 745 return 'List<%s>' % self._item_info.dart_type()
731 746
747 def interface_name(self):
748 return self.dart_type()
749
750 def implementation_name(self):
751 return self.dart_type()
752
732 def vector_to_dart_template_parameter(self): 753 def vector_to_dart_template_parameter(self):
733 raise Exception('sequences of sequences are not supported yet') 754 raise Exception('sequences of sequences are not supported yet')
734 755
735 def to_native_info(self, idl_node, interface_name): 756 def to_native_info(self, idl_node, interface_name):
736 item_native_type = self._item_info.vector_to_dart_template_parameter() 757 item_native_type = self._item_info.vector_to_dart_template_parameter()
737 return '%s', 'Vector<%s>' % item_native_type, 'DartUtilities', 'toNativeVect or<%s>' % item_native_type 758 return '%s', 'Vector<%s>' % item_native_type, 'DartUtilities', 'toNativeVect or<%s>' % item_native_type
738 759
739 def pass_native_by_ref(self): return True 760 def pass_native_by_ref(self): return True
740 761
741 def to_dart_conversion(self, value, interface_name=None, attributes=None): 762 def to_dart_conversion(self, value, interface_name=None, attributes=None):
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after
1029 if type_data.clazz == 'Interface': 1050 if type_data.clazz == 'Interface':
1030 if self._database.HasInterface(type_name): 1051 if self._database.HasInterface(type_name):
1031 dart_interface_name = self._renamer.RenameInterface( 1052 dart_interface_name = self._renamer.RenameInterface(
1032 self._database.GetInterface(type_name)) 1053 self._database.GetInterface(type_name))
1033 else: 1054 else:
1034 dart_interface_name = type_name 1055 dart_interface_name = type_name
1035 return InterfaceIDLTypeInfo(type_name, type_data, dart_interface_name) 1056 return InterfaceIDLTypeInfo(type_name, type_data, dart_interface_name)
1036 1057
1037 class_name = '%sIDLTypeInfo' % type_data.clazz 1058 class_name = '%sIDLTypeInfo' % type_data.clazz
1038 return globals()[class_name](type_name, type_data) 1059 return globals()[class_name](type_name, type_data)
OLDNEW
« no previous file with comments | « lib/html/dartium/html_dartium.dart ('k') | lib/html/scripts/systemhtml.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698