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 json | 10 import json |
(...skipping 1118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1129 if 'ImplementedAs' in interface.ext_attrs: | 1129 if 'ImplementedAs' in interface.ext_attrs: |
1130 return interface.ext_attrs['ImplementedAs'] | 1130 return interface.ext_attrs['ImplementedAs'] |
1131 return super(InterfaceIDLTypeInfo, self).native_type() | 1131 return super(InterfaceIDLTypeInfo, self).native_type() |
1132 | 1132 |
1133 def has_generated_interface(self): | 1133 def has_generated_interface(self): |
1134 return not self._data.suppress_interface | 1134 return not self._data.suppress_interface |
1135 | 1135 |
1136 def list_item_type(self): | 1136 def list_item_type(self): |
1137 return self._data.item_type | 1137 return self._data.item_type |
1138 | 1138 |
| 1139 def list_item_type_nullable(self): |
| 1140 return self._data.item_type_nullable |
| 1141 |
1139 def merged_interface(self): | 1142 def merged_interface(self): |
1140 # All constants, attributes, and operations of merged interface should be | 1143 # All constants, attributes, and operations of merged interface should be |
1141 # added to this interface. Merged idl interface does not have corresponding | 1144 # added to this interface. Merged idl interface does not have corresponding |
1142 # Dart generated interface, and all references to merged idl interface | 1145 # Dart generated interface, and all references to merged idl interface |
1143 # (e.g. parameter types, return types, parent interfaces) should be replaced | 1146 # (e.g. parameter types, return types, parent interfaces) should be replaced |
1144 # with this interface. There are two important restrictions: | 1147 # with this interface. There are two important restrictions: |
1145 # 1) Merged and target interfaces shouldn't have common members, otherwise | 1148 # 1) Merged and target interfaces shouldn't have common members, otherwise |
1146 # there would be duplicated declarations in generated Dart code. | 1149 # there would be duplicated declarations in generated Dart code. |
1147 # 2) Merged interface should be direct child of target interface, so the | 1150 # 2) Merged interface should be direct child of target interface, so the |
1148 # children of merged interface are not affected by the merge. | 1151 # children of merged interface are not affected by the merge. |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1383 return '%s.get()', 'RefPtr<%s>' % self._idl_type, 'DartUtilities', 'dartTo%s
' % self._idl_type | 1386 return '%s.get()', 'RefPtr<%s>' % self._idl_type, 'DartUtilities', 'dartTo%s
' % self._idl_type |
1384 | 1387 |
1385 | 1388 |
1386 class TypeData(object): | 1389 class TypeData(object): |
1387 def __init__(self, clazz, dart_type=None, native_type=None, | 1390 def __init__(self, clazz, dart_type=None, native_type=None, |
1388 merged_interface=None, merged_into=None, | 1391 merged_interface=None, merged_into=None, |
1389 custom_to_dart=False, custom_to_native=False, | 1392 custom_to_dart=False, custom_to_native=False, |
1390 conversion_includes=None, | 1393 conversion_includes=None, |
1391 webcore_getter_name='getAttribute', | 1394 webcore_getter_name='getAttribute', |
1392 webcore_setter_name='setAttribute', | 1395 webcore_setter_name='setAttribute', |
1393 item_type=None, suppress_interface=False): | 1396 item_type=None, item_type_nullable=False, |
| 1397 suppress_interface=False): |
1394 self.clazz = clazz | 1398 self.clazz = clazz |
1395 self.dart_type = dart_type | 1399 self.dart_type = dart_type |
1396 self.native_type = native_type | 1400 self.native_type = native_type |
1397 self.merged_interface = merged_interface | 1401 self.merged_interface = merged_interface |
1398 self.merged_into = merged_into | 1402 self.merged_into = merged_into |
1399 self.custom_to_dart = custom_to_dart | 1403 self.custom_to_dart = custom_to_dart |
1400 self.custom_to_native = custom_to_native | 1404 self.custom_to_native = custom_to_native |
1401 self.conversion_includes = conversion_includes | 1405 self.conversion_includes = conversion_includes |
1402 self.webcore_getter_name = webcore_getter_name | 1406 self.webcore_getter_name = webcore_getter_name |
1403 self.webcore_setter_name = webcore_setter_name | 1407 self.webcore_setter_name = webcore_setter_name |
1404 self.item_type = item_type | 1408 self.item_type = item_type |
| 1409 self.item_type_nullable = item_type_nullable |
1405 self.suppress_interface = suppress_interface | 1410 self.suppress_interface = suppress_interface |
1406 | 1411 |
1407 | 1412 |
1408 def TypedListTypeData(item_type): | 1413 def TypedListTypeData(item_type): |
1409 return TypeData(clazz='TypedList', item_type=item_type) | 1414 return TypeData(clazz='TypedList', item_type=item_type) |
1410 | 1415 |
1411 | 1416 |
1412 _idl_type_registry = monitored.Dict('generator._idl_type_registry', { | 1417 _idl_type_registry = monitored.Dict('generator._idl_type_registry', { |
1413 'boolean': TypeData(clazz='Primitive', dart_type='bool', native_type='bool', | 1418 'boolean': TypeData(clazz='Primitive', dart_type='bool', native_type='bool', |
1414 webcore_getter_name='hasAttribute', | 1419 webcore_getter_name='hasAttribute', |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1481 'CSSValueList': TypeData(clazz='Interface', | 1486 'CSSValueList': TypeData(clazz='Interface', |
1482 item_type='CSSValue', suppress_interface=True), | 1487 item_type='CSSValue', suppress_interface=True), |
1483 'MimeTypeArray': TypeData(clazz='Interface', item_type='MimeType'), | 1488 'MimeTypeArray': TypeData(clazz='Interface', item_type='MimeType'), |
1484 'PluginArray': TypeData(clazz='Interface', item_type='Plugin'), | 1489 'PluginArray': TypeData(clazz='Interface', item_type='Plugin'), |
1485 'DOMStringList': TypeData(clazz='Interface', item_type='DOMString', | 1490 'DOMStringList': TypeData(clazz='Interface', item_type='DOMString', |
1486 dart_type='List<String>', custom_to_native=True), | 1491 dart_type='List<String>', custom_to_native=True), |
1487 'FileList': TypeData(clazz='Interface', item_type='File', | 1492 'FileList': TypeData(clazz='Interface', item_type='File', |
1488 dart_type='List<File>'), | 1493 dart_type='List<File>'), |
1489 'Future': TypeData(clazz='Interface', dart_type='Future'), | 1494 'Future': TypeData(clazz='Interface', dart_type='Future'), |
1490 'GamepadList': TypeData(clazz='Interface', item_type='Gamepad', | 1495 'GamepadList': TypeData(clazz='Interface', item_type='Gamepad', |
1491 suppress_interface=True), | 1496 item_type_nullable=True, suppress_interface=True), |
1492 'GLenum': TypeData(clazz='Primitive', dart_type='int', | 1497 'GLenum': TypeData(clazz='Primitive', dart_type='int', |
1493 native_type='unsigned'), | 1498 native_type='unsigned'), |
1494 'GLboolean': TypeData(clazz='Primitive', dart_type='bool', | 1499 'GLboolean': TypeData(clazz='Primitive', dart_type='bool', |
1495 native_type='bool'), | 1500 native_type='bool'), |
1496 'GLbitfield': TypeData(clazz='Primitive', dart_type='int', | 1501 'GLbitfield': TypeData(clazz='Primitive', dart_type='int', |
1497 native_type='unsigned'), | 1502 native_type='unsigned'), |
1498 'GLshort': TypeData(clazz='Primitive', dart_type='int', native_type='short')
, | 1503 'GLshort': TypeData(clazz='Primitive', dart_type='int', native_type='short')
, |
1499 'GLint': TypeData(clazz='Primitive', dart_type='int', | 1504 'GLint': TypeData(clazz='Primitive', dart_type='int', |
1500 native_type='long'), | 1505 native_type='long'), |
1501 'GLsizei': TypeData(clazz='Primitive', dart_type='int', | 1506 'GLsizei': TypeData(clazz='Primitive', dart_type='int', |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1697 return_type == 'Rectangle') | 1702 return_type == 'Rectangle') |
1698 | 1703 |
1699 def wrap_return_type_blink(return_type, type_name, type_registry): | 1704 def wrap_return_type_blink(return_type, type_name, type_registry): |
1700 """Returns True if we should wrap the returned value. This checks | 1705 """Returns True if we should wrap the returned value. This checks |
1701 a number of different variations, calling the more basic functions | 1706 a number of different variations, calling the more basic functions |
1702 above.""" | 1707 above.""" |
1703 return (wrap_unwrap_type_blink(return_type, type_registry) or | 1708 return (wrap_unwrap_type_blink(return_type, type_registry) or |
1704 wrap_unwrap_type_blink(type_name, type_registry) or | 1709 wrap_unwrap_type_blink(type_name, type_registry) or |
1705 wrap_type_blink(return_type, type_registry) or | 1710 wrap_type_blink(return_type, type_registry) or |
1706 wrap_unwrap_list_blink(return_type, type_registry)) | 1711 wrap_unwrap_list_blink(return_type, type_registry)) |
OLD | NEW |