| 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 1449 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1460 'DOMObject': TypeData(clazz='Primitive', dart_type='Object', native_type='Sc
riptValue'), | 1460 'DOMObject': TypeData(clazz='Primitive', dart_type='Object', native_type='Sc
riptValue'), |
| 1461 'DOMString': TypeData(clazz='Primitive', dart_type='String', native_type='St
ring'), | 1461 'DOMString': TypeData(clazz='Primitive', dart_type='String', native_type='St
ring'), |
| 1462 # TODO(vsm): This won't actually work until we convert the Map to | 1462 # TODO(vsm): This won't actually work until we convert the Map to |
| 1463 # a native JS Map for JS DOM. | 1463 # a native JS Map for JS DOM. |
| 1464 'Dictionary': TypeData(clazz='Primitive', dart_type='Map'), | 1464 'Dictionary': TypeData(clazz='Primitive', dart_type='Map'), |
| 1465 # TODO(terry): It's a dictionary but a very complex dictionary is multiple l
ists. | 1465 # TODO(terry): It's a dictionary but a very complex dictionary is multiple l
ists. |
| 1466 # Need to investigate a 1-off solution probably. | 1466 # Need to investigate a 1-off solution probably. |
| 1467 'MediaKeySystemConfiguration': TypeData(clazz='Primitive', dart_type='Map'), | 1467 'MediaKeySystemConfiguration': TypeData(clazz='Primitive', dart_type='Map'), |
| 1468 'DOMTimeStamp': TypeData(clazz='Primitive', dart_type='int', native_type='un
signed long long'), | 1468 'DOMTimeStamp': TypeData(clazz='Primitive', dart_type='int', native_type='un
signed long long'), |
| 1469 'object': TypeData(clazz='Primitive', dart_type='Object', native_type='Scrip
tValue'), | 1469 'object': TypeData(clazz='Primitive', dart_type='Object', native_type='Scrip
tValue'), |
| 1470 'ObjectArray': TypeData(clazz='Primitive', dart_type='List'), | |
| 1471 'PositionOptions': TypeData(clazz='Primitive', dart_type='Object'), | 1470 'PositionOptions': TypeData(clazz='Primitive', dart_type='Object'), |
| 1472 # TODO(sra): Come up with some meaningful name so that where this appears in | 1471 # TODO(sra): Come up with some meaningful name so that where this appears in |
| 1473 # the documentation, the user is made aware that only a limited subset of | 1472 # the documentation, the user is made aware that only a limited subset of |
| 1474 # serializable types are actually permitted. | 1473 # serializable types are actually permitted. |
| 1475 'SerializedScriptValue': TypeData(clazz='Primitive', dart_type='dynamic'), | 1474 'SerializedScriptValue': TypeData(clazz='Primitive', dart_type='dynamic'), |
| 1476 'sequence': TypeData(clazz='Primitive', dart_type='List'), | 1475 'sequence': TypeData(clazz='Primitive', dart_type='List'), |
| 1476 'sequence<any>': TypeData(clazz='Primitive', dart_type='List'), |
| 1477 'void': TypeData(clazz='Primitive', dart_type='void'), | 1477 'void': TypeData(clazz='Primitive', dart_type='void'), |
| 1478 | 1478 |
| 1479 'CSSRule': TypeData(clazz='Interface', conversion_includes=['CSSImportRule']
), | 1479 'CSSRule': TypeData(clazz='Interface', conversion_includes=['CSSImportRule']
), |
| 1480 'DOMStringMap': TypeData(clazz='Interface', dart_type='Map<String, String>')
, | 1480 'DOMStringMap': TypeData(clazz='Interface', dart_type='Map<String, String>')
, |
| 1481 'Window': TypeData(clazz='Interface', custom_to_dart=True), | 1481 'Window': TypeData(clazz='Interface', custom_to_dart=True), |
| 1482 'Element': TypeData(clazz='Interface', merged_interface='HTMLElement', | 1482 'Element': TypeData(clazz='Interface', merged_interface='HTMLElement', |
| 1483 custom_to_dart=True), | 1483 custom_to_dart=True), |
| 1484 'EventListener': TypeData(clazz='Interface', custom_to_native=True), | 1484 'EventListener': TypeData(clazz='Interface', custom_to_native=True), |
| 1485 'EventHandler': TypeData(clazz='Interface', custom_to_native=True), | 1485 'EventHandler': TypeData(clazz='Interface', custom_to_native=True), |
| 1486 'EventTarget': TypeData(clazz='Interface', custom_to_native=True), | 1486 'EventTarget': TypeData(clazz='Interface', custom_to_native=True), |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1603 def TypeInfo(self, type_name): | 1603 def TypeInfo(self, type_name): |
| 1604 if not type_name in self._cache: | 1604 if not type_name in self._cache: |
| 1605 self._cache[type_name] = self._TypeInfo(type_name) | 1605 self._cache[type_name] = self._TypeInfo(type_name) |
| 1606 return self._cache[type_name] | 1606 return self._cache[type_name] |
| 1607 | 1607 |
| 1608 def DartType(self, type_name): | 1608 def DartType(self, type_name): |
| 1609 return self.TypeInfo(type_name).dart_type() | 1609 return self.TypeInfo(type_name).dart_type() |
| 1610 | 1610 |
| 1611 def _TypeInfo(self, type_name): | 1611 def _TypeInfo(self, type_name): |
| 1612 match = re.match(r'(?:sequence<([\w ]+)>|(\w+)\[\])$', type_name) | 1612 match = re.match(r'(?:sequence<([\w ]+)>|(\w+)\[\])$', type_name) |
| 1613 if match: | 1613 # sequence<any> should not be List<Object> |
| 1614 if match and match.group(1) != 'any': |
| 1614 type_data = TypeData('Sequence') | 1615 type_data = TypeData('Sequence') |
| 1615 if self.HasTypeDef(match.group(1) or match.group(2)): | 1616 if self.HasTypeDef(match.group(1) or match.group(2)): |
| 1616 # It's a typedef (union) | 1617 # It's a typedef (union) |
| 1617 item_info = self.TypeInfo('any') | 1618 item_info = self.TypeInfo('any') |
| 1618 else: | 1619 else: |
| 1619 item_info = self.TypeInfo(match.group(1) or match.group(2)) | 1620 item_info = self.TypeInfo(match.group(1) or match.group(2)) |
| 1620 # TODO(vsm): Generalize this code. | 1621 # TODO(vsm): Generalize this code. |
| 1621 if 'SourceInfo' in type_name: | 1622 if 'SourceInfo' in type_name: |
| 1622 type_data.native_type = 'const Vector<RefPtr<SourceInfo> >& ' | 1623 type_data.native_type = 'const Vector<RefPtr<SourceInfo> >& ' |
| 1623 return SequenceIDLTypeInfo(type_name, type_data, item_info) | 1624 return SequenceIDLTypeInfo(type_name, type_data, item_info) |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1722 return_type == 'Rectangle') | 1723 return_type == 'Rectangle') |
| 1723 | 1724 |
| 1724 def wrap_return_type_blink(return_type, type_name, type_registry): | 1725 def wrap_return_type_blink(return_type, type_name, type_registry): |
| 1725 """Returns True if we should wrap the returned value. This checks | 1726 """Returns True if we should wrap the returned value. This checks |
| 1726 a number of different variations, calling the more basic functions | 1727 a number of different variations, calling the more basic functions |
| 1727 above.""" | 1728 above.""" |
| 1728 return (wrap_unwrap_type_blink(return_type, type_registry) or | 1729 return (wrap_unwrap_type_blink(return_type, type_registry) or |
| 1729 wrap_unwrap_type_blink(type_name, type_registry) or | 1730 wrap_unwrap_type_blink(type_name, type_registry) or |
| 1730 wrap_type_blink(return_type, type_registry) or | 1731 wrap_type_blink(return_type, type_registry) or |
| 1731 wrap_unwrap_list_blink(return_type, type_registry)) | 1732 wrap_unwrap_list_blink(return_type, type_registry)) |
| OLD | NEW |