aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Piotr Jaroszyński <peper@gentoo.org> 2007-10-08 20:26:55 +0000
committerAvatar Piotr Jaroszyński <peper@gentoo.org> 2007-10-08 20:26:55 +0000
commit1bdf09699a222f8c97163ef6fd75a16533abf578 (patch)
treeeb5739c52775de13dfcd4b25181494eb5d47021a
parent7013a78602e95afd0a83b3144a6c63c9276ff29b (diff)
downloadpaludis-1bdf09699a222f8c97163ef6fd75a16533abf578.tar.gz
paludis-1bdf09699a222f8c97163ef6fd75a16533abf578.tar.xz
Add NiceNames generator.
-rwxr-xr-xmisc/make_nn.bash94
1 files changed, 94 insertions, 0 deletions
diff --git a/misc/make_nn.bash b/misc/make_nn.bash
new file mode 100755
index 0000000..e994fc4
--- /dev/null
+++ b/misc/make_nn.bash
@@ -0,0 +1,94 @@
+#!/bin/bash
+# vim: set sw=4 sts=4 et tw=0 :
+
+echo -n "/* vim"
+echo ": set ro : */"
+echo
+echo "/* ******************************************************** */"
+echo "/* THIS IS A GENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY */"
+echo "/* ******************************************************** */"
+
+what_to_make=${1}
+shift
+
+include_cc() {
+ if [[ "${what_to_make}" == "--source" ]] ; then
+ echo
+ cat
+ echo
+ fi
+}
+
+include_hh() {
+ if [[ "${what_to_make}" == "--header" ]] ; then
+ echo
+ cat
+ echo
+ fi
+}
+
+use_namespace() {
+ if [[ "${what_to_make}" == "--source" ]] ; then
+ echo "using namespace $1;"
+ fi
+}
+
+if ! source ${1} ; then
+ echo "source ${1} failed" 1>&2
+ exit 7
+fi
+
+set | grep '^make_nn_.*() $' | sort -r | \
+while read name ; do
+ name=${name##make_nn_}
+ name=${name%% *}
+
+ if [[ "${what_to_make}" == "--header" ]] ; then
+ namespace() {
+ a=${1//::/ }
+ echo
+ for ns in ${a}; do
+ echo "${indent}namespace ${ns}"
+ echo "${indent}{"
+ indent+=" "
+ done
+
+ echo "${indent}template <typename>"
+ echo "${indent}struct ${name};"
+ }
+
+ name() {
+ class=$1
+ echo
+ echo "${indent}template<>"
+ echo "${indent}struct ${name}<${class}>"
+ echo "${indent}{"
+ echo "${indent} static const char * name;"
+ echo "${indent}};"
+ }
+
+ make_nn_${name}
+
+ while [[ -n ${indent} ]]; do
+ indent=${indent/ }
+ echo "${indent}}"
+ done
+
+ elif [[ "${what_to_make}" == "--source" ]] ; then
+ namespace() {
+ ns="${1}::"
+ }
+
+ name() {
+ class=$1
+ class_name=${2:-$1}
+ echo "const char * ${ns}${name}<${class}>::name = \"${class_name}\";"
+ }
+
+ echo
+ make_nn_${name}
+ else
+ echo "bad argument (expected --header or --source)" 1>&2
+ exit 1
+ fi
+done