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

Side by Side Diff: mojom/generators/c/templates/struct.tmpl.go

Issue 2200843002: C bindings: Implement _DeepCopy() & some unittests. (Closed) Base URL: git@github.com:domokit/mojo.git@cgen_validate
Patch Set: oops, include c.sha1. also properly merge 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 templates 5 package templates
6 6
7 const GenerateStructDeclarations = ` 7 const GenerateStructDeclarations = `
8 {{- /* . (dot) refers to the Go type |cgen.StructTemplate| */ -}} 8 {{- /* . (dot) refers to the Go type |cgen.StructTemplate| */ -}}
9 {{define "GenerateStructDeclarations" -}} 9 {{define "GenerateStructDeclarations" -}}
10 {{- $struct := . -}} 10 {{- $struct := . -}}
(...skipping 20 matching lines...) Expand all
31 struct {{$struct.Name}}* {{$struct.Name}}_New(struct MojomBuffer* in_buffer); 31 struct {{$struct.Name}}* {{$struct.Name}}_New(struct MojomBuffer* in_buffer);
32 32
33 void {{$struct.Name}}_Init( 33 void {{$struct.Name}}_Init(
34 struct {{$struct.Name}}* in_data); 34 struct {{$struct.Name}}* in_data);
35 35
36 void {{$struct.Name}}_CloseAllHandles( 36 void {{$struct.Name}}_CloseAllHandles(
37 struct {{$struct.Name}}* in_data); 37 struct {{$struct.Name}}* in_data);
38 38
39 struct {{$struct.Name}}* {{$struct.Name}}_DeepCopy( 39 struct {{$struct.Name}}* {{$struct.Name}}_DeepCopy(
40 struct MojomBuffer* in_buffer, 40 struct MojomBuffer* in_buffer,
41 struct {{$struct.Name}}* in_data); 41 struct {{$struct.Name}}* in_struct);
42 42
43 size_t {{$struct.Name}}_ComputeSerializedSize( 43 size_t {{$struct.Name}}_ComputeSerializedSize(
44 const struct {{$struct.Name}}* in_data); 44 const struct {{$struct.Name}}* in_data);
45 45
46 void {{$struct.Name}}_EncodePointersAndHandles( 46 void {{$struct.Name}}_EncodePointersAndHandles(
47 struct {{$struct.Name}}* inout_struct, uint32_t in_struct_size, 47 struct {{$struct.Name}}* inout_struct, uint32_t in_struct_size,
48 struct MojomHandleBuffer* inout_handle_buffer); 48 struct MojomHandleBuffer* inout_handle_buffer);
49 49
50 void {{$struct.Name}}_DecodePointersAndHandles( 50 void {{$struct.Name}}_DecodePointersAndHandles(
51 struct {{$struct.Name}}* inout_struct, uint32_t in_struct_size, 51 struct {{$struct.Name}}* inout_struct, uint32_t in_struct_size,
52 MojoHandle inout_handles[], uint32_t in_num_handles); 52 MojoHandle inout_handles[], uint32_t in_num_handles);
53 53
54 MojomValidationResult {{$struct.Name}}_Validate( 54 MojomValidationResult {{$struct.Name}}_Validate(
55 const struct {{$struct.Name}}* in_struct, uint32_t in_struct_size, 55 const struct {{$struct.Name}}* in_struct, uint32_t in_struct_size,
56 uint32_t in_num_handles); 56 uint32_t in_num_handles);
57 57
58 {{end}} 58 {{end}}
59 ` 59 `
60 60
61 // TODO(vardhan): Move other struct constant definitions in here. 61 // TODO(vardhan): Move other struct constant definitions in here.
62 const GenerateStructDefinitions = ` 62 const GenerateStructDefinitions = `
63 {{- /* . (dot) refers to the Go type |cgen.StructTemplate| */ -}} 63 {{- /* . (dot) refers to the Go type |cgen.StructTemplate| */ -}}
64 {{define "GenerateStructDefinitions" -}} 64 {{define "GenerateStructDefinitions" -}}
65 {{- $struct := . -}} 65 {{- $struct := . -}}
66 66
67 {{range $const := $struct.Constants -}} 67 {{range $const := $struct.Constants -}}
68 const {{$const.Type}} {{$const.Name}} = {{$const.Value}}; 68 const {{$const.Type}} {{$const.Name}} = {{$const.Value}};
69 {{end -}} 69 {{end -}}
70 70
71 struct {{$struct.Name}}* {{$struct.Name}}_DeepCopy(
72 struct MojomBuffer* in_buffer,
73 struct {{$struct.Name}}* in_struct) {
74 return (struct {{$struct.Name}}*)MojomStruct_DeepCopy(
75 in_buffer, &{{$struct.Name}}__TypeDesc,
76 (struct MojomStructHeader*)in_struct);
77 }
78
71 size_t {{$struct.Name}}_ComputeSerializedSize( 79 size_t {{$struct.Name}}_ComputeSerializedSize(
72 const struct {{$struct.Name}}* in_data) { 80 const struct {{$struct.Name}}* in_data) {
73 return MojomStruct_ComputeSerializedSize( 81 return MojomStruct_ComputeSerializedSize(
74 &{{$struct.Name}}__TypeDesc, 82 &{{$struct.Name}}__TypeDesc,
75 (const struct MojomStructHeader*)in_data); 83 (const struct MojomStructHeader*)in_data);
76 } 84 }
77 85
78 void {{$struct.Name}}_EncodePointersAndHandles( 86 void {{$struct.Name}}_EncodePointersAndHandles(
79 struct {{$struct.Name}}* inout_struct, uint32_t in_struct_size, 87 struct {{$struct.Name}}* inout_struct, uint32_t in_struct_size,
80 struct MojomHandleBuffer* inout_handle_buffer) { 88 struct MojomHandleBuffer* inout_handle_buffer) {
(...skipping 20 matching lines...) Expand all
101 .next_pointer = (char*)in_struct + in_struct->header_.num_bytes, 109 .next_pointer = (char*)in_struct + in_struct->header_.num_bytes,
102 }; 110 };
103 return MojomStruct_Validate( 111 return MojomStruct_Validate(
104 &{{$struct.Name}}__TypeDesc, 112 &{{$struct.Name}}__TypeDesc,
105 (struct MojomStructHeader*)in_struct, in_struct_size, in_num_handles, 113 (struct MojomStructHeader*)in_struct, in_struct_size, in_num_handles,
106 &context); 114 &context);
107 } 115 }
108 116
109 {{end}} 117 {{end}}
110 ` 118 `
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698