Skip to content

Commit 39d8724

Browse files
committed
[sipify] fix handling of nested classes
going to proper section when ending a nesting classes (public/private) also improve debugging output
1 parent 92b5265 commit 39d8724

File tree

2 files changed

+90
-61
lines changed

2 files changed

+90
-61
lines changed

python/core/qgsmaplayer.sip

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -177,11 +177,10 @@ Returns the layer's unique ID, which is used to access this layer from QgsProjec
177177
:rtype: str
178178
%End
179179

180+
180181
void setDataUrl( const QString &dataUrl );
181182
%Docstring
182-
Layer dataUrl information */
183-
184-
/** Sets the DataUrl of the layer
183+
Sets the DataUrl of the layer
185184
used by QGIS Server in GetCapabilities request.
186185
DataUrl is a a link to the underlying data represented by a particular layer.
187186
:return: the layer DataUrl
@@ -217,11 +216,10 @@ Returns the layer's unique ID, which is used to access this layer from QgsProjec
217216
:rtype: str
218217
%End
219218

219+
220220
void setAttribution( const QString &attrib );
221221
%Docstring
222-
Layer attribution information */
223-
224-
/** Sets the attribution of the layer
222+
Sets the attribution of the layer
225223
used by QGIS Server in GetCapabilities request.
226224
Attribution indicates the provider of a layer or collection of layers.
227225
:return: the layer attribution
@@ -257,11 +255,10 @@ Returns the layer's unique ID, which is used to access this layer from QgsProjec
257255
:rtype: str
258256
%End
259257

258+
260259
void setMetadataUrl( const QString &metaUrl );
261260
%Docstring
262-
Layer metadataUrl information */
263-
264-
/** Sets the metadata URL of the layer
261+
Sets the metadata URL of the layer
265262
used by QGIS Server in GetCapabilities request.
266263
MetadataUrl is a a link to the detailed, standardized metadata about the data.
267264
:return: the layer metadata URL

scripts/sipify.pl

Lines changed: 84 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,12 @@ sub processDoxygenLine
4848
# contexts
4949
my $SIP_RUN = 0;
5050
my $HEADER_CODE = 0;
51-
my $ACCESS = PUBLIC;
51+
my @ACCESS = (PUBLIC);
5252
my $MULTILINE_DEFINITION = 0;
5353

5454
my $comment = '';
55-
my $global_nesting_index = 0;
55+
my $global_ifdef_nesting_index = 0;
56+
my @global_bracket_nesting_index = (0);
5657
my $private_section_line = '';
5758
my $classname = '';
5859
my $return_type = '';
@@ -84,15 +85,15 @@ sub dbg_info
8485
{
8586
if ($debug == 1){
8687
push @output, $_[0]."\n";
87-
print $_[0]."\n";
88+
print $line_idx." ".@ACCESS." ".$SIP_RUN." ".$MULTILINE_DEFINITION." ".$_[0]."\n";
8889
}
8990
}
9091

9192
# main loop
9293
while ($line_idx < $line_count){
9394
$line = $lines[$line_idx];
9495
$line_idx++;
95-
#print "$line\n";
96+
$debug == 0 or print sprintf('%d DEP:%d ACC:%d BRC:%d SIP:%d MLT:%d ', $line_idx, $#ACCESS, $ACCESS[$#ACCESS], $global_bracket_nesting_index[$#global_bracket_nesting_index], $SIP_RUN, $MULTILINE_DEFINITION).$line."\n";
9697

9798
if ($line =~ m/^\s*SIP_FEATURE\( (\w+) \)(.*)$/){
9899
push @output, dbg("SF1")."%Feature $1$2\n";
@@ -138,41 +139,42 @@ sub dbg_info
138139

139140
if ( $line =~ m/^\s*#ifdef SIP_RUN/){
140141
$SIP_RUN = 1;
141-
if ($ACCESS == PRIVATE){
142+
if ($ACCESS[$#ACCESS] == PRIVATE){
143+
dbg_info("writing private content");
142144
push @output, dbg("PRV1").$private_section_line."\n";
143145
}
144146
next;
145147
}
146148
if ( $SIP_RUN == 1 ){
147149
if ( $line =~ m/^\s*#endif/ ){
148-
if ( $global_nesting_index == 0 ){
150+
if ( $global_ifdef_nesting_index == 0 ){
149151
$SIP_RUN = 0;
150152
next;
151153
}
152154
else {
153-
$global_nesting_index--;
155+
$global_ifdef_nesting_index--;
154156
}
155157
}
156158
if ( $line =~ m/^\s*#if(def)?\s+/ ){
157-
$global_nesting_index++;
159+
$global_ifdef_nesting_index++;
158160
}
159161

160162
# if there is an else at this level, code will be ignored i.e. not SIP_RUN
161-
if ( $line =~ m/^\s*#else/ && $global_nesting_index == 0){
163+
if ( $line =~ m/^\s*#else/ && $global_ifdef_nesting_index == 0){
162164
while ($line_idx < $line_count){
163165
$line = $lines[$line_idx];
164166
$line_idx++;
165167
if ( $line =~ m/^\s*#if(def)?\s+/ ){
166-
$global_nesting_index++;
168+
$global_ifdef_nesting_index++;
167169
}
168170
elsif ( $line =~ m/^\s*#endif/ ){
169-
if ( $global_nesting_index == 0 ){
171+
if ( $global_ifdef_nesting_index == 0 ){
170172
$comment = '';
171173
$SIP_RUN = 0;
172174
last;
173175
}
174176
else {
175-
$global_nesting_index--;
177+
$global_ifdef_nesting_index--;
176178
}
177179
}
178180
}
@@ -185,24 +187,25 @@ sub dbg_info
185187
$line = $lines[$line_idx];
186188
$line_idx++;
187189
if ( $line =~ m/^\s*#if(def)?\s+/ ){
188-
$global_nesting_index++;
190+
$global_ifdef_nesting_index++;
189191
}
190-
elsif ( $line =~ m/^\s*#else/ && $global_nesting_index == 0 ){
192+
elsif ( $line =~ m/^\s*#else/ && $global_ifdef_nesting_index == 0 ){
191193
# code here will be printed out
192-
if ($ACCESS == PRIVATE){
194+
if ($ACCESS[$#ACCESS] == PRIVATE){
195+
dbg_info("writing private content");
193196
push @output, dbg("PRV2").$private_section_line."\n";
194197
}
195198
$SIP_RUN = 1;
196199
last;
197200
}
198201
elsif ( $line =~ m/^\s*#endif/ ){
199-
if ( $global_nesting_index == 0 ){
202+
if ( $global_ifdef_nesting_index == 0 ){
200203
$comment = '';
201204
$SIP_RUN = 0;
202205
last;
203206
}
204207
else {
205-
$global_nesting_index--;
208+
$global_ifdef_nesting_index--;
206209
}
207210
}
208211
}
@@ -272,54 +275,76 @@ sub dbg_info
272275
next;
273276
}
274277

278+
# Detect comment block
279+
if ($line =~ m/^\s*\/\*/){
280+
do {no warnings 'uninitialized';
281+
$comment = processDoxygenLine( $line =~ s/^\s*\/\*(\*)?(.*?)\n?$/$2/r );
282+
};
283+
$comment =~ s/^\s*$//;
284+
#$comment =~ s/^(\s*\n)*(.+)/$2/;
285+
while ($line !~ m/\*\/\s*(\/\/.*?)?$/){
286+
$line = $lines[$line_idx];
287+
$line_idx++;
288+
$comment .= processDoxygenLine( $line =~ s/\s*\*?(.*?)(\/)?\n?$/$1/r );
289+
}
290+
$comment =~ s/\n+$//;
291+
#push @output, dbg("XXX").$comment;
292+
next;
293+
}
294+
295+
# bracket balance in class/struct tree
296+
if ($SIP_RUN == 0){
297+
my $bracket_balance = 0;
298+
$bracket_balance += $line =~ tr/\{//;
299+
$bracket_balance -= $line =~ tr/\}//;
300+
if ($bracket_balance != 0){
301+
$global_bracket_nesting_index[$#global_bracket_nesting_index] += $bracket_balance;
302+
if ($global_bracket_nesting_index[$#global_bracket_nesting_index] == 0){
303+
dbg_info(" going up in class/struct tree");
304+
if ($#ACCESS > 1){
305+
pop(@global_bracket_nesting_index);
306+
pop(@ACCESS);
307+
}
308+
else{
309+
# top level should stasy public
310+
dbg_info
311+
$ACCESS[$#ACCESS] = PUBLIC;
312+
$comment = '';
313+
}
314+
}
315+
dbg_info("new bracket balance: @global_bracket_nesting_index");
316+
}
317+
}
318+
275319
# Private members (exclude SIP_RUN)
276320
if ( $line =~ m/^\s*private( slots)?:/ ){
277-
$ACCESS = PRIVATE;
321+
$ACCESS[$#ACCESS] = PRIVATE;
278322
$private_section_line = $line;
279323
$comment = '';
324+
dbg_info("going private");
280325
next;
281326
}
282327
elsif ( $line =~ m/^\s*(public)( slots)?:.*$/ ){
283-
$ACCESS = PUBLIC;
284-
$comment = '';
285-
}
286-
elsif ( $line =~ m/^\};.*$/ ) {
287-
$ACCESS = PUBLIC;
328+
dbg_info("going public");
329+
$ACCESS[$#ACCESS] = PUBLIC;
288330
$comment = '';
289331
}
290332
elsif ( $line =~ m/^\s*(protected)( slots)?:.*$/ ){
291-
$ACCESS = PROTECTED;
333+
dbg_info("going protected");
334+
$ACCESS[$#ACCESS] = PROTECTED;
292335
$comment = '';
293336
}
294-
elsif ( $ACCESS == PRIVATE && $line =~ m/SIP_FORCE/){
337+
elsif ( $ACCESS[$#ACCESS] == PRIVATE && $line =~ m/SIP_FORCE/){
338+
dbg_info("private with SIP_FORCE");
295339
push @output, dbg("PRV3").$private_section_line."\n";
296340
}
297-
elsif ( $ACCESS == PRIVATE && $SIP_RUN == 0 ) {
298-
$comment = '';
299-
next;
341+
elsif ( $ACCESS[$#ACCESS] == PRIVATE && $SIP_RUN == 0 ) {
342+
$comment = '';
343+
next;
300344
}
301345
# Skip operators
302346
if ( $line =~ m/operator(=|<<|>>)\s*\(/ ){
303-
next;
304-
}
305-
306-
# Detect comment block
307-
if ($line =~ m/^\s*\/\*/){
308-
do {no warnings 'uninitialized';
309-
$comment = processDoxygenLine( $line =~ s/^\s*\/\*(\*)?(.*?)\n?$/$2/r );
310-
};
311-
$comment =~ s/^\s*$//;
312-
#$comment =~ s/^(\s*\n)*(.+)/$2/;
313-
while ($line_idx < $line_count){
314-
$line = $lines[$line_idx];
315-
$line_idx++;
316-
$comment .= processDoxygenLine( $line =~ s/\s*\*?(.*?)(\/)?\n?$/$1/r );
317-
if ( $line =~ m/\*\/\s*(\/\/.*?)?$/ ){
318-
last;
319-
}
320-
}
321-
$comment =~ s/\n+$//;
322-
#push @output, dbg("XXX").$comment;
347+
dbg_info("skip operator");
323348
next;
324349
}
325350

@@ -334,11 +359,16 @@ sub dbg_info
334359
}
335360

336361
if ( $line =~ m/^(\s*struct)\s+(\w+)$/ ) {
337-
$ACCESS = PUBLIC;
362+
dbg_info(" going to struct => public");
363+
push @ACCESS, PUBLIC;
364+
push @global_bracket_nesting_index, 0;
338365
}
339366

340367
# class declaration started
341368
if ( $line =~ m/^(\s*class)\s*([A-Z]+_EXPORT)?\s+(\w+)(\s*\:.*)?(\s*SIP_ABSTRACT)?$/ ){
369+
dbg_info("class definition started => private");
370+
push @ACCESS, PRIVATE;
371+
push @global_bracket_nesting_index, 0;
342372
do {no warnings 'uninitialized';
343373
$classname = $3;
344374
$line =~ m/\b[A-Z]+_EXPORT\b/ or die "Class$classname in $headerfile should be exported with appropriate [LIB]_EXPORT macro. If this should not be available in python, wrap it in a `#ifndef SIP_RUN` block.";
@@ -368,10 +398,11 @@ sub dbg_info
368398
my $skip = $lines[$line_idx];
369399
$line_idx++;
370400
$skip =~ m/^\s*{\s*$/ || die "Unexpected content on line $skip";
401+
$global_bracket_nesting_index[$#global_bracket_nesting_index]++;
371402

372403
$comment = '';
373404
$HEADER_CODE = 1;
374-
$ACCESS = PRIVATE;
405+
$ACCESS[$#ACCESS] = PRIVATE;
375406
next;
376407
}
377408

@@ -406,13 +437,13 @@ sub dbg_info
406437
}
407438

408439
# skip non-method member declaration in non-public sections
409-
if ( $SIP_RUN != 1 && $ACCESS != PUBLIC && $line =~ m/^\s*(?:mutable\s)?\w+[\w<> *&:,]* \*?\w+( = \w+(\([^()]+\))?)?;/){
440+
if ( $SIP_RUN != 1 && $ACCESS[$#ACCESS] != PUBLIC && $line =~ m/^\s*(?:mutable\s)?\w+[\w<> *&:,]* \*?\w+( = \w+(\([^()]+\))?)?;/){
410441
dbg_info("skip non-method member declaration in non-public sections");
411442
next;
412443
}
413444

414445
# remove struct member assignment
415-
if ( $SIP_RUN != 1 && $ACCESS == PUBLIC && $line =~ m/^(\s*\w+[\w<> *&:,]* \*?\w+) = \w+(\([^()]+\))?;/ ){
446+
if ( $SIP_RUN != 1 && $ACCESS[$#ACCESS] == PUBLIC && $line =~ m/^(\s*\w+[\w<> *&:,]* \*?\w+) = \w+(\([^()]+\))?;/ ){
416447
dbg_info("remove struct member assignment");
417448
$line = "$1;";
418449
}
@@ -479,6 +510,7 @@ sub dbg_info
479510
my $nesting_index = 1;
480511
if ( $line =~ m/^\s*\{$/ ){
481512
while ($line_idx < $line_count){
513+
dbg_info(" remove body");
482514
$line = $lines[$line_idx];
483515
$line_idx++;
484516
$nesting_index += $line =~ tr/\{//;

0 commit comments

Comments
 (0)