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

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

Issue 841973002: IDL: Support iterable<>, maplike<> and setlike<> syntax (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 11 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 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 class IdlInterface(object): 263 class IdlInterface(object):
264 def __init__(self, idl_name, node=None): 264 def __init__(self, idl_name, node=None):
265 self.attributes = [] 265 self.attributes = []
266 self.constants = [] 266 self.constants = []
267 self.constructors = [] 267 self.constructors = []
268 self.custom_constructors = [] 268 self.custom_constructors = []
269 self.extended_attributes = {} 269 self.extended_attributes = {}
270 self.operations = [] 270 self.operations = []
271 self.parent = None 271 self.parent = None
272 self.stringifier = None 272 self.stringifier = None
273 self.iterable = None
274 self.maplike = None
275 self.setlike = None
273 self.original_interface = None 276 self.original_interface = None
274 self.partial_interfaces = [] 277 self.partial_interfaces = []
275 if not node: # Early exit for IdlException.__init__ 278 if not node: # Early exit for IdlException.__init__
276 return 279 return
277 280
278 self.is_callback = node.GetProperty('CALLBACK') or False 281 self.is_callback = node.GetProperty('CALLBACK') or False
279 self.is_exception = False 282 self.is_exception = False
280 # FIXME: uppercase 'Partial' => 'PARTIAL' in base IDL parser 283 # FIXME: uppercase 'Partial' => 'PARTIAL' in base IDL parser
281 self.is_partial = node.GetProperty('Partial') or False 284 self.is_partial = node.GetProperty('Partial') or False
282 self.idl_name = idl_name 285 self.idl_name = idl_name
(...skipping 13 matching lines...) Expand all
296 extended_attributes_to_constructors(idl_name, extended_attri butes)) 299 extended_attributes_to_constructors(idl_name, extended_attri butes))
297 clear_constructor_attributes(extended_attributes) 300 clear_constructor_attributes(extended_attributes)
298 self.extended_attributes = extended_attributes 301 self.extended_attributes = extended_attributes
299 elif child_class == 'Operation': 302 elif child_class == 'Operation':
300 self.operations.append(IdlOperation(idl_name, child)) 303 self.operations.append(IdlOperation(idl_name, child))
301 elif child_class == 'Inherit': 304 elif child_class == 'Inherit':
302 self.parent = child.GetName() 305 self.parent = child.GetName()
303 elif child_class == 'Stringifier': 306 elif child_class == 'Stringifier':
304 self.stringifier = IdlStringifier(idl_name, child) 307 self.stringifier = IdlStringifier(idl_name, child)
305 self.process_stringifier() 308 self.process_stringifier()
309 elif child_class == 'Iterable':
310 self.iterable = IdlIterable(idl_name, child)
311 elif child_class == 'Maplike':
312 self.maplike = IdlMaplike(idl_name, child)
313 elif child_class == 'Setlike':
314 self.setlike = IdlSetlike(idl_name, child)
306 else: 315 else:
307 raise ValueError('Unrecognized node class: %s' % child_class) 316 raise ValueError('Unrecognized node class: %s' % child_class)
308 317
318 if len(filter(None, [self.iterable, self.maplike, self.setlike])) > 1:
319 raise ValueError('Interface can only have one of iterable<>, maplike <> and setlike<>.')
320
309 def resolve_typedefs(self, typedefs): 321 def resolve_typedefs(self, typedefs):
310 for attribute in self.attributes: 322 for attribute in self.attributes:
311 attribute.resolve_typedefs(typedefs) 323 attribute.resolve_typedefs(typedefs)
312 for constant in self.constants: 324 for constant in self.constants:
313 constant.resolve_typedefs(typedefs) 325 constant.resolve_typedefs(typedefs)
314 for constructor in self.constructors: 326 for constructor in self.constructors:
315 constructor.resolve_typedefs(typedefs) 327 constructor.resolve_typedefs(typedefs)
316 for custom_constructor in self.custom_constructors: 328 for custom_constructor in self.custom_constructors:
317 custom_constructor.resolve_typedefs(typedefs) 329 custom_constructor.resolve_typedefs(typedefs)
318 for operation in self.operations: 330 for operation in self.operations:
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after
630 raise ValueError('Unrecognized node class: %s' % child_class) 642 raise ValueError('Unrecognized node class: %s' % child_class)
631 643
632 # Copy the stringifier's extended attributes (such as [Unforgable]) onto 644 # Copy the stringifier's extended attributes (such as [Unforgable]) onto
633 # the underlying attribute or operation, if there is one. 645 # the underlying attribute or operation, if there is one.
634 if self.attribute or self.operation: 646 if self.attribute or self.operation:
635 (self.attribute or self.operation).extended_attributes.update( 647 (self.attribute or self.operation).extended_attributes.update(
636 self.extended_attributes) 648 self.extended_attributes)
637 649
638 650
639 ################################################################################ 651 ################################################################################
652 # Iterable, Maplike, Setlike
653 ################################################################################
654
655 class IdlIterable(object):
656 def __init__(self, idl_name, node):
657 children = node.GetChildren()
658
659 if len(children) == 1:
660 self.key_type = None
661 self.value_type = type_node_to_type(children[0])
662 elif len(children) == 2:
663 self.key_type = type_node_to_type(children[0])
664 self.value_type = type_node_to_type(children[1])
665 else:
666 raise ValueError('Unexpected number of children: %d' % len(children) )
667
668
669 class IdlMaplike(object):
670 def __init__(self, idl_name, node):
671 self.is_read_only = node.GetProperty('READONLY') or False
yhirano 2015/01/09 02:30:01 bool(node.GetProperty('READONLY'))
Jens Widell 2015/01/09 07:15:04 Done. I had simply copied this from IdlAttribute,
672
673 children = node.GetChildren()
674
675 if len(children) == 2:
676 self.key_type = type_node_to_type(children[0])
677 self.value_type = type_node_to_type(children[1])
678 else:
679 raise ValueError('Unexpected number of children: %d' % len(children) )
680
681
682 class IdlSetlike(object):
683 def __init__(self, idl_name, node):
684 self.is_read_only = node.GetProperty('READONLY') or False
yhirano 2015/01/09 02:30:01 ditto
Jens Widell 2015/01/09 07:15:04 Done.
685
686 children = node.GetChildren()
687
688 if len(children) == 1:
689 self.value_type = type_node_to_type(children[0])
690 else:
691 raise ValueError('Unexpected number of children: %d' % len(children) )
692
693
694 ################################################################################
640 # Implement statements 695 # Implement statements
641 ################################################################################ 696 ################################################################################
642 697
643 class IdlImplement(object): 698 class IdlImplement(object):
644 def __init__(self, node): 699 def __init__(self, node):
645 self.left_interface = node.GetName() 700 self.left_interface = node.GetName()
646 self.right_interface = node.GetProperty('REFERENCE') 701 self.right_interface = node.GetProperty('REFERENCE')
647 702
648 703
649 ################################################################################ 704 ################################################################################
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
860 child_class = child.GetClass() 915 child_class = child.GetClass()
861 if child_class != 'Type': 916 if child_class != 'Type':
862 raise ValueError('Unrecognized node class: %s' % child_class) 917 raise ValueError('Unrecognized node class: %s' % child_class)
863 return type_node_to_type(child) 918 return type_node_to_type(child)
864 919
865 920
866 def union_type_node_to_idl_union_type(node): 921 def union_type_node_to_idl_union_type(node):
867 member_types = [type_node_to_type(member_type_node) 922 member_types = [type_node_to_type(member_type_node)
868 for member_type_node in node.GetChildren()] 923 for member_type_node in node.GetChildren()]
869 return IdlUnionType(member_types) 924 return IdlUnionType(member_types)
OLDNEW
« no previous file with comments | « no previous file | Source/bindings/scripts/v8_interface.py » ('j') | Source/bindings/scripts/v8_interface.py » ('J')

Powered by Google App Engine
This is Rietveld 408576698