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

Unified Diff: mojom/mojom_parser/mojom/types.go

Issue 1819223002: Mojom frontend: Allow non-reference types in non-zero versions of a struct. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 4 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « mojom/mojom_parser/mojom/computed_data.go ('k') | mojom/mojom_parser/mojom/user_defined_types.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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.")
« no previous file with comments | « mojom/mojom_parser/mojom/computed_data.go ('k') | mojom/mojom_parser/mojom/user_defined_types.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698