head	1.2;
access;
symbols
	perseant-exfatfs-base-20250801:1.2
	netbsd-10-1-RELEASE:1.1.1.8
	perseant-exfatfs-base-20240630:1.2
	perseant-exfatfs:1.2.0.2
	perseant-exfatfs-base:1.2
	netbsd-8-3-RELEASE:1.1.1.2
	netbsd-9-4-RELEASE:1.1.1.3
	netbsd-10-0-RELEASE:1.1.1.8
	netbsd-10-0-RC6:1.1.1.8
	netbsd-10-0-RC5:1.1.1.8
	netbsd-10-0-RC4:1.1.1.8
	netbsd-10-0-RC3:1.1.1.8
	netbsd-10-0-RC2:1.1.1.8
	netbsd-10-0-RC1:1.1.1.8
	gcc-10-5-0:1.1.1.8
	netbsd-10:1.1.1.8.0.6
	netbsd-10-base:1.1.1.8
	netbsd-9-3-RELEASE:1.1.1.3
	gcc-10-4-0:1.1.1.8
	cjep_sun2x-base1:1.1.1.8
	cjep_sun2x:1.1.1.8.0.4
	cjep_sun2x-base:1.1.1.8
	cjep_staticlib_x-base1:1.1.1.8
	netbsd-9-2-RELEASE:1.1.1.3
	cjep_staticlib_x:1.1.1.8.0.2
	cjep_staticlib_x-base:1.1.1.8
	gcc-10-3-0:1.1.1.8
	netbsd-9-1-RELEASE:1.1.1.3
	gcc-9-3-0:1.1.1.7
	gcc-7-5-0:1.1.1.5
	phil-wifi-20200421:1.1.1.4
	phil-wifi-20200411:1.1.1.4
	is-mlppp:1.1.1.4.0.2
	is-mlppp-base:1.1.1.4
	phil-wifi-20200406:1.1.1.4
	netbsd-8-2-RELEASE:1.1.1.2
	gcc-8-4-0:1.1.1.6
	netbsd-9-0-RELEASE:1.1.1.3
	netbsd-9-0-RC2:1.1.1.3
	netbsd-9-0-RC1:1.1.1.3
	phil-wifi-20191119:1.1.1.4
	gcc-8-3-0:1.1.1.4
	netbsd-9:1.1.1.3.0.6
	netbsd-9-base:1.1.1.3
	phil-wifi-20190609:1.1.1.3
	netbsd-8-1-RELEASE:1.1.1.2
	netbsd-8-1-RC1:1.1.1.2
	pgoyette-compat-merge-20190127:1.1.1.3
	pgoyette-compat-20190127:1.1.1.3
	gcc-7-4-0:1.1.1.3
	pgoyette-compat-20190118:1.1.1.3
	pgoyette-compat-1226:1.1.1.3
	pgoyette-compat-1126:1.1.1.3
	gcc-6-5-0:1.1.1.3
	pgoyette-compat-1020:1.1.1.3
	pgoyette-compat-0930:1.1.1.3
	pgoyette-compat-0906:1.1.1.3
	netbsd-7-2-RELEASE:1.1.1.1
	pgoyette-compat-0728:1.1.1.3
	netbsd-8-0-RELEASE:1.1.1.2
	phil-wifi:1.1.1.3.0.4
	phil-wifi-base:1.1.1.3
	pgoyette-compat-0625:1.1.1.3
	netbsd-8-0-RC2:1.1.1.2
	pgoyette-compat-0521:1.1.1.3
	pgoyette-compat-0502:1.1.1.3
	pgoyette-compat-0422:1.1.1.3
	netbsd-8-0-RC1:1.1.1.2
	pgoyette-compat-0415:1.1.1.3
	pgoyette-compat-0407:1.1.1.3
	pgoyette-compat-0330:1.1.1.3
	pgoyette-compat-0322:1.1.1.3
	pgoyette-compat-0315:1.1.1.3
	netbsd-7-1-2-RELEASE:1.1.1.1
	pgoyette-compat:1.1.1.3.0.2
	pgoyette-compat-base:1.1.1.3
	gcc-6-4-0:1.1.1.3
	netbsd-7-1-1-RELEASE:1.1.1.1
	gcc-5-5-0:1.1.1.2
	matt-nb8-mediatek:1.1.1.2.0.12
	matt-nb8-mediatek-base:1.1.1.2
	perseant-stdc-iso10646:1.1.1.2.0.10
	perseant-stdc-iso10646-base:1.1.1.2
	netbsd-8:1.1.1.2.0.8
	netbsd-8-base:1.1.1.2
	prg-localcount2-base3:1.1.1.2
	prg-localcount2-base2:1.1.1.2
	prg-localcount2-base1:1.1.1.2
	prg-localcount2:1.1.1.2.0.6
	prg-localcount2-base:1.1.1.2
	pgoyette-localcount-20170426:1.1.1.2
	bouyer-socketcan-base1:1.1.1.2
	pgoyette-localcount-20170320:1.1.1.2
	netbsd-7-1:1.1.1.1.0.14
	netbsd-7-1-RELEASE:1.1.1.1
	netbsd-7-1-RC2:1.1.1.1
	netbsd-7-nhusb-base-20170116:1.1.1.1
	bouyer-socketcan:1.1.1.2.0.4
	bouyer-socketcan-base:1.1.1.2
	pgoyette-localcount-20170107:1.1.1.2
	netbsd-7-1-RC1:1.1.1.1
	pgoyette-localcount-20161104:1.1.1.2
	netbsd-7-0-2-RELEASE:1.1.1.1
	localcount-20160914:1.1.1.2
	netbsd-7-nhusb:1.1.1.1.0.12
	netbsd-7-nhusb-base:1.1.1.1
	pgoyette-localcount-20160806:1.1.1.2
	pgoyette-localcount-20160726:1.1.1.2
	pgoyette-localcount:1.1.1.2.0.2
	pgoyette-localcount-base:1.1.1.2
	gcc-5-4-0:1.1.1.2
	netbsd-7-0-1-RELEASE:1.1.1.1
	gcc-5-3-0:1.1.1.2
	netbsd-7-0:1.1.1.1.0.10
	netbsd-7-0-RELEASE:1.1.1.1
	gcc-4-8-5-pre-gcc-old-import:1.1.1.1
	netbsd-7-0-RC3:1.1.1.1
	netbsd-7-0-RC2:1.1.1.1
	post-gcc-4-8-5-merge:1.1.1.1
	gcc-4-8-5:1.1.1.1
	netbsd-7-0-RC1:1.1.1.1
	gcc-4-8-4:1.1.1.1
	gcc-4-8-20141009:1.1.1.1
	tls-maxphys-base:1.1.1.1
	tls-maxphys:1.1.1.1.0.8
	netbsd-7:1.1.1.1.0.6
	netbsd-7-base:1.1.1.1
	gcc-4-8-3:1.1.1.1
	yamt-pagecache:1.1.1.1.0.4
	yamt-pagecache-base9:1.1.1.1
	tls-earlyentropy:1.1.1.1.0.2
	tls-earlyentropy-base:1.1.1.1
	riastradh-xf86-video-intel-2-7-1-pre-2-21-15:1.1.1.1
	riastradh-drm2-base3:1.1.1.1
	gcc-4-8-3-pre-r208254:1.1.1.1
	gcc-4-8-3-pre-r206687:1.1.1.1
	FSF:1.1.1;
locks; strict;
comment	@# @;


1.2
date	2023.07.30.05.51.10;	author mrg;	state dead;
branches;
next	1.1;
commitid	Iugici1GtQ2mWMyE;

1.1
date	2014.03.01.08.41.42;	author mrg;	state Exp;
branches
	1.1.1.1;
next	;
commitid	TtaB91QNTknAoYqx;

1.1.1.1
date	2014.03.01.08.41.42;	author mrg;	state Exp;
branches
	1.1.1.1.4.1
	1.1.1.1.8.1;
next	1.1.1.2;
commitid	TtaB91QNTknAoYqx;

1.1.1.2
date	2016.01.24.06.05.41;	author mrg;	state Exp;
branches;
next	1.1.1.3;
commitid	uWWfbLp08zOK79Sy;

1.1.1.3
date	2018.02.02.01.59.06;	author mrg;	state Exp;
branches
	1.1.1.3.4.1;
next	1.1.1.4;
commitid	XNKaycqpfhzd5epA;

1.1.1.4
date	2019.10.01.09.36.13;	author mrg;	state Exp;
branches;
next	1.1.1.5;
commitid	smvgr2IPAQDr89FB;

1.1.1.5
date	2020.08.11.05.10.41;	author mrg;	state Exp;
branches;
next	1.1.1.6;
commitid	5dBRDT7i6e65xBjC;

1.1.1.6
date	2020.08.11.05.30.16;	author mrg;	state Exp;
branches;
next	1.1.1.7;
commitid	7AI4OfpLi4eqEBjC;

1.1.1.7
date	2020.09.05.07.52.20;	author mrg;	state Exp;
branches;
next	1.1.1.8;
commitid	ZRYA7IOuwfMjAPmC;

1.1.1.8
date	2021.04.10.22.10.13;	author mrg;	state Exp;
branches;
next	;
commitid	eC4g0MRpqTvEkNOC;

1.1.1.1.4.1
date	2014.03.01.08.41.42;	author yamt;	state dead;
branches;
next	1.1.1.1.4.2;
commitid	W5NbWi8HaA1uoyBx;

1.1.1.1.4.2
date	2014.05.22.16.35.06;	author yamt;	state Exp;
branches;
next	;
commitid	W5NbWi8HaA1uoyBx;

1.1.1.1.8.1
date	2014.03.01.08.41.42;	author tls;	state dead;
branches;
next	1.1.1.1.8.2;
commitid	jTnpym9Qu0o4R1Nx;

1.1.1.1.8.2
date	2014.08.19.23.53.12;	author tls;	state Exp;
branches;
next	;
commitid	jTnpym9Qu0o4R1Nx;

1.1.1.3.4.1
date	2020.04.13.07.57.04;	author martin;	state Exp;
branches;
next	;
commitid	X01YhRUPVUDaec4C;


desc
@@


1.2
log
@initial merge of GCC 12.3.0.

this doesn't include any of the changes to the .c -> .cc files renamed,
and reverts our local changes to the vax port and libsanitizer subdir.
vax GCC was rewritten and our local fixes no longer are relevant, and
the new libsanitizer is more updated than our old one, and merging via
gcc10->gcc12 is not really possible.

unfortunately, our local changes to libsanitizer that aren't related
to the general update of those sources (ie, the netbsd code) will need
to be re-checked and perhaps re-ported.
@
text
@#!/usr/bin/perl
# Copyright (C) 2012 Free Software Foundation, Inc.
#
# This file is part of GCC.
#
# GCC is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3, or (at your option)
# any later version.
#
# GCC is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GCC; see the file COPYING.  If not, write to
# the Free Software Foundation, 51 Franklin Street, Fifth Floor,
# Boston, MA 02110-1301, USA.

# This script parses a .diff file generated with 'diff -up' or 'diff -cp'
# and writes a skeleton ChangeLog file to stdout. It does not try to be
# very smart when parsing function names, but it produces a reasonable
# approximation.
#
# Author: Diego Novillo <dnovillo@@google.com> and
#         Cary Coutant <ccoutant@@google.com>

# Change these settings to reflect your profile.
$username = $ENV{'USER'};
$name = `finger $username | grep -o 'Name: .*'`;
@@n = split(/: /, $name);
$name = @@n[1]; chop($name);
$addr = $username . "\@@my.domain.org";
$date = `date +%Y-%m-%d`; chop ($date);


#-----------------------------------------------------------------------------
# Program starts here. You should not need to edit anything below this
# line.
#-----------------------------------------------------------------------------
if ( $#ARGV != 0 ) {
    $prog = `basename $0`; chop ($prog);
    print "usage: $prog file.diff\n\n";
    print "Adds a ChangeLog template to the start of file.diff\n";
    print "It assumes that file.diff has been created with -up or -cp.\n";
    exit 1;
}

$diff = $ARGV[0];
$dir = `dirname $diff`; chop ($dir);
$basename = `basename $diff`; chop ($basename);
$cl = `mktemp /tmp/$basename.XXXXXX` || exit 1; chop ($cl);
$hdrline = "$date  $name  <$addr>";

open (CLFILE, ">$cl") or die "Could not open file $cl for writing";

print CLFILE "$hdrline\n\n";

# For every file in the .diff print all the function names in ChangeLog
# format.
$bof = 0;
open (DFILE, $diff) or die "Could not open file $diff for reading";
while (<DFILE>) {
    # Check if we found a new file.
    if (/^\+\+\+ (b\/)?(\S+)/) {
	# If we have not seen any function names in the previous file (ie,
	# $bof == 1), we just write out a ':' before starting the next
	# file.
	if ($bof == 1) {
	    print CLFILE ":\n";
	}
	$filename = $2;
	print CLFILE "\t* $filename";
	$bof = 1;
    }

    # Remember the last line in a unified diff block that might start
    # a new function.
    if (/^[-+ ]([a-zA-Z0-9_].*)/) {
        $save_fn = $1;
    }

    # If we find a new function, print it in brackets.  Special case if
    # this is the first function in a file.  
    #
    # Note that we don't try too hard to find good matches.  This should
    # return a superset of the actual set of functions in the .diff file.
    #
    # The first two patterns work with context diff files (diff -c). The
    # third pattern works with unified diff files (diff -u).
    #
    # The fourth pattern looks for the starts of functions or classes
    # within a unified diff block.

    if (/^\*\*\*\*\*\** ([a-zA-Z0-9_].*)/
        || /^[\-\+\!] ([a-zA-Z0-9_]+)[ \t]*\(.*/
	|| /^@@@@ .* @@@@ ([a-zA-Z0-9_].*)/
	|| /^[-+ ](\{)/)
      {
	$_ = $1;
	my $fn;
	if (/^\{/) {
	    # Beginning of a new function.
	    $_ = $save_fn;
	} else {
	    $save_fn = "";
	}
	if (/;$/) {
	    # No usable function name found.
	} elsif (/^((class|struct|union|enum) [a-zA-Z0-9_]+)/) {
	    # Discard stuff after the class/struct/etc. tag.
	    $fn = $1;
	} elsif (/([a-zA-Z0-9_][^(]*)\(/) {
	    # Discard template and function parameters.
	    $fn = $1;
	    1 while ($fn =~ s/<[^<>]*>//);
	    $fn =~ s/[ \t]*$//;
	}
	if ($fn && $seen_names{$fn} == 0) {
	    # If this is the first function in the file, we display it next
	    # to the filename, so we need an extra space before the opening
	    # brace.
	    if ($bof) {
		print CLFILE " ";
		$bof = 0;
	    } else {
		print CLFILE "\t";
	    }

	    print CLFILE "($fn):\n";
	    $seen_names{$fn} = 1;
	}
    }
}

# If we have not seen any function names (ie, $bof == 1), we just
# write out a ':'. This happens when there is only one file with no
# functions.
if ($bof == 1) {
    print CLFILE ":\n";
}

print CLFILE "\n";
close (DFILE);

# Concatenate the ChangeLog template and the original .diff file.
system ("cat $diff >>$cl && mv $cl $diff") == 0
    or die "Could not add the ChangeLog entry to $diff";

exit 0;
@


1.1
log
@Initial revision
@
text
@@


1.1.1.1
log
@import GCC 4.8 branch at r206687.

highlights from: http://gcc.gnu.org/gcc-4.6/changes.html

   GCC now has stricter checks for invalid command-line options
   New -Wunused-but-set-variable and -Wunused-but-set-parameter
      warnings
   Many platforms have been obsoleted
   Link-time optimization improvements
   A new switch -fstack-usage has been added
   A new function attribute leaf was introduced
   A new warning, enabled by -Wdouble-promotion
   Support for selectively enabling and disabling warnings via
      #pragma GCC diagnostic has been added
   There is now experimental support for some features from the
      upcoming C1X revision of the ISO C standard
   Improved experimental support for the upcoming C++0x ISO C++
      standard
   G++ now issues clearer diagnostics in several cases
   Updates for ARM, x86, MIPS, PPC/PPC64, SPARC
   Darwin, FreeBSD, Solaris 2, MinGW and Cygwin now all support
      __float128 on 32-bit and 64-bit x86 targets. [*1]

highlights from: http://gcc.gnu.org/gcc-4.7/changes.html

   The -fconserve-space flag has been deprecated
   Support for a new parameter --param case-values-threshold=n
      was added
   Interprocedural and Link-time optimization improvements
   A new built-in, __builtin_assume_aligned, has been added
   A new warning option -Wunused-local-typedefs was added
   A new experimental command-line option -ftrack-macro-expansion
      was added
   Support for atomic operations specifying the C++11/C11 memory
      model has been added
   There is support for some more features from the C11 revision
      of the ISO C standard
   Improved experimental support for the new ISO C++ standard,
      C++11
   Updates for ARM, x86, MIPS, PPC/PPC64, SH, SPARC, TILE*
   A new option (-grecord-gcc-switches) was added

highlights from: http://gcc.gnu.org/gcc-4.8/changes.html

   GCC now uses C++ as its implementation language.  This means
      that to build GCC from sources, you will need a C++
      compiler that understands C++ 2003
   DWARF4 is now the default when generating DWARF debug
      information
   A new general optimization level, -Og, has been introduced
   A new option -ftree-partial-pre was added
   The option -fconserve-space has been removed
   The command-line options -fipa-struct-reorg and
      -fipa-matrix-reorg have been removed
   Interprocedural and Link-time optimization improvements
   AddressSanitizer, a fast memory error detector, has been
      added  [*2]
   A new -Wsizeof-pointer-memaccess warning has been added
   G++ now supports a -std=c++1y option for experimentation
      with features proposed for the next revision of the
      standard, expected around 2014
   Improved experimental support for the new ISO C++ standard,
      C++11
   A new port has been added to support AArch64
   Updates for ARM, x86, MIPS, PPC/PPC64, SH, SPARC, TILE*


[*1] we should support this too!
[*2] we should look into this.
     https://code.google.com/p/address-sanitizer/
@
text
@@


1.1.1.2
log
@import GCC 5.3.0.  see these urls for details which are too large to
include here:

	http://gcc.gnu.org/gcc-4.9/changes.html
	http://gcc.gnu.org/gcc-5/changes.html

(note that GCC 5.x is a release stream like GCC 4.9.x, 4.8.x, etc.)


the main issues we will have are:

The default mode for C is now -std=gnu11 instead of -std=gnu89.

ARM:
The deprecated option -mwords-little-endian has been removed.
The options -mapcs, -mapcs-frame, -mtpcs-frame and -mtpcs-leaf-frame
 which are only applicable to the old ABI have been deprecated.

MIPS:
The o32 ABI has been modified and extended. The o32 64-bit
 floating-point register support is now obsolete and has been removed.
 It has been replaced by three ABI extensions FPXX, FP64A, and FP64.
 The meaning of the -mfp64 command-line option has changed. It is now
 used to enable the FP64A and FP64 ABI extensions.
@
text
@d2 1
a2 1
# Copyright (C) 2012-2014 Free Software Foundation, Inc.
d22 1
a22 1
# and adds a skeleton ChangeLog file to the file. It does not try to be
d29 6
a34 3
use File::Temp;
use File::Copy qw(cp mv);

a36 37
$dot_mklog_format_msg =
    "The .mklog format is:\n"
    . "NAME = ...\n"
    . "EMAIL = ...\n";

# Create a .mklog to reflect your profile, if necessary.
my $conf = "$ENV{HOME}/.mklog";
if (-f "$conf") {
    open (CONF, "$conf")
	or die "Could not open file '$conf' for reading: $!\n";
    while (<CONF>) {
	if (m/^\s*NAME\s*=\s*(.*?)\s*$/) {
	    $name = $1;
	} elsif (m/^\s*EMAIL\s*=\s*(.*?)\s*$/) {
	    $addr = $1;
	}
    }
    if (!($name && $addr)) {
	die "Could not read .mklog settings.\n"
	    . $dot_mklog_format_msg;
    }
} else {
    $name = `git config user.name`;
    chomp($name);
    $addr = `git config user.email`;
    chomp($addr);

    if (!($name && $addr)) {
	die "Could not read git user.name and user.email settings.\n"
	    . "Please add missing git settings, or create a .mklog file in"
	    . " $ENV{HOME}.\n"
	    . $dot_mklog_format_msg;
    }
}

$gcc_root = $0;
$gcc_root =~ s/[^\\\/]+$/../;
d42 1
a42 5
$inline = 0;
if ($#ARGV == 1 && ("$ARGV[0]" eq "-i" || "$ARGV[0]" eq "--inline")) {
	shift;
	$inline = 1;
} elsif ($#ARGV != 0) {
d44 3
a46 11
    print <<EOF;
usage: $prog [ -i | --inline ] file.diff

Generate ChangeLog template for file.diff.
It assumes that patch has been created with -up or -cp.
When -i is used, the ChangeLog template is followed by the contents of
file.diff.
When file.diff is -, read standard input.
When -i is used and file.diff is not -, it writes to file.diff, otherwise it
writes to stdout.
EOF
d53 1
d56 1
a56 23
sub get_clname ($) {
	return ('ChangeLog', $_[0]) if ($_[0] !~ /[\/\\]/);

	my $dirname = $_[0];
	while ($dirname) {
		my $clname = "$dirname/ChangeLog";
		if (-f "$gcc_root/$clname") {
			my $relname = substr ($_[0], length ($dirname) + 1);
			return ($clname, $relname);
		} else {
			$dirname =~ s/[\/\\]?[^\/\\]*$//;
		} 
	}

	return ('Unknown ChangeLog', $_[0]);
}

sub remove_suffixes ($) {
	my $filename = $_[0];
	$filename =~ s/^[ab]\///;
	$filename =~ s/\.jj$//;
	return $filename;
}
d58 1
a58 34
sub is_context_hunk_start {
	return @@_[0] =~ /^\*\*\*\*\*\** ([a-zA-Z0-9_].*)/;
}

sub is_unified_hunk_start {
	return @@_[0] =~ /^@@@@ .* @@@@ ([a-zA-Z0-9_].*)/;
}

# Check if line is a top-level declaration.
# TODO: ignore preprocessor directives except maybe #define ?
sub is_top_level {
	my ($function, $is_context_diff) = (@@_);
	if (is_unified_hunk_start ($function)
	    || is_context_hunk_start ($function)) {
	    return 1;
	}
	if ($is_context_diff) {
		$function =~ s/^..//;
	} else {
		$function =~ s/^.//;
	}
	return $function && $function !~ /^[\s{]/;
}

# Read contents of .diff file
open (DFILE, $diff) or die "Could not open file $diff for reading";
chomp (my @@diff_lines = <DFILE>);
close (DFILE);

# Array diff_lines is modified by the log generation, so save a copy in
# orig_diff_lines if needed.
if ($inline) {
    @@orig_diff_lines = @@diff_lines;
}
d62 5
a66 23
%cl_entries = ();
$change_msg = undef;
$look_for_funs = 0;
$clname = get_clname('');
$line_idx = 0;
foreach (@@diff_lines) {
    # Stop processing functions if we found a new file.
	# Remember both left and right names because one may be /dev/null.
    # Don't be fooled by line markers in case of context diff.
    if (!/\*\*\*$/ && /^[+*][+*][+*] +(\S+)/) {
		$left = remove_suffixes ($1);
		$look_for_funs = 0;
	}
    if (!/---$/ && /^--- +(\S+)?/) {
		$right = remove_suffixes ($1);
		$look_for_funs = 0;
	}

	# Check if the body of diff started.
	# We should now have both left and right name,
	# so we can decide filename.

    if ($left && (/^\*{15}/ || /^@@@@ /)) {
d68 1
a68 1
	# $change_msg is empty), we just write out a ':' before starting the next
d70 2
a71 13
	if ($clname) {
		$cl_entries{$clname} .= $change_msg ? "$change_msg" : ":\n";
	}

	if ($left eq $right) {
		$filename = $left;
	} elsif($left eq '/dev/null') {
		$filename = $right;
	} elsif($right eq '/dev/null') {
		$filename = $left;
	} else {
		print STDERR "Error: failed to parse diff for $left and $right\n";
		exit 1;
d73 3
a75 11
	$left = $right = undef;
	($clname, $relname) = get_clname ($filename);
	$cl_entries{$clname} .= "\t* $relname";
	$change_msg = '';
	$look_for_funs = $filename =~ '\.(c|cpp|C|cc|h|inc|def)$';
    }

    # Context diffs have extra whitespace after first char;
    # remove it to make matching easier.
    if ($is_context_diff) {
      s/^([-+! ]) /\1/;
d78 1
a78 1
    # Remember the last line in a diff block that might start
d80 1
a80 1
    if (/^[-+! ]([a-zA-Z0-9_].*)/) {
a83 23
    # Check if file is newly added.
    # Two patterns: for context and unified diff.
    if (/^\*\*\* 0 \*\*\*\*/
        || /^@@@@ -0,0 \+1.* @@@@/) {
        $change_msg = $filename =~ /testsuite.*(?<!\.exp)$/ ? ": New test.\n" : ": New file.\n";
        $look_for_funs = 0;
    }

    # Check if file was removed.
    # Two patterns: for context and unified diff.
    if (/^--- 0 ----/
        || /^@@@@ -1.* \+0,0 @@@@/) {
        $change_msg = ": Remove.\n";
        $look_for_funs = 0;
    }

    if (is_unified_hunk_start ($diff_lines[$line_idx])) {
        $is_context_diff = 0;
    }
    elsif (is_context_hunk_start ($diff_lines[$line_idx])) {
	    $is_context_diff = 1;
    }

d90 2
a91 2
    # The first pattern works with context diff files (diff -c). The
    # second pattern works with unified diff files (diff -u).
d93 5
a97 4
    # The third pattern looks for the starts of functions or classes
    # within a diff block both for context and unified diff files.
    if ($look_for_funs
        && (/^\*\*\*\*\*\** ([a-zA-Z0-9_].*)/
d99 1
a99 1
	|| /^[-+! ](\{)/))
d120 1
a120 16
	# Check is function really modified
	$no_real_change = 0;
	$idx = $line_idx;
	# Skip line info in context diffs.
	while ($idx <= $#diff_lines && $is_context_diff
               && $diff_lines[$idx + 1] =~ /^[-\*]{3} [0-9]/) {
		++$idx;
	}
	# Check all lines till the first change
	# for the presence of really changed function
	do {
		++$idx;
		$no_real_change = $idx > $#diff_lines
				  || is_top_level ($diff_lines[$idx], $is_context_diff);
	} while (!$no_real_change && ($diff_lines[$idx] !~ /^[-+!]/));
	if ($fn && !$seen_names{$fn} && !$no_real_change) {
d124 3
a126 2
	    if (!$change_msg) {
		$change_msg .= " ";
d128 1
a128 1
		$change_msg .= "\t";
d131 1
a131 1
		$change_msg .= "($fn):\n";
a134 1
	$line_idx++;
d137 1
a137 1
# If we have not seen any function names (ie, $change_msg is empty), we just
d140 2
a141 15
$cl_entries{$clname} .= $change_msg ? "$change_msg\n" : ":\n";

if ($inline && $diff ne "-") {
	# Get a temp filename, rather than an open filehandle, because we use
	# the open to truncate.
	$tmp = mktemp("tmp.XXXXXXXX") or die "Could not create temp file: $!";

	# Copy the permissions to the temp file (in File::Copy module version
	# 2.15 and later).
	cp $diff, $tmp or die "Could not copy patch file to temp file: $!";

	# Open the temp file, clearing contents.
	open (OUTPUTFILE, '>', $tmp) or die "Could not open temp file: $!";
} else {
	*OUTPUTFILE = STDOUT;
d144 2
a145 15
# Print the log
foreach my $clname (keys %cl_entries) {
	print OUTPUTFILE "$clname:\n\n$hdrline\n\n$cl_entries{$clname}\n";
}

if ($inline) {
	# Append the patch to the log
	foreach (@@orig_diff_lines) {
		print OUTPUTFILE "$_\n";
	}
}

if ($inline && $diff ne "-") {
	# Close $tmp
	close(OUTPUTFILE);
d147 3
a149 3
	# Write new contents to $diff atomically
	mv $tmp, $diff or die "Could not move temp file to patch file: $!";
}
@


1.1.1.3
log
@import GCC 6.4.0.  see this url for details which are too large to
include here:

   http://gcc.gnu.org/gcc-6/changes.html

the main visible changes appear to be:

- The default mode for C++ is now -std=gnu++14 instead of -std=gnu++98.
- The C and C++ compilers now support attributes on enumerators.
- Diagnostics can now contain "fix-it hints"
- more warnings (some added to -Wall)
@
text
@d107 1
a107 1
		if (-f "$gcc_root/$clname" || -f "$clname") {
d134 1
d146 1
a146 1
	return $function && $function !~ /^[\s{#]/;
@


1.1.1.3.4.1
log
@Mostly merge changes from HEAD upto 20200411
@
text
@d1 2
a2 3
#!/usr/bin/python

# Copyright (C) 2017 Free Software Foundation, Inc.
d23 1
a23 1
# too smart when parsing function names, but it produces a reasonable
d26 7
a32 3
# This is a straightforward adaptation of original Perl script.
#
# Author: Yury Gribov <tetra2005@@gmail.com>
d34 173
a206 194
import sys
import re
import os.path
import os
import getopt
import tempfile
import time
import shutil
from subprocess import Popen, PIPE

me = os.path.basename(sys.argv[0])

def error(msg):
  sys.stderr.write("%s: error: %s\n" % (me, msg))
  sys.exit(1)

def warn(msg):
  sys.stderr.write("%s: warning: %s\n" % (me, msg))

class RegexCache(object):
  """Simple trick to Perl-like combined match-and-bind."""

  def __init__(self):
    self.last_match = None

  def match(self, p, s):
    self.last_match = re.match(p, s) if isinstance(p, str) else p.match(s)
    return self.last_match

  def search(self, p, s):
    self.last_match = re.search(p, s) if isinstance(p, str) else p.search(s)
    return self.last_match

  def group(self, n):
    return self.last_match.group(n)

cache = RegexCache()

def print_help_and_exit():
    print """\
Usage: %s [-i | --inline] [PATCH]
Generate ChangeLog template for PATCH.
PATCH must be generated using diff(1)'s -up or -cp options
(or their equivalent in Subversion/git).

When PATCH is - or missing, read standard input.

When -i is used, prepends ChangeLog to PATCH.
If PATCH is not stdin, modifies PATCH in-place, otherwise writes
to stdout.
""" % me
    sys.exit(1)

def run(cmd, die_on_error):
  """Simple wrapper for Popen."""
  proc = Popen(cmd.split(' '), stderr = PIPE, stdout = PIPE)
  (out, err) = proc.communicate()
  if die_on_error and proc.returncode != 0:
    error("`%s` failed:\n" % (cmd, proc.stderr))
  return proc.returncode, out, err

def read_user_info():
  dot_mklog_format_msg = """\
The .mklog format is:
NAME = ...
EMAIL = ...
"""

  # First try to read .mklog config
  mklog_conf = os.path.expanduser('~/.mklog')
  if os.path.exists(mklog_conf):
    attrs = {}
    f = open(mklog_conf, 'rb')
    for s in f:
      if cache.match(r'^\s*([a-zA-Z0-9_]+)\s*=\s*(.*?)\s*$', s):
        attrs[cache.group(1)] = cache.group(2)
    f.close()
    if 'NAME' not in attrs:
      error("'NAME' not present in .mklog")
    if 'EMAIL' not in attrs:
      error("'EMAIL' not present in .mklog")
    return attrs['NAME'], attrs['EMAIL']

  # Otherwise go with git

  rc1, name, _ = run('git config user.name', False)
  name = name.rstrip()
  rc2, email, _ = run('git config user.email', False)
  email = email.rstrip()

  if rc1 != 0 or rc2 != 0:
    error("""\
Could not read git user.name and user.email settings.
Please add missing git settings, or create a %s.
""" % mklog_conf)

  return name, email

def get_parent_changelog (s):
  """See which ChangeLog this file change should go to."""

  if s.find('\\') == -1 and s.find('/') == -1:
    return "ChangeLog", s

  gcc_root = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))

  d = s
  while d:
    clname = d + "/ChangeLog"
    if os.path.exists(gcc_root + '/' + clname) or os.path.exists(clname):
      relname = s[len(d)+1:]
      return clname, relname
    d, _ = os.path.split(d)

  return "Unknown ChangeLog", s

class FileDiff:
  """Class to represent changes in a single file."""

  def __init__(self, filename):
    self.filename = filename
    self.hunks = []
    self.clname, self.relname = get_parent_changelog(filename);

  def dump(self):
    print "Diff for %s:\n  ChangeLog = %s\n  rel name = %s\n" % (self.filename, self.clname, self.relname)
    for i, h in enumerate(self.hunks):
      print "Next hunk %d:" % i
      h.dump()

class Hunk:
  """Class to represent a single hunk of changes."""

  def __init__(self, hdr):
    self.hdr = hdr
    self.lines = []
    self.ctx_diff = is_ctx_hunk_start(hdr)

  def dump(self):
    print '%s' % self.hdr
    print '%s' % '\n'.join(self.lines)

  def is_file_addition(self):
    """Does hunk describe addition of file?"""
    if self.ctx_diff:
      for line in self.lines:
        if re.match(r'^\*\*\* 0 \*\*\*\*', line):
          return True
    else:
      return re.match(r'^@@@@ -0,0 \+1.* @@@@', self.hdr)

  def is_file_removal(self):
    """Does hunk describe removal of file?"""
    if self.ctx_diff:
      for line in self.lines:
        if re.match(r'^--- 0 ----', line):
          return True
    else:
      return re.match(r'^@@@@ -1.* \+0,0 @@@@', self.hdr)

def is_file_diff_start(s):
  # Don't be fooled by context diff line markers:
  #   *** 385,391 ****
  return ((s.startswith('***') and not s.endswith('***'))
          or (s.startswith('---') and not s.endswith('---')))

def is_ctx_hunk_start(s):
  return re.match(r'^\*\*\*\*\*\**', s)

def is_uni_hunk_start(s):
  return re.match(r'^@@@@ .* @@@@', s)

def is_hunk_start(s):
  return is_ctx_hunk_start(s) or is_uni_hunk_start(s)

def remove_suffixes(s):
  if s.startswith('a/') or s.startswith('b/'):
    s = s[2:]
  if s.endswith('.jj'):
    s = s[:-3]
  return s

def find_changed_funs(hunk):
  """Find all functions touched by hunk.  We don't try too hard
     to find good matches.  This should return a superset
     of the actual set of functions in the .diff file.
  """

  fns = []
  fn = None

  if (cache.match(r'^\*\*\*\*\*\** ([a-zA-Z0-9_].*)', hunk.hdr)
      or cache.match(r'^@@@@ .* @@@@ ([a-zA-Z0-9_].*)', hunk.hdr)):
    fn = cache.group(1)
a207 1
  for i, line in enumerate(hunk.lines):
d210 139
a348 239
    if hunk.ctx_diff:
      line = re.sub(r'^([-+! ]) ', r'\1', line)

    # Remember most recent identifier in hunk
    # that might be a function name.
    if cache.match(r'^[-+! ]([a-zA-Z0-9_#].*)', line):
      fn = cache.group(1)

    change = line and re.match(r'^[-+!][^-]', line)

    # Top-level comment can not belong to function
    if re.match(r'^[-+! ]\/\*', line):
      fn = None

    if change and fn:
      if cache.match(r'^((class|struct|union|enum)\s+[a-zA-Z0-9_]+)', fn):
        # Struct declaration
        fn = cache.group(1)
      elif cache.search(r'#\s*define\s+([a-zA-Z0-9_]+)', fn):
        # Macro definition
        fn = cache.group(1)
      elif cache.match('^DEF[A-Z0-9_]+\s*\(([a-zA-Z0-9_]+)', fn):
        # Supermacro
        fn = cache.group(1)
      elif cache.search(r'([a-zA-Z_][^()\s]*)\s*\([^*]', fn):
        # Discard template and function parameters.
        fn = cache.group(1)
        fn = re.sub(r'<[^<>]*>', '', fn)
        fn = fn.rstrip()
      else:
        fn = None

      if fn and fn not in fns:  # Avoid dups
        fns.append(fn)

      fn = None

  return fns

def parse_patch(contents):
  """Parse patch contents to a sequence of FileDiffs."""

  diffs = []

  lines = contents.split('\n')

  i = 0
  while i < len(lines):
    line = lines[i]

    # Diff headers look like
    #   --- a/gcc/tree.c
    #   +++ b/gcc/tree.c
    # or
    #   *** gcc/cfgexpand.c     2013-12-25 20:07:24.800350058 +0400
    #   --- gcc/cfgexpand.c     2013-12-25 20:06:30.612350178 +0400

    if is_file_diff_start(line):
      left = re.split(r'\s+', line)[1]
    else:
      i += 1
      continue

    left = remove_suffixes(left);

    i += 1
    line = lines[i]

    if not cache.match(r'^[+-][+-][+-] +(\S+)', line):
      error("expected filename in line %d" % i)
    right = remove_suffixes(cache.group(1));

    # Extract real file name from left and right names.
    filename = None
    if left == right:
      filename = left
    elif left == '/dev/null':
      filename = right;
    elif right == '/dev/null':
      filename = left;
    else:
      comps = []
      while left and right:
        left, l = os.path.split(left)
        right, r = os.path.split(right)
        if l != r:
          break
        comps.append(l)
    
      if not comps:
        error("failed to extract common name for %s and %s" % (left, right))

      comps.reverse()
      filename = '/'.join(comps)

    d = FileDiff(filename)
    diffs.append(d)

    # Collect hunks for current file.
    hunk = None
    i += 1
    while i < len(lines):
      line = lines[i]

      # Create new hunk when we see hunk header
      if is_hunk_start(line):
        if hunk is not None:
          d.hunks.append(hunk)
        hunk = Hunk(line)
        i += 1
        continue

      # Stop when we reach next diff
      if (is_file_diff_start(line)
          or line.startswith('diff ')
          or line.startswith('Index: ')):
        i -= 1
        break

      if hunk is not None:
        hunk.lines.append(line)
      i += 1

    d.hunks.append(hunk)

  return diffs

def main():
  name, email = read_user_info()

  try:
    opts, args = getopt.getopt(sys.argv[1:], 'hiv', ['help', 'verbose', 'inline'])
  except getopt.GetoptError, err:
    error(str(err))

  inline = False
  verbose = 0

  for o, a in opts:
    if o in ('-h', '--help'):
      print_help_and_exit()
    elif o in ('-i', '--inline'):
      inline = True
    elif o in ('-v', '--verbose'):
      verbose += 1
    else:
      assert False, "unhandled option"

  if len(args) == 0:
    args = ['-']

  if len(args) == 1 and args[0] == '-':
    input = sys.stdin
  elif len(args) == 1:
    input = open(args[0], 'rb')
  else:
    error("too many arguments; for more details run with -h")

  contents = input.read()
  diffs = parse_patch(contents)

  if verbose:
    print "Parse results:"
    for d in diffs:
      d.dump()

  # Generate template ChangeLog.

  logs = {}
  for d in diffs:
    log_name = d.clname

    logs.setdefault(log_name, '')
    logs[log_name] += '\t* %s' % d.relname

    change_msg = ''

    # Check if file was removed or added.
    # Two patterns for context and unified diff.
    if len(d.hunks) == 1:
      hunk0 = d.hunks[0]
      if hunk0.is_file_addition():
        if re.search(r'testsuite.*(?<!\.exp)$', d.filename):
          change_msg = ': New test.\n'
        else:
          change_msg = ": New file.\n"
      elif hunk0.is_file_removal():
        change_msg = ": Remove.\n"

    _, ext = os.path.splitext(d.filename)
    if not change_msg and ext in ['.c', '.cpp', '.C', '.cc', '.h', '.inc', '.def']:
      fns = []
      for hunk in d.hunks:
        for fn in find_changed_funs(hunk):
          if fn not in fns:
            fns.append(fn)

      for fn in fns:
        if change_msg:
          change_msg += "\t(%s):\n" % fn
        else:
          change_msg = " (%s):\n" % fn

    logs[log_name] += change_msg if change_msg else ":\n"

  if inline and args[0] != '-':
    # Get a temp filename, rather than an open filehandle, because we use
    # the open to truncate.
    fd, tmp = tempfile.mkstemp("tmp.XXXXXXXX")
    os.close(fd)

    # Copy permissions to temp file
    # (old Pythons do not support shutil.copymode)
    shutil.copymode(args[0], tmp)

    # Open the temp file, clearing contents.
    out = open(tmp, 'wb')
  else:
    tmp = None
    out = sys.stdout

  # Print log
  date = time.strftime('%Y-%m-%d')
  for log_name, msg in sorted(logs.iteritems()):
    out.write("""\
%s:

%s  %s  <%s>

%s\n""" % (log_name, date, name, email, msg))

  if inline:
    # Append patch body
    out.write(contents)

    if args[0] != '-':
      # Write new contents atomically
      out.close()
      shutil.move(tmp, args[0])
d350 1
a350 2
if __name__ == '__main__':
    main()
@


1.1.1.4
log
@import GCC 8.3.  it includes these new features:
- many optimisations improved: inter-procedural, profile-directed,
  LTO, loops including user-controllable unroll support, and more.
- columns numbers added to line numbers in dwarf
- gcov extended significantly
- many sanitizer updates
- many new warning messages
- many better hints and more useful error messages
- minor ABI changes on x86-64 libstdc++, and some c++17 modes
- draft c++2a features
- better c++17 experimental support
- Armv8.4-A supported, better 8.2-A and 8.3-A support, including
  32 bit arm port.  cortex a-55, a-75 and a-55.a-75 combo support.
- in the GCC bugzilla, 8.1 shows 1149 bugs fixed, 8.2 shows 100, and
  8.3 shows 158.
@
text
@d1 2
a2 3
#!/usr/bin/python

# Copyright (C) 2017 Free Software Foundation, Inc.
d23 1
a23 1
# too smart when parsing function names, but it produces a reasonable
d26 7
a32 3
# This is a straightforward adaptation of original Perl script.
#
# Author: Yury Gribov <tetra2005@@gmail.com>
d34 173
a206 194
import sys
import re
import os.path
import os
import getopt
import tempfile
import time
import shutil
from subprocess import Popen, PIPE

me = os.path.basename(sys.argv[0])

def error(msg):
  sys.stderr.write("%s: error: %s\n" % (me, msg))
  sys.exit(1)

def warn(msg):
  sys.stderr.write("%s: warning: %s\n" % (me, msg))

class RegexCache(object):
  """Simple trick to Perl-like combined match-and-bind."""

  def __init__(self):
    self.last_match = None

  def match(self, p, s):
    self.last_match = re.match(p, s) if isinstance(p, str) else p.match(s)
    return self.last_match

  def search(self, p, s):
    self.last_match = re.search(p, s) if isinstance(p, str) else p.search(s)
    return self.last_match

  def group(self, n):
    return self.last_match.group(n)

cache = RegexCache()

def print_help_and_exit():
    print """\
Usage: %s [-i | --inline] [PATCH]
Generate ChangeLog template for PATCH.
PATCH must be generated using diff(1)'s -up or -cp options
(or their equivalent in Subversion/git).

When PATCH is - or missing, read standard input.

When -i is used, prepends ChangeLog to PATCH.
If PATCH is not stdin, modifies PATCH in-place, otherwise writes
to stdout.
""" % me
    sys.exit(1)

def run(cmd, die_on_error):
  """Simple wrapper for Popen."""
  proc = Popen(cmd.split(' '), stderr = PIPE, stdout = PIPE)
  (out, err) = proc.communicate()
  if die_on_error and proc.returncode != 0:
    error("`%s` failed:\n" % (cmd, proc.stderr))
  return proc.returncode, out, err

def read_user_info():
  dot_mklog_format_msg = """\
The .mklog format is:
NAME = ...
EMAIL = ...
"""

  # First try to read .mklog config
  mklog_conf = os.path.expanduser('~/.mklog')
  if os.path.exists(mklog_conf):
    attrs = {}
    f = open(mklog_conf, 'rb')
    for s in f:
      if cache.match(r'^\s*([a-zA-Z0-9_]+)\s*=\s*(.*?)\s*$', s):
        attrs[cache.group(1)] = cache.group(2)
    f.close()
    if 'NAME' not in attrs:
      error("'NAME' not present in .mklog")
    if 'EMAIL' not in attrs:
      error("'EMAIL' not present in .mklog")
    return attrs['NAME'], attrs['EMAIL']

  # Otherwise go with git

  rc1, name, _ = run('git config user.name', False)
  name = name.rstrip()
  rc2, email, _ = run('git config user.email', False)
  email = email.rstrip()

  if rc1 != 0 or rc2 != 0:
    error("""\
Could not read git user.name and user.email settings.
Please add missing git settings, or create a %s.
""" % mklog_conf)

  return name, email

def get_parent_changelog (s):
  """See which ChangeLog this file change should go to."""

  if s.find('\\') == -1 and s.find('/') == -1:
    return "ChangeLog", s

  gcc_root = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))

  d = s
  while d:
    clname = d + "/ChangeLog"
    if os.path.exists(gcc_root + '/' + clname) or os.path.exists(clname):
      relname = s[len(d)+1:]
      return clname, relname
    d, _ = os.path.split(d)

  return "Unknown ChangeLog", s

class FileDiff:
  """Class to represent changes in a single file."""

  def __init__(self, filename):
    self.filename = filename
    self.hunks = []
    self.clname, self.relname = get_parent_changelog(filename);

  def dump(self):
    print "Diff for %s:\n  ChangeLog = %s\n  rel name = %s\n" % (self.filename, self.clname, self.relname)
    for i, h in enumerate(self.hunks):
      print "Next hunk %d:" % i
      h.dump()

class Hunk:
  """Class to represent a single hunk of changes."""

  def __init__(self, hdr):
    self.hdr = hdr
    self.lines = []
    self.ctx_diff = is_ctx_hunk_start(hdr)

  def dump(self):
    print '%s' % self.hdr
    print '%s' % '\n'.join(self.lines)

  def is_file_addition(self):
    """Does hunk describe addition of file?"""
    if self.ctx_diff:
      for line in self.lines:
        if re.match(r'^\*\*\* 0 \*\*\*\*', line):
          return True
    else:
      return re.match(r'^@@@@ -0,0 \+1.* @@@@', self.hdr)

  def is_file_removal(self):
    """Does hunk describe removal of file?"""
    if self.ctx_diff:
      for line in self.lines:
        if re.match(r'^--- 0 ----', line):
          return True
    else:
      return re.match(r'^@@@@ -1.* \+0,0 @@@@', self.hdr)

def is_file_diff_start(s):
  # Don't be fooled by context diff line markers:
  #   *** 385,391 ****
  return ((s.startswith('***') and not s.endswith('***'))
          or (s.startswith('---') and not s.endswith('---')))

def is_ctx_hunk_start(s):
  return re.match(r'^\*\*\*\*\*\**', s)

def is_uni_hunk_start(s):
  return re.match(r'^@@@@ .* @@@@', s)

def is_hunk_start(s):
  return is_ctx_hunk_start(s) or is_uni_hunk_start(s)

def remove_suffixes(s):
  if s.startswith('a/') or s.startswith('b/'):
    s = s[2:]
  if s.endswith('.jj'):
    s = s[:-3]
  return s

def find_changed_funs(hunk):
  """Find all functions touched by hunk.  We don't try too hard
     to find good matches.  This should return a superset
     of the actual set of functions in the .diff file.
  """

  fns = []
  fn = None

  if (cache.match(r'^\*\*\*\*\*\** ([a-zA-Z0-9_].*)', hunk.hdr)
      or cache.match(r'^@@@@ .* @@@@ ([a-zA-Z0-9_].*)', hunk.hdr)):
    fn = cache.group(1)
a207 1
  for i, line in enumerate(hunk.lines):
d210 139
a348 239
    if hunk.ctx_diff:
      line = re.sub(r'^([-+! ]) ', r'\1', line)

    # Remember most recent identifier in hunk
    # that might be a function name.
    if cache.match(r'^[-+! ]([a-zA-Z0-9_#].*)', line):
      fn = cache.group(1)

    change = line and re.match(r'^[-+!][^-]', line)

    # Top-level comment can not belong to function
    if re.match(r'^[-+! ]\/\*', line):
      fn = None

    if change and fn:
      if cache.match(r'^((class|struct|union|enum)\s+[a-zA-Z0-9_]+)', fn):
        # Struct declaration
        fn = cache.group(1)
      elif cache.search(r'#\s*define\s+([a-zA-Z0-9_]+)', fn):
        # Macro definition
        fn = cache.group(1)
      elif cache.match('^DEF[A-Z0-9_]+\s*\(([a-zA-Z0-9_]+)', fn):
        # Supermacro
        fn = cache.group(1)
      elif cache.search(r'([a-zA-Z_][^()\s]*)\s*\([^*]', fn):
        # Discard template and function parameters.
        fn = cache.group(1)
        fn = re.sub(r'<[^<>]*>', '', fn)
        fn = fn.rstrip()
      else:
        fn = None

      if fn and fn not in fns:  # Avoid dups
        fns.append(fn)

      fn = None

  return fns

def parse_patch(contents):
  """Parse patch contents to a sequence of FileDiffs."""

  diffs = []

  lines = contents.split('\n')

  i = 0
  while i < len(lines):
    line = lines[i]

    # Diff headers look like
    #   --- a/gcc/tree.c
    #   +++ b/gcc/tree.c
    # or
    #   *** gcc/cfgexpand.c     2013-12-25 20:07:24.800350058 +0400
    #   --- gcc/cfgexpand.c     2013-12-25 20:06:30.612350178 +0400

    if is_file_diff_start(line):
      left = re.split(r'\s+', line)[1]
    else:
      i += 1
      continue

    left = remove_suffixes(left);

    i += 1
    line = lines[i]

    if not cache.match(r'^[+-][+-][+-] +(\S+)', line):
      error("expected filename in line %d" % i)
    right = remove_suffixes(cache.group(1));

    # Extract real file name from left and right names.
    filename = None
    if left == right:
      filename = left
    elif left == '/dev/null':
      filename = right;
    elif right == '/dev/null':
      filename = left;
    else:
      comps = []
      while left and right:
        left, l = os.path.split(left)
        right, r = os.path.split(right)
        if l != r:
          break
        comps.append(l)
    
      if not comps:
        error("failed to extract common name for %s and %s" % (left, right))

      comps.reverse()
      filename = '/'.join(comps)

    d = FileDiff(filename)
    diffs.append(d)

    # Collect hunks for current file.
    hunk = None
    i += 1
    while i < len(lines):
      line = lines[i]

      # Create new hunk when we see hunk header
      if is_hunk_start(line):
        if hunk is not None:
          d.hunks.append(hunk)
        hunk = Hunk(line)
        i += 1
        continue

      # Stop when we reach next diff
      if (is_file_diff_start(line)
          or line.startswith('diff ')
          or line.startswith('Index: ')):
        i -= 1
        break

      if hunk is not None:
        hunk.lines.append(line)
      i += 1

    d.hunks.append(hunk)

  return diffs

def main():
  name, email = read_user_info()

  try:
    opts, args = getopt.getopt(sys.argv[1:], 'hiv', ['help', 'verbose', 'inline'])
  except getopt.GetoptError, err:
    error(str(err))

  inline = False
  verbose = 0

  for o, a in opts:
    if o in ('-h', '--help'):
      print_help_and_exit()
    elif o in ('-i', '--inline'):
      inline = True
    elif o in ('-v', '--verbose'):
      verbose += 1
    else:
      assert False, "unhandled option"

  if len(args) == 0:
    args = ['-']

  if len(args) == 1 and args[0] == '-':
    input = sys.stdin
  elif len(args) == 1:
    input = open(args[0], 'rb')
  else:
    error("too many arguments; for more details run with -h")

  contents = input.read()
  diffs = parse_patch(contents)

  if verbose:
    print "Parse results:"
    for d in diffs:
      d.dump()

  # Generate template ChangeLog.

  logs = {}
  for d in diffs:
    log_name = d.clname

    logs.setdefault(log_name, '')
    logs[log_name] += '\t* %s' % d.relname

    change_msg = ''

    # Check if file was removed or added.
    # Two patterns for context and unified diff.
    if len(d.hunks) == 1:
      hunk0 = d.hunks[0]
      if hunk0.is_file_addition():
        if re.search(r'testsuite.*(?<!\.exp)$', d.filename):
          change_msg = ': New test.\n'
        else:
          change_msg = ": New file.\n"
      elif hunk0.is_file_removal():
        change_msg = ": Remove.\n"

    _, ext = os.path.splitext(d.filename)
    if not change_msg and ext in ['.c', '.cpp', '.C', '.cc', '.h', '.inc', '.def']:
      fns = []
      for hunk in d.hunks:
        for fn in find_changed_funs(hunk):
          if fn not in fns:
            fns.append(fn)

      for fn in fns:
        if change_msg:
          change_msg += "\t(%s):\n" % fn
        else:
          change_msg = " (%s):\n" % fn

    logs[log_name] += change_msg if change_msg else ":\n"

  if inline and args[0] != '-':
    # Get a temp filename, rather than an open filehandle, because we use
    # the open to truncate.
    fd, tmp = tempfile.mkstemp("tmp.XXXXXXXX")
    os.close(fd)

    # Copy permissions to temp file
    # (old Pythons do not support shutil.copymode)
    shutil.copymode(args[0], tmp)

    # Open the temp file, clearing contents.
    out = open(tmp, 'wb')
  else:
    tmp = None
    out = sys.stdout

  # Print log
  date = time.strftime('%Y-%m-%d')
  for log_name, msg in sorted(logs.iteritems()):
    out.write("""\
%s:

%s  %s  <%s>

%s\n""" % (log_name, date, name, email, msg))

  if inline:
    # Append patch body
    out.write(contents)

    if args[0] != '-':
      # Write new contents atomically
      out.close()
      shutil.move(tmp, args[0])
d350 1
a350 2
if __name__ == '__main__':
    main()
@


1.1.1.5
log
@import GCC 7.5.0.  doing this here so that the vendor branch has
the code we'll merge into gcc.old and the netbsd-9 tree gcc tree.
GCC 8.4.0 will be imported immediately on top of this again,
restoring the current status.

these PRs in the GCC bugzilla are fixed with this update:

89869 80693 89795 84272 85593 86669 87148 87647 87895 88103 88107 88563
88870 88976 89002 89187 89195 89234 89303 89314 89354 89361 89403 89412
89512 89520 89590 89621 89663 89679 89704 89734 89872 89933 90090 90208
87075 85870 89009 89242 88167 80864 81933 85890 86608 87145 88857 89024
89119 89214 89511 89612 89705 89400 81740 82186 84552 86554 87609 88105
88149 88415 88739 88903 89135 89223 89296 89505 89572 89677 89698 89710
90006 90020 90071 90328 90474 91126 91162 91812 91887 90075 88998 89945
87047 87506 88074 88656 88740 91137 89008 84010 89349 91136 91347 91995
89397 87030 60702 78884 85594 87649 87725 88181 88470 88553 88568 88588
88620 88644 88906 88949 89246 89587 89726 89768 89796 89998 90108 90756
90950 91704 88825 88983 86538 51333 89446 90220 91308 92143 89392 90213
90278 91131 91200 91510 89037 91481 87673 88418 88938 88948 90547 27221
58321 61250 67183 67958 77583 83531 86215 88648 88720 88726 89091 89466
89629 90105 90329 90585 90760 90924 91087 89222 81956 71861 35031 69455
81849 82993 85798 88138 88155 88169 88205 88206 88228 88249 88269 88376
77703 80260 82077 86248 88393 90786 57048 66089 66695 67679 68009 71723
72714 84394 85544 87734 88298 90937 91557 63891 64132 65342 68649 68717
71066 71860 71935 77746 78421 78645 78865 78983 79485 79540 85953 88326
89651 90744
@
text
@d1 3
a3 2
#!/usr/bin/perl
# Copyright (C) 2012-2014 Free Software Foundation, Inc.
d24 1
a24 1
# very smart when parsing function names, but it produces a reasonable
d27 3
a29 5
# Author: Diego Novillo <dnovillo@@google.com> and
#         Cary Coutant <ccoutant@@google.com>

use File::Temp;
use File::Copy qw(cp mv);
d31 194
a224 175
$date = `date +%Y-%m-%d`; chop ($date);

$dot_mklog_format_msg =
    "The .mklog format is:\n"
    . "NAME = ...\n"
    . "EMAIL = ...\n";

# Create a .mklog to reflect your profile, if necessary.
my $conf = "$ENV{HOME}/.mklog";
if (-f "$conf") {
    open (CONF, "$conf")
	or die "Could not open file '$conf' for reading: $!\n";
    while (<CONF>) {
	if (m/^\s*NAME\s*=\s*(.*?)\s*$/) {
	    $name = $1;
	} elsif (m/^\s*EMAIL\s*=\s*(.*?)\s*$/) {
	    $addr = $1;
	}
    }
    if (!($name && $addr)) {
	die "Could not read .mklog settings.\n"
	    . $dot_mklog_format_msg;
    }
} else {
    $name = `git config user.name`;
    chomp($name);
    $addr = `git config user.email`;
    chomp($addr);

    if (!($name && $addr)) {
	die "Could not read git user.name and user.email settings.\n"
	    . "Please add missing git settings, or create a .mklog file in"
	    . " $ENV{HOME}.\n"
	    . $dot_mklog_format_msg;
    }
}

$gcc_root = $0;
$gcc_root =~ s/[^\\\/]+$/../;

#-----------------------------------------------------------------------------
# Program starts here. You should not need to edit anything below this
# line.
#-----------------------------------------------------------------------------
$inline = 0;
if ($#ARGV == 1 && ("$ARGV[0]" eq "-i" || "$ARGV[0]" eq "--inline")) {
	shift;
	$inline = 1;
} elsif ($#ARGV != 0) {
    $prog = `basename $0`; chop ($prog);
    print <<EOF;
usage: $prog [ -i | --inline ] file.diff

Generate ChangeLog template for file.diff.
It assumes that patch has been created with -up or -cp.
When -i is used, the ChangeLog template is followed by the contents of
file.diff.
When file.diff is -, read standard input.
When -i is used and file.diff is not -, it writes to file.diff, otherwise it
writes to stdout.
EOF
    exit 1;
}

$diff = $ARGV[0];
$dir = `dirname $diff`; chop ($dir);
$basename = `basename $diff`; chop ($basename);
$hdrline = "$date  $name  <$addr>";

sub get_clname ($) {
	return ('ChangeLog', $_[0]) if ($_[0] !~ /[\/\\]/);

	my $dirname = $_[0];
	while ($dirname) {
		my $clname = "$dirname/ChangeLog";
		if (-f "$gcc_root/$clname" || -f "$clname") {
			my $relname = substr ($_[0], length ($dirname) + 1);
			return ($clname, $relname);
		} else {
			$dirname =~ s/[\/\\]?[^\/\\]*$//;
		} 
	}

	return ('Unknown ChangeLog', $_[0]);
}

sub remove_suffixes ($) {
	my $filename = $_[0];
	$filename =~ s/^[ab]\///;
	$filename =~ s/\.jj$//;
	return $filename;
}

sub is_context_hunk_start {
	return @@_[0] =~ /^\*\*\*\*\*\** ([a-zA-Z0-9_].*)/;
}

sub is_unified_hunk_start {
	return @@_[0] =~ /^@@@@ .* @@@@ ([a-zA-Z0-9_].*)/;
}

# Check if line is a top-level declaration.
sub is_top_level {
	my ($function, $is_context_diff) = (@@_);
	if (is_unified_hunk_start ($function)
	    || is_context_hunk_start ($function)) {
	    return 1;
	}
	if ($is_context_diff) {
		$function =~ s/^..//;
	} else {
		$function =~ s/^.//;
	}
	return $function && $function !~ /^[\s{#]/;
}

# Read contents of .diff file
open (DFILE, $diff) or die "Could not open file $diff for reading";
chomp (my @@diff_lines = <DFILE>);
close (DFILE);

# Array diff_lines is modified by the log generation, so save a copy in
# orig_diff_lines if needed.
if ($inline) {
    @@orig_diff_lines = @@diff_lines;
}

# For every file in the .diff print all the function names in ChangeLog
# format.
%cl_entries = ();
$change_msg = undef;
$look_for_funs = 0;
$clname = get_clname('');
$line_idx = 0;
foreach (@@diff_lines) {
    # Stop processing functions if we found a new file.
	# Remember both left and right names because one may be /dev/null.
    # Don't be fooled by line markers in case of context diff.
    if (!/\*\*\*$/ && /^[+*][+*][+*] +(\S+)/) {
		$left = remove_suffixes ($1);
		$look_for_funs = 0;
	}
    if (!/---$/ && /^--- +(\S+)?/) {
		$right = remove_suffixes ($1);
		$look_for_funs = 0;
	}

	# Check if the body of diff started.
	# We should now have both left and right name,
	# so we can decide filename.

    if ($left && (/^\*{15}/ || /^@@@@ /)) {
	# If we have not seen any function names in the previous file (ie,
	# $change_msg is empty), we just write out a ':' before starting the next
	# file.
	if ($clname) {
		$cl_entries{$clname} .= $change_msg ? "$change_msg" : ":\n";
	}

	if ($left eq $right) {
		$filename = $left;
	} elsif($left eq '/dev/null') {
		$filename = $right;
	} elsif($right eq '/dev/null') {
		$filename = $left;
	} else {
		print STDERR "Error: failed to parse diff for $left and $right\n";
		exit 1;
	}
	$left = $right = undef;
	($clname, $relname) = get_clname ($filename);
	$cl_entries{$clname} .= "\t* $relname";
	$change_msg = '';
	$look_for_funs = $filename =~ '\.(c|cpp|C|cc|h|inc|def)$';
    }
d226 1
d229 239
a467 139
    if ($is_context_diff) {
      s/^([-+! ]) /\1/;
    }

    # Remember the last line in a diff block that might start
    # a new function.
    if (/^[-+! ]([a-zA-Z0-9_].*)/) {
        $save_fn = $1;
    }

    # Check if file is newly added.
    # Two patterns: for context and unified diff.
    if (/^\*\*\* 0 \*\*\*\*/
        || /^@@@@ -0,0 \+1.* @@@@/) {
        $change_msg = $filename =~ /testsuite.*(?<!\.exp)$/ ? ": New test.\n" : ": New file.\n";
        $look_for_funs = 0;
    }

    # Check if file was removed.
    # Two patterns: for context and unified diff.
    if (/^--- 0 ----/
        || /^@@@@ -1.* \+0,0 @@@@/) {
        $change_msg = ": Remove.\n";
        $look_for_funs = 0;
    }

    if (is_unified_hunk_start ($diff_lines[$line_idx])) {
        $is_context_diff = 0;
    }
    elsif (is_context_hunk_start ($diff_lines[$line_idx])) {
	    $is_context_diff = 1;
    }

    # If we find a new function, print it in brackets.  Special case if
    # this is the first function in a file.  
    #
    # Note that we don't try too hard to find good matches.  This should
    # return a superset of the actual set of functions in the .diff file.
    #
    # The first pattern works with context diff files (diff -c). The
    # second pattern works with unified diff files (diff -u).
    #
    # The third pattern looks for the starts of functions or classes
    # within a diff block both for context and unified diff files.
    if ($look_for_funs
        && (/^\*\*\*\*\*\** ([a-zA-Z0-9_].*)/
	|| /^@@@@ .* @@@@ ([a-zA-Z0-9_].*)/
	|| /^[-+! ](\{)/))
      {
	$_ = $1;
	my $fn;
	if (/^\{/) {
	    # Beginning of a new function.
	    $_ = $save_fn;
	} else {
	    $save_fn = "";
	}
	if (/;$/) {
	    # No usable function name found.
	} elsif (/^((class|struct|union|enum) [a-zA-Z0-9_]+)/) {
	    # Discard stuff after the class/struct/etc. tag.
	    $fn = $1;
	} elsif (/([a-zA-Z0-9_][^(]*)\(/) {
	    # Discard template and function parameters.
	    $fn = $1;
	    1 while ($fn =~ s/<[^<>]*>//);
	    $fn =~ s/[ \t]*$//;
	}
	# Check is function really modified
	$no_real_change = 0;
	$idx = $line_idx;
	# Skip line info in context diffs.
	while ($idx <= $#diff_lines && $is_context_diff
               && $diff_lines[$idx + 1] =~ /^[-\*]{3} [0-9]/) {
		++$idx;
	}
	# Check all lines till the first change
	# for the presence of really changed function
	do {
		++$idx;
		$no_real_change = $idx > $#diff_lines
				  || is_top_level ($diff_lines[$idx], $is_context_diff);
	} while (!$no_real_change && ($diff_lines[$idx] !~ /^[-+!]/));
	if ($fn && !$seen_names{$fn} && !$no_real_change) {
	    # If this is the first function in the file, we display it next
	    # to the filename, so we need an extra space before the opening
	    # brace.
	    if (!$change_msg) {
		$change_msg .= " ";
	    } else {
		$change_msg .= "\t";
	    }

		$change_msg .= "($fn):\n";
	    $seen_names{$fn} = 1;
	}
    }
	$line_idx++;
}

# If we have not seen any function names (ie, $change_msg is empty), we just
# write out a ':'. This happens when there is only one file with no
# functions.
$cl_entries{$clname} .= $change_msg ? "$change_msg\n" : ":\n";

if ($inline && $diff ne "-") {
	# Get a temp filename, rather than an open filehandle, because we use
	# the open to truncate.
	$tmp = mktemp("tmp.XXXXXXXX") or die "Could not create temp file: $!";

	# Copy the permissions to the temp file (in File::Copy module version
	# 2.15 and later).
	cp $diff, $tmp or die "Could not copy patch file to temp file: $!";

	# Open the temp file, clearing contents.
	open (OUTPUTFILE, '>', $tmp) or die "Could not open temp file: $!";
} else {
	*OUTPUTFILE = STDOUT;
}

# Print the log
foreach my $clname (keys %cl_entries) {
	print OUTPUTFILE "$clname:\n\n$hdrline\n\n$cl_entries{$clname}\n";
}

if ($inline) {
	# Append the patch to the log
	foreach (@@orig_diff_lines) {
		print OUTPUTFILE "$_\n";
	}
}

if ($inline && $diff ne "-") {
	# Close $tmp
	close(OUTPUTFILE);

	# Write new contents to $diff atomically
	mv $tmp, $diff or die "Could not move temp file to patch file: $!";
}
d469 2
a470 1
exit 0;
@


1.1.1.6
log
@re-import GCC 8.4.0.
@
text
@d1 2
a2 3
#!/usr/bin/python

# Copyright (C) 2017 Free Software Foundation, Inc.
d23 1
a23 1
# too smart when parsing function names, but it produces a reasonable
d26 7
a32 3
# This is a straightforward adaptation of original Perl script.
#
# Author: Yury Gribov <tetra2005@@gmail.com>
d34 173
a206 194
import sys
import re
import os.path
import os
import getopt
import tempfile
import time
import shutil
from subprocess import Popen, PIPE

me = os.path.basename(sys.argv[0])

def error(msg):
  sys.stderr.write("%s: error: %s\n" % (me, msg))
  sys.exit(1)

def warn(msg):
  sys.stderr.write("%s: warning: %s\n" % (me, msg))

class RegexCache(object):
  """Simple trick to Perl-like combined match-and-bind."""

  def __init__(self):
    self.last_match = None

  def match(self, p, s):
    self.last_match = re.match(p, s) if isinstance(p, str) else p.match(s)
    return self.last_match

  def search(self, p, s):
    self.last_match = re.search(p, s) if isinstance(p, str) else p.search(s)
    return self.last_match

  def group(self, n):
    return self.last_match.group(n)

cache = RegexCache()

def print_help_and_exit():
    print """\
Usage: %s [-i | --inline] [PATCH]
Generate ChangeLog template for PATCH.
PATCH must be generated using diff(1)'s -up or -cp options
(or their equivalent in Subversion/git).

When PATCH is - or missing, read standard input.

When -i is used, prepends ChangeLog to PATCH.
If PATCH is not stdin, modifies PATCH in-place, otherwise writes
to stdout.
""" % me
    sys.exit(1)

def run(cmd, die_on_error):
  """Simple wrapper for Popen."""
  proc = Popen(cmd.split(' '), stderr = PIPE, stdout = PIPE)
  (out, err) = proc.communicate()
  if die_on_error and proc.returncode != 0:
    error("`%s` failed:\n" % (cmd, proc.stderr))
  return proc.returncode, out, err

def read_user_info():
  dot_mklog_format_msg = """\
The .mklog format is:
NAME = ...
EMAIL = ...
"""

  # First try to read .mklog config
  mklog_conf = os.path.expanduser('~/.mklog')
  if os.path.exists(mklog_conf):
    attrs = {}
    f = open(mklog_conf, 'rb')
    for s in f:
      if cache.match(r'^\s*([a-zA-Z0-9_]+)\s*=\s*(.*?)\s*$', s):
        attrs[cache.group(1)] = cache.group(2)
    f.close()
    if 'NAME' not in attrs:
      error("'NAME' not present in .mklog")
    if 'EMAIL' not in attrs:
      error("'EMAIL' not present in .mklog")
    return attrs['NAME'], attrs['EMAIL']

  # Otherwise go with git

  rc1, name, _ = run('git config user.name', False)
  name = name.rstrip()
  rc2, email, _ = run('git config user.email', False)
  email = email.rstrip()

  if rc1 != 0 or rc2 != 0:
    error("""\
Could not read git user.name and user.email settings.
Please add missing git settings, or create a %s.
""" % mklog_conf)

  return name, email

def get_parent_changelog (s):
  """See which ChangeLog this file change should go to."""

  if s.find('\\') == -1 and s.find('/') == -1:
    return "ChangeLog", s

  gcc_root = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))

  d = s
  while d:
    clname = d + "/ChangeLog"
    if os.path.exists(gcc_root + '/' + clname) or os.path.exists(clname):
      relname = s[len(d)+1:]
      return clname, relname
    d, _ = os.path.split(d)

  return "Unknown ChangeLog", s

class FileDiff:
  """Class to represent changes in a single file."""

  def __init__(self, filename):
    self.filename = filename
    self.hunks = []
    self.clname, self.relname = get_parent_changelog(filename);

  def dump(self):
    print "Diff for %s:\n  ChangeLog = %s\n  rel name = %s\n" % (self.filename, self.clname, self.relname)
    for i, h in enumerate(self.hunks):
      print "Next hunk %d:" % i
      h.dump()

class Hunk:
  """Class to represent a single hunk of changes."""

  def __init__(self, hdr):
    self.hdr = hdr
    self.lines = []
    self.ctx_diff = is_ctx_hunk_start(hdr)

  def dump(self):
    print '%s' % self.hdr
    print '%s' % '\n'.join(self.lines)

  def is_file_addition(self):
    """Does hunk describe addition of file?"""
    if self.ctx_diff:
      for line in self.lines:
        if re.match(r'^\*\*\* 0 \*\*\*\*', line):
          return True
    else:
      return re.match(r'^@@@@ -0,0 \+1.* @@@@', self.hdr)

  def is_file_removal(self):
    """Does hunk describe removal of file?"""
    if self.ctx_diff:
      for line in self.lines:
        if re.match(r'^--- 0 ----', line):
          return True
    else:
      return re.match(r'^@@@@ -1.* \+0,0 @@@@', self.hdr)

def is_file_diff_start(s):
  # Don't be fooled by context diff line markers:
  #   *** 385,391 ****
  return ((s.startswith('***') and not s.endswith('***'))
          or (s.startswith('---') and not s.endswith('---')))

def is_ctx_hunk_start(s):
  return re.match(r'^\*\*\*\*\*\**', s)

def is_uni_hunk_start(s):
  return re.match(r'^@@@@ .* @@@@', s)

def is_hunk_start(s):
  return is_ctx_hunk_start(s) or is_uni_hunk_start(s)

def remove_suffixes(s):
  if s.startswith('a/') or s.startswith('b/'):
    s = s[2:]
  if s.endswith('.jj'):
    s = s[:-3]
  return s

def find_changed_funs(hunk):
  """Find all functions touched by hunk.  We don't try too hard
     to find good matches.  This should return a superset
     of the actual set of functions in the .diff file.
  """

  fns = []
  fn = None

  if (cache.match(r'^\*\*\*\*\*\** ([a-zA-Z0-9_].*)', hunk.hdr)
      or cache.match(r'^@@@@ .* @@@@ ([a-zA-Z0-9_].*)', hunk.hdr)):
    fn = cache.group(1)
a207 1
  for i, line in enumerate(hunk.lines):
d210 139
a348 239
    if hunk.ctx_diff:
      line = re.sub(r'^([-+! ]) ', r'\1', line)

    # Remember most recent identifier in hunk
    # that might be a function name.
    if cache.match(r'^[-+! ]([a-zA-Z0-9_#].*)', line):
      fn = cache.group(1)

    change = line and re.match(r'^[-+!][^-]', line)

    # Top-level comment can not belong to function
    if re.match(r'^[-+! ]\/\*', line):
      fn = None

    if change and fn:
      if cache.match(r'^((class|struct|union|enum)\s+[a-zA-Z0-9_]+)', fn):
        # Struct declaration
        fn = cache.group(1)
      elif cache.search(r'#\s*define\s+([a-zA-Z0-9_]+)', fn):
        # Macro definition
        fn = cache.group(1)
      elif cache.match('^DEF[A-Z0-9_]+\s*\(([a-zA-Z0-9_]+)', fn):
        # Supermacro
        fn = cache.group(1)
      elif cache.search(r'([a-zA-Z_][^()\s]*)\s*\([^*]', fn):
        # Discard template and function parameters.
        fn = cache.group(1)
        fn = re.sub(r'<[^<>]*>', '', fn)
        fn = fn.rstrip()
      else:
        fn = None

      if fn and fn not in fns:  # Avoid dups
        fns.append(fn)

      fn = None

  return fns

def parse_patch(contents):
  """Parse patch contents to a sequence of FileDiffs."""

  diffs = []

  lines = contents.split('\n')

  i = 0
  while i < len(lines):
    line = lines[i]

    # Diff headers look like
    #   --- a/gcc/tree.c
    #   +++ b/gcc/tree.c
    # or
    #   *** gcc/cfgexpand.c     2013-12-25 20:07:24.800350058 +0400
    #   --- gcc/cfgexpand.c     2013-12-25 20:06:30.612350178 +0400

    if is_file_diff_start(line):
      left = re.split(r'\s+', line)[1]
    else:
      i += 1
      continue

    left = remove_suffixes(left);

    i += 1
    line = lines[i]

    if not cache.match(r'^[+-][+-][+-] +(\S+)', line):
      error("expected filename in line %d" % i)
    right = remove_suffixes(cache.group(1));

    # Extract real file name from left and right names.
    filename = None
    if left == right:
      filename = left
    elif left == '/dev/null':
      filename = right;
    elif right == '/dev/null':
      filename = left;
    else:
      comps = []
      while left and right:
        left, l = os.path.split(left)
        right, r = os.path.split(right)
        if l != r:
          break
        comps.append(l)
    
      if not comps:
        error("failed to extract common name for %s and %s" % (left, right))

      comps.reverse()
      filename = '/'.join(comps)

    d = FileDiff(filename)
    diffs.append(d)

    # Collect hunks for current file.
    hunk = None
    i += 1
    while i < len(lines):
      line = lines[i]

      # Create new hunk when we see hunk header
      if is_hunk_start(line):
        if hunk is not None:
          d.hunks.append(hunk)
        hunk = Hunk(line)
        i += 1
        continue

      # Stop when we reach next diff
      if (is_file_diff_start(line)
          or line.startswith('diff ')
          or line.startswith('Index: ')):
        i -= 1
        break

      if hunk is not None:
        hunk.lines.append(line)
      i += 1

    d.hunks.append(hunk)

  return diffs

def main():
  name, email = read_user_info()

  try:
    opts, args = getopt.getopt(sys.argv[1:], 'hiv', ['help', 'verbose', 'inline'])
  except getopt.GetoptError, err:
    error(str(err))

  inline = False
  verbose = 0

  for o, a in opts:
    if o in ('-h', '--help'):
      print_help_and_exit()
    elif o in ('-i', '--inline'):
      inline = True
    elif o in ('-v', '--verbose'):
      verbose += 1
    else:
      assert False, "unhandled option"

  if len(args) == 0:
    args = ['-']

  if len(args) == 1 and args[0] == '-':
    input = sys.stdin
  elif len(args) == 1:
    input = open(args[0], 'rb')
  else:
    error("too many arguments; for more details run with -h")

  contents = input.read()
  diffs = parse_patch(contents)

  if verbose:
    print "Parse results:"
    for d in diffs:
      d.dump()

  # Generate template ChangeLog.

  logs = {}
  for d in diffs:
    log_name = d.clname

    logs.setdefault(log_name, '')
    logs[log_name] += '\t* %s' % d.relname

    change_msg = ''

    # Check if file was removed or added.
    # Two patterns for context and unified diff.
    if len(d.hunks) == 1:
      hunk0 = d.hunks[0]
      if hunk0.is_file_addition():
        if re.search(r'testsuite.*(?<!\.exp)$', d.filename):
          change_msg = ': New test.\n'
        else:
          change_msg = ": New file.\n"
      elif hunk0.is_file_removal():
        change_msg = ": Remove.\n"

    _, ext = os.path.splitext(d.filename)
    if not change_msg and ext in ['.c', '.cpp', '.C', '.cc', '.h', '.inc', '.def']:
      fns = []
      for hunk in d.hunks:
        for fn in find_changed_funs(hunk):
          if fn not in fns:
            fns.append(fn)

      for fn in fns:
        if change_msg:
          change_msg += "\t(%s):\n" % fn
        else:
          change_msg = " (%s):\n" % fn

    logs[log_name] += change_msg if change_msg else ":\n"

  if inline and args[0] != '-':
    # Get a temp filename, rather than an open filehandle, because we use
    # the open to truncate.
    fd, tmp = tempfile.mkstemp("tmp.XXXXXXXX")
    os.close(fd)

    # Copy permissions to temp file
    # (old Pythons do not support shutil.copymode)
    shutil.copymode(args[0], tmp)

    # Open the temp file, clearing contents.
    out = open(tmp, 'wb')
  else:
    tmp = None
    out = sys.stdout

  # Print log
  date = time.strftime('%Y-%m-%d')
  for log_name, msg in sorted(logs.iteritems()):
    out.write("""\
%s:

%s  %s  <%s>

%s\n""" % (log_name, date, name, email, msg))

  if inline:
    # Append patch body
    out.write(contents)

    if args[0] != '-':
      # Write new contents atomically
      out.close()
      shutil.move(tmp, args[0])
d350 1
a350 2
if __name__ == '__main__':
    main()
@


1.1.1.7
log
@initial import of GCC 9.3.0.  changes include:

- live patching support
- shell completion help
- generally better diagnostic output (less verbose/more useful)
- diagnostics and optimisation choices can be emitted in json
- asan memory usage reduction
- many general, and specific to switch, inter-procedure,
  profile and link-time optimisations.  from the release notes:
  "Overall compile time of Firefox 66 and LibreOffice 6.2.3 on
  an 8-core machine was reduced by about 5% compared to GCC 8.3"
- OpenMP 5.0 support
- better spell-guesser
- partial experimental support for c2x and c++2a
- c++17 is no longer experimental
- arm AAPCS GCC 6-8 structure passing bug fixed, may cause
  incompatibility (restored compat with GCC 5 and earlier.)
- openrisc support
@
text
@d239 1
a239 1
    # Top-level comment cannot belong to function
@


1.1.1.8
log
@initial import of GCC 10.3.0.  main changes include:

caveats:
- ABI issue between c++14 and c++17 fixed
- profile mode is removed from libstdc++
- -fno-common is now the default

new features:
- new flags -fallocation-dce, -fprofile-partial-training,
  -fprofile-reproducible, -fprofile-prefix-path, and -fanalyzer
- many new compile and link time optimisations
- enhanced drive optimisations
- openacc 2.6 support
- openmp 5.0 features
- new warnings: -Wstring-compare and -Wzero-length-bounds
- extended warnings: -Warray-bounds, -Wformat-overflow,
  -Wrestrict, -Wreturn-local-addr, -Wstringop-overflow,
  -Warith-conversion, -Wmismatched-tags, and -Wredundant-tags
- some likely C2X features implemented
- more C++20 implemented
- many new arm & intel CPUs known

hundreds of reported bugs are fixed.  full list of changes
can be found at:

   https://gcc.gnu.org/gcc-10/changes.html
@
text
@d1 1
a1 1
#!/usr/bin/env python3
d3 1
a3 1
# Copyright (C) 2017-2019 Free Software Foundation, Inc.
a30 1
import argparse
d35 1
a42 2
pr_regex = re.compile('\+(\/(\/|\*)|[Cc*!])\s+(PR [a-z+-]+\/[0-9]+)')

d69 15
d90 1
a90 1
  return proc.returncode, out.decode(), err
d103 1
a103 1
    f = open(mklog_conf)
d156 1
a156 1
    print("Diff for %s:\n  ChangeLog = %s\n  rel name = %s\n" % (self.filename, self.clname, self.relname))
d158 1
a158 1
      print("Next hunk %d:" % i)
d170 2
a171 2
    print('%s' % self.hdr)
    print('%s' % '\n'.join(self.lines))
d194 2
a195 2
  return ((s.startswith('*** ') and not s.endswith('***'))
          or (s.startswith('--- ') and not s.endswith('---')))
d317 1
a317 1

d356 2
d359 15
a373 4
def get_pr_from_testcase(line):
    r = pr_regex.search(line)
    if r != None:
        return r.group(3)
d375 1
a375 1
        return None
d377 2
a378 2
def main():
  name, email = read_user_info()
d380 6
a385 5
  help_message =  """\
Generate ChangeLog template for PATCH.
PATCH must be generated using diff(1)'s -up or -cp options
(or their equivalent in Subversion/git).
"""
a386 14
  inline_message = """\
Prepends ChangeLog to PATCH.
If PATCH is not stdin, modifies PATCH in-place,
otherwise writes to stdout.'
"""

  parser = argparse.ArgumentParser(description = help_message)
  parser.add_argument('-v', '--verbose', action = 'store_true', help = 'Verbose messages')
  parser.add_argument('-i', '--inline', action = 'store_true', help = inline_message)
  parser.add_argument('input', nargs = '?', help = 'Patch file (or missing, read standard input)')
  args = parser.parse_args()
  if args.input == '-':
      args.input = None
  input = open(args.input) if args.input else sys.stdin
d390 2
a391 2
  if args.verbose:
    print("Parse results:")
a397 1
  prs = []
a412 3
          pr = get_pr_from_testcase(hunk0.lines[0])
          if pr and pr not in prs:
              prs.append(pr)
d419 1
a419 2
    if (not change_msg and ext in ['.c', '.cpp', '.C', '.cc', '.h', '.inc', '.def']
        and not 'testsuite' in d.filename):
d434 1
a434 1
  if args.inline and args.input:
d442 1
a442 1
    shutil.copymode(args.input, tmp)
d445 1
a445 1
    out = open(tmp, 'w')
d452 1
a452 5
  bugmsg = ''
  if len(prs):
    bugmsg = '\n'.join(['\t' + pr for pr in prs]) + '\n'

  for log_name, msg in sorted(logs.items()):
d458 1
a458 1
%s%s\n""" % (log_name, date, name, email, bugmsg, msg))
d460 1
a460 1
  if args.inline:
d464 1
a464 1
    if args.input:
d467 1
a467 1
      shutil.move(tmp, args.input)
@


1.1.1.1.8.1
log
@file mklog was added on branch tls-maxphys on 2014-08-19 23:53:12 +0000
@
text
@d1 151
@


1.1.1.1.8.2
log
@Rebase to HEAD as of a few days ago.
@
text
@a0 151
#!/usr/bin/perl
# Copyright (C) 2012 Free Software Foundation, Inc.
#
# This file is part of GCC.
#
# GCC is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3, or (at your option)
# any later version.
#
# GCC is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GCC; see the file COPYING.  If not, write to
# the Free Software Foundation, 51 Franklin Street, Fifth Floor,
# Boston, MA 02110-1301, USA.

# This script parses a .diff file generated with 'diff -up' or 'diff -cp'
# and writes a skeleton ChangeLog file to stdout. It does not try to be
# very smart when parsing function names, but it produces a reasonable
# approximation.
#
# Author: Diego Novillo <dnovillo@@google.com> and
#         Cary Coutant <ccoutant@@google.com>

# Change these settings to reflect your profile.
$username = $ENV{'USER'};
$name = `finger $username | grep -o 'Name: .*'`;
@@n = split(/: /, $name);
$name = @@n[1]; chop($name);
$addr = $username . "\@@my.domain.org";
$date = `date +%Y-%m-%d`; chop ($date);


#-----------------------------------------------------------------------------
# Program starts here. You should not need to edit anything below this
# line.
#-----------------------------------------------------------------------------
if ( $#ARGV != 0 ) {
    $prog = `basename $0`; chop ($prog);
    print "usage: $prog file.diff\n\n";
    print "Adds a ChangeLog template to the start of file.diff\n";
    print "It assumes that file.diff has been created with -up or -cp.\n";
    exit 1;
}

$diff = $ARGV[0];
$dir = `dirname $diff`; chop ($dir);
$basename = `basename $diff`; chop ($basename);
$cl = `mktemp /tmp/$basename.XXXXXX` || exit 1; chop ($cl);
$hdrline = "$date  $name  <$addr>";

open (CLFILE, ">$cl") or die "Could not open file $cl for writing";

print CLFILE "$hdrline\n\n";

# For every file in the .diff print all the function names in ChangeLog
# format.
$bof = 0;
open (DFILE, $diff) or die "Could not open file $diff for reading";
while (<DFILE>) {
    # Check if we found a new file.
    if (/^\+\+\+ (b\/)?(\S+)/) {
	# If we have not seen any function names in the previous file (ie,
	# $bof == 1), we just write out a ':' before starting the next
	# file.
	if ($bof == 1) {
	    print CLFILE ":\n";
	}
	$filename = $2;
	print CLFILE "\t* $filename";
	$bof = 1;
    }

    # Remember the last line in a unified diff block that might start
    # a new function.
    if (/^[-+ ]([a-zA-Z0-9_].*)/) {
        $save_fn = $1;
    }

    # If we find a new function, print it in brackets.  Special case if
    # this is the first function in a file.  
    #
    # Note that we don't try too hard to find good matches.  This should
    # return a superset of the actual set of functions in the .diff file.
    #
    # The first two patterns work with context diff files (diff -c). The
    # third pattern works with unified diff files (diff -u).
    #
    # The fourth pattern looks for the starts of functions or classes
    # within a unified diff block.

    if (/^\*\*\*\*\*\** ([a-zA-Z0-9_].*)/
        || /^[\-\+\!] ([a-zA-Z0-9_]+)[ \t]*\(.*/
	|| /^@@@@ .* @@@@ ([a-zA-Z0-9_].*)/
	|| /^[-+ ](\{)/)
      {
	$_ = $1;
	my $fn;
	if (/^\{/) {
	    # Beginning of a new function.
	    $_ = $save_fn;
	} else {
	    $save_fn = "";
	}
	if (/;$/) {
	    # No usable function name found.
	} elsif (/^((class|struct|union|enum) [a-zA-Z0-9_]+)/) {
	    # Discard stuff after the class/struct/etc. tag.
	    $fn = $1;
	} elsif (/([a-zA-Z0-9_][^(]*)\(/) {
	    # Discard template and function parameters.
	    $fn = $1;
	    1 while ($fn =~ s/<[^<>]*>//);
	    $fn =~ s/[ \t]*$//;
	}
	if ($fn && $seen_names{$fn} == 0) {
	    # If this is the first function in the file, we display it next
	    # to the filename, so we need an extra space before the opening
	    # brace.
	    if ($bof) {
		print CLFILE " ";
		$bof = 0;
	    } else {
		print CLFILE "\t";
	    }

	    print CLFILE "($fn):\n";
	    $seen_names{$fn} = 1;
	}
    }
}

# If we have not seen any function names (ie, $bof == 1), we just
# write out a ':'. This happens when there is only one file with no
# functions.
if ($bof == 1) {
    print CLFILE ":\n";
}

print CLFILE "\n";
close (DFILE);

# Concatenate the ChangeLog template and the original .diff file.
system ("cat $diff >>$cl && mv $cl $diff") == 0
    or die "Could not add the ChangeLog entry to $diff";

exit 0;
@


1.1.1.1.4.1
log
@file mklog was added on branch yamt-pagecache on 2014-05-22 16:35:06 +0000
@
text
@d1 151
@


1.1.1.1.4.2
log
@sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs.  ("Protocol error: too many arguments")
@
text
@a0 151
#!/usr/bin/perl
# Copyright (C) 2012 Free Software Foundation, Inc.
#
# This file is part of GCC.
#
# GCC is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3, or (at your option)
# any later version.
#
# GCC is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GCC; see the file COPYING.  If not, write to
# the Free Software Foundation, 51 Franklin Street, Fifth Floor,
# Boston, MA 02110-1301, USA.

# This script parses a .diff file generated with 'diff -up' or 'diff -cp'
# and writes a skeleton ChangeLog file to stdout. It does not try to be
# very smart when parsing function names, but it produces a reasonable
# approximation.
#
# Author: Diego Novillo <dnovillo@@google.com> and
#         Cary Coutant <ccoutant@@google.com>

# Change these settings to reflect your profile.
$username = $ENV{'USER'};
$name = `finger $username | grep -o 'Name: .*'`;
@@n = split(/: /, $name);
$name = @@n[1]; chop($name);
$addr = $username . "\@@my.domain.org";
$date = `date +%Y-%m-%d`; chop ($date);


#-----------------------------------------------------------------------------
# Program starts here. You should not need to edit anything below this
# line.
#-----------------------------------------------------------------------------
if ( $#ARGV != 0 ) {
    $prog = `basename $0`; chop ($prog);
    print "usage: $prog file.diff\n\n";
    print "Adds a ChangeLog template to the start of file.diff\n";
    print "It assumes that file.diff has been created with -up or -cp.\n";
    exit 1;
}

$diff = $ARGV[0];
$dir = `dirname $diff`; chop ($dir);
$basename = `basename $diff`; chop ($basename);
$cl = `mktemp /tmp/$basename.XXXXXX` || exit 1; chop ($cl);
$hdrline = "$date  $name  <$addr>";

open (CLFILE, ">$cl") or die "Could not open file $cl for writing";

print CLFILE "$hdrline\n\n";

# For every file in the .diff print all the function names in ChangeLog
# format.
$bof = 0;
open (DFILE, $diff) or die "Could not open file $diff for reading";
while (<DFILE>) {
    # Check if we found a new file.
    if (/^\+\+\+ (b\/)?(\S+)/) {
	# If we have not seen any function names in the previous file (ie,
	# $bof == 1), we just write out a ':' before starting the next
	# file.
	if ($bof == 1) {
	    print CLFILE ":\n";
	}
	$filename = $2;
	print CLFILE "\t* $filename";
	$bof = 1;
    }

    # Remember the last line in a unified diff block that might start
    # a new function.
    if (/^[-+ ]([a-zA-Z0-9_].*)/) {
        $save_fn = $1;
    }

    # If we find a new function, print it in brackets.  Special case if
    # this is the first function in a file.  
    #
    # Note that we don't try too hard to find good matches.  This should
    # return a superset of the actual set of functions in the .diff file.
    #
    # The first two patterns work with context diff files (diff -c). The
    # third pattern works with unified diff files (diff -u).
    #
    # The fourth pattern looks for the starts of functions or classes
    # within a unified diff block.

    if (/^\*\*\*\*\*\** ([a-zA-Z0-9_].*)/
        || /^[\-\+\!] ([a-zA-Z0-9_]+)[ \t]*\(.*/
	|| /^@@@@ .* @@@@ ([a-zA-Z0-9_].*)/
	|| /^[-+ ](\{)/)
      {
	$_ = $1;
	my $fn;
	if (/^\{/) {
	    # Beginning of a new function.
	    $_ = $save_fn;
	} else {
	    $save_fn = "";
	}
	if (/;$/) {
	    # No usable function name found.
	} elsif (/^((class|struct|union|enum) [a-zA-Z0-9_]+)/) {
	    # Discard stuff after the class/struct/etc. tag.
	    $fn = $1;
	} elsif (/([a-zA-Z0-9_][^(]*)\(/) {
	    # Discard template and function parameters.
	    $fn = $1;
	    1 while ($fn =~ s/<[^<>]*>//);
	    $fn =~ s/[ \t]*$//;
	}
	if ($fn && $seen_names{$fn} == 0) {
	    # If this is the first function in the file, we display it next
	    # to the filename, so we need an extra space before the opening
	    # brace.
	    if ($bof) {
		print CLFILE " ";
		$bof = 0;
	    } else {
		print CLFILE "\t";
	    }

	    print CLFILE "($fn):\n";
	    $seen_names{$fn} = 1;
	}
    }
}

# If we have not seen any function names (ie, $bof == 1), we just
# write out a ':'. This happens when there is only one file with no
# functions.
if ($bof == 1) {
    print CLFILE ":\n";
}

print CLFILE "\n";
close (DFILE);

# Concatenate the ChangeLog template and the original .diff file.
system ("cat $diff >>$cl && mv $cl $diff") == 0
    or die "Could not add the ChangeLog entry to $diff";

exit 0;
@


