File indexing completed on 2024-04-28 09:37:05

0001 #!/usr/bin/perl -w
0002 
0003 # Laurent Montel <montel@kde.org> (2017)
0004 # Use qoverload (qt5.7)
0005 # it's totally experimental
0006 # find -iname "*.cpp" |xargs kde-dev-scripts/kf5/convert-to_qoverload.pl
0007 
0008 use strict;
0009 use File::Basename;
0010 use lib dirname($0);
0011 use functionUtilkde;
0012 
0013 my $activateDebug = 1;
0014 
0015 
0016 
0017 foreach my $file (@ARGV) {
0018 
0019 
0020     my $currentLine = 1;
0021 
0022     # 4) Parse cpp file
0023     my $modified;
0024     my $tojoin;
0025     my $toorig;
0026     my %varnamewithpointer = ();
0027     open( my $FILE, "<", $file ) or warn "We can't open file $file:$!\n";
0028     my @l = map {
0029         my $orig = $_;
0030 
0031         # Verify comment
0032         if ( defined $tojoin ) {
0033 
0034             $toorig .= $_;
0035 
0036             $tojoin =~ s/\s*\n$//;    # remove any trailing space
0037             $_ =~ s/^\s*/ /;          # replace indent with single space
0038             $_ = $tojoin . $_;
0039             warn "look at end ? \'$_\'\n";
0040             if ( /;\s*$/ || /;\s*\/\*\.*\*\// || /;\s*\n$/ ) {
0041                 undef $tojoin;
0042             }
0043         }
0044 
0045         my $regexpConnect = qr/
0046           ^(\s*(?:[\-\>:\w]+)?)           # (1) Indentation, optional classname or variable name
0047           connect\s*
0048           ${functionUtilkde::paren_begin}2${functionUtilkde::paren_end}  # (2) (args)         
0049           ;/x;                        # /x Enables extended whitespace mode
0050         if ( my ( $indent, $argument ) = $_ =~ $regexpConnect ) {
0051             if ( defined $activateDebug ) {
0052                 warn "ARGUMENT $argument\n";
0053             }
0054             my ( $sender, $classname, $secondargument, $methodname, $end, $after);
0055 
0056             my $connectArgument_regexp = qr/
0057                                  ^([^,]*)\s*                 # (1) sender
0058                                  ,\s*static_cast\s*<\s*void\s*\((.*\*\)) #(2) classname
0059                                  \((.*)\)\> #(2) secondargument
0060                                  (\(&.*\)) #methodname
0061                                  #,\s*static_cast\s*<\s*void\s*(\(\s*\*\))
0062                                  ,\s*(.*)$                       # (6) after
0063                                  /x;
0064                                  
0065             if (($sender, $classname, $secondargument, $methodname, $after) = $argument =~ $connectArgument_regexp)
0066             {
0067                 #warn "SPLIT!!!!!!!! : SENDER: $sender, CLASSNAME : $classname, SECONDARGUMENT: $secondargument, METHODENAME: $methodname, $end, $after\n";
0068                 $_ = $indent . "connect" . $sender . ", QOverload<$secondargument>::of$methodname,$end $after;\n";
0069             } else {
0070                if (defined $toorig) {
0071                   $_ = $toorig;
0072                   undef $toorig;
0073                }
0074             }
0075             undef $toorig;
0076         }
0077         else {
0078             if (/^(\s*(?:[\-\>:\w]+)?)\bconnect\b\s*/) {
0079                 warn "It's perhaps a multi line " . $_ . "\n";
0080                 $tojoin = $_;
0081                 $toorig = $_;
0082                 $_      = "";
0083             }
0084         }
0085         $currentLine++;
0086         $modified ||= $orig ne $_;
0087         $_;
0088     } <$FILE>;
0089 
0090     if ($modified) {
0091         open( my $OUT, ">", $file );
0092         print $OUT @l;
0093         close($OUT);
0094     }
0095 }
0096 functionUtilkde::diffFile("@ARGV");