Skip to content

Commit 92b5265

Browse files
committedApr 30, 2017
[sipify] fix multiline definition with member initiliazing list
1 parent 82418ea commit 92b5265

File tree

3 files changed

+55
-28
lines changed

3 files changed

+55
-28
lines changed
 

‎scripts/sipify.pl

Lines changed: 43 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,10 @@ sub dbg
8282
}
8383
sub dbg_info
8484
{
85-
$debug == 0 or push @output, $_[0]."\n";
85+
if ($debug == 1){
86+
push @output, $_[0]."\n";
87+
print $_[0]."\n";
88+
}
8689
}
8790

8891
# main loop
@@ -468,7 +471,7 @@ sub dbg_info
468471
dbg_info(" go for multiline");
469472
$line = $lines[$line_idx];
470473
$line_idx++;
471-
while ( $line =~ m/^\s*[:,] [\w<>]+\(.*?\)/){
474+
while ( $line =~ m/^\s*[:,]\s+[\w<>]+\(.*?\)/){
472475
dbg_info(" member initializing list");
473476
$line = $lines[$line_idx];
474477
$line_idx++;
@@ -569,33 +572,45 @@ sub dbg_info
569572

570573
# multiline definition (parenthesis left open)
571574
if ( $MULTILINE_DEFINITION == 1 ){
572-
# see https://regex101.com/r/DN01iM/2
573-
if ( $line =~ m/^([^()]+(\((?:[^()]++|(?1))*\)))*[^()]*\)[^()]*$/){
574-
$MULTILINE_DEFINITION = 0;
575-
# remove potential following body
576-
if ( $SIP_RUN == 0 && $lines[$line_idx] =~ m/^\s*\{$/ ){
577-
dbg_info("remove following body of multiline def");
578-
my $last_line = $line;
579-
my $nesting_index = 0;
580-
while ($line_idx < $line_count){
581-
$line = $lines[$line_idx];
582-
$line_idx++;
575+
dbg_info("on multiline");
576+
# https://regex101.com/r/DN01iM/2
577+
if ( $line =~ m/^([^()]+(\((?:[^()]++|(?1))*\)))*[^()]*\)[^()]*$/){
578+
$MULTILINE_DEFINITION = 0;
579+
dbg_info("ending multiline");
580+
# remove potential following body
583581

584-
$nesting_index += $line =~ tr/\{//;
585-
$nesting_index -= $line =~ tr/\}//;
586-
if ($nesting_index == 0){
587-
last;
588-
}
589-
}
590-
# add missing semi column
591-
my $dummy = pop(@output);
592-
push @output, dbg("MLT")."$last_line;\n";
593-
}
594-
}
595-
else
596-
{
597-
next;
598-
}
582+
583+
if ( $SIP_RUN == 0 && $line !~ m/(\{.*\}|;)\s*(\/\/.*)?$/ ){
584+
dbg_info("remove following body of multiline def");
585+
my $last_line = $line;
586+
$line = $lines[$line_idx];
587+
$line_idx++;
588+
while ( $line =~ m/^\s*[:,]\s+[\w<>]+\(.*?\)/){
589+
dbg_info(" member initializing list");
590+
$line = $lines[$line_idx];
591+
$line_idx++;
592+
}
593+
my $nesting_index = 1;
594+
if ( $line =~ m/^\s*\{$/ ){
595+
while ($line_idx < $line_count){
596+
$line = $lines[$line_idx];
597+
$line_idx++;
598+
$nesting_index += $line =~ tr/\{//;
599+
$nesting_index -= $line =~ tr/\}//;
600+
if ($nesting_index == 0){
601+
last;
602+
}
603+
}
604+
}
605+
# add missing semi column
606+
my $dummy = pop(@output);
607+
push @output, dbg("MLT")."$last_line;\n";
608+
}
609+
}
610+
else
611+
{
612+
next;
613+
}
599614
}
600615
elsif ( $line =~ m/^[^()]+\([^()]*([^()]*\([^()]*\)[^()]*)*[^)]*$/ ){
601616
dbg_info("Mulitline detected");

‎tests/scripts/sipifyheader.expected.sip

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,10 @@ A constructor with no empty `()`
101101
A constructor with some special character types
102102
%End
103103

104+
Parameter( const QString &name,
105+
bool optional = false,
106+
const QVariant &defaultValue = QVariant() );
107+
104108
QgsSipifyHeader();
105109
%Docstring
106110
Default constructor

‎tests/scripts/sipifyheader.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,14 @@ class CORE_EXPORT QgsSipifyHeader : public QtClass<QVariant>, private Ui::QgsBas
145145
: mMember( nullptr )
146146
{}
147147

148+
Parameter( const QString &name,
149+
bool optional = false,
150+
const QVariant &defaultValue = QVariant() )
151+
: mName( name )
152+
, mOptional( optional )
153+
, mDefaultValue( defaultValue )
154+
{}
155+
148156
//! Default constructor
149157
QgsSipifyHeader() = default;
150158

0 commit comments

Comments
 (0)
Please sign in to comment.