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

Side by Side Diff: mojom/generators/rust/rustgen/source.go

Issue 2240003002: Rust: Polish off communication across Mojom interfaces (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Upload newest version of code gen Created 4 years, 4 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 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 rustgen 5 package rustgen
6 6
7 import ( 7 import (
8 "log" 8 "log"
9 "sort" 9 "sort"
10 "strconv" 10 "strconv"
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 Value int64 75 Value int64
76 } 76 }
77 77
78 type EnumTemplate struct { 78 type EnumTemplate struct {
79 Name string 79 Name string
80 // In declaration order. 80 // In declaration order.
81 Values []EnumValueTemplate 81 Values []EnumValueTemplate
82 Signed bool 82 Signed bool
83 } 83 }
84 84
85 type EndpointTemplate struct {
86 Name string
87 Interface string
88 }
89
85 type InterfaceMessageTemplate struct { 90 type InterfaceMessageTemplate struct {
86 Name string 91 Name string
87 // This is the ordinal name (denoted by '@x' in the IDL). 92 // This is the ordinal name (denoted by '@x' in the IDL).
88 MessageOrdinal uint32 93 MessageOrdinal uint32
89 MinVersion uint32 94 MinVersion uint32
90 RequestStruct StructTemplate 95 RequestStruct StructTemplate
91 // ResponseStruct.Name == "" if response not defined. 96 // ResponseStruct.Name == "" if response not defined.
92 ResponseStruct StructTemplate 97 ResponseStruct StructTemplate
93 } 98 }
94 99
95 type InterfaceTemplate struct { 100 type InterfaceTemplate struct {
96 Name string 101 Name string
97 ServiceName string 102 ServiceName string
103 Client EndpointTemplate
104 Server EndpointTemplate
98 Version uint32 105 Version uint32
99 Messages []InterfaceMessageTemplate 106 Messages []InterfaceMessageTemplate
100 Enums []EnumTemplate 107 Enums []EnumTemplate
101 Constants []ConstantTemplate 108 Constants []ConstantTemplate
102 } 109 }
103 110
104 // The type, name and initial value of the constant. 111 // The type, name and initial value of the constant.
105 // Describes mojom constants declared top level, in structs, and in 112 // Describes mojom constants declared top level, in structs, and in
106 // interfaces. 113 // interfaces.
107 type ConstantTemplate struct { 114 type ConstantTemplate struct {
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 } 296 }
290 return 297 return
291 } 298 }
292 299
293 func NewInterfaceTemplate(context *Context, mojomInterface *mojom_types.MojomInt erface) InterfaceTemplate { 300 func NewInterfaceTemplate(context *Context, mojomInterface *mojom_types.MojomInt erface) InterfaceTemplate {
294 interface_name := mojomToRustName(mojomInterface.DeclData, context) 301 interface_name := mojomToRustName(mojomInterface.DeclData, context)
295 var service_name string 302 var service_name string
296 if mojomInterface.ServiceName != nil { 303 if mojomInterface.ServiceName != nil {
297 service_name = *mojomInterface.ServiceName 304 service_name = *mojomInterface.ServiceName
298 } 305 }
306 client := EndpointTemplate{
307 Name: interface_name + "Client",
308 Interface: interface_name,
309 }
310 server := EndpointTemplate{
311 Name: interface_name + "Server",
312 Interface: interface_name,
313 }
299 314
300 // Generate templates for the containing constants and enums 315 // Generate templates for the containing constants and enums
301 var constants []ConstantTemplate 316 var constants []ConstantTemplate
302 var enums []EnumTemplate 317 var enums []EnumTemplate
303 if decls := mojomInterface.DeclData.ContainedDeclarations; decls != nil { 318 if decls := mojomInterface.DeclData.ContainedDeclarations; decls != nil {
304 constants, enums = generateContainedDeclarations(context, decls) 319 constants, enums = generateContainedDeclarations(context, decls)
305 } 320 }
306 321
307 var msgs []InterfaceMessageTemplate 322 var msgs []InterfaceMessageTemplate
308 for _, mojomMethod := range mojomInterface.Methods { 323 for _, mojomMethod := range mojomInterface.Methods {
309 msg_name := assertNotReservedKeyword(interface_name + *mojomMeth od.DeclData.ShortName) 324 msg_name := assertNotReservedKeyword(interface_name + *mojomMeth od.DeclData.ShortName)
310 req_struct := NewStructTemplate(context, &mojomMethod.Parameters ) 325 req_struct := NewStructTemplate(context, &mojomMethod.Parameters )
311 req_struct.Name = interface_name + req_struct.Name 326 req_struct.Name = interface_name + req_struct.Name
312 327
313 var resp_struct StructTemplate 328 var resp_struct StructTemplate
314 if mojomMethod.ResponseParams != nil { 329 if mojomMethod.ResponseParams != nil {
315 resp_struct = NewStructTemplate(context, mojomMethod.Res ponseParams) 330 resp_struct = NewStructTemplate(context, mojomMethod.Res ponseParams)
316 resp_struct.Name = interface_name + resp_struct.Name 331 resp_struct.Name = interface_name + resp_struct.Name
317 } 332 }
318 333
319 msgs = append(msgs, InterfaceMessageTemplate{ 334 msgs = append(msgs, InterfaceMessageTemplate{
320 Name: msg_name, 335 Name: msg_name,
321 MessageOrdinal: mojomMethod.Ordinal, 336 MessageOrdinal: mojomMethod.Ordinal,
322 MinVersion: mojomMethod.MinVersion, 337 MinVersion: mojomMethod.MinVersion,
323 RequestStruct: req_struct, 338 RequestStruct: req_struct,
324 ResponseStruct: resp_struct, 339 ResponseStruct: resp_struct,
325 }) 340 })
326 } 341 }
327
328 return InterfaceTemplate{ 342 return InterfaceTemplate{
329 Name: interface_name, 343 Name: interface_name,
330 ServiceName: service_name, 344 ServiceName: service_name,
345 Client: client,
346 Server: server,
331 Version: mojomInterface.CurrentVersion, 347 Version: mojomInterface.CurrentVersion,
332 Enums: enums, 348 Enums: enums,
333 Constants: constants, 349 Constants: constants,
334 Messages: msgs, 350 Messages: msgs,
335 } 351 }
336 } 352 }
337 353
338 // TODO(vardhan): We can make this function, along with all other New*Template() 354 // TODO(vardhan): We can make this function, along with all other New*Template()
339 // functions, be a method for InterfaceTemplate so that we don't have to pass 355 // functions, be a method for InterfaceTemplate so that we don't have to pass
340 // around |fileGraph| all over the place. 356 // around |fileGraph| all over the place.
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
458 474
459 return SourceTemplate{ 475 return SourceTemplate{
460 Constants: constants, 476 Constants: constants,
461 Structs: structs, 477 Structs: structs,
462 Unions: unions, 478 Unions: unions,
463 Enums: enums, 479 Enums: enums,
464 Interfaces: interfaces, 480 Interfaces: interfaces,
465 } 481 }
466 } 482 }
467 483
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698