Skip to content

Commit

Permalink
sipify improvements
Browse files Browse the repository at this point in the history
 * one liner enum (without assignements)
 * remove function bodies of skipped methods
  • Loading branch information
3nids committed Apr 24, 2017
1 parent 5a19463 commit 8f35ee4
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 12 deletions.
39 changes: 27 additions & 12 deletions scripts/sipify.pl
Expand Up @@ -200,6 +200,13 @@ sub processDoxygenLine
}
$MULTILINE_DEFINITION = 0;
}
# also skip method body if there is one
if ($lines[$line_idx] =~ m/^\s*\{/){
while($lines[$line_idx] !~ m/^\s*\}/){
$line_idx++;
}
$line_idx++;
}
next;
}

Expand Down Expand Up @@ -310,23 +317,31 @@ sub processDoxygenLine
# Enum declaration
if ( $line =~ m/^\s*enum\s+\w+.*?$/ ){
push @output, "$line\n";
$line = $lines[$line_idx];
$line_idx++;
$line =~ m/^\s*\{\s*$/ || die "Unexpected content: enum should be followed by {\nline: $line";
push @output, "$line\n";
while ($line_idx < $line_count){
if ($line =~ m/\{((\s*\w+)(\s*=\s*[\w\s\d<|]+.*?)?(,?))+\s*\}/){
# one line declaration
$line !~ m/=/ or die 'spify.pl does not handle enum one liners with value assignment. Use multiple lines instead.';
push @output, "$line\n";
}
else
{
$line = $lines[$line_idx];
$line_idx++;
if ($line =~ m/\};/){
last;
$line =~ m/^\s*\{\s*$/ || die "Unexpected content: enum should be followed by {\nline: $line";
push @output, "$line\n";
while ($line_idx < $line_count){
$line = $lines[$line_idx];
$line_idx++;
if ($line =~ m/\};/){
last;
}
$line =~ s/(\s*\w+)(\s*=\s*[\w\s\d<|]+.*?)?(,?).*$/$1$3/;
push @output, "$line\n";
}
$line =~ s/(\s*\w+)(\s*=\s*[\w\s\d<|]+.*?)?(,?).*$/$1$3/;
push @output, "$line\n";
# enums don't have Docstring apparently
$comment = '';
next;
}
push @output, "$line\n";
# enums don't have Docstring apparently
$comment = '';
next;
}

# skip non-method member declaration in non-public sections
Expand Down
5 changes: 5 additions & 0 deletions tests/scripts/sipifyheader.expected.sip
Expand Up @@ -70,6 +70,10 @@ class QgsSipifyHeader : QtClass<QVariant>
typedef QFlags<QgsSipifyHeader::MyEnum> Flags;


enum OneLiner { Success, NoSuccess };
enum OneLiner { Success, NoSuccess };
enum OneLiner;

struct Data
{
Data( QgsMapLayer *layer, Qstring name );
Expand Down Expand Up @@ -191,6 +195,7 @@ complex default value and type (i.e. containing commas) should be given as a str
%Docstring
:rtype: bool
%End

QgsRaster::RasterBuildPyramids buildPyramidsFlag() const;
%Docstring
Removing function body with namespaced return value
Expand Down
7 changes: 7 additions & 0 deletions tests/scripts/sipifyheader.h
Expand Up @@ -106,6 +106,8 @@ class CORE_EXPORT QgsSipifyHeader : public QtClass<QVariant>, private Ui::QgsBas
};
Q_DECLARE_FLAGS( Flags, MyEnum )

enum OneLiner { Success, NoSuccess };

/**
* Docstring headers for structs are not supported by sip (as of 4.18) and
* therefore this docstring must not to be copied to the sipfile.
Expand Down Expand Up @@ -217,6 +219,11 @@ class CORE_EXPORT QgsSipifyHeader : public QtClass<QVariant>, private Ui::QgsBas

bool removeFunctionBody( const QList<int, QString> &list, QgsVectorLayer *vl ) { doSomething; return true; } // some comments

static inline QgsMapLayer *skippedMethodWithBody() SIP_SKIP
{
OhNoYouShouldnotHaveReadThis();
}

//! Removing function body with namespaced return value
QgsRaster::RasterBuildPyramids buildPyramidsFlag() const { return mBuildPyramidsFlag; }

Expand Down

0 comments on commit 8f35ee4

Please sign in to comment.