Skip to content

Commit

Permalink
[sipify] fix multiline definition with member initiliazing list
Browse files Browse the repository at this point in the history
  • Loading branch information
3nids committed Apr 30, 2017
1 parent 82418ea commit 92b5265
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 28 deletions.
71 changes: 43 additions & 28 deletions scripts/sipify.pl
Expand Up @@ -82,7 +82,10 @@ sub dbg
}
sub dbg_info
{
$debug == 0 or push @output, $_[0]."\n";
if ($debug == 1){
push @output, $_[0]."\n";
print $_[0]."\n";
}
}

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

# multiline definition (parenthesis left open)
if ( $MULTILINE_DEFINITION == 1 ){
# see https://regex101.com/r/DN01iM/2
if ( $line =~ m/^([^()]+(\((?:[^()]++|(?1))*\)))*[^()]*\)[^()]*$/){
$MULTILINE_DEFINITION = 0;
# remove potential following body
if ( $SIP_RUN == 0 && $lines[$line_idx] =~ m/^\s*\{$/ ){
dbg_info("remove following body of multiline def");
my $last_line = $line;
my $nesting_index = 0;
while ($line_idx < $line_count){
$line = $lines[$line_idx];
$line_idx++;
dbg_info("on multiline");
# https://regex101.com/r/DN01iM/2
if ( $line =~ m/^([^()]+(\((?:[^()]++|(?1))*\)))*[^()]*\)[^()]*$/){
$MULTILINE_DEFINITION = 0;
dbg_info("ending multiline");
# remove potential following body

$nesting_index += $line =~ tr/\{//;
$nesting_index -= $line =~ tr/\}//;
if ($nesting_index == 0){
last;
}
}
# add missing semi column
my $dummy = pop(@output);
push @output, dbg("MLT")."$last_line;\n";
}
}
else
{
next;
}

if ( $SIP_RUN == 0 && $line !~ m/(\{.*\}|;)\s*(\/\/.*)?$/ ){
dbg_info("remove following body of multiline def");
my $last_line = $line;
$line = $lines[$line_idx];
$line_idx++;
while ( $line =~ m/^\s*[:,]\s+[\w<>]+\(.*?\)/){
dbg_info(" member initializing list");
$line = $lines[$line_idx];
$line_idx++;
}
my $nesting_index = 1;
if ( $line =~ m/^\s*\{$/ ){
while ($line_idx < $line_count){
$line = $lines[$line_idx];
$line_idx++;
$nesting_index += $line =~ tr/\{//;
$nesting_index -= $line =~ tr/\}//;
if ($nesting_index == 0){
last;
}
}
}
# add missing semi column
my $dummy = pop(@output);
push @output, dbg("MLT")."$last_line;\n";
}
}
else
{
next;
}
}
elsif ( $line =~ m/^[^()]+\([^()]*([^()]*\([^()]*\)[^()]*)*[^)]*$/ ){
dbg_info("Mulitline detected");
Expand Down
4 changes: 4 additions & 0 deletions tests/scripts/sipifyheader.expected.sip
Expand Up @@ -101,6 +101,10 @@ A constructor with no empty `()`
A constructor with some special character types
%End

Parameter( const QString &name,
bool optional = false,
const QVariant &defaultValue = QVariant() );

QgsSipifyHeader();
%Docstring
Default constructor
Expand Down
8 changes: 8 additions & 0 deletions tests/scripts/sipifyheader.h
Expand Up @@ -145,6 +145,14 @@ class CORE_EXPORT QgsSipifyHeader : public QtClass<QVariant>, private Ui::QgsBas
: mMember( nullptr )
{}

Parameter( const QString &name,
bool optional = false,
const QVariant &defaultValue = QVariant() )
: mName( name )
, mOptional( optional )
, mDefaultValue( defaultValue )
{}

//! Default constructor
QgsSipifyHeader() = default;

Expand Down

0 comments on commit 92b5265

Please sign in to comment.