Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
SIP 4.19.7+ allows to document template based classes
  • Loading branch information
3nids committed Jan 17, 2018
1 parent 8c74c5b commit 5327978
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 22 deletions.
4 changes: 2 additions & 2 deletions python/core/qgsrange.sip
Expand Up @@ -246,9 +246,9 @@ Returns true if this range overlaps another range.
};


typedef QgsTemporalRange< QDate > QgsDateRange;
typedef QgsTemporalRange< QDate > QgsDateRange ;

typedef QgsTemporalRange< QDateTime > QgsDateTimeRange;
typedef QgsTemporalRange< QDateTime > QgsDateTimeRange ;

/************************************************************************
* This file has been generated automatically from *
Expand Down
44 changes: 27 additions & 17 deletions scripts/sipify.pl
Expand Up @@ -23,7 +23,8 @@

# read arguments
my $debug = 0;
die("usage: $0 [-debug] headerfile\n") unless GetOptions ("debug" => \$debug) && @ARGV == 1;
my $SUPPORT_TEMPLATE_DOCSTRING = 0;
die("usage: $0 [-debug] [-template-doc] headerfile\n") unless GetOptions ("debug" => \$debug, "template-doc" => \$SUPPORT_TEMPLATE_DOCSTRING) && @ARGV == 1;
my $headerfile = $ARGV[0];

# read file
Expand Down Expand Up @@ -51,6 +52,7 @@
my $COMMENT_PARAM_LIST = 0;
my $COMMENT_LAST_LINE_NOTE_WARNING = 0;
my $COMMENT_CODE_SNIPPET = 0;
my $COMMENT_TEMPLATE_DOCSTRING = 0;
my $GLOB_IFDEF_NESTING_IDX = 0;
my @GLOB_BRACKET_NESTING_IDX = (0);
my $PRIVATE_SECTION_LINE = '';
Expand Down Expand Up @@ -370,6 +372,7 @@ sub fix_annotations {
$line =~ s/\(\s+\)/()/;
}
$line =~ s/SIP_FORCE//;
$line =~ s/SIP_DOC_TEMPLATE//;
return $line;
}

Expand Down Expand Up @@ -963,6 +966,28 @@ sub detect_non_method_member{
# remove export macro from struct definition
$LINE =~ s/^(\s*struct )\w+_EXPORT (.+)$/$1$2/;

# Skip comments
if ( $SUPPORT_TEMPLATE_DOCSTRING == 1 &&
$LINE =~ m/^\s*typedef\s+\w+\s*<\s*\w+\s*>\s+\w+\s+.*SIP_DOC_TEMPLATE/ ) {
# support Docstring for template based classes in SIP 4.19.7+
}
elsif ( $LINE =~ m/\/\// ||
$LINE =~ m/^\s*typedef / ||
$LINE =~ m/\s*struct / ||
$LINE =~ m/operator\[\]\(/ ||
$LINE =~ m/^\s*operator\b/ ||
$LINE =~ m/operator\s?[!+-=*\/\[\]<>]{1,2}/ ||
$LINE =~ m/^\s*%\w+(.*)?$/ ||
$LINE =~ m/^\s*namespace\s+\w+/ ||
$LINE =~ m/^\s*(virtual\s*)?~/ ||
detect_non_method_member() == 1 ){
dbg_info('skipping comment');
dbg_info('because typedef') if ($LINE =~ m/\s*typedef.*?(?!SIP_DOC_TEMPLATE)/);
$COMMENT = '';
$RETURN_TYPE = '';
$IS_OVERRIDE = 0;
}

$LINE = fix_annotations($LINE);

# fix astyle placing space after % character
Expand Down Expand Up @@ -1016,22 +1041,7 @@ sub detect_non_method_member{
# do not comment now for templates, wait for class definition
next;
}
if ( $LINE =~ m/\/\// ||
$LINE =~ m/\s*typedef / ||
$LINE =~ m/\s*struct / ||
$LINE =~ m/operator\[\]\(/ ||
$LINE =~ m/^\s*operator\b/ ||
$LINE =~ m/operator\s?[!+-=*\/\[\]<>]{1,2}/ ||
$LINE =~ m/^\s*%\w+(.*)?$/ ||
$LINE =~ m/^\s*namespace\s+\w+/ ||
$LINE =~ m/^\s*(virtual\s*)?~/ ||
detect_non_method_member() == 1 ){
dbg_info('skipping comment');
$COMMENT = '';
$RETURN_TYPE = '';
$IS_OVERRIDE = 0;
}
elsif ( $COMMENT !~ m/^\s*$/ || $RETURN_TYPE ne ''){
if ( $COMMENT !~ m/^\s*$/ || $RETURN_TYPE ne ''){
if ( $IS_OVERRIDE == 1 && $COMMENT =~ m/^\s*$/ ){
# overridden method with no new docs - so don't create a Docstring and use
# parent class Docstring
Expand Down
12 changes: 11 additions & 1 deletion scripts/sipify_all.sh
Expand Up @@ -15,6 +15,16 @@
###########################################################################
set -e

TEMPLATE_DOC=""
while :; do
case $1 in
-t|--template-doc) TEMPLATE_DOC="-template-doc"
;;
*) break
esac
shift
done

DIR=$(git rev-parse --show-toplevel)

# GNU prefix command for mac os support (gsed, gsplit)
Expand All @@ -37,7 +47,7 @@ for module in "${modules[@]}"; do
else
path=$(${GP}sed -r 's@/[^/]+$@@' <<< $sipfile)
mkdir -p python/$path
./scripts/sipify.pl $header > python/$sipfile
./scripts/sipify.pl $TEMPLATE_DOC $header > python/$sipfile
fi
count=$((count+1))
done < <( ${GP}sed -n -r "s/^%Include (.*\.sip)/${module}\/\1/p" python/${module}/${module}_auto.sip )
Expand Down
6 changes: 6 additions & 0 deletions src/core/qgis_sip.h
Expand Up @@ -184,4 +184,10 @@
*/
#define SIP_VIRTUAL_CATCHER_CODE(code)

/*
* Force documentation of templates
* Available for SIP 4.19.7+
*/
#define SIP_DOC_TEMPLATE

#endif // QGIS_SIP_H
4 changes: 2 additions & 2 deletions src/core/qgsrange.h
Expand Up @@ -412,7 +412,7 @@ class QgsTemporalRange
* \since QGIS 3.0
* \see QgsDateTimeRange
*/
typedef QgsTemporalRange< QDate > QgsDateRange;
typedef QgsTemporalRange< QDate > QgsDateRange SIP_DOC_TEMPLATE;

/**
* QgsRange which stores a range of date times.
Expand All @@ -424,6 +424,6 @@ typedef QgsTemporalRange< QDate > QgsDateRange;
* \since QGIS 3.0
* \see QgsDateRange
*/
typedef QgsTemporalRange< QDateTime > QgsDateTimeRange;
typedef QgsTemporalRange< QDateTime > QgsDateTimeRange SIP_DOC_TEMPLATE;

#endif // QGSRANGE_H

0 comments on commit 5327978

Please sign in to comment.