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 457 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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.extended_attributes = {} | 473 self.extended_attributes = {} |
474 self.idl_type = None | 474 self.idl_type = None |
475 self.is_optional = node.GetProperty('OPTIONAL') # syntax: (optional T) | 475 self.is_optional = node.GetProperty('OPTIONAL') # syntax: (optional T) |
476 self.is_variadic = False # syntax: (T...) | 476 self.is_variadic = False # syntax: (T...) |
477 self.name = node.GetName() | 477 self.name = node.GetName() |
| 478 self.default_value = None |
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 = child.GetName() |
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: |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
689 child_class = child.GetClass() | 692 child_class = child.GetClass() |
690 if child_class != 'Type': | 693 if child_class != 'Type': |
691 raise ValueError('Unrecognized node class: %s' % child_class) | 694 raise ValueError('Unrecognized node class: %s' % child_class) |
692 return type_node_to_type(child) | 695 return type_node_to_type(child) |
693 | 696 |
694 | 697 |
695 def union_type_node_to_idl_union_type(node, is_nullable=False): | 698 def union_type_node_to_idl_union_type(node, is_nullable=False): |
696 member_types = [type_node_to_type(member_type_node) | 699 member_types = [type_node_to_type(member_type_node) |
697 for member_type_node in node.GetChildren()] | 700 for member_type_node in node.GetChildren()] |
698 return IdlUnionType(member_types, is_nullable=is_nullable) | 701 return IdlUnionType(member_types, is_nullable=is_nullable) |
OLD | NEW |