Skip to content

Commit 837607c

Browse files
committed
[sipify] handle moving enum to scope based and out of class enum
1 parent 21207b8 commit 837607c

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

scripts/sipify.pl

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -959,7 +959,9 @@ sub detect_non_method_member{
959959
my $is_scope_based = "0";
960960
$is_scope_based = "1" if defined $2;
961961
my $monkeypatch = "0";
962-
$monkeypatch = "1" if defined $is_scope_based eq "1" and $LINE =~ m/SIP_MONKEYPATCH_SCOPEENUM/;
962+
$monkeypatch = "1" if defined $is_scope_based eq "1" and $LINE =~ m/SIP_MONKEYPATCH_SCOPEENUM(:?\(\s*(?<emkb>\w+)\s*\))/;
963+
my $enum_mk_base = "";
964+
$enum_mk_base = $+{emkb} if defined $+{emkb};
963965
if ($LINE =~ m/\{((\s*\w+)(\s*=\s*[\w\s\d<|]+.*?)?(,?))+\s*\}/){
964966
# one line declaration
965967
$LINE !~ m/=/ or exit_with_error("spify.pl does not handle enum one liners with value assignment. Use multiple lines instead.");
@@ -986,7 +988,13 @@ sub detect_non_method_member{
986988
push @enum_members_doc, "'* $enum_member: ' + $ACTUAL_CLASS.$enum_qualname.$2.__doc__";
987989
my $comment = $+{co};
988990
push @OUTPUT_PYTHON, "$ACTUAL_CLASS.$enum_qualname.$enum_member.__doc__ = \"$comment\"\n" if $is_scope_based eq "1";
989-
push @OUTPUT_PYTHON, "$ACTUAL_CLASS.$enum_member = $ACTUAL_CLASS.$enum_qualname.$enum_member\n" if $monkeypatch eq "1";
991+
if ($monkeypatch eq "1") {
992+
if ( $enum_mk_base ne "" ){
993+
push @OUTPUT_PYTHON, "$enum_mk_base.$enum_member = $enum_qualname.$enum_member\n";
994+
} else {
995+
push @OUTPUT_PYTHON, "$ACTUAL_CLASS.$enum_member = $ACTUAL_CLASS.$enum_qualname.$enum_member\n";
996+
}
997+
}
990998
$enum_decl = fix_annotations($enum_decl);
991999
write_output("ENU3", "$enum_decl\n");
9921000
};

0 commit comments

Comments
 (0)