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

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

Issue 1029093003: [WIP] IDL: Add limited serializer support and use for RTCIceCandidate (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: use V8ObjectBuilder in modules/crypto Created 5 years, 9 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 29 matching lines...) Expand all
40 40
41 IdlDefinitions 41 IdlDefinitions
42 IdlCallbackFunction < TypedObject 42 IdlCallbackFunction < TypedObject
43 IdlEnum :: FIXME: remove, just use a dict for enums 43 IdlEnum :: FIXME: remove, just use a dict for enums
44 IdlInterface 44 IdlInterface
45 IdlAttribute < TypedObject 45 IdlAttribute < TypedObject
46 IdlConstant < TypedObject 46 IdlConstant < TypedObject
47 IdlLiteral 47 IdlLiteral
48 IdlOperation < TypedObject 48 IdlOperation < TypedObject
49 IdlArgument < TypedObject 49 IdlArgument < TypedObject
50 IdlSerializer
50 IdlStringifier 51 IdlStringifier
51 IdlIterable < IdlIterableOrMaplikeOrSetlike 52 IdlIterable < IdlIterableOrMaplikeOrSetlike
52 IdlMaplike < IdlIterableOrMaplikeOrSetlike 53 IdlMaplike < IdlIterableOrMaplikeOrSetlike
53 IdlSetlike < IdlIterableOrMaplikeOrSetlike 54 IdlSetlike < IdlIterableOrMaplikeOrSetlike
54 IdlException < IdlInterface 55 IdlException < IdlInterface
55 (same contents as IdlInterface) 56 (same contents as IdlInterface)
56 57
57 TypedObject :: Object with one or more attributes that is a type. 58 TypedObject :: Object with one or more attributes that is a type.
58 59
59 IdlArgument is 'picklable', as it is stored in interfaces_info. 60 IdlArgument is 'picklable', as it is stored in interfaces_info.
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 259
259 class IdlInterface(object): 260 class IdlInterface(object):
260 def __init__(self, idl_name, node=None): 261 def __init__(self, idl_name, node=None):
261 self.attributes = [] 262 self.attributes = []
262 self.constants = [] 263 self.constants = []
263 self.constructors = [] 264 self.constructors = []
264 self.custom_constructors = [] 265 self.custom_constructors = []
265 self.extended_attributes = {} 266 self.extended_attributes = {}
266 self.operations = [] 267 self.operations = []
267 self.parent = None 268 self.parent = None
269 self.serializer = None
268 self.stringifier = None 270 self.stringifier = None
269 self.iterable = None 271 self.iterable = None
270 self.maplike = None 272 self.maplike = None
271 self.setlike = None 273 self.setlike = None
272 self.original_interface = None 274 self.original_interface = None
273 self.partial_interfaces = [] 275 self.partial_interfaces = []
274 if not node: # Early exit for IdlException.__init__ 276 if not node: # Early exit for IdlException.__init__
275 return 277 return
276 278
277 self.is_callback = bool(node.GetProperty('CALLBACK')) 279 self.is_callback = bool(node.GetProperty('CALLBACK'))
(...skipping 14 matching lines...) Expand all
292 elif child_class == 'ExtAttributes': 294 elif child_class == 'ExtAttributes':
293 extended_attributes = ext_attributes_node_to_extended_attributes (idl_name, child) 295 extended_attributes = ext_attributes_node_to_extended_attributes (idl_name, child)
294 self.constructors, self.custom_constructors = ( 296 self.constructors, self.custom_constructors = (
295 extended_attributes_to_constructors(idl_name, extended_attri butes)) 297 extended_attributes_to_constructors(idl_name, extended_attri butes))
296 clear_constructor_attributes(extended_attributes) 298 clear_constructor_attributes(extended_attributes)
297 self.extended_attributes = extended_attributes 299 self.extended_attributes = extended_attributes
298 elif child_class == 'Operation': 300 elif child_class == 'Operation':
299 self.operations.append(IdlOperation(idl_name, child)) 301 self.operations.append(IdlOperation(idl_name, child))
300 elif child_class == 'Inherit': 302 elif child_class == 'Inherit':
301 self.parent = child.GetName() 303 self.parent = child.GetName()
304 elif child_class == 'Serializer':
305 self.serializer = IdlSerializer(idl_name, child)
306 self.process_serializer()
302 elif child_class == 'Stringifier': 307 elif child_class == 'Stringifier':
303 self.stringifier = IdlStringifier(idl_name, child) 308 self.stringifier = IdlStringifier(idl_name, child)
304 self.process_stringifier() 309 self.process_stringifier()
305 elif child_class == 'Iterable': 310 elif child_class == 'Iterable':
306 self.iterable = IdlIterable(idl_name, child) 311 self.iterable = IdlIterable(idl_name, child)
307 elif child_class == 'Maplike': 312 elif child_class == 'Maplike':
308 self.maplike = IdlMaplike(idl_name, child) 313 self.maplike = IdlMaplike(idl_name, child)
309 elif child_class == 'Setlike': 314 elif child_class == 'Setlike':
310 self.setlike = IdlSetlike(idl_name, child) 315 self.setlike = IdlSetlike(idl_name, child)
311 else: 316 else:
(...skipping 14 matching lines...) Expand all
326 custom_constructor.accept(visitor) 331 custom_constructor.accept(visitor)
327 for operation in self.operations: 332 for operation in self.operations:
328 operation.accept(visitor) 333 operation.accept(visitor)
329 if self.iterable: 334 if self.iterable:
330 self.iterable.accept(visitor) 335 self.iterable.accept(visitor)
331 elif self.maplike: 336 elif self.maplike:
332 self.maplike.accept(visitor) 337 self.maplike.accept(visitor)
333 elif self.setlike: 338 elif self.setlike:
334 self.setlike.accept(visitor) 339 self.setlike.accept(visitor)
335 340
341 def process_serializer(self):
342 """Add the serializer's named operation child, if it has one, as a regul ar
343 operation of this interface."""
344 if self.serializer.operation:
345 self.operations.append(self.serializer.operation)
346
336 def process_stringifier(self): 347 def process_stringifier(self):
337 """Add the stringifier's attribute or named operation child, if it has 348 """Add the stringifier's attribute or named operation child, if it has
338 one, as a regular attribute/operation of this interface.""" 349 one, as a regular attribute/operation of this interface."""
339 if self.stringifier.attribute: 350 if self.stringifier.attribute:
340 self.attributes.append(self.stringifier.attribute) 351 self.attributes.append(self.stringifier.attribute)
341 elif self.stringifier.operation: 352 elif self.stringifier.operation:
342 self.operations.append(self.stringifier.operation) 353 self.operations.append(self.stringifier.operation)
343 354
344 def merge(self, other): 355 def merge(self, other):
345 """Merge in another interface's members (e.g., partial interface)""" 356 """Merge in another interface's members (e.g., partial interface)"""
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
499 if idl_type == 'NULL': 510 if idl_type == 'NULL':
500 return IdlLiteralNull() 511 return IdlLiteralNull()
501 raise ValueError('Unrecognized default value type: %s' % idl_type) 512 raise ValueError('Unrecognized default value type: %s' % idl_type)
502 513
503 514
504 ################################################################################ 515 ################################################################################
505 # Operations 516 # Operations
506 ################################################################################ 517 ################################################################################
507 518
508 class IdlOperation(TypedObject): 519 class IdlOperation(TypedObject):
520 def __str__(self):
521 return "%s %s(%s)" % (self.idl_type, self.name, ", ".join(str(a) for a i n self.arguments))
522
509 def __init__(self, idl_name, node=None): 523 def __init__(self, idl_name, node=None):
510 self.arguments = [] 524 self.arguments = []
511 self.extended_attributes = {} 525 self.extended_attributes = {}
512 self.specials = [] 526 self.specials = []
513 self.is_constructor = False 527 self.is_constructor = False
514 self.idl_name = idl_name 528 self.idl_name = idl_name
515 self.idl_type = None 529 self.idl_type = None
516 self.is_static = False 530 self.is_static = False
517 531
518 if not node: 532 if not node:
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
574 visitor.visit_operation(self) 588 visitor.visit_operation(self)
575 for argument in self.arguments: 589 for argument in self.arguments:
576 argument.accept(visitor) 590 argument.accept(visitor)
577 591
578 592
579 ################################################################################ 593 ################################################################################
580 # Arguments 594 # Arguments
581 ################################################################################ 595 ################################################################################
582 596
583 class IdlArgument(TypedObject): 597 class IdlArgument(TypedObject):
598 def __str__(self):
599 return "%s %s" % (self.idl_type, self.name)
600
584 def __init__(self, idl_name, node=None): 601 def __init__(self, idl_name, node=None):
585 self.extended_attributes = {} 602 self.extended_attributes = {}
586 self.idl_type = None 603 self.idl_type = None
587 self.is_optional = False # syntax: (optional T) 604 self.is_optional = False # syntax: (optional T)
588 self.is_variadic = False # syntax: (T...) 605 self.is_variadic = False # syntax: (T...)
589 self.idl_name = idl_name 606 self.idl_name = idl_name
590 self.default_value = None 607 self.default_value = None
591 608
592 if not node: 609 if not node:
593 return 610 return
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
629 # have None instead of an arguments node, but have the same meaning as using 646 # have None instead of an arguments node, but have the same meaning as using
630 # an empty argument list, [Constructor()], so special-case this. 647 # an empty argument list, [Constructor()], so special-case this.
631 # http://www.w3.org/TR/WebIDL/#Constructor 648 # http://www.w3.org/TR/WebIDL/#Constructor
632 if node is None: 649 if node is None:
633 return [] 650 return []
634 return [IdlArgument(idl_name, argument_node) 651 return [IdlArgument(idl_name, argument_node)
635 for argument_node in node.GetChildren()] 652 for argument_node in node.GetChildren()]
636 653
637 654
638 ################################################################################ 655 ################################################################################
656 # Serializers
657 ################################################################################
658
659 class IdlSerializer(object):
660 def __init__(self, idl_name, node):
661 self.attribute_name = node.GetProperty('ATTRIBUTE')
662 self.attribute_names = None
663 self.operation = None
664 self.extended_attributes = {}
665 self.is_attribute = False
666 self.is_getter = False
667 self.is_inherit = False
668 self.is_list = False
669 self.is_map = False
670 self.idl_name = idl_name
671
672 for child in node.GetChildren():
673 child_class = child.GetClass()
674 if child_class == 'Operation':
675 self.operation = IdlOperation(idl_name, child)
676 elif child_class == 'List':
677 self.is_list = True
678 self.is_getter = bool(child.GetProperty('GETTER'))
679 self.attributes = child.GetProperty('ATTRIBUTES')
680 elif child_class == 'Map':
681 self.is_map = True
682 self.is_attribute = bool(child.GetProperty('ATTRIBUTE'))
683 self.is_getter = bool(child.GetProperty('GETTER'))
684 self.is_inherit = bool(child.GetProperty('INHERIT'))
685 self.attributes = child.GetProperty('ATTRIBUTES')
686 elif child_class == 'ExtAttributes':
687 self.extended_attributes = ext_attributes_node_to_extended_attri butes(idl_name, child)
688 else:
689 raise ValueError('Unrecognized node class: %s' % child_class)
690
691
692 ################################################################################
639 # Stringifiers 693 # Stringifiers
640 ################################################################################ 694 ################################################################################
641 695
642 class IdlStringifier(object): 696 class IdlStringifier(object):
643 def __init__(self, idl_name, node): 697 def __init__(self, idl_name, node):
644 self.attribute = None 698 self.attribute = None
645 self.operation = None 699 self.operation = None
646 self.extended_attributes = {} 700 self.extended_attributes = {}
647 self.idl_name = idl_name 701 self.idl_name = idl_name
648 702
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after
1013 self.visit_typed_object(argument) 1067 self.visit_typed_object(argument)
1014 1068
1015 def visit_iterable(self, iterable): 1069 def visit_iterable(self, iterable):
1016 self.visit_typed_object(iterable) 1070 self.visit_typed_object(iterable)
1017 1071
1018 def visit_maplike(self, maplike): 1072 def visit_maplike(self, maplike):
1019 self.visit_typed_object(maplike) 1073 self.visit_typed_object(maplike)
1020 1074
1021 def visit_setlike(self, setlike): 1075 def visit_setlike(self, setlike):
1022 self.visit_typed_object(setlike) 1076 self.visit_typed_object(setlike)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698