Index: mojom/mojom_parser/mojom/types.go |
diff --git a/mojom/mojom_parser/mojom/types.go b/mojom/mojom_parser/mojom/types.go |
index c8af282f058355cbecf0b3ac8996886e2a9d8261..4917148da4b38faca2b02657ea9efa4f688dc628 100644 |
--- a/mojom/mojom_parser/mojom/types.go |
+++ b/mojom/mojom_parser/mojom/types.go |
@@ -124,8 +124,13 @@ type TypeRef interface { |
// types of the key type and the value type. |
ReferencedUserDefinedTypes() UserDefinedTypeSet |
- // Returns true just in case the type referene is nullable. |
- Nullable() bool |
+ // Returns true just in case this type reference is allowed as the type of |
+ // a struct field in a non-zero version of a struct. We disallow |
+ // pointer and handle types that are not nullable. This means we allow all primitive |
+ // types and enums, and nullable strings, arrays, maps, handles, interfaces |
+ // structs and unions. This method should only be invoked after successful |
+ // parsing and resolution have occurred. |
+ AllowedInNonZeroStructVersion() bool |
// SerializationSize() is invoked after the resolution and validation phases. |
// It returns the number of bytes necessary to serialize an instance of the type |
@@ -204,8 +209,8 @@ func (SimpleType) MarkUsedAsConstantType() bool { |
return true |
} |
-func (SimpleType) Nullable() bool { |
- return false |
+func (SimpleType) AllowedInNonZeroStructVersion() bool { |
+ return true |
} |
// A SimpleType does not reference any UserDefinedTypes. |
@@ -419,6 +424,10 @@ func (s StringType) Nullable() bool { |
return s.nullable |
} |
+func (s StringType) AllowedInNonZeroStructVersion() bool { |
+ return s.nullable |
+} |
+ |
func (StringType) SerializationSize() uint32 { |
return 8 |
} |
@@ -517,6 +526,10 @@ func (h HandleTypeRef) Nullable() bool { |
return h.nullable |
} |
+func (h HandleTypeRef) AllowedInNonZeroStructVersion() bool { |
+ return h.nullable |
+} |
+ |
func (HandleTypeRef) SerializationSize() uint32 { |
return 4 |
} |
@@ -655,6 +668,10 @@ func (a ArrayTypeRef) Nullable() bool { |
return a.nullable |
} |
+func (a ArrayTypeRef) AllowedInNonZeroStructVersion() bool { |
+ return a.nullable |
+} |
+ |
func (ArrayTypeRef) SerializationSize() uint32 { |
return 8 |
} |
@@ -751,6 +768,10 @@ func (m MapTypeRef) Nullable() bool { |
return m.nullable |
} |
+func (m MapTypeRef) AllowedInNonZeroStructVersion() bool { |
+ return m.nullable |
+} |
+ |
func (MapTypeRef) SerializationSize() uint32 { |
return 8 |
} |
@@ -879,6 +900,16 @@ func (t *UserTypeRef) Nullable() bool { |
return t.nullable |
} |
+func (t *UserTypeRef) AllowedInNonZeroStructVersion() bool { |
+ if t.resolvedType == nil { |
+ panic("This method should only be invoked after successful resolution.") |
+ } |
+ if t.resolvedType.Kind() == UserDefinedTypeKindEnum { |
+ return true |
+ } |
+ return t.nullable |
+} |
+ |
func (t *UserTypeRef) SerializationSize() uint32 { |
if t.resolvedType == nil { |
panic("This method should only be invoked after successful resolution.") |