Issue 4377: Run a script for using derived_unsmob where obvious
Script is:
matched="[^()]*"
for i in 1 2 3 4 5
do
matched="\\(($matched)\\|[^()]\\)*"
done
filelist="$(git grep -l '\<dynamic_cast[^>]*> ([_a-zA-Z]*::unsmob\>')"
typelist="$(sed -n 's/^.*\<dynamic_cast\s*<\([_a-zA-Z]\+\)\s*\*> (\([_a-zA-Z]*\)::unsmob\>.*$/\1/p' $filelist | sort -u )"
for typ in $typelist
do
# crazy: we have unsmob definitions that are not even used
if git grep -q "$typ::unsmob" || git grep -q "\\<$typ"'\s*\*\s*unsmob\s*(SCM'
then
echo "There already is $typ::unsmob"
sed -i '/unsmob (SCM/,/;/!s/\<dynamic_cast\s*<\('"$typ"'\)\s*\*> (\([_a-zA-Z]*\)::unsmob\s*(\('"$matched"'\))\s*)/\1::unsmob (\3)/g' $filelist
else
sed -i 's/\<dynamic_cast\s*<\('"$typ"'\)\s*\*> (\([_a-zA-Z]*\)::unsmob\s*(\('"$matched"'\))\s*)/derived_unsmob<\1> (\3)/g' $filelist
fi
done
The awkward bit at the start of the script is for matching matched
parentheses. This replaces the construct
dynamic_cast<T *>(xxx::unsmob (yyy))
with
derived_unsmob<T> (yyy)
where appropriate. If T::unsmob already exists, it is used
instead (apart from inside of its own definition, of course).