Skip to content
Permalink
Browse files

[sipify] monkey patch enum for PyQGIS API compatibility

  • Loading branch information
3nids committed Mar 7, 2019
1 parent 717ea43 commit ee37345aef192b507bd344a8b5c7b25b0b1d0fee
Showing with 13 additions and 2 deletions.
  1. +13 −2 scripts/sipify.pl
@@ -951,8 +951,11 @@ sub detect_non_method_member{

# Enum declaration
# For scoped and type based enum, the type has to be removed
if ( $LINE =~ m/^(\s*enum\s+(class\s+)?\w+)(\s*:\s*\w+)?.*$/ ){
if ( $LINE =~ m/^(\s*enum\s+(class\s+)?(\w+))(\s*:\s*\w+)?.*$/ ){
write_output("ENU1", "$1\n");
my $is_scope_based = "0";
$is_scope_based = "1" if defined $2;
my $enum_qualname = $3;
if ($LINE =~ m/\{((\s*\w+)(\s*=\s*[\w\s\d<|]+.*?)?(,?))+\s*\}/){
# one line declaration
$LINE !~ m/=/ or exit_with_error("spify.pl does not handle enum one liners with value assignment. Use multiple lines instead.");
@@ -963,6 +966,8 @@ sub detect_non_method_member{
$LINE = read_line();
$LINE =~ m/^\s*\{\s*$/ or exit_with_error('Unexpected content: enum should be followed by {');
write_output("ENU2", "$LINE\n");
push @OUTPUT_PYTHON, "# monkey patching scoped based enum\n" if $is_scope_based eq "1";
my @enum_members_doc = ();
while ($LINE_IDX < $LINE_COUNT){
$LINE = read_line();
if (detect_comment_block()){
@@ -972,13 +977,19 @@ sub detect_non_method_member{
next if ($LINE =~ m/^\s*\w+\s*\|/); # multi line declaration as sum of enums

do {no warnings 'uninitialized';
my $enum_decl = $LINE =~ s/^(\s*\w+)(\s+SIP_\w+(?:\([^()]+\))?)?(?:\s*=\s*(?:[\w\s\d|+-]|::|<<)+)?(,?).*$/$1$2$3/r;
my $enum_decl = $LINE =~ s/^(\s*(\w+))(\s+SIP_\w+(?:\([^()]+\))?)?(?:\s*=\s*(?:[\w\s\d|+-]|::|<<)+)?(,?)(\s*\/\/!<\s*(.*$))?/$1$3$4/r;
my $enum_member = $2;
push @enum_members_doc, "'* $enum_member: ' + $ACTUAL_CLASS.$enum_qualname.$2.__doc__";
my $comment = $6;
push @OUTPUT_PYTHON, "$ACTUAL_CLASS.$enum_qualname.$enum_member.__doc__ = \"$comment\"\n" if $is_scope_based eq "1";
push @OUTPUT_PYTHON, "$ACTUAL_CLASS.$enum_member = $ACTUAL_CLASS.$enum_qualname.$enum_member\n" if $is_scope_based eq "1";
$enum_decl = fix_annotations($enum_decl);
write_output("ENU3", "$enum_decl\n");
};
detect_comment_block(strict_mode => UNSTRICT);
}
write_output("ENU4", "$LINE\n");
push @OUTPUT_PYTHON, "$ACTUAL_CLASS.$enum_qualname.__doc__ = '$COMMENT\\n' + " . join(" + '\\n' + ", @enum_members_doc) . "\n# --\n" if $is_scope_based eq "1";
# enums don't have Docstring apparently
$COMMENT = '';
next;

0 comments on commit ee37345

Please sign in to comment.
You can’t perform that action at this time.