Skip to content

Commit f20b9b9

Browse files
committed
[sipify] better remove body, remove duplicate code
1 parent c2b1272 commit f20b9b9

File tree

5 files changed

+58
-76
lines changed

5 files changed

+58
-76
lines changed

python/core/geometry/qgsgeometry.sip

+2-3
Original file line numberDiff line numberDiff line change
@@ -904,11 +904,10 @@ Returns an extruded version of this geometry.
904904
:rtype: QgsGeometry
905905
%End
906906

907+
907908
QgsPoint asPoint() const;
908909
%Docstring
909-
Accessor functions for getting geometry data */
910-
911-
/** Return contents of the geometry as a point
910+
Return contents of the geometry as a point
912911
if wkbType is WKBPoint, otherwise returns [0,0]
913912
:rtype: QgsPoint
914913
%End

python/core/geometry/qgswkbptr.sip

-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ class QgsConstWkbPtr
4545

4646

4747

48-
4948
};
5049

5150
/************************************************************************

python/core/qgsdataprovider.sip

-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414

1515

16-
1716
class QgsDataProvider : QObject
1817
{
1918
%Docstring
@@ -354,7 +353,6 @@ Current time stamp of data source
354353
.. versionadded:: 2.16
355354
%End
356355

357-
358356
QVariant providerProperty( ProviderProperty property, const QVariant &defaultValue = QVariant() ) const;
359357
%Docstring
360358
Get the current value of a certain provider property.
@@ -364,7 +362,6 @@ Current time stamp of data source
364362
:rtype: QVariant
365363
%End
366364

367-
368365
signals:
369366

370367
void fullExtentCalculated();

python/core/qgspropertytransformer.sip

+1-1
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ class QgsPropertyTransformer
149149
%TypeHeaderCode
150150
#include "qgspropertytransformer.h"
151151
%End
152-
private:
152+
153153
%ConvertToSubClassCode
154154
if ( sipCpp->transformerType() == QgsPropertyTransformer::GenericNumericTransformer )
155155
sipType = sipType_QgsGenericNumericTransformer;

scripts/sipify.pl

+55-68
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ sub processDoxygenLine
7878
sub dbg
7979
{
8080
my $msg = '';
81-
$debug == 0 or $msg = sprintf("%-4s %-1d %-1d ", $_[0], $SIP_RUN, $MULTILINE_DEFINITION);
81+
$debug == 0 or $msg = sprintf("%d %-4s %-1d %-1d ", $line_idx, $_[0], $SIP_RUN, $MULTILINE_DEFINITION);
8282
return $msg;
8383
}
8484
sub dbg_info
@@ -89,6 +89,42 @@ sub dbg_info
8989
}
9090
}
9191

92+
sub remove_constructor_or_body {
93+
# https://regex101.com/r/ZaP3tC/1
94+
do {no warnings 'uninitialized';
95+
if ( $line =~ m/^(\s*)?(explicit )?(virtual )?(static |const )*(([\w:]+(<.*?>)?\s+(\*|&)?)?(~?\w+|operator.{1,2})\(([\w=()\/ ,&*<>-]|::)*\)( (?:const|SIP_[A-Z_]*?))*)\s*((\s*[:,]\s+\w+\(.*\))*\s*\{.*\};?|(?!;))(\s*\/\/.*)?$/
96+
|| $line =~ m/SIP_SKIP\s*(?!;)\s*(\/\/.*)?$/ ){
97+
dbg_info("remove constructor definition, function bodies, member initializing list");
98+
my $newline = "$1$2$3$4$5;";
99+
if ($line !~ m/{.*}(\s*SIP_\w+)?\s*(\/\/.*)?$/){
100+
dbg_info(" go for multiline");
101+
$line = $lines[$line_idx];
102+
$line_idx++;
103+
while ( $line =~ m/^\s*[:,]\s+[\w<>]+\(.*?\)/){
104+
dbg_info(" member initializing list");
105+
$line = $lines[$line_idx];
106+
$line_idx++;
107+
}
108+
if ( $line =~ m/^\s*\{/ ){
109+
my $nesting_index = 0;
110+
while ($line_idx < $line_count){
111+
dbg_info(" remove body");
112+
$nesting_index += $line =~ tr/\{//;
113+
$nesting_index -= $line =~ tr/\}//;
114+
if ($nesting_index == 0){
115+
last;
116+
}
117+
$line = $lines[$line_idx];
118+
$line_idx++;
119+
}
120+
}
121+
}
122+
$line = $newline;
123+
}
124+
};
125+
}
126+
127+
92128
# main loop
93129
while ($line_idx < $line_count){
94130
$line = $lines[$line_idx];
@@ -233,46 +269,23 @@ sub dbg_info
233269

234270
# SIP_SKIP
235271
if ( $line =~ m/SIP_SKIP/ ){
236-
$comment = '';
237-
# if multiline definition, remove previous lines
238-
if ( $MULTILINE_DEFINITION == 1){
239-
my $opening_line = '';
240-
while ( $opening_line !~ m/^[^()]*\(([^()]*\([^()]*\)[^()]*)*[^()]*$/){
241-
$opening_line = pop(@output);
242-
$#output >= 0 or die 'could not reach opening definition';
243-
}
272+
dbg_info('SIP SKIP!');
273+
$comment = '';
274+
# if multiline definition, remove previous lines
275+
if ( $MULTILINE_DEFINITION == 1){
276+
dbg_info('SIP_SKIP with MultiLine');
277+
my $opening_line = '';
278+
while ( $opening_line !~ m/^[^()]*\(([^()]*\([^()]*\)[^()]*)*[^()]*$/){
279+
$opening_line = pop(@output);
280+
$#output >= 0 or die 'could not reach opening definition';
281+
}
244282
dbg_info("removed multiline definition of SIP_SKIP method");
245283
$MULTILINE_DEFINITION = 0;
246-
}
247-
# also skip method body if there is one
248-
if ($lines[$line_idx] =~ m/^\s*\{/){
249-
my $nesting_index = 0;
250-
dbg_info("skipping method body of SIP_SKIP method");
251-
while ($line_idx < $line_count){
252-
$line = $lines[$line_idx];
253-
$line_idx++;
254-
if ( $nesting_index == 0 ){
255-
if ( $line =~ m/^\s*(:|,)/ ){
256-
next;
257-
}
258-
$line =~ m/^\s*\{/ or die 'Constructor definition misses {';
259-
if ( $line =~ m/^\s*\{.*?\}/ ){
260-
last;
261-
}
262-
$nesting_index = 1;
263-
next;
264-
}
265-
else {
266-
$nesting_index += $line =~ tr/\{//;
267-
$nesting_index -= $line =~ tr/\}//;
268-
if ($nesting_index eq 0){
269-
last;
270-
}
271-
}
272284
}
273-
}
274-
# line skipped, go to next iteration
275-
next;
285+
# also skip method body if there is one
286+
remove_constructor_or_body();
287+
# line skipped, go to next iteration
288+
next;
276289
}
277290

278291
# Detect comment block
@@ -305,12 +318,14 @@ sub dbg_info
305318
pop(@global_bracket_nesting_index);
306319
pop(@ACCESS);
307320
}
308-
else{
321+
if ($#ACCESS == 1){
322+
dbg_info("reached top level");
309323
# top level should stasy public
310324
dbg_info
311325
$ACCESS[$#ACCESS] = PUBLIC;
312326
$comment = '';
313327
}
328+
$private_section_line = '';
314329
}
315330
dbg_info("new bracket balance: @global_bracket_nesting_index");
316331
}
@@ -495,35 +510,7 @@ sub dbg_info
495510
$line =~ s/\s*=\s*default\b//g;
496511

497512
# remove constructor definition, function bodies, member initializing list
498-
# https://regex101.com/r/ZaP3tC/1
499-
if ( $SIP_RUN != 1 && $line =~ m/^(\s*)?(explicit )?(virtual )?(static |const )*(([\w:]+(<.*?>)?\s+(\*|&)?)?(~?\w+|operator.{1,2})\(([\w=()\/ ,&*<>-]|::)*\)( (?:const|SIP_[A-Z_]*?))*)\s*((\s*[:,]\s+\w+\(.*\))*\s*\{.*\};?|(?!;))(\s*\/\/.*)?$/ ){
500-
dbg_info("remove constructor definition, function bodies, member initializing list");
501-
my $newline = "$1$2$3$4$5;";
502-
if ($line !~ m/\{.*?\}\s*(\/\/.*)?$/){
503-
dbg_info(" go for multiline");
504-
$line = $lines[$line_idx];
505-
$line_idx++;
506-
while ( $line =~ m/^\s*[:,]\s+[\w<>]+\(.*?\)/){
507-
dbg_info(" member initializing list");
508-
$line = $lines[$line_idx];
509-
$line_idx++;
510-
}
511-
my $nesting_index = 1;
512-
if ( $line =~ m/^\s*\{$/ ){
513-
while ($line_idx < $line_count){
514-
dbg_info(" remove body");
515-
$line = $lines[$line_idx];
516-
$line_idx++;
517-
$nesting_index += $line =~ tr/\{//;
518-
$nesting_index -= $line =~ tr/\}//;
519-
if ($nesting_index == 0){
520-
last;
521-
}
522-
}
523-
}
524-
}
525-
$line = $newline;
526-
}
513+
$SIP_RUN == 1 or remove_constructor_or_body();
527514

528515
# remove inline declarations
529516
if ( $line =~ m/^(\s*)?(static |const )*(([\w:]+(<.*?>)?\s+(\*|&)?)?(\w+)( (?:const*?))*)\s*(\{.*\});(\s*\/\/.*)?$/ ){

0 commit comments

Comments
 (0)