Compare commits

...

2 Commits

Author SHA1 Message Date
uan
ccd59f6a0a specify immutable class members 2026-02-08 11:20:23 +01:00
uan
08686c2681 print specify immutable members 2026-02-08 08:47:13 +01:00

View File

@@ -82,12 +82,20 @@ fn (mut g Generator) gen_class_print_func(stmt ClassDecl) {
g.out.writeln('for(int i=0; i<indent + 1; i++) printf(" ");') g.out.writeln('for(int i=0; i<indent + 1; i++) printf(" ");')
g.out.write_string('printf("${member.name}: ");') g.out.write_string('printf("${member.name}: ");')
if member.type != 'string' && g.symbols.lookup_class(member.type) != none { if member.type != 'string' && g.symbols.lookup_class(member.type) != none {
inner_struct_name := mangle_struct(member.type) inner_struct_name := mangle_struct(member.type)
g.out.writeln('print_${inner_struct_name}(s.${member.name}, indent + 1);') g.out.write_string('print_${inner_struct_name}(s.${member.name}, indent + 1);')
if member.is_immutable {
g.out.write_string('printf(" (immutable)\\n");')
}
} else { } else {
format := get_type_format(member.type) format := get_type_format(member.type)
g.out.write_string('printf("%${format}\\n", s.${member.name}') g.out.write_string('printf("%${format}')
if member.is_immutable {
g.out.write_string(' (immutable) ')
}
g.out.write_string('\\n", s.${member.name}')
if member.type == 'string' { if member.type == 'string' {
g.out.write_string('.string') g.out.write_string('.string')
} }