| 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 re | 9 import re |
| 10 | 10 |
| 11 _pure_interfaces = set([ | 11 _pure_interfaces = set([ |
| 12 # TODO(sra): DOMStringMap should be a class implementing Map<String,String>. |
| 12 'DOMStringMap', | 13 'DOMStringMap', |
| 13 'ElementTimeControl', | 14 'ElementTimeControl', |
| 14 'ElementTraversal', | 15 'ElementTraversal', |
| 15 'MediaQueryListListener', | 16 'MediaQueryListListener', |
| 16 'NodeSelector', | 17 'NodeSelector', |
| 17 'SVGExternalResourcesRequired', | 18 'SVGExternalResourcesRequired', |
| 18 'SVGFilterPrimitiveStandardAttributes', | 19 'SVGFilterPrimitiveStandardAttributes', |
| 19 'SVGFitToViewBox', | 20 'SVGFitToViewBox', |
| 20 'SVGLangSpace', | 21 'SVGLangSpace', |
| 21 'SVGLocatable', | 22 'SVGLocatable', |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 | 228 |
| 228 # Zip together arguments from each overload by position, then convert | 229 # Zip together arguments from each overload by position, then convert |
| 229 # to a dart argument. | 230 # to a dart argument. |
| 230 args = map(lambda *args: _DartArg(args, interface), | 231 args = map(lambda *args: _DartArg(args, interface), |
| 231 *(op.arguments for op in operations)) | 232 *(op.arguments for op in operations)) |
| 232 | 233 |
| 233 info = OperationInfo() | 234 info = OperationInfo() |
| 234 info.overloads = operations | 235 info.overloads = operations |
| 235 info.declared_name = operations[0].id | 236 info.declared_name = operations[0].id |
| 236 info.name = operations[0].ext_attrs.get('DartName', info.declared_name) | 237 info.name = operations[0].ext_attrs.get('DartName', info.declared_name) |
| 238 info.constructor_name = None |
| 237 info.js_name = info.declared_name | 239 info.js_name = info.declared_name |
| 238 info.type_name = DartType(operations[0].type.id) # TODO: widen. | 240 info.type_name = DartType(operations[0].type.id) # TODO: widen. |
| 239 info.param_infos = args | 241 info.param_infos = args |
| 240 return info | 242 return info |
| 241 | 243 |
| 242 | 244 |
| 243 def AnalyzeConstructor(interface): | 245 def AnalyzeConstructor(interface): |
| 244 """Returns an OperationInfo object for the constructor. | 246 """Returns an OperationInfo object for the constructor. |
| 245 | 247 |
| 246 Returns None if the interface has no Constructor. | 248 Returns None if the interface has no Constructor. |
| (...skipping 18 matching lines...) Expand all Loading... |
| 265 args = GetArgs(func_value) | 267 args = GetArgs(func_value) |
| 266 idl_args = func_value.arguments | 268 idl_args = func_value.arguments |
| 267 else: | 269 else: |
| 268 return None | 270 return None |
| 269 | 271 |
| 270 info = OperationInfo() | 272 info = OperationInfo() |
| 271 info.overloads = None | 273 info.overloads = None |
| 272 info.idl_args = idl_args | 274 info.idl_args = idl_args |
| 273 info.declared_name = name | 275 info.declared_name = name |
| 274 info.name = name | 276 info.name = name |
| 277 info.constructor_name = None |
| 275 info.js_name = name | 278 info.js_name = name |
| 276 info.type_name = interface.id | 279 info.type_name = interface.id |
| 277 info.param_infos = args | 280 info.param_infos = args |
| 278 return info | 281 return info |
| 279 | 282 |
| 280 | 283 |
| 281 def RecognizeCallback(interface): | 284 def RecognizeCallback(interface): |
| 282 """Returns the info for the callback method if the interface smells like a | 285 """Returns the info for the callback method if the interface smells like a |
| 283 callback. | 286 callback. |
| 284 """ | 287 """ |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 344 else: | 347 else: |
| 345 return dart_type | 348 return dart_type |
| 346 | 349 |
| 347 | 350 |
| 348 class OperationInfo(object): | 351 class OperationInfo(object): |
| 349 """Holder for various derived information from a set of overloaded operations. | 352 """Holder for various derived information from a set of overloaded operations. |
| 350 | 353 |
| 351 Attributes: | 354 Attributes: |
| 352 overloads: A list of IDL operation overloads with the same name. | 355 overloads: A list of IDL operation overloads with the same name. |
| 353 name: A string, the simple name of the operation. | 356 name: A string, the simple name of the operation. |
| 357 constructor_name: A string, the name of the constructor iff the constructor |
| 358 is named, e.g. 'fromList' in Int8Array.fromList(list). |
| 354 type_name: A string, the name of the return type of the operation. | 359 type_name: A string, the name of the return type of the operation. |
| 355 param_infos: A list of ParamInfo. | 360 param_infos: A list of ParamInfo. |
| 356 """ | 361 """ |
| 357 | 362 |
| 358 def ParametersInterfaceDeclaration(self): | 363 def ParametersInterfaceDeclaration(self): |
| 359 """Returns a formatted string declaring the parameters for the interface.""" | 364 """Returns a formatted string declaring the parameters for the interface.""" |
| 360 return self._FormatParams( | 365 return self._FormatParams( |
| 361 self.param_infos, True, | 366 self.param_infos, True, |
| 362 lambda param: TypeOrNothing(param.dart_type, param.type_id)) | 367 lambda param: TypeOrNothing(param.dart_type, param.type_id)) |
| 363 | 368 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 415 argtexts = map(FormatParam, required) | 420 argtexts = map(FormatParam, required) |
| 416 if optional: | 421 if optional: |
| 417 argtexts.append('[' + ', '.join(map(FormatParam, optional)) + ']') | 422 argtexts.append('[' + ', '.join(map(FormatParam, optional)) + ']') |
| 418 return ', '.join(argtexts) | 423 return ', '.join(argtexts) |
| 419 | 424 |
| 420 def IsStatic(self): | 425 def IsStatic(self): |
| 421 is_static = self.overloads[0].is_static | 426 is_static = self.overloads[0].is_static |
| 422 assert any([is_static == o.is_static for o in self.overloads]) | 427 assert any([is_static == o.is_static for o in self.overloads]) |
| 423 return is_static | 428 return is_static |
| 424 | 429 |
| 430 def ConstructorFullName(self): |
| 431 if self.constructor_name: |
| 432 return self.type_name + '.' + self.constructor_name |
| 433 else: |
| 434 return self.type_name |
| 435 |
| 425 | 436 |
| 426 def AttributeOutputOrder(a, b): | 437 def AttributeOutputOrder(a, b): |
| 427 """Canonical output ordering for attributes.""" | 438 """Canonical output ordering for attributes.""" |
| 428 # Getters before setters: | 439 # Getters before setters: |
| 429 if a.id < b.id: return -1 | 440 if a.id < b.id: return -1 |
| 430 if a.id > b.id: return 1 | 441 if a.id > b.id: return 1 |
| 431 if a.is_fc_setter < b.is_fc_setter: return -1 | 442 if a.is_fc_setter < b.is_fc_setter: return -1 |
| 432 if a.is_fc_setter > b.is_fc_setter: return 1 | 443 if a.is_fc_setter > b.is_fc_setter: return 1 |
| 433 return 0 | 444 return 0 |
| 434 | 445 |
| (...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 756 '"SVGAnimatedListPropertyTearOff.h"', | 767 '"SVGAnimatedListPropertyTearOff.h"', |
| 757 '"SVGTransformListPropertyTearOff.h"', | 768 '"SVGTransformListPropertyTearOff.h"', |
| 758 '"SVGPathSegListPropertyTearOff.h"', | 769 '"SVGPathSegListPropertyTearOff.h"', |
| 759 ] | 770 ] |
| 760 | 771 |
| 761 def GetIDLTypeInfo(idl_type_name): | 772 def GetIDLTypeInfo(idl_type_name): |
| 762 match = re.match(r'sequence<(\w+)>$', idl_type_name) | 773 match = re.match(r'sequence<(\w+)>$', idl_type_name) |
| 763 if match: | 774 if match: |
| 764 return SequenceIDLTypeInfo(idl_type_name, GetIDLTypeInfo(match.group(1))) | 775 return SequenceIDLTypeInfo(idl_type_name, GetIDLTypeInfo(match.group(1))) |
| 765 return _idl_type_registry.get(idl_type_name, IDLTypeInfo(idl_type_name)) | 776 return _idl_type_registry.get(idl_type_name, IDLTypeInfo(idl_type_name)) |
| OLD | NEW |