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

Side by Side Diff: mojom/mojom_parser/serialization/serialization.go

Issue 1717583003: Mojom compiler: Move RuntimeTypeInfo from mojom_files.mojom to mojom_types.mojom. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: New sha1s Created 4 years, 10 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 unified diff | Download patch
OLDNEW
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 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 if len(*file.Imports) == 0 { 122 if len(*file.Imports) == 0 {
123 // If we are in a mode where canonical file names are no t being resolved 123 // If we are in a mode where canonical file names are no t being resolved
124 // then emit a null value for |imports| rather than an e mpty array. 124 // then emit a null value for |imports| rather than an e mpty array.
125 file.Imports = nil 125 file.Imports = nil
126 } 126 }
127 } 127 }
128 128
129 // We will populate a RuntimeTypeInfo structure and then serialize it an d 129 // We will populate a RuntimeTypeInfo structure and then serialize it an d
130 // the serialized bytes will form the |serialized_runtime_type_info| fie ld 130 // the serialized bytes will form the |serialized_runtime_type_info| fie ld
131 // of the MojomFile. 131 // of the MojomFile.
132 » typeInfo := mojom_files.RuntimeTypeInfo{} 132 » typeInfo := mojom_types.RuntimeTypeInfo{}
133 » typeInfo.ServicesByName = make(map[string]mojom_files.ServiceTypeInfo) 133 » typeInfo.ServicesByName = make(map[string]mojom_types.ServiceTypeInfo)
134 typeInfo.TypeMap = make(map[string]mojom_types.UserDefinedType) 134 typeInfo.TypeMap = make(map[string]mojom_types.UserDefinedType)
135 135
136 // We populate the declared_mojom_objects field 136 // We populate the declared_mojom_objects field
137 // and simultaneously we populate typeInfo.TypeMap. 137 // and simultaneously we populate typeInfo.TypeMap.
138 138
139 // Interfaces 139 // Interfaces
140 if f.Interfaces != nil && len(f.Interfaces) > 0 { 140 if f.Interfaces != nil && len(f.Interfaces) > 0 {
141 file.DeclaredMojomObjects.Interfaces = new([]string) 141 file.DeclaredMojomObjects.Interfaces = new([]string)
142 for _, intrfc := range f.Interfaces { 142 for _, intrfc := range f.Interfaces {
143 typeKey := intrfc.TypeKey() 143 typeKey := intrfc.TypeKey()
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 } 214 }
215 file.SerializedRuntimeTypeInfo = &bytes 215 file.SerializedRuntimeTypeInfo = &bytes
216 } 216 }
217 217
218 return 218 return
219 } 219 }
220 220
221 // addServiceTypeInfo will add a ServiceTypeInfo to the ServicesByName field of |typeInfo| corresponding 221 // addServiceTypeInfo will add a ServiceTypeInfo to the ServicesByName field of |typeInfo| corresponding
222 // to |intrfc| if |intrfc| is a top-level interface, meaning that it has a non-n il service name. In that 222 // to |intrfc| if |intrfc| is a top-level interface, meaning that it has a non-n il service name. In that
223 // case this method returns true. Otherwise this method will do nothing and retu rn fals. 223 // case this method returns true. Otherwise this method will do nothing and retu rn fals.
224 func addServiceTypeInfo(intrfc *mojom.MojomInterface, typeInfo *mojom_files.Runt imeTypeInfo) (isTopLevel bool) { 224 func addServiceTypeInfo(intrfc *mojom.MojomInterface, typeInfo *mojom_types.Runt imeTypeInfo) (isTopLevel bool) {
225 isTopLevel = intrfc.ServiceName != nil 225 isTopLevel = intrfc.ServiceName != nil
226 if isTopLevel { 226 if isTopLevel {
227 » » serviceTypeInfo := mojom_files.ServiceTypeInfo{} 227 » » serviceTypeInfo := mojom_types.ServiceTypeInfo{}
228 serviceTypeInfo.TopLevelInterface = intrfc.TypeKey() 228 serviceTypeInfo.TopLevelInterface = intrfc.TypeKey()
229 serviceTypeInfo.CompleteTypeSet = intrfc.FindReachableTypes() 229 serviceTypeInfo.CompleteTypeSet = intrfc.FindReachableTypes()
230 typeInfo.ServicesByName[*intrfc.ServiceName] = serviceTypeInfo 230 typeInfo.ServicesByName[*intrfc.ServiceName] = serviceTypeInfo
231 } 231 }
232 return 232 return
233 } 233 }
234 234
235 // translateUserDefinedType translates from a mojom.UserDefinedType (the pure Go 235 // translateUserDefinedType translates from a mojom.UserDefinedType (the pure Go
236 // representation used by the parser) to a mojom_types.UserDefinedType (the 236 // representation used by the parser) to a mojom_types.UserDefinedType (the
237 // Mojo Go representation used for serialization.) 237 // Mojo Go representation used for serialization.)
(...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after
668 668
669 // stringPointer is a convenience function for creating a pointer to a string wh ose value 669 // 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 670 // 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 671 // 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 672 // 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 673 // that is how the Mojom type |string?| (i.e. nullable string) is represented in
674 // in the Mojom Go bindings. 674 // in the Mojom Go bindings.
675 func stringPointer(s string) *string { 675 func stringPointer(s string) *string {
676 return &s 676 return &s
677 } 677 }
OLDNEW
« no previous file with comments | « mojom/mojom_parser/generated/mojom_types/mojom_types.mojom.go ('k') | mojom/mojom_parser/serialization/serialization_test.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698