| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 | 4 |
| 5 package translator | 5 package translator |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "fmt" | 8 "fmt" |
| 9 "log" | 9 "log" |
| 10 "sort" | 10 "sort" |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 | 114 |
| 115 return m | 115 return m |
| 116 } | 116 } |
| 117 | 117 |
| 118 func (t *translator) translateUnionField(mojomField *mojom_types.UnionField) (fi
eld UnionFieldTemplate) { | 118 func (t *translator) translateUnionField(mojomField *mojom_types.UnionField) (fi
eld UnionFieldTemplate) { |
| 119 field.Name = formatName(*mojomField.DeclData.ShortName) | 119 field.Name = formatName(*mojomField.DeclData.ShortName) |
| 120 field.Type = t.translateType(mojomField.Type) | 120 field.Type = t.translateType(mojomField.Type) |
| 121 field.Tag = mojomField.Tag | 121 field.Tag = mojomField.Tag |
| 122 field.EncodingInfo = t.encodingInfo(mojomField.Type) | 122 field.EncodingInfo = t.encodingInfo(mojomField.Type) |
| 123 field.EncodingInfo.setIdentifier("u.Value") | 123 field.EncodingInfo.setIdentifier("u.Value") |
| 124 if info, ok := field.EncodingInfo.(*unionTypeEncodingInfo); ok { |
| 125 info.nestedUnion = true |
| 126 } |
| 124 return field | 127 return field |
| 125 } | 128 } |
| 126 | 129 |
| 127 func (t *translator) encodingInfo(mojomType mojom_types.Type) EncodingInfo { | 130 func (t *translator) encodingInfo(mojomType mojom_types.Type) EncodingInfo { |
| 128 return t.encodingInfoNested(mojomType, 0) | 131 return t.encodingInfoNested(mojomType, 0) |
| 129 } | 132 } |
| 130 | 133 |
| 131 func (t *translator) encodingInfoNested(mojomType mojom_types.Type, level int) (
info EncodingInfo) { | 134 func (t *translator) encodingInfoNested(mojomType mojom_types.Type, level int) (
info EncodingInfo) { |
| 132 switch m := mojomType.(type) { | 135 switch m := mojomType.(type) { |
| 133 default: | 136 default: |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 247 valueEncodingInfo.elementEncodingInfo.setIdentifier(fmt.Sprintf("value%v
", level)) | 250 valueEncodingInfo.elementEncodingInfo.setIdentifier(fmt.Sprintf("value%v
", level)) |
| 248 | 251 |
| 249 return info | 252 return info |
| 250 } | 253 } |
| 251 | 254 |
| 252 func (t *translator) typeRefEncodingInfo(typeRef mojom_types.TypeReference) (inf
o EncodingInfo) { | 255 func (t *translator) typeRefEncodingInfo(typeRef mojom_types.TypeReference) (inf
o EncodingInfo) { |
| 253 mojomType := t.GetUserDefinedType(*typeRef.TypeKey) | 256 mojomType := t.GetUserDefinedType(*typeRef.TypeKey) |
| 254 switch m := mojomType.(type) { | 257 switch m := mojomType.(type) { |
| 255 case *mojom_types.UserDefinedTypeStructType: | 258 case *mojom_types.UserDefinedTypeStructType: |
| 256 info = t.structTypeEncodingInfo(m.Value) | 259 info = t.structTypeEncodingInfo(m.Value) |
| 260 case *mojom_types.UserDefinedTypeUnionType: |
| 261 info = t.unionTypeEncodingInfo(m.Value) |
| 257 } | 262 } |
| 258 info.setNullable(typeRef.Nullable) | 263 info.setNullable(typeRef.Nullable) |
| 259 return info | 264 return info |
| 260 } | 265 } |
| 261 | 266 |
| 262 func (t *translator) structTypeEncodingInfo(mojomType mojom_types.MojomStruct) (
info *structTypeEncodingInfo) { | 267 func (t *translator) structTypeEncodingInfo(mojomType mojom_types.MojomStruct) (
info *structTypeEncodingInfo) { |
| 263 info = new(structTypeEncodingInfo) | 268 info = new(structTypeEncodingInfo) |
| 264 return info | 269 return info |
| 265 } | 270 } |
| 266 | 271 |
| 272 func (t *translator) unionTypeEncodingInfo(mojomType mojom_types.MojomUnion) (in
fo *unionTypeEncodingInfo) { |
| 273 info = new(unionTypeEncodingInfo) |
| 274 return info |
| 275 } |
| 276 |
| 267 // Implements sort.Interface. | 277 // Implements sort.Interface. |
| 268 type structFieldSerializationSorter []mojom_types.StructField | 278 type structFieldSerializationSorter []mojom_types.StructField |
| 269 | 279 |
| 270 func (s structFieldSerializationSorter) Len() int { | 280 func (s structFieldSerializationSorter) Len() int { |
| 271 return len(s) | 281 return len(s) |
| 272 } | 282 } |
| 273 | 283 |
| 274 func (s structFieldSerializationSorter) Less(i, j int) bool { | 284 func (s structFieldSerializationSorter) Less(i, j int) bool { |
| 275 if s[i].Offset < s[j].Offset { | 285 if s[i].Offset < s[j].Offset { |
| 276 return true | 286 return true |
| 277 } | 287 } |
| 278 | 288 |
| 279 if s[i].Offset == s[j].Offset && s[i].Bit < s[j].Bit { | 289 if s[i].Offset == s[j].Offset && s[i].Bit < s[j].Bit { |
| 280 return true | 290 return true |
| 281 } | 291 } |
| 282 | 292 |
| 283 return false | 293 return false |
| 284 } | 294 } |
| 285 | 295 |
| 286 func (s structFieldSerializationSorter) Swap(i, j int) { | 296 func (s structFieldSerializationSorter) Swap(i, j int) { |
| 287 s[i], s[j] = s[j], s[i] | 297 s[i], s[j] = s[j], s[i] |
| 288 } | 298 } |
| OLD | NEW |