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

Method generate_function

crates/cpp/src/lib.rs:1279–1483  ·  view source on GitHub ↗
(&mut self, func: &Function, owner: &TypeOwner, variant: AbiVariant)

Source from the content-addressed store, hash-verified

1277 }
1278
1279 fn generate_function(&mut self, func: &Function, owner: &TypeOwner, variant: AbiVariant) {
1280 fn class_namespace(
1281 cifg: &CppInterfaceGenerator,
1282 func: &Function,
1283 variant: AbiVariant,
1284 ) -> Vec<String> {
1285 let owner = &cifg.resolve.types[match &func.kind {
1286 FunctionKind::Static(id) => *id,
1287 _ => panic!("special func should be static"),
1288 }];
1289 let mut namespace = namespace(
1290 cifg.resolve,
1291 &owner.owner,
1292 matches!(variant, AbiVariant::GuestExport),
1293 &cifg.r#gen.opts,
1294 );
1295 namespace.push(owner.name.as_ref().unwrap().to_upper_camel_case());
1296 namespace
1297 }
1298
1299 let export = match variant {
1300 AbiVariant::GuestImport => false,
1301 AbiVariant::GuestExport => true,
1302 AbiVariant::GuestImportAsync => todo!(),
1303 AbiVariant::GuestExportAsync => todo!(),
1304 AbiVariant::GuestExportAsyncStackful => todo!(),
1305 };
1306 if func.docs.contents.is_some() && !self.r#gen.h_src.src.ends_with('\n') {
1307 uwriteln!(self.r#gen.h_src.src, "");
1308 }
1309 Self::docs(&mut self.r#gen.h_src.src, &func.docs);
1310 let params = self.print_signature(func, variant, !export);
1311 let special = is_special_method(func);
1312 if !matches!(special, SpecialMethod::Allocate) {
1313 self.r#gen.c_src.src.push_str("{\n");
1314 let needs_dealloc = if self.r#gen.opts.api_style == APIStyle::Symmetric
1315 && matches!(variant, AbiVariant::GuestExport)
1316 {
1317 self.r#gen
1318 .c_src
1319 .src
1320 .push_str("std::vector<void*> _deallocate;\n");
1321 self.r#gen.dependencies.needs_vector = true;
1322 true
1323 } else {
1324 false
1325 };
1326 let lift_lower = if export {
1327 LiftLower::LiftArgsLowerResults
1328 } else {
1329 LiftLower::LowerArgsLiftResults
1330 };
1331 match is_special_method(func) {
1332 SpecialMethod::ResourceDrop => match lift_lower {
1333 LiftLower::LiftArgsLowerResults => {
1334 let module_name =
1335 String::from("[export]") + &self.wasm_import_module.clone().unwrap();
1336 let wasm_sig =

Callers 5

import_interfaceMethod · 0.80
export_interfaceMethod · 0.80
import_funcsMethod · 0.80
export_funcsMethod · 0.80
type_resourceMethod · 0.80

Calls 15

is_special_methodFunction · 0.85
namespaceFunction · 0.85
newFunction · 0.85
callFunction · 0.85
make_external_componentFunction · 0.85
make_external_symbolFunction · 0.85
post_returnFunction · 0.85
joinMethod · 0.80
print_signatureMethod · 0.45
push_strMethod · 0.45

Tested by

no test coverage detected