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 the system to generate | 6 """This module provides shared functionality for the system to generate |
7 Dart:html APIs from the IDL database.""" | 7 Dart:html APIs from the IDL database.""" |
8 | 8 |
9 from systemfrog import * | 9 from systemfrog import * |
10 from systeminterface import * | 10 from systeminterface import * |
(...skipping 1233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1244 template = self._system._templates.Load('factoryprovider.darttemplate') | 1244 template = self._system._templates.Load('factoryprovider.darttemplate') |
1245 | 1245 |
1246 factory_provider = '_' + interface_name + 'FactoryProvider' | 1246 factory_provider = '_' + interface_name + 'FactoryProvider' |
1247 emitter = self._system._ImplFileEmitter(factory_provider) | 1247 emitter = self._system._ImplFileEmitter(factory_provider) |
1248 emitter.Emit( | 1248 emitter.Emit( |
1249 template, | 1249 template, |
1250 FACTORYPROVIDER=factory_provider, | 1250 FACTORYPROVIDER=factory_provider, |
1251 CONSTRUCTOR=interface_name, | 1251 CONSTRUCTOR=interface_name, |
1252 PARAMETERS=constructor_info.ParametersImplementationDeclaration(), | 1252 PARAMETERS=constructor_info.ParametersImplementationDeclaration(), |
1253 NAMED_CONSTRUCTOR=constructor_info.name or interface_name, | 1253 NAMED_CONSTRUCTOR=constructor_info.name or interface_name, |
1254 ARGUMENTS=constructor_info.ParametersAsArgumentList()) | 1254 ARGUMENTS=self._UnwrappedParameters(constructor_info, |
| 1255 len(constructor_info.arg_infos))) |
| 1256 |
| 1257 def _UnwrappedParameters(self, operation_info, length): |
| 1258 """Returns string for an argument list that unwraps first |length| |
| 1259 parameters.""" |
| 1260 def UnwrapArgInfo(arg_info): |
| 1261 (name, type, value) = arg_info |
| 1262 # TODO(sra): Type dependent unwrapping. |
| 1263 return '_unwrap(%s)' % name |
| 1264 |
| 1265 return ', '.join(map(UnwrapArgInfo, operation_info.arg_infos[:length])) |
1255 | 1266 |
1256 def _BaseClassName(self, interface): | 1267 def _BaseClassName(self, interface): |
1257 if not interface.parents: | 1268 if not interface.parents: |
1258 return '_DOMTypeBase' | 1269 return '_DOMTypeBase' |
1259 | 1270 |
1260 supertype = DartType(interface.parents[0].type.id) | 1271 supertype = DartType(interface.parents[0].type.id) |
1261 | 1272 |
1262 if IsDartListType(supertype) or IsDartCollectionType(supertype): | 1273 if IsDartListType(supertype) or IsDartCollectionType(supertype): |
1263 return 'DOMWrapperBase' | 1274 return 'DOMWrapperBase' |
1264 | 1275 |
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1578 | 1589 |
1579 def GenerateSingleOperation(self, emitter, info, indent, operation): | 1590 def GenerateSingleOperation(self, emitter, info, indent, operation): |
1580 """Generates a call to a single operation. | 1591 """Generates a call to a single operation. |
1581 | 1592 |
1582 Arguments: | 1593 Arguments: |
1583 emitter: an Emitter for the body of a block of code. | 1594 emitter: an Emitter for the body of a block of code. |
1584 info: the compound information about the operation and its overloads. | 1595 info: the compound information about the operation and its overloads. |
1585 indent: an indentation string for generated code. | 1596 indent: an indentation string for generated code. |
1586 operation: the IDLOperation to call. | 1597 operation: the IDLOperation to call. |
1587 """ | 1598 """ |
1588 # TODO(sra): Do we need to distinguish calling with missing optional | 1599 argument_expressions = self._UnwrappedParameters( |
1589 # arguments from passing 'null' which is represented as 'undefined'? | 1600 info, |
1590 def UnwrapArgExpression(name, type): | 1601 len(operation.arguments)) # Just the parameters this far. |
1591 # TODO: Type specific unwrapping. | |
1592 return '_unwrap(%s)' % (name) | |
1593 | 1602 |
1594 def ArgNameAndUnwrapper(arg_info, overload_arg): | |
1595 (name, type, value) = arg_info | |
1596 return (name, UnwrapArgExpression(name, type)) | |
1597 | |
1598 names_and_unwrappers = [ArgNameAndUnwrapper(info.arg_infos[i], arg) | |
1599 for (i, arg) in enumerate(operation.arguments)] | |
1600 unwrap_args = [unwrap_arg for (_, unwrap_arg) in names_and_unwrappers] | |
1601 arg_names = ['_unwrap(%s)' % name for (name, _) in names_and_unwrappers] | |
1602 | |
1603 argument_expressions = ', '.join(arg_names) | |
1604 if info.type_name != 'void': | 1603 if info.type_name != 'void': |
1605 # We could place the logic for handling Document directly in _wrap | 1604 # We could place the logic for handling Document directly in _wrap |
1606 # but we chose to place it here so that bugs in the wrapper and | 1605 # but we chose to place it here so that bugs in the wrapper and |
1607 # wrapperless implementations are more consistent. | 1606 # wrapperless implementations are more consistent. |
1608 if self._shared.MaybeReturnDocument(info.type_name): | 1607 if self._shared.MaybeReturnDocument(info.type_name): |
1609 emitter.Emit('$(INDENT)return _FixHtmlDocumentReference(' | 1608 emitter.Emit('$(INDENT)return _FixHtmlDocumentReference(' |
1610 '_wrap($(THIS).$NAME($ARGS)));\n', | 1609 '_wrap($(THIS).$NAME($ARGS)));\n', |
1611 INDENT=indent, | 1610 INDENT=indent, |
1612 THIS=self.DomObjectName(), | 1611 THIS=self.DomObjectName(), |
1613 NAME=info.name, | 1612 NAME=info.name, |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1716 # dispatch has removed f(X), leaving only f(Y), but there is no guarantee | 1715 # dispatch has removed f(X), leaving only f(Y), but there is no guarantee |
1717 # that Y = Z-X, so we need to check for Y. | 1716 # that Y = Z-X, so we need to check for Y. |
1718 true_code = emitter.Emit( | 1717 true_code = emitter.Emit( |
1719 '$(INDENT)if ($COND) {\n' | 1718 '$(INDENT)if ($COND) {\n' |
1720 '$!TRUE' | 1719 '$!TRUE' |
1721 '$(INDENT)}\n', | 1720 '$(INDENT)}\n', |
1722 COND=test, INDENT=indent) | 1721 COND=test, INDENT=indent) |
1723 self.GenerateDispatch( | 1722 self.GenerateDispatch( |
1724 true_code, info, indent + ' ', position + 1, positive) | 1723 true_code, info, indent + ' ', position + 1, positive) |
1725 return True | 1724 return True |
OLD | NEW |