Skip to content

Commit

Permalink
sipify improvements
Browse files Browse the repository at this point in the history
* add demo file and start a short doc
* fix some annotations
* do not display hidden line (SIP_SKIP, delete)
* use a defined var for SIP_SKIP
* remove constructor definition in header
* fix comment after method definition in header
* add a test for sipify itself
  • Loading branch information
3nids committed Mar 30, 2017
1 parent 21be025 commit 15e4903
Show file tree
Hide file tree
Showing 14 changed files with 381 additions and 69 deletions.
3 changes: 2 additions & 1 deletion ci/travis/code_layout/CMakeLists.txt
Expand Up @@ -8,4 +8,5 @@ ENABLE_TESTING()

ADD_TEST(qgis_indentation ${CMAKE_SOURCE_DIR}/../../../scripts/verify-indentation.sh)
ADD_TEST(qgis_spelling ${CMAKE_SOURCE_DIR}/../../../scripts/spell_check/spell_test.sh)
ADD_TEST(qgis_sip ${CMAKE_SOURCE_DIR}/../../../tests/scripts/test_auto_sipfiles.sh)
ADD_TEST(qgis_sipify ${CMAKE_SOURCE_DIR}/../../../tests/scripts/test_sipify.sh)
ADD_TEST(qgis_sip_uptodate ${CMAKE_SOURCE_DIR}/../../../tests/scripts/test_sipfiles_uptodate.sh)
3 changes: 2 additions & 1 deletion cmake_templates/Doxyfile.in
Expand Up @@ -1356,7 +1356,8 @@ EXPAND_AS_DEFINED = "SIP_TRANSFER" \
"SIP_TRANSFERBACK" \
"SIP_FACTORY" \
"SIP_KEEPREFERENCE" \
"SIP_PYNAME"
"SIP_PYNAME" \
"SIP_SKIP"

# If the SKIP_FUNCTION_MACROS tag is set to YES (the default) then
# doxygen's preprocessor will remove all function-like macros that are alone
Expand Down
1 change: 1 addition & 0 deletions python/core/qgsattributes.sip
Expand Up @@ -10,6 +10,7 @@




typedef QMap<int, QVariant> QgsAttributeMap;

typedef QMap<int, QString> QgsFieldNameMap;
Expand Down
13 changes: 1 addition & 12 deletions python/core/qgsfeature.sip
Expand Up @@ -10,6 +10,7 @@




typedef qint64 QgsFeatureId;


Expand Down Expand Up @@ -152,13 +153,7 @@ class QgsFeature
Copy constructor
%End

// QgsFeature &operator=( const QgsFeature &rhs ); // SIP_SKIP


// bool operator==( const QgsFeature &other ) const; // SIP_SKIP


// bool operator!=( const QgsFeature &other ) const; // SIP_SKIP


virtual ~QgsFeature();
Expand Down Expand Up @@ -437,10 +432,6 @@ Allows direct construction of QVariants from features.

}; // class QgsFeature

// CORE_EXPORT QDataStream &operator<<( QDataStream &out, const QgsFeature &feature ); // SIP_SKIP

// CORE_EXPORT QDataStream &operator>>( QDataStream &in, QgsFeature &feature ); // SIP_SKIP


typedef QMap<qint64, QMap<int, QVariant> > QgsChangedAttributesMap;

Expand All @@ -450,7 +441,5 @@ typedef QSet<qint64> QgsFeatureIds;

typedef QList<QgsFeature> QgsFeatureList;

// uint qHash( const QgsFeature &key, uint seed = 0 ); // SIP_SKIP



14 changes: 0 additions & 14 deletions python/core/qgsvectorlayer.sip
Expand Up @@ -335,8 +335,6 @@ class QgsVectorLayer : QgsMapLayer, QgsExpressionContextGenerator

virtual ~QgsVectorLayer();

// QgsVectorLayer( const QgsVectorLayer &rhs ) = delete;
// QgsVectorLayer &operator=( QgsVectorLayer const &rhs ) = delete;

QString storageType() const;
%Docstring
Expand Down Expand Up @@ -384,8 +382,6 @@ Returns a comment for the data in the layer
Returns the data provider
%End

// const QgsVectorDataProvider *dataProvider() const; // SIP_SKIP


void setProviderEncoding( const QString &encoding );
%Docstring
Expand Down Expand Up @@ -630,8 +626,6 @@ Sets diagram rendering object (takes ownership)
Return renderer.
%End

// const QgsFeatureRenderer *renderer() const { return mRenderer; } // SIP_SKIP


void setRenderer( QgsFeatureRenderer *r /Transfer/ );
%Docstring
Expand Down Expand Up @@ -973,10 +967,6 @@ TODO QGIS 3.0 returns an enum instead of a magic constant
@return 0 in case of success
%End

// const QgsAbstractVectorLayerLabeling *labeling() const { return mLabeling; } // SIP_SKIP


// void setLabeling( QgsAbstractVectorLayerLabeling *labeling ); // SIP_SKIP


virtual bool isEditable() const;
Expand Down Expand Up @@ -1256,8 +1246,6 @@ Set annotation form for layer
Buffer with uncommitted editing operations. Only valid after editing has been turned on.
%End

// const QgsVectorLayerEditBuffer *editBuffer() const { return mEditBuffer; } // SIP_SKIP


void beginEditCommand( const QString &text );
%Docstring
Expand Down Expand Up @@ -1512,8 +1500,6 @@ Returns the current transparency for the vector layer

QString metadata() const;

// inline QgsGeometryCache *cache() { return mCache; } // SIP_SKIP


void setSimplifyMethod( const QgsVectorSimplifyMethod &simplifyMethod );
%Docstring
Expand Down
83 changes: 58 additions & 25 deletions scripts/sipify.pl
Expand Up @@ -35,7 +35,6 @@
# Skip preprocessor stuff
if ($line =~ m/^\s*#/){
if ( $line =~ m/^\s*#ifdef SIP_RUN/){

$SIP_RUN = 1;
if ($PRIVATE_SECTION == 1){
print $private_section_line;
Expand Down Expand Up @@ -125,13 +124,11 @@

# SIP_SKIP
if ( $line =~ m/SIP_SKIP/ ){
$line =~ s/^(\s*)(\w.*)$/$1\/\/ $2\n/;
print $line;
next;
}

# Private members (exclude SIP_RUN)
if ( $line =~ m/^\s*private( slots)?:.*$/ ){
if ( $line =~ m/^\s*private( slots)?:/ ){
$PRIVATE_SECTION = 1;
$private_section_line = $line;
next;
Expand All @@ -148,18 +145,20 @@
}

# Detect comment block
if ($line =~ m/\s*\/\*\*/){
$comment = $line =~ s/\s*\/\*\*(.*)$/$1/r;
if ($line =~ m/^\s*\/\*/){
do {no warnings 'uninitialized';
$comment = $line =~ s/^\s*\/\*(\*)?(.*)$/$2/r;
};
$comment =~ s/^\s*$//;
while(!eof $header){
$line = readline $header;
$line =~ m/\s*\*?(.*?)(\/)?$/;
$comment .= "$1\n";
$comment .= $line =~ s/\s*\*?(.*?)(\/)?$/$1/r;
if ( $line =~ m/\*\/$/ ){
last;
}
}
$comment =~ s/(\n)+$//;
#print $comment;
next;
}

Expand All @@ -177,14 +176,17 @@
$line = "$1$3";
# Inheritance
if ($4){
my $m;
$m = $4;
my $m = $4;
$m =~ s/public //g;
$m =~ s/\s*private \w+,?//;
$m =~ s/,?\s*private \w+//;
$m =~ s/(\s*:)?\s*$//;
$line .= $m;
}

$line .= "\n{\n%Docstring\n$comment\n%End\n";
$line .= "\n{\n";
if ( $comment !~ m/^\s*$/ ){
$line .= "%Docstring\n$comment\n%End\n";
}
$line .= "\n%TypeHeaderCode\n#include \"" . basename($headerfile) . "\"\n";

print $line;
Expand Down Expand Up @@ -214,17 +216,46 @@
print $line;
}
print $line;
# enums don't have Docstring apparently
next;
}

# remove keywords
do {no warnings 'uninitialized';
$line =~ s/\s*override( SIP_FACTORY)?;/$1;/;
# remove keywords
$line =~ s/\s*override( SIP_\w+(\(.+\))?)?;/$1;/;
$line =~ s/^(\s*)?(const )?(virtual |static )?inline /$1$2$3/;
$line =~ s/\bnullptr\b/0/g;

# remove constructor definition
if ( $line =~ m/^(\s*)?(explicit )?(\w+)\(([^()]*\([^()]*\)[^()]*)*\)(?!;)$/ ){
my $newline = $line =~ s/\n/;\n/r;
my $nesting_index = 0;
while(!eof $header){
$line = readline $header;
if ( $nesting_index == 0 ){
if ( $line =~ m/^\s*(:|,)/ ){
next;
}
$line =~ m/^\s*\{/ or die 'Constructor definition misses {';
if ( $line =~ m/^\s*\{.*?\}/ ){
last;
}
$nesting_index = 1;
next;
}
else {
$nesting_index += $line =~ tr/\{//;
$nesting_index -= $line =~ tr/\}//;
if ($nesting_index eq 0){
last;
}
}
}
$line = $newline;
}

# remove function bodies
if ( $line =~ m/^(\s*)?(const )?(virtual |static )?((\w+(<.*?>)?\s+(\*|&)?)?(\w+|operator.)\(.*?(\(.*\))*.*\)( const)?)\s*(\{.*\})?(?!;)$/ ){
if ( $line =~ m/^(\s*)?(const )?(virtual |static )?((\w+(<.*?>)?\s+(\*|&)?)?(\w+|operator.)\(.*?(\(.*\))*.*\)( const)?)\s*(\{.*\})?(?!;)(\s*\/\/.*)?$/ ){
my $newline = "$1$2$3$4;\n";
if ($line !~ m/\{.*?\}$/){
$line = readline $header;
Expand All @@ -242,18 +273,20 @@
};

# deleted functions
if ( $line =~ m/^(\s*)?(const )?(virtual |static )?((\w+(<.*?>)?\s+(\*|&)?)?(\w+|operator.)\(.*?(\(.*\))*.*\)( const)?)\s*= delete;$/ ){
$line =~ s/^/\/\//;
if ( $line =~ m/^(\s*)?(const )?(virtual |static )?((\w+(<.*?>)?\s+(\*|&)?)?(\w+|operator.)\(.*?(\(.*\))*.*\)( const)?)\s*= delete;(\s*\/\/.*)?$/ ){
$comment = '';
next;
}

$line =~ s/SIP_FACTORY/\/Factory\//;
$line =~ s/SIP_OUT/\/Out\//g;
$line =~ s/SIP_INOUT/\/In,Out\//g;
$line =~ s/SIP_TRANSFER/\/Transfer\//g;
$line =~ s/\bSIP_FACTORY\b/\/Factory\//;
$line =~ s/\bSIP_OUT\b/\/Out\//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/SIP_PYNAME\(\s*(\w+)\s*\)/\/PyName=$1\//;
$line =~ s/SIP_KEEPREFERENCE\((\w+)\)/\/KeepReference\//;
$line =~ s/SIP_TRANSFERTHIS\((\w+)\)/\/TransferThis\//;
$line =~ s/SIP_TRANSFERBACK\((\w+)\)/\/TransferBack\//;

# fix astyle placing space after % character
$line =~ s/\s*% (MappedType|TypeHeaderCode|ConvertFromTypeCode|ConvertToTypeCode|MethodCode|End)/%$1/;
Expand All @@ -280,7 +313,7 @@
if ( $line =~ m/^\s*$/ || $line =~ m/\/\// || $line =~ m/\s*typedef / ){
$comment = '';
}
elsif ( $comment ne '' ){
elsif ( $comment !~ m/^\s*$/ ){
print "%Docstring\n$comment\n%End\n";
$comment = '';
}
Expand Down
7 changes: 6 additions & 1 deletion src/core/qgis.h
Expand Up @@ -416,7 +416,7 @@ typedef unsigned long long qgssize;
* and
* http://pyqt.sourceforge.net/Docs/sip4/annotations.html?highlight=keepreference#argument-annotation-Out
*/
#define SIP_IN_OUT
#define SIP_INOUT

/**
* http://pyqt.sourceforge.net/Docs/sip4/annotations.html?highlight=keepreference#function-annotation-Factory
Expand All @@ -432,3 +432,8 @@ typedef unsigned long long qgssize;
* http://pyqt.sourceforge.net/Docs/sip4/annotations.html?highlight=keepreference#argument-annotation-KeepReference
*/
#define SIP_KEEPREFERENCE

/**
* discard line
*/
#define SIP_SKIP
4 changes: 3 additions & 1 deletion src/core/qgsattributes.h
Expand Up @@ -19,6 +19,8 @@
#define QGSATTRIBUTES_H

#include "qgis_core.h"
#include "qgis.h"

#include <QMap>
#include <QString>
#include <QVariant>
Expand Down Expand Up @@ -113,7 +115,7 @@ class CORE_EXPORT QgsAttributes : public QVector<QVariant>
* @note added in QGIS 3.0
* @note not available in Python bindings
*/
QgsAttributeMap toMap() const; // SIP_SKIP
QgsAttributeMap toMap() const SIP_SKIP;

inline bool operator!=( const QgsAttributes &v ) const { return !( *this == v ); }
};
Expand Down
14 changes: 8 additions & 6 deletions src/core/qgsfeature.h
Expand Up @@ -17,6 +17,8 @@ email : sherman at mrcc.com
#define QGSFEATURE_H

#include "qgis_core.h"
#include "qgis.h"

#include <QExplicitlySharedDataPointer>
#include <QList>
#include <QMap>
Expand Down Expand Up @@ -200,17 +202,17 @@ class CORE_EXPORT QgsFeature

/** Assignment operator
*/
QgsFeature &operator=( const QgsFeature &rhs ); // SIP_SKIP
QgsFeature &operator=( const QgsFeature &rhs ) SIP_SKIP;

/**
* Compares two features
*/
bool operator==( const QgsFeature &other ) const; // SIP_SKIP
bool operator==( const QgsFeature &other ) const SIP_SKIP;

/**
* Compares two features
*/
bool operator!=( const QgsFeature &other ) const; // SIP_SKIP
bool operator!=( const QgsFeature &other ) const SIP_SKIP;

virtual ~QgsFeature();

Expand Down Expand Up @@ -498,9 +500,9 @@ class CORE_EXPORT QgsFeature
}; // class QgsFeature

//! Writes the feature to stream out. QGIS version compatibility is not guaranteed.
CORE_EXPORT QDataStream &operator<<( QDataStream &out, const QgsFeature &feature ); // SIP_SKIP
CORE_EXPORT QDataStream &operator<<( QDataStream &out, const QgsFeature &feature ) SIP_SKIP;
//! Reads a feature from stream in into feature. QGIS version compatibility is not guaranteed.
CORE_EXPORT QDataStream &operator>>( QDataStream &in, QgsFeature &feature ); // SIP_SKIP
CORE_EXPORT QDataStream &operator>>( QDataStream &in, QgsFeature &feature ) SIP_SKIP;

// key = feature id, value = changed attributes
#ifndef SIP_RUN
Expand All @@ -524,7 +526,7 @@ typedef QSet<qint64> QgsFeatureIds;

typedef QList<QgsFeature> QgsFeatureList;

uint qHash( const QgsFeature &key, uint seed = 0 ); // SIP_SKIP
uint qHash( const QgsFeature &key, uint seed = 0 ) SIP_SKIP;

Q_DECLARE_METATYPE( QgsFeature )
Q_DECLARE_METATYPE( QgsFeatureList )
Expand Down

0 comments on commit 15e4903

Please sign in to comment.