| 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 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 argument.resolve_typedefs(typedefs) | 197 argument.resolve_typedefs(typedefs) |
| 198 | 198 |
| 199 | 199 |
| 200 ################################################################################ | 200 ################################################################################ |
| 201 # Dictionary | 201 # Dictionary |
| 202 ################################################################################ | 202 ################################################################################ |
| 203 | 203 |
| 204 class IdlDictionary(object): | 204 class IdlDictionary(object): |
| 205 def __init__(self, idl_name, node): | 205 def __init__(self, idl_name, node): |
| 206 self.extended_attributes = {} | 206 self.extended_attributes = {} |
| 207 self.is_partial = node.GetProperty('Partial') or False | 207 self.is_partial = bool(node.GetProperty('Partial')) |
| 208 self.idl_name = idl_name | 208 self.idl_name = idl_name |
| 209 self.name = node.GetName() | 209 self.name = node.GetName() |
| 210 self.members = [] | 210 self.members = [] |
| 211 self.parent = None | 211 self.parent = None |
| 212 for child in node.GetChildren(): | 212 for child in node.GetChildren(): |
| 213 child_class = child.GetClass() | 213 child_class = child.GetClass() |
| 214 if child_class == 'Inherit': | 214 if child_class == 'Inherit': |
| 215 self.parent = child.GetName() | 215 self.parent = child.GetName() |
| 216 elif child_class == 'Key': | 216 elif child_class == 'Key': |
| 217 self.members.append(IdlDictionaryMember(idl_name, child)) | 217 self.members.append(IdlDictionaryMember(idl_name, child)) |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 = bool(node.GetProperty('CALLBACK')) |
| 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 = bool(node.GetProperty('Partial')) |
| 282 self.idl_name = idl_name | 285 self.idl_name = idl_name |
| 283 self.name = node.GetName() | 286 self.name = node.GetName() |
| 284 self.idl_type = IdlType(self.name) | 287 self.idl_type = IdlType(self.name) |
| 285 | 288 |
| 286 children = node.GetChildren() | 289 children = node.GetChildren() |
| 287 for child in children: | 290 for child in children: |
| 288 child_class = child.GetClass() | 291 child_class = child.GetClass() |
| 289 if child_class == 'Attribute': | 292 if child_class == 'Attribute': |
| 290 self.attributes.append(IdlAttribute(idl_name, child)) | 293 self.attributes.append(IdlAttribute(idl_name, child)) |
| 291 elif child_class == 'Const': | 294 elif child_class == 'Const': |
| 292 self.constants.append(IdlConstant(idl_name, child)) | 295 self.constants.append(IdlConstant(idl_name, child)) |
| 293 elif child_class == 'ExtAttributes': | 296 elif child_class == 'ExtAttributes': |
| 294 extended_attributes = ext_attributes_node_to_extended_attributes
(idl_name, child) | 297 extended_attributes = ext_attributes_node_to_extended_attributes
(idl_name, child) |
| 295 self.constructors, self.custom_constructors = ( | 298 self.constructors, self.custom_constructors = ( |
| 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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 365 else: | 377 else: |
| 366 raise ValueError('Unrecognized node class: %s' % child_class) | 378 raise ValueError('Unrecognized node class: %s' % child_class) |
| 367 | 379 |
| 368 | 380 |
| 369 ################################################################################ | 381 ################################################################################ |
| 370 # Attributes | 382 # Attributes |
| 371 ################################################################################ | 383 ################################################################################ |
| 372 | 384 |
| 373 class IdlAttribute(TypedObject): | 385 class IdlAttribute(TypedObject): |
| 374 def __init__(self, idl_name, node): | 386 def __init__(self, idl_name, node): |
| 375 self.is_read_only = node.GetProperty('READONLY') or False | 387 self.is_read_only = bool(node.GetProperty('READONLY')) |
| 376 self.is_static = node.GetProperty('STATIC') or False | 388 self.is_static = bool(node.GetProperty('STATIC')) |
| 377 self.idl_name = idl_name | 389 self.idl_name = idl_name |
| 378 self.name = node.GetName() | 390 self.name = node.GetName() |
| 379 # Defaults, overridden below | 391 # Defaults, overridden below |
| 380 self.idl_type = None | 392 self.idl_type = None |
| 381 self.extended_attributes = {} | 393 self.extended_attributes = {} |
| 382 | 394 |
| 383 children = node.GetChildren() | 395 children = node.GetChildren() |
| 384 for child in children: | 396 for child in children: |
| 385 child_class = child.GetClass() | 397 child_class = child.GetClass() |
| 386 if child_class == 'Type': | 398 if child_class == 'Type': |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 493 | 505 |
| 494 if not node: | 506 if not node: |
| 495 self.is_static = False | 507 self.is_static = False |
| 496 return | 508 return |
| 497 self.idl_name = idl_name | 509 self.idl_name = idl_name |
| 498 self.name = node.GetName() # FIXME: should just be: or '' | 510 self.name = node.GetName() # FIXME: should just be: or '' |
| 499 # FIXME: AST should use None internally | 511 # FIXME: AST should use None internally |
| 500 if self.name == '_unnamed_': | 512 if self.name == '_unnamed_': |
| 501 self.name = '' | 513 self.name = '' |
| 502 | 514 |
| 503 self.is_static = node.GetProperty('STATIC') or False | 515 self.is_static = bool(node.GetProperty('STATIC')) |
| 504 property_dictionary = node.GetProperties() | 516 property_dictionary = node.GetProperties() |
| 505 for special_keyword in SPECIAL_KEYWORD_LIST: | 517 for special_keyword in SPECIAL_KEYWORD_LIST: |
| 506 if special_keyword in property_dictionary: | 518 if special_keyword in property_dictionary: |
| 507 self.specials.append(special_keyword.lower()) | 519 self.specials.append(special_keyword.lower()) |
| 508 | 520 |
| 509 self.idl_type = None | 521 self.idl_type = None |
| 510 children = node.GetChildren() | 522 children = node.GetChildren() |
| 511 for child in children: | 523 for child in children: |
| 512 child_class = child.GetClass() | 524 child_class = child.GetClass() |
| 513 if child_class == 'Arguments': | 525 if child_class == 'Arguments': |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 572 for child in children: | 584 for child in children: |
| 573 child_class = child.GetClass() | 585 child_class = child.GetClass() |
| 574 if child_class == 'Type': | 586 if child_class == 'Type': |
| 575 self.idl_type = type_node_to_type(child) | 587 self.idl_type = type_node_to_type(child) |
| 576 elif child_class == 'ExtAttributes': | 588 elif child_class == 'ExtAttributes': |
| 577 self.extended_attributes = ext_attributes_node_to_extended_attri
butes(idl_name, child) | 589 self.extended_attributes = ext_attributes_node_to_extended_attri
butes(idl_name, child) |
| 578 elif child_class == 'Argument': | 590 elif child_class == 'Argument': |
| 579 child_name = child.GetName() | 591 child_name = child.GetName() |
| 580 if child_name != '...': | 592 if child_name != '...': |
| 581 raise ValueError('Unrecognized Argument node; expected "..."
, got "%s"' % child_name) | 593 raise ValueError('Unrecognized Argument node; expected "..."
, got "%s"' % child_name) |
| 582 self.is_variadic = child.GetProperty('ELLIPSIS') or False | 594 self.is_variadic = bool(child.GetProperty('ELLIPSIS')) |
| 583 elif child_class == 'Default': | 595 elif child_class == 'Default': |
| 584 self.default_value = default_node_to_idl_literal(child) | 596 self.default_value = default_node_to_idl_literal(child) |
| 585 else: | 597 else: |
| 586 raise ValueError('Unrecognized node class: %s' % child_class) | 598 raise ValueError('Unrecognized node class: %s' % child_class) |
| 587 | 599 |
| 588 def __getstate__(self): | 600 def __getstate__(self): |
| 589 # FIXME: Return a picklable object which has enough information to | 601 # FIXME: Return a picklable object which has enough information to |
| 590 # unpickle. | 602 # unpickle. |
| 591 return {} | 603 return {} |
| 592 | 604 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 # FIXME: Support extended attributes. |
| 660 |
| 661 if len(children) == 1: |
| 662 self.key_type = None |
| 663 self.value_type = type_node_to_type(children[0]) |
| 664 elif len(children) == 2: |
| 665 self.key_type = type_node_to_type(children[0]) |
| 666 self.value_type = type_node_to_type(children[1]) |
| 667 else: |
| 668 raise ValueError('Unexpected number of children: %d' % len(children)
) |
| 669 |
| 670 |
| 671 class IdlMaplike(object): |
| 672 def __init__(self, idl_name, node): |
| 673 self.is_read_only = bool(node.GetProperty('READONLY')) |
| 674 |
| 675 children = node.GetChildren() |
| 676 |
| 677 # FIXME: Support extended attributes. |
| 678 |
| 679 if len(children) == 2: |
| 680 self.key_type = type_node_to_type(children[0]) |
| 681 self.value_type = type_node_to_type(children[1]) |
| 682 else: |
| 683 raise ValueError('Unexpected number of children: %d' % len(children)
) |
| 684 |
| 685 |
| 686 class IdlSetlike(object): |
| 687 def __init__(self, idl_name, node): |
| 688 self.is_read_only = bool(node.GetProperty('READONLY')) |
| 689 |
| 690 children = node.GetChildren() |
| 691 |
| 692 # FIXME: Support extended attributes. |
| 693 |
| 694 if len(children) == 1: |
| 695 self.value_type = type_node_to_type(children[0]) |
| 696 else: |
| 697 raise ValueError('Unexpected number of children: %d' % len(children)
) |
| 698 |
| 699 |
| 700 ################################################################################ |
| 640 # Implement statements | 701 # Implement statements |
| 641 ################################################################################ | 702 ################################################################################ |
| 642 | 703 |
| 643 class IdlImplement(object): | 704 class IdlImplement(object): |
| 644 def __init__(self, node): | 705 def __init__(self, node): |
| 645 self.left_interface = node.GetName() | 706 self.left_interface = node.GetName() |
| 646 self.right_interface = node.GetProperty('REFERENCE') | 707 self.right_interface = node.GetProperty('REFERENCE') |
| 647 | 708 |
| 648 | 709 |
| 649 ################################################################################ | 710 ################################################################################ |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 817 return base_type | 878 return base_type |
| 818 | 879 |
| 819 | 880 |
| 820 def type_node_inner_to_type(node): | 881 def type_node_inner_to_type(node): |
| 821 node_class = node.GetClass() | 882 node_class = node.GetClass() |
| 822 # Note Type*r*ef, not Typedef, meaning the type is an identifier, thus | 883 # Note Type*r*ef, not Typedef, meaning the type is an identifier, thus |
| 823 # either a typedef shorthand (but not a Typedef declaration itself) or an | 884 # either a typedef shorthand (but not a Typedef declaration itself) or an |
| 824 # interface type. We do not distinguish these, and just use the type name. | 885 # interface type. We do not distinguish these, and just use the type name. |
| 825 if node_class in ['PrimitiveType', 'Typeref']: | 886 if node_class in ['PrimitiveType', 'Typeref']: |
| 826 # unrestricted syntax: unrestricted double | unrestricted float | 887 # unrestricted syntax: unrestricted double | unrestricted float |
| 827 is_unrestricted = node.GetProperty('UNRESTRICTED') or False | 888 is_unrestricted = bool(node.GetProperty('UNRESTRICTED')) |
| 828 return IdlType(node.GetName(), is_unrestricted=is_unrestricted) | 889 return IdlType(node.GetName(), is_unrestricted=is_unrestricted) |
| 829 elif node_class == 'Any': | 890 elif node_class == 'Any': |
| 830 return IdlType('any') | 891 return IdlType('any') |
| 831 elif node_class == 'Sequence': | 892 elif node_class == 'Sequence': |
| 832 return sequence_node_to_type(node) | 893 return sequence_node_to_type(node) |
| 833 elif node_class == 'UnionType': | 894 elif node_class == 'UnionType': |
| 834 return union_type_node_to_idl_union_type(node) | 895 return union_type_node_to_idl_union_type(node) |
| 835 elif node_class == 'Promise': | 896 elif node_class == 'Promise': |
| 836 return IdlType('Promise') | 897 return IdlType('Promise') |
| 837 raise ValueError('Unrecognized node class: %s' % node_class) | 898 raise ValueError('Unrecognized node class: %s' % node_class) |
| (...skipping 22 matching lines...) Expand all Loading... |
| 860 child_class = child.GetClass() | 921 child_class = child.GetClass() |
| 861 if child_class != 'Type': | 922 if child_class != 'Type': |
| 862 raise ValueError('Unrecognized node class: %s' % child_class) | 923 raise ValueError('Unrecognized node class: %s' % child_class) |
| 863 return type_node_to_type(child) | 924 return type_node_to_type(child) |
| 864 | 925 |
| 865 | 926 |
| 866 def union_type_node_to_idl_union_type(node): | 927 def union_type_node_to_idl_union_type(node): |
| 867 member_types = [type_node_to_type(member_type_node) | 928 member_types = [type_node_to_type(member_type_node) |
| 868 for member_type_node in node.GetChildren()] | 929 for member_type_node in node.GetChildren()] |
| 869 return IdlUnionType(member_types) | 930 return IdlUnionType(member_types) |
| OLD | NEW |