| 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 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 # Nodes with different tags in different browsers can be listed as multiple | 107 # Nodes with different tags in different browsers can be listed as multiple |
| 108 # tags here provided there is not conflict in usage (e.g. browser X has tag | 108 # tags here provided there is not conflict in usage (e.g. browser X has tag |
| 109 # T and no other browser has tag T). | 109 # T and no other browser has tag T). |
| 110 | 110 |
| 111 'AnalyserNode': 'AnalyserNode,RealtimeAnalyserNode', | 111 'AnalyserNode': 'AnalyserNode,RealtimeAnalyserNode', |
| 112 'AudioContext': 'AudioContext,webkitAudioContext', | 112 'AudioContext': 'AudioContext,webkitAudioContext', |
| 113 | 113 |
| 114 'ChannelMergerNode': 'ChannelMergerNode,AudioChannelMerger', | 114 'ChannelMergerNode': 'ChannelMergerNode,AudioChannelMerger', |
| 115 'ChannelSplitterNode': 'ChannelSplitterNode,AudioChannelSplitter', | 115 'ChannelSplitterNode': 'ChannelSplitterNode,AudioChannelSplitter', |
| 116 | 116 |
| 117 'ClientRect': 'ClientRect,DOMRect', |
| 117 'ClientRectList': 'ClientRectList,DOMRectList', | 118 'ClientRectList': 'ClientRectList,DOMRectList', |
| 118 | 119 |
| 119 'CSSStyleDeclaration': | 120 'CSSStyleDeclaration': |
| 120 # IE Firefox | 121 # IE Firefox |
| 121 'CSSStyleDeclaration,MSStyleCSSProperties,CSS2Properties', | 122 'CSSStyleDeclaration,MSStyleCSSProperties,CSS2Properties', |
| 122 | 123 |
| 123 'Clipboard': 'Clipboard,DataTransfer', | 124 'Clipboard': 'Clipboard,DataTransfer', |
| 124 | 125 |
| 125 'ApplicationCache': | 126 'ApplicationCache': |
| 126 'ApplicationCache,DOMApplicationCache,OfflineResourceList', | 127 'ApplicationCache,DOMApplicationCache,OfflineResourceList', |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 return argument.optional | 232 return argument.optional |
| 232 if 'DartForceOptional' in argument.ext_attrs: | 233 if 'DartForceOptional' in argument.ext_attrs: |
| 233 return True | 234 return True |
| 234 return False | 235 return False |
| 235 | 236 |
| 236 # Given a list of overloaded arguments, choose a suitable name. | 237 # Given a list of overloaded arguments, choose a suitable name. |
| 237 def OverloadedName(args): | 238 def OverloadedName(args): |
| 238 return '_OR_'.join(sorted(set(arg.id for arg in args))) | 239 return '_OR_'.join(sorted(set(arg.id for arg in args))) |
| 239 | 240 |
| 240 def DartType(idl_type_name): | 241 def DartType(idl_type_name): |
| 241 if idl_type_name in _idl_type_registry: | 242 if idl_type_name in _idl_type_registry: |
| 242 return _idl_type_registry[idl_type_name].dart_type or idl_type_name | 243 return _idl_type_registry[idl_type_name].dart_type or idl_type_name |
| 243 return idl_type_name | 244 return idl_type_name |
| 244 | 245 |
| 245 # Given a list of overloaded arguments, choose a suitable type. | 246 # Given a list of overloaded arguments, choose a suitable type. |
| 246 def OverloadedType(args): | 247 def OverloadedType(args): |
| 247 type_ids = sorted(set(arg.type.id for arg in args)) | 248 type_ids = sorted(set(arg.type.id for arg in args)) |
| 248 if len(set(DartType(arg.type.id) for arg in args)) == 1: | 249 if len(set(DartType(arg.type.id) for arg in args)) == 1: |
| 249 return type_ids[0] | 250 return type_ids[0] |
| 250 else: | 251 else: |
| 251 return None | 252 return None |
| 252 | 253 |
| 253 result = [] | 254 result = [] |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 442 dart_type = rename_type(param.type_id) if param.type_id else 'dynamic' | 443 dart_type = rename_type(param.type_id) if param.type_id else 'dynamic' |
| 443 return (TypeOrNothing(dart_type, param.type_id), param.name) | 444 return (TypeOrNothing(dart_type, param.type_id), param.name) |
| 444 required = [] | 445 required = [] |
| 445 optional = [] | 446 optional = [] |
| 446 for param_info in self.param_infos: | 447 for param_info in self.param_infos: |
| 447 if param_info.is_optional: | 448 if param_info.is_optional: |
| 448 optional.append(FormatParam(param_info)) | 449 optional.append(FormatParam(param_info)) |
| 449 else: | 450 else: |
| 450 if optional: | 451 if optional: |
| 451 raise Exception('Optional parameters cannot precede required ones: ' | 452 raise Exception('Optional parameters cannot precede required ones: ' |
| 452 + str(param_info)) | 453 + str(params)) |
| 453 required.append(FormatParam(param_info)) | 454 required.append(FormatParam(param_info)) |
| 454 needs_named = optional and self.requires_named_arguments and not force_optio
nal | 455 needs_named = optional and self.requires_named_arguments and not force_optio
nal |
| 455 return (required, optional, needs_named) | 456 return (required, optional, needs_named) |
| 456 | 457 |
| 457 def ParametersAsDecStringList(self, rename_type, force_optional=False): | 458 def ParametersAsDecStringList(self, rename_type, force_optional=False): |
| 458 """Returns a list of strings where each string corresponds to a parameter | 459 """Returns a list of strings where each string corresponds to a parameter |
| 459 declaration. All of the optional/named parameters if any will appear as | 460 declaration. All of the optional/named parameters if any will appear as |
| 460 a single entry at the end of the list. | 461 a single entry at the end of the list. |
| 461 """ | 462 """ |
| 462 (required, optional, needs_named) = \ | 463 (required, optional, needs_named) = \ |
| (...skipping 859 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1322 if type_data.clazz == 'BasicTypedList': | 1323 if type_data.clazz == 'BasicTypedList': |
| 1323 if type_name == 'ArrayBuffer': | 1324 if type_name == 'ArrayBuffer': |
| 1324 dart_interface_name = 'ByteBuffer' | 1325 dart_interface_name = 'ByteBuffer' |
| 1325 else: | 1326 else: |
| 1326 dart_interface_name = self._renamer.RenameInterfaceId(type_name) | 1327 dart_interface_name = self._renamer.RenameInterfaceId(type_name) |
| 1327 return BasicTypedListIDLTypeInfo( | 1328 return BasicTypedListIDLTypeInfo( |
| 1328 type_name, type_data, dart_interface_name, self) | 1329 type_name, type_data, dart_interface_name, self) |
| 1329 | 1330 |
| 1330 class_name = '%sIDLTypeInfo' % type_data.clazz | 1331 class_name = '%sIDLTypeInfo' % type_data.clazz |
| 1331 return globals()[class_name](type_name, type_data) | 1332 return globals()[class_name](type_name, type_data) |
| OLD | NEW |