diff --git a/cmake_templates/Doxyfile.in b/cmake_templates/Doxyfile.in index 957c6c8d69e..a14048cd96a 100644 --- a/cmake_templates/Doxyfile.in +++ b/cmake_templates/Doxyfile.in @@ -2049,26 +2049,25 @@ PREDEFINED = # definition found in the source code. # This tag requires that the tag ENABLE_PREPROCESSING is set to YES. -EXPAND_AS_DEFINED = "SIP_TRANSFER" \ - "SIP_PYNAME" \ - "SIP_OUT" \ - "SIP_INOUT" \ - "SIP_TRANSFERTHIS" \ - "SIP_TRANSFERBACK" \ - "SIP_FACTORY" \ - "SIP_KEEPREFERENCE" \ +EXPAND_AS_DEFINED = "SIP_ABSTRACT" \ "SIP_ARRAY" \ "SIP_ARRAYSIZE" \ - "SIP_PYNAME" \ - "SIP_SKIP" \ - "SIP_PYARGDEFAULT" \ - "SIP_PYTYPE" \ - "SIP_PYARGREMOVE" \ "SIP_CONVERT_TO_SUBCLASS_CODE" \ + "SIP_END" \ + "SIP_FACTORY" \ "SIP_FEATURE" \ "SIP_IF_FEATURE" \ - "SIP_END" \ - "SIP_ABSTRACT" + "SIP_INOUT" \ + "SIP_KEEPREFERENCE" \ + "SIP_OUT" \ + "SIP_PYARGDEFAULT" \ + "SIP_PYARGREMOVE" \ + "SIP_PYNAME" \ + "SIP_PYTYPE" \ + "SIP_SKIP" \ + "SIP_TRANSFER" \ + "SIP_TRANSFERBACK" \ + "SIP_TRANSFERTHIS" # If the SKIP_FUNCTION_MACROS tag is set to YES then doxygen's preprocessor will # remove all references to function-like macros that are alone on a line, have diff --git a/python/auto_sip.blacklist b/python/auto_sip.blacklist index 058d55ec378..93404bed032 100644 --- a/python/auto_sip.blacklist +++ b/python/auto_sip.blacklist @@ -13,7 +13,6 @@ core/qgsfeaturerequest.sip core/qgsgeometrysimplifier.sip core/qgsgeometryvalidator.sip core/qgsmaptopixelgeometrysimplifier.sip -core/qgstransaction.sip core/qgstransactiongroup.sip core/qgsdartmeasurement.sip core/qgsexpressionfieldbuffer.sip diff --git a/scripts/sipify.pl b/scripts/sipify.pl index 9a492947900..adf194b4677 100755 --- a/scripts/sipify.pl +++ b/scripts/sipify.pl @@ -127,6 +127,54 @@ sub remove_constructor_or_body { }; } +sub fix_annotations(){ + # printed annotations + $line =~ s/\bSIP_ABSTRACT\b/\/Abstract\//; + $line =~ s/\bSIP_ARRAY\b/\/Array\//; + $line =~ s/\bSIP_ARRAYSIZE\b/\/ArraySize\//; + $line =~ s/\bSIP_FACTORY\b/\/Factory\//; + $line =~ s/\bSIP_IN\b/\/In\//g; + $line =~ s/\bSIP_INOUT\b/\/In,Out\//g; + $line =~ s/\bSIP_KEEPREFERENCE\b/\/KeepReference\//; + $line =~ s/\bSIP_OUT\b/\/Out\//g; + $line =~ s/\bSIP_RELEASEGIL\b/\/ReleaseGIL\//; + $line =~ s/\bSIP_TRANSFER\b/\/Transfer\//g; + $line =~ s/\bSIP_TRANSFERBACK\b/\/TransferBack\//; + $line =~ s/\bSIP_TRANSFERTHIS\b/\/TransferThis\//; + + $line =~ s/SIP_PYNAME\(\s*(\w+)\s*\)/\/PyName=$1\//; + + # combine multiple annotations + # https://regex101.com/r/uvCt4M/3 + do {no warnings 'uninitialized'; + $line =~ s/\/(\w+(=\w+)?)\/\s*\/(\w+(=\w+)?)\//\/$1,$3\//; + (! $3) or dbg_info("combine multiple annotations -- works only for 2"); + }; + + # unprinted annotations + $line =~ s/(\w+)(\<(?>[^<>]|(?2))*\>)?\s+SIP_PYTYPE\(\s*\'?([^()']+)(\(\s*(?:[^()]++|(?2))*\s*\))?\'?\s*\)/$3/g; + $line =~ s/=\s+[^=]*?\s+SIP_PYARGDEFAULT\(\s*\'?([^()']+)(\(\s*(?:[^()]++|(?2))*\s*\))?\'?\s*\)/= $1/g; + # remove argument + if ($line =~ m/SIP_PYARGREMOVE/){ + if ( $MULTILINE_DEFINITION == 1 ){ + my $prev_line = pop(@output) =~ s/\n$//r; + # update multi line status + my $parenthesis_balance = 0; + $parenthesis_balance += $prev_line =~ tr/\(//; + $parenthesis_balance -= $prev_line =~ tr/\)//; + if ($parenthesis_balance == 1){ + $MULTILINE_DEFINITION = 0; + } + # concat with above line to bring previous commas + $line =~ s/^\s+//; + $line = "$prev_line $line\n"; + } + # see https://regex101.com/r/5iNptO/4 + $line =~ s/(?, +)?(const )?(\w+)(\<(?>[^<>]|(?4))*\>)? [\w&*]+ SIP_PYARGREMOVE( = [^()]*(\(\s*(?:[^()]++|(?6))*\s*\))?)?(?()|,?)//g; + } + $line =~ s/SIP_FORCE//; +} + # main loop while ($line_idx < $line_count){ @@ -388,7 +436,8 @@ while ($line_idx < $line_count){ } # class declaration started - if ( $line =~ m/^(\s*class)\s*([A-Z]+_EXPORT)?\s+(\w+)(\s*\:.*)?(\s*SIP_ABSTRACT)?$/ ){ + # https://regex101.com/r/6FWntP/2 + 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+>)?)*)*)?(?\s*SIP_.*)?$/ ){ dbg_info("class definition started => private"); push @ACCESS, PRIVATE; push @global_bracket_nesting_index, 0; @@ -401,12 +450,14 @@ while ($line_idx < $line_count){ if ($4){ my $m = $4; $m =~ s/public //g; - $m =~ s/,?\s*private \w+(::\w+)?//; + $m =~ s/[,:]?\s*private \w+(::\w+)?//; $m =~ s/(\s*:)?\s*$//; $line .= $m; } - if ($5) { - $line .= ' /Abstract/'; + if (defined $+{annot}) + { + $line .= "$+{annot}"; + fix_annotations(); } $line .= "\n{\n"; @@ -559,49 +610,7 @@ while ($line_idx < $line_count){ # remove export macro from struct definition $line =~ s/^(\s*struct )\w+_EXPORT (.+)$/$1$2/; - # printed annotations - $line =~ s/\bSIP_FACTORY\b/\/Factory\//; - $line =~ s/\bSIP_OUT\b/\/Out\//g; - $line =~ s/\bSIP_IN\b/\/In\//g; - $line =~ s/\bSIP_INOUT\b/\/In,Out\//g; - $line =~ s/\bSIP_TRANSFER\b/\/Transfer\//g; - $line =~ s/\bSIP_KEEPREFERENCE\b/\/KeepReference\//; - $line =~ s/\bSIP_TRANSFERTHIS\b/\/TransferThis\//; - $line =~ s/\bSIP_TRANSFERBACK\b/\/TransferBack\//; - $line =~ s/\bSIP_RELEASEGIL\b/\/ReleaseGIL\//; - $line =~ s/\bSIP_ARRAY\b/\/Array\//; - $line =~ s/\bSIP_ARRAYSIZE\b/\/ArraySize\//; - $line =~ s/SIP_PYNAME\(\s*(\w+)\s*\)/\/PyName=$1\//; - - # combine multiple annotations - # https://regex101.com/r/uvCt4M/3 - do {no warnings 'uninitialized'; - $line =~ s/\/(\w+(=\w+)?)\/\s*\/(\w+(=\w+)?)\//\/$1,$3\//; - (! $3) or dbg_info("combine multiple annotations -- works only for 2"); - }; - - # unprinted annotations - $line =~ s/(\w+)(\<(?>[^<>]|(?2))*\>)?\s+SIP_PYTYPE\(\s*\'?([^()']+)(\(\s*(?:[^()]++|(?2))*\s*\))?\'?\s*\)/$3/g; - $line =~ s/=\s+[^=]*?\s+SIP_PYARGDEFAULT\(\s*\'?([^()']+)(\(\s*(?:[^()]++|(?2))*\s*\))?\'?\s*\)/= $1/g; - # remove argument - if ($line =~ m/SIP_PYARGREMOVE/){ - if ( $MULTILINE_DEFINITION == 1 ){ - my $prev_line = pop(@output) =~ s/\n$//r; - # update multi line status - my $parenthesis_balance = 0; - $parenthesis_balance += $prev_line =~ tr/\(//; - $parenthesis_balance -= $prev_line =~ tr/\)//; - if ($parenthesis_balance == 1){ - $MULTILINE_DEFINITION = 0; - } - # concat with above line to bring previous commas - $line =~ s/^\s+//; - $line = "$prev_line $line\n"; - } - # see https://regex101.com/r/5iNptO/4 - $line =~ s/(?, +)?(const )?(\w+)(\<(?>[^<>]|(?4))*\>)? [\w&*]+ SIP_PYARGREMOVE( = [^()]*(\(\s*(?:[^()]++|(?6))*\s*\))?)?(?()|,?)//g; - } - $line =~ s/SIP_FORCE//; + fix_annotations(); # fix astyle placing space after % character $line =~ s/\s*% (MappedType|TypeCode|TypeHeaderCode|ModuleHeaderCode|ConvertFromTypeCode|ConvertToTypeCode|MethodCode|End)/%$1/; diff --git a/tests/scripts/sipifyheader.expected.sip b/tests/scripts/sipifyheader.expected.sip index a9f6773929c..4f5e0a6cc22 100644 --- a/tests/scripts/sipifyheader.expected.sip +++ b/tests/scripts/sipifyheader.expected.sip @@ -354,7 +354,7 @@ remove argument void ShowThisPrivateOne() ; }; -class ClassWithPrivateInheritanceOnly +class ClassWithPrivateInheritanceOnly /Abstract/ { %Docstring Documentation goes here diff --git a/tests/scripts/sipifyheader.h b/tests/scripts/sipifyheader.h index ab99f52e846..b1711107791 100644 --- a/tests/scripts/sipifyheader.h +++ b/tests/scripts/sipifyheader.h @@ -422,7 +422,7 @@ class CORE_EXPORT QgsSipifyHeader : public QtClass, private Ui::QgsBas * \ingroup core * Documentation goes here */ -class CORE_EXPORT ClassWithPrivateInheritanceOnly : private QgsBaseClass +class CORE_EXPORT ClassWithPrivateInheritanceOnly : private QgsBaseClass SIP_ABSTRACT { public: //! A constructor with definition in header on several lines