MCPcopy Create free account
hub / github.com/bytecodealliance/wit-bindgen / name_with_qualifier

Method name_with_qualifier

crates/csharp/src/interface.rs:1189–1324  ·  view source on GitHub ↗
(
        &mut self,
        ty: &Type,
        qualifier: bool,
        parameter_type: ParameterType,
    )

Source from the content-addressed store, hash-verified

1187 }
1188
1189 pub(crate) fn name_with_qualifier(
1190 &mut self,
1191 ty: &Type,
1192 qualifier: bool,
1193 parameter_type: ParameterType,
1194 ) -> String {
1195 match ty {
1196 Type::Bool => "bool".to_owned(),
1197 Type::U8 => "byte".to_owned(),
1198 Type::U16 => "ushort".to_owned(),
1199 Type::U32 => "uint".to_owned(),
1200 Type::U64 => "ulong".to_owned(),
1201 Type::S8 => "sbyte".to_owned(),
1202 Type::S16 => "short".to_owned(),
1203 Type::S32 => "int".to_owned(),
1204 Type::S64 => "long".to_owned(),
1205 Type::F32 => "float".to_owned(),
1206 Type::F64 => "double".to_owned(),
1207 Type::Char => "uint".to_owned(),
1208 Type::String => "string".to_owned(),
1209 Type::ErrorContext => todo!("error context name with qualifier"),
1210 Type::Id(id) => {
1211 let ty = &self.resolve.types[*id];
1212 match &ty.kind {
1213 TypeDefKind::Type(ty) => {
1214 self.name_with_qualifier(ty, qualifier, parameter_type)
1215 }
1216 TypeDefKind::List(ty) => {
1217 if crate::world_generator::is_primitive(ty)
1218 && self.direction == Direction::Import
1219 && parameter_type == ParameterType::Span
1220 {
1221 format!("global::System.Span<{}>", self.type_name(ty))
1222 } else if crate::world_generator::is_primitive(ty)
1223 && self.direction == Direction::Import
1224 && parameter_type == ParameterType::Memory
1225 {
1226 format!("global::System.Memory<{}>", self.type_name(ty))
1227 } else if crate::world_generator::is_primitive(ty) {
1228 format!("{}[]", self.type_name(ty))
1229 } else {
1230 format!(
1231 "global::System.Collections.Generic.List<{}>",
1232 self.type_name_with_qualifier(ty, qualifier)
1233 )
1234 }
1235 }
1236 TypeDefKind::Tuple(tuple) => {
1237 let count = tuple.types.len();
1238 self.csharp_gen.tuple_counts.insert(count);
1239
1240 let params = match count {
1241 0 => String::new(),
1242 1 => self
1243 .type_name_with_qualifier(tuple.types.first().unwrap(), qualifier),
1244 _ => format!(
1245 "({})",
1246 tuple

Callers 2

gen_import_srcMethod · 0.80

Calls 5

is_primitiveFunction · 0.85
newFunction · 0.85
mapMethod · 0.80
insertMethod · 0.45

Tested by

no test coverage detected