changeset 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 12c7ba704de7
children 36ed64fea8c1
files src/file.h src/gearsTools/check_convert_context_struct.pl src/gearsTools/lib/Gears/Context.pm src/gearsTools/lib/Gears/Util.pm
diffstat 4 files changed, 58 insertions(+), 48 deletions(-) [+]
line wrap: on
line diff
--- a/src/file.h	Thu Feb 27 19:27:27 2020 +0900
+++ b/src/file.h	Sun Mar 01 18:10:05 2020 +0900
@@ -1,3 +1,4 @@
+#ifndef FILE_STRUCT
 struct file {
     enum { FD_NONE, FD_PIPE, FD_INODE } type;
     int          ref;   // reference count
@@ -7,8 +8,12 @@
     struct inode *ip;
     uint         off;
 };
+
+#define FILE_STRUCT
+#endif
 // in-memory copy of an inode
 
+#ifndef INODE_STRUCT
 struct inode {
     uint    dev;        // Device number
     uint    inum;       // Inode number
@@ -22,6 +27,8 @@
     uint    size;
     uint    addrs[NDIRECT+1];
 };
+#define INODE_STRUCT
+#endif
 
 #define I_BUSY 0x1
 #define I_VALID 0x2
--- a/src/gearsTools/check_convert_context_struct.pl	Thu Feb 27 19:27:27 2020 +0900
+++ b/src/gearsTools/check_convert_context_struct.pl	Sun Mar 01 18:10:05 2020 +0900
@@ -9,7 +9,7 @@
 
 my $interface_file = shift or die "require itnerface file";
 my $h2context = Gears::Util->parse_interface($interface_file);
-my $context = Gears::Util->h2context_str($h2context);
+my $context = Gears::Context->h2context_str($h2context);
 
 print "$context";
 
--- a/src/gearsTools/lib/Gears/Context.pm	Thu Feb 27 19:27:27 2020 +0900
+++ b/src/gearsTools/lib/Gears/Context.pm	Sun Mar 01 18:10:05 2020 +0900
@@ -86,10 +86,10 @@
   my ($self, $dg_str) = @_;
   my $data_struct_str  = "";
   for my $interface (sort keys %$dg_str) {
-    $data_struct_str .= Gears::Util->h2context_str($dg_str->{$interface}->{elem});
+    $data_struct_str .= $self->h2context_str($dg_str->{$interface}->{elem});
     next unless ($dg_str->{$interface}->{impl});
     for my $impl (sort keys %{$dg_str->{$interface}->{impl}}) {
-       $data_struct_str .= Gears::Util->h2context_str($dg_str->{$interface}->{impl}->{$impl});
+       $data_struct_str .= $self->h2context_str($dg_str->{$interface}->{impl}->{$impl});
     }
   }
   return $data_struct_str;
@@ -121,4 +121,52 @@
   return \%dg_str;
 }
 
+sub h2context_str {
+  my ($self, $h2context) = @_;
+  my $space = '    ';
+
+  my $context = "${space}//$h2context->{file_name}\n";
+  $context .= "#ifndef ". uc($h2context->{name}) ."_STRUCT \n";
+  $context .=  "${space}struct $h2context->{name} {\n";
+  my $content_space;
+
+  my @enumCodes;
+  my @var;
+
+  for my $c (@{$h2context->{content}}) {
+    if ($c =~ /\A\s*enum Code/) {
+      push(@enumCodes,$c);
+    } else  {
+      push(@var,$c);
+    }
+  }
+
+  if (@var){
+    my @chars = split //, $var[0];
+    for my $w (@chars) {
+      last if ($w !~ /\s/);
+      $content_space .= $w;
+    }
+  }
+
+  unless (defined $content_space) {
+    $content_space = "";
+  }
+
+  for my $c (@var) {
+    $c =~ s/$content_space//;
+    $context .= "${space}${space}$c";
+  }
+
+  for my $c (@enumCodes) {
+    $c =~ s/$content_space//;
+    $context .= "${space}${space}$c";
+  }
+
+  $context .= "${space}} $h2context->{name};\n";
+  $context .= "#define ". uc($h2context->{name}) ."_STRUCT \n";
+  $context .= "#endif\n";
+  return $context;
+}
+
 1;
--- a/src/gearsTools/lib/Gears/Util.pm	Thu Feb 27 19:27:27 2020 +0900
+++ b/src/gearsTools/lib/Gears/Util.pm	Sun Mar 01 18:10:05 2020 +0900
@@ -164,51 +164,6 @@
   return \@files;
 }
 
-sub h2context_str {
-  my ($class, $h2context) = @_;
-  my $space = '    ';
-
-  my $context = "${space}//$h2context->{file_name}\n";
-  $context .=  "${space}struct $h2context->{name} {\n";
-  my $content_space;
-
-  my @enumCodes;
-  my @var;
-
-  for my $c (@{$h2context->{content}}) {
-    if ($c =~ /\A\s*enum Code/) {
-      push(@enumCodes,$c);
-    } else  {
-      push(@var,$c);
-    }
-  }
-
-  if (@var){
-    my @chars = split //, $var[0];
-    for my $w (@chars) {
-      last if ($w !~ /\s/);
-      $content_space .= $w;
-    }
-  }
-
-  unless (defined $content_space) {
-    $content_space = "";
-  }
-
-  for my $c (@var) {
-    $c =~ s/$content_space//;
-    $context .= "${space}${space}$c";
-  }
-
-  for my $c (@enumCodes) {
-    $c =~ s/$content_space//;
-    $context .= "${space}${space}$c";
-  }
-
-  $context .= "${space}} $h2context->{name};\n";
-  return $context;
-}
-
 sub extraction_dg_compile_sources {
   my ($class, $compile_sources) = @_;
   my %counter;