| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 serialization | 5 package serialization |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "fmt" | 8 "fmt" |
| 9 "mojo/public/go/bindings" | 9 "mojo/public/go/bindings" |
| 10 "mojom/mojom_parser/generated/mojom_files" | 10 "mojom/mojom_parser/generated/mojom_files" |
| (...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 249 panic(fmt.Sprintf("Unexpected type: %T", t)) | 249 panic(fmt.Sprintf("Unexpected type: %T", t)) |
| 250 | 250 |
| 251 } | 251 } |
| 252 } | 252 } |
| 253 | 253 |
| 254 func translateMojomStruct(s *mojom.MojomStruct) mojom_types.MojomStruct { | 254 func translateMojomStruct(s *mojom.MojomStruct) mojom_types.MojomStruct { |
| 255 mojomStruct := mojom_types.MojomStruct{} | 255 mojomStruct := mojom_types.MojomStruct{} |
| 256 mojomStruct.DeclData = translateDeclarationData(&s.DeclarationData) | 256 mojomStruct.DeclData = translateDeclarationData(&s.DeclarationData) |
| 257 mojomStruct.DeclData.ContainedDeclarations = translateContainedDeclarati
ons(&s.NestedDeclarations) | 257 mojomStruct.DeclData.ContainedDeclarations = translateContainedDeclarati
ons(&s.NestedDeclarations) |
| 258 | 258 |
| 259 » for _, field := range s.Fields { | 259 » for _, field := range s.FieldsInOrdinalOrder() { |
| 260 mojomStruct.Fields = append(mojomStruct.Fields, translateStructF
ield(field)) | 260 mojomStruct.Fields = append(mojomStruct.Fields, translateStructF
ield(field)) |
| 261 } | 261 } |
| 262 | 262 |
| 263 // TODO(rudominer) Implement VersionInfo. | 263 // TODO(rudominer) Implement VersionInfo. |
| 264 //mojomStruct.Value.VersionInfo = new([]mojom_types.StructVersion) | 264 //mojomStruct.Value.VersionInfo = new([]mojom_types.StructVersion) |
| 265 | 265 |
| 266 return mojomStruct | 266 return mojomStruct |
| 267 } | 267 } |
| 268 | 268 |
| 269 func translateStructField(f *mojom.StructField) (field mojom_types.StructField)
{ | 269 func translateStructField(f *mojom.StructField) (field mojom_types.StructField)
{ |
| (...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 604 } | 604 } |
| 605 | 605 |
| 606 // declared_ordinal field | 606 // declared_ordinal field |
| 607 if d.DeclaredOrdinal() < 0 { | 607 if d.DeclaredOrdinal() < 0 { |
| 608 declData.DeclaredOrdinal = -1 | 608 declData.DeclaredOrdinal = -1 |
| 609 } else { | 609 } else { |
| 610 declData.DeclaredOrdinal = int32(d.DeclaredOrdinal()) | 610 declData.DeclaredOrdinal = int32(d.DeclaredOrdinal()) |
| 611 } | 611 } |
| 612 | 612 |
| 613 // declaration_order | 613 // declaration_order |
| 614 » // TODO(rudominer) DeclarationOrder is currently not populated. | 614 » if d.LexicalPosition() < 0 { |
| 615 » declData.DeclarationOrder = -1 | 615 » » declData.DeclarationOrder = -1 |
| 616 » } else { |
| 617 » » declData.DeclarationOrder = d.LexicalPosition() |
| 618 » } |
| 616 | 619 |
| 617 // container_type_key | 620 // container_type_key |
| 618 containingType := d.ContainingType() | 621 containingType := d.ContainingType() |
| 619 if containingType != nil { | 622 if containingType != nil { |
| 620 switch d.DeclaredObject().(type) { | 623 switch d.DeclaredObject().(type) { |
| 621 // We do not serialize the |container_type_key| field for object
s that only exist | 624 // We do not serialize the |container_type_key| field for object
s that only exist |
| 622 // as children of their container objects and are not independen
tly | 625 // as children of their container objects and are not independen
tly |
| 623 // referenceable. | 626 // referenceable. |
| 624 case *mojom.StructField, *mojom.MojomMethod: | 627 case *mojom.StructField, *mojom.MojomMethod: |
| 625 // We do not serialize the |container_type_key| field fo
r an EnumValue | 628 // We do not serialize the |container_type_key| field fo
r an EnumValue |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 668 | 671 |
| 669 // stringPointer is a convenience function for creating a pointer to a string wh
ose value | 672 // stringPointer is a convenience function for creating a pointer to a string wh
ose value |
| 670 // is the specified string. It may be used in situations where the compiler will | 673 // is the specified string. It may be used in situations where the compiler will |
| 671 // not allow you to take the address of a string value directly, such as the | 674 // not allow you to take the address of a string value directly, such as the |
| 672 // return value of a function. It is necessary to create pointers to strings bec
ause | 675 // return value of a function. It is necessary to create pointers to strings bec
ause |
| 673 // that is how the Mojom type |string?| (i.e. nullable string) is represented in | 676 // that is how the Mojom type |string?| (i.e. nullable string) is represented in |
| 674 // in the Mojom Go bindings. | 677 // in the Mojom Go bindings. |
| 675 func stringPointer(s string) *string { | 678 func stringPointer(s string) *string { |
| 676 return &s | 679 return &s |
| 677 } | 680 } |
| OLD | NEW |