Skip to content

Commit

Permalink
[sipify] fix Abstract class
Browse files Browse the repository at this point in the history
unblacklist qgstransaction.sip
(followup 931bf32)
also fix method declaration with private only inheritance
  • Loading branch information
3nids committed May 8, 2017
1 parent a88cf7a commit bfb62c4
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 65 deletions.
29 changes: 14 additions & 15 deletions cmake_templates/Doxyfile.in
Original file line number Diff line number Diff line change
Expand Up @@ -2049,26 +2049,25 @@ PREDEFINED =
# definition found in the source code.
# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.

EXPAND_AS_DEFINED = "SIP_TRANSFER" \
"SIP_PYNAME" \
"SIP_OUT" \
"SIP_INOUT" \
"SIP_TRANSFERTHIS" \
"SIP_TRANSFERBACK" \
"SIP_FACTORY" \
"SIP_KEEPREFERENCE" \
EXPAND_AS_DEFINED = "SIP_ABSTRACT" \
"SIP_ARRAY" \
"SIP_ARRAYSIZE" \
"SIP_PYNAME" \
"SIP_SKIP" \
"SIP_PYARGDEFAULT" \
"SIP_PYTYPE" \
"SIP_PYARGREMOVE" \
"SIP_CONVERT_TO_SUBCLASS_CODE" \
"SIP_END" \
"SIP_FACTORY" \
"SIP_FEATURE" \
"SIP_IF_FEATURE" \
"SIP_END" \
"SIP_ABSTRACT"
"SIP_INOUT" \
"SIP_KEEPREFERENCE" \
"SIP_OUT" \
"SIP_PYARGDEFAULT" \
"SIP_PYARGREMOVE" \
"SIP_PYNAME" \
"SIP_PYTYPE" \
"SIP_SKIP" \
"SIP_TRANSFER" \
"SIP_TRANSFERBACK" \
"SIP_TRANSFERTHIS"

# If the SKIP_FUNCTION_MACROS tag is set to YES then doxygen's preprocessor will
# remove all references to function-like macros that are alone on a line, have
Expand Down
1 change: 0 additions & 1 deletion python/auto_sip.blacklist
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ core/qgsfeaturerequest.sip
core/qgsgeometrysimplifier.sip
core/qgsgeometryvalidator.sip
core/qgsmaptopixelgeometrysimplifier.sip
core/qgstransaction.sip
core/qgstransactiongroup.sip
core/qgsdartmeasurement.sip
core/qgsexpressionfieldbuffer.sip
Expand Down
103 changes: 56 additions & 47 deletions scripts/sipify.pl
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,54 @@ sub remove_constructor_or_body {
};
}

sub fix_annotations(){
# printed annotations
$line =~ s/\bSIP_ABSTRACT\b/\/Abstract\//;
$line =~ s/\bSIP_ARRAY\b/\/Array\//;
$line =~ s/\bSIP_ARRAYSIZE\b/\/ArraySize\//;
$line =~ s/\bSIP_FACTORY\b/\/Factory\//;
$line =~ s/\bSIP_IN\b/\/In\//g;
$line =~ s/\bSIP_INOUT\b/\/In,Out\//g;
$line =~ s/\bSIP_KEEPREFERENCE\b/\/KeepReference\//;
$line =~ s/\bSIP_OUT\b/\/Out\//g;
$line =~ s/\bSIP_RELEASEGIL\b/\/ReleaseGIL\//;
$line =~ s/\bSIP_TRANSFER\b/\/Transfer\//g;
$line =~ s/\bSIP_TRANSFERBACK\b/\/TransferBack\//;
$line =~ s/\bSIP_TRANSFERTHIS\b/\/TransferThis\//;

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

# combine multiple annotations
# https://regex101.com/r/uvCt4M/3
do {no warnings 'uninitialized';
$line =~ s/\/(\w+(=\w+)?)\/\s*\/(\w+(=\w+)?)\//\/$1,$3\//;
(! $3) or dbg_info("combine multiple annotations -- works only for 2");
};

# unprinted annotations
$line =~ s/(\w+)(\<(?>[^<>]|(?2))*\>)?\s+SIP_PYTYPE\(\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 ){
my $prev_line = pop(@output) =~ s/\n$//r;
# update multi line status
my $parenthesis_balance = 0;
$parenthesis_balance += $prev_line =~ tr/\(//;
$parenthesis_balance -= $prev_line =~ tr/\)//;
if ($parenthesis_balance == 1){
$MULTILINE_DEFINITION = 0;
}
# concat with above line to bring previous commas
$line =~ s/^\s+//;
$line = "$prev_line $line\n";
}
# 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//;
}


# main loop
while ($line_idx < $line_count){
Expand Down Expand Up @@ -388,7 +436,8 @@ sub remove_constructor_or_body {
}

# class declaration started
if ( $line =~ m/^(\s*class)\s*([A-Z]+_EXPORT)?\s+(\w+)(\s*\:.*)?(\s*SIP_ABSTRACT)?$/ ){
# https://regex101.com/r/6FWntP/2
if ( $line =~ m/^(\s*class)\s+([A-Z]+_EXPORT)?\s+(\w+)(\s*\:\s*(public|private)\s+\w+(<\w+>)?(::\w+(<\w+>)?)*(,\s*(public|private)\s+\w+(<\w+>)?(::\w+(<\w+>)?)*)*)?(?<annot>\s*SIP_.*)?$/ ){
dbg_info("class definition started => private");
push @ACCESS, PRIVATE;
push @global_bracket_nesting_index, 0;
Expand All @@ -401,12 +450,14 @@ sub remove_constructor_or_body {
if ($4){
my $m = $4;
$m =~ s/public //g;
$m =~ s/,?\s*private \w+(::\w+)?//;
$m =~ s/[,:]?\s*private \w+(::\w+)?//;
$m =~ s/(\s*:)?\s*$//;
$line .= $m;
}
if ($5) {
$line .= ' /Abstract/';
if (defined $+{annot})
{
$line .= "$+{annot}";
fix_annotations();
}

$line .= "\n{\n";
Expand Down Expand Up @@ -559,49 +610,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;
$line =~ s/\bSIP_INOUT\b/\/In,Out\//g;
$line =~ s/\bSIP_TRANSFER\b/\/Transfer\//g;
$line =~ s/\bSIP_KEEPREFERENCE\b/\/KeepReference\//;
$line =~ s/\bSIP_TRANSFERTHIS\b/\/TransferThis\//;
$line =~ s/\bSIP_TRANSFERBACK\b/\/TransferBack\//;
$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
# https://regex101.com/r/uvCt4M/3
do {no warnings 'uninitialized';
$line =~ s/\/(\w+(=\w+)?)\/\s*\/(\w+(=\w+)?)\//\/$1,$3\//;
(! $3) or dbg_info("combine multiple annotations -- works only for 2");
};

# unprinted annotations
$line =~ s/(\w+)(\<(?>[^<>]|(?2))*\>)?\s+SIP_PYTYPE\(\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 ){
my $prev_line = pop(@output) =~ s/\n$//r;
# update multi line status
my $parenthesis_balance = 0;
$parenthesis_balance += $prev_line =~ tr/\(//;
$parenthesis_balance -= $prev_line =~ tr/\)//;
if ($parenthesis_balance == 1){
$MULTILINE_DEFINITION = 0;
}
# concat with above line to bring previous commas
$line =~ s/^\s+//;
$line = "$prev_line $line\n";
}
# 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_annotations();

# fix astyle placing space after % character
$line =~ s/\s*% (MappedType|TypeCode|TypeHeaderCode|ModuleHeaderCode|ConvertFromTypeCode|ConvertToTypeCode|MethodCode|End)/%$1/;
Expand Down
2 changes: 1 addition & 1 deletion tests/scripts/sipifyheader.expected.sip
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ remove argument
void ShowThisPrivateOne() ;
};

class ClassWithPrivateInheritanceOnly
class ClassWithPrivateInheritanceOnly /Abstract/
{
%Docstring
Documentation goes here
Expand Down
2 changes: 1 addition & 1 deletion tests/scripts/sipifyheader.h
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ class CORE_EXPORT QgsSipifyHeader : public QtClass<QVariant>, private Ui::QgsBas
* \ingroup core
* Documentation goes here
*/
class CORE_EXPORT ClassWithPrivateInheritanceOnly : private QgsBaseClass
class CORE_EXPORT ClassWithPrivateInheritanceOnly : private QgsBaseClass SIP_ABSTRACT
{
public:
//! A constructor with definition in header on several lines
Expand Down

0 comments on commit bfb62c4

Please sign in to comment.