@@ -127,6 +127,54 @@ sub remove_constructor_or_body {
127
127
};
128
128
}
129
129
130
+ sub fix_annotations (){
131
+ # printed annotations
132
+ $line =~ s /\b SIP_ABSTRACT\b / \/ Abstract\/ / ;
133
+ $line =~ s /\b SIP_ARRAY\b / \/ Array\/ / ;
134
+ $line =~ s /\b SIP_ARRAYSIZE\b / \/ ArraySize\/ / ;
135
+ $line =~ s /\b SIP_FACTORY\b / \/ Factory\/ / ;
136
+ $line =~ s /\b SIP_IN\b / \/ In\/ / g ;
137
+ $line =~ s /\b SIP_INOUT\b / \/ In,Out\/ / g ;
138
+ $line =~ s /\b SIP_KEEPREFERENCE\b / \/ KeepReference\/ / ;
139
+ $line =~ s /\b SIP_OUT\b / \/ Out\/ / g ;
140
+ $line =~ s /\b SIP_RELEASEGIL\b / \/ ReleaseGIL\/ / ;
141
+ $line =~ s /\b SIP_TRANSFER\b / \/ Transfer\/ / g ;
142
+ $line =~ s /\b SIP_TRANSFERBACK\b / \/ TransferBack\/ / ;
143
+ $line =~ s /\b SIP_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
+
130
178
131
179
# main loop
132
180
while ($line_idx < $line_count ){
@@ -388,7 +436,8 @@ sub remove_constructor_or_body {
388
436
}
389
437
390
438
# 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_.*)?$ / ){
392
441
dbg_info(" class definition started => private" );
393
442
push @ACCESS , PRIVATE;
394
443
push @global_bracket_nesting_index , 0;
@@ -401,12 +450,14 @@ sub remove_constructor_or_body {
401
450
if ($4 ){
402
451
my $m = $4 ;
403
452
$m =~ s / public // g ;
404
- $m =~ s /, ?\s *private \w +(::\w +)?// ;
453
+ $m =~ s /[,:] ?\s *private \w +(::\w +)?// ;
405
454
$m =~ s / (\s *:)?\s *$// ;
406
455
$line .= $m ;
407
456
}
408
- if ($5 ) {
409
- $line .= ' /Abstract/' ;
457
+ if (defined $+ {annot })
458
+ {
459
+ $line .= " $+ {annot}" ;
460
+ fix_annotations();
410
461
}
411
462
412
463
$line .= " \n {\n " ;
@@ -559,49 +610,7 @@ sub remove_constructor_or_body {
559
610
# remove export macro from struct definition
560
611
$line =~ s / ^(\s *struct )\w +_EXPORT (.+)$/ $1$2 / ;
561
612
562
- # printed annotations
563
- $line =~ s /\b SIP_FACTORY\b / \/ Factory\/ / ;
564
- $line =~ s /\b SIP_OUT\b / \/ Out\/ / g ;
565
- $line =~ s /\b SIP_IN\b / \/ In\/ / g ;
566
- $line =~ s /\b SIP_INOUT\b / \/ In,Out\/ / g ;
567
- $line =~ s /\b SIP_TRANSFER\b / \/ Transfer\/ / g ;
568
- $line =~ s /\b SIP_KEEPREFERENCE\b / \/ KeepReference\/ / ;
569
- $line =~ s /\b SIP_TRANSFERTHIS\b / \/ TransferThis\/ / ;
570
- $line =~ s /\b SIP_TRANSFERBACK\b / \/ TransferBack\/ / ;
571
- $line =~ s /\b SIP_RELEASEGIL\b / \/ ReleaseGIL\/ / ;
572
- $line =~ s /\b SIP_ARRAY\b / \/ Array\/ / ;
573
- $line =~ s /\b SIP_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();
605
614
606
615
# fix astyle placing space after % character
607
616
$line =~ s /\s *% (MappedType|TypeCode|TypeHeaderCode|ModuleHeaderCode|ConvertFromTypeCode|ConvertToTypeCode|MethodCode|End)/ %$1 / ;
0 commit comments