Skip to content

Commit

Permalink
[sipify] handle override method signature on several lines
Browse files Browse the repository at this point in the history
  • Loading branch information
3nids committed Apr 20, 2017
1 parent 8f2a5c7 commit 1ab5a62
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
22 changes: 19 additions & 3 deletions scripts/sipify.pl
Expand Up @@ -338,11 +338,26 @@ sub processDoxygenLine
# remove keywords
if ( $line =~ m/\boverride\b/){
$is_override = 1;
if ( $line !~ m/^(\s*)virtual\b(.*)$/ ){

# handle multiline definition to add virtual keyword on opening line
if ( $MULTILINE_DEFINITION == 1 ){
my $virtual_line = $line;
my $virtual_line_idx = $line_idx;
while ( $virtual_line !~ m/^[^()]*\(([^()]*\([^()]*\)[^()]*)*[^()]*$/){
$virtual_line_idx--;
$virtual_line = $lines[$virtual_line_idx];
$virtual_line_idx >= 0 or die 'could not reach opening definition';
}
if ( $virtual_line !~ m/^(\s*)virtual\b(.*)$/ ){
my $idx = $#output-$line_idx+$virtual_line_idx+2;
#print "len: $#output line_idx: $line_idx virt: $virtual_line_idx\n"idx: $idx\n$output[$idx]\n";
$output[$idx] = $virtual_line =~ s/^(\s*?)\b(.*)$/$1 virtual $2\n/r;
}
}
elsif ( $line !~ m/^(\s*)virtual\b(.*)$/ ){
#sip often requires the virtual keyword to be present, or it chokes on covariant return types
#in overridden methods
$line =~ m/^(\s*?)\b(.*)$/;
$line = "$1virtual $2\n";
$line =~ s/^(\s*?)\b(.*)$/$1virtual $2\n/;
}
}
$line =~ s/\s*\boverride\b//;
Expand Down Expand Up @@ -467,6 +482,7 @@ sub processDoxygenLine
# write comment
if ( $line =~ m/^\s*$/ )
{
$is_override = 0;
next;
}
elsif ( $line =~ m/\/\// || $line =~ m/\s*typedef / || $line =~ m/\s*struct / ){
Expand Down
3 changes: 3 additions & 0 deletions tests/scripts/sipifyheader.expected.sip
Expand Up @@ -207,6 +207,9 @@ Removing function body with virtual const reference
virtual int overrideWithoutVirtual();


virtual void overrideWithoutVirtualMultLine( const QList<int, QString> &list1,
const QList<int, QString> &list2 );

QString returnTypeString() const;
%Docstring
:rtype: str
Expand Down
3 changes: 3 additions & 0 deletions tests/scripts/sipifyheader.h
Expand Up @@ -225,6 +225,9 @@ class CORE_EXPORT QgsSipifyHeader : public QtClass<QVariant>, private Ui::QgsBas

int overrideWithoutVirtual() override;

void overrideWithoutVirtualMultLine( const QList<int, QString> &list1,
const QList<int, QString> &list2 ) override;

QString returnTypeString() const;

double returnTypeDouble() const;
Expand Down

0 comments on commit 1ab5a62

Please sign in to comment.