Skip to content

Commit 4b730c3

Browse files
committed
sipdiff: remove forward declarations and option to keep comments
1 parent bd6e068 commit 4b730c3

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

scripts/sipdiff

+25-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,21 @@
11
#!/usr/bin/env bash
22

3+
# ARGUMENTS
4+
REMOVE_COMMENTS=YES
5+
while getopts ":c" opt; do
6+
case $opt in
7+
c)
8+
# keep comments
9+
REMOVE_COMMENTS=NO
10+
;;
11+
\?)
12+
echo "Invalid option: -$OPTARG" >&2
13+
exit 1
14+
;;
15+
esac
16+
done
17+
shift $(expr $OPTIND - 1)
18+
319
# GNU prefix command for mac os support (gsed, gsplit)
420
GP=
521
if [[ "$OSTYPE" =~ darwin* ]]; then
@@ -15,7 +31,11 @@ for file in $*; do
1531
tempfile=$(${GP}mktemp ${f}XXXX --suffix=.h)
1632

1733
# Remove comments
18-
${GP}sed 's/a/aA/g;s/__/aB/g;s/#/aC/g' "src/$d/$f.h" | cpp -E $arg - | ${GP}sed 's/aC/#/g;s/aB/__/g;s/aA/a/g' > $tempfile
34+
if [[ "$REMOVE_COMMENTS" =~ YES ]]; then
35+
${GP}sed 's/a/aA/g;s/__/aB/g;s/#/aC/g' "src/$d/$f.h" | cpp -E $arg - | ${GP}sed 's/aC/#/g;s/aB/__/g;s/aA/a/g' > $tempfile
36+
else
37+
cp "src/$d/$f.h" $tempfile
38+
fi
1939

2040
# Remove override keyword
2141
${GP}sed -i 's/ override;/;/g' $tempfile
@@ -33,11 +53,14 @@ for file in $*; do
3353
${GP}sed -i -r '/^\s*Q_(OBJECT|ENUMS|PROPERTY).*?$/d' $tempfile
3454

3555
# Remove function definition in header
36-
${GP}sed -i -r 's/^(\s*)?(inline )?(void|bool|int|double|Q\w+)(\s+[^ ]*?\(.*?\)( const)?)\s*\{.*?\}$/\1\3\4;/g' $tempfile
56+
${GP}sed -i -r 's/^(\s*)?(virtual |static )?(inline )?(void|bool|int|double|Q\w+)(\s+[^ ]*?\(.*?\)( const)?)\s*\{.*?\}$/\1\2\4\5;/g' $tempfile
3757

3858
# Remove nullptr
3959
${GP}sed -i 's/nullptr/0/g' $tempfile
4060

61+
# Remove forward declarations
62+
${GP}sed -i -r '/^\s*class Q\w+;$/d' $tempfile
63+
4164
vimdiff $tempfile python/$d/$f.sip
4265

4366
rm $tempfile

0 commit comments

Comments
 (0)