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

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

Issue 312683005: IDL: Support optional argument default value syntax (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 # Copyright (C) 2013 Google Inc. All rights reserved. 1 # Copyright (C) 2013 Google Inc. All rights reserved.
2 # 2 #
3 # Redistribution and use in source and binary forms, with or without 3 # Redistribution and use in source and binary forms, with or without
4 # modification, are permitted provided that the following conditions are 4 # modification, are permitted provided that the following conditions are
5 # met: 5 # met:
6 # 6 #
7 # * Redistributions of source code must retain the above copyright 7 # * Redistributions of source code must retain the above copyright
8 # notice, this list of conditions and the following disclaimer. 8 # notice, this list of conditions and the following disclaimer.
9 # * Redistributions in binary form must reproduce the above 9 # * Redistributions in binary form must reproduce the above
10 # copyright notice, this list of conditions and the following disclaimer 10 # copyright notice, this list of conditions and the following disclaimer
(...skipping 457 matching lines...) Expand 10 before | Expand all | Expand 10 after
468 # Arguments 468 # Arguments
469 ################################################################################ 469 ################################################################################
470 470
471 class IdlArgument(TypedObject): 471 class IdlArgument(TypedObject):
472 def __init__(self, node): 472 def __init__(self, node):
473 self.extended_attributes = {} 473 self.extended_attributes = {}
474 self.idl_type = None 474 self.idl_type = None
475 self.is_optional = node.GetProperty('OPTIONAL') # syntax: (optional T) 475 self.is_optional = node.GetProperty('OPTIONAL') # syntax: (optional T)
476 self.is_variadic = False # syntax: (T...) 476 self.is_variadic = False # syntax: (T...)
477 self.name = node.GetName() 477 self.name = node.GetName()
478 self.default_value = None
478 479
479 children = node.GetChildren() 480 children = node.GetChildren()
480 for child in children: 481 for child in children:
481 child_class = child.GetClass() 482 child_class = child.GetClass()
482 if child_class == 'Type': 483 if child_class == 'Type':
483 self.idl_type = type_node_to_type(child) 484 self.idl_type = type_node_to_type(child)
484 elif child_class == 'ExtAttributes': 485 elif child_class == 'ExtAttributes':
485 self.extended_attributes = ext_attributes_node_to_extended_attri butes(child) 486 self.extended_attributes = ext_attributes_node_to_extended_attri butes(child)
486 elif child_class == 'Argument': 487 elif child_class == 'Argument':
487 child_name = child.GetName() 488 child_name = child.GetName()
488 if child_name != '...': 489 if child_name != '...':
489 raise ValueError('Unrecognized Argument node; expected "..." , got "%s"' % child_name) 490 raise ValueError('Unrecognized Argument node; expected "..." , got "%s"' % child_name)
490 self.is_variadic = child.GetProperty('ELLIPSIS') or False 491 self.is_variadic = child.GetProperty('ELLIPSIS') or False
492 elif child_class == 'Default':
493 self.default_value = IdlDefaultValue(child)
491 else: 494 else:
492 raise ValueError('Unrecognized node class: %s' % child_class) 495 raise ValueError('Unrecognized node class: %s' % child_class)
493 496
494 497
495 def arguments_node_to_arguments(node): 498 def arguments_node_to_arguments(node):
496 # [Constructor] and [CustomConstructor] without arguments (the bare form) 499 # [Constructor] and [CustomConstructor] without arguments (the bare form)
497 # have None instead of an arguments node, but have the same meaning as using 500 # have None instead of an arguments node, but have the same meaning as using
498 # an empty argument list, [Constructor()], so special-case this. 501 # an empty argument list, [Constructor()], so special-case this.
499 # http://www.w3.org/TR/WebIDL/#Constructor 502 # http://www.w3.org/TR/WebIDL/#Constructor
500 if node is None: 503 if node is None:
501 return [] 504 return []
502 return [IdlArgument(argument_node) 505 return [IdlArgument(argument_node)
503 for argument_node in node.GetChildren()] 506 for argument_node in node.GetChildren()]
504 507
505 508
509 class IdlDefaultValue(TypedObject):
Nils Barth (inactive) 2014/06/04 05:22:24 You don't need TypedObject here I don't think: Typ
510 def __init__(self, node):
511 self.value_type = node.GetProperty('TYPE')
Nils Barth (inactive) 2014/06/04 05:22:24 Naming: idl_type, rather than value_type. (might n
512 if self.value_type == 'DOMString':
Nils Barth (inactive) 2014/06/04 05:22:24 Could you factor out this evaluation into a functi
513 self.value = node.GetProperty('NAME')
514 elif self.value_type == 'integer':
515 self.value = eval(node.GetProperty('NAME'))
Nils Barth (inactive) 2014/06/04 05:22:24 !!! Could you please use constructors int() and fl
Jens Widell 2014/06/04 06:12:18 Using eval() here is clearly ridiculous. Sorry abo
Nils Barth (inactive) 2014/06/04 06:33:35 n/p, that makes sense -- I was wondering what exac
516 elif self.value_type == 'float':
517 self.value = eval(node.GetProperty('VALUE'))
Nils Barth (inactive) 2014/06/04 05:22:24 Could you add a FIXME for the irregular upstream t
518 elif self.value_type == 'boolean':
519 self.value = node.GetProperty('VALUE')
520 elif self.value_type == 'NULL':
Nils Barth (inactive) 2014/06/04 05:22:24 Handling null and undefined will be a bit ugly. We
521 self.value = None
522 else:
523 raise ValueError('Unrecognized default value type: %s' % self.value_ type)
524
525
506 ################################################################################ 526 ################################################################################
507 # Extended attributes 527 # Extended attributes
508 ################################################################################ 528 ################################################################################
509 529
510 def ext_attributes_node_to_extended_attributes(node): 530 def ext_attributes_node_to_extended_attributes(node):
511 """ 531 """
512 Returns: 532 Returns:
513 Dictionary of {ExtAttributeName: ExtAttributeValue}. 533 Dictionary of {ExtAttributeName: ExtAttributeValue}.
514 Value is usually a string, with three exceptions: 534 Value is usually a string, with three exceptions:
515 Constructors: value is a list of Arguments nodes, corresponding to 535 Constructors: value is a list of Arguments nodes, corresponding to
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
689 child_class = child.GetClass() 709 child_class = child.GetClass()
690 if child_class != 'Type': 710 if child_class != 'Type':
691 raise ValueError('Unrecognized node class: %s' % child_class) 711 raise ValueError('Unrecognized node class: %s' % child_class)
692 return type_node_to_type(child) 712 return type_node_to_type(child)
693 713
694 714
695 def union_type_node_to_idl_union_type(node, is_nullable=False): 715 def union_type_node_to_idl_union_type(node, is_nullable=False):
696 member_types = [type_node_to_type(member_type_node) 716 member_types = [type_node_to_type(member_type_node)
697 for member_type_node in node.GetChildren()] 717 for member_type_node in node.GetChildren()]
698 return IdlUnionType(member_types, is_nullable=is_nullable) 718 return IdlUnionType(member_types, is_nullable=is_nullable)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698