File: convert-to_qoverload.pl

package info (click to toggle)
kde-dev-scripts 4%3A18.08.0-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 3,496 kB
  • sloc: perl: 15,466; lisp: 5,627; sh: 4,157; python: 3,892; ruby: 2,158; makefile: 16; sed: 9
file content (96 lines) | stat: -rwxr-xr-x 3,183 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/usr/bin/perl -w

# Laurent Montel <montel@kde.org> (2017)
# Use qoverload (qt5.7)
# it's totally experimental
# find -iname "*.cpp" |xargs kde-dev-scripts/kf5/convert-to_qoverload.pl

use strict;
use File::Basename;
use lib dirname($0);
use functionUtilkde;

my $activateDebug = 1;



foreach my $file (@ARGV) {


    my $currentLine = 1;

    # 4) Parse cpp file
    my $modified;
    my $tojoin;
    my $toorig;
    my %varnamewithpointer = ();
    open( my $FILE, "<", $file ) or warn "We can't open file $file:$!\n";
    my @l = map {
        my $orig = $_;

        # Verify comment
        if ( defined $tojoin ) {

            $toorig .= $_;

            $tojoin =~ s/\s*\n$//;    # remove any trailing space
            $_ =~ s/^\s*/ /;          # replace indent with single space
            $_ = $tojoin . $_;
            warn "look at end ? \'$_\'\n";
            if ( /;\s*$/ || /;\s*\/\*\.*\*\// || /;\s*\n$/ ) {
                undef $tojoin;
            }
        }

        my $regexpConnect = qr/
          ^(\s*(?:[\-\>:\w]+)?)           # (1) Indentation, optional classname or variable name
          connect\s*
          ${functionUtilkde::paren_begin}2${functionUtilkde::paren_end}  # (2) (args)         
          ;/x;                        # /x Enables extended whitespace mode
        if ( my ( $indent, $argument ) = $_ =~ $regexpConnect ) {
            if ( defined $activateDebug ) {
                warn "ARGUMENT $argument\n";
            }
            my ( $sender, $classname, $secondargument, $methodname, $end, $after);

            my $connectArgument_regexp = qr/
                                 ^([^,]*)\s*                 # (1) sender
                                 ,\s*static_cast\s*<\s*void\s*\((.*\*\)) #(2) classname
                                 \((.*)\)\> #(2) secondargument
                                 (\(&.*\)) #methodname
                                 #,\s*static_cast\s*<\s*void\s*(\(\s*\*\))
                                 ,\s*(.*)$                       # (6) after
                                 /x;
                                 
            if (($sender, $classname, $secondargument, $methodname, $after) = $argument =~ $connectArgument_regexp)
            {
                #warn "SPLIT!!!!!!!! : SENDER: $sender, CLASSNAME : $classname, SECONDARGUMENT: $secondargument, METHODENAME: $methodname, $end, $after\n";
                $_ = $indent . "connect" . $sender . ", QOverload<$secondargument>::of$methodname,$end $after;\n";
            } else {
               if (defined $toorig) {
                  $_ = $toorig;
                  undef $toorig;
               }
            }
            undef $toorig;
        }
        else {
            if (/^(\s*(?:[\-\>:\w]+)?)\bconnect\b\s*/) {
                warn "It's perhaps a multi line " . $_ . "\n";
                $tojoin = $_;
                $toorig = $_;
                $_      = "";
            }
        }
        $currentLine++;
        $modified ||= $orig ne $_;
        $_;
    } <$FILE>;

    if ($modified) {
        open( my $OUT, ">", $file );
        print $OUT @l;
        close($OUT);
    }
}
functionUtilkde::diffFile("@ARGV");