| 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 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 287 | 287 |
| 288 def IsOptional(argument): | 288 def IsOptional(argument): |
| 289 return argument.optional and (not(HasSuppressedOptionalDefault(argument))) \ | 289 return argument.optional and (not(HasSuppressedOptionalDefault(argument))) \ |
| 290 or 'DartForceOptional' in argument.ext_attrs | 290 or 'DartForceOptional' in argument.ext_attrs |
| 291 | 291 |
| 292 def AnalyzeOperation(interface, operations): | 292 def AnalyzeOperation(interface, operations): |
| 293 """Makes operation calling convention decision for a set of overloads. | 293 """Makes operation calling convention decision for a set of overloads. |
| 294 | 294 |
| 295 Returns: An OperationInfo object. | 295 Returns: An OperationInfo object. |
| 296 """ | 296 """ |
| 297 | |
| 298 # split operations with optional args into multiple operations | 297 # split operations with optional args into multiple operations |
| 299 split_operations = [] | 298 split_operations = [] |
| 300 for operation in operations: | 299 for operation in operations: |
| 301 for i in range(0, len(operation.arguments)): | 300 for i in range(0, len(operation.arguments)): |
| 302 if IsOptional(operation.arguments[i]): | 301 if IsOptional(operation.arguments[i]): |
| 303 new_operation = copy.deepcopy(operation) | 302 new_operation = copy.deepcopy(operation) |
| 304 new_operation.arguments = new_operation.arguments[:i] | 303 new_operation.arguments = new_operation.arguments[:i] |
| 305 split_operations.append(new_operation) | 304 split_operations.append(new_operation) |
| 306 split_operations.append(operation) | 305 split_operations.append(operation) |
| 307 | 306 |
| (...skipping 1151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1459 if type_name == 'ArrayBuffer': | 1458 if type_name == 'ArrayBuffer': |
| 1460 dart_interface_name = 'ByteBuffer' | 1459 dart_interface_name = 'ByteBuffer' |
| 1461 else: | 1460 else: |
| 1462 dart_interface_name = self._renamer.RenameInterfaceId(type_name) | 1461 dart_interface_name = self._renamer.RenameInterfaceId(type_name) |
| 1463 return BasicTypedListIDLTypeInfo( | 1462 return BasicTypedListIDLTypeInfo( |
| 1464 type_name, type_data, dart_interface_name, self) | 1463 type_name, type_data, dart_interface_name, self) |
| 1465 | 1464 |
| 1466 class_name = '%sIDLTypeInfo' % type_data.clazz | 1465 class_name = '%sIDLTypeInfo' % type_data.clazz |
| 1467 return globals()[class_name](type_name, type_data) | 1466 return globals()[class_name](type_name, type_data) |
| 1468 | 1467 |
| 1468 def isList(return_type): |
| 1469 return return_type.startswith('List<') if return_type else False |
| 1470 |
| 1471 def get_list_type(return_type): |
| 1472 # Get the list type NNNN inside of List<NNNN> |
| 1473 return return_type[5:-1] if isList(return_type) else return_type |
| 1474 |
| 1469 def wrap_unwrap_list_blink(return_type, type_registry): | 1475 def wrap_unwrap_list_blink(return_type, type_registry): |
| 1470 """Return True if the type is a List<Node>""" | 1476 """Return True if the type is the list type is a blink know |
| 1471 return return_type.startswith('List<Node>') | 1477 type e.g., List<Node>, List<FontFace>, etc.""" |
| 1478 if isList(return_type): |
| 1479 list_type = get_list_type(return_type) |
| 1480 if type_registry.HasInterface(list_type): |
| 1481 return True; |
| 1472 | 1482 |
| 1473 def wrap_unwrap_type_blink(return_type, type_registry): | 1483 def wrap_unwrap_type_blink(return_type, type_registry): |
| 1474 """Returns True if the type is a blink type that requires wrap_jso or | 1484 """Returns True if the type is a blink type that requires wrap_jso or |
| 1475 unwrap_jso""" | 1485 unwrap_jso""" |
| 1476 if return_type and return_type.startswith('Html'): | 1486 if return_type and return_type.startswith('Html'): |
| 1477 return_type = return_type.replace('Html', 'HTML', 1) | 1487 return_type = return_type.replace('Html', 'HTML', 1) |
| 1478 return (type_registry.HasInterface(return_type) or not(return_type) or | 1488 return (type_registry.HasInterface(return_type) or not(return_type) or |
| 1479 return_type == 'Object' or | 1489 return_type == 'Object' or |
| 1480 return_type == 'dynamic' or | 1490 return_type == 'dynamic' or |
| 1481 return_type == 'Future' or | 1491 return_type == 'Future' or |
| 1482 return_type == 'SqlDatabase' or # renamed to Database | 1492 return_type == 'SqlDatabase' or # renamed to Database |
| 1483 return_type == 'HTMLElement' or | 1493 return_type == 'HTMLElement' or |
| 1484 return_type == 'MutationObserver' or | 1494 return_type == 'MutationObserver' or |
| 1485 (return_type.endswith('[]') and return_type != 'DOMString[]')) | 1495 (return_type.endswith('[]') and return_type != 'DOMString[]')) |
| 1486 | 1496 |
| 1487 def wrap_type_blink(return_type, type_registry): | 1497 def wrap_type_blink(return_type, type_registry): |
| 1488 """Returns True if the type is a blink type that requires wrap_jso but | 1498 """Returns True if the type is a blink type that requires wrap_jso but |
| 1489 NOT unwrap_jso""" | 1499 NOT unwrap_jso""" |
| 1490 return (return_type == 'Map' or | 1500 return (return_type == 'Map' or |
| 1491 return_type == 'Rectangle') | 1501 return_type == 'Rectangle') |
| 1492 | 1502 |
| 1493 def wrap_return_type_blink(return_type, type_name, type_registry): | 1503 def wrap_return_type_blink(return_type, type_name, type_registry): |
| 1494 """Returns True if we should wrap the returned value. This checks | 1504 """Returns True if we should wrap the returned value. This checks |
| 1495 a number of different variations, calling the more basic functions | 1505 a number of different variations, calling the more basic functions |
| 1496 above.""" | 1506 above.""" |
| 1497 return (wrap_unwrap_type_blink(return_type, type_registry) or | 1507 return (wrap_unwrap_type_blink(return_type, type_registry) or |
| 1498 wrap_unwrap_type_blink(type_name, type_registry) or | 1508 wrap_unwrap_type_blink(type_name, type_registry) or |
| 1499 wrap_type_blink(return_type, type_registry) or | 1509 wrap_type_blink(return_type, type_registry) or |
| 1500 wrap_unwrap_list_blink(return_type, type_registry)) | 1510 wrap_unwrap_list_blink(return_type, type_registry)) |
| OLD | NEW |