MCPcopy Create free account
hub / github.com/diem/move / write_module_to_string

Function write_module_to_string

language/move-compiler/src/interface_generator.rs:47–121  ·  view source on GitHub ↗
(
    named_address_mapping: &BTreeMap<ModuleId, impl AsRef<str>>,
    module: &CompiledModule,
)

Source from the content-addressed store, hash-verified

45}
46
47pub 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!(

Callers 2

write_file_to_stringFunction · 0.85

Calls 15

write_friend_declFunction · 0.85
write_struct_defFunction · 0.85
write_function_defFunction · 0.85
to_stringMethod · 0.80
self_idMethod · 0.45
friend_declsMethod · 0.45
pushMethod · 0.45
is_emptyMethod · 0.45
struct_defsMethod · 0.45
filterMethod · 0.45
iterMethod · 0.45
function_defsMethod · 0.45

Tested by

no test coverage detected