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

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

Issue 735983002: IDL: Defer typedef resolution (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 1 month 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
« no previous file with comments | « Source/bindings/scripts/idl_compiler.py ('k') | Source/bindings/scripts/scripts.gni » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 13 matching lines...) Expand all
24 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 28
29 """Blink IDL Intermediate Representation (IR) classes. 29 """Blink IDL Intermediate Representation (IR) classes.
30 30
31 Classes are primarily constructors, which build an IdlDefinitions object 31 Classes are primarily constructors, which build an IdlDefinitions object
32 (and various contained objects) from an AST (produced by blink_idl_parser). 32 (and various contained objects) from an AST (produced by blink_idl_parser).
33 33
34 This is in two steps: 34 IR stores typedefs and they are resolved by the code generator.
35 * Constructors walk the AST, creating objects.
36 * Typedef resolution.
37
38 Typedefs are all resolved here, and not stored in IR.
39 35
40 Typedef resolution uses some auxiliary classes and OOP techniques to make this 36 Typedef resolution uses some auxiliary classes and OOP techniques to make this
41 a generic call, via the resolve_typedefs() method. 37 a generic call, via the resolve_typedefs() method.
42 38
43 Class hierarchy (mostly containment, '<' for inheritance): 39 Class hierarchy (mostly containment, '<' for inheritance):
44 40
45 IdlDefinitions 41 IdlDefinitions
46 IdlCallbackFunction < TypedObject 42 IdlCallbackFunction < TypedObject
47 IdlEnum :: FIXME: remove, just use a dict for enums 43 IdlEnum :: FIXME: remove, just use a dict for enums
48 IdlInterface 44 IdlInterface
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 99
104 class IdlDefinitions(object): 100 class IdlDefinitions(object):
105 def __init__(self, idl_name, node): 101 def __init__(self, idl_name, node):
106 """Args: node: AST root node, class == 'File'""" 102 """Args: node: AST root node, class == 'File'"""
107 self.callback_functions = {} 103 self.callback_functions = {}
108 self.dictionaries = {} 104 self.dictionaries = {}
109 self.enumerations = {} 105 self.enumerations = {}
110 self.implements = [] 106 self.implements = []
111 self.interfaces = {} 107 self.interfaces = {}
112 self.idl_name = idl_name 108 self.idl_name = idl_name
109 self.typedefs = {}
113 110
114 node_class = node.GetClass() 111 node_class = node.GetClass()
115 if node_class != 'File': 112 if node_class != 'File':
116 raise ValueError('Unrecognized node class: %s' % node_class) 113 raise ValueError('Unrecognized node class: %s' % node_class)
117 114
118 typedefs = dict((typedef_name, IdlType(type_name))
119 for typedef_name, type_name in
120 STANDARD_TYPEDEFS.iteritems())
121
122 children = node.GetChildren() 115 children = node.GetChildren()
123 for child in children: 116 for child in children:
124 child_class = child.GetClass() 117 child_class = child.GetClass()
125 if child_class == 'Interface': 118 if child_class == 'Interface':
126 interface = IdlInterface(idl_name, child) 119 interface = IdlInterface(idl_name, child)
127 self.interfaces[interface.name] = interface 120 self.interfaces[interface.name] = interface
128 elif child_class == 'Exception': 121 elif child_class == 'Exception':
129 exception = IdlException(idl_name, child) 122 exception = IdlException(idl_name, child)
130 # For simplicity, treat exceptions as interfaces 123 # For simplicity, treat exceptions as interfaces
131 self.interfaces[exception.name] = exception 124 self.interfaces[exception.name] = exception
132 elif child_class == 'Typedef': 125 elif child_class == 'Typedef':
133 type_name = child.GetName() 126 type_name = child.GetName()
134 typedefs[type_name] = typedef_node_to_type(child) 127 self.typedefs[type_name] = typedef_node_to_type(child)
135 elif child_class == 'Enum': 128 elif child_class == 'Enum':
136 enumeration = IdlEnum(idl_name, child) 129 enumeration = IdlEnum(idl_name, child)
137 self.enumerations[enumeration.name] = enumeration 130 self.enumerations[enumeration.name] = enumeration
138 elif child_class == 'Callback': 131 elif child_class == 'Callback':
139 callback_function = IdlCallbackFunction(idl_name, child) 132 callback_function = IdlCallbackFunction(idl_name, child)
140 self.callback_functions[callback_function.name] = callback_funct ion 133 self.callback_functions[callback_function.name] = callback_funct ion
141 elif child_class == 'Implements': 134 elif child_class == 'Implements':
142 self.implements.append(IdlImplement(child)) 135 self.implements.append(IdlImplement(child))
143 elif child_class == 'Dictionary': 136 elif child_class == 'Dictionary':
144 dictionary = IdlDictionary(idl_name, child) 137 dictionary = IdlDictionary(idl_name, child)
145 self.dictionaries[dictionary.name] = dictionary 138 self.dictionaries[dictionary.name] = dictionary
146 else: 139 else:
147 raise ValueError('Unrecognized node class: %s' % child_class) 140 raise ValueError('Unrecognized node class: %s' % child_class)
148 141
149 # Typedefs are not stored in IR: 142 def resolve_typedefs(self, typedefs):
150 # Resolve typedefs with the actual types and then discard the Typedefs. 143 # Resolve typedefs with the actual types.
151 # http://www.w3.org/TR/WebIDL/#idl-typedefs 144 # http://www.w3.org/TR/WebIDL/#idl-typedefs
152 self.resolve_typedefs(typedefs) 145 typedefs.update(dict((typedef_name, IdlType(type_name))
153 146 for typedef_name, type_name in
154 def resolve_typedefs(self, typedefs): 147 STANDARD_TYPEDEFS.iteritems()))
155 for callback_function in self.callback_functions.itervalues(): 148 for callback_function in self.callback_functions.itervalues():
156 callback_function.resolve_typedefs(typedefs) 149 callback_function.resolve_typedefs(typedefs)
157 for interface in self.interfaces.itervalues(): 150 for interface in self.interfaces.itervalues():
158 interface.resolve_typedefs(typedefs) 151 interface.resolve_typedefs(typedefs)
159 152
160 def update(self, other): 153 def update(self, other):
161 """Update with additional IdlDefinitions.""" 154 """Update with additional IdlDefinitions."""
162 for interface_name, new_interface in other.interfaces.iteritems(): 155 for interface_name, new_interface in other.interfaces.iteritems():
163 if not new_interface.is_partial: 156 if not new_interface.is_partial:
164 # Add as new interface 157 # Add as new interface
(...skipping 676 matching lines...) Expand 10 before | Expand all | Expand 10 after
841 child_class = child.GetClass() 834 child_class = child.GetClass()
842 if child_class != 'Type': 835 if child_class != 'Type':
843 raise ValueError('Unrecognized node class: %s' % child_class) 836 raise ValueError('Unrecognized node class: %s' % child_class)
844 return type_node_to_type(child) 837 return type_node_to_type(child)
845 838
846 839
847 def union_type_node_to_idl_union_type(node): 840 def union_type_node_to_idl_union_type(node):
848 member_types = [type_node_to_type(member_type_node) 841 member_types = [type_node_to_type(member_type_node)
849 for member_type_node in node.GetChildren()] 842 for member_type_node in node.GetChildren()]
850 return IdlUnionType(member_types) 843 return IdlUnionType(member_types)
OLDNEW
« no previous file with comments | « Source/bindings/scripts/idl_compiler.py ('k') | Source/bindings/scripts/scripts.gni » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698