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

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

Issue 257783003: Basic support for unrestricted types (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 8 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 | Annotate | Revision Log
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
11 from collections import defaultdict 11 from collections import defaultdict
12 12
13 13
14 ################################################################################ 14 ################################################################################
15 # IDL types 15 # IDL types
16 ################################################################################ 16 ################################################################################
17 17
18 BASIC_TYPES = set([ 18 BASIC_TYPES = set([
19 # Built-in, non-composite, non-object data types 19 # Built-in, non-composite, non-object data types
20 # http://www.w3.org/TR/WebIDL/#dfn-primitive-type 20 # http://www.w3.org/TR/WebIDL/#dfn-primitive-type
21 'boolean', 21 'boolean',
22 'float', 22 'float',
23 # unrestricted float is not supported 23 'unrestricted float',
24 'double', 24 'double',
25 # unrestricted double is not supported 25 'unrestricted double',
26 # http://www.w3.org/TR/WebIDL/#idl-types 26 # http://www.w3.org/TR/WebIDL/#idl-types
27 'DOMString', 27 'DOMString',
28 'Date', 28 'Date',
29 # http://www.w3.org/TR/WebIDL/#es-type-mapping 29 # http://www.w3.org/TR/WebIDL/#es-type-mapping
30 'void', 30 'void',
31 ]) 31 ])
32 INTEGER_TYPES = frozenset([ 32 INTEGER_TYPES = frozenset([
33 # http://www.w3.org/TR/WebIDL/#dfn-integer-type 33 # http://www.w3.org/TR/WebIDL/#dfn-integer-type
34 'byte', 34 'byte',
35 'octet', 35 'octet',
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 85
86 class IdlType(object): 86 class IdlType(object):
87 # FIXME: incorporate Nullable, etc. 87 # FIXME: incorporate Nullable, etc.
88 # FIXME: use nested types: IdlArrayType, IdlNullableType, IdlSequenceType 88 # FIXME: use nested types: IdlArrayType, IdlNullableType, IdlSequenceType
89 # to support types like short?[] vs. short[]?, instead of treating these 89 # to support types like short?[] vs. short[]?, instead of treating these
90 # as orthogonal properties (via flags). 90 # as orthogonal properties (via flags).
91 callback_functions = set() 91 callback_functions = set()
92 callback_interfaces = set() 92 callback_interfaces = set()
93 enums = {} # name -> values 93 enums = {} # name -> values
94 94
95 def __init__(self, base_type, is_array=False, is_sequence=False, is_nullable =False): 95 def __init__(self, base_type, is_array=False, is_sequence=False, is_nullable =False, is_unrestricted=False):
96 if is_array and is_sequence: 96 if is_array and is_sequence:
97 raise ValueError('Array of Sequences are not allowed.') 97 raise ValueError('Array of Sequences are not allowed.')
98 self.base_type = base_type 98 if is_unrestricted:
99 self.base_type = 'unrestricted %s' % base_type
100 else:
101 self.base_type = base_type
99 self.is_array = is_array 102 self.is_array = is_array
100 self.is_sequence = is_sequence 103 self.is_sequence = is_sequence
101 self.is_nullable = is_nullable 104 self.is_nullable = is_nullable
102 105
103 def __str__(self): 106 def __str__(self):
104 type_string = self.base_type 107 type_string = self.base_type
105 if self.is_array: 108 if self.is_array:
106 return type_string + '[]' 109 return type_string + '[]'
107 if self.is_sequence: 110 if self.is_sequence:
108 return 'sequence<%s>' % type_string 111 return 'sequence<%s>' % type_string
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 289
287 @property 290 @property
288 def name(self): 291 def name(self):
289 return 'Or'.join(member_type.name for member_type in self.member_types) 292 return 'Or'.join(member_type.name for member_type in self.member_types)
290 293
291 def resolve_typedefs(self, typedefs): 294 def resolve_typedefs(self, typedefs):
292 self.member_types = [ 295 self.member_types = [
293 typedefs.get(member_type, member_type) 296 typedefs.get(member_type, member_type)
294 for member_type in self.member_types] 297 for member_type in self.member_types]
295 return self 298 return self
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698