@@ -48,11 +48,12 @@ sub processDoxygenLine
48
48
# contexts
49
49
my $SIP_RUN = 0;
50
50
my $HEADER_CODE = 0;
51
- my $ ACCESS = PUBLIC;
51
+ my @ ACCESS = ( PUBLIC) ;
52
52
my $MULTILINE_DEFINITION = 0;
53
53
54
54
my $comment = ' ' ;
55
- my $global_nesting_index = 0;
55
+ my $global_ifdef_nesting_index = 0;
56
+ my @global_bracket_nesting_index = (0);
56
57
my $private_section_line = ' ' ;
57
58
my $classname = ' ' ;
58
59
my $return_type = ' ' ;
@@ -84,15 +85,15 @@ sub dbg_info
84
85
{
85
86
if ($debug == 1){
86
87
push @output , $_ [0]." \n " ;
87
- print $_ [0]." \n " ;
88
+ print $line_idx . " " . @ACCESS . " " . $SIP_RUN . " " . $MULTILINE_DEFINITION . " " . $ _ [0]." \n " ;
88
89
}
89
90
}
90
91
91
92
# main loop
92
93
while ($line_idx < $line_count ){
93
94
$line = $lines [$line_idx ];
94
95
$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 " ;
96
97
97
98
if ($line =~ m / ^\s *SIP_FEATURE\( (\w +) \) (.*)$ / ){
98
99
push @output , dbg(" SF1" )." %Feature $1$2 \n " ;
@@ -138,41 +139,42 @@ sub dbg_info
138
139
139
140
if ( $line =~ m / ^\s *#ifdef SIP_RUN/ ){
140
141
$SIP_RUN = 1;
141
- if ($ACCESS == PRIVATE){
142
+ if ($ACCESS [$#ACCESS ] == PRIVATE){
143
+ dbg_info(" writing private content" );
142
144
push @output , dbg(" PRV1" ).$private_section_line ." \n " ;
143
145
}
144
146
next ;
145
147
}
146
148
if ( $SIP_RUN == 1 ){
147
149
if ( $line =~ m / ^\s *#endif/ ){
148
- if ( $global_nesting_index == 0 ){
150
+ if ( $global_ifdef_nesting_index == 0 ){
149
151
$SIP_RUN = 0;
150
152
next ;
151
153
}
152
154
else {
153
- $global_nesting_index --;
155
+ $global_ifdef_nesting_index --;
154
156
}
155
157
}
156
158
if ( $line =~ m / ^\s *#if(def)?\s +/ ){
157
- $global_nesting_index ++;
159
+ $global_ifdef_nesting_index ++;
158
160
}
159
161
160
162
# 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){
162
164
while ($line_idx < $line_count ){
163
165
$line = $lines [$line_idx ];
164
166
$line_idx ++;
165
167
if ( $line =~ m / ^\s *#if(def)?\s +/ ){
166
- $global_nesting_index ++;
168
+ $global_ifdef_nesting_index ++;
167
169
}
168
170
elsif ( $line =~ m / ^\s *#endif/ ){
169
- if ( $global_nesting_index == 0 ){
171
+ if ( $global_ifdef_nesting_index == 0 ){
170
172
$comment = ' ' ;
171
173
$SIP_RUN = 0;
172
174
last ;
173
175
}
174
176
else {
175
- $global_nesting_index --;
177
+ $global_ifdef_nesting_index --;
176
178
}
177
179
}
178
180
}
@@ -185,24 +187,25 @@ sub dbg_info
185
187
$line = $lines [$line_idx ];
186
188
$line_idx ++;
187
189
if ( $line =~ m / ^\s *#if(def)?\s +/ ){
188
- $global_nesting_index ++;
190
+ $global_ifdef_nesting_index ++;
189
191
}
190
- elsif ( $line =~ m / ^\s *#else/ && $global_nesting_index == 0 ){
192
+ elsif ( $line =~ m / ^\s *#else/ && $global_ifdef_nesting_index == 0 ){
191
193
# code here will be printed out
192
- if ($ACCESS == PRIVATE){
194
+ if ($ACCESS [$#ACCESS ] == PRIVATE){
195
+ dbg_info(" writing private content" );
193
196
push @output , dbg(" PRV2" ).$private_section_line ." \n " ;
194
197
}
195
198
$SIP_RUN = 1;
196
199
last ;
197
200
}
198
201
elsif ( $line =~ m / ^\s *#endif/ ){
199
- if ( $global_nesting_index == 0 ){
202
+ if ( $global_ifdef_nesting_index == 0 ){
200
203
$comment = ' ' ;
201
204
$SIP_RUN = 0;
202
205
last ;
203
206
}
204
207
else {
205
- $global_nesting_index --;
208
+ $global_ifdef_nesting_index --;
206
209
}
207
210
}
208
211
}
@@ -272,54 +275,76 @@ sub dbg_info
272
275
next ;
273
276
}
274
277
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
+
275
319
# Private members (exclude SIP_RUN)
276
320
if ( $line =~ m / ^\s *private( slots)?:/ ){
277
- $ACCESS = PRIVATE;
321
+ $ACCESS [ $#ACCESS ] = PRIVATE;
278
322
$private_section_line = $line ;
279
323
$comment = ' ' ;
324
+ dbg_info(" going private" );
280
325
next ;
281
326
}
282
327
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;
288
330
$comment = ' ' ;
289
331
}
290
332
elsif ( $line =~ m / ^\s *(protected)( slots)?:.*$ / ){
291
- $ACCESS = PROTECTED;
333
+ dbg_info(" going protected" );
334
+ $ACCESS [$#ACCESS ] = PROTECTED;
292
335
$comment = ' ' ;
293
336
}
294
- elsif ( $ACCESS == PRIVATE && $line =~ m / SIP_FORCE/ ){
337
+ elsif ( $ACCESS [$#ACCESS ] == PRIVATE && $line =~ m / SIP_FORCE/ ){
338
+ dbg_info(" private with SIP_FORCE" );
295
339
push @output , dbg(" PRV3" ).$private_section_line ." \n " ;
296
340
}
297
- elsif ( $ACCESS == PRIVATE && $SIP_RUN == 0 ) {
298
- $comment = ' ' ;
299
- next ;
341
+ elsif ( $ACCESS [ $#ACCESS ] == PRIVATE && $SIP_RUN == 0 ) {
342
+ $comment = ' ' ;
343
+ next ;
300
344
}
301
345
# Skip operators
302
346
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" );
323
348
next ;
324
349
}
325
350
@@ -334,11 +359,16 @@ sub dbg_info
334
359
}
335
360
336
361
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;
338
365
}
339
366
340
367
# class declaration started
341
368
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;
342
372
do {no warnings ' uninitialized' ;
343
373
$classname = $3 ;
344
374
$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
368
398
my $skip = $lines [$line_idx ];
369
399
$line_idx ++;
370
400
$skip =~ m / ^\s *{\s *$ / || die " Unexpected content on line $skip " ;
401
+ $global_bracket_nesting_index [$#global_bracket_nesting_index ]++;
371
402
372
403
$comment = ' ' ;
373
404
$HEADER_CODE = 1;
374
- $ACCESS = PRIVATE;
405
+ $ACCESS [ $#ACCESS ] = PRIVATE;
375
406
next ;
376
407
}
377
408
@@ -406,13 +437,13 @@ sub dbg_info
406
437
}
407
438
408
439
# 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 +(\( [^()]+\) )?)?;/ ){
410
441
dbg_info(" skip non-method member declaration in non-public sections" );
411
442
next ;
412
443
}
413
444
414
445
# 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 +(\( [^()]+\) )?;/ ){
416
447
dbg_info(" remove struct member assignment" );
417
448
$line = " $1 ;" ;
418
449
}
@@ -479,6 +510,7 @@ sub dbg_info
479
510
my $nesting_index = 1;
480
511
if ( $line =~ m / ^\s *\{ $ / ){
481
512
while ($line_idx < $line_count ){
513
+ dbg_info(" remove body" );
482
514
$line = $lines [$line_idx ];
483
515
$line_idx ++;
484
516
$nesting_index += $line =~ tr / \{// ;
0 commit comments