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