38
38
my $HEADER_CODE = 0;
39
39
my @ACCESS = (PUBLIC);
40
40
my @CLASSNAME = ();
41
+ my @DECLARED_CLASSES = ();
41
42
my @EXPORTED = (0);
42
43
my $MULTILINE_DEFINITION = MULTILINE_NO;
43
44
my $ACTUAL_CLASS = ' ' ;
@@ -487,8 +488,8 @@ sub detect_comment_block{
487
488
}
488
489
489
490
# class declaration started
490
- # https://regex101.com/r/6FWntP/8
491
- if ( $LINE =~ m / ^(\s *class)\s +([A-Z]+_EXPORT\s +)?(\w +)(\s *\:\s *(public|protected|private)\s +\w +(<([ \w ] |::)+>)?(::\w +(<\w +>)?)*(,\s *(public|protected|private)\s +\w +(<([ \w ] |::)+>)?(::\w +(<\w +>)?)*)*)?(?<annot>\s *SIP_\w +)?\s *?(\/\/ .*|(?!;))$ / ){
491
+ # https://regex101.com/r/6FWntP/10
492
+ if ( $LINE =~ m / ^(\s *class)\s +([A-Z]+_EXPORT\s +)?(\w +)(\s *\:\s *(public|protected|private)\s +\w +(< *( \w |::)+ * >)?(::\w +(<\w +>)?)*(,\s *(public|protected|private)\s +\w +(< *( \w |::)+ * >)?(::\w +(<\w +>)?)*)*)?(?<annot>\s *SIP_\w +)?\s *?(\/\/ .*|(?!;))$ / ){
492
493
dbg_info(" class definition started" );
493
494
push @ACCESS , PUBLIC;
494
495
push @EXPORTED , 0;
@@ -497,7 +498,14 @@ sub detect_comment_block{
497
498
my @template_inheritance_class = ();
498
499
do {no warnings ' uninitialized' ;
499
500
push @CLASSNAME , $3 ;
500
- dbg_info(" class: " .$CLASSNAME [$#CLASSNAME ]);
501
+ if ($#CLASSNAME == 0){
502
+ dbg_info(' www' );
503
+ # might be worth to add in-class classes later on
504
+ # in case of a tamplate based class declaration
505
+ # based on an in-class and in the same file
506
+ push @DECLARED_CLASSES , $CLASSNAME [$#CLASSNAME ];
507
+ }
508
+ dbg_info(" class: " .$CLASSNAME [$#CLASSNAME ].$#CLASSNAME );
501
509
if ($LINE =~ m /\b [A-Z] +_EXPORT\b / || $#CLASSNAME != 0 || $INPUT_LINES [$LINE_IDX -2] =~ m / ^\s *template</ ){
502
510
# class should be exported except those not at top level or template classes
503
511
# if class is not exported, then its methods should be (checked whenever leaving out the class)
@@ -512,13 +520,13 @@ sub detect_comment_block{
512
520
$m =~ s / public +// g ;
513
521
$m =~ s / [,:]?\s *private +\w +(::\w +)?// g ;
514
522
# detect template based inheritance
515
- while ($m =~ / [,:]\s +((?!QList)\w +)<((\w |::)+)>/g ){
523
+ while ($m =~ / [,:]\s +((?!QList)\w +)< * ((\w |::)+) * >/g ){
516
524
dbg_info(" template class" );
517
525
push @template_inheritance_template , $1 ;
518
526
push @template_inheritance_class , $2 ;
519
527
}
520
- $m =~ s / (\b (?!QList)\w +)<((?:\w |::)+)>/ $1 ${2}Base/ g ; # use the typeded as template inheritance
521
- $m =~ s / (\w +)<((?:\w |::)+)>// g ; # remove remaining templates
528
+ $m =~ s / (\b (?!QList)\w +)<((?:[ \w ] |::)+)>/ $1 ${2}Base/ g ; # use the typeded as template inheritance
529
+ $m =~ s / (\w +)<((?:[ \w ] |::)+)>// g ; # remove remaining templates
522
530
$m =~ s / ([:,])\s *,/ $1 / g ;
523
531
$m =~ s / (\s *[:,])?\s *$// ;
524
532
$LINE .= $m ;
@@ -538,15 +546,17 @@ sub detect_comment_block{
538
546
# add it to the class and to the TypeHeaderCode
539
547
# also include the template header
540
548
# see https://www.riverbankcomputing.com/pipermail/pyqt/2015-May/035893.html
541
- while (@template_inheritance_template ) {
549
+ while ( @template_inheritance_template ) {
542
550
my $tpl = pop @template_inheritance_template ;
543
551
my $cls = pop @template_inheritance_class ;
544
- my $tpl_header = lc $tpl . " .h" ;
545
- if (exists $SIP_CONFIG -> {class_headerfile }-> {$tpl }){
546
- $tpl_header = $SIP_CONFIG -> {class_headerfile }-> {$tpl };
547
- }
548
552
$LINE = " \n typedef $tpl <$cls > ${tpl}${cls} Base;\n\n $LINE " ;
549
- $LINE .= " \n #include \" " . $tpl_header . " \" " ;
553
+ if ( not $tpl ~~ @DECLARED_CLASSES ){
554
+ my $tpl_header = lc $tpl . " .h" ;
555
+ if ( exists $SIP_CONFIG -> {class_headerfile }-> {$tpl } ){
556
+ $tpl_header = $SIP_CONFIG -> {class_headerfile }-> {$tpl };
557
+ }
558
+ $LINE .= " \n #include \" " . $tpl_header . " \" " ;
559
+ }
550
560
$LINE .= " \n typedef $tpl <$cls > ${tpl}${cls} Base;" ;
551
561
}
552
562
if ( PRIVATE ~~ @ACCESS && $#ACCESS != 0){
0 commit comments