3838my $HEADER_CODE = 0;
3939my @ACCESS = (PUBLIC);
4040my @CLASSNAME = ();
41+ my @DECLARED_CLASSES = ();
4142my @EXPORTED = (0);
4243my $MULTILINE_DEFINITION = MULTILINE_NO;
4344my $ACTUAL_CLASS = ' ' ;
@@ -487,8 +488,8 @@ sub detect_comment_block{
487488 }
488489
489490 # 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 *?(\/\/ .*|(?!;))$ / ){
492493 dbg_info(" class definition started" );
493494 push @ACCESS , PUBLIC;
494495 push @EXPORTED , 0;
@@ -497,7 +498,14 @@ sub detect_comment_block{
497498 my @template_inheritance_class = ();
498499 do {no warnings ' uninitialized' ;
499500 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 );
501509 if ($LINE =~ m /\b [A-Z] +_EXPORT\b / || $#CLASSNAME != 0 || $INPUT_LINES [$LINE_IDX -2] =~ m / ^\s *template</ ){
502510 # class should be exported except those not at top level or template classes
503511 # if class is not exported, then its methods should be (checked whenever leaving out the class)
@@ -512,13 +520,13 @@ sub detect_comment_block{
512520 $m =~ s / public +// g ;
513521 $m =~ s / [,:]?\s *private +\w +(::\w +)?// g ;
514522 # detect template based inheritance
515- while ($m =~ / [,:]\s +((?!QList)\w +)<((\w |::)+)>/g ){
523+ while ($m =~ / [,:]\s +((?!QList)\w +)< * ((\w |::)+) * >/g ){
516524 dbg_info(" template class" );
517525 push @template_inheritance_template , $1 ;
518526 push @template_inheritance_class , $2 ;
519527 }
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
522530 $m =~ s / ([:,])\s *,/ $1 / g ;
523531 $m =~ s / (\s *[:,])?\s *$// ;
524532 $LINE .= $m ;
@@ -538,15 +546,17 @@ sub detect_comment_block{
538546 # add it to the class and to the TypeHeaderCode
539547 # also include the template header
540548 # see https://www.riverbankcomputing.com/pipermail/pyqt/2015-May/035893.html
541- while (@template_inheritance_template ) {
549+ while ( @template_inheritance_template ) {
542550 my $tpl = pop @template_inheritance_template ;
543551 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- }
548552 $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+ }
550560 $LINE .= " \n typedef $tpl <$cls > ${tpl}${cls} Base;" ;
551561 }
552562 if ( PRIVATE ~~ @ACCESS && $#ACCESS != 0){
0 commit comments