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

Side by Side Diff: tools/dom/scripts/idlnode.py

Issue 1763063003: Fixed typedef used globally in IDLs (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 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
« no previous file with comments | « tools/dom/scripts/generator.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 # Report of union types mapped to any. 15 # Report of union types mapped to any.
16 _unions_to_any = [] 16 _unions_to_any = []
17 17
18 def report_unions_to_any(): 18 def report_unions_to_any():
19 global _unions_to_any 19 global _unions_to_any
20 20
21 warnings = [] 21 warnings = []
22 for union_id in sorted(_unions_to_any): 22 for union_id in sorted(_unions_to_any):
23 warnings.append('Union type %s is mapped to \'any\'' % union_id) 23 warnings.append('Union type %s is mapped to \'any\'' % union_id)
24 24
25 return warnings 25 return warnings
26 26
27 # Ugly but Chrome IDLs can reference typedefs in any IDL w/o an include. So we 27 # Ugly but Chrome IDLs can reference typedefs in any IDL w/o an include. So we
28 # need to remember any typedef seen then alias any reference to a typedef. 28 # need to remember any typedef seen then alias any reference to a typedef.
29 typeDefsFixup = [] 29 _typeDefsFixup = []
30 30
31 def _resolveTypedef(type): 31 def _addTypedef(typedef):
32 _typeDefsFixup.append(typedef)
33
34 def resolveTypedef(type):
32 """ Given a type if it's a known typedef (only typedef's that aren't union) 35 """ Given a type if it's a known typedef (only typedef's that aren't union)
33 are remembered for fixup. typedefs that are union type are mapped to 36 are remembered for fixup. typedefs that are union type are mapped to
34 any so those we don't need to alias. typedefs referenced in the file 37 any so those we don't need to alias. typedefs referenced in the file
35 where the typedef was defined are automatically aliased to the real type. 38 where the typedef was defined are automatically aliased to the real type.
36 This resolves typedef where the declaration is in another IDL file. 39 This resolves typedef where the declaration is in another IDL file.
37 """ 40 """
38 for typedef in typeDefsFixup: 41 for typedef in _typeDefsFixup:
39 if typedef.id == type.id: 42 if typedef.id == type.id:
40 return typedef.type 43 return typedef.type
41 44
42 return type 45 return type
43 46
44 47
45 _operation_suffix_map = { 48 _operation_suffix_map = {
46 '__getter__': "Getter", 49 '__getter__': "Getter",
47 '__setter__': "Setter", 50 '__setter__': "Setter",
48 '__delete__': "Deleter", 51 '__delete__': "Deleter",
(...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after
432 # Hack to record typedefs that are unions. 435 # Hack to record typedefs that are unions.
433 for typedefName in ast.typedefs: 436 for typedefName in ast.typedefs:
434 typedef_type = ast.typedefs[typedefName] 437 typedef_type = ast.typedefs[typedefName]
435 if isinstance(typedef_type.idl_type, IdlUnionType): 438 if isinstance(typedef_type.idl_type, IdlUnionType):
436 self.typeDefs.append(IDLTypeDef(typedef_type)) 439 self.typeDefs.append(IDLTypeDef(typedef_type))
437 elif typedef_type.idl_type.base_type == 'Dictionary': 440 elif typedef_type.idl_type.base_type == 'Dictionary':
438 dictionary = IDLDictionary(typedef_type, True) 441 dictionary = IDLDictionary(typedef_type, True)
439 self.dictionaries.append(dictionary) 442 self.dictionaries.append(dictionary)
440 else: 443 else:
441 # All other typedefs we record 444 # All other typedefs we record
442 typeDefsFixup.append(IDLTypeDef(typedef_type)) 445 _addTypedef(IDLTypeDef(typedef_type))
443 446
444 self.enums = self._convert_all(ast, 'Enum', IDLEnum) 447 self.enums = self._convert_all(ast, 'Enum', IDLEnum)
445 448
446 def _createImplementsStatement(self, implementor, implemented_name): 449 def _createImplementsStatement(self, implementor, implemented_name):
447 implemented = new_asts[implemented_name].interfaces.get(implemented_name) 450 implemented = new_asts[implemented_name].interfaces.get(implemented_name)
448 451
449 implement_statement = IDLImplementsStatement(implemented) 452 implement_statement = IDLImplementsStatement(implemented)
450 453
451 implement_statement.implementor = IDLType(implementor) 454 implement_statement.implementor = IDLType(implementor)
452 implement_statement.implemented = IDLType(implemented) 455 implement_statement.implemented = IDLType(implemented)
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after
780 self.type = self._convert_first(ast, 'InterfaceType', IDLType) 783 self.type = self._convert_first(ast, 'InterfaceType', IDLType)
781 784
782 785
783 class IDLMember(IDLNode): 786 class IDLMember(IDLNode):
784 """A base class for constants, attributes and operations.""" 787 """A base class for constants, attributes and operations."""
785 788
786 def __init__(self, ast, doc_js_interface_name): 789 def __init__(self, ast, doc_js_interface_name):
787 IDLNode.__init__(self, ast) 790 IDLNode.__init__(self, ast)
788 791
789 self.type = self._convert_first(ast, 'Type', IDLType) 792 self.type = self._convert_first(ast, 'Type', IDLType)
790 self.type = _resolveTypedef(self.type) 793 self.type = resolveTypedef(self.type)
791 794
792 self._convert_ext_attrs(ast) 795 self._convert_ext_attrs(ast)
793 self._convert_annotations(ast) 796 self._convert_annotations(ast)
794 self.doc_js_interface_name = doc_js_interface_name 797 self.doc_js_interface_name = doc_js_interface_name
795 # TODO(terry): Can eliminate Suppressed when we're only using blink parser. 798 # TODO(terry): Can eliminate Suppressed when we're only using blink parser.
796 self.is_fc_suppressed = 'Suppressed' in self.ext_attrs or \ 799 self.is_fc_suppressed = 'Suppressed' in self.ext_attrs or \
797 'DartSuppress' in self.ext_attrs 800 'DartSuppress' in self.ext_attrs
798 self.is_static = self._has(ast, 'Static') 801 self.is_static = self._has(ast, 'Static')
799 802
800 class IDLOperation(IDLMember): 803 class IDLOperation(IDLMember):
801 """IDLNode specialization for 'type name(args)' declarations.""" 804 """IDLNode specialization for 'type name(args)' declarations."""
802 def __init__(self, ast, doc_js_interface_name): 805 def __init__(self, ast, doc_js_interface_name):
803 IDLMember.__init__(self, ast, doc_js_interface_name) 806 IDLMember.__init__(self, ast, doc_js_interface_name)
804 807
805 self.type = self._convert_first(ast, 'ReturnType', IDLType) 808 self.type = self._convert_first(ast, 'ReturnType', IDLType)
806 self.type = _resolveTypedef(self.type) 809 self.type = resolveTypedef(self.type)
810
807 self.arguments = self._convert_all(ast, 'Argument', IDLArgument) 811 self.arguments = self._convert_all(ast, 'Argument', IDLArgument)
808 self.specials = self._find_all(ast, 'Special') 812 self.specials = self._find_all(ast, 'Special')
809 # Special case: there are getters of the form 813 # Special case: there are getters of the form
810 # getter <ReturnType>(args). For now force the name to be __getter__, 814 # getter <ReturnType>(args). For now force the name to be __getter__,
811 # but it should be operator[] later. 815 # but it should be operator[] later.
812 if self.id is None: 816 if self.id is None:
813 if self.specials == ['getter']: 817 if self.specials == ['getter']:
814 if self.ext_attrs.get('Custom') == 'PropertyQuery': 818 if self.ext_attrs.get('Custom') == 'PropertyQuery':
815 # Handling __propertyQuery__ the extended attribute is: 819 # Handling __propertyQuery__ the extended attribute is:
816 # [Custom=PropertyQuery] getter boolean (DOMString name); 820 # [Custom=PropertyQuery] getter boolean (DOMString name);
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
874 if isinstance(ast.default_value, idl_definitions.IdlLiteral) and ast.defau lt_value: 878 if isinstance(ast.default_value, idl_definitions.IdlLiteral) and ast.defau lt_value:
875 self.default_value = ast.default_value.value 879 self.default_value = ast.default_value.value
876 self.default_value_is_null = ast.default_value.is_null 880 self.default_value_is_null = ast.default_value.is_null
877 elif 'Default' in ast.extended_attributes: 881 elif 'Default' in ast.extended_attributes:
878 # Work around [Default=Undefined] for arguments - only look in the model 's 882 # Work around [Default=Undefined] for arguments - only look in the model 's
879 # default_value 883 # default_value
880 self.default_value = ast.extended_attributes.get('Default') 884 self.default_value = ast.extended_attributes.get('Default')
881 self.default_value_is_null = False 885 self.default_value_is_null = False
882 886
883 self.type = self._convert_first(ast, 'Type', IDLType) 887 self.type = self._convert_first(ast, 'Type', IDLType)
884 self.type = _resolveTypedef(self.type) 888 self.type = resolveTypedef(self.type)
885 889
886 self.optional = self._has(ast, 'Optional') 890 self.optional = self._has(ast, 'Optional')
887 self._convert_ext_attrs(ast) 891 self._convert_ext_attrs(ast)
888 # TODO(vsm): Recover this from the type instead. 892 # TODO(vsm): Recover this from the type instead.
889 if 'Callback' in self.type.id: 893 if 'Callback' in self.type.id:
890 self.ext_attrs['Callback'] = None 894 self.ext_attrs['Callback'] = None
891 895
892 def __repr__(self): 896 def __repr__(self):
893 return '<IDLArgument(type = %s, id = %s)>' % (self.type, self.id) 897 return '<IDLArgument(type = %s, id = %s)>' % (self.type, self.id)
894 898
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
927 """IDLDictNode specialization for one annotation.""" 931 """IDLDictNode specialization for one annotation."""
928 def __init__(self, ast=None): 932 def __init__(self, ast=None):
929 IDLDictNode.__init__(self, ast) 933 IDLDictNode.__init__(self, ast)
930 self.id = None 934 self.id = None
931 if not ast: 935 if not ast:
932 return 936 return
933 for arg in self._find_all(ast, 'AnnotationArg'): 937 for arg in self._find_all(ast, 'AnnotationArg'):
934 name = self._find_first(arg, 'Id') 938 name = self._find_first(arg, 'Id')
935 value = self._find_first(arg, 'AnnotationArgValue') 939 value = self._find_first(arg, 'AnnotationArgValue')
936 self[name] = value 940 self[name] = value
OLDNEW
« no previous file with comments | « tools/dom/scripts/generator.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698