Index: Source/bindings/scripts/idl_types.py |
diff --git a/Source/bindings/scripts/idl_types.py b/Source/bindings/scripts/idl_types.py |
index a86a800de225217f7534bbb249830647027e6c51..ff18e317b3ce501776d3a22a759e9908b200d110 100644 |
--- a/Source/bindings/scripts/idl_types.py |
+++ b/Source/bindings/scripts/idl_types.py |
@@ -7,6 +7,7 @@ Classes: |
IdlTypeBase |
IdlType |
IdlUnionType |
+ IdlArrayOrSequenceType |
""" |
from collections import defaultdict |
@@ -96,17 +97,29 @@ def set_ancestors(new_ancestors): |
class IdlTypeBase(object): |
- """Base class for IdlType and IdlUnionType.""" |
+ """Base class for IdlType, IdlUnionType and IdlArrayOrSequenceType.""" |
- def __init__(self, is_array=False, is_sequence=False, is_nullable=False): |
+ def __init__(self, is_nullable): |
self.base_type = None |
- self.is_array = is_array |
- self.is_sequence = is_sequence |
+ self.is_array = False |
self.is_nullable = is_nullable |
+ self.is_sequence = False |
+ |
+ def __str__(self): |
+ inner_string = self.inner_string |
+ if self.is_nullable: |
+ # FIXME: Dictionary::ConversionContext::setConversionType can't |
+ # handle the '?' in nullable types (passes nullability separately). |
+ # Update that function to handle nullability from the type name, |
+ # simplifying its signature. |
+ # return inner_string + '?' |
+ return inner_string |
+ return inner_string |
@property |
- def native_array_element_type(self): |
- return None |
+ def inner_string(self): |
+ raise NotImplementedError( |
+ 'inner_string property should be defined in subclasses') |
@property |
def array_element_type(self): |
@@ -121,6 +134,10 @@ class IdlTypeBase(object): |
return False |
@property |
+ def is_callback_interface(self): |
+ return False |
+ |
+ @property |
def is_dictionary(self): |
return False |
@@ -137,7 +154,11 @@ class IdlTypeBase(object): |
return False |
@property |
- def is_primitivee_type(self): |
+ def is_primitive_type(self): |
+ return False |
+ |
+ @property |
+ def is_interface_type(self): |
return False |
@property |
@@ -154,8 +175,14 @@ class IdlTypeBase(object): |
@property |
def name(self): |
+ if self.is_nullable: |
+ return self.inner_name + "OrNull" |
Nils Barth (inactive)
2014/08/14 14:24:44
Nit: single quotes
Jens Widell
2014/08/14 15:02:55
Sometimes I forget...
Double quotes is what typic
|
+ return self.inner_name |
+ |
+ @property |
+ def inner_name(self): |
raise NotImplementedError( |
- 'name property should be defined in subclasses') |
+ 'inner_name property should be defined in subclasses') |
def resolve_typedefs(self, typedefs): |
raise NotImplementedError( |
@@ -168,7 +195,6 @@ class IdlTypeBase(object): |
class IdlType(IdlTypeBase): |
# FIXME: incorporate Nullable, etc. |
- # FIXME: use nested types: IdlArrayType, IdlNullableType, IdlSequenceType |
# to support types like short?[] vs. short[]?, instead of treating these |
# as orthogonal properties (via flags). |
callback_functions = set() |
@@ -176,34 +202,16 @@ class IdlType(IdlTypeBase): |
dictionaries = set() |
enums = {} # name -> values |
- def __init__(self, base_type, is_array=False, is_sequence=False, is_nullable=False, is_unrestricted=False): |
- super(IdlType, self).__init__(is_array=is_array, is_sequence=is_sequence, is_nullable=is_nullable) |
- if is_array and is_sequence: |
- raise ValueError('Array of Sequences are not allowed.') |
+ def __init__(self, base_type, is_nullable=False, is_unrestricted=False): |
+ super(IdlType, self).__init__(is_nullable) |
if is_unrestricted: |
self.base_type = 'unrestricted %s' % base_type |
else: |
self.base_type = base_type |
- def __str__(self): |
- type_string = self.base_type |
- if self.is_array: |
- return type_string + '[]' |
- if self.is_sequence: |
- return 'sequence<%s>' % type_string |
- if self.is_nullable: |
- # FIXME: Dictionary::ConversionContext::setConversionType can't |
- # handle the '?' in nullable types (passes nullability separately). |
- # Update that function to handle nullability from the type name, |
- # simplifying its signature. |
- # return type_string + '?' |
- return type_string |
- return type_string |
- |
- # FIXME: move to v8_types.py |
@property |
- def native_array_element_type(self): |
- return self.array_element_type or self.sequence_element_type |
+ def inner_string(self): |
+ return self.base_type |
@property |
def array_element_type(self): |
@@ -215,7 +223,7 @@ class IdlType(IdlTypeBase): |
@property |
def is_basic_type(self): |
- return self.base_type in BASIC_TYPES and not self.native_array_element_type |
+ return self.base_type in BASIC_TYPES |
@property |
def is_callback_function(self): |
@@ -230,13 +238,6 @@ class IdlType(IdlTypeBase): |
return self.base_type in IdlType.dictionaries |
@property |
- def is_composite_type(self): |
- return (self.name == 'Any' or |
- self.array_element_type or |
- self.sequence_element_type or |
- self.is_union_type) |
- |
- @property |
def is_enum(self): |
# FIXME: add an IdlEnumType class and a resolve_enums step at end of |
# IdlDefinitions constructor |
@@ -248,15 +249,15 @@ class IdlType(IdlTypeBase): |
@property |
def is_integer_type(self): |
- return self.base_type in INTEGER_TYPES and not self.native_array_element_type |
+ return self.base_type in INTEGER_TYPES |
@property |
def is_numeric_type(self): |
- return self.base_type in NUMERIC_TYPES and not self.native_array_element_type |
+ return self.base_type in NUMERIC_TYPES |
@property |
def is_primitive_type(self): |
- return self.base_type in PRIMITIVE_TYPES and not self.native_array_element_type |
+ return self.base_type in PRIMITIVE_TYPES |
@property |
def is_interface_type(self): |
@@ -265,16 +266,16 @@ class IdlType(IdlTypeBase): |
# http://www.w3.org/TR/WebIDL/#idl-interface |
# In C++ these are RefPtr or PassRefPtr types. |
return not(self.is_basic_type or |
- self.is_composite_type or |
self.is_callback_function or |
self.is_dictionary or |
self.is_enum or |
+ self.name == 'Any' or |
self.name == 'Object' or |
self.name == 'Promise') # Promise will be basic in future |
@property |
def is_string_type(self): |
- return self.base_type_name in STRING_TYPES |
+ return self.inner_name in STRING_TYPES |
@property |
def may_raise_exception_on_conversion(self): |
@@ -286,24 +287,13 @@ class IdlType(IdlTypeBase): |
return isinstance(self, IdlUnionType) |
@property |
- def base_type_name(self): |
- base_type = self.base_type |
- return TYPE_NAMES.get(base_type, base_type) |
- |
- @property |
- def name(self): |
- """Return type name. |
+ def inner_name(self): |
+ """Return type name (or inner type name if nullable) |
http://heycam.github.io/webidl/#dfn-type-name |
""" |
- base_type_name = self.base_type_name |
- if self.is_array: |
- return base_type_name + 'Array' |
- if self.is_sequence: |
- return base_type_name + 'Sequence' |
- if self.is_nullable: |
- return base_type_name + 'OrNull' |
- return base_type_name |
+ base_type = self.base_type |
+ return TYPE_NAMES.get(base_type, base_type) |
@classmethod |
def set_callback_functions(cls, new_callback_functions): |
@@ -330,16 +320,7 @@ class IdlType(IdlTypeBase): |
# since can't change type(self) |
return new_type |
# If type doesn't change, just mutate self to avoid a new object |
- # FIXME: a bit ugly; use __init__ instead of setting flags |
- self.base_type = new_type.base_type |
- # handle array both in use and in typedef itself: |
- # typedef Type TypeDef; |
- # TypeDef[] ... |
- # and: |
- # typedef Type[] TypeArray |
- # TypeArray ... |
- self.is_array |= new_type.is_array |
- self.is_sequence |= new_type.is_sequence |
+ self.__init__(new_type.base_type, self.is_nullable or new_type.is_nullable) |
return self |
@@ -358,7 +339,11 @@ class IdlUnionType(IdlTypeBase): |
return True |
@property |
- def name(self): |
+ def inner_name(self): |
+ """Return type name (or inner type name if nullable) |
+ |
+ http://heycam.github.io/webidl/#dfn-type-name |
+ """ |
return 'Or'.join(member_type.name for member_type in self.member_types) |
def resolve_typedefs(self, typedefs): |
@@ -366,3 +351,38 @@ class IdlUnionType(IdlTypeBase): |
typedefs.get(member_type, member_type) |
for member_type in self.member_types] |
return self |
+ |
+ |
+################################################################################ |
+# IdlArrayOrSequenceType |
Nils Barth (inactive)
2014/08/14 14:24:44
It would be a bit cleaner to have separate
IdlArra
Jens Widell
2014/08/14 15:02:54
Agree, that's a better approach. Done.
|
+################################################################################ |
+ |
+class IdlArrayOrSequenceType(IdlTypeBase): |
+ def __init__(self, element_type, is_array=False, is_sequence=False, is_nullable=False): |
+ assert is_array != is_sequence |
haraken
2014/08/14 14:48:58
Also shall we assert is_array or is_sequence?
Nils Barth (inactive)
2014/08/14 14:54:55
That does follow logically...
(X != Y => ((X && !Y
Jens Widell
2014/08/14 15:02:54
Yes, all gone now. It existing in the first place
|
+ super(IdlArrayOrSequenceType, self).__init__(is_nullable) |
+ self.element_type = element_type |
+ self.is_array = is_array |
+ self.is_sequence = is_sequence |
+ |
+ @property |
+ def inner_string(self): |
+ element_type_string = str(self.element_type) |
+ if self.is_array: |
+ return element_type_string + '[]' |
+ return 'sequence<%s>' % element_type_string |
+ |
+ @property |
+ def inner_name(self): |
+ """Return type name (or inner type name if nullable) |
+ |
+ http://heycam.github.io/webidl/#dfn-type-name |
+ """ |
+ element_type_name = self.element_type.name |
+ if self.is_array: |
+ return element_type_name + 'Array' |
+ return element_type_name + 'Sequence' |
+ |
+ def resolve_typedefs(self, typedefs): |
+ self.element_type = self.element_type.resolve_typedefs(typedefs) |
+ return self |