Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright (C) 2013 Google Inc. All rights reserved. | 1 # Copyright (C) 2013 Google Inc. All rights reserved. |
| 2 # | 2 # |
| 3 # Redistribution and use in source and binary forms, with or without | 3 # Redistribution and use in source and binary forms, with or without |
| 4 # modification, are permitted provided that the following conditions are | 4 # modification, are permitted provided that the following conditions are |
| 5 # met: | 5 # met: |
| 6 # | 6 # |
| 7 # * Redistributions of source code must retain the above copyright | 7 # * Redistributions of source code must retain the above copyright |
| 8 # notice, this list of conditions and the following disclaimer. | 8 # notice, this list of conditions and the following disclaimer. |
| 9 # * Redistributions in binary form must reproduce the above | 9 # * Redistributions in binary form must reproduce the above |
| 10 # copyright notice, this list of conditions and the following disclaimer | 10 # copyright notice, this list of conditions and the following disclaimer |
| (...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 463 for argument in self.arguments: | 463 for argument in self.arguments: |
| 464 argument.resolve_typedefs(typedefs) | 464 argument.resolve_typedefs(typedefs) |
| 465 | 465 |
| 466 | 466 |
| 467 ################################################################################ | 467 ################################################################################ |
| 468 # Arguments | 468 # Arguments |
| 469 ################################################################################ | 469 ################################################################################ |
| 470 | 470 |
| 471 class IdlArgument(TypedObject): | 471 class IdlArgument(TypedObject): |
| 472 def __init__(self, node): | 472 def __init__(self, node): |
| 473 self.default_value = None | |
| 473 self.extended_attributes = {} | 474 self.extended_attributes = {} |
| 474 self.idl_type = None | 475 self.idl_type = None |
| 475 self.is_optional = node.GetProperty('OPTIONAL') # syntax: (optional T) | 476 self.is_optional = node.GetProperty('OPTIONAL') # syntax: (optional T) |
| 476 self.is_variadic = False # syntax: (T...) | 477 self.is_variadic = False # syntax: (T...) |
| 477 self.name = node.GetName() | 478 self.name = node.GetName() |
| 478 | 479 |
| 479 children = node.GetChildren() | 480 children = node.GetChildren() |
| 480 for child in children: | 481 for child in children: |
| 481 child_class = child.GetClass() | 482 child_class = child.GetClass() |
| 482 if child_class == 'Type': | 483 if child_class == 'Type': |
| 483 self.idl_type = type_node_to_type(child) | 484 self.idl_type = type_node_to_type(child) |
| 484 elif child_class == 'ExtAttributes': | 485 elif child_class == 'ExtAttributes': |
| 485 self.extended_attributes = ext_attributes_node_to_extended_attri butes(child) | 486 self.extended_attributes = ext_attributes_node_to_extended_attri butes(child) |
| 486 elif child_class == 'Argument': | 487 elif child_class == 'Argument': |
| 487 child_name = child.GetName() | 488 child_name = child.GetName() |
| 488 if child_name != '...': | 489 if child_name != '...': |
| 489 raise ValueError('Unrecognized Argument node; expected "..." , got "%s"' % child_name) | 490 raise ValueError('Unrecognized Argument node; expected "..." , got "%s"' % child_name) |
| 490 self.is_variadic = child.GetProperty('ELLIPSIS') or False | 491 self.is_variadic = child.GetProperty('ELLIPSIS') or False |
| 492 elif child_class == 'Default': | |
| 493 self.default_value = default_node_to_default_value(child) | |
| 491 else: | 494 else: |
| 492 raise ValueError('Unrecognized node class: %s' % child_class) | 495 raise ValueError('Unrecognized node class: %s' % child_class) |
| 493 | 496 |
| 494 | 497 |
| 495 def arguments_node_to_arguments(node): | 498 def arguments_node_to_arguments(node): |
| 496 # [Constructor] and [CustomConstructor] without arguments (the bare form) | 499 # [Constructor] and [CustomConstructor] without arguments (the bare form) |
| 497 # have None instead of an arguments node, but have the same meaning as using | 500 # have None instead of an arguments node, but have the same meaning as using |
| 498 # an empty argument list, [Constructor()], so special-case this. | 501 # an empty argument list, [Constructor()], so special-case this. |
| 499 # http://www.w3.org/TR/WebIDL/#Constructor | 502 # http://www.w3.org/TR/WebIDL/#Constructor |
| 500 if node is None: | 503 if node is None: |
| 501 return [] | 504 return [] |
| 502 return [IdlArgument(argument_node) | 505 return [IdlArgument(argument_node) |
| 503 for argument_node in node.GetChildren()] | 506 for argument_node in node.GetChildren()] |
| 504 | 507 |
| 505 | 508 |
| 506 ################################################################################ | 509 ################################################################################ |
| 510 # Default value | |
| 511 ################################################################################ | |
| 512 | |
| 513 def default_node_to_default_value(node): | |
| 514 # FIXME: IDL parser currently outputs literal values inconsistently(crbug.co m/374178). | |
|
Nils Barth (inactive)
2014/06/02 02:48:34
Please use complete URLs (so syntax matching detec
| |
| 515 # This function should return node.GetProperty('VALUE') once this issue is f ixed. | |
| 516 if (node.GetProperty('TYPE') == "boolean" or | |
|
Nils Barth (inactive)
2014/06/02 02:48:34
Single quotes.
| |
| 517 node.GetProperty('TYPE') == "float"): | |
|
Nils Barth (inactive)
2014/06/02 02:48:34
You can use |in| for checking against a list:
node
Nils Barth (inactive)
2014/06/02 02:54:15
BTW, since it's probably unfamiliar:
You can also
| |
| 518 return node.GetProperty('VALUE') | |
| 519 return node.GetName() | |
| 520 | |
| 521 | |
| 522 ################################################################################ | |
| 507 # Extended attributes | 523 # Extended attributes |
| 508 ################################################################################ | 524 ################################################################################ |
| 509 | 525 |
| 510 def ext_attributes_node_to_extended_attributes(node): | 526 def ext_attributes_node_to_extended_attributes(node): |
| 511 """ | 527 """ |
| 512 Returns: | 528 Returns: |
| 513 Dictionary of {ExtAttributeName: ExtAttributeValue}. | 529 Dictionary of {ExtAttributeName: ExtAttributeValue}. |
| 514 Value is usually a string, with three exceptions: | 530 Value is usually a string, with three exceptions: |
| 515 Constructors: value is a list of Arguments nodes, corresponding to | 531 Constructors: value is a list of Arguments nodes, corresponding to |
| 516 possible signatures of the constructor. | 532 possible signatures of the constructor. |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 689 child_class = child.GetClass() | 705 child_class = child.GetClass() |
| 690 if child_class != 'Type': | 706 if child_class != 'Type': |
| 691 raise ValueError('Unrecognized node class: %s' % child_class) | 707 raise ValueError('Unrecognized node class: %s' % child_class) |
| 692 return type_node_to_type(child) | 708 return type_node_to_type(child) |
| 693 | 709 |
| 694 | 710 |
| 695 def union_type_node_to_idl_union_type(node, is_nullable=False): | 711 def union_type_node_to_idl_union_type(node, is_nullable=False): |
| 696 member_types = [type_node_to_type(member_type_node) | 712 member_types = [type_node_to_type(member_type_node) |
| 697 for member_type_node in node.GetChildren()] | 713 for member_type_node in node.GetChildren()] |
| 698 return IdlUnionType(member_types, is_nullable=is_nullable) | 714 return IdlUnionType(member_types, is_nullable=is_nullable) |
| OLD | NEW |