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

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

Issue 581453002: Dartium Roll 38 roll (Closed) Base URL: https://dart.googlecode.com/svn/third_party/WebCore
Patch Set: Sync'd w/ r 182210 Created 6 years, 3 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 | Annotate | Revision Log
« no previous file with comments | « bindings/scripts/idl_compiler.py ('k') | bindings/scripts/idl_reader.py » ('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 30 matching lines...) Expand all
41 a generic call, via the resolve_typedefs() method. 41 a generic call, via the resolve_typedefs() method.
42 42
43 Class hierarchy (mostly containment, '<' for inheritance): 43 Class hierarchy (mostly containment, '<' for inheritance):
44 44
45 IdlDefinitions 45 IdlDefinitions
46 IdlCallbackFunction < TypedObject 46 IdlCallbackFunction < TypedObject
47 IdlEnum :: FIXME: remove, just use a dict for enums 47 IdlEnum :: FIXME: remove, just use a dict for enums
48 IdlInterface 48 IdlInterface
49 IdlAttribute < TypedObject 49 IdlAttribute < TypedObject
50 IdlConstant < TypedObject 50 IdlConstant < TypedObject
51 IdlLiteral
51 IdlOperation < TypedObject 52 IdlOperation < TypedObject
52 IdlArgument < TypedObject 53 IdlArgument < TypedObject
54 IdlStringifier
53 IdlException < IdlInterface 55 IdlException < IdlInterface
54 (same contents as IdlInterface) 56 (same contents as IdlInterface)
55 57
56 TypedObject :: mixin for typedef resolution 58 TypedObject :: mixin for typedef resolution
57 59
58 Design doc: http://www.chromium.org/developers/design-documents/idl-compiler 60 Design doc: http://www.chromium.org/developers/design-documents/idl-compiler
59 """ 61 """
60 62
61 import abc 63 import abc
62 64
63 from idl_types import IdlType, IdlUnionType 65 from idl_types import IdlType, IdlUnionType, IdlArrayType, IdlSequenceType
64 66
65 SPECIAL_KEYWORD_LIST = ['GETTER', 'SETTER', 'DELETER'] 67 SPECIAL_KEYWORD_LIST = ['GETTER', 'SETTER', 'DELETER']
66 STANDARD_TYPEDEFS = { 68 STANDARD_TYPEDEFS = {
67 # http://www.w3.org/TR/WebIDL/#common-DOMTimeStamp 69 # http://www.w3.org/TR/WebIDL/#common-DOMTimeStamp
68 'DOMTimeStamp': 'unsigned long long', 70 'DOMTimeStamp': 'unsigned long long',
69 } 71 }
70 72
71 73
72 ################################################################################ 74 ################################################################################
73 # TypedObject (mixin for typedef resolution) 75 # TypedObject (mixin for typedef resolution)
(...skipping 17 matching lines...) Expand all
91 # Need to re-assign self.idl_type, not just mutate idl_type, 93 # Need to re-assign self.idl_type, not just mutate idl_type,
92 # since type(idl_type) may change. 94 # since type(idl_type) may change.
93 self.idl_type = self.idl_type.resolve_typedefs(typedefs) 95 self.idl_type = self.idl_type.resolve_typedefs(typedefs)
94 96
95 97
96 ################################################################################ 98 ################################################################################
97 # Definitions (main container class) 99 # Definitions (main container class)
98 ################################################################################ 100 ################################################################################
99 101
100 class IdlDefinitions(object): 102 class IdlDefinitions(object):
101 def __init__(self, node): 103 def __init__(self, idl_name, node):
102 """Args: node: AST root node, class == 'File'""" 104 """Args: node: AST root node, class == 'File'"""
103 self.callback_functions = {} 105 self.callback_functions = {}
104 self.dictionaries = {} 106 self.dictionaries = {}
105 self.enumerations = {} 107 self.enumerations = {}
106 self.interfaces = {} 108 self.interfaces = {}
109 self.idl_name = idl_name
107 110
108 node_class = node.GetClass() 111 node_class = node.GetClass()
109 if node_class != 'File': 112 if node_class != 'File':
110 raise ValueError('Unrecognized node class: %s' % node_class) 113 raise ValueError('Unrecognized node class: %s' % node_class)
111 114
112 typedefs = dict((typedef_name, IdlType(type_name)) 115 typedefs = dict((typedef_name, IdlType(type_name))
113 for typedef_name, type_name in 116 for typedef_name, type_name in
114 STANDARD_TYPEDEFS.iteritems()) 117 STANDARD_TYPEDEFS.iteritems())
115 118
116 children = node.GetChildren() 119 children = node.GetChildren()
117 for child in children: 120 for child in children:
118 child_class = child.GetClass() 121 child_class = child.GetClass()
119 if child_class == 'Interface': 122 if child_class == 'Interface':
120 interface = IdlInterface(child) 123 interface = IdlInterface(idl_name, child)
121 self.interfaces[interface.name] = interface 124 self.interfaces[interface.name] = interface
122 elif child_class == 'Exception': 125 elif child_class == 'Exception':
123 exception = IdlException(child) 126 exception = IdlException(idl_name, child)
124 # For simplicity, treat exceptions as interfaces 127 # For simplicity, treat exceptions as interfaces
125 self.interfaces[exception.name] = exception 128 self.interfaces[exception.name] = exception
126 elif child_class == 'Typedef': 129 elif child_class == 'Typedef':
127 type_name = child.GetName() 130 type_name = child.GetName()
128 typedefs[type_name] = typedef_node_to_type(child) 131 typedefs[type_name] = typedef_node_to_type(child)
129 elif child_class == 'Enum': 132 elif child_class == 'Enum':
130 enumeration = IdlEnum(child) 133 enumeration = IdlEnum(idl_name, child)
131 self.enumerations[enumeration.name] = enumeration 134 self.enumerations[enumeration.name] = enumeration
132 elif child_class == 'Callback': 135 elif child_class == 'Callback':
133 callback_function = IdlCallbackFunction(child) 136 callback_function = IdlCallbackFunction(idl_name, child)
134 self.callback_functions[callback_function.name] = callback_funct ion 137 self.callback_functions[callback_function.name] = callback_funct ion
135 elif child_class == 'Implements': 138 elif child_class == 'Implements':
136 # Implements is handled at the interface merging step 139 # Implements is handled at the interface merging step
137 pass 140 pass
138 elif child_class == 'Dictionary': 141 elif child_class == 'Dictionary':
139 dictionary = IdlDictionary(child) 142 dictionary = IdlDictionary(idl_name, child)
140 self.dictionaries[dictionary.name] = dictionary 143 self.dictionaries[dictionary.name] = dictionary
141 else: 144 else:
142 raise ValueError('Unrecognized node class: %s' % child_class) 145 raise ValueError('Unrecognized node class: %s' % child_class)
143 146
144 # Typedefs are not stored in IR: 147 # Typedefs are not stored in IR:
145 # Resolve typedefs with the actual types and then discard the Typedefs. 148 # Resolve typedefs with the actual types and then discard the Typedefs.
146 # http://www.w3.org/TR/WebIDL/#idl-typedefs 149 # http://www.w3.org/TR/WebIDL/#idl-typedefs
147 self.resolve_typedefs(typedefs) 150 self.resolve_typedefs(typedefs)
148 151
149 def resolve_typedefs(self, typedefs): 152 def resolve_typedefs(self, typedefs):
(...skipping 21 matching lines...) Expand all
171 # Merge callbacks and enumerations 174 # Merge callbacks and enumerations
172 self.enumerations.update(other.enumerations) 175 self.enumerations.update(other.enumerations)
173 self.callback_functions.update(other.callback_functions) 176 self.callback_functions.update(other.callback_functions)
174 177
175 178
176 ################################################################################ 179 ################################################################################
177 # Callback Functions 180 # Callback Functions
178 ################################################################################ 181 ################################################################################
179 182
180 class IdlCallbackFunction(TypedObject): 183 class IdlCallbackFunction(TypedObject):
181 def __init__(self, node): 184 def __init__(self, idl_name, node):
182 children = node.GetChildren() 185 children = node.GetChildren()
183 num_children = len(children) 186 num_children = len(children)
184 if num_children != 2: 187 if num_children != 2:
185 raise ValueError('Expected 2 children, got %s' % num_children) 188 raise ValueError('Expected 2 children, got %s' % num_children)
186 type_node, arguments_node = children 189 type_node, arguments_node = children
187 arguments_node_class = arguments_node.GetClass() 190 arguments_node_class = arguments_node.GetClass()
188 if arguments_node_class != 'Arguments': 191 if arguments_node_class != 'Arguments':
189 raise ValueError('Expected Arguments node, got %s' % arguments_node_ class) 192 raise ValueError('Expected Arguments node, got %s' % arguments_node_ class)
190 193
194 self.idl_name = idl_name
191 self.name = node.GetName() 195 self.name = node.GetName()
192 self.idl_type = type_node_to_type(type_node) 196 self.idl_type = type_node_to_type(type_node)
193 self.arguments = arguments_node_to_arguments(arguments_node) 197 self.arguments = arguments_node_to_arguments(idl_name, arguments_node)
194 198
195 def resolve_typedefs(self, typedefs): 199 def resolve_typedefs(self, typedefs):
196 TypedObject.resolve_typedefs(self, typedefs) 200 TypedObject.resolve_typedefs(self, typedefs)
197 for argument in self.arguments: 201 for argument in self.arguments:
198 argument.resolve_typedefs(typedefs) 202 argument.resolve_typedefs(typedefs)
199 203
200 204
201 ################################################################################ 205 ################################################################################
202 # Dictionary 206 # Dictionary
203 ################################################################################ 207 ################################################################################
204 208
205 class IdlDictionary(object): 209 class IdlDictionary(object):
206 def __init__(self, node): 210 def __init__(self, idl_name, node):
207 self.parent = None 211 self.extended_attributes = {}
212 self.is_partial = node.GetProperty('Partial') or False
213 self.idl_name = idl_name
208 self.name = node.GetName() 214 self.name = node.GetName()
209 self.members = [] 215 self.members = []
216 self.parent = None
210 for child in node.GetChildren(): 217 for child in node.GetChildren():
211 child_class = child.GetClass() 218 child_class = child.GetClass()
212 if child_class == 'Inherit': 219 if child_class == 'Inherit':
213 self.parent = child.GetName() 220 self.parent = child.GetName()
214 elif child_class == 'Key': 221 elif child_class == 'Key':
215 self.members.append(IdlDictionaryMember(child)) 222 self.members.append(IdlDictionaryMember(idl_name, child))
223 elif child_class == 'ExtAttributes':
224 self.extended_attributes = (
225 ext_attributes_node_to_extended_attributes(idl_name, child))
216 else: 226 else:
217 raise ValueError('Unrecognized node class: %s' % child_class) 227 raise ValueError('Unrecognized node class: %s' % child_class)
218 228
219 229
220 class IdlDictionaryMember(object): 230 class IdlDictionaryMember(object):
221 def __init__(self, node): 231 def __init__(self, idl_name, node):
222 self.default_value = None 232 self.default_value = None
223 self.extended_attributes = {} 233 self.extended_attributes = {}
224 self.idl_type = None 234 self.idl_type = None
235 self.idl_name = idl_name
225 self.name = node.GetName() 236 self.name = node.GetName()
226 for child in node.GetChildren(): 237 for child in node.GetChildren():
227 child_class = child.GetClass() 238 child_class = child.GetClass()
228 if child_class == 'Type': 239 if child_class == 'Type':
229 self.idl_type = type_node_to_type(child) 240 self.idl_type = type_node_to_type(child)
230 elif child_class == 'Default': 241 elif child_class == 'Default':
231 self.default_value = child.GetProperty('VALUE') 242 self.default_value = default_node_to_idl_literal(child)
232 elif child_class == 'ExtAttributes': 243 elif child_class == 'ExtAttributes':
233 self.extended_attributes = ext_attributes_node_to_extended_attri butes(child) 244 self.extended_attributes = (
245 ext_attributes_node_to_extended_attributes(idl_name, child))
234 else: 246 else:
235 raise ValueError('Unrecognized node class: %s' % child_class) 247 raise ValueError('Unrecognized node class: %s' % child_class)
236 248
237 249
238 ################################################################################ 250 ################################################################################
239 # Enumerations 251 # Enumerations
240 ################################################################################ 252 ################################################################################
241 253
242 class IdlEnum(object): 254 class IdlEnum(object):
243 # FIXME: remove, just treat enums as a dictionary 255 # FIXME: remove, just treat enums as a dictionary
244 def __init__(self, node): 256 def __init__(self, idl_name, node):
257 self.idl_name = idl_name
245 self.name = node.GetName() 258 self.name = node.GetName()
246 self.values = [] 259 self.values = []
247 for child in node.GetChildren(): 260 for child in node.GetChildren():
248 self.values.append(child.GetName()) 261 self.values.append(child.GetName())
249 262
250 263
251 ################################################################################ 264 ################################################################################
252 # Interfaces and Exceptions 265 # Interfaces and Exceptions
253 ################################################################################ 266 ################################################################################
254 267
255 class IdlInterface(object): 268 class IdlInterface(object):
256 def __init__(self, node=None): 269 def __init__(self, idl_name, node=None):
257 self.attributes = [] 270 self.attributes = []
258 self.constants = [] 271 self.constants = []
259 self.constructors = [] 272 self.constructors = []
260 self.custom_constructors = [] 273 self.custom_constructors = []
261 self.extended_attributes = {} 274 self.extended_attributes = {}
262 self.operations = [] 275 self.operations = []
263 self.parent = None 276 self.parent = None
277 self.stringifier = None
264 if not node: # Early exit for IdlException.__init__ 278 if not node: # Early exit for IdlException.__init__
265 return 279 return
266 280
267 self.is_callback = node.GetProperty('CALLBACK') or False 281 self.is_callback = node.GetProperty('CALLBACK') or False
268 self.is_exception = False 282 self.is_exception = False
269 # FIXME: uppercase 'Partial' => 'PARTIAL' in base IDL parser 283 # FIXME: uppercase 'Partial' => 'PARTIAL' in base IDL parser
270 self.is_partial = node.GetProperty('Partial') or False 284 self.is_partial = node.GetProperty('Partial') or False
285 self.idl_name = idl_name
271 self.name = node.GetName() 286 self.name = node.GetName()
272 287
273 children = node.GetChildren() 288 children = node.GetChildren()
274 for child in children: 289 for child in children:
275 child_class = child.GetClass() 290 child_class = child.GetClass()
276 if child_class == 'Attribute': 291 if child_class == 'Attribute':
277 self.attributes.append(IdlAttribute(child)) 292 self.attributes.append(IdlAttribute(idl_name, child))
278 elif child_class == 'Const': 293 elif child_class == 'Const':
279 self.constants.append(IdlConstant(child)) 294 self.constants.append(IdlConstant(idl_name, child))
280 elif child_class == 'ExtAttributes': 295 elif child_class == 'ExtAttributes':
281 extended_attributes = ext_attributes_node_to_extended_attributes (child) 296 extended_attributes = ext_attributes_node_to_extended_attributes (idl_name, child)
282 self.constructors, self.custom_constructors = ( 297 self.constructors, self.custom_constructors = (
283 extended_attributes_to_constructors(extended_attributes)) 298 extended_attributes_to_constructors(idl_name, extended_attri butes))
284 clear_constructor_attributes(extended_attributes) 299 clear_constructor_attributes(extended_attributes)
285 self.extended_attributes = extended_attributes 300 self.extended_attributes = extended_attributes
286 elif child_class == 'Operation': 301 elif child_class == 'Operation':
287 self.operations.append(IdlOperation(child)) 302 self.operations.append(IdlOperation(idl_name, child))
288 elif child_class == 'Inherit': 303 elif child_class == 'Inherit':
289 self.parent = child.GetName() 304 self.parent = child.GetName()
305 elif child_class == 'Stringifier':
306 self.stringifier = IdlStringifier(idl_name, child)
307 self.process_stringifier()
290 else: 308 else:
291 raise ValueError('Unrecognized node class: %s' % child_class) 309 raise ValueError('Unrecognized node class: %s' % child_class)
292 310
293 def resolve_typedefs(self, typedefs): 311 def resolve_typedefs(self, typedefs):
294 for attribute in self.attributes: 312 for attribute in self.attributes:
295 attribute.resolve_typedefs(typedefs) 313 attribute.resolve_typedefs(typedefs)
296 for constant in self.constants: 314 for constant in self.constants:
297 constant.resolve_typedefs(typedefs) 315 constant.resolve_typedefs(typedefs)
298 for constructor in self.constructors: 316 for constructor in self.constructors:
299 constructor.resolve_typedefs(typedefs) 317 constructor.resolve_typedefs(typedefs)
300 for custom_constructor in self.custom_constructors: 318 for custom_constructor in self.custom_constructors:
301 custom_constructor.resolve_typedefs(typedefs) 319 custom_constructor.resolve_typedefs(typedefs)
302 for operation in self.operations: 320 for operation in self.operations:
303 operation.resolve_typedefs(typedefs) 321 operation.resolve_typedefs(typedefs)
304 322
323 def process_stringifier(self):
324 """Add the stringifier's attribute or named operation child, if it has
325 one, as a regular attribute/operation of this interface."""
326 if self.stringifier.attribute:
327 self.attributes.append(self.stringifier.attribute)
328 elif self.stringifier.operation:
329 self.operations.append(self.stringifier.operation)
330
305 def merge(self, other): 331 def merge(self, other):
306 """Merge in another interface's members (e.g., partial interface)""" 332 """Merge in another interface's members (e.g., partial interface)"""
307 self.attributes.extend(other.attributes) 333 self.attributes.extend(other.attributes)
308 self.constants.extend(other.constants) 334 self.constants.extend(other.constants)
309 self.operations.extend(other.operations) 335 self.operations.extend(other.operations)
310 336
311 337
312 class IdlException(IdlInterface): 338 class IdlException(IdlInterface):
313 # Properly exceptions and interfaces are distinct, and thus should inherit a 339 # Properly exceptions and interfaces are distinct, and thus should inherit a
314 # common base class (say, "IdlExceptionOrInterface"). 340 # common base class (say, "IdlExceptionOrInterface").
315 # However, there is only one exception (DOMException), and new exceptions 341 # However, there is only one exception (DOMException), and new exceptions
316 # are not expected. Thus it is easier to implement exceptions as a 342 # are not expected. Thus it is easier to implement exceptions as a
317 # restricted subclass of interfaces. 343 # restricted subclass of interfaces.
318 # http://www.w3.org/TR/WebIDL/#idl-exceptions 344 # http://www.w3.org/TR/WebIDL/#idl-exceptions
319 def __init__(self, node): 345 def __init__(self, idl_name, node):
320 # Exceptions are similar to Interfaces, but simpler 346 # Exceptions are similar to Interfaces, but simpler
321 IdlInterface.__init__(self) 347 IdlInterface.__init__(self, idl_name)
322 self.is_callback = False 348 self.is_callback = False
323 self.is_exception = True 349 self.is_exception = True
324 self.is_partial = False 350 self.is_partial = False
351 self.idl_name = idl_name
325 self.name = node.GetName() 352 self.name = node.GetName()
326 353
327 children = node.GetChildren() 354 children = node.GetChildren()
328 for child in children: 355 for child in children:
329 child_class = child.GetClass() 356 child_class = child.GetClass()
330 if child_class == 'Attribute': 357 if child_class == 'Attribute':
331 attribute = IdlAttribute(child) 358 attribute = IdlAttribute(idl_name, child)
332 self.attributes.append(attribute) 359 self.attributes.append(attribute)
333 elif child_class == 'Const': 360 elif child_class == 'Const':
334 self.constants.append(IdlConstant(child)) 361 self.constants.append(IdlConstant(idl_name, child))
335 elif child_class == 'ExtAttributes': 362 elif child_class == 'ExtAttributes':
336 self.extended_attributes = ext_attributes_node_to_extended_attri butes(child) 363 self.extended_attributes = ext_attributes_node_to_extended_attri butes(idl_name, child)
337 elif child_class == 'ExceptionOperation': 364 elif child_class == 'ExceptionOperation':
338 self.operations.append(IdlOperation.from_exception_operation_nod e(child)) 365 self.operations.append(IdlOperation.from_exception_operation_nod e(idl_name, child))
339 else: 366 else:
340 raise ValueError('Unrecognized node class: %s' % child_class) 367 raise ValueError('Unrecognized node class: %s' % child_class)
341 368
342 369
343 ################################################################################ 370 ################################################################################
344 # Attributes 371 # Attributes
345 ################################################################################ 372 ################################################################################
346 373
347 class IdlAttribute(TypedObject): 374 class IdlAttribute(TypedObject):
348 def __init__(self, node): 375 def __init__(self, idl_name, node):
349 self.is_read_only = node.GetProperty('READONLY') or False 376 self.is_read_only = node.GetProperty('READONLY') or False
350 self.is_static = node.GetProperty('STATIC') or False 377 self.is_static = node.GetProperty('STATIC') or False
378 self.idl_name = idl_name
351 self.name = node.GetName() 379 self.name = node.GetName()
352 # Defaults, overridden below 380 # Defaults, overridden below
353 self.idl_type = None 381 self.idl_type = None
354 self.extended_attributes = {} 382 self.extended_attributes = {}
355 383
356 children = node.GetChildren() 384 children = node.GetChildren()
357 for child in children: 385 for child in children:
358 child_class = child.GetClass() 386 child_class = child.GetClass()
359 if child_class == 'Type': 387 if child_class == 'Type':
360 self.idl_type = type_node_to_type(child) 388 self.idl_type = type_node_to_type(child)
361 elif child_class == 'ExtAttributes': 389 elif child_class == 'ExtAttributes':
362 self.extended_attributes = ext_attributes_node_to_extended_attri butes(child) 390 self.extended_attributes = ext_attributes_node_to_extended_attri butes(idl_name, child)
363 else: 391 else:
364 raise ValueError('Unrecognized node class: %s' % child_class) 392 raise ValueError('Unrecognized node class: %s' % child_class)
365 393
366 394
367 ################################################################################ 395 ################################################################################
368 # Constants 396 # Constants
369 ################################################################################ 397 ################################################################################
370 398
371 class IdlConstant(TypedObject): 399 class IdlConstant(TypedObject):
372 def __init__(self, node): 400 def __init__(self, idl_name, node):
373 children = node.GetChildren() 401 children = node.GetChildren()
374 num_children = len(children) 402 num_children = len(children)
375 if num_children < 2 or num_children > 3: 403 if num_children < 2 or num_children > 3:
376 raise ValueError('Expected 2 or 3 children, got %s' % num_children) 404 raise ValueError('Expected 2 or 3 children, got %s' % num_children)
377 type_node = children[0] 405 type_node = children[0]
378 value_node = children[1] 406 value_node = children[1]
379 value_node_class = value_node.GetClass() 407 value_node_class = value_node.GetClass()
380 if value_node_class != 'Value': 408 if value_node_class != 'Value':
381 raise ValueError('Expected Value node, got %s' % value_node_class) 409 raise ValueError('Expected Value node, got %s' % value_node_class)
382 410
411 self.idl_name = idl_name
383 self.name = node.GetName() 412 self.name = node.GetName()
384 # ConstType is more limited than Type, so subtree is smaller and 413 # ConstType is more limited than Type, so subtree is smaller and
385 # we don't use the full type_node_to_type function. 414 # we don't use the full type_node_to_type function.
386 self.idl_type = type_node_inner_to_type(type_node) 415 self.idl_type = type_node_inner_to_type(type_node)
387 self.value = value_node.GetName() 416 # FIXME: This code is unnecessarily complicated due to the rather
417 # inconsistent way the upstream IDL parser outputs default values.
418 # http://crbug.com/374178
419 if value_node.GetProperty('TYPE') == 'float':
420 self.value = value_node.GetProperty('VALUE')
421 else:
422 self.value = value_node.GetName()
388 423
389 if num_children == 3: 424 if num_children == 3:
390 ext_attributes_node = children[2] 425 ext_attributes_node = children[2]
391 self.extended_attributes = ext_attributes_node_to_extended_attribute s(ext_attributes_node) 426 self.extended_attributes = ext_attributes_node_to_extended_attribute s(idl_name, ext_attributes_node)
392 else: 427 else:
393 self.extended_attributes = {} 428 self.extended_attributes = {}
394 429
395 430
396 ################################################################################ 431 ################################################################################
397 # Literals 432 # Literals
398 ################################################################################ 433 ################################################################################
399 434
400 class IdlLiteral(object): 435 class IdlLiteral(object):
401 def __init__(self, idl_type, value): 436 def __init__(self, idl_type, value):
(...skipping 27 matching lines...) Expand all
429 # FIXME: This code is unnecessarily complicated due to the rather 464 # FIXME: This code is unnecessarily complicated due to the rather
430 # inconsistent way the upstream IDL parser outputs default values. 465 # inconsistent way the upstream IDL parser outputs default values.
431 # http://crbug.com/374178 466 # http://crbug.com/374178
432 idl_type = node.GetProperty('TYPE') 467 idl_type = node.GetProperty('TYPE')
433 if idl_type == 'DOMString': 468 if idl_type == 'DOMString':
434 value = node.GetProperty('NAME') 469 value = node.GetProperty('NAME')
435 if '"' in value or '\\' in value: 470 if '"' in value or '\\' in value:
436 raise ValueError('Unsupported string value: %r' % value) 471 raise ValueError('Unsupported string value: %r' % value)
437 return IdlLiteral(idl_type, value) 472 return IdlLiteral(idl_type, value)
438 if idl_type == 'integer': 473 if idl_type == 'integer':
439 return IdlLiteral(idl_type, int(node.GetProperty('NAME'))) 474 return IdlLiteral(idl_type, int(node.GetProperty('NAME'), base=0))
440 if idl_type == 'float': 475 if idl_type == 'float':
441 return IdlLiteral(idl_type, float(node.GetProperty('VALUE'))) 476 return IdlLiteral(idl_type, float(node.GetProperty('VALUE')))
442 if idl_type == 'boolean': 477 if idl_type == 'boolean':
443 return IdlLiteral(idl_type, node.GetProperty('VALUE')) 478 return IdlLiteral(idl_type, node.GetProperty('VALUE'))
444 if idl_type == 'NULL': 479 if idl_type == 'NULL':
445 return IdlLiteralNull() 480 return IdlLiteralNull()
446 raise ValueError('Unrecognized default value type: %s' % idl_type) 481 raise ValueError('Unrecognized default value type: %s' % idl_type)
447 482
448 483
449 ################################################################################ 484 ################################################################################
450 # Operations 485 # Operations
451 ################################################################################ 486 ################################################################################
452 487
453 class IdlOperation(TypedObject): 488 class IdlOperation(TypedObject):
454 def __init__(self, node=None): 489 def __init__(self, idl_name, node=None):
455 self.arguments = [] 490 self.arguments = []
456 self.extended_attributes = {} 491 self.extended_attributes = {}
457 self.specials = [] 492 self.specials = []
458 self.is_constructor = False 493 self.is_constructor = False
459 494
460 if not node: 495 if not node:
461 self.is_static = False 496 self.is_static = False
462 return 497 return
498 self.idl_name = idl_name
463 self.name = node.GetName() # FIXME: should just be: or '' 499 self.name = node.GetName() # FIXME: should just be: or ''
464 # FIXME: AST should use None internally 500 # FIXME: AST should use None internally
465 if self.name == '_unnamed_': 501 if self.name == '_unnamed_':
466 self.name = '' 502 self.name = ''
467 503
468 self.is_static = node.GetProperty('STATIC') or False 504 self.is_static = node.GetProperty('STATIC') or False
469 property_dictionary = node.GetProperties() 505 property_dictionary = node.GetProperties()
470 for special_keyword in SPECIAL_KEYWORD_LIST: 506 for special_keyword in SPECIAL_KEYWORD_LIST:
471 if special_keyword in property_dictionary: 507 if special_keyword in property_dictionary:
472 self.specials.append(special_keyword.lower()) 508 self.specials.append(special_keyword.lower())
473 509
474 self.idl_type = None 510 self.idl_type = None
475 children = node.GetChildren() 511 children = node.GetChildren()
476 for child in children: 512 for child in children:
477 child_class = child.GetClass() 513 child_class = child.GetClass()
478 if child_class == 'Arguments': 514 if child_class == 'Arguments':
479 self.arguments = arguments_node_to_arguments(child) 515 self.arguments = arguments_node_to_arguments(idl_name, child)
480 elif child_class == 'Type': 516 elif child_class == 'Type':
481 self.idl_type = type_node_to_type(child) 517 self.idl_type = type_node_to_type(child)
482 elif child_class == 'ExtAttributes': 518 elif child_class == 'ExtAttributes':
483 self.extended_attributes = ext_attributes_node_to_extended_attri butes(child) 519 self.extended_attributes = ext_attributes_node_to_extended_attri butes(idl_name, child)
484 else: 520 else:
485 raise ValueError('Unrecognized node class: %s' % child_class) 521 raise ValueError('Unrecognized node class: %s' % child_class)
486 522
487 @classmethod 523 @classmethod
488 def from_exception_operation_node(cls, node): 524 def from_exception_operation_node(cls, idl_name, node):
489 # Needed to handle one case in DOMException.idl: 525 # Needed to handle one case in DOMException.idl:
490 # // Override in a Mozilla compatible format 526 # // Override in a Mozilla compatible format
491 # [NotEnumerable] DOMString toString(); 527 # [NotEnumerable] DOMString toString();
492 # FIXME: can we remove this? replace with a stringifier? 528 # FIXME: can we remove this? replace with a stringifier?
493 operation = cls() 529 operation = cls(idl_name)
494 operation.name = node.GetName() 530 operation.name = node.GetName()
495 children = node.GetChildren() 531 children = node.GetChildren()
496 if len(children) < 1 or len(children) > 2: 532 if len(children) < 1 or len(children) > 2:
497 raise ValueError('ExceptionOperation node with %s children, expected 1 or 2' % len(children)) 533 raise ValueError('ExceptionOperation node with %s children, expected 1 or 2' % len(children))
498 534
499 type_node = children[0] 535 type_node = children[0]
500 operation.idl_type = type_node_to_type(type_node) 536 operation.idl_type = type_node_to_type(type_node)
501 537
502 if len(children) > 1: 538 if len(children) > 1:
503 ext_attributes_node = children[1] 539 ext_attributes_node = children[1]
504 operation.extended_attributes = ext_attributes_node_to_extended_attr ibutes(ext_attributes_node) 540 operation.extended_attributes = ext_attributes_node_to_extended_attr ibutes(idl_name, ext_attributes_node)
505 541
506 return operation 542 return operation
507 543
508 @classmethod 544 @classmethod
509 def constructor_from_arguments_node(cls, name, arguments_node): 545 def constructor_from_arguments_node(cls, name, idl_name, arguments_node):
510 constructor = cls() 546 constructor = cls(idl_name)
511 constructor.name = name 547 constructor.name = name
512 constructor.arguments = arguments_node_to_arguments(arguments_node) 548 constructor.arguments = arguments_node_to_arguments(idl_name, arguments_ node)
513 constructor.is_constructor = True 549 constructor.is_constructor = True
514 return constructor 550 return constructor
515 551
516 def resolve_typedefs(self, typedefs): 552 def resolve_typedefs(self, typedefs):
517 TypedObject.resolve_typedefs(self, typedefs) 553 TypedObject.resolve_typedefs(self, typedefs)
518 for argument in self.arguments: 554 for argument in self.arguments:
519 argument.resolve_typedefs(typedefs) 555 argument.resolve_typedefs(typedefs)
520 556
521 557
522 ################################################################################ 558 ################################################################################
523 # Arguments 559 # Arguments
524 ################################################################################ 560 ################################################################################
525 561
526 class IdlArgument(TypedObject): 562 class IdlArgument(TypedObject):
527 def __init__(self, node): 563 def __init__(self, idl_name, node):
528 self.extended_attributes = {} 564 self.extended_attributes = {}
529 self.idl_type = None 565 self.idl_type = None
530 self.is_optional = node.GetProperty('OPTIONAL') # syntax: (optional T) 566 self.is_optional = node.GetProperty('OPTIONAL') # syntax: (optional T)
531 self.is_variadic = False # syntax: (T...) 567 self.is_variadic = False # syntax: (T...)
568 self.idl_name = idl_name
532 self.name = node.GetName() 569 self.name = node.GetName()
533 self.default_value = None 570 self.default_value = None
534 571
535 children = node.GetChildren() 572 children = node.GetChildren()
536 for child in children: 573 for child in children:
537 child_class = child.GetClass() 574 child_class = child.GetClass()
538 if child_class == 'Type': 575 if child_class == 'Type':
539 self.idl_type = type_node_to_type(child) 576 self.idl_type = type_node_to_type(child)
540 elif child_class == 'ExtAttributes': 577 elif child_class == 'ExtAttributes':
541 self.extended_attributes = ext_attributes_node_to_extended_attri butes(child) 578 self.extended_attributes = ext_attributes_node_to_extended_attri butes(idl_name, child)
542 elif child_class == 'Argument': 579 elif child_class == 'Argument':
543 child_name = child.GetName() 580 child_name = child.GetName()
544 if child_name != '...': 581 if child_name != '...':
545 raise ValueError('Unrecognized Argument node; expected "..." , got "%s"' % child_name) 582 raise ValueError('Unrecognized Argument node; expected "..." , got "%s"' % child_name)
546 self.is_variadic = child.GetProperty('ELLIPSIS') or False 583 self.is_variadic = child.GetProperty('ELLIPSIS') or False
547 elif child_class == 'Default': 584 elif child_class == 'Default':
548 self.default_value = default_node_to_idl_literal(child) 585 self.default_value = default_node_to_idl_literal(child)
549 else: 586 else:
550 raise ValueError('Unrecognized node class: %s' % child_class) 587 raise ValueError('Unrecognized node class: %s' % child_class)
551 588
552 589
553 def arguments_node_to_arguments(node): 590 def arguments_node_to_arguments(idl_name, node):
554 # [Constructor] and [CustomConstructor] without arguments (the bare form) 591 # [Constructor] and [CustomConstructor] without arguments (the bare form)
555 # have None instead of an arguments node, but have the same meaning as using 592 # have None instead of an arguments node, but have the same meaning as using
556 # an empty argument list, [Constructor()], so special-case this. 593 # an empty argument list, [Constructor()], so special-case this.
557 # http://www.w3.org/TR/WebIDL/#Constructor 594 # http://www.w3.org/TR/WebIDL/#Constructor
558 if node is None: 595 if node is None:
559 return [] 596 return []
560 return [IdlArgument(argument_node) 597 return [IdlArgument(idl_name, argument_node)
561 for argument_node in node.GetChildren()] 598 for argument_node in node.GetChildren()]
562 599
563 600
564 ################################################################################ 601 ################################################################################
602 # Stringifiers
603 ################################################################################
604
605 class IdlStringifier(object):
606 def __init__(self, idl_name, node):
607 self.attribute = None
608 self.operation = None
609 self.extended_attributes = {}
610 self.idl_name = idl_name
611
612 for child in node.GetChildren():
613 child_class = child.GetClass()
614 if child_class == 'Attribute':
615 self.attribute = IdlAttribute(idl_name, child)
616 elif child_class == 'Operation':
617 operation = IdlOperation(idl_name, child)
618 if operation.name:
619 self.operation = operation
620 elif child_class == 'ExtAttributes':
621 self.extended_attributes = ext_attributes_node_to_extended_attri butes(idl_name, child)
622 else:
623 raise ValueError('Unrecognized node class: %s' % child_class)
624
625 # Copy the stringifier's extended attributes (such as [Unforgable]) onto
626 # the underlying attribute or operation, if there is one.
627 if self.attribute or self.operation:
628 (self.attribute or self.operation).extended_attributes.update(
629 self.extended_attributes)
630
631
632 ################################################################################
565 # Extended attributes 633 # Extended attributes
566 ################################################################################ 634 ################################################################################
567 635
568 def ext_attributes_node_to_extended_attributes(node): 636 def ext_attributes_node_to_extended_attributes(idl_name, node):
569 """ 637 """
570 Returns: 638 Returns:
571 Dictionary of {ExtAttributeName: ExtAttributeValue}. 639 Dictionary of {ExtAttributeName: ExtAttributeValue}.
572 Value is usually a string, with three exceptions: 640 Value is usually a string, with three exceptions:
573 Constructors: value is a list of Arguments nodes, corresponding to 641 Constructors: value is a list of Arguments nodes, corresponding to
574 possible signatures of the constructor. 642 possible signatures of the constructor.
575 CustomConstructors: value is a list of Arguments nodes, corresponding to 643 CustomConstructors: value is a list of Arguments nodes, corresponding to
576 possible signatures of the custom constructor. 644 possible signatures of the custom constructor.
577 NamedConstructor: value is a Call node, corresponding to the single 645 NamedConstructor: value is a Call node, corresponding to the single
578 signature of the named constructor. 646 signature of the named constructor.
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
612 custom_constructors.append(child) 680 custom_constructors.append(child)
613 elif name == 'NamedConstructor': 681 elif name == 'NamedConstructor':
614 if child_class and child_class != 'Call': 682 if child_class and child_class != 'Call':
615 raise ValueError('[NamedConstructor] only supports Call as child , but has child of class: %s' % child_class) 683 raise ValueError('[NamedConstructor] only supports Call as child , but has child of class: %s' % child_class)
616 extended_attributes[name] = child 684 extended_attributes[name] = child
617 elif name == 'SetWrapperReferenceTo': 685 elif name == 'SetWrapperReferenceTo':
618 if not child: 686 if not child:
619 raise ValueError('[SetWrapperReferenceTo] requires a child, but has none.') 687 raise ValueError('[SetWrapperReferenceTo] requires a child, but has none.')
620 if child_class != 'Arguments': 688 if child_class != 'Arguments':
621 raise ValueError('[SetWrapperReferenceTo] only supports Argument s as child, but has child of class: %s' % child_class) 689 raise ValueError('[SetWrapperReferenceTo] only supports Argument s as child, but has child of class: %s' % child_class)
622 extended_attributes[name] = arguments_node_to_arguments(child) 690 extended_attributes[name] = arguments_node_to_arguments(idl_name, ch ild)
623 elif child: 691 elif child:
624 raise ValueError('ExtAttributes node with unexpected children: %s' % name) 692 raise ValueError('ExtAttributes node with unexpected children: %s' % name)
625 else: 693 else:
626 value = extended_attribute_node.GetProperty('VALUE') 694 value = extended_attribute_node.GetProperty('VALUE')
627 extended_attributes[name] = value 695 extended_attributes[name] = value
628 696
629 # Store constructors and custom constructors in special list attributes, 697 # Store constructors and custom constructors in special list attributes,
630 # which are deleted later. Note plural in key. 698 # which are deleted later. Note plural in key.
631 if constructors: 699 if constructors:
632 extended_attributes['Constructors'] = constructors 700 extended_attributes['Constructors'] = constructors
633 if custom_constructors: 701 if custom_constructors:
634 extended_attributes['CustomConstructors'] = custom_constructors 702 extended_attributes['CustomConstructors'] = custom_constructors
635 703
636 return extended_attributes 704 return extended_attributes
637 705
638 706
639 def extended_attributes_to_constructors(extended_attributes): 707 def extended_attributes_to_constructors(idl_name, extended_attributes):
640 """Returns constructors and custom_constructors (lists of IdlOperations). 708 """Returns constructors and custom_constructors (lists of IdlOperations).
641 709
642 Auxiliary function for IdlInterface.__init__. 710 Auxiliary function for IdlInterface.__init__.
643 """ 711 """
644 712
645 constructor_list = extended_attributes.get('Constructors', []) 713 constructor_list = extended_attributes.get('Constructors', [])
646 constructors = [ 714 constructors = [
647 IdlOperation.constructor_from_arguments_node('Constructor', arguments_no de) 715 IdlOperation.constructor_from_arguments_node('Constructor', idl_name, ar guments_node)
648 for arguments_node in constructor_list] 716 for arguments_node in constructor_list]
649 717
650 custom_constructor_list = extended_attributes.get('CustomConstructors', []) 718 custom_constructor_list = extended_attributes.get('CustomConstructors', [])
651 custom_constructors = [ 719 custom_constructors = [
652 IdlOperation.constructor_from_arguments_node('CustomConstructor', argume nts_node) 720 IdlOperation.constructor_from_arguments_node('CustomConstructor', idl_na me, arguments_node)
653 for arguments_node in custom_constructor_list] 721 for arguments_node in custom_constructor_list]
654 722
655 if 'NamedConstructor' in extended_attributes: 723 if 'NamedConstructor' in extended_attributes:
656 # FIXME: support overloaded named constructors, and make homogeneous 724 # FIXME: support overloaded named constructors, and make homogeneous
657 name = 'NamedConstructor' 725 name = 'NamedConstructor'
658 call_node = extended_attributes['NamedConstructor'] 726 call_node = extended_attributes['NamedConstructor']
659 extended_attributes['NamedConstructor'] = call_node.GetName() 727 extended_attributes['NamedConstructor'] = call_node.GetName()
660 children = call_node.GetChildren() 728 children = call_node.GetChildren()
661 if len(children) != 1: 729 if len(children) != 1:
662 raise ValueError('NamedConstructor node expects 1 child, got %s.' % len(children)) 730 raise ValueError('NamedConstructor node expects 1 child, got %s.' % len(children))
663 arguments_node = children[0] 731 arguments_node = children[0]
664 named_constructor = IdlOperation.constructor_from_arguments_node('NamedC onstructor', arguments_node) 732 named_constructor = IdlOperation.constructor_from_arguments_node('NamedC onstructor', idl_name, arguments_node)
665 # FIXME: should return named_constructor separately; appended for Perl 733 # FIXME: should return named_constructor separately; appended for Perl
666 constructors.append(named_constructor) 734 constructors.append(named_constructor)
667 735
668 return constructors, custom_constructors 736 return constructors, custom_constructors
669 737
670 738
671 def clear_constructor_attributes(extended_attributes): 739 def clear_constructor_attributes(extended_attributes):
672 # Deletes Constructor*s* (plural), sets Constructor (singular) 740 # Deletes Constructor*s* (plural), sets Constructor (singular)
673 if 'Constructors' in extended_attributes: 741 if 'Constructors' in extended_attributes:
674 del extended_attributes['Constructors'] 742 del extended_attributes['Constructors']
675 extended_attributes['Constructor'] = None 743 extended_attributes['Constructor'] = None
676 if 'CustomConstructors' in extended_attributes: 744 if 'CustomConstructors' in extended_attributes:
677 del extended_attributes['CustomConstructors'] 745 del extended_attributes['CustomConstructors']
678 extended_attributes['CustomConstructor'] = None 746 extended_attributes['CustomConstructor'] = None
679 747
680 748
681 ################################################################################ 749 ################################################################################
682 # Types 750 # Types
683 ################################################################################ 751 ################################################################################
684 752
685 def type_node_to_type(node): 753 def type_node_to_type(node):
686 children = node.GetChildren() 754 children = node.GetChildren()
687 if len(children) < 1 or len(children) > 2: 755 if len(children) < 1 or len(children) > 2:
688 raise ValueError('Type node expects 1 or 2 children (type + optional arr ay []), got %s (multi-dimensional arrays are not supported).' % len(children)) 756 raise ValueError('Type node expects 1 or 2 children (type + optional arr ay []), got %s (multi-dimensional arrays are not supported).' % len(children))
689 757
758 is_nullable = node.GetProperty('NULLABLE') or False # syntax: T?
690 type_node_child = children[0] 759 type_node_child = children[0]
760 base_type = type_node_inner_to_type(type_node_child, is_nullable=is_nullable )
691 761
692 if len(children) == 2: 762 if len(children) == 2:
693 array_node = children[1] 763 array_node = children[1]
694 array_node_class = array_node.GetClass() 764 array_node_class = array_node.GetClass()
695 if array_node_class != 'Array': 765 if array_node_class != 'Array':
696 raise ValueError('Expected Array node as TypeSuffix, got %s node.' % array_node_class) 766 raise ValueError('Expected Array node as TypeSuffix, got %s node.' % array_node_class)
697 # FIXME: use IdlArrayType instead of is_array, once have that 767 array_is_nullable = array_node.GetProperty('NULLABLE') or False
698 is_array = True 768 return IdlArrayType(base_type, is_nullable=array_is_nullable)
699 else:
700 is_array = False
701 769
702 is_nullable = node.GetProperty('NULLABLE') or False # syntax: T? 770 return base_type
703
704 return type_node_inner_to_type(type_node_child, is_array=is_array, is_nullab le=is_nullable)
705 771
706 772
707 def type_node_inner_to_type(node, is_array=False, is_nullable=False): 773 def type_node_inner_to_type(node, is_nullable=False):
708 # FIXME: remove is_array and is_nullable once have IdlArrayType and IdlNulla bleType 774 # FIXME: remove is_nullable once have IdlNullableType
709 node_class = node.GetClass() 775 node_class = node.GetClass()
710 # Note Type*r*ef, not Typedef, meaning the type is an identifier, thus 776 # Note Type*r*ef, not Typedef, meaning the type is an identifier, thus
711 # either a typedef shorthand (but not a Typedef declaration itself) or an 777 # either a typedef shorthand (but not a Typedef declaration itself) or an
712 # interface type. We do not distinguish these, and just use the type name. 778 # interface type. We do not distinguish these, and just use the type name.
713 if node_class in ['PrimitiveType', 'Typeref']: 779 if node_class in ['PrimitiveType', 'Typeref']:
714 # unrestricted syntax: unrestricted double | unrestricted float 780 # unrestricted syntax: unrestricted double | unrestricted float
715 is_unrestricted = node.GetProperty('UNRESTRICTED') or False 781 is_unrestricted = node.GetProperty('UNRESTRICTED') or False
716 return IdlType(node.GetName(), is_array=is_array, is_nullable=is_nullabl e, is_unrestricted=is_unrestricted) 782 return IdlType(node.GetName(), is_nullable=is_nullable, is_unrestricted= is_unrestricted)
717 elif node_class == 'Any': 783 elif node_class == 'Any':
718 return IdlType('any', is_array=is_array, is_nullable=is_nullable) 784 return IdlType('any', is_nullable=is_nullable)
719 elif node_class == 'Sequence': 785 elif node_class == 'Sequence':
720 if is_array: 786 sequence_is_nullable = node.GetProperty('NULLABLE') or False
721 raise ValueError('Arrays of sequences are not supported') 787 return sequence_node_to_type(node, is_nullable=sequence_is_nullable)
722 return sequence_node_to_type(node, is_nullable=is_nullable)
723 elif node_class == 'UnionType': 788 elif node_class == 'UnionType':
724 if is_array:
725 raise ValueError('Arrays of unions are not supported')
726 return union_type_node_to_idl_union_type(node, is_nullable=is_nullable) 789 return union_type_node_to_idl_union_type(node, is_nullable=is_nullable)
727 raise ValueError('Unrecognized node class: %s' % node_class) 790 raise ValueError('Unrecognized node class: %s' % node_class)
728 791
729 792
730 def sequence_node_to_type(node, is_nullable=False): 793 def sequence_node_to_type(node, is_nullable=False):
731 children = node.GetChildren() 794 children = node.GetChildren()
732 if len(children) != 1: 795 if len(children) != 1:
733 raise ValueError('Sequence node expects exactly 1 child, got %s' % len(c hildren)) 796 raise ValueError('Sequence node expects exactly 1 child, got %s' % len(c hildren))
734 sequence_child = children[0] 797 sequence_child = children[0]
735 sequence_child_class = sequence_child.GetClass() 798 sequence_child_class = sequence_child.GetClass()
736 if sequence_child_class != 'Type': 799 if sequence_child_class != 'Type':
737 raise ValueError('Unrecognized node class: %s' % sequence_child_class) 800 raise ValueError('Unrecognized node class: %s' % sequence_child_class)
738 element_type = type_node_to_type(sequence_child).base_type 801 element_type = type_node_to_type(sequence_child)
739 return IdlType(element_type, is_sequence=True, is_nullable=is_nullable) 802 return IdlSequenceType(element_type, is_nullable=is_nullable)
740 803
741 804
742 def typedef_node_to_type(node): 805 def typedef_node_to_type(node):
743 children = node.GetChildren() 806 children = node.GetChildren()
744 if len(children) != 1: 807 if len(children) != 1:
745 raise ValueError('Typedef node with %s children, expected 1' % len(child ren)) 808 raise ValueError('Typedef node with %s children, expected 1' % len(child ren))
746 child = children[0] 809 child = children[0]
747 child_class = child.GetClass() 810 child_class = child.GetClass()
748 if child_class != 'Type': 811 if child_class != 'Type':
749 raise ValueError('Unrecognized node class: %s' % child_class) 812 raise ValueError('Unrecognized node class: %s' % child_class)
750 return type_node_to_type(child) 813 return type_node_to_type(child)
751 814
752 815
753 def union_type_node_to_idl_union_type(node, is_nullable=False): 816 def union_type_node_to_idl_union_type(node, is_nullable=False):
754 member_types = [type_node_to_type(member_type_node) 817 member_types = [type_node_to_type(member_type_node)
755 for member_type_node in node.GetChildren()] 818 for member_type_node in node.GetChildren()]
756 return IdlUnionType(member_types, is_nullable=is_nullable) 819 return IdlUnionType(member_types, is_nullable=is_nullable)
OLDNEW
« no previous file with comments | « bindings/scripts/idl_compiler.py ('k') | bindings/scripts/idl_reader.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698