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

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

Issue 473893002: Add 'idl_name' to IdlDefinition, IdlOperation, IdlAttribute etc (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 4 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 | « no previous file | Source/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 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 # 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,
94 # since type(idl_type) may change. 94 # since type(idl_type) may change.
95 self.idl_type = self.idl_type.resolve_typedefs(typedefs) 95 self.idl_type = self.idl_type.resolve_typedefs(typedefs)
96 96
97 97
98 ################################################################################ 98 ################################################################################
99 # Definitions (main container class) 99 # Definitions (main container class)
100 ################################################################################ 100 ################################################################################
101 101
102 class IdlDefinitions(object): 102 class IdlDefinitions(object):
103 def __init__(self, node): 103 def __init__(self, idl_name, node):
104 """Args: node: AST root node, class == 'File'""" 104 """Args: node: AST root node, class == 'File'"""
105 self.callback_functions = {} 105 self.callback_functions = {}
106 self.dictionaries = {} 106 self.dictionaries = {}
107 self.enumerations = {} 107 self.enumerations = {}
108 self.interfaces = {} 108 self.interfaces = {}
109 self.idl_name = idl_name
109 110
110 node_class = node.GetClass() 111 node_class = node.GetClass()
111 if node_class != 'File': 112 if node_class != 'File':
112 raise ValueError('Unrecognized node class: %s' % node_class) 113 raise ValueError('Unrecognized node class: %s' % node_class)
113 114
114 typedefs = dict((typedef_name, IdlType(type_name)) 115 typedefs = dict((typedef_name, IdlType(type_name))
115 for typedef_name, type_name in 116 for typedef_name, type_name in
116 STANDARD_TYPEDEFS.iteritems()) 117 STANDARD_TYPEDEFS.iteritems())
117 118
118 children = node.GetChildren() 119 children = node.GetChildren()
119 for child in children: 120 for child in children:
120 child_class = child.GetClass() 121 child_class = child.GetClass()
121 if child_class == 'Interface': 122 if child_class == 'Interface':
122 interface = IdlInterface(child) 123 interface = IdlInterface(idl_name, child)
123 self.interfaces[interface.name] = interface 124 self.interfaces[interface.name] = interface
124 elif child_class == 'Exception': 125 elif child_class == 'Exception':
125 exception = IdlException(child) 126 exception = IdlException(idl_name, child)
126 # For simplicity, treat exceptions as interfaces 127 # For simplicity, treat exceptions as interfaces
127 self.interfaces[exception.name] = exception 128 self.interfaces[exception.name] = exception
128 elif child_class == 'Typedef': 129 elif child_class == 'Typedef':
129 type_name = child.GetName() 130 type_name = child.GetName()
130 typedefs[type_name] = typedef_node_to_type(child) 131 typedefs[type_name] = typedef_node_to_type(child)
131 elif child_class == 'Enum': 132 elif child_class == 'Enum':
132 enumeration = IdlEnum(child) 133 enumeration = IdlEnum(idl_name, child)
133 self.enumerations[enumeration.name] = enumeration 134 self.enumerations[enumeration.name] = enumeration
134 elif child_class == 'Callback': 135 elif child_class == 'Callback':
135 callback_function = IdlCallbackFunction(child) 136 callback_function = IdlCallbackFunction(idl_name, child)
136 self.callback_functions[callback_function.name] = callback_funct ion 137 self.callback_functions[callback_function.name] = callback_funct ion
137 elif child_class == 'Implements': 138 elif child_class == 'Implements':
138 # Implements is handled at the interface merging step 139 # Implements is handled at the interface merging step
139 pass 140 pass
140 elif child_class == 'Dictionary': 141 elif child_class == 'Dictionary':
141 dictionary = IdlDictionary(child) 142 dictionary = IdlDictionary(idl_name, child)
142 self.dictionaries[dictionary.name] = dictionary 143 self.dictionaries[dictionary.name] = dictionary
143 else: 144 else:
144 raise ValueError('Unrecognized node class: %s' % child_class) 145 raise ValueError('Unrecognized node class: %s' % child_class)
145 146
146 # Typedefs are not stored in IR: 147 # Typedefs are not stored in IR:
147 # Resolve typedefs with the actual types and then discard the Typedefs. 148 # Resolve typedefs with the actual types and then discard the Typedefs.
148 # http://www.w3.org/TR/WebIDL/#idl-typedefs 149 # http://www.w3.org/TR/WebIDL/#idl-typedefs
149 self.resolve_typedefs(typedefs) 150 self.resolve_typedefs(typedefs)
150 151
151 def resolve_typedefs(self, typedefs): 152 def resolve_typedefs(self, typedefs):
(...skipping 21 matching lines...) Expand all
173 # Merge callbacks and enumerations 174 # Merge callbacks and enumerations
174 self.enumerations.update(other.enumerations) 175 self.enumerations.update(other.enumerations)
175 self.callback_functions.update(other.callback_functions) 176 self.callback_functions.update(other.callback_functions)
176 177
177 178
178 ################################################################################ 179 ################################################################################
179 # Callback Functions 180 # Callback Functions
180 ################################################################################ 181 ################################################################################
181 182
182 class IdlCallbackFunction(TypedObject): 183 class IdlCallbackFunction(TypedObject):
183 def __init__(self, node): 184 def __init__(self, idl_name, node):
184 children = node.GetChildren() 185 children = node.GetChildren()
185 num_children = len(children) 186 num_children = len(children)
186 if num_children != 2: 187 if num_children != 2:
187 raise ValueError('Expected 2 children, got %s' % num_children) 188 raise ValueError('Expected 2 children, got %s' % num_children)
188 type_node, arguments_node = children 189 type_node, arguments_node = children
189 arguments_node_class = arguments_node.GetClass() 190 arguments_node_class = arguments_node.GetClass()
190 if arguments_node_class != 'Arguments': 191 if arguments_node_class != 'Arguments':
191 raise ValueError('Expected Arguments node, got %s' % arguments_node_ class) 192 raise ValueError('Expected Arguments node, got %s' % arguments_node_ class)
192 193
194 self.idl_name = idl_name
193 self.name = node.GetName() 195 self.name = node.GetName()
194 self.idl_type = type_node_to_type(type_node) 196 self.idl_type = type_node_to_type(type_node)
195 self.arguments = arguments_node_to_arguments(arguments_node) 197 self.arguments = arguments_node_to_arguments(idl_name, arguments_node)
196 198
197 def resolve_typedefs(self, typedefs): 199 def resolve_typedefs(self, typedefs):
198 TypedObject.resolve_typedefs(self, typedefs) 200 TypedObject.resolve_typedefs(self, typedefs)
199 for argument in self.arguments: 201 for argument in self.arguments:
200 argument.resolve_typedefs(typedefs) 202 argument.resolve_typedefs(typedefs)
201 203
202 204
203 ################################################################################ 205 ################################################################################
204 # Dictionary 206 # Dictionary
205 ################################################################################ 207 ################################################################################
206 208
207 class IdlDictionary(object): 209 class IdlDictionary(object):
208 def __init__(self, node): 210 def __init__(self, idl_name, node):
209 self.extended_attributes = {} 211 self.extended_attributes = {}
210 self.is_partial = node.GetProperty('Partial') or False 212 self.is_partial = node.GetProperty('Partial') or False
213 self.idl_name = idl_name
211 self.name = node.GetName() 214 self.name = node.GetName()
212 self.members = [] 215 self.members = []
213 self.parent = None 216 self.parent = None
214 for child in node.GetChildren(): 217 for child in node.GetChildren():
215 child_class = child.GetClass() 218 child_class = child.GetClass()
216 if child_class == 'Inherit': 219 if child_class == 'Inherit':
217 self.parent = child.GetName() 220 self.parent = child.GetName()
218 elif child_class == 'Key': 221 elif child_class == 'Key':
219 self.members.append(IdlDictionaryMember(child)) 222 self.members.append(IdlDictionaryMember(idl_name, child))
220 elif child_class == 'ExtAttributes': 223 elif child_class == 'ExtAttributes':
221 self.extended_attributes = ( 224 self.extended_attributes = (
222 ext_attributes_node_to_extended_attributes(child)) 225 ext_attributes_node_to_extended_attributes(idl_name, child))
223 else: 226 else:
224 raise ValueError('Unrecognized node class: %s' % child_class) 227 raise ValueError('Unrecognized node class: %s' % child_class)
225 228
226 229
227 class IdlDictionaryMember(object): 230 class IdlDictionaryMember(object):
228 def __init__(self, node): 231 def __init__(self, idl_name, node):
229 self.default_value = None 232 self.default_value = None
230 self.extended_attributes = {} 233 self.extended_attributes = {}
231 self.idl_type = None 234 self.idl_type = None
235 self.idl_name = idl_name
232 self.name = node.GetName() 236 self.name = node.GetName()
233 for child in node.GetChildren(): 237 for child in node.GetChildren():
234 child_class = child.GetClass() 238 child_class = child.GetClass()
235 if child_class == 'Type': 239 if child_class == 'Type':
236 self.idl_type = type_node_to_type(child) 240 self.idl_type = type_node_to_type(child)
237 elif child_class == 'Default': 241 elif child_class == 'Default':
238 self.default_value = default_node_to_idl_literal(child) 242 self.default_value = default_node_to_idl_literal(child)
239 elif child_class == 'ExtAttributes': 243 elif child_class == 'ExtAttributes':
240 self.extended_attributes = ( 244 self.extended_attributes = (
241 ext_attributes_node_to_extended_attributes(child)) 245 ext_attributes_node_to_extended_attributes(idl_name, child))
242 else: 246 else:
243 raise ValueError('Unrecognized node class: %s' % child_class) 247 raise ValueError('Unrecognized node class: %s' % child_class)
244 248
245 249
246 ################################################################################ 250 ################################################################################
247 # Enumerations 251 # Enumerations
248 ################################################################################ 252 ################################################################################
249 253
250 class IdlEnum(object): 254 class IdlEnum(object):
251 # FIXME: remove, just treat enums as a dictionary 255 # FIXME: remove, just treat enums as a dictionary
252 def __init__(self, node): 256 def __init__(self, idl_name, node):
257 self.idl_name = idl_name
253 self.name = node.GetName() 258 self.name = node.GetName()
254 self.values = [] 259 self.values = []
255 for child in node.GetChildren(): 260 for child in node.GetChildren():
256 self.values.append(child.GetName()) 261 self.values.append(child.GetName())
257 262
258 263
259 ################################################################################ 264 ################################################################################
260 # Interfaces and Exceptions 265 # Interfaces and Exceptions
261 ################################################################################ 266 ################################################################################
262 267
263 class IdlInterface(object): 268 class IdlInterface(object):
264 def __init__(self, node=None): 269 def __init__(self, idl_name, node=None):
265 self.attributes = [] 270 self.attributes = []
266 self.constants = [] 271 self.constants = []
267 self.constructors = [] 272 self.constructors = []
268 self.custom_constructors = [] 273 self.custom_constructors = []
269 self.extended_attributes = {} 274 self.extended_attributes = {}
270 self.operations = [] 275 self.operations = []
271 self.parent = None 276 self.parent = None
272 self.stringifier = None 277 self.stringifier = None
273 if not node: # Early exit for IdlException.__init__ 278 if not node: # Early exit for IdlException.__init__
274 return 279 return
275 280
276 self.is_callback = node.GetProperty('CALLBACK') or False 281 self.is_callback = node.GetProperty('CALLBACK') or False
277 self.is_exception = False 282 self.is_exception = False
278 # FIXME: uppercase 'Partial' => 'PARTIAL' in base IDL parser 283 # FIXME: uppercase 'Partial' => 'PARTIAL' in base IDL parser
279 self.is_partial = node.GetProperty('Partial') or False 284 self.is_partial = node.GetProperty('Partial') or False
285 self.idl_name = idl_name
280 self.name = node.GetName() 286 self.name = node.GetName()
281 287
282 children = node.GetChildren() 288 children = node.GetChildren()
283 for child in children: 289 for child in children:
284 child_class = child.GetClass() 290 child_class = child.GetClass()
285 if child_class == 'Attribute': 291 if child_class == 'Attribute':
286 self.attributes.append(IdlAttribute(child)) 292 self.attributes.append(IdlAttribute(idl_name, child))
287 elif child_class == 'Const': 293 elif child_class == 'Const':
288 self.constants.append(IdlConstant(child)) 294 self.constants.append(IdlConstant(idl_name, child))
289 elif child_class == 'ExtAttributes': 295 elif child_class == 'ExtAttributes':
290 extended_attributes = ext_attributes_node_to_extended_attributes (child) 296 extended_attributes = ext_attributes_node_to_extended_attributes (idl_name, child)
291 self.constructors, self.custom_constructors = ( 297 self.constructors, self.custom_constructors = (
292 extended_attributes_to_constructors(extended_attributes)) 298 extended_attributes_to_constructors(idl_name, extended_attri butes))
293 clear_constructor_attributes(extended_attributes) 299 clear_constructor_attributes(extended_attributes)
294 self.extended_attributes = extended_attributes 300 self.extended_attributes = extended_attributes
295 elif child_class == 'Operation': 301 elif child_class == 'Operation':
296 self.operations.append(IdlOperation(child)) 302 self.operations.append(IdlOperation(idl_name, child))
297 elif child_class == 'Inherit': 303 elif child_class == 'Inherit':
298 self.parent = child.GetName() 304 self.parent = child.GetName()
299 elif child_class == 'Stringifier': 305 elif child_class == 'Stringifier':
300 self.stringifier = IdlStringifier(child) 306 self.stringifier = IdlStringifier(idl_name, child)
301 self.process_stringifier() 307 self.process_stringifier()
302 else: 308 else:
303 raise ValueError('Unrecognized node class: %s' % child_class) 309 raise ValueError('Unrecognized node class: %s' % child_class)
304 310
305 def resolve_typedefs(self, typedefs): 311 def resolve_typedefs(self, typedefs):
306 for attribute in self.attributes: 312 for attribute in self.attributes:
307 attribute.resolve_typedefs(typedefs) 313 attribute.resolve_typedefs(typedefs)
308 for constant in self.constants: 314 for constant in self.constants:
309 constant.resolve_typedefs(typedefs) 315 constant.resolve_typedefs(typedefs)
310 for constructor in self.constructors: 316 for constructor in self.constructors:
(...skipping 18 matching lines...) Expand all
329 self.operations.extend(other.operations) 335 self.operations.extend(other.operations)
330 336
331 337
332 class IdlException(IdlInterface): 338 class IdlException(IdlInterface):
333 # Properly exceptions and interfaces are distinct, and thus should inherit a 339 # Properly exceptions and interfaces are distinct, and thus should inherit a
334 # common base class (say, "IdlExceptionOrInterface"). 340 # common base class (say, "IdlExceptionOrInterface").
335 # However, there is only one exception (DOMException), and new exceptions 341 # However, there is only one exception (DOMException), and new exceptions
336 # 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
337 # restricted subclass of interfaces. 343 # restricted subclass of interfaces.
338 # http://www.w3.org/TR/WebIDL/#idl-exceptions 344 # http://www.w3.org/TR/WebIDL/#idl-exceptions
339 def __init__(self, node): 345 def __init__(self, idl_name, node):
340 # Exceptions are similar to Interfaces, but simpler 346 # Exceptions are similar to Interfaces, but simpler
341 IdlInterface.__init__(self) 347 IdlInterface.__init__(self, idl_name)
342 self.is_callback = False 348 self.is_callback = False
343 self.is_exception = True 349 self.is_exception = True
344 self.is_partial = False 350 self.is_partial = False
351 self.idl_name = idl_name
345 self.name = node.GetName() 352 self.name = node.GetName()
346 353
347 children = node.GetChildren() 354 children = node.GetChildren()
348 for child in children: 355 for child in children:
349 child_class = child.GetClass() 356 child_class = child.GetClass()
350 if child_class == 'Attribute': 357 if child_class == 'Attribute':
351 attribute = IdlAttribute(child) 358 attribute = IdlAttribute(idl_name, child)
352 self.attributes.append(attribute) 359 self.attributes.append(attribute)
353 elif child_class == 'Const': 360 elif child_class == 'Const':
354 self.constants.append(IdlConstant(child)) 361 self.constants.append(IdlConstant(idl_name, child))
355 elif child_class == 'ExtAttributes': 362 elif child_class == 'ExtAttributes':
356 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)
357 elif child_class == 'ExceptionOperation': 364 elif child_class == 'ExceptionOperation':
358 self.operations.append(IdlOperation.from_exception_operation_nod e(child)) 365 self.operations.append(IdlOperation.from_exception_operation_nod e(idl_name, child))
359 else: 366 else:
360 raise ValueError('Unrecognized node class: %s' % child_class) 367 raise ValueError('Unrecognized node class: %s' % child_class)
361 368
362 369
363 ################################################################################ 370 ################################################################################
364 # Attributes 371 # Attributes
365 ################################################################################ 372 ################################################################################
366 373
367 class IdlAttribute(TypedObject): 374 class IdlAttribute(TypedObject):
368 def __init__(self, node): 375 def __init__(self, idl_name, node):
369 self.is_read_only = node.GetProperty('READONLY') or False 376 self.is_read_only = node.GetProperty('READONLY') or False
370 self.is_static = node.GetProperty('STATIC') or False 377 self.is_static = node.GetProperty('STATIC') or False
378 self.idl_name = idl_name
371 self.name = node.GetName() 379 self.name = node.GetName()
372 # Defaults, overridden below 380 # Defaults, overridden below
373 self.idl_type = None 381 self.idl_type = None
374 self.extended_attributes = {} 382 self.extended_attributes = {}
375 383
376 children = node.GetChildren() 384 children = node.GetChildren()
377 for child in children: 385 for child in children:
378 child_class = child.GetClass() 386 child_class = child.GetClass()
379 if child_class == 'Type': 387 if child_class == 'Type':
380 self.idl_type = type_node_to_type(child) 388 self.idl_type = type_node_to_type(child)
381 elif child_class == 'ExtAttributes': 389 elif child_class == 'ExtAttributes':
382 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)
383 else: 391 else:
384 raise ValueError('Unrecognized node class: %s' % child_class) 392 raise ValueError('Unrecognized node class: %s' % child_class)
385 393
386 394
387 ################################################################################ 395 ################################################################################
388 # Constants 396 # Constants
389 ################################################################################ 397 ################################################################################
390 398
391 class IdlConstant(TypedObject): 399 class IdlConstant(TypedObject):
392 def __init__(self, node): 400 def __init__(self, idl_name, node):
393 children = node.GetChildren() 401 children = node.GetChildren()
394 num_children = len(children) 402 num_children = len(children)
395 if num_children < 2 or num_children > 3: 403 if num_children < 2 or num_children > 3:
396 raise ValueError('Expected 2 or 3 children, got %s' % num_children) 404 raise ValueError('Expected 2 or 3 children, got %s' % num_children)
397 type_node = children[0] 405 type_node = children[0]
398 value_node = children[1] 406 value_node = children[1]
399 value_node_class = value_node.GetClass() 407 value_node_class = value_node.GetClass()
400 if value_node_class != 'Value': 408 if value_node_class != 'Value':
401 raise ValueError('Expected Value node, got %s' % value_node_class) 409 raise ValueError('Expected Value node, got %s' % value_node_class)
402 410
411 self.idl_name = idl_name
403 self.name = node.GetName() 412 self.name = node.GetName()
404 # ConstType is more limited than Type, so subtree is smaller and 413 # ConstType is more limited than Type, so subtree is smaller and
405 # we don't use the full type_node_to_type function. 414 # we don't use the full type_node_to_type function.
406 self.idl_type = type_node_inner_to_type(type_node) 415 self.idl_type = type_node_inner_to_type(type_node)
407 # FIXME: This code is unnecessarily complicated due to the rather 416 # FIXME: This code is unnecessarily complicated due to the rather
408 # inconsistent way the upstream IDL parser outputs default values. 417 # inconsistent way the upstream IDL parser outputs default values.
409 # http://crbug.com/374178 418 # http://crbug.com/374178
410 if value_node.GetProperty('TYPE') == 'float': 419 if value_node.GetProperty('TYPE') == 'float':
411 self.value = value_node.GetProperty('VALUE') 420 self.value = value_node.GetProperty('VALUE')
412 else: 421 else:
413 self.value = value_node.GetName() 422 self.value = value_node.GetName()
414 423
415 if num_children == 3: 424 if num_children == 3:
416 ext_attributes_node = children[2] 425 ext_attributes_node = children[2]
417 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)
418 else: 427 else:
419 self.extended_attributes = {} 428 self.extended_attributes = {}
420 429
421 430
422 ################################################################################ 431 ################################################################################
423 # Literals 432 # Literals
424 ################################################################################ 433 ################################################################################
425 434
426 class IdlLiteral(object): 435 class IdlLiteral(object):
427 def __init__(self, idl_type, value): 436 def __init__(self, idl_type, value):
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
470 if idl_type == 'NULL': 479 if idl_type == 'NULL':
471 return IdlLiteralNull() 480 return IdlLiteralNull()
472 raise ValueError('Unrecognized default value type: %s' % idl_type) 481 raise ValueError('Unrecognized default value type: %s' % idl_type)
473 482
474 483
475 ################################################################################ 484 ################################################################################
476 # Operations 485 # Operations
477 ################################################################################ 486 ################################################################################
478 487
479 class IdlOperation(TypedObject): 488 class IdlOperation(TypedObject):
480 def __init__(self, node=None): 489 def __init__(self, idl_name, node=None):
481 self.arguments = [] 490 self.arguments = []
482 self.extended_attributes = {} 491 self.extended_attributes = {}
483 self.specials = [] 492 self.specials = []
484 self.is_constructor = False 493 self.is_constructor = False
485 494
486 if not node: 495 if not node:
487 self.is_static = False 496 self.is_static = False
488 return 497 return
498 self.idl_name = idl_name
489 self.name = node.GetName() # FIXME: should just be: or '' 499 self.name = node.GetName() # FIXME: should just be: or ''
490 # FIXME: AST should use None internally 500 # FIXME: AST should use None internally
491 if self.name == '_unnamed_': 501 if self.name == '_unnamed_':
492 self.name = '' 502 self.name = ''
493 503
494 self.is_static = node.GetProperty('STATIC') or False 504 self.is_static = node.GetProperty('STATIC') or False
495 property_dictionary = node.GetProperties() 505 property_dictionary = node.GetProperties()
496 for special_keyword in SPECIAL_KEYWORD_LIST: 506 for special_keyword in SPECIAL_KEYWORD_LIST:
497 if special_keyword in property_dictionary: 507 if special_keyword in property_dictionary:
498 self.specials.append(special_keyword.lower()) 508 self.specials.append(special_keyword.lower())
499 509
500 self.idl_type = None 510 self.idl_type = None
501 children = node.GetChildren() 511 children = node.GetChildren()
502 for child in children: 512 for child in children:
503 child_class = child.GetClass() 513 child_class = child.GetClass()
504 if child_class == 'Arguments': 514 if child_class == 'Arguments':
505 self.arguments = arguments_node_to_arguments(child) 515 self.arguments = arguments_node_to_arguments(idl_name, child)
506 elif child_class == 'Type': 516 elif child_class == 'Type':
507 self.idl_type = type_node_to_type(child) 517 self.idl_type = type_node_to_type(child)
508 elif child_class == 'ExtAttributes': 518 elif child_class == 'ExtAttributes':
509 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)
510 else: 520 else:
511 raise ValueError('Unrecognized node class: %s' % child_class) 521 raise ValueError('Unrecognized node class: %s' % child_class)
512 522
513 @classmethod 523 @classmethod
514 def from_exception_operation_node(cls, node): 524 def from_exception_operation_node(cls, idl_name, node):
515 # Needed to handle one case in DOMException.idl: 525 # Needed to handle one case in DOMException.idl:
516 # // Override in a Mozilla compatible format 526 # // Override in a Mozilla compatible format
517 # [NotEnumerable] DOMString toString(); 527 # [NotEnumerable] DOMString toString();
518 # FIXME: can we remove this? replace with a stringifier? 528 # FIXME: can we remove this? replace with a stringifier?
519 operation = cls() 529 operation = cls(idl_name)
520 operation.name = node.GetName() 530 operation.name = node.GetName()
521 children = node.GetChildren() 531 children = node.GetChildren()
522 if len(children) < 1 or len(children) > 2: 532 if len(children) < 1 or len(children) > 2:
523 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))
524 534
525 type_node = children[0] 535 type_node = children[0]
526 operation.idl_type = type_node_to_type(type_node) 536 operation.idl_type = type_node_to_type(type_node)
527 537
528 if len(children) > 1: 538 if len(children) > 1:
529 ext_attributes_node = children[1] 539 ext_attributes_node = children[1]
530 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)
531 541
532 return operation 542 return operation
533 543
534 @classmethod 544 @classmethod
535 def constructor_from_arguments_node(cls, name, arguments_node): 545 def constructor_from_arguments_node(cls, name, idl_name, arguments_node):
536 constructor = cls() 546 constructor = cls(idl_name)
537 constructor.name = name 547 constructor.name = name
538 constructor.arguments = arguments_node_to_arguments(arguments_node) 548 constructor.arguments = arguments_node_to_arguments(idl_name, arguments_ node)
539 constructor.is_constructor = True 549 constructor.is_constructor = True
540 return constructor 550 return constructor
541 551
542 def resolve_typedefs(self, typedefs): 552 def resolve_typedefs(self, typedefs):
543 TypedObject.resolve_typedefs(self, typedefs) 553 TypedObject.resolve_typedefs(self, typedefs)
544 for argument in self.arguments: 554 for argument in self.arguments:
545 argument.resolve_typedefs(typedefs) 555 argument.resolve_typedefs(typedefs)
546 556
547 557
548 ################################################################################ 558 ################################################################################
549 # Arguments 559 # Arguments
550 ################################################################################ 560 ################################################################################
551 561
552 class IdlArgument(TypedObject): 562 class IdlArgument(TypedObject):
553 def __init__(self, node): 563 def __init__(self, idl_name, node):
554 self.extended_attributes = {} 564 self.extended_attributes = {}
555 self.idl_type = None 565 self.idl_type = None
556 self.is_optional = node.GetProperty('OPTIONAL') # syntax: (optional T) 566 self.is_optional = node.GetProperty('OPTIONAL') # syntax: (optional T)
557 self.is_variadic = False # syntax: (T...) 567 self.is_variadic = False # syntax: (T...)
568 self.idl_name = idl_name
558 self.name = node.GetName() 569 self.name = node.GetName()
559 self.default_value = None 570 self.default_value = None
560 571
561 children = node.GetChildren() 572 children = node.GetChildren()
562 for child in children: 573 for child in children:
563 child_class = child.GetClass() 574 child_class = child.GetClass()
564 if child_class == 'Type': 575 if child_class == 'Type':
565 self.idl_type = type_node_to_type(child) 576 self.idl_type = type_node_to_type(child)
566 elif child_class == 'ExtAttributes': 577 elif child_class == 'ExtAttributes':
567 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)
568 elif child_class == 'Argument': 579 elif child_class == 'Argument':
569 child_name = child.GetName() 580 child_name = child.GetName()
570 if child_name != '...': 581 if child_name != '...':
571 raise ValueError('Unrecognized Argument node; expected "..." , got "%s"' % child_name) 582 raise ValueError('Unrecognized Argument node; expected "..." , got "%s"' % child_name)
572 self.is_variadic = child.GetProperty('ELLIPSIS') or False 583 self.is_variadic = child.GetProperty('ELLIPSIS') or False
573 elif child_class == 'Default': 584 elif child_class == 'Default':
574 self.default_value = default_node_to_idl_literal(child) 585 self.default_value = default_node_to_idl_literal(child)
575 else: 586 else:
576 raise ValueError('Unrecognized node class: %s' % child_class) 587 raise ValueError('Unrecognized node class: %s' % child_class)
577 588
578 589
579 def arguments_node_to_arguments(node): 590 def arguments_node_to_arguments(idl_name, node):
580 # [Constructor] and [CustomConstructor] without arguments (the bare form) 591 # [Constructor] and [CustomConstructor] without arguments (the bare form)
581 # 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
582 # an empty argument list, [Constructor()], so special-case this. 593 # an empty argument list, [Constructor()], so special-case this.
583 # http://www.w3.org/TR/WebIDL/#Constructor 594 # http://www.w3.org/TR/WebIDL/#Constructor
584 if node is None: 595 if node is None:
585 return [] 596 return []
586 return [IdlArgument(argument_node) 597 return [IdlArgument(idl_name, argument_node)
587 for argument_node in node.GetChildren()] 598 for argument_node in node.GetChildren()]
588 599
589 600
590 ################################################################################ 601 ################################################################################
591 # Stringifiers 602 # Stringifiers
592 ################################################################################ 603 ################################################################################
593 604
594 class IdlStringifier(object): 605 class IdlStringifier(object):
595 def __init__(self, node): 606 def __init__(self, idl_name, node):
596 self.attribute = None 607 self.attribute = None
597 self.operation = None 608 self.operation = None
598 self.extended_attributes = {} 609 self.extended_attributes = {}
610 self.idl_name = idl_name
599 611
600 for child in node.GetChildren(): 612 for child in node.GetChildren():
601 child_class = child.GetClass() 613 child_class = child.GetClass()
602 if child_class == 'Attribute': 614 if child_class == 'Attribute':
603 self.attribute = IdlAttribute(child) 615 self.attribute = IdlAttribute(idl_name, child)
604 elif child_class == 'Operation': 616 elif child_class == 'Operation':
605 operation = IdlOperation(child) 617 operation = IdlOperation(idl_name, child)
606 if operation.name: 618 if operation.name:
607 self.operation = operation 619 self.operation = operation
608 elif child_class == 'ExtAttributes': 620 elif child_class == 'ExtAttributes':
609 self.extended_attributes = ext_attributes_node_to_extended_attri butes(child) 621 self.extended_attributes = ext_attributes_node_to_extended_attri butes(idl_name, child)
610 else: 622 else:
611 raise ValueError('Unrecognized node class: %s' % child_class) 623 raise ValueError('Unrecognized node class: %s' % child_class)
612 624
613 # Copy the stringifier's extended attributes (such as [Unforgable]) onto 625 # Copy the stringifier's extended attributes (such as [Unforgable]) onto
614 # the underlying attribute or operation, if there is one. 626 # the underlying attribute or operation, if there is one.
615 if self.attribute or self.operation: 627 if self.attribute or self.operation:
616 (self.attribute or self.operation).extended_attributes.update( 628 (self.attribute or self.operation).extended_attributes.update(
617 self.extended_attributes) 629 self.extended_attributes)
618 630
619 631
620 ################################################################################ 632 ################################################################################
621 # Extended attributes 633 # Extended attributes
622 ################################################################################ 634 ################################################################################
623 635
624 def ext_attributes_node_to_extended_attributes(node): 636 def ext_attributes_node_to_extended_attributes(idl_name, node):
625 """ 637 """
626 Returns: 638 Returns:
627 Dictionary of {ExtAttributeName: ExtAttributeValue}. 639 Dictionary of {ExtAttributeName: ExtAttributeValue}.
628 Value is usually a string, with three exceptions: 640 Value is usually a string, with three exceptions:
629 Constructors: value is a list of Arguments nodes, corresponding to 641 Constructors: value is a list of Arguments nodes, corresponding to
630 possible signatures of the constructor. 642 possible signatures of the constructor.
631 CustomConstructors: value is a list of Arguments nodes, corresponding to 643 CustomConstructors: value is a list of Arguments nodes, corresponding to
632 possible signatures of the custom constructor. 644 possible signatures of the custom constructor.
633 NamedConstructor: value is a Call node, corresponding to the single 645 NamedConstructor: value is a Call node, corresponding to the single
634 signature of the named constructor. 646 signature of the named constructor.
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
668 custom_constructors.append(child) 680 custom_constructors.append(child)
669 elif name == 'NamedConstructor': 681 elif name == 'NamedConstructor':
670 if child_class and child_class != 'Call': 682 if child_class and child_class != 'Call':
671 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)
672 extended_attributes[name] = child 684 extended_attributes[name] = child
673 elif name == 'SetWrapperReferenceTo': 685 elif name == 'SetWrapperReferenceTo':
674 if not child: 686 if not child:
675 raise ValueError('[SetWrapperReferenceTo] requires a child, but has none.') 687 raise ValueError('[SetWrapperReferenceTo] requires a child, but has none.')
676 if child_class != 'Arguments': 688 if child_class != 'Arguments':
677 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)
678 extended_attributes[name] = arguments_node_to_arguments(child) 690 extended_attributes[name] = arguments_node_to_arguments(idl_name, ch ild)
679 elif child: 691 elif child:
680 raise ValueError('ExtAttributes node with unexpected children: %s' % name) 692 raise ValueError('ExtAttributes node with unexpected children: %s' % name)
681 else: 693 else:
682 value = extended_attribute_node.GetProperty('VALUE') 694 value = extended_attribute_node.GetProperty('VALUE')
683 extended_attributes[name] = value 695 extended_attributes[name] = value
684 696
685 # Store constructors and custom constructors in special list attributes, 697 # Store constructors and custom constructors in special list attributes,
686 # which are deleted later. Note plural in key. 698 # which are deleted later. Note plural in key.
687 if constructors: 699 if constructors:
688 extended_attributes['Constructors'] = constructors 700 extended_attributes['Constructors'] = constructors
689 if custom_constructors: 701 if custom_constructors:
690 extended_attributes['CustomConstructors'] = custom_constructors 702 extended_attributes['CustomConstructors'] = custom_constructors
691 703
692 return extended_attributes 704 return extended_attributes
693 705
694 706
695 def extended_attributes_to_constructors(extended_attributes): 707 def extended_attributes_to_constructors(idl_name, extended_attributes):
696 """Returns constructors and custom_constructors (lists of IdlOperations). 708 """Returns constructors and custom_constructors (lists of IdlOperations).
697 709
698 Auxiliary function for IdlInterface.__init__. 710 Auxiliary function for IdlInterface.__init__.
699 """ 711 """
700 712
701 constructor_list = extended_attributes.get('Constructors', []) 713 constructor_list = extended_attributes.get('Constructors', [])
702 constructors = [ 714 constructors = [
703 IdlOperation.constructor_from_arguments_node('Constructor', arguments_no de) 715 IdlOperation.constructor_from_arguments_node('Constructor', idl_name, ar guments_node)
704 for arguments_node in constructor_list] 716 for arguments_node in constructor_list]
705 717
706 custom_constructor_list = extended_attributes.get('CustomConstructors', []) 718 custom_constructor_list = extended_attributes.get('CustomConstructors', [])
707 custom_constructors = [ 719 custom_constructors = [
708 IdlOperation.constructor_from_arguments_node('CustomConstructor', argume nts_node) 720 IdlOperation.constructor_from_arguments_node('CustomConstructor', idl_na me, arguments_node)
709 for arguments_node in custom_constructor_list] 721 for arguments_node in custom_constructor_list]
710 722
711 if 'NamedConstructor' in extended_attributes: 723 if 'NamedConstructor' in extended_attributes:
712 # FIXME: support overloaded named constructors, and make homogeneous 724 # FIXME: support overloaded named constructors, and make homogeneous
713 name = 'NamedConstructor' 725 name = 'NamedConstructor'
714 call_node = extended_attributes['NamedConstructor'] 726 call_node = extended_attributes['NamedConstructor']
715 extended_attributes['NamedConstructor'] = call_node.GetName() 727 extended_attributes['NamedConstructor'] = call_node.GetName()
716 children = call_node.GetChildren() 728 children = call_node.GetChildren()
717 if len(children) != 1: 729 if len(children) != 1:
718 raise ValueError('NamedConstructor node expects 1 child, got %s.' % len(children)) 730 raise ValueError('NamedConstructor node expects 1 child, got %s.' % len(children))
719 arguments_node = children[0] 731 arguments_node = children[0]
720 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)
721 # FIXME: should return named_constructor separately; appended for Perl 733 # FIXME: should return named_constructor separately; appended for Perl
722 constructors.append(named_constructor) 734 constructors.append(named_constructor)
723 735
724 return constructors, custom_constructors 736 return constructors, custom_constructors
725 737
726 738
727 def clear_constructor_attributes(extended_attributes): 739 def clear_constructor_attributes(extended_attributes):
728 # Deletes Constructor*s* (plural), sets Constructor (singular) 740 # Deletes Constructor*s* (plural), sets Constructor (singular)
729 if 'Constructors' in extended_attributes: 741 if 'Constructors' in extended_attributes:
730 del extended_attributes['Constructors'] 742 del extended_attributes['Constructors']
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
804 child_class = child.GetClass() 816 child_class = child.GetClass()
805 if child_class != 'Type': 817 if child_class != 'Type':
806 raise ValueError('Unrecognized node class: %s' % child_class) 818 raise ValueError('Unrecognized node class: %s' % child_class)
807 return type_node_to_type(child) 819 return type_node_to_type(child)
808 820
809 821
810 def union_type_node_to_idl_union_type(node, is_nullable=False): 822 def union_type_node_to_idl_union_type(node, is_nullable=False):
811 member_types = [type_node_to_type(member_type_node) 823 member_types = [type_node_to_type(member_type_node)
812 for member_type_node in node.GetChildren()] 824 for member_type_node in node.GetChildren()]
813 return IdlUnionType(member_types, is_nullable=is_nullable) 825 return IdlUnionType(member_types, is_nullable=is_nullable)
OLDNEW
« no previous file with comments | « no previous file | Source/bindings/scripts/idl_reader.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698