OLD | NEW |
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 Loading... |
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 Loading... |
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 Loading... |
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 Loading... |
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 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
629 # have None instead of an arguments node, but have the same meaning as using | 640 # have None instead of an arguments node, but have the same meaning as using |
630 # an empty argument list, [Constructor()], so special-case this. | 641 # an empty argument list, [Constructor()], so special-case this. |
631 # http://www.w3.org/TR/WebIDL/#Constructor | 642 # http://www.w3.org/TR/WebIDL/#Constructor |
632 if node is None: | 643 if node is None: |
633 return [] | 644 return [] |
634 return [IdlArgument(idl_name, argument_node) | 645 return [IdlArgument(idl_name, argument_node) |
635 for argument_node in node.GetChildren()] | 646 for argument_node in node.GetChildren()] |
636 | 647 |
637 | 648 |
638 ################################################################################ | 649 ################################################################################ |
| 650 # Serializers |
| 651 ################################################################################ |
| 652 |
| 653 class IdlSerializer(object): |
| 654 def __init__(self, idl_name, node): |
| 655 self.attribute_name = node.GetProperty('ATTRIBUTE') |
| 656 self.attribute_names = None |
| 657 self.operation = None |
| 658 self.extended_attributes = {} |
| 659 self.is_attribute = False |
| 660 self.is_getter = False |
| 661 self.is_inherit = False |
| 662 self.is_list = False |
| 663 self.is_map = False |
| 664 self.idl_name = idl_name |
| 665 |
| 666 for child in node.GetChildren(): |
| 667 child_class = child.GetClass() |
| 668 if child_class == 'Operation': |
| 669 self.operation = IdlOperation(idl_name, child) |
| 670 elif child_class == 'List': |
| 671 self.is_list = True |
| 672 self.is_getter = bool(child.GetProperty('GETTER')) |
| 673 self.attributes = child.GetProperty('ATTRIBUTES') |
| 674 elif child_class == 'Map': |
| 675 self.is_map = True |
| 676 self.is_attribute = bool(child.GetProperty('ATTRIBUTE')) |
| 677 self.is_getter = bool(child.GetProperty('GETTER')) |
| 678 self.is_inherit = bool(child.GetProperty('INHERIT')) |
| 679 self.attributes = child.GetProperty('ATTRIBUTES') |
| 680 elif child_class == 'ExtAttributes': |
| 681 self.extended_attributes = ext_attributes_node_to_extended_attri
butes(idl_name, child) |
| 682 else: |
| 683 raise ValueError('Unrecognized node class: %s' % child_class) |
| 684 |
| 685 |
| 686 ################################################################################ |
639 # Stringifiers | 687 # Stringifiers |
640 ################################################################################ | 688 ################################################################################ |
641 | 689 |
642 class IdlStringifier(object): | 690 class IdlStringifier(object): |
643 def __init__(self, idl_name, node): | 691 def __init__(self, idl_name, node): |
644 self.attribute = None | 692 self.attribute = None |
645 self.operation = None | 693 self.operation = None |
646 self.extended_attributes = {} | 694 self.extended_attributes = {} |
647 self.idl_name = idl_name | 695 self.idl_name = idl_name |
648 | 696 |
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1013 self.visit_typed_object(argument) | 1061 self.visit_typed_object(argument) |
1014 | 1062 |
1015 def visit_iterable(self, iterable): | 1063 def visit_iterable(self, iterable): |
1016 self.visit_typed_object(iterable) | 1064 self.visit_typed_object(iterable) |
1017 | 1065 |
1018 def visit_maplike(self, maplike): | 1066 def visit_maplike(self, maplike): |
1019 self.visit_typed_object(maplike) | 1067 self.visit_typed_object(maplike) |
1020 | 1068 |
1021 def visit_setlike(self, setlike): | 1069 def visit_setlike(self, setlike): |
1022 self.visit_typed_object(setlike) | 1070 self.visit_typed_object(setlike) |
OLD | NEW |