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 IdlType | 7 IdlType |
8 IdlUnionType | 8 IdlUnionType |
9 """ | 9 """ |
10 | 10 |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
63 'unrestricted float': 'UnrestrictedFloat', | 63 'unrestricted float': 'UnrestrictedFloat', |
64 'double': 'Double', | 64 'double': 'Double', |
65 'unrestricted double': 'UnrestrictedDouble', | 65 'unrestricted double': 'UnrestrictedDouble', |
66 'DOMString': 'String', | 66 'DOMString': 'String', |
67 'ByteString': 'ByteString', | 67 'ByteString': 'ByteString', |
68 'ScalarValueString': 'ScalarValueString', | 68 'ScalarValueString': 'ScalarValueString', |
69 'object': 'Object', | 69 'object': 'Object', |
70 'Date': 'Date', | 70 'Date': 'Date', |
71 } | 71 } |
72 | 72 |
73 STRING_TYPES = frozenset([ | |
74 # http://heycam.github.io/webidl/, Section 4.5.1.1.10.11 (Interface object [ [Call]] method) | |
75 'String', | |
76 'ByteString', | |
77 'ScalarValueString', | |
78 ]) | |
79 | |
80 | |
jsbell
2014/06/19 20:49:19
Nit: remove one of these blank lines
sof
2014/06/20 07:21:16
Done.
| |
73 | 81 |
74 ################################################################################ | 82 ################################################################################ |
75 # Inheritance | 83 # Inheritance |
76 ################################################################################ | 84 ################################################################################ |
77 | 85 |
78 ancestors = defaultdict(list) # interface_name -> ancestors | 86 ancestors = defaultdict(list) # interface_name -> ancestors |
79 | 87 |
80 def inherits_interface(interface_name, ancestor_name): | 88 def inherits_interface(interface_name, ancestor_name): |
81 return (interface_name == ancestor_name or | 89 return (interface_name == ancestor_name or |
82 ancestor_name in ancestors[interface_name]) | 90 ancestor_name in ancestors[interface_name]) |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
188 # http://www.w3.org/TR/WebIDL/#idl-interface | 196 # http://www.w3.org/TR/WebIDL/#idl-interface |
189 # In C++ these are RefPtr or PassRefPtr types. | 197 # In C++ these are RefPtr or PassRefPtr types. |
190 return not(self.is_basic_type or | 198 return not(self.is_basic_type or |
191 self.is_composite_type or | 199 self.is_composite_type or |
192 self.is_callback_function or | 200 self.is_callback_function or |
193 self.is_enum or | 201 self.is_enum or |
194 self.name == 'Object' or | 202 self.name == 'Object' or |
195 self.name == 'Promise') # Promise will be basic in future | 203 self.name == 'Promise') # Promise will be basic in future |
196 | 204 |
197 @property | 205 @property |
206 def is_string_type(self): | |
207 return self.name in STRING_TYPES | |
208 | |
209 @property | |
210 def may_raise_exception_on_conversion(self): | |
jsbell
2014/06/19 20:49:19
We may want to refactor the conversions even furth
jsbell
2014/06/19 20:50:26
... but that should be a follow-up CL.
| |
211 return (self.is_integer_type or | |
212 self.name in ('ByteString', 'ScalarValueString')) | |
213 | |
214 @property | |
198 def is_union_type(self): | 215 def is_union_type(self): |
199 return isinstance(self, IdlUnionType) | 216 return isinstance(self, IdlUnionType) |
200 | 217 |
201 @property | 218 @property |
202 def name(self): | 219 def name(self): |
203 """Return type name. | 220 """Return type name. |
204 | 221 |
205 http://heycam.github.io/webidl/#dfn-type-name | 222 http://heycam.github.io/webidl/#dfn-type-name |
206 """ | 223 """ |
207 base_type = self.base_type | 224 base_type = self.base_type |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
312 | 329 |
313 @property | 330 @property |
314 def name(self): | 331 def name(self): |
315 return 'Or'.join(member_type.name for member_type in self.member_types) | 332 return 'Or'.join(member_type.name for member_type in self.member_types) |
316 | 333 |
317 def resolve_typedefs(self, typedefs): | 334 def resolve_typedefs(self, typedefs): |
318 self.member_types = [ | 335 self.member_types = [ |
319 typedefs.get(member_type, member_type) | 336 typedefs.get(member_type, member_type) |
320 for member_type in self.member_types] | 337 for member_type in self.member_types] |
321 return self | 338 return self |
OLD | NEW |