Mercurial > hg > CbC > CbC_xv6
comparison src/gearsTools/lib/Gears/Context.pm @ 345:efef0767b1bc
emit include guard at context.h
author | anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Sun, 01 Mar 2020 18:10:05 +0900 |
parents | 0e1c64818c0d |
children | 36ed64fea8c1 |
comparison
equal
deleted
inserted
replaced
344:12c7ba704de7 | 345:efef0767b1bc |
---|---|
84 | 84 |
85 sub tree2data_struct_str { | 85 sub tree2data_struct_str { |
86 my ($self, $dg_str) = @_; | 86 my ($self, $dg_str) = @_; |
87 my $data_struct_str = ""; | 87 my $data_struct_str = ""; |
88 for my $interface (sort keys %$dg_str) { | 88 for my $interface (sort keys %$dg_str) { |
89 $data_struct_str .= Gears::Util->h2context_str($dg_str->{$interface}->{elem}); | 89 $data_struct_str .= $self->h2context_str($dg_str->{$interface}->{elem}); |
90 next unless ($dg_str->{$interface}->{impl}); | 90 next unless ($dg_str->{$interface}->{impl}); |
91 for my $impl (sort keys %{$dg_str->{$interface}->{impl}}) { | 91 for my $impl (sort keys %{$dg_str->{$interface}->{impl}}) { |
92 $data_struct_str .= Gears::Util->h2context_str($dg_str->{$interface}->{impl}->{$impl}); | 92 $data_struct_str .= $self->h2context_str($dg_str->{$interface}->{impl}->{$impl}); |
93 } | 93 } |
94 } | 94 } |
95 return $data_struct_str; | 95 return $data_struct_str; |
96 } | 96 } |
97 | 97 |
119 } | 119 } |
120 } keys %$impls; | 120 } keys %$impls; |
121 return \%dg_str; | 121 return \%dg_str; |
122 } | 122 } |
123 | 123 |
124 sub h2context_str { | |
125 my ($self, $h2context) = @_; | |
126 my $space = ' '; | |
127 | |
128 my $context = "${space}//$h2context->{file_name}\n"; | |
129 $context .= "#ifndef ". uc($h2context->{name}) ."_STRUCT \n"; | |
130 $context .= "${space}struct $h2context->{name} {\n"; | |
131 my $content_space; | |
132 | |
133 my @enumCodes; | |
134 my @var; | |
135 | |
136 for my $c (@{$h2context->{content}}) { | |
137 if ($c =~ /\A\s*enum Code/) { | |
138 push(@enumCodes,$c); | |
139 } else { | |
140 push(@var,$c); | |
141 } | |
142 } | |
143 | |
144 if (@var){ | |
145 my @chars = split //, $var[0]; | |
146 for my $w (@chars) { | |
147 last if ($w !~ /\s/); | |
148 $content_space .= $w; | |
149 } | |
150 } | |
151 | |
152 unless (defined $content_space) { | |
153 $content_space = ""; | |
154 } | |
155 | |
156 for my $c (@var) { | |
157 $c =~ s/$content_space//; | |
158 $context .= "${space}${space}$c"; | |
159 } | |
160 | |
161 for my $c (@enumCodes) { | |
162 $c =~ s/$content_space//; | |
163 $context .= "${space}${space}$c"; | |
164 } | |
165 | |
166 $context .= "${space}} $h2context->{name};\n"; | |
167 $context .= "#define ". uc($h2context->{name}) ."_STRUCT \n"; | |
168 $context .= "#endif\n"; | |
169 return $context; | |
170 } | |
171 | |
124 1; | 172 1; |