Mercurial > hg > CbC > CbC_xv6
changeset 349:0e72eb96b6b1
fix decamelize
author | anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 02 Mar 2020 15:38:42 +0900 |
parents | 1616cb02ecec |
children | 26ab43de3654 |
files | src/gearsTools/check_convert_context_struct.pl src/gearsTools/static_gen_header.pl src/gearsTools/trans_impl.pl src/impl/ConsoleIO.cbc |
diffstat | 4 files changed, 41 insertions(+), 25 deletions(-) [+] |
line wrap: on
line diff
--- a/src/gearsTools/check_convert_context_struct.pl Mon Mar 02 15:14:19 2020 +0900 +++ b/src/gearsTools/check_convert_context_struct.pl Mon Mar 02 15:38:42 2020 +0900 @@ -5,6 +5,7 @@ use FindBin; use lib "$FindBin::Bin/lib"; use Gears::Util; +use Gears::Context; my $interface_file = shift or die "require itnerface file";
--- a/src/gearsTools/static_gen_header.pl Mon Mar 02 15:14:19 2020 +0900 +++ b/src/gearsTools/static_gen_header.pl Mon Mar 02 15:38:42 2020 +0900 @@ -75,7 +75,7 @@ my $type = shift; my $msg = <<"EOF"; __code next(....); -} $type; EOF + $msg .= "} $type;\n" return $msg; }
--- a/src/gearsTools/trans_impl.pl Mon Mar 02 15:14:19 2020 +0900 +++ b/src/gearsTools/trans_impl.pl Mon Mar 02 15:38:42 2020 +0900 @@ -24,8 +24,7 @@ $interface_var_name = $1; } -my $impl_var_name = lcfirst $impl_ir->{name}; -$impl_var_name =~ s/([A-Z])/_\l$1/g; +my $impl_var_name = decamelize($impl_ir->{name}); my $interface = {ir => $inter_ir, var_name => $interface_var_name}; my $impl = {ir => $impl_ir, var_name => $impl_var_name}; @@ -51,7 +50,7 @@ emit_include_part($stdout, $inter_ir->{name}); emit_impl_header_in_comment($stdout, $impl_file); emit_constracutor($stdout,$impl,$interface); -emit_code_gears($stdout,$impl_ir,$inter_ir); +emit_code_gears($stdout,$impl,$interface); close $stdout; sub emit_include_part { @@ -134,23 +133,25 @@ sub emit_code_gears { - my ($out, $impl_ir, $inter_ir) = @_; - my $impl = $impl_ir->{name}; + my ($out, $impl, $interface) = @_; + + my $inter_ir = $interface->{ir}; + my $impl_ir = $impl->{ir}; + + my $impl_name = $impl_ir->{name}; my $interface_name = $inter_ir->{name}; + my $impl_var_name = $impl->{var_name}; + my $interface_var_name = $interface->{var_name}; + my @inter_data = @{$inter_ir->{data}}; - my $interface_var_name = shift @inter_data; - if ($interface_var_name =~ /union\s*Data\*\s*(\w+)/) { - $interface_var_name = $1; - } - my $impl_var_name = lcfirst $impl_ir->{name}; - $impl_var_name =~ s/([A-Z])/_\l$1/g; + my $data_gear_types = {}; if (defined $impl_ir->{codes}) { - replace_code_gears($impl_ir,$impl,$interface_name,1,$out); + replace_code_gears($impl_ir,$impl_name,$interface_name,1,$out); } - replace_code_gears($inter_ir,$impl,$interface_name,0,$out); + replace_code_gears($inter_ir,$impl_name,$interface_name,0,$out); } sub replace_code_gears { @@ -206,7 +207,7 @@ my ($output_file, $interface, $impl, $impl_file) = @_; my $under_code = collection_save_code_gears($output_file,$interface->{var_name}); open my $fh, '>', $output_file; - emit_include_part($fh, $interface->{var_name}); + emit_include_part($fh, $interface->{ir}->{name}); emit_impl_header_in_comment($fh, $impl_file); emit_constracutor($fh,$impl,$interface); map { print $fh $_ } @{$under_code}; @@ -227,3 +228,17 @@ push(@res, <$fh>); return \@res; } + +#https://metacpan.org/pod/String::CamelCase +sub decamelize +{ + my $s = shift; + $s =~ s{([^a-zA-Z]?)([A-Z]*)([A-Z])([a-z]?)}{ + my $fc = pos($s)==0; + my ($p0,$p1,$p2,$p3) = ($1,lc$2,lc$3,$4); + my $t = $p0 || $fc ? $p0 : '_'; + $t .= $p3 ? $p1 ? "${p1}_$p2$p3" : "$p2$p3" : "$p1$p2"; + $t; + }ge; + $s; +}
--- a/src/impl/ConsoleIO.cbc Mon Mar 02 15:14:19 2020 +0900 +++ b/src/impl/ConsoleIO.cbc Mon Mar 02 15:38:42 2020 +0900 @@ -12,16 +12,16 @@ IO* createConsoleIO(struct Context* cbc_context) { struct IO* io = new IO(); - struct ConsoleIO* console_i_o = new ConsoleIO(); - io->io = (union Data*)console_i_o; - console_i_o->IO = NULL; - console_i_o->ip = NULL; - console_i_o->dst = NULL; - console_i_o->n = 0; - console_i_o->target = 0; - console_i_o->consoleread = C_consoleread; - console_i_o->consoleread1 = C_consoleread1; - console_i_o->consoleread2 = C_consoleread2; + struct ConsoleIO* console_io = new ConsoleIO(); + io->io = (union Data*)console_io; + console_io->IO = NULL; + console_io->ip = NULL; + console_io->dst = NULL; + console_io->n = 0; + console_io->target = 0; + console_io->consoleread = C_consoleread; + console_io->consoleread1 = C_consoleread1; + console_io->consoleread2 = C_consoleread2; io->read = C_readConsoleIO; io->write = C_writeConsoleIO; io->close = C_closeConsoleIO;