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

Side by Side Diff: Source/bindings/scripts/idl_types.py

Issue 386963003: [WIP][NotForLand] IDL dictionary support (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: sequence and array support Created 6 years, 5 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
OLDNEW
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 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 # IdlType 98 # IdlType
99 ################################################################################ 99 ################################################################################
100 100
101 class IdlType(object): 101 class IdlType(object):
102 # FIXME: incorporate Nullable, etc. 102 # FIXME: incorporate Nullable, etc.
103 # FIXME: use nested types: IdlArrayType, IdlNullableType, IdlSequenceType 103 # FIXME: use nested types: IdlArrayType, IdlNullableType, IdlSequenceType
104 # to support types like short?[] vs. short[]?, instead of treating these 104 # to support types like short?[] vs. short[]?, instead of treating these
105 # as orthogonal properties (via flags). 105 # as orthogonal properties (via flags).
106 callback_functions = set() 106 callback_functions = set()
107 callback_interfaces = set() 107 callback_interfaces = set()
108 dictionaries = set()
108 enums = {} # name -> values 109 enums = {} # name -> values
109 110
110 def __init__(self, base_type, is_array=False, is_sequence=False, is_nullable =False, is_unrestricted=False): 111 def __init__(self, base_type, is_array=False, is_sequence=False, is_nullable =False, is_unrestricted=False):
111 if is_array and is_sequence: 112 if is_array and is_sequence:
112 raise ValueError('Array of Sequences are not allowed.') 113 raise ValueError('Array of Sequences are not allowed.')
113 if is_unrestricted: 114 if is_unrestricted:
114 self.base_type = 'unrestricted %s' % base_type 115 self.base_type = 'unrestricted %s' % base_type
115 else: 116 else:
116 self.base_type = base_type 117 self.base_type = base_type
117 self.is_array = is_array 118 self.is_array = is_array
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 153
153 @property 154 @property
154 def is_callback_function(self): 155 def is_callback_function(self):
155 return self.base_type in IdlType.callback_functions 156 return self.base_type in IdlType.callback_functions
156 157
157 @property 158 @property
158 def is_callback_interface(self): 159 def is_callback_interface(self):
159 return self.base_type in IdlType.callback_interfaces 160 return self.base_type in IdlType.callback_interfaces
160 161
161 @property 162 @property
163 def is_dictionary(self):
164 return self.base_type in IdlType.dictionaries
165
166 @property
162 def is_composite_type(self): 167 def is_composite_type(self):
163 return (self.name == 'Any' or 168 return (self.name == 'Any' or
164 self.array_element_type or 169 self.array_element_type or
165 self.sequence_element_type or 170 self.sequence_element_type or
166 self.is_union_type) 171 self.is_union_type)
167 172
168 @property 173 @property
169 def is_enum(self): 174 def is_enum(self):
170 # FIXME: add an IdlEnumType class and a resolve_enums step at end of 175 # FIXME: add an IdlEnumType class and a resolve_enums step at end of
171 # IdlDefinitions constructor 176 # IdlDefinitions constructor
(...skipping 17 matching lines...) Expand all
189 194
190 @property 195 @property
191 def is_interface_type(self): 196 def is_interface_type(self):
192 # Anything that is not another type is an interface type. 197 # Anything that is not another type is an interface type.
193 # http://www.w3.org/TR/WebIDL/#idl-types 198 # http://www.w3.org/TR/WebIDL/#idl-types
194 # http://www.w3.org/TR/WebIDL/#idl-interface 199 # http://www.w3.org/TR/WebIDL/#idl-interface
195 # In C++ these are RefPtr or PassRefPtr types. 200 # In C++ these are RefPtr or PassRefPtr types.
196 return not(self.is_basic_type or 201 return not(self.is_basic_type or
197 self.is_composite_type or 202 self.is_composite_type or
198 self.is_callback_function or 203 self.is_callback_function or
204 self.is_dictionary or
199 self.is_enum or 205 self.is_enum or
200 self.name == 'Object' or 206 self.name == 'Object' or
201 self.name == 'Promise') # Promise will be basic in future 207 self.name == 'Promise') # Promise will be basic in future
202 208
203 @property 209 @property
204 def is_string_type(self): 210 def is_string_type(self):
205 return self.base_type_name in STRING_TYPES 211 return self.base_type_name in STRING_TYPES
206 212
207 @property 213 @property
208 def may_raise_exception_on_conversion(self): 214 def may_raise_exception_on_conversion(self):
(...skipping 26 matching lines...) Expand all
235 241
236 @classmethod 242 @classmethod
237 def set_callback_functions(cls, new_callback_functions): 243 def set_callback_functions(cls, new_callback_functions):
238 cls.callback_functions.update(new_callback_functions) 244 cls.callback_functions.update(new_callback_functions)
239 245
240 @classmethod 246 @classmethod
241 def set_callback_interfaces(cls, new_callback_interfaces): 247 def set_callback_interfaces(cls, new_callback_interfaces):
242 cls.callback_interfaces.update(new_callback_interfaces) 248 cls.callback_interfaces.update(new_callback_interfaces)
243 249
244 @classmethod 250 @classmethod
251 def set_dictionaries(cls, new_dictionaries):
252 cls.dictionaries.update(new_dictionaries)
253
254 @classmethod
245 def set_enums(cls, new_enums): 255 def set_enums(cls, new_enums):
246 cls.enums.update(new_enums) 256 cls.enums.update(new_enums)
247 257
248 def resolve_typedefs(self, typedefs): 258 def resolve_typedefs(self, typedefs):
249 if self.base_type not in typedefs: 259 if self.base_type not in typedefs:
250 return self 260 return self
251 new_type = typedefs[self.base_type] 261 new_type = typedefs[self.base_type]
252 if type(new_type) != type(self): 262 if type(new_type) != type(self):
253 # If type changes, need to return a different object, 263 # If type changes, need to return a different object,
254 # since can't change type(self) 264 # since can't change type(self)
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 308
299 @property 309 @property
300 def is_basic_type(self): 310 def is_basic_type(self):
301 return False 311 return False
302 312
303 @property 313 @property
304 def is_callback_function(self): 314 def is_callback_function(self):
305 return False 315 return False
306 316
307 @property 317 @property
318 def is_dictionary(self):
319 return False
320
321 @property
308 def is_enum(self): 322 def is_enum(self):
309 return False 323 return False
310 324
311 @property 325 @property
312 def is_integer_type(self): 326 def is_integer_type(self):
313 return False 327 return False
314 328
315 @property 329 @property
316 def is_numeric_type(self): 330 def is_numeric_type(self):
317 return False 331 return False
(...skipping 21 matching lines...) Expand all
339 353
340 @property 354 @property
341 def name(self): 355 def name(self):
342 return 'Or'.join(member_type.name for member_type in self.member_types) 356 return 'Or'.join(member_type.name for member_type in self.member_types)
343 357
344 def resolve_typedefs(self, typedefs): 358 def resolve_typedefs(self, typedefs):
345 self.member_types = [ 359 self.member_types = [
346 typedefs.get(member_type, member_type) 360 typedefs.get(member_type, member_type)
347 for member_type in self.member_types] 361 for member_type in self.member_types]
348 return self 362 return self
OLDNEW
« no previous file with comments | « Source/bindings/scripts/idl_reader.py ('k') | Source/bindings/scripts/interface_dependency_resolver.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698