}
# if we produced an interface file "no matter what",
- # print what we got on stderr (ToDo: honor -ohi flag)
+ # print what we got on stderr.
if ( $HiOnStdout ) {
- system("$Cat $new_hi 1>&2");
+ if ( $HiWith ne '' ) {
+ # output some of the sections
+ local($hi_after) = "$Tmp_prefix.hi-now";
+
+ foreach $hi ( split(' ',$HiWith) ) {
+ $HiSection{$hi} = 1;
+ }
+ &hiSectionsOnly($new_hi, $hi_after);
+
+ system("$Cat $hi_after 1>&2 ; $Rm $hi_after; ");
+ } else {
+ system("$Cat $new_hi 1>&2");
+ }
} else {
&run_something("$Cmp -s $hifile_target $new_hi || ( $Rm $hifile_target && $Cp $new_hi $hifile_target )",
"Replace .$HiSuffix file, if changed");
\end{code}
\begin{code}
+sub hiSectionsOnly {
+ local($ifile,$ofile) = @_;
+
+ open(OLDHIF, "< $ifile") || &tidy_up_and_die(1,"Can't open $ifile (read)\n");
+ open(NEWHIF, "> $ofile") || &tidy_up_and_die(1,"Can't open $ofile (write)\n");
+
+ # read up to _usages_ line
+ $_ = <OLDHIF>;
+ while ($_ ne '' ) {
+ if ( /^__export/ && $HiSection {'exports'} ||
+ /^import / && $HiSection {'imports'} ||
+ /^\d+ ([^ ]+ :: |type |data |class |newtype )/ && $HiSection {'declarations'} ||
+ /^instance / && $HiSection {'instances'} ) {
+ print NEWHIF $_;
+ $_ = <OLDHIF>;
+ } else {
+ $_ = <OLDHIF>;
+ }
+ }
+
+ close(OLDHIF) || &tidy_up_and_die(1,"Failed reading from $ifile\n");
+ close(NEWHIF) || &tidy_up_and_die(1,"Failed writing to $ofile\n");
+}
+\end{code}
+
+\begin{code}
sub constructNewHiFile {
local($hsc_hi, # The iface info produced by hsc.
*hifile_target, # Pre-existing .hi filename (if it exists)
$new_hi, # Filename for new one
$show_hi_diffs) = @_;
local($hiname,$hidir);
-
+ local($mod_name_dec);
+
&readHiFile('new',$hsc_hi) unless $HiHasBeenRead{'new'} == 1;
+
+ # Sigh, we need decode the module name found in the interface file
+ # since that's the (base)name we want to use when outputting the
+ # interface file.
+ $mod_name_dec = $ModuleName{'new'};
+ $mod_name_dec =~ s/zz/z/g;
+ $mod_name_dec =~ s/ZZ/Z/g;
+
if ($Specific_hi_file eq '') { # -ohi is used even if module name != stem of filename.
- ($hiname = $hifile_target) =~ s/([^\/]*\/)*(.*)\.$HiSuffix/$2/;
- if ($ModuleName{'new'} ne $hiname) {
- ($hidir = $hifile_target) =~ s/([^\/]*\/)*.*\.$HiSuffix/$1/;
- $hifile_target = $hidir . $ModuleName{'new'} . ".$HiSuffix";
+ ($hiname = $hifile_target) = $1 if $hifile_target =~ /\/?([^\/]+)\.$HiSuffix$/;
+ if ( $mod_name_dec ne $hiname ) {
+ $hidir = '';
+ # strip off basename only if we've got a dirname.
+ ($hidir = $hifile_target) =~ s/(.*\/)[^\/]*$/$1/
+ if ( $hifile_target =~ /\/$hiname\.$HiSuffix/ );
+ $hifile_target = $hidir . $mod_name_dec . ".$HiSuffix";
}
}
&readHiFile('old',$hifile_target) unless $HiHasBeenRead{'old'} == 1;
}
local($new_module_version) = &calcNewModuleVersion(@decl_names);
- print NEWHI "__interface ", $ModuleName{'new'}, " $new_module_version $ProjectVersionInt where\n";
-
- print NEWHI $Stuff{'new:usages'} unless $Stuff{'new:usages'} eq '';
- print NEWHI $Stuff{'new:instance_modules'} unless $Stuff{'new:instance_modules'} eq '';
+ print NEWHI "__interface ", $ModuleName{'new'}, " $new_module_version $Orphan{'new'} $ProjectVersionInt where\n";
print NEWHI $Stuff{'new:exports'};
- print NEWHI $Stuff{'new:fixities'} unless $Stuff{'new:fixities'} eq '';
+ print NEWHI $Stuff{'new:usages'} unless $Stuff{'new:usages'} eq '';
print NEWHI $Stuff{'new:instances'} unless $Stuff{'new:instances'} eq '';
foreach $v (@decl_names) {
&printNewItemVersion(NEWHI, $v, $new_module_version, $show_hi_diffs); # Print new version number
print NEWHI $Decl{"new:$v"}; # Print the new decl itself
}
+ print NEWHI $Stuff{'new:rules'} unless $Stuff{'new:rules'} eq '';
+ print NEWHI $Stuff{'new:deprecations'} unless $Stuff{'new:deprecations'} eq '';
close(NEWHI) || &tidy_up_and_die(1,"Failed writing to $new_hi\n");
}
$HiExists{$mod} = -1; # 1 <=> definitely exists; 0 <=> doesn't
$HiHasBeenRead{$mod} = 0;
$ModuleVersion{$mod} = 0;
- $Stuff{"$mod:instance_modules"} = '';
$Stuff{"$mod:usages"} = ''; # stuff glommed together
$Stuff{"$mod:exports"} = '';
- $Stuff{"$mod:fixities"} = '';
$Stuff{"$mod:instances"} = '';
$Stuff{"$mod:declarations"} = '';
+ $Stuff{"$mod:rules"} = '';
+ $Stuff{"$mod:deprecations"} = '';
if (! -f $hifile) { # no pre-existing .hi file
$HiExists{$mod} = 0;
hi_line: while (<HIFILE>) {
next if /^ *$/; # blank line
- if ( /^__interface ([A-Z]\S*) (\d+)/ ) {
+ if ( /^__interface ([A-Z]\S*) (\d+)( \!)?/ ) {
if ( $mod ne 'new' ) {
+ # Reading old .hi file
$ModuleVersion{$mod} = $2;
}
- $ModuleName{$mod} = $1; # used to decide name of iface file.
+
+ $ModuleName{$mod} = $1; # used to decide name of iface file.
+ $Orphan{$mod} = $3;
+ # optional "!" indicates that the
+ # module contains orphan rules or instance decls
} elsif ( /^import / ) {
$Stuff{"$mod:usages"} .= $_; # save the whole thing
- } elsif ( /^__instimport/ ) {
- $Stuff{"$mod:instance_modules"} .= $_;
-
} elsif ( /^__export/ ) {
$Stuff{"$mod:exports"} .= $_;
- } elsif ( /^infix(r|l)? / ) {
- $Stuff{"$mod:fixities"} .= $_;
-
} elsif ( /^instance / ) {
$Stuff{"$mod:instances"} .= $_;
- } elsif ( /^--.*/ ) { # silently ignore comment lines.
+ } elsif ( /^{-## __R / ) {
+ $Stuff{"$mod:rules"} .= $_;
+
+ } elsif ( /^{-## __D / ) {
+ $Stuff{"$mod:deprecations"} .= $_;
+
+ } elsif ( /^-[-]+ .*/ ) { # silently ignore comment lines.
;
} else { # We're in a declaration
$Decl{"$mod:$current_name"} = $_;
if ($mod eq "old") { $OldVersion{$current_name} = $version; }
- } elsif ( /^(newtype|data)\s+(.*\s+=>\s+)?(\S+)\s+/ ) {
+ } elsif ( /^(newtype|data)\s+({.*}\s+=>\s+)?(\S+)\s+/ ) {
# Data declaration
+ # The (...)? parts skips over the context of a data decl
+ # to find the name of the type constructor. The curly
+ # brackets are part of the iface file syntax for contexts
$current_name = "data $3";
$Decl{"$mod:$current_name"} = $_;
if ($mod eq "old") { $OldVersion{$current_name} = $version; }
$Decl{"$mod:$current_name"} = $_;
if ($mod eq "old") { $OldVersion{$current_name} = $version; }
+ } elsif ( /^infix(r|l)?\s+[0-9]\s+(\S+)/ ) {
+ # fixity declaration
+ $current_name = "fixity $2";
+ $Decl{"$mod:$current_name"} = $_;
+ if ($mod eq "old") { $OldVersion{$current_name} = $version; }
+
} elsif ( /^(\S+)\s+::\s+/ ) {
# Value declaration
$current_name = $1;
if ($mod eq "old") { $OldVersion{$current_name} = $version; }
} else { # Continuation line
- print STDERR "$Pgm:junk old iface line?:$_";
- # $Decl{"$mod:$current_name"} .= $_
+ # print STDERR "$Pgm:junk old iface line?:$_";
+ $Decl{"$mod:$current_name"} .= $_
}
}
local($unchanged_version) = $ModuleVersion{'old'}; # will return one of these two
local($changed_version) = $unchanged_version + 1;
- foreach $t ( 'usages' , 'exports', 'instance_modules', 'instances', 'fixities' ) {
+ if ($Orphan{'old'} ne $Orphan{'new'}) {
+ return(&mv_change($changed_version, "orphan-hood changed"));
+ }
+
+ foreach $t ( 'usages' , 'exports', 'instances', 'fixities', 'rules', 'deprecations' ) {
return(&mv_change($changed_version,"$t changed")) if $Stuff{"old:$t"} ne $Stuff{"new:$t"};
}
return(&mv_change($changed_version,"$v changed")) if $Decl{"old:$v"} ne $Decl{"new:$v"};
}
- print STDERR "$Pgm: module version unchanged at $unchanged_version\n";
+ print STDERR "$Pgm: module version unchanged at $unchanged_version\n"
+ if $Verbose;
return($unchanged_version);
}
sub mv_change {
local($mv, $str) = @_;
- print STDERR "$Pgm: module version changed to $mv; reason: $str\n";
+ print STDERR "$Pgm: module version changed to $mv; reason: $str\n"
+ if $Verbose;
return($mv);
}