Chromium Code Reviews| Index: mojom/generators/c/cgen/type_table.go |
| diff --git a/mojom/generators/c/cgen/type_table.go b/mojom/generators/c/cgen/type_table.go |
| index 60021bdd75d2245762bafcaca1387e6f75d4677b..134c797762ae6bb8e05ea7c75cb81c1b4567f511 100644 |
| --- a/mojom/generators/c/cgen/type_table.go |
| +++ b/mojom/generators/c/cgen/type_table.go |
| @@ -12,6 +12,7 @@ import ( |
| "log" |
| "mojom/generated/mojom_files" |
| "mojom/generated/mojom_types" |
| + "sort" |
| ) |
| type StructPointerTableEntry struct { |
| @@ -35,11 +36,20 @@ type ArrayPointerTableEntry struct { |
| NumElements uint32 |
| Nullable bool |
| ElemType string |
| + ElemNumBits uint32 |
| } |
| +type StructVersion struct { |
| + Version uint32 |
| + NumBytes uint32 |
| +} |
| +type StructVersions []StructVersion |
| + |
| type StructPointerTable struct { |
| - Name string |
| - Entries []StructPointerTableEntry |
| + Name string |
| + // List of version -> struct sizes, ordered by increasing version. |
| + Versions StructVersions |
| + Entries []StructPointerTableEntry |
| } |
| type UnionPointerTable struct { |
| Name string |
| @@ -62,6 +72,10 @@ type TypeTableTemplate struct { |
| fileGraph *mojom_files.MojomFileGraph |
| } |
| +func (a StructVersions) Len() int { return len(a) } |
| +func (a StructVersions) Swap(i, j int) { a[i], a[j] = a[j], a[i] } |
| +func (a StructVersions) Less(i, j int) bool { return a[i].Version < a[j].Version } |
| + |
| func (table *TypeTableTemplate) getTableForUDT(typeRef mojom_types.TypeReference) (elemTable string, elemType string, nullable bool) { |
| nullable = typeRef.Nullable |
| if typeRef.IsInterfaceRequest { |
| @@ -111,7 +125,8 @@ func (table *TypeTableTemplate) makeTableForType(prefix string, dataType mojom_t |
| table.counter++ |
| typ := dataType.Interface().(mojom_types.MapType) |
| elemTable = "&" + table.makeMapPointerTable(mapTableName, typ) |
| - elemType = "MOJOM_TYPE_DESCRIPTOR_TYPE_STRUCT_PTR" |
| + |
|
viettrungluu
2016/07/28 23:03:01
Did you really mean to add a blank line here?
vardhan
2016/07/29 21:29:22
Done.
|
| + elemType = "MOJOM_TYPE_DESCRIPTOR_TYPE_MAP_PTR" |
| nullable = typ.Nullable |
| case *mojom_types.TypeHandleType: |
| typ := dataType.Interface().(mojom_types.HandleType) |
| @@ -123,6 +138,7 @@ func (table *TypeTableTemplate) makeTableForType(prefix string, dataType mojom_t |
| case *mojom_types.TypeSimpleType: |
| elemTable = "NULL" |
| elemType = "MOJOM_TYPE_DESCRIPTOR_TYPE_POD" |
| + nullable = false |
| default: |
| log.Fatal("uhoh, should not be here.") |
| } |
| @@ -140,6 +156,7 @@ func (table *TypeTableTemplate) makeArrayPointerEntry(prefix string, f mojom_typ |
| entry := ArrayPointerTableEntry{ |
| Name: prefix + "__TypeDesc", |
| NumElements: numElements, |
| + ElemNumBits: mojomTypeBitSize(f.ElementType, table.fileGraph), |
| Nullable: f.Nullable, |
| } |
| entry.ElemTable, entry.ElemType, entry.Nullable = table.makeTableForType(prefix, f.ElementType) |
| @@ -151,6 +168,12 @@ func (table *TypeTableTemplate) makeArrayPointerEntry(prefix string, f mojom_typ |
| func (table *TypeTableTemplate) makeMapPointerTable(prefix string, f mojom_types.MapType) string { |
| structTable := StructPointerTable{ |
| Name: prefix + "__TypeDesc", |
| + Versions: []StructVersion{ |
| + { |
| + Version: 0, |
| + NumBytes: 24, // A map has a struct header, and 2 pointers to arrays. |
| + }, |
| + }, |
| } |
| keyType := mojom_types.ArrayType{ |
| @@ -241,6 +264,17 @@ func (table *TypeTableTemplate) insertStructPointerTable(s mojom_types.MojomStru |
| structTable := StructPointerTable{ |
| Name: structTablePrefix + "__TypeDesc", |
| } |
| + if s.VersionInfo != nil { |
| + for _, structVersion := range *s.VersionInfo { |
| + structTable.Versions = append(structTable.Versions, StructVersion{ |
| + Version: structVersion.VersionNumber, |
| + NumBytes: structVersion.NumBytes, |
| + }) |
| + } |
| + // Sort by verion number in increasing order. |
| + sort.Sort(structTable.Versions) |
| + } |
| + |
| for _, field := range s.Fields { |
| if table.isPointerOrHandle(field.Type) { |
| structTable.Entries = append(structTable.Entries, table.makeStructPointerTableEntry( |