Skip to content

Commit

Permalink
fix script + add test
Browse files Browse the repository at this point in the history
  • Loading branch information
3nids committed Apr 22, 2023
1 parent 53f4889 commit f122f66
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
13 changes: 8 additions & 5 deletions scripts/sipify.pl
Expand Up @@ -897,8 +897,8 @@ sub detect_non_method_member{
}

# class declaration started
# https://regex101.com/r/j4Q66v/1 (older versions: https://regex101.com/r/6FWntP/16)
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*?(\/\/.*|(?!;))$/ ){
# https://regex101.com/r/KMQdF5/1 (older versions: https://regex101.com/r/6FWntP/16)
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*?(\/\/.*|(?!;))$/ ){
dbg_info("class definition started");
push @ACCESS, PUBLIC;
push @EXPORTED, 0;
Expand Down Expand Up @@ -931,18 +931,21 @@ sub detect_non_method_member{
$m =~ s/[,:]?\s*private +\w+(::\w+)?//g;

# detect template based inheritance
# https://regex101.com/r/wHoptq/1
# https://regex101.com/r/9LGhyy/1
while ($m =~ /[,:]\s+(?<tpl>(?!QList)\w+)< *(?<cls1>(\w|::)+) *(, *(?<cls2>(\w|::)+)? *(, *(?<cls3>(\w|::)+)? *)?)? *>/g){
dbg_info("template class");
push @template_inheritance_template, $+{tpl};
push @template_inheritance_class1, $+{cls1};
push @template_inheritance_class2, $+{cls2} // "";
push @template_inheritance_class3, $+{cls3} // "";
dbg_info("template classes (max 3): $+{cls1} $+{cls2} $+{cls3}");
}
dbg_info("domain: $m");
do {no warnings 'uninitialized';
# https://regex101.com/r/wPKbLi/1
$m =~ s/(?<tpl>(?!QList)\w+)< *(?<cls1>(\w|::)+) *(, *(?<cls2>(\w|::)+)? *(, *(?<cls3>(\w|::)+)? *)?)? *>/$+{tpl}$+{cls1}$+{cls2}$+{cls3}Base/g; # use the typeded as template inheritance
# https://regex101.com/r/nOLg2r/1
$m =~ s/\b(?<tpl>(?!QList)\w+)< *(?<cls1>(\w|::)+) *(, *(?<cls2>(\w|::)+)? *(, *(?<cls3>(\w|::)+)? *)?)? *>/$+{tpl}$+{cls1}$+{cls2}$+{cls3}Base/g; # use the typeded as template inheritance
};
$m =~ s/(\w+)< *(?:\w|::)+ *>//g; # remove remaining templates
$m =~ s/([:,])\s*,/$1/g;
$m =~ s/(\s*[:,])?\s*$//;
$LINE .= $m;
Expand Down
7 changes: 7 additions & 0 deletions tests/code_layout/sipify/sipifyheader.expected.sip
Expand Up @@ -439,6 +439,13 @@ class TemplateInheritance4 : SomethingElse1, SomethingElse2
class TemplateInheritance5 : SomethingElse
{

%TypeHeaderCode
#include "sipifyheader.h"
%End
}
class TemplateInheritance6 : SomethingElse, QList<Abc,Def,Ghi>
{

%TypeHeaderCode
#include "sipifyheader.h"
%End
Expand Down
3 changes: 3 additions & 0 deletions tests/code_layout/sipify/sipifyheader.h
Expand Up @@ -523,6 +523,9 @@ class CORE_EXPORT TemplateInheritance4 : public SomethingElse1, public QList<Som
class CORE_EXPORT TemplateInheritance5 : public SomethingElse, public QList<Something>
{
}
class CORE_EXPORT TemplateInheritance6 : public SomethingElse, public QList<Abc,Def,Ghi>
{
}


#endif

0 comments on commit f122f66

Please sign in to comment.