Chromium Code Reviews| Index: tools/dom/scripts/htmldartgenerator.py |
| diff --git a/tools/dom/scripts/htmldartgenerator.py b/tools/dom/scripts/htmldartgenerator.py |
| index b4bccf95575221b3f0cfc7f56a7bc7a926ca2a41..380ccf461c9bd0bfdeac06383704747fbcbcf23a 100644 |
| --- a/tools/dom/scripts/htmldartgenerator.py |
| +++ b/tools/dom/scripts/htmldartgenerator.py |
| @@ -10,7 +10,10 @@ import emitter |
| from generator import AnalyzeOperation, ConstantOutputOrder, \ |
| DartDomNameOfAttribute, FindMatchingAttribute, IsDartCollectionType, \ |
| IsPureInterface, TypeOrNothing, ConvertToFuture, GetCallbackInfo |
| -from htmlrenamer import convert_to_future_members |
| +from copy import deepcopy |
| +from htmlrenamer import convert_to_future_members, keep_overloaded_members, \ |
| + private_html_members, renamed_html_members, renamed_overloads |
| +import monitored |
| # Types that are accessible cross-frame in a limited fashion. |
| # In these cases, the base type (e.g., WindowBase) provides restricted access |
| @@ -83,6 +86,7 @@ class HtmlDartGenerator(object): |
| break |
| # Group overloaded operations by name. |
| + self._AddRenamedOverloads(interface) |
| operationsByName = self._OperationsByName(interface) |
| # Generate operations. |
| @@ -119,6 +123,45 @@ class HtmlDartGenerator(object): |
| self.SecondaryContext(parent_interface) |
| self.AddOperation(info) |
| + def _AddRenamedOverloads(self, interface): |
| + """The IDL has a number of functions with the same name but that accept |
| + different types. This is fine for JavaScript, but results in vague type |
| + signatures for Dart. We rename some of these (by adding a new identical |
| + operation with a different DartName), but leave the original version as |
| + well.""" |
| + # This function gets called twice per interface if we generate both dart2js |
| + # and dartium APIs, but we only want to rename the overloads once, so we |
| + # keep track of this via already_renamed. |
| + already_renamed = [operation.ext_attrs['DartName'] if 'DartName' in |
| + operation.ext_attrs else '' for operation in interface.operations] |
| + added_operations = [] |
| + operations_by_name = self._OperationsByName(interface) |
| + for operation in interface.operations: |
| + full_operation_str = self._GetStringRepresentation(interface, operation) |
| + if (full_operation_str in renamed_overloads and |
| + renamed_overloads[full_operation_str] not in already_renamed): |
| + cloned_operation = deepcopy(operation) |
| + cloned_operation.ext_attrs['DartName'] = renamed_overloads[ |
| + full_operation_str] |
| + added_operations.append(cloned_operation) |
| + operation_str = '%s.%s' % (interface.id, operation.id) |
| + if (operation.id in operations_by_name and |
| + len(operations_by_name[operation.id]) > 1 and |
| + len(filter(lambda overload: overload.startswith(operation_str), |
| + renamed_overloads.keys())) == 0 and |
| + operation_str not in keep_overloaded_members and |
| + operation_str not in renamed_html_members and |
| + operation_str not in private_html_members): |
| + print 'WARNING: Multiple type signatures for %s.%s' % ( |
|
blois
2013/06/28 20:57:48
This should use the logging mechanism.
|
| + interface.id, operation.id) |
| + interface.operations += added_operations |
| + |
| + def _GetStringRepresentation(self, interface, operation): |
| + """Given an IDLOperation, return a object-independent representation of the |
| + operations's signature.""" |
| + return '%s.%s(%s)' % (interface.id, operation.id, ', '.join( |
| + ['%s %s' % (arg.type.id, arg.id) for arg in operation.arguments])) |
| + |
| def _OperationsByName(self, interface): |
| operationsByName = {} |
| for operation in interface.operations: |