Skip to content

Commit 1ab5a62

Browse files
committedApr 20, 2017
[sipify] handle override method signature on several lines
1 parent 8f2a5c7 commit 1ab5a62

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed
 

‎scripts/sipify.pl

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -338,11 +338,26 @@ sub processDoxygenLine
338338
# remove keywords
339339
if ( $line =~ m/\boverride\b/){
340340
$is_override = 1;
341-
if ( $line !~ m/^(\s*)virtual\b(.*)$/ ){
341+
342+
# handle multiline definition to add virtual keyword on opening line
343+
if ( $MULTILINE_DEFINITION == 1 ){
344+
my $virtual_line = $line;
345+
my $virtual_line_idx = $line_idx;
346+
while ( $virtual_line !~ m/^[^()]*\(([^()]*\([^()]*\)[^()]*)*[^()]*$/){
347+
$virtual_line_idx--;
348+
$virtual_line = $lines[$virtual_line_idx];
349+
$virtual_line_idx >= 0 or die 'could not reach opening definition';
350+
}
351+
if ( $virtual_line !~ m/^(\s*)virtual\b(.*)$/ ){
352+
my $idx = $#output-$line_idx+$virtual_line_idx+2;
353+
#print "len: $#output line_idx: $line_idx virt: $virtual_line_idx\n"idx: $idx\n$output[$idx]\n";
354+
$output[$idx] = $virtual_line =~ s/^(\s*?)\b(.*)$/$1 virtual $2\n/r;
355+
}
356+
}
357+
elsif ( $line !~ m/^(\s*)virtual\b(.*)$/ ){
342358
#sip often requires the virtual keyword to be present, or it chokes on covariant return types
343359
#in overridden methods
344-
$line =~ m/^(\s*?)\b(.*)$/;
345-
$line = "$1virtual $2\n";
360+
$line =~ s/^(\s*?)\b(.*)$/$1virtual $2\n/;
346361
}
347362
}
348363
$line =~ s/\s*\boverride\b//;
@@ -467,6 +482,7 @@ sub processDoxygenLine
467482
# write comment
468483
if ( $line =~ m/^\s*$/ )
469484
{
485+
$is_override = 0;
470486
next;
471487
}
472488
elsif ( $line =~ m/\/\// || $line =~ m/\s*typedef / || $line =~ m/\s*struct / ){

‎tests/scripts/sipifyheader.expected.sip

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,9 @@ Removing function body with virtual const reference
207207
virtual int overrideWithoutVirtual();
208208

209209

210+
virtual void overrideWithoutVirtualMultLine( const QList<int, QString> &list1,
211+
const QList<int, QString> &list2 );
212+
210213
QString returnTypeString() const;
211214
%Docstring
212215
:rtype: str

‎tests/scripts/sipifyheader.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,9 @@ class CORE_EXPORT QgsSipifyHeader : public QtClass<QVariant>, private Ui::QgsBas
225225

226226
int overrideWithoutVirtual() override;
227227

228+
void overrideWithoutVirtualMultLine( const QList<int, QString> &list1,
229+
const QList<int, QString> &list2 ) override;
230+
228231
QString returnTypeString() const;
229232

230233
double returnTypeDouble() const;

0 commit comments

Comments
 (0)