@@ -897,14 +897,16 @@ sub detect_non_method_member{
897
897
}
898
898
899
899
# class declaration started
900
- # https://regex101.com/r/6FWntP/16
901
- if ( $LINE =~ m / ^(\s *(class))\s +([A-Z0-9_]+_EXPORT\s +)?(Q_DECL_DEPRECATED\s +)?(?<classname>\w +)(?<domain>\s *\:\s *(public|protected|private)\s +\w +(< *(\w |::)+ *>)?(::\w +(<\w + >)?)*(,\s *(public|protected|private)\s +\w +(< *(\w |::)+ *>)?(::\w +(<\w +>)?)*)*)?(?<annot>\s *\/ ?\/ ?\s *SIP_\w +)?\s *?(\/\/ .*|(?!;))$ / ){
900
+ # https://regex101.com/r/KMQdF5/1 (older versions: https://regex101.com/r/ 6FWntP/16)
901
+ if ( $LINE =~ m / ^(\s *(class))\s +([A-Z0-9_]+_EXPORT\s +)?(Q_DECL_DEPRECATED\s +)?(?<classname>\w +)(?<domain>\s *\:\s *(public|protected|private)\s +\w +(< *(\w |::)+ *(, *( \w |::)+ *)* >)?(::\w +(<( \w |::)+(, *( \w |::)+)* >)?)*(,\s *(public|protected|private)\s +\w +(< *(\w |::)+ *(, *( \w |::)+)* >)?(::\w +(<\w +(, *( \w |::)+)? >)?)*)*)?(?<annot>\s *\/ ?\/ ?\s *SIP_\w +)?\s *?(\/\/ .*|(?!;))$ / ){
902
902
dbg_info(" class definition started" );
903
903
push @ACCESS , PUBLIC;
904
904
push @EXPORTED , 0;
905
905
push @GLOB_BRACKET_NESTING_IDX , 0;
906
906
my @template_inheritance_template = ();
907
- my @template_inheritance_class = ();
907
+ my @template_inheritance_class1 = ();
908
+ my @template_inheritance_class2 = ();
909
+ my @template_inheritance_class3 = ();
908
910
do {no warnings ' uninitialized' ;
909
911
push @CLASSNAME , $+ {classname };
910
912
if ($#CLASSNAME == 0){
@@ -927,14 +929,23 @@ sub detect_non_method_member{
927
929
$m =~ s / public +(\w +, *)*(Ui::\w +,? *)+// g ; # remove Ui::xxx public inheritance as the namespace is causing troubles
928
930
$m =~ s / public +// g ;
929
931
$m =~ s / [,:]?\s *private +\w +(::\w +)?// g ;
932
+
930
933
# detect template based inheritance
931
- while ($m =~ / [,:]\s +((?!QList)\w +)< *((\w |::)+) *>/g ){
934
+ # https://regex101.com/r/9LGhyy/1
935
+ while ($m =~ / [,:]\s +(?<tpl>(?!QList)\w +)< *(?<cls1>(\w |::)+) *(, *(?<cls2>(\w |::)+)? *(, *(?<cls3>(\w |::)+)? *)?)? *>/g ){
932
936
dbg_info(" template class" );
933
- push @template_inheritance_template , $1 ;
934
- push @template_inheritance_class , $2 ;
937
+ push @template_inheritance_template , $+ {tpl };
938
+ push @template_inheritance_class1 , $+ {cls1 };
939
+ push @template_inheritance_class2 , $+ {cls2 } // " " ;
940
+ push @template_inheritance_class3 , $+ {cls3 } // " " ;
941
+ # dbg_info("template classes (max 3): $+{cls1} $+{cls2} $+{cls3}");
935
942
}
936
- $m =~ s / (\b (?!QList)\w +)< *((?:\w |::)+) *>/ $1 ${2}Base/ g ; # use the typeded as template inheritance
937
- $m =~ s / (\w +)< *((?:\w |::)+) *>// g ; # remove remaining templates
943
+ dbg_info(" domain: $m " );
944
+ do {no warnings ' uninitialized' ;
945
+ # https://regex101.com/r/nOLg2r/1
946
+ $m =~ s /\b (?<tpl>(?!QList)\w +)< *(?<cls1>(\w |::)+) *(, *(?<cls2>(\w |::)+)? *(, *(?<cls3>(\w |::)+)? *)?)? *>/ $+ {tpl}$+ {cls1}$+ {cls2}$+ {cls3}Base/ g ; # use the typeded as template inheritance
947
+ };
948
+ $m =~ s / (\w +)< *(?:\w |::)+ *>// g ; # remove remaining templates
938
949
$m =~ s / ([:,])\s *,/ $1 / g ;
939
950
$m =~ s / (\s *[:,])?\s *$// ;
940
951
$LINE .= $m ;
@@ -956,16 +967,30 @@ sub detect_non_method_member{
956
967
# see https://www.riverbankcomputing.com/pipermail/pyqt/2015-May/035893.html
957
968
while ( @template_inheritance_template ) {
958
969
my $tpl = pop @template_inheritance_template ;
959
- my $cls = pop @template_inheritance_class ;
960
- $LINE = " \n typedef $tpl <$cls > ${tpl}${cls} Base;\n\n $LINE " ;
970
+ my $cls1 = pop @template_inheritance_class1 ;
971
+ my $cls2 = pop @template_inheritance_class2 ;
972
+ my $cls3 = pop @template_inheritance_class3 ;
973
+ if ( $cls2 eq " " ){
974
+ $LINE = " \n typedef $tpl <$cls1 > ${tpl}${cls1} Base;\n\n $LINE " ;
975
+ } elsif ( $cls3 eq " " ){
976
+ $LINE = " \n typedef $tpl <$cls1 ,$cls2 > ${tpl}${cls1}${cls2} Base;\n\n $LINE " ;
977
+ } else {
978
+ $LINE = " \n typedef $tpl <$cls1 ,$cls2 ,$cls3 > ${tpl}${cls1}${cls2}${cls3} Base;\n\n $LINE " ;
979
+ }
961
980
if ( not $tpl ~~ @DECLARED_CLASSES ){
962
981
my $tpl_header = lc $tpl . " .h" ;
963
982
if ( exists $SIP_CONFIG -> {class_headerfile }-> {$tpl } ){
964
983
$tpl_header = $SIP_CONFIG -> {class_headerfile }-> {$tpl };
965
984
}
966
985
$LINE .= " \n #include \" " . $tpl_header . " \" " ;
967
986
}
968
- $LINE .= " \n typedef $tpl <$cls > ${tpl}${cls} Base;" ;
987
+ if ( $cls2 eq " " ){
988
+ $LINE .= " \n typedef $tpl <$cls1 > ${tpl}${cls1} Base;" ;
989
+ } elsif ( $cls3 eq " " ){
990
+ $LINE .= " \n typedef $tpl <$cls1 ,$cls2 > ${tpl}${cls1}${cls2} Base;" ;
991
+ } else {
992
+ $LINE .= " \n typedef $tpl <$cls1 ,$cls2 ,$cls3 > ${tpl}${cls1}${cls2}${cls3} Base;" ;
993
+ }
969
994
}
970
995
if ( PRIVATE ~~ @ACCESS && $#ACCESS != 0){
971
996
# do not write anything in PRIVATE context and not top level
@@ -1194,6 +1219,9 @@ sub detect_non_method_member{
1194
1219
# keyword fixes
1195
1220
do {no warnings ' uninitialized' ;
1196
1221
$LINE =~ s / ^(\s *template\s *<)(?:class|typename) (\w +>)(.*)$/ $1$2$3 / ;
1222
+ $LINE =~ s / ^(\s *template\s *<)(?:class|typename) (\w +) *, *(?:class|typename) (\w +>)(.*)$/ $1$2 ,$3$4 / ;
1223
+ # https://regex101.com/r/EB1mpx/1
1224
+ $LINE =~ s / ^(\s *template\s *<)(?:class|typename) (\w +) *, *(?:class|typename) (\w +) *, *(?:class|typename) (\w +>)(.*)$/ $1$2 ,$3 ,$4$5 / ;
1197
1225
$LINE =~ s /\s *\b override\b // ;
1198
1226
$LINE =~ s /\s *\b SIP_MAKE_PRIVATE\b // ;
1199
1227
$LINE =~ s /\s *\b FINAL\b / \$ {SIP_FINAL}/ ;
0 commit comments