Chromium Code Reviews| 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 30 matching lines...) Expand all Loading... | |
| 41 a generic call, via the resolve_typedefs() method. | 41 a generic call, via the resolve_typedefs() method. |
| 42 | 42 |
| 43 Class hierarchy (mostly containment, '<' for inheritance): | 43 Class hierarchy (mostly containment, '<' for inheritance): |
| 44 | 44 |
| 45 IdlDefinitions | 45 IdlDefinitions |
| 46 IdlCallbackFunction < TypedObject | 46 IdlCallbackFunction < TypedObject |
| 47 IdlEnum :: FIXME: remove, just use a dict for enums | 47 IdlEnum :: FIXME: remove, just use a dict for enums |
| 48 IdlInterface | 48 IdlInterface |
| 49 IdlAttribute < TypedObject | 49 IdlAttribute < TypedObject |
| 50 IdlConstant < TypedObject | 50 IdlConstant < TypedObject |
| 51 IdlLiteral | |
| 51 IdlOperation < TypedObject | 52 IdlOperation < TypedObject |
| 52 IdlArgument < TypedObject | 53 IdlArgument < TypedObject |
| 54 IdlStringifier | |
| 53 IdlException < IdlInterface | 55 IdlException < IdlInterface |
| 54 (same contents as IdlInterface) | 56 (same contents as IdlInterface) |
| 55 | 57 |
| 56 TypedObject :: mixin for typedef resolution | 58 TypedObject :: mixin for typedef resolution |
| 57 | 59 |
| 58 Design doc: http://www.chromium.org/developers/design-documents/idl-compiler | 60 Design doc: http://www.chromium.org/developers/design-documents/idl-compiler |
| 59 """ | 61 """ |
| 60 | 62 |
| 61 import abc | 63 import abc |
| 62 | 64 |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 254 | 256 |
| 255 class IdlInterface(object): | 257 class IdlInterface(object): |
| 256 def __init__(self, node=None): | 258 def __init__(self, node=None): |
| 257 self.attributes = [] | 259 self.attributes = [] |
| 258 self.constants = [] | 260 self.constants = [] |
| 259 self.constructors = [] | 261 self.constructors = [] |
| 260 self.custom_constructors = [] | 262 self.custom_constructors = [] |
| 261 self.extended_attributes = {} | 263 self.extended_attributes = {} |
| 262 self.operations = [] | 264 self.operations = [] |
| 263 self.parent = None | 265 self.parent = None |
| 266 self.stringifier = None | |
| 264 if not node: # Early exit for IdlException.__init__ | 267 if not node: # Early exit for IdlException.__init__ |
| 265 return | 268 return |
| 266 | 269 |
| 267 self.is_callback = node.GetProperty('CALLBACK') or False | 270 self.is_callback = node.GetProperty('CALLBACK') or False |
| 268 self.is_exception = False | 271 self.is_exception = False |
| 269 # FIXME: uppercase 'Partial' => 'PARTIAL' in base IDL parser | 272 # FIXME: uppercase 'Partial' => 'PARTIAL' in base IDL parser |
| 270 self.is_partial = node.GetProperty('Partial') or False | 273 self.is_partial = node.GetProperty('Partial') or False |
| 271 self.name = node.GetName() | 274 self.name = node.GetName() |
| 272 | 275 |
| 273 children = node.GetChildren() | 276 children = node.GetChildren() |
| 274 for child in children: | 277 for child in children: |
| 275 child_class = child.GetClass() | 278 child_class = child.GetClass() |
| 276 if child_class == 'Attribute': | 279 if child_class == 'Attribute': |
| 277 self.attributes.append(IdlAttribute(child)) | 280 self.attributes.append(IdlAttribute(child)) |
| 278 elif child_class == 'Const': | 281 elif child_class == 'Const': |
| 279 self.constants.append(IdlConstant(child)) | 282 self.constants.append(IdlConstant(child)) |
| 280 elif child_class == 'ExtAttributes': | 283 elif child_class == 'ExtAttributes': |
| 281 extended_attributes = ext_attributes_node_to_extended_attributes (child) | 284 extended_attributes = ext_attributes_node_to_extended_attributes (child) |
| 282 self.constructors, self.custom_constructors = ( | 285 self.constructors, self.custom_constructors = ( |
| 283 extended_attributes_to_constructors(extended_attributes)) | 286 extended_attributes_to_constructors(extended_attributes)) |
| 284 clear_constructor_attributes(extended_attributes) | 287 clear_constructor_attributes(extended_attributes) |
| 285 self.extended_attributes = extended_attributes | 288 self.extended_attributes = extended_attributes |
| 286 elif child_class == 'Operation': | 289 elif child_class == 'Operation': |
| 287 self.operations.append(IdlOperation(child)) | 290 self.operations.append(IdlOperation(child)) |
| 288 elif child_class == 'Inherit': | 291 elif child_class == 'Inherit': |
| 289 self.parent = child.GetName() | 292 self.parent = child.GetName() |
| 293 elif child_class == 'Stringifier': | |
| 294 self.stringifier = IdlStringifier(child) | |
| 295 self.process_stringifier() | |
| 290 else: | 296 else: |
| 291 raise ValueError('Unrecognized node class: %s' % child_class) | 297 raise ValueError('Unrecognized node class: %s' % child_class) |
| 292 | 298 |
| 293 def resolve_typedefs(self, typedefs): | 299 def resolve_typedefs(self, typedefs): |
| 294 for attribute in self.attributes: | 300 for attribute in self.attributes: |
| 295 attribute.resolve_typedefs(typedefs) | 301 attribute.resolve_typedefs(typedefs) |
| 296 for constant in self.constants: | 302 for constant in self.constants: |
| 297 constant.resolve_typedefs(typedefs) | 303 constant.resolve_typedefs(typedefs) |
| 298 for constructor in self.constructors: | 304 for constructor in self.constructors: |
| 299 constructor.resolve_typedefs(typedefs) | 305 constructor.resolve_typedefs(typedefs) |
| 300 for custom_constructor in self.custom_constructors: | 306 for custom_constructor in self.custom_constructors: |
| 301 custom_constructor.resolve_typedefs(typedefs) | 307 custom_constructor.resolve_typedefs(typedefs) |
| 302 for operation in self.operations: | 308 for operation in self.operations: |
| 303 operation.resolve_typedefs(typedefs) | 309 operation.resolve_typedefs(typedefs) |
| 304 | 310 |
| 311 def process_stringifier(self): | |
| 312 """Add the stringifier's attribute or named operation child, if it has | |
| 313 one, as a regular attribute/operation of this interface.""" | |
| 314 if self.stringifier.attribute: | |
| 315 self.attributes.append(self.stringifier.attribute) | |
| 316 elif self.stringifier.operation and self.stringifier.operation.name: | |
|
haraken
2014/06/24 08:28:36
Do we need the 'and self.stringifier.operation.nam
Jens Widell
2014/06/24 08:38:43
Need that check somewhere because there will be an
| |
| 317 self.operations.append(self.stringifier.operation) | |
| 318 | |
| 305 def merge(self, other): | 319 def merge(self, other): |
| 306 """Merge in another interface's members (e.g., partial interface)""" | 320 """Merge in another interface's members (e.g., partial interface)""" |
| 307 self.attributes.extend(other.attributes) | 321 self.attributes.extend(other.attributes) |
| 308 self.constants.extend(other.constants) | 322 self.constants.extend(other.constants) |
| 309 self.operations.extend(other.operations) | 323 self.operations.extend(other.operations) |
| 310 | 324 |
| 311 | 325 |
| 312 class IdlException(IdlInterface): | 326 class IdlException(IdlInterface): |
| 313 # Properly exceptions and interfaces are distinct, and thus should inherit a | 327 # Properly exceptions and interfaces are distinct, and thus should inherit a |
| 314 # common base class (say, "IdlExceptionOrInterface"). | 328 # common base class (say, "IdlExceptionOrInterface"). |
| (...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 555 # have None instead of an arguments node, but have the same meaning as using | 569 # have None instead of an arguments node, but have the same meaning as using |
| 556 # an empty argument list, [Constructor()], so special-case this. | 570 # an empty argument list, [Constructor()], so special-case this. |
| 557 # http://www.w3.org/TR/WebIDL/#Constructor | 571 # http://www.w3.org/TR/WebIDL/#Constructor |
| 558 if node is None: | 572 if node is None: |
| 559 return [] | 573 return [] |
| 560 return [IdlArgument(argument_node) | 574 return [IdlArgument(argument_node) |
| 561 for argument_node in node.GetChildren()] | 575 for argument_node in node.GetChildren()] |
| 562 | 576 |
| 563 | 577 |
| 564 ################################################################################ | 578 ################################################################################ |
| 579 # Stringifiers | |
| 580 ################################################################################ | |
| 581 | |
| 582 class IdlStringifier(object): | |
| 583 def __init__(self, node): | |
| 584 self.attribute = None | |
| 585 self.operation = None | |
| 586 self.extended_attributes = {} | |
| 587 | |
| 588 for child in node.GetChildren(): | |
| 589 child_class = child.GetClass() | |
| 590 if child_class == 'Attribute': | |
| 591 self.attribute = IdlAttribute(child) | |
| 592 elif child_class == 'Operation': | |
| 593 self.operation = IdlOperation(child) | |
| 594 elif child_class == 'ExtAttributes': | |
| 595 self.extended_attributes = ext_attributes_node_to_extended_attri butes(child) | |
| 596 else: | |
| 597 raise ValueError('Unrecognized node class: %s' % child_class) | |
| 598 | |
| 599 # Copy the stringifier's extended attributes (such as [Unforgable]) onto | |
| 600 # the underlying attribute or operation, if there is one. | |
| 601 if self.attribute or self.operation: | |
| 602 (self.attribute or self.operation).extended_attributes.update( | |
| 603 self.extended_attributes) | |
| 604 | |
| 605 | |
| 606 ################################################################################ | |
| 565 # Extended attributes | 607 # Extended attributes |
| 566 ################################################################################ | 608 ################################################################################ |
| 567 | 609 |
| 568 def ext_attributes_node_to_extended_attributes(node): | 610 def ext_attributes_node_to_extended_attributes(node): |
| 569 """ | 611 """ |
| 570 Returns: | 612 Returns: |
| 571 Dictionary of {ExtAttributeName: ExtAttributeValue}. | 613 Dictionary of {ExtAttributeName: ExtAttributeValue}. |
| 572 Value is usually a string, with three exceptions: | 614 Value is usually a string, with three exceptions: |
| 573 Constructors: value is a list of Arguments nodes, corresponding to | 615 Constructors: value is a list of Arguments nodes, corresponding to |
| 574 possible signatures of the constructor. | 616 possible signatures of the constructor. |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 747 child_class = child.GetClass() | 789 child_class = child.GetClass() |
| 748 if child_class != 'Type': | 790 if child_class != 'Type': |
| 749 raise ValueError('Unrecognized node class: %s' % child_class) | 791 raise ValueError('Unrecognized node class: %s' % child_class) |
| 750 return type_node_to_type(child) | 792 return type_node_to_type(child) |
| 751 | 793 |
| 752 | 794 |
| 753 def union_type_node_to_idl_union_type(node, is_nullable=False): | 795 def union_type_node_to_idl_union_type(node, is_nullable=False): |
| 754 member_types = [type_node_to_type(member_type_node) | 796 member_types = [type_node_to_type(member_type_node) |
| 755 for member_type_node in node.GetChildren()] | 797 for member_type_node in node.GetChildren()] |
| 756 return IdlUnionType(member_types, is_nullable=is_nullable) | 798 return IdlUnionType(member_types, is_nullable=is_nullable) |
| OLD | NEW |