Skip to content

Commit bfb62c4

Browse files
committed
[sipify] fix Abstract class
unblacklist qgstransaction.sip (followup 931bf32) also fix method declaration with private only inheritance
1 parent a88cf7a commit bfb62c4

File tree

5 files changed

+72
-65
lines changed

5 files changed

+72
-65
lines changed

cmake_templates/Doxyfile.in

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2049,26 +2049,25 @@ PREDEFINED =
20492049
# definition found in the source code.
20502050
# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.
20512051

2052-
EXPAND_AS_DEFINED = "SIP_TRANSFER" \
2053-
"SIP_PYNAME" \
2054-
"SIP_OUT" \
2055-
"SIP_INOUT" \
2056-
"SIP_TRANSFERTHIS" \
2057-
"SIP_TRANSFERBACK" \
2058-
"SIP_FACTORY" \
2059-
"SIP_KEEPREFERENCE" \
2052+
EXPAND_AS_DEFINED = "SIP_ABSTRACT" \
20602053
"SIP_ARRAY" \
20612054
"SIP_ARRAYSIZE" \
2062-
"SIP_PYNAME" \
2063-
"SIP_SKIP" \
2064-
"SIP_PYARGDEFAULT" \
2065-
"SIP_PYTYPE" \
2066-
"SIP_PYARGREMOVE" \
20672055
"SIP_CONVERT_TO_SUBCLASS_CODE" \
2056+
"SIP_END" \
2057+
"SIP_FACTORY" \
20682058
"SIP_FEATURE" \
20692059
"SIP_IF_FEATURE" \
2070-
"SIP_END" \
2071-
"SIP_ABSTRACT"
2060+
"SIP_INOUT" \
2061+
"SIP_KEEPREFERENCE" \
2062+
"SIP_OUT" \
2063+
"SIP_PYARGDEFAULT" \
2064+
"SIP_PYARGREMOVE" \
2065+
"SIP_PYNAME" \
2066+
"SIP_PYTYPE" \
2067+
"SIP_SKIP" \
2068+
"SIP_TRANSFER" \
2069+
"SIP_TRANSFERBACK" \
2070+
"SIP_TRANSFERTHIS"
20722071

20732072
# If the SKIP_FUNCTION_MACROS tag is set to YES then doxygen's preprocessor will
20742073
# remove all references to function-like macros that are alone on a line, have

python/auto_sip.blacklist

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ core/qgsfeaturerequest.sip
1313
core/qgsgeometrysimplifier.sip
1414
core/qgsgeometryvalidator.sip
1515
core/qgsmaptopixelgeometrysimplifier.sip
16-
core/qgstransaction.sip
1716
core/qgstransactiongroup.sip
1817
core/qgsdartmeasurement.sip
1918
core/qgsexpressionfieldbuffer.sip

scripts/sipify.pl

Lines changed: 56 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,54 @@ sub remove_constructor_or_body {
127127
};
128128
}
129129

130+
sub fix_annotations(){
131+
# printed annotations
132+
$line =~ s/\bSIP_ABSTRACT\b/\/Abstract\//;
133+
$line =~ s/\bSIP_ARRAY\b/\/Array\//;
134+
$line =~ s/\bSIP_ARRAYSIZE\b/\/ArraySize\//;
135+
$line =~ s/\bSIP_FACTORY\b/\/Factory\//;
136+
$line =~ s/\bSIP_IN\b/\/In\//g;
137+
$line =~ s/\bSIP_INOUT\b/\/In,Out\//g;
138+
$line =~ s/\bSIP_KEEPREFERENCE\b/\/KeepReference\//;
139+
$line =~ s/\bSIP_OUT\b/\/Out\//g;
140+
$line =~ s/\bSIP_RELEASEGIL\b/\/ReleaseGIL\//;
141+
$line =~ s/\bSIP_TRANSFER\b/\/Transfer\//g;
142+
$line =~ s/\bSIP_TRANSFERBACK\b/\/TransferBack\//;
143+
$line =~ s/\bSIP_TRANSFERTHIS\b/\/TransferThis\//;
144+
145+
$line =~ s/SIP_PYNAME\(\s*(\w+)\s*\)/\/PyName=$1\//;
146+
147+
# combine multiple annotations
148+
# https://regex101.com/r/uvCt4M/3
149+
do {no warnings 'uninitialized';
150+
$line =~ s/\/(\w+(=\w+)?)\/\s*\/(\w+(=\w+)?)\//\/$1,$3\//;
151+
(! $3) or dbg_info("combine multiple annotations -- works only for 2");
152+
};
153+
154+
# unprinted annotations
155+
$line =~ s/(\w+)(\<(?>[^<>]|(?2))*\>)?\s+SIP_PYTYPE\(\s*\'?([^()']+)(\(\s*(?:[^()]++|(?2))*\s*\))?\'?\s*\)/$3/g;
156+
$line =~ s/=\s+[^=]*?\s+SIP_PYARGDEFAULT\(\s*\'?([^()']+)(\(\s*(?:[^()]++|(?2))*\s*\))?\'?\s*\)/= $1/g;
157+
# remove argument
158+
if ($line =~ m/SIP_PYARGREMOVE/){
159+
if ( $MULTILINE_DEFINITION == 1 ){
160+
my $prev_line = pop(@output) =~ s/\n$//r;
161+
# update multi line status
162+
my $parenthesis_balance = 0;
163+
$parenthesis_balance += $prev_line =~ tr/\(//;
164+
$parenthesis_balance -= $prev_line =~ tr/\)//;
165+
if ($parenthesis_balance == 1){
166+
$MULTILINE_DEFINITION = 0;
167+
}
168+
# concat with above line to bring previous commas
169+
$line =~ s/^\s+//;
170+
$line = "$prev_line $line\n";
171+
}
172+
# see https://regex101.com/r/5iNptO/4
173+
$line =~ s/(?<coma>, +)?(const )?(\w+)(\<(?>[^<>]|(?4))*\>)? [\w&*]+ SIP_PYARGREMOVE( = [^()]*(\(\s*(?:[^()]++|(?6))*\s*\))?)?(?(<coma>)|,?)//g;
174+
}
175+
$line =~ s/SIP_FORCE//;
176+
}
177+
130178

131179
# main loop
132180
while ($line_idx < $line_count){
@@ -388,7 +436,8 @@ sub remove_constructor_or_body {
388436
}
389437

390438
# class declaration started
391-
if ( $line =~ m/^(\s*class)\s*([A-Z]+_EXPORT)?\s+(\w+)(\s*\:.*)?(\s*SIP_ABSTRACT)?$/ ){
439+
# https://regex101.com/r/6FWntP/2
440+
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_.*)?$/ ){
392441
dbg_info("class definition started => private");
393442
push @ACCESS, PRIVATE;
394443
push @global_bracket_nesting_index, 0;
@@ -401,12 +450,14 @@ sub remove_constructor_or_body {
401450
if ($4){
402451
my $m = $4;
403452
$m =~ s/public //g;
404-
$m =~ s/,?\s*private \w+(::\w+)?//;
453+
$m =~ s/[,:]?\s*private \w+(::\w+)?//;
405454
$m =~ s/(\s*:)?\s*$//;
406455
$line .= $m;
407456
}
408-
if ($5) {
409-
$line .= ' /Abstract/';
457+
if (defined $+{annot})
458+
{
459+
$line .= "$+{annot}";
460+
fix_annotations();
410461
}
411462

412463
$line .= "\n{\n";
@@ -559,49 +610,7 @@ sub remove_constructor_or_body {
559610
# remove export macro from struct definition
560611
$line =~ s/^(\s*struct )\w+_EXPORT (.+)$/$1$2/;
561612

562-
# printed annotations
563-
$line =~ s/\bSIP_FACTORY\b/\/Factory\//;
564-
$line =~ s/\bSIP_OUT\b/\/Out\//g;
565-
$line =~ s/\bSIP_IN\b/\/In\//g;
566-
$line =~ s/\bSIP_INOUT\b/\/In,Out\//g;
567-
$line =~ s/\bSIP_TRANSFER\b/\/Transfer\//g;
568-
$line =~ s/\bSIP_KEEPREFERENCE\b/\/KeepReference\//;
569-
$line =~ s/\bSIP_TRANSFERTHIS\b/\/TransferThis\//;
570-
$line =~ s/\bSIP_TRANSFERBACK\b/\/TransferBack\//;
571-
$line =~ s/\bSIP_RELEASEGIL\b/\/ReleaseGIL\//;
572-
$line =~ s/\bSIP_ARRAY\b/\/Array\//;
573-
$line =~ s/\bSIP_ARRAYSIZE\b/\/ArraySize\//;
574-
$line =~ s/SIP_PYNAME\(\s*(\w+)\s*\)/\/PyName=$1\//;
575-
576-
# combine multiple annotations
577-
# https://regex101.com/r/uvCt4M/3
578-
do {no warnings 'uninitialized';
579-
$line =~ s/\/(\w+(=\w+)?)\/\s*\/(\w+(=\w+)?)\//\/$1,$3\//;
580-
(! $3) or dbg_info("combine multiple annotations -- works only for 2");
581-
};
582-
583-
# unprinted annotations
584-
$line =~ s/(\w+)(\<(?>[^<>]|(?2))*\>)?\s+SIP_PYTYPE\(\s*\'?([^()']+)(\(\s*(?:[^()]++|(?2))*\s*\))?\'?\s*\)/$3/g;
585-
$line =~ s/=\s+[^=]*?\s+SIP_PYARGDEFAULT\(\s*\'?([^()']+)(\(\s*(?:[^()]++|(?2))*\s*\))?\'?\s*\)/= $1/g;
586-
# remove argument
587-
if ($line =~ m/SIP_PYARGREMOVE/){
588-
if ( $MULTILINE_DEFINITION == 1 ){
589-
my $prev_line = pop(@output) =~ s/\n$//r;
590-
# update multi line status
591-
my $parenthesis_balance = 0;
592-
$parenthesis_balance += $prev_line =~ tr/\(//;
593-
$parenthesis_balance -= $prev_line =~ tr/\)//;
594-
if ($parenthesis_balance == 1){
595-
$MULTILINE_DEFINITION = 0;
596-
}
597-
# concat with above line to bring previous commas
598-
$line =~ s/^\s+//;
599-
$line = "$prev_line $line\n";
600-
}
601-
# see https://regex101.com/r/5iNptO/4
602-
$line =~ s/(?<coma>, +)?(const )?(\w+)(\<(?>[^<>]|(?4))*\>)? [\w&*]+ SIP_PYARGREMOVE( = [^()]*(\(\s*(?:[^()]++|(?6))*\s*\))?)?(?(<coma>)|,?)//g;
603-
}
604-
$line =~ s/SIP_FORCE//;
613+
fix_annotations();
605614

606615
# fix astyle placing space after % character
607616
$line =~ s/\s*% (MappedType|TypeCode|TypeHeaderCode|ModuleHeaderCode|ConvertFromTypeCode|ConvertToTypeCode|MethodCode|End)/%$1/;

tests/scripts/sipifyheader.expected.sip

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ remove argument
354354
void ShowThisPrivateOne() ;
355355
};
356356

357-
class ClassWithPrivateInheritanceOnly
357+
class ClassWithPrivateInheritanceOnly /Abstract/
358358
{
359359
%Docstring
360360
Documentation goes here

tests/scripts/sipifyheader.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ class CORE_EXPORT QgsSipifyHeader : public QtClass<QVariant>, private Ui::QgsBas
422422
* \ingroup core
423423
* Documentation goes here
424424
*/
425-
class CORE_EXPORT ClassWithPrivateInheritanceOnly : private QgsBaseClass
425+
class CORE_EXPORT ClassWithPrivateInheritanceOnly : private QgsBaseClass SIP_ABSTRACT
426426
{
427427
public:
428428
//! A constructor with definition in header on several lines

0 commit comments

Comments
 (0)