OLD | NEW |
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 # Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 2 # Copyright (c) 2011, 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 generates Dart APIs from the IDL database.""" | 6 """This module generates Dart APIs from the IDL database.""" |
7 | 7 |
8 import emitter | 8 import emitter |
9 import idlnode | 9 import idlnode |
10 import logging | 10 import logging |
11 import multiemitter | 11 import multiemitter |
12 import os | 12 import os |
13 import re | 13 import re |
14 import shutil | 14 import shutil |
15 | 15 |
16 _logger = logging.getLogger('dartgenerator') | 16 _logger = logging.getLogger('dartgenerator') |
17 | 17 |
18 # IDL->Dart primitive types conversion. | 18 # IDL->Dart primitive types conversion. |
19 _idl_to_dart_type_conversions = { | 19 _idl_to_dart_type_conversions = { |
20 'any': 'Object', | 20 'any': 'Object', |
| 21 'any[]': 'List', |
21 'custom': 'Dynamic', | 22 'custom': 'Dynamic', |
22 'boolean': 'bool', | 23 'boolean': 'bool', |
23 'DOMObject': 'Object', | 24 'DOMObject': 'Object', |
24 'DOMString': 'String', | 25 'DOMString': 'String', |
25 'DOMStringList': 'List<String>', | 26 'DOMStringList': 'List<String>', |
26 'DOMTimeStamp': 'int', | 27 'DOMTimeStamp': 'int', |
27 'Date': 'Date', | 28 'Date': 'Date', |
28 # Map to num to enable callers to pass in Dart int, rational | 29 # Map to num to enable callers to pass in Dart int, rational |
29 # types. Our implementations will need to convert these to | 30 # types. Our implementations will need to convert these to |
30 # doubles or floats as needed. | 31 # doubles or floats as needed. |
(...skipping 1688 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1719 always dispatches. | 1720 always dispatches. |
1720 """ | 1721 """ |
1721 | 1722 |
1722 def NullCheck(name): | 1723 def NullCheck(name): |
1723 return '%s === null' % name | 1724 return '%s === null' % name |
1724 | 1725 |
1725 def TypeCheck(name, type): | 1726 def TypeCheck(name, type): |
1726 return '%s is %s' % (name, type) | 1727 return '%s is %s' % (name, type) |
1727 | 1728 |
1728 if position == len(info.arg_infos): | 1729 if position == len(info.arg_infos): |
1729 assert len(overloads) == 1 | 1730 if len(overloads) > 1: |
| 1731 raise Exception('Duplicate operations ' + str(overloads)) |
1730 operation = overloads[0] | 1732 operation = overloads[0] |
1731 self.GenerateSingleOperation(emitter, info, indent, operation) | 1733 self.GenerateSingleOperation(emitter, info, indent, operation) |
1732 return False | 1734 return False |
1733 | 1735 |
1734 # FIXME: Consider a simpler dispatch that iterates over the | 1736 # FIXME: Consider a simpler dispatch that iterates over the |
1735 # overloads and generates an overload specific check. Revisit | 1737 # overloads and generates an overload specific check. Revisit |
1736 # when we move to named optional arguments. | 1738 # when we move to named optional arguments. |
1737 | 1739 |
1738 # Partition the overloads to divide and conquer on the dispatch. | 1740 # Partition the overloads to divide and conquer on the dispatch. |
1739 positive = [] | 1741 positive = [] |
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2014 Arguments: | 2016 Arguments: |
2015 info: An OperationInfo object. | 2017 info: An OperationInfo object. |
2016 """ | 2018 """ |
2017 # TODO(vsm): Handle overloads. | 2019 # TODO(vsm): Handle overloads. |
2018 self._members_emitter.Emit( | 2020 self._members_emitter.Emit( |
2019 '\n' | 2021 '\n' |
2020 ' $TYPE $NAME($ARGS) native;\n', | 2022 ' $TYPE $NAME($ARGS) native;\n', |
2021 TYPE=info.type_name, | 2023 TYPE=info.type_name, |
2022 NAME=info.name, | 2024 NAME=info.name, |
2023 ARGS=info.arg_implementation_declaration) | 2025 ARGS=info.arg_implementation_declaration) |
OLD | NEW |