(
named_address_mapping: &BTreeMap<ModuleId, impl AsRef<str>>,
module: &CompiledModule,
)
| 45 | } |
| 46 | |
| 47 | pub fn write_module_to_string( |
| 48 | named_address_mapping: &BTreeMap<ModuleId, impl AsRef<str>>, |
| 49 | module: &CompiledModule, |
| 50 | ) -> Result<(ModuleId, String)> { |
| 51 | let mut out = String::new(); |
| 52 | |
| 53 | let id = module.self_id(); |
| 54 | push_line!( |
| 55 | out, |
| 56 | format!("module {} {{", write_module_id(named_address_mapping, &id)) |
| 57 | ); |
| 58 | push_line!(out, ""); |
| 59 | |
| 60 | let mut context = Context::new(module); |
| 61 | let mut members = vec![]; |
| 62 | |
| 63 | for fdecl in module.friend_decls() { |
| 64 | members.push(write_friend_decl(&mut context, fdecl)); |
| 65 | } |
| 66 | if !module.friend_decls().is_empty() { |
| 67 | members.push("".to_string()); |
| 68 | } |
| 69 | |
| 70 | for sdef in module.struct_defs() { |
| 71 | members.push(write_struct_def(&mut context, sdef)); |
| 72 | } |
| 73 | if !module.struct_defs().is_empty() { |
| 74 | members.push("".to_string()); |
| 75 | } |
| 76 | |
| 77 | let mut externally_visible_funs = module |
| 78 | .function_defs() |
| 79 | .iter() |
| 80 | .filter(|fdef| match fdef.visibility { |
| 81 | Visibility::Public | Visibility::Friend => true, |
| 82 | Visibility::Private => false, |
| 83 | }) |
| 84 | .peekable(); |
| 85 | let has_externally_visible_funs = externally_visible_funs.peek().is_some(); |
| 86 | if has_externally_visible_funs { |
| 87 | members.push(format!(" {}", DISCLAIMER)); |
| 88 | } |
| 89 | for fdef in externally_visible_funs { |
| 90 | members.push(write_function_def(&mut context, fdef)); |
| 91 | } |
| 92 | if has_externally_visible_funs { |
| 93 | members.push("".to_string()); |
| 94 | } |
| 95 | |
| 96 | let has_uses = !context.uses.is_empty(); |
| 97 | for (module_id, alias) in context.uses { |
| 98 | let use_ = if module_id.name().as_str() == alias { |
| 99 | format!( |
| 100 | " use {};", |
| 101 | write_module_id(named_address_mapping, &module_id), |
| 102 | ) |
| 103 | } else { |
| 104 | format!( |
no test coverage detected