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 632 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
643 class IdlImplement(object): | 643 class IdlImplement(object): |
644 def __init__(self, node): | 644 def __init__(self, node): |
645 self.left_interface = node.GetName() | 645 self.left_interface = node.GetName() |
646 self.right_interface = node.GetProperty('REFERENCE') | 646 self.right_interface = node.GetProperty('REFERENCE') |
647 | 647 |
648 | 648 |
649 ################################################################################ | 649 ################################################################################ |
650 # Extended attributes | 650 # Extended attributes |
651 ################################################################################ | 651 ################################################################################ |
652 | 652 |
| 653 class Exposure: |
| 654 """An Exposure holds one Exposed or RuntimeEnabled condition. |
| 655 Each exposure has two properties: exposed and runtime_enabled. |
| 656 Exposure(e, r) corresponds to [Exposed(e r)]. Exposure(e) corresponds to |
| 657 [Exposed=e]. |
| 658 """ |
| 659 def __init__(self, exposed, runtime_enabled=None): |
| 660 self.exposed = exposed |
| 661 self.runtime_enabled = runtime_enabled |
| 662 |
| 663 |
653 def ext_attributes_node_to_extended_attributes(idl_name, node): | 664 def ext_attributes_node_to_extended_attributes(idl_name, node): |
654 """ | 665 """ |
655 Returns: | 666 Returns: |
656 Dictionary of {ExtAttributeName: ExtAttributeValue}. | 667 Dictionary of {ExtAttributeName: ExtAttributeValue}. |
657 Value is usually a string, with these exceptions: | 668 Value is usually a string, with these exceptions: |
658 Constructors: value is a list of Arguments nodes, corresponding to | 669 Constructors: value is a list of Arguments nodes, corresponding to |
659 possible signatures of the constructor. | 670 possible signatures of the constructor. |
660 CustomConstructors: value is a list of Arguments nodes, corresponding to | 671 CustomConstructors: value is a list of Arguments nodes, corresponding to |
661 possible signatures of the custom constructor. | 672 possible signatures of the custom constructor. |
662 NamedConstructor: value is a Call node, corresponding to the single | 673 NamedConstructor: value is a Call node, corresponding to the single |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
699 elif name == 'NamedConstructor': | 710 elif name == 'NamedConstructor': |
700 if child_class and child_class != 'Call': | 711 if child_class and child_class != 'Call': |
701 raise ValueError('[NamedConstructor] only supports Call as child
, but has child of class: %s' % child_class) | 712 raise ValueError('[NamedConstructor] only supports Call as child
, but has child of class: %s' % child_class) |
702 extended_attributes[name] = child | 713 extended_attributes[name] = child |
703 elif name == 'SetWrapperReferenceTo': | 714 elif name == 'SetWrapperReferenceTo': |
704 if not child: | 715 if not child: |
705 raise ValueError('[SetWrapperReferenceTo] requires a child, but
has none.') | 716 raise ValueError('[SetWrapperReferenceTo] requires a child, but
has none.') |
706 if child_class != 'Arguments': | 717 if child_class != 'Arguments': |
707 raise ValueError('[SetWrapperReferenceTo] only supports Argument
s as child, but has child of class: %s' % child_class) | 718 raise ValueError('[SetWrapperReferenceTo] only supports Argument
s as child, but has child of class: %s' % child_class) |
708 extended_attributes[name] = arguments_node_to_arguments(idl_name, ch
ild) | 719 extended_attributes[name] = arguments_node_to_arguments(idl_name, ch
ild) |
| 720 elif name == 'Exposed': |
| 721 if child_class and child_class != 'Arguments': |
| 722 raise ValueError('[Exposed] only supports Arguments as child, bu
t has child of class: %s' % child_class) |
| 723 exposures = [] |
| 724 if child_class == 'Arguments': |
| 725 exposures = [Exposure(exposed=str(arg.idl_type), |
| 726 runtime_enabled=arg.name) |
| 727 for arg in arguments_node_to_arguments('*', child)] |
| 728 else: |
| 729 value = extended_attribute_node.GetProperty('VALUE') |
| 730 if type(value) is str: |
| 731 exposures = [Exposure(exposed=value)] |
| 732 else: |
| 733 exposures = [Exposure(exposed=v) for v in value] |
| 734 extended_attributes[name] = exposures |
709 elif child: | 735 elif child: |
710 raise ValueError('ExtAttributes node with unexpected children: %s' %
name) | 736 raise ValueError('ExtAttributes node with unexpected children: %s' %
name) |
711 else: | 737 else: |
712 value = extended_attribute_node.GetProperty('VALUE') | 738 value = extended_attribute_node.GetProperty('VALUE') |
713 extended_attributes[name] = value | 739 extended_attributes[name] = value |
714 | 740 |
715 # Store constructors and custom constructors in special list attributes, | 741 # Store constructors and custom constructors in special list attributes, |
716 # which are deleted later. Note plural in key. | 742 # which are deleted later. Note plural in key. |
717 if constructors: | 743 if constructors: |
718 extended_attributes['Constructors'] = constructors | 744 extended_attributes['Constructors'] = constructors |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
834 child_class = child.GetClass() | 860 child_class = child.GetClass() |
835 if child_class != 'Type': | 861 if child_class != 'Type': |
836 raise ValueError('Unrecognized node class: %s' % child_class) | 862 raise ValueError('Unrecognized node class: %s' % child_class) |
837 return type_node_to_type(child) | 863 return type_node_to_type(child) |
838 | 864 |
839 | 865 |
840 def union_type_node_to_idl_union_type(node): | 866 def union_type_node_to_idl_union_type(node): |
841 member_types = [type_node_to_type(member_type_node) | 867 member_types = [type_node_to_type(member_type_node) |
842 for member_type_node in node.GetChildren()] | 868 for member_type_node in node.GetChildren()] |
843 return IdlUnionType(member_types) | 869 return IdlUnionType(member_types) |
OLD | NEW |