Skip to content

Commit 2685acc

Browse files
Use new 'TypeContext' names.
1 parent a083841 commit 2685acc

File tree

7 files changed

+57
-57
lines changed

7 files changed

+57
-57
lines changed

tools/slicec-cs/src/builders.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ impl FunctionBuilder {
347347
let parameter_type = parameter.cs_type_string(&operation.namespace(), context, false);
348348
let parameter_name = parameter.parameter_name();
349349

350-
let default_value = if context == TypeContext::Encode && (index >= trailing_optional_parameters_index) {
350+
let default_value = if context == TypeContext::OutgoingParam && (index >= trailing_optional_parameters_index) {
351351
match parameter.data_type.concrete_typeref() {
352352
// Sequences of fixed-size numeric types are mapped to `ReadOnlyMemory<T>` and have to use
353353
// 'default' as their default value. Other optional types are mapped to nullable types and
@@ -373,15 +373,15 @@ impl FunctionBuilder {
373373
}
374374

375375
match context {
376-
TypeContext::Decode => {
376+
TypeContext::IncomingParam => {
377377
self.add_parameter(
378378
"IceRpc.Features.IFeatureCollection",
379379
&escape_parameter_name(&parameters, "features"),
380380
None,
381381
Some("The dispatch features.".to_owned()),
382382
);
383383
}
384-
TypeContext::Encode => {
384+
TypeContext::OutgoingParam => {
385385
self.add_parameter(
386386
"IceRpc.Features.IFeatureCollection?",
387387
&escape_parameter_name(&parameters, "features"),
@@ -395,7 +395,7 @@ impl FunctionBuilder {
395395
self.add_parameter(
396396
"global::System.Threading.CancellationToken",
397397
&escape_parameter_name(&parameters, "cancellationToken"),
398-
if context == TypeContext::Encode {
398+
if context == TypeContext::OutgoingParam {
399399
Some("default")
400400
} else {
401401
None
@@ -450,8 +450,8 @@ impl FunctionBuilder {
450450
// since they can't have '@returns' tags in their doc comments.
451451
if operation.return_type.is_empty() {
452452
let comment = match context {
453-
TypeContext::Decode => "A value task that completes when this implementation completes.",
454-
TypeContext::Encode => "A task that completes when the response is received.",
453+
TypeContext::IncomingParam => "A value task that completes when this implementation completes.",
454+
TypeContext::OutgoingParam => "A task that completes when the response is received.",
455455
_ => unreachable!("Unexpected context value"),
456456
};
457457
self.add_comment("returns", comment);

tools/slicec-cs/src/decoding.rs

+17-17
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ pub fn default_activator(encoding: Encoding) -> &'static str {
9898
fn decode_member(member: &impl Member, namespace: &str, encoding: Encoding) -> CodeBlock {
9999
let mut code = CodeBlock::default();
100100
let data_type = member.data_type();
101-
let type_string = data_type.cs_type_string(namespace, TypeContext::Decode, true);
101+
let type_string = data_type.cs_type_string(namespace, TypeContext::IncomingParam, true);
102102

103103
if data_type.is_optional {
104104
match data_type.concrete_type() {
@@ -199,11 +199,11 @@ pub fn decode_dictionary(dictionary_ref: &TypeRef<Dictionary>, namespace: &str,
199199
write!(
200200
decode_value,
201201
" as {}",
202-
value_type.cs_type_string(namespace, TypeContext::Nested, true),
202+
value_type.cs_type_string(namespace, TypeContext::Field, true),
203203
);
204204
}
205205

206-
let dictionary_type = dictionary_ref.cs_type_string(namespace, TypeContext::Decode, true);
206+
let dictionary_type = dictionary_ref.cs_type_string(namespace, TypeContext::IncomingParam, true);
207207
let decode_key = decode_key.indent();
208208
let decode_value = decode_value.indent();
209209

@@ -257,20 +257,20 @@ pub fn decode_sequence(sequence_ref: &TypeRef<Sequence>, namespace: &str, encodi
257257
write!(
258258
code,
259259
"({}[])",
260-
element_type.cs_type_string(namespace, TypeContext::Nested, false),
260+
element_type.cs_type_string(namespace, TypeContext::Field, false),
261261
);
262262
};
263263

264264
if has_cs_type_attribute {
265-
let sequence_type = sequence_ref.cs_type_string(namespace, TypeContext::Decode, true);
265+
let sequence_type = sequence_ref.cs_type_string(namespace, TypeContext::IncomingParam, true);
266266

267267
let arg: Option<String> = match element_type.concrete_type() {
268268
Types::Primitive(primitive) if primitive.fixed_wire_size().is_some() && !element_type.is_optional => {
269269
// We always read an array even when mapped to a collection, as it's expected to be
270270
// faster than decoding the collection elements one by one.
271271
Some(format!(
272272
"decoder.DecodeSequence<{}>({})",
273-
element_type.cs_type_string(namespace, TypeContext::Decode, true),
273+
element_type.cs_type_string(namespace, TypeContext::IncomingParam, true),
274274
if matches!(primitive, Primitive::Bool) {
275275
"checkElement: SliceDecoder.CheckBoolValue"
276276
} else {
@@ -288,14 +288,14 @@ pub fn decode_sequence(sequence_ref: &TypeRef<Sequence>, namespace: &str, encodi
288288
if enum_def.is_unchecked {
289289
Some(format!(
290290
"decoder.DecodeSequence<{}>()",
291-
element_type.cs_type_string(namespace, TypeContext::Decode, true),
291+
element_type.cs_type_string(namespace, TypeContext::IncomingParam, true),
292292
))
293293
} else {
294294
Some(format!(
295295
"\
296296
decoder.DecodeSequence(
297297
({enum_type_name} e) => _ = {underlying_extensions_class}.As{name}(({underlying_type})e))",
298-
enum_type_name = element_type.cs_type_string(namespace, TypeContext::Decode, false),
298+
enum_type_name = element_type.cs_type_string(namespace, TypeContext::IncomingParam, false),
299299
underlying_extensions_class = enum_def.escape_scoped_identifier_with_suffix(
300300
&format!(
301301
"{}Extensions",
@@ -355,7 +355,7 @@ decoder.DecodeSequenceOfOptionals(
355355
write!(
356356
code,
357357
"decoder.DecodeSequence<{}>({})",
358-
element_type.cs_type_string(namespace, TypeContext::Decode, true),
358+
element_type.cs_type_string(namespace, TypeContext::IncomingParam, true),
359359
if matches!(primitive, Primitive::Bool) {
360360
"checkElement: SliceDecoder.CheckBoolValue"
361361
} else {
@@ -368,15 +368,15 @@ decoder.DecodeSequenceOfOptionals(
368368
write!(
369369
code,
370370
"decoder.DecodeSequence<{}>()",
371-
element_type.cs_type_string(namespace, TypeContext::Decode, true),
371+
element_type.cs_type_string(namespace, TypeContext::IncomingParam, true),
372372
)
373373
} else {
374374
write!(
375375
code,
376376
"\
377377
decoder.DecodeSequence(
378378
({enum_type} e) => _ = {underlying_extensions_class}.As{name}(({underlying_type})e))",
379-
enum_type = element_type.cs_type_string(namespace, TypeContext::Decode, false),
379+
enum_type = element_type.cs_type_string(namespace, TypeContext::IncomingParam, false),
380380
underlying_extensions_class = enum_def.escape_scoped_identifier_with_suffix(
381381
&format!(
382382
"{}Extensions",
@@ -424,7 +424,7 @@ fn decode_result_field(type_ref: &TypeRef, namespace: &str, encoding: Encoding)
424424
write!(
425425
decode_func_body,
426426
" as {}",
427-
type_ref.cs_type_string(namespace, TypeContext::Nested, false),
427+
type_ref.cs_type_string(namespace, TypeContext::Field, false),
428428
);
429429
}
430430

@@ -445,7 +445,7 @@ fn decode_result_field(type_ref: &TypeRef, namespace: &str, encoding: Encoding)
445445
write!(
446446
decode_func,
447447
" as {}",
448-
type_ref.cs_type_string(namespace, TypeContext::Nested, false),
448+
type_ref.cs_type_string(namespace, TypeContext::Field, false),
449449
);
450450
}
451451

@@ -461,7 +461,7 @@ pub fn decode_func(type_ref: &TypeRef, namespace: &str, encoding: Encoding) -> C
461461

462462
fn decode_func_body(type_ref: &TypeRef, namespace: &str, encoding: Encoding) -> CodeBlock {
463463
let mut code = CodeBlock::default();
464-
let type_name = type_ref.cs_type_string(namespace, TypeContext::Decode, true);
464+
let type_name = type_ref.cs_type_string(namespace, TypeContext::IncomingParam, true);
465465

466466
// When we decode the type, we decode it as a non-optional.
467467
// If the type is supposed to be optional, we cast it after decoding.
@@ -548,7 +548,7 @@ pub fn decode_operation(operation: &Operation, dispatch: bool) -> CodeBlock {
548548
// For optional value types we have to use the full type as the compiler cannot
549549
// disambiguate between null and the actual value type.
550550
param_type = match member.data_type().is_optional && member.data_type().is_value_type() {
551-
true => member.data_type().cs_type_string(namespace, TypeContext::Decode, false),
551+
true => member.data_type().cs_type_string(namespace, TypeContext::IncomingParam, false),
552552
false => String::from("var"),
553553
},
554554
param_name = &member.parameter_name_with_prefix("sliceP_"),
@@ -563,7 +563,7 @@ pub fn decode_operation(operation: &Operation, dispatch: bool) -> CodeBlock {
563563
// For optional value types we have to use the full type as the compiler cannot
564564
// disambiguate between null and the actual value type.
565565
param_type = match member.data_type().is_value_type() {
566-
true => member.data_type().cs_type_string(namespace, TypeContext::Decode, false),
566+
true => member.data_type().cs_type_string(namespace, TypeContext::IncomingParam, false),
567567
false => String::from("var"),
568568
},
569569
param_name = &member.parameter_name_with_prefix("sliceP_"),
@@ -589,7 +589,7 @@ pub fn decode_operation_stream(
589589
) -> CodeBlock {
590590
let cs_encoding = encoding.to_cs_encoding();
591591
let param_type = stream_member.data_type();
592-
let param_type_str = param_type.cs_type_string(namespace, TypeContext::Decode, false);
592+
let param_type_str = param_type.cs_type_string(namespace, TypeContext::IncomingParam, false);
593593
let fixed_wire_size = param_type.fixed_wire_size();
594594

595595
match param_type.concrete_type() {

tools/slicec-cs/src/encoding.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ if ({param} != null)
138138
TypeRefs::Sequence(sequence_ref)
139139
if sequence_ref.has_fixed_size_primitive_elements()
140140
&& !sequence_ref.has_attribute::<CsType>()
141-
&& type_context == TypeContext::Encode =>
141+
&& type_context == TypeContext::OutgoingParam =>
142142
format!("{param}.Span"),
143143
_ => param.to_owned(),
144144
},
@@ -170,7 +170,7 @@ fn encode_tagged_type(
170170
let read_only_memory = matches!(
171171
data_type.concrete_type(),
172172
Types::Sequence(sequence_def) if sequence_def.has_fixed_size_primitive_elements()
173-
&& type_context == TypeContext::Encode
173+
&& type_context == TypeContext::OutgoingParam
174174
&& !data_type.has_attribute::<CsType>()
175175
);
176176

@@ -289,7 +289,7 @@ fn encode_sequence(
289289
encoding: Encoding,
290290
) -> CodeBlock {
291291
if sequence_ref.has_fixed_size_primitive_elements() && !sequence_ref.has_attribute::<CsType>() {
292-
if type_context == TypeContext::Encode {
292+
if type_context == TypeContext::OutgoingParam {
293293
format!("{encoder_param}.EncodeSpan({value}.Span)")
294294
} else {
295295
format!("{encoder_param}.EncodeSequence({value})")
@@ -306,7 +306,7 @@ fn encode_sequence(
306306
} else {
307307
""
308308
},
309-
encode_action = encode_action(element_type, TypeContext::Nested, namespace, encoding, false).indent(),
309+
encode_action = encode_action(element_type, TypeContext::Field, namespace, encoding, false).indent(),
310310
)
311311
}
312312
.into()
@@ -332,8 +332,8 @@ fn encode_dictionary(
332332
} else {
333333
"EncodeDictionary"
334334
},
335-
encode_key = encode_action(key_type, TypeContext::Nested, namespace, encoding, false).indent(),
336-
encode_value = encode_action(value_type, TypeContext::Nested, namespace, encoding, false).indent(),
335+
encode_key = encode_action(key_type, TypeContext::Field, namespace, encoding, false).indent(),
336+
encode_value = encode_action(value_type, TypeContext::Field, namespace, encoding, false).indent(),
337337
)
338338
.into()
339339
}
@@ -533,7 +533,7 @@ fn encode_operation_parameters(operation: &Operation, return_type: bool, encoder
533533

534534
code.writeln(&encode_type(
535535
member.data_type(),
536-
TypeContext::Encode,
536+
TypeContext::OutgoingParam,
537537
namespace,
538538
name.as_str(),
539539
encoder_param,
@@ -552,7 +552,7 @@ fn encode_operation_parameters(operation: &Operation, return_type: bool, encoder
552552
namespace,
553553
name.as_str(),
554554
encoder_param,
555-
TypeContext::Encode,
555+
TypeContext::OutgoingParam,
556556
operation.encoding,
557557
));
558558
}

tools/slicec-cs/src/generators/dispatch_generator.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ fn request_class(interface_def: &Interface) -> CodeBlock {
108108
},
109109
&format!(
110110
"global::System.Threading.Tasks.ValueTask<{}>",
111-
&parameters.to_tuple_type(namespace, TypeContext::Decode, false),
111+
&parameters.to_tuple_type(namespace, TypeContext::IncomingParam, false),
112112
),
113113
&operation.escape_identifier_with_prefix_and_suffix("Decode", "Async"),
114114
function_type,
@@ -192,7 +192,7 @@ fn response_class(interface_def: &Interface) -> CodeBlock {
192192
match non_streamed_returns.as_slice() {
193193
[param] => {
194194
builder.add_parameter(
195-
&param.cs_type_string(namespace, TypeContext::Encode, false),
195+
&param.cs_type_string(namespace, TypeContext::OutgoingParam, false),
196196
"returnValue",
197197
None,
198198
Some("The operation return value.".to_owned()),
@@ -201,7 +201,7 @@ fn response_class(interface_def: &Interface) -> CodeBlock {
201201
_ => {
202202
for param in &non_streamed_returns {
203203
builder.add_parameter(
204-
&param.cs_type_string(namespace, TypeContext::Encode, false),
204+
&param.cs_type_string(namespace, TypeContext::OutgoingParam, false),
205205
&param.parameter_name(),
206206
None,
207207
param.formatted_parameter_doc_comment(),
@@ -345,7 +345,7 @@ fn operation_declaration(operation: &Operation) -> CodeBlock {
345345
builder.add_comment("summary", summary);
346346
}
347347
builder
348-
.add_operation_parameters(operation, TypeContext::Decode)
348+
.add_operation_parameters(operation, TypeContext::IncomingParam)
349349
.add_comments(operation.formatted_doc_comment_seealso())
350350
.build()
351351
}
@@ -567,7 +567,7 @@ fn payload_continuation(operation: &Operation, encoding: &str) -> CodeBlock {
567567
{encoding},
568568
{encode_options})",
569569
encode_stream_parameter =
570-
encode_stream_parameter(stream_type, TypeContext::Encode, namespace, operation.encoding)
570+
encode_stream_parameter(stream_type, TypeContext::OutgoingParam, namespace, operation.encoding)
571571
.indent(),
572572
use_segments = stream_type.fixed_wire_size().is_none(),
573573
encode_options = "request.Features.Get<ISliceFeature>()?.EncodeOptions",

tools/slicec-cs/src/generators/proxy_generator.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ fn proxy_operation_impl(operation: &Operation) -> CodeBlock {
293293
let mut builder = FunctionBuilder::new("public", &return_task, &async_operation_name, body_type);
294294
builder.set_inherit_doc(true);
295295
builder.add_obsolete_attribute(operation);
296-
builder.add_operation_parameters(operation, TypeContext::Encode);
296+
builder.add_operation_parameters(operation, TypeContext::OutgoingParam);
297297

298298
let mut body = CodeBlock::default();
299299

@@ -347,11 +347,11 @@ if ({features_parameter}?.Get<IceRpc.Features.ICompressFeature>() is null)
347347
invocation_builder.add_argument(
348348
FunctionCallBuilder::new(format!(
349349
"{stream_parameter_name}.ToPipeReader<{}>",
350-
stream_type.cs_type_string(namespace, TypeContext::Encode, false),
350+
stream_type.cs_type_string(namespace, TypeContext::OutgoingParam, false),
351351
))
352352
.use_semicolon(false)
353353
.add_argument(
354-
encode_stream_parameter(stream_type, TypeContext::Encode, namespace, operation.encoding)
354+
encode_stream_parameter(stream_type, TypeContext::OutgoingParam, namespace, operation.encoding)
355355
.indent(),
356356
)
357357
.add_argument(stream_type.fixed_wire_size().is_none())
@@ -409,7 +409,7 @@ fn proxy_base_operation_impl(operation: &Operation, namespace: &str) -> CodeBloc
409409
let mut builder = FunctionBuilder::new("public", &return_task, &async_name, FunctionType::ExpressionBody);
410410
builder.set_inherit_doc(true);
411411
builder.add_obsolete_attribute(operation);
412-
builder.add_operation_parameters(operation, TypeContext::Encode);
412+
builder.add_operation_parameters(operation, TypeContext::OutgoingParam);
413413

414414
builder.set_body(
415415
format!(
@@ -438,7 +438,7 @@ fn proxy_interface_operations(interface_def: &Interface) -> CodeBlock {
438438
builder.add_comment("summary", summary);
439439
}
440440
builder
441-
.add_operation_parameters(operation, TypeContext::Encode)
441+
.add_operation_parameters(operation, TypeContext::OutgoingParam)
442442
.add_comments(operation.formatted_doc_comment_seealso())
443443
.add_obsolete_attribute(operation);
444444
code.add_block(&builder.build());
@@ -489,7 +489,7 @@ fn request_class(interface_def: &Interface) -> CodeBlock {
489489

490490
for param in &params {
491491
builder.add_parameter(
492-
&param.cs_type_string(namespace, TypeContext::Encode, false),
492+
&param.cs_type_string(namespace, TypeContext::OutgoingParam, false),
493493
&param.parameter_name(),
494494
None,
495495
param.formatted_parameter_doc_comment(),
@@ -557,7 +557,7 @@ fn response_class(interface_def: &Interface) -> CodeBlock {
557557
} else {
558558
format!(
559559
"global::System.Threading.Tasks.ValueTask<{}>",
560-
members.to_tuple_type(namespace, TypeContext::Decode, false),
560+
members.to_tuple_type(namespace, TypeContext::IncomingParam, false),
561561
)
562562
};
563563

tools/slicec-cs/src/slicec_ext/operation_ext.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ impl OperationExt for Operation {
3838
self,
3939
is_dispatch,
4040
if is_dispatch {
41-
TypeContext::Encode
41+
TypeContext::OutgoingParam
4242
} else {
43-
TypeContext::Decode
43+
TypeContext::IncomingParam
4444
},
4545
);
4646
if is_dispatch {

0 commit comments

Comments
 (0)