Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(155)

Side by Side Diff: Source/bindings/scripts/idl_definitions.py

Issue 670663002: IDL: Use IdlReader to compute interface_info_individual (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 IdlConstant < TypedObject 50 IdlConstant < TypedObject
51 IdlLiteral 51 IdlLiteral
52 IdlOperation < TypedObject 52 IdlOperation < TypedObject
53 IdlArgument < TypedObject 53 IdlArgument < TypedObject
54 IdlStringifier 54 IdlStringifier
55 IdlException < IdlInterface 55 IdlException < IdlInterface
56 (same contents as IdlInterface) 56 (same contents as IdlInterface)
57 57
58 TypedObject :: mixin for typedef resolution 58 TypedObject :: mixin for typedef resolution
59 59
60 IdlArgument is 'picklable', as it is stored in interfaces_info.
61
60 Design doc: http://www.chromium.org/developers/design-documents/idl-compiler 62 Design doc: http://www.chromium.org/developers/design-documents/idl-compiler
61 """ 63 """
62 64
63 import abc 65 import abc
64 66
65 from idl_types import IdlType, IdlUnionType, IdlArrayType, IdlSequenceType, IdlN ullableType 67 from idl_types import IdlType, IdlUnionType, IdlArrayType, IdlSequenceType, IdlN ullableType
66 68
67 SPECIAL_KEYWORD_LIST = ['GETTER', 'SETTER', 'DELETER'] 69 SPECIAL_KEYWORD_LIST = ['GETTER', 'SETTER', 'DELETER']
68 STANDARD_TYPEDEFS = { 70 STANDARD_TYPEDEFS = {
69 # http://www.w3.org/TR/WebIDL/#common-DOMTimeStamp 71 # http://www.w3.org/TR/WebIDL/#common-DOMTimeStamp
(...skipping 28 matching lines...) Expand all
98 ################################################################################ 100 ################################################################################
99 # Definitions (main container class) 101 # Definitions (main container class)
100 ################################################################################ 102 ################################################################################
101 103
102 class IdlDefinitions(object): 104 class IdlDefinitions(object):
103 def __init__(self, idl_name, node): 105 def __init__(self, idl_name, node):
104 """Args: node: AST root node, class == 'File'""" 106 """Args: node: AST root node, class == 'File'"""
105 self.callback_functions = {} 107 self.callback_functions = {}
106 self.dictionaries = {} 108 self.dictionaries = {}
107 self.enumerations = {} 109 self.enumerations = {}
110 self.implements = []
108 self.interfaces = {} 111 self.interfaces = {}
109 self.idl_name = idl_name 112 self.idl_name = idl_name
110 113
111 node_class = node.GetClass() 114 node_class = node.GetClass()
112 if node_class != 'File': 115 if node_class != 'File':
113 raise ValueError('Unrecognized node class: %s' % node_class) 116 raise ValueError('Unrecognized node class: %s' % node_class)
114 117
115 typedefs = dict((typedef_name, IdlType(type_name)) 118 typedefs = dict((typedef_name, IdlType(type_name))
116 for typedef_name, type_name in 119 for typedef_name, type_name in
117 STANDARD_TYPEDEFS.iteritems()) 120 STANDARD_TYPEDEFS.iteritems())
(...skipping 11 matching lines...) Expand all
129 elif child_class == 'Typedef': 132 elif child_class == 'Typedef':
130 type_name = child.GetName() 133 type_name = child.GetName()
131 typedefs[type_name] = typedef_node_to_type(child) 134 typedefs[type_name] = typedef_node_to_type(child)
132 elif child_class == 'Enum': 135 elif child_class == 'Enum':
133 enumeration = IdlEnum(idl_name, child) 136 enumeration = IdlEnum(idl_name, child)
134 self.enumerations[enumeration.name] = enumeration 137 self.enumerations[enumeration.name] = enumeration
135 elif child_class == 'Callback': 138 elif child_class == 'Callback':
136 callback_function = IdlCallbackFunction(idl_name, child) 139 callback_function = IdlCallbackFunction(idl_name, child)
137 self.callback_functions[callback_function.name] = callback_funct ion 140 self.callback_functions[callback_function.name] = callback_funct ion
138 elif child_class == 'Implements': 141 elif child_class == 'Implements':
139 # Implements is handled at the interface merging step 142 self.implements.append(IdlImplement(child))
140 pass
141 elif child_class == 'Dictionary': 143 elif child_class == 'Dictionary':
142 dictionary = IdlDictionary(idl_name, child) 144 dictionary = IdlDictionary(idl_name, child)
143 self.dictionaries[dictionary.name] = dictionary 145 self.dictionaries[dictionary.name] = dictionary
144 else: 146 else:
145 raise ValueError('Unrecognized node class: %s' % child_class) 147 raise ValueError('Unrecognized node class: %s' % child_class)
146 148
147 # Typedefs are not stored in IR: 149 # Typedefs are not stored in IR:
148 # Resolve typedefs with the actual types and then discard the Typedefs. 150 # Resolve typedefs with the actual types and then discard the Typedefs.
149 # http://www.w3.org/TR/WebIDL/#idl-typedefs 151 # http://www.w3.org/TR/WebIDL/#idl-typedefs
150 self.resolve_typedefs(typedefs) 152 self.resolve_typedefs(typedefs)
(...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after
581 elif child_class == 'Argument': 583 elif child_class == 'Argument':
582 child_name = child.GetName() 584 child_name = child.GetName()
583 if child_name != '...': 585 if child_name != '...':
584 raise ValueError('Unrecognized Argument node; expected "..." , got "%s"' % child_name) 586 raise ValueError('Unrecognized Argument node; expected "..." , got "%s"' % child_name)
585 self.is_variadic = child.GetProperty('ELLIPSIS') or False 587 self.is_variadic = child.GetProperty('ELLIPSIS') or False
586 elif child_class == 'Default': 588 elif child_class == 'Default':
587 self.default_value = default_node_to_idl_literal(child) 589 self.default_value = default_node_to_idl_literal(child)
588 else: 590 else:
589 raise ValueError('Unrecognized node class: %s' % child_class) 591 raise ValueError('Unrecognized node class: %s' % child_class)
590 592
593 def __getstate__(self):
594 # FIXME: Return a picklable object which has enough information to
595 # unpickle.
596 return {}
597
598 def __setstate__(self, state):
599 pass
600
591 601
592 def arguments_node_to_arguments(idl_name, node): 602 def arguments_node_to_arguments(idl_name, node):
593 # [Constructor] and [CustomConstructor] without arguments (the bare form) 603 # [Constructor] and [CustomConstructor] without arguments (the bare form)
594 # have None instead of an arguments node, but have the same meaning as using 604 # have None instead of an arguments node, but have the same meaning as using
595 # an empty argument list, [Constructor()], so special-case this. 605 # an empty argument list, [Constructor()], so special-case this.
596 # http://www.w3.org/TR/WebIDL/#Constructor 606 # http://www.w3.org/TR/WebIDL/#Constructor
597 if node is None: 607 if node is None:
598 return [] 608 return []
599 return [IdlArgument(idl_name, argument_node) 609 return [IdlArgument(idl_name, argument_node)
600 for argument_node in node.GetChildren()] 610 for argument_node in node.GetChildren()]
(...skipping 24 matching lines...) Expand all
625 raise ValueError('Unrecognized node class: %s' % child_class) 635 raise ValueError('Unrecognized node class: %s' % child_class)
626 636
627 # Copy the stringifier's extended attributes (such as [Unforgable]) onto 637 # Copy the stringifier's extended attributes (such as [Unforgable]) onto
628 # the underlying attribute or operation, if there is one. 638 # the underlying attribute or operation, if there is one.
629 if self.attribute or self.operation: 639 if self.attribute or self.operation:
630 (self.attribute or self.operation).extended_attributes.update( 640 (self.attribute or self.operation).extended_attributes.update(
631 self.extended_attributes) 641 self.extended_attributes)
632 642
633 643
634 ################################################################################ 644 ################################################################################
645 # Implement statements
646 ################################################################################
647
648 class IdlImplement(object):
649 def __init__(self, node):
650 self.left_interface = node.GetName()
651 self.right_interface = node.GetProperty('REFERENCE')
652
653
654 ################################################################################
635 # Extended attributes 655 # Extended attributes
636 ################################################################################ 656 ################################################################################
637 657
638 def ext_attributes_node_to_extended_attributes(idl_name, node): 658 def ext_attributes_node_to_extended_attributes(idl_name, node):
639 """ 659 """
640 Returns: 660 Returns:
641 Dictionary of {ExtAttributeName: ExtAttributeValue}. 661 Dictionary of {ExtAttributeName: ExtAttributeValue}.
642 Value is usually a string, with these exceptions: 662 Value is usually a string, with these exceptions:
643 Constructors: value is a list of Arguments nodes, corresponding to 663 Constructors: value is a list of Arguments nodes, corresponding to
644 possible signatures of the constructor. 664 possible signatures of the constructor.
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
819 child_class = child.GetClass() 839 child_class = child.GetClass()
820 if child_class != 'Type': 840 if child_class != 'Type':
821 raise ValueError('Unrecognized node class: %s' % child_class) 841 raise ValueError('Unrecognized node class: %s' % child_class)
822 return type_node_to_type(child) 842 return type_node_to_type(child)
823 843
824 844
825 def union_type_node_to_idl_union_type(node): 845 def union_type_node_to_idl_union_type(node):
826 member_types = [type_node_to_type(member_type_node) 846 member_types = [type_node_to_type(member_type_node)
827 for member_type_node in node.GetChildren()] 847 for member_type_node in node.GetChildren()]
828 return IdlUnionType(member_types) 848 return IdlUnionType(member_types)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698