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