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 427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
438 else: | 438 else: |
439 return '\n' | 439 return '\n' |
440 return ''.join(FormatLine(line) for line in text.split('\n')) | 440 return ''.join(FormatLine(line) for line in text.split('\n')) |
441 | 441 |
442 # Given a sorted sequence of type identifiers, return an appropriate type | 442 # Given a sorted sequence of type identifiers, return an appropriate type |
443 # name | 443 # name |
444 def TypeName(type_ids, interface): | 444 def TypeName(type_ids, interface): |
445 # Dynamically type this field for now. | 445 # Dynamically type this field for now. |
446 return 'dynamic' | 446 return 'dynamic' |
447 | 447 |
448 def ImplementationClassNameForInterfaceName(interface_name): | |
449 return '_%sImpl' % interface_name | |
450 | |
451 # ------------------------------------------------------------------------------ | 448 # ------------------------------------------------------------------------------ |
452 | 449 |
453 class Conversion(object): | 450 class Conversion(object): |
454 """Represents a way of converting between types.""" | 451 """Represents a way of converting between types.""" |
455 def __init__(self, name, input_type, output_type): | 452 def __init__(self, name, input_type, output_type): |
456 # input_type is the type of the API input (and the argument type of the | 453 # input_type is the type of the API input (and the argument type of the |
457 # conversion function) | 454 # conversion function) |
458 # output_type is the type of the API output (and the result type of the | 455 # output_type is the type of the API output (and the result type of the |
459 # conversion function) | 456 # conversion function) |
460 self.function_name = name | 457 self.function_name = name |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
679 return 'List<Node>' | 676 return 'List<Node>' |
680 if self.list_item_type() and not self.has_generated_interface(): | 677 if self.list_item_type() and not self.has_generated_interface(): |
681 return 'List<%s>' % self._type_registry.TypeInfo(self._data.item_type).dar
t_type() | 678 return 'List<%s>' % self._type_registry.TypeInfo(self._data.item_type).dar
t_type() |
682 return self._data.dart_type or self._dart_interface_name | 679 return self._data.dart_type or self._dart_interface_name |
683 | 680 |
684 def narrow_dart_type(self): | 681 def narrow_dart_type(self): |
685 # TODO(podivilov): why NodeList is special? | 682 # TODO(podivilov): why NodeList is special? |
686 if self.idl_type() == 'NodeList': | 683 if self.idl_type() == 'NodeList': |
687 return 'List<Node>' | 684 return 'List<Node>' |
688 if self.list_item_type(): | 685 if self.list_item_type(): |
689 return ImplementationClassNameForInterfaceName(self.idl_type()) | 686 return self.idl_type() |
690 # TODO(podivilov): only primitive and collection types should override | 687 # TODO(podivilov): only primitive and collection types should override |
691 # dart_type. | 688 # dart_type. |
692 if self._data.dart_type != None: | 689 if self._data.dart_type != None: |
693 return self.dart_type() | 690 return self.dart_type() |
694 if IsPureInterface(self.idl_type()): | 691 if IsPureInterface(self.idl_type()): |
695 return self.idl_type() | 692 return self.idl_type() |
696 return ImplementationClassNameForInterfaceName(self.interface_name()) | 693 return self.interface_name() |
697 | 694 |
698 def interface_name(self): | 695 def interface_name(self): |
699 if self.list_item_type() and not self.has_generated_interface(): | 696 if self.list_item_type() and not self.has_generated_interface(): |
700 return self.dart_type() | 697 return self.dart_type() |
701 return self._dart_interface_name | 698 return self._dart_interface_name |
702 | 699 |
703 def implementation_name(self): | 700 def implementation_name(self): |
704 if self.list_item_type(): | 701 if self.list_item_type(): |
705 return ImplementationClassNameForInterfaceName(self.idl_type()) | 702 implementation_name = self.idl_type() |
706 implementation_name = ImplementationClassNameForInterfaceName( | 703 else: |
707 self.interface_name()) | 704 implementation_name = self.interface_name() |
708 if self.merged_into(): | 705 if self.merged_into(): |
709 implementation_name = '%s_Merged' % implementation_name | 706 implementation_name = '%s_Merged' % implementation_name |
| 707 |
| 708 if not self.has_generated_interface(): |
| 709 implementation_name = '_%s' % implementation_name |
| 710 |
710 return implementation_name | 711 return implementation_name |
711 | 712 |
712 def has_generated_interface(self): | 713 def has_generated_interface(self): |
713 return not self._data.suppress_interface | 714 return not self._data.suppress_interface |
714 | 715 |
715 def list_item_type(self): | 716 def list_item_type(self): |
716 return self._data.item_type | 717 return self._data.item_type |
717 | 718 |
718 def is_typed_array(self): | 719 def is_typed_array(self): |
719 return self._data.is_typed_array | 720 return self._data.is_typed_array |
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1091 else: | 1092 else: |
1092 dart_interface_name = type_name | 1093 dart_interface_name = type_name |
1093 return InterfaceIDLTypeInfo(type_name, type_data, dart_interface_name, | 1094 return InterfaceIDLTypeInfo(type_name, type_data, dart_interface_name, |
1094 self) | 1095 self) |
1095 | 1096 |
1096 if type_data.clazz == 'SVGTearOff': | 1097 if type_data.clazz == 'SVGTearOff': |
1097 return SVGTearOffIDLTypeInfo(type_name, type_data, self) | 1098 return SVGTearOffIDLTypeInfo(type_name, type_data, self) |
1098 | 1099 |
1099 class_name = '%sIDLTypeInfo' % type_data.clazz | 1100 class_name = '%sIDLTypeInfo' % type_data.clazz |
1100 return globals()[class_name](type_name, type_data) | 1101 return globals()[class_name](type_name, type_data) |
OLD | NEW |