| 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 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 # Given a list of overloaded arguments, render dart arguments. | 221 # Given a list of overloaded arguments, render dart arguments. |
| 222 def _BuildArguments(args, interface, constructor=False): | 222 def _BuildArguments(args, interface, constructor=False): |
| 223 def IsOptional(argument): | 223 def IsOptional(argument): |
| 224 if 'Callback' in argument.ext_attrs: | 224 if 'Callback' in argument.ext_attrs: |
| 225 # Optional callbacks arguments are treated as optional arguments. | 225 # Optional callbacks arguments are treated as optional arguments. |
| 226 return argument.optional | 226 return argument.optional |
| 227 if constructor: | 227 if constructor: |
| 228 # FIXME: Optional constructors arguments should not be treated as | 228 # FIXME: Optional constructors arguments should not be treated as |
| 229 # optional arguments. | 229 # optional arguments. |
| 230 return argument.optional | 230 return argument.optional |
| 231 if 'ForceOptional' in argument.ext_attrs: | 231 if 'DartForceOptional' in argument.ext_attrs: |
| 232 return True | 232 return True |
| 233 return False | 233 return False |
| 234 | 234 |
| 235 # Given a list of overloaded arguments, choose a suitable name. | 235 # Given a list of overloaded arguments, choose a suitable name. |
| 236 def OverloadedName(args): | 236 def OverloadedName(args): |
| 237 return '_OR_'.join(sorted(set(arg.id for arg in args))) | 237 return '_OR_'.join(sorted(set(arg.id for arg in args))) |
| 238 | 238 |
| 239 def DartType(idl_type_name): | 239 def DartType(idl_type_name): |
| 240 if idl_type_name in _idl_type_registry: | 240 if idl_type_name in _idl_type_registry: |
| 241 return _idl_type_registry[idl_type_name].dart_type or idl_type_name | 241 return _idl_type_registry[idl_type_name].dart_type or idl_type_name |
| (...skipping 13 matching lines...) Expand all Loading... |
| 255 for arg_tuple in map(lambda *x: x, *args): | 255 for arg_tuple in map(lambda *x: x, *args): |
| 256 is_optional = is_optional or any(arg is None or IsOptional(arg) for arg in a
rg_tuple) | 256 is_optional = is_optional or any(arg is None or IsOptional(arg) for arg in a
rg_tuple) |
| 257 | 257 |
| 258 filtered = filter(None, arg_tuple) | 258 filtered = filter(None, arg_tuple) |
| 259 type_id = OverloadedType(filtered) | 259 type_id = OverloadedType(filtered) |
| 260 name = OverloadedName(filtered) | 260 name = OverloadedName(filtered) |
| 261 result.append(ParamInfo(name, type_id, is_optional)) | 261 result.append(ParamInfo(name, type_id, is_optional)) |
| 262 | 262 |
| 263 return result | 263 return result |
| 264 | 264 |
| 265 # Argument default value set (literal value or null). |
| 266 def HasDefault(argument): |
| 267 return (argument.default_value != None) or argument.default_value_is_null |
| 268 |
| 265 def IsOptional(argument): | 269 def IsOptional(argument): |
| 266 return argument.optional and ('Default' not in argument.ext_attrs)\ | 270 return argument.optional and (not(HasDefault(argument))) \ |
| 267 or 'ForceOptional' in argument.ext_attrs | 271 or 'DartForceOptional' in argument.ext_attrs |
| 268 | 272 |
| 269 def AnalyzeOperation(interface, operations): | 273 def AnalyzeOperation(interface, operations): |
| 270 """Makes operation calling convention decision for a set of overloads. | 274 """Makes operation calling convention decision for a set of overloads. |
| 271 | 275 |
| 272 Returns: An OperationInfo object. | 276 Returns: An OperationInfo object. |
| 273 """ | 277 """ |
| 274 | 278 |
| 275 # split operations with optional args into multiple operations | 279 # split operations with optional args into multiple operations |
| 276 split_operations = [] | 280 split_operations = [] |
| 277 for operation in operations: | 281 for operation in operations: |
| (...skipping 1039 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1317 if type_data.clazz == 'BasicTypedList': | 1321 if type_data.clazz == 'BasicTypedList': |
| 1318 if type_name == 'ArrayBuffer': | 1322 if type_name == 'ArrayBuffer': |
| 1319 dart_interface_name = 'ByteBuffer' | 1323 dart_interface_name = 'ByteBuffer' |
| 1320 else: | 1324 else: |
| 1321 dart_interface_name = self._renamer.RenameInterfaceId(type_name) | 1325 dart_interface_name = self._renamer.RenameInterfaceId(type_name) |
| 1322 return BasicTypedListIDLTypeInfo( | 1326 return BasicTypedListIDLTypeInfo( |
| 1323 type_name, type_data, dart_interface_name, self) | 1327 type_name, type_data, dart_interface_name, self) |
| 1324 | 1328 |
| 1325 class_name = '%sIDLTypeInfo' % type_data.clazz | 1329 class_name = '%sIDLTypeInfo' % type_data.clazz |
| 1326 return globals()[class_name](type_name, type_data) | 1330 return globals()[class_name](type_name, type_data) |
| OLD | NEW |