| OLD | NEW |
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 # Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 2 # Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
| 3 # for details. All rights reserved. Use of this source code is governed by a | 3 # for details. All rights reserved. Use of this source code is governed by a |
| 4 # BSD-style license that can be found in the LICENSE file. | 4 # BSD-style license that can be found in the LICENSE file. |
| 5 | 5 |
| 6 import os | 6 import os |
| 7 import sys | 7 import sys |
| 8 | 8 |
| 9 import idl_definitions | 9 import idl_definitions |
| 10 from idl_types import IdlType, IdlNullableType, IdlUnionType, IdlArrayOrSequence
Type | 10 from idl_types import IdlType, IdlNullableType, IdlUnionType, IdlArrayOrSequence
Type |
| 11 import dependency | 11 import dependency |
| 12 | 12 |
| 13 new_asts = {} | 13 new_asts = {} |
| 14 | 14 |
| 15 # Ugly but Chrome IDLs can reference typedefs in any IDL w/o an include. So we |
| 16 # need to remember any typedef seen then alias any reference to a typedef. |
| 17 typeDefsFixup = [] |
| 18 |
| 19 def _resolveTypedef(type): |
| 20 """ Given a type if it's a known typedef (only typedef's that aren't union) |
| 21 are remembered for fixup. typedefs that are union type are mapped to |
| 22 any so those we don't need to alias. typedefs referenced in the file |
| 23 where the typedef was defined are automatically aliased to the real type. |
| 24 This resolves typedef where the declaration is in another IDL file. |
| 25 """ |
| 26 for typedef in typeDefsFixup: |
| 27 if typedef.id == type.id: |
| 28 return typedef.type |
| 29 |
| 30 return type |
| 31 |
| 15 | 32 |
| 16 _operation_suffix_map = { | 33 _operation_suffix_map = { |
| 17 '__getter__': "Getter", | 34 '__getter__': "Getter", |
| 18 '__setter__': "Setter", | 35 '__setter__': "Setter", |
| 19 '__delete__': "Deleter", | 36 '__delete__': "Deleter", |
| 20 } | 37 } |
| 21 | 38 |
| 22 class IDLNode(object): | 39 class IDLNode(object): |
| 23 """Base class for all IDL elements. | 40 """Base class for all IDL elements. |
| 24 IDLNode may contain various child nodes, and have properties. Examples | 41 IDLNode may contain various child nodes, and have properties. Examples |
| (...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 399 self.typeDefs = [] if is_blink else self._convert_all(ast, 'TypeDef', IDLTyp
eDef) | 416 self.typeDefs = [] if is_blink else self._convert_all(ast, 'TypeDef', IDLTyp
eDef) |
| 400 | 417 |
| 401 # Hack to record typedefs that are unions. | 418 # Hack to record typedefs that are unions. |
| 402 for typedefName in ast.typedefs: | 419 for typedefName in ast.typedefs: |
| 403 typedef_type = ast.typedefs[typedefName] | 420 typedef_type = ast.typedefs[typedefName] |
| 404 if isinstance(typedef_type.idl_type, IdlUnionType): | 421 if isinstance(typedef_type.idl_type, IdlUnionType): |
| 405 self.typeDefs.append(IDLTypeDef(typedef_type)) | 422 self.typeDefs.append(IDLTypeDef(typedef_type)) |
| 406 elif typedef_type.idl_type.base_type == 'Dictionary': | 423 elif typedef_type.idl_type.base_type == 'Dictionary': |
| 407 dictionary = IDLDictionary(typedef_type, True) | 424 dictionary = IDLDictionary(typedef_type, True) |
| 408 self.dictionaries.append(dictionary) | 425 self.dictionaries.append(dictionary) |
| 426 else: |
| 427 # All other typedefs we record |
| 428 typeDefsFixup.append(IDLTypeDef(typedef_type)) |
| 409 | 429 |
| 410 self.enums = self._convert_all(ast, 'Enum', IDLEnum) | 430 self.enums = self._convert_all(ast, 'Enum', IDLEnum) |
| 411 | 431 |
| 412 def _createImplementsStatement(self, implementor, implemented_name): | 432 def _createImplementsStatement(self, implementor, implemented_name): |
| 413 implemented = new_asts[implemented_name].interfaces.get(implemented_name) | 433 implemented = new_asts[implemented_name].interfaces.get(implemented_name) |
| 414 | 434 |
| 415 implement_statement = IDLImplementsStatement(implemented) | 435 implement_statement = IDLImplementsStatement(implemented) |
| 416 | 436 |
| 417 implement_statement.implementor = IDLType(implementor) | 437 implement_statement.implementor = IDLType(implementor) |
| 418 implement_statement.implemented = IDLType(implemented) | 438 implement_statement.implemented = IDLType(implemented) |
| (...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 741 self.type = self._convert_first(ast, 'InterfaceType', IDLType) | 761 self.type = self._convert_first(ast, 'InterfaceType', IDLType) |
| 742 | 762 |
| 743 | 763 |
| 744 class IDLMember(IDLNode): | 764 class IDLMember(IDLNode): |
| 745 """A base class for constants, attributes and operations.""" | 765 """A base class for constants, attributes and operations.""" |
| 746 | 766 |
| 747 def __init__(self, ast, doc_js_interface_name): | 767 def __init__(self, ast, doc_js_interface_name): |
| 748 IDLNode.__init__(self, ast) | 768 IDLNode.__init__(self, ast) |
| 749 | 769 |
| 750 self.type = self._convert_first(ast, 'Type', IDLType) | 770 self.type = self._convert_first(ast, 'Type', IDLType) |
| 771 self.type = _resolveTypedef(self.type) |
| 772 |
| 751 self._convert_ext_attrs(ast) | 773 self._convert_ext_attrs(ast) |
| 752 self._convert_annotations(ast) | 774 self._convert_annotations(ast) |
| 753 self.doc_js_interface_name = doc_js_interface_name | 775 self.doc_js_interface_name = doc_js_interface_name |
| 754 # TODO(terry): Can eliminate Suppressed when we're only using blink parser. | 776 # TODO(terry): Can eliminate Suppressed when we're only using blink parser. |
| 755 self.is_fc_suppressed = 'Suppressed' in self.ext_attrs or \ | 777 self.is_fc_suppressed = 'Suppressed' in self.ext_attrs or \ |
| 756 'DartSuppress' in self.ext_attrs | 778 'DartSuppress' in self.ext_attrs |
| 757 self.is_static = self._has(ast, 'Static') | 779 self.is_static = self._has(ast, 'Static') |
| 758 | 780 |
| 759 | |
| 760 class IDLOperation(IDLMember): | 781 class IDLOperation(IDLMember): |
| 761 """IDLNode specialization for 'type name(args)' declarations.""" | 782 """IDLNode specialization for 'type name(args)' declarations.""" |
| 762 def __init__(self, ast, doc_js_interface_name): | 783 def __init__(self, ast, doc_js_interface_name): |
| 763 IDLMember.__init__(self, ast, doc_js_interface_name) | 784 IDLMember.__init__(self, ast, doc_js_interface_name) |
| 764 | 785 |
| 765 self.type = self._convert_first(ast, 'ReturnType', IDLType) | 786 self.type = self._convert_first(ast, 'ReturnType', IDLType) |
| 787 self.type = _resolveTypedef(self.type) |
| 766 self.arguments = self._convert_all(ast, 'Argument', IDLArgument) | 788 self.arguments = self._convert_all(ast, 'Argument', IDLArgument) |
| 767 self.specials = self._find_all(ast, 'Special') | 789 self.specials = self._find_all(ast, 'Special') |
| 768 # Special case: there are getters of the form | 790 # Special case: there are getters of the form |
| 769 # getter <ReturnType>(args). For now force the name to be __getter__, | 791 # getter <ReturnType>(args). For now force the name to be __getter__, |
| 770 # but it should be operator[] later. | 792 # but it should be operator[] later. |
| 771 if self.id is None: | 793 if self.id is None: |
| 772 if self.specials == ['getter']: | 794 if self.specials == ['getter']: |
| 773 if self.ext_attrs.get('Custom') == 'PropertyQuery': | 795 if self.ext_attrs.get('Custom') == 'PropertyQuery': |
| 774 # Handling __propertyQuery__ the extended attribute is: | 796 # Handling __propertyQuery__ the extended attribute is: |
| 775 # [Custom=PropertyQuery] getter boolean (DOMString name); | 797 # [Custom=PropertyQuery] getter boolean (DOMString name); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 833 if isinstance(ast.default_value, idl_definitions.IdlLiteral) and ast.defau
lt_value: | 855 if isinstance(ast.default_value, idl_definitions.IdlLiteral) and ast.defau
lt_value: |
| 834 self.default_value = ast.default_value.value | 856 self.default_value = ast.default_value.value |
| 835 self.default_value_is_null = ast.default_value.is_null | 857 self.default_value_is_null = ast.default_value.is_null |
| 836 elif 'Default' in ast.extended_attributes: | 858 elif 'Default' in ast.extended_attributes: |
| 837 # Work around [Default=Undefined] for arguments - only look in the model
's | 859 # Work around [Default=Undefined] for arguments - only look in the model
's |
| 838 # default_value | 860 # default_value |
| 839 self.default_value = ast.extended_attributes.get('Default') | 861 self.default_value = ast.extended_attributes.get('Default') |
| 840 self.default_value_is_null = False | 862 self.default_value_is_null = False |
| 841 | 863 |
| 842 self.type = self._convert_first(ast, 'Type', IDLType) | 864 self.type = self._convert_first(ast, 'Type', IDLType) |
| 865 self.type = _resolveTypedef(self.type) |
| 866 |
| 843 self.optional = self._has(ast, 'Optional') | 867 self.optional = self._has(ast, 'Optional') |
| 844 self._convert_ext_attrs(ast) | 868 self._convert_ext_attrs(ast) |
| 845 # TODO(vsm): Recover this from the type instead. | 869 # TODO(vsm): Recover this from the type instead. |
| 846 if 'Callback' in self.type.id: | 870 if 'Callback' in self.type.id: |
| 847 self.ext_attrs['Callback'] = None | 871 self.ext_attrs['Callback'] = None |
| 848 | 872 |
| 849 def __repr__(self): | 873 def __repr__(self): |
| 850 return '<IDLArgument(type = %s, id = %s)>' % (self.type, self.id) | 874 return '<IDLArgument(type = %s, id = %s)>' % (self.type, self.id) |
| 851 | 875 |
| 852 | 876 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 884 """IDLDictNode specialization for one annotation.""" | 908 """IDLDictNode specialization for one annotation.""" |
| 885 def __init__(self, ast=None): | 909 def __init__(self, ast=None): |
| 886 IDLDictNode.__init__(self, ast) | 910 IDLDictNode.__init__(self, ast) |
| 887 self.id = None | 911 self.id = None |
| 888 if not ast: | 912 if not ast: |
| 889 return | 913 return |
| 890 for arg in self._find_all(ast, 'AnnotationArg'): | 914 for arg in self._find_all(ast, 'AnnotationArg'): |
| 891 name = self._find_first(arg, 'Id') | 915 name = self._find_first(arg, 'Id') |
| 892 value = self._find_first(arg, 'AnnotationArgValue') | 916 value = self._find_first(arg, 'AnnotationArgValue') |
| 893 self[name] = value | 917 self[name] = value |
| OLD | NEW |