Skip to content

Commit

Permalink
[sipify] handle multiple annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
3nids committed Apr 30, 2017
1 parent 4ae22ac commit 298e14b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
13 changes: 9 additions & 4 deletions scripts/sipify.pl
Expand Up @@ -99,7 +99,7 @@ sub remove_constructor_or_body {
|| $line =~ m/SIP_SKIP\s*(?!;)\s*(\/\/.*)?$/ ){
dbg_info("remove constructor definition, function bodies, member initializing list");
my $newline = "$1$2$3$4$5;";
if ($line !~ m/{.*}(\s*SIP_\w+)?\s*(\/\/.*)?$/){
if ($line !~ m/{.*}(\s*SIP_\w+)*\s*(\/\/.*)?$/){
dbg_info(" go for multiline");
$line = $lines[$line_idx];
$line_idx++;
Expand Down Expand Up @@ -554,6 +554,7 @@ sub remove_constructor_or_body {
# remove export macro from struct definition
$line =~ s/^(\s*struct )\w+_EXPORT (.+)$/$1$2/;

# printed annotations
$line =~ s/\bSIP_FACTORY\b/\/Factory\//;
$line =~ s/\bSIP_OUT\b/\/Out\//g;
$line =~ s/\bSIP_IN\b/\/In\//g;
Expand All @@ -565,11 +566,16 @@ sub remove_constructor_or_body {
$line =~ s/\bSIP_RELEASEGIL\b/\/ReleaseGIL\//;
$line =~ s/\bSIP_ARRAY\b/\/Array\//;
$line =~ s/\bSIP_ARRAYSIZE\b/\/ArraySize\//;

$line =~ s/SIP_PYNAME\(\s*(\w+)\s*\)/\/PyName=$1\//;

# combine multiple annotations
dbg_info("combine multiple annotations -- works only for 2");
# https://regex101.com/r/uvCt4M/1
$line =~ s/\/(\w+(=\w+)?)\/\s*\/(\w+(=\w+)?)\/\s*;(\s*(\/\/.*)?)$/\/$1,$3\/$5;/;

# unprinted annotations
$line =~ s/(\w+)(\<(?>[^<>]|(?2))*\>)?\s+SIP_PYARGTYPE\(\s*\'?([^()']+)(\(\s*(?:[^()]++|(?2))*\s*\))?\'?\s*\)/$3/g;
$line =~ s/=\s+[^=]*?\s+SIP_PYARGDEFAULT\(\s*\'?([^()']+)(\(\s*(?:[^()]++|(?2))*\s*\))?\'?\s*\)/= $1/g;

# remove argument
if ($line =~ m/SIP_PYARGREMOVE/){
if ( $MULTILINE_DEFINITION == 1 ){
Expand All @@ -588,7 +594,6 @@ sub remove_constructor_or_body {
# see https://regex101.com/r/5iNptO/4
$line =~ s/(?<coma>, +)?(const )?(\w+)(\<(?>[^<>]|(?4))*\>)? [\w&*]+ SIP_PYARGREMOVE( = [^()]*(\(\s*(?:[^()]++|(?6))*\s*\))?)?(?(<coma>)|,?)//g;
}

$line =~ s/SIP_FORCE//;

# fix astyle placing space after % character
Expand Down
2 changes: 2 additions & 0 deletions tests/scripts/sipifyheader.expected.sip
Expand Up @@ -290,6 +290,8 @@ Mulitline body
VertexType type;
}

void combinedAnnotations() /Factory,PyName=otherName/;

void simple( );
%Docstring
remove argument
Expand Down
2 changes: 2 additions & 0 deletions tests/scripts/sipifyheader.h
Expand Up @@ -316,6 +316,8 @@ class CORE_EXPORT QgsSipifyHeader : public QtClass<QVariant>, private Ui::QgsBas
VertexType type;
}

void combinedAnnotations() SIP_FACTORY SIP_PYNAME(otherName);

//! remove argument
void simple( bool test SIP_PYARGREMOVE );
void method( bool myArg SIP_PYARGREMOVE = test );
Expand Down

0 comments on commit 298e14b

Please sign in to comment.