OLD | NEW |
1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 """IDL type handling. | 4 """IDL type handling. |
5 | 5 |
6 Classes: | 6 Classes: |
7 IdlTypeBase | 7 IdlTypeBase |
8 IdlType | 8 IdlType |
9 IdlUnionType | 9 IdlUnionType |
10 IdlArrayOrSequenceType | 10 IdlArrayOrSequenceType |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 } | 77 } |
78 | 78 |
79 STRING_TYPES = frozenset([ | 79 STRING_TYPES = frozenset([ |
80 # http://heycam.github.io/webidl/#es-interface-call (step 10.11) | 80 # http://heycam.github.io/webidl/#es-interface-call (step 10.11) |
81 # (Interface object [[Call]] method's string types.) | 81 # (Interface object [[Call]] method's string types.) |
82 'String', | 82 'String', |
83 'ByteString', | 83 'ByteString', |
84 'USVString', | 84 'USVString', |
85 ]) | 85 ]) |
86 | 86 |
| 87 STANDARD_CALLBACK_FUNCTIONS = frozenset([ |
| 88 # http://heycam.github.io/webidl/#common-Function |
| 89 'Function', |
| 90 # http://heycam.github.io/webidl/#common-VoidFunction |
| 91 'VoidFunction', |
| 92 ]) |
| 93 |
87 | 94 |
88 ################################################################################ | 95 ################################################################################ |
89 # Inheritance | 96 # Inheritance |
90 ################################################################################ | 97 ################################################################################ |
91 | 98 |
92 ancestors = defaultdict(list) # interface_name -> ancestors | 99 ancestors = defaultdict(list) # interface_name -> ancestors |
93 | 100 |
94 def inherits_interface(interface_name, ancestor_name): | 101 def inherits_interface(interface_name, ancestor_name): |
95 return (interface_name == ancestor_name or | 102 return (interface_name == ancestor_name or |
96 ancestor_name in ancestors[interface_name]) | 103 ancestor_name in ancestors[interface_name]) |
(...skipping 22 matching lines...) Expand all Loading... |
119 | 126 |
120 | 127 |
121 ################################################################################ | 128 ################################################################################ |
122 # IdlType | 129 # IdlType |
123 ################################################################################ | 130 ################################################################################ |
124 | 131 |
125 class IdlType(IdlTypeBase): | 132 class IdlType(IdlTypeBase): |
126 # FIXME: incorporate Nullable, etc. | 133 # FIXME: incorporate Nullable, etc. |
127 # to support types like short?[] vs. short[]?, instead of treating these | 134 # to support types like short?[] vs. short[]?, instead of treating these |
128 # as orthogonal properties (via flags). | 135 # as orthogonal properties (via flags). |
129 callback_functions = set() | 136 callback_functions = set(STANDARD_CALLBACK_FUNCTIONS) |
130 callback_interfaces = set() | 137 callback_interfaces = set() |
131 dictionaries = set() | 138 dictionaries = set() |
132 enums = {} # name -> values | 139 enums = {} # name -> values |
133 | 140 |
134 def __init__(self, base_type, is_unrestricted=False): | 141 def __init__(self, base_type, is_unrestricted=False): |
135 super(IdlType, self).__init__() | 142 super(IdlType, self).__init__() |
136 if is_unrestricted: | 143 if is_unrestricted: |
137 self.base_type = 'unrestricted %s' % base_type | 144 self.base_type = 'unrestricted %s' % base_type |
138 else: | 145 else: |
139 self.base_type = base_type | 146 self.base_type = base_type |
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
395 def is_nullable(self): | 402 def is_nullable(self): |
396 return True | 403 return True |
397 | 404 |
398 @property | 405 @property |
399 def name(self): | 406 def name(self): |
400 return self.inner_type.name + 'OrNull' | 407 return self.inner_type.name + 'OrNull' |
401 | 408 |
402 def resolve_typedefs(self, typedefs): | 409 def resolve_typedefs(self, typedefs): |
403 self.inner_type = self.inner_type.resolve_typedefs(typedefs) | 410 self.inner_type = self.inner_type.resolve_typedefs(typedefs) |
404 return self | 411 return self |
OLD | NEW |