#!/bin/bash # # mkkind # Morgan Deters for CVC4 # Copyright (c) 2010-2011 The CVC4 Project # # The purpose of this script is to create kind.h from a template and a # list of theory kinds. # # Invocation: # # mkkind template-file theory-kind-files... # # Output is to standard out. # copyright=2010-2011 cat <&2 exit 1 fi seen_theory_builtin=true elif [ -z "$1" -o -z "$2" -o -z "$3" ]; then echo "$kf:$lineno: error: \"theory\" directive missing class or header argument" >&2 exit 1 elif ! expr "$2" : '\(::*\)' >/dev/null; then echo "$kf:$lineno: warning: theory class \`$2' isn't fully-qualified (e.g., ::CVC4::theory::foo)" >&2 elif ! expr "$2" : '\(::CVC4::theory::*\)' >/dev/null; then echo "$kf:$lineno: warning: theory class not under ::CVC4::theory namespace" >&2 fi theory_id="$1" theory_enum="${theory_enum} $1, " theory_descriptions="${theory_descriptions} case ${theory_id}: out << \"${theory_id}\"; break; " } function properties { # rewriter class header lineno=${BASH_LINENO[0]} check_theory_seen } function endtheory { # endtheory lineno=${BASH_LINENO[0]} check_theory_seen } function rewriter { # properties prop* lineno=${BASH_LINENO[0]} check_theory_seen } function sort { # sort TYPE ["comment"] lineno=${BASH_LINENO[0]} check_theory_seen register_sort "$1" "$2" } function variable { # variable K ["comment"] lineno=${BASH_LINENO[0]} check_theory_seen register_kind "$1" 0 "$2" } function operator { # operator K #children ["comment"] lineno=${BASH_LINENO[0]} check_theory_seen register_kind "$1" "$2" "$3" } function parameterized { # parameterized K1 K2 #children ["comment"] lineno=${BASH_LINENO[0]} check_theory_seen register_kind "$1" "$3" "$4" } function constant { # constant K T Hasher header ["comment"] lineno=${BASH_LINENO[0]} check_theory_seen register_kind "$1" 0 "$5" } function register_sort { id=$1 comment=$2 type_constant_list="${type_constant_list} ${id}, /**< ${comment} */ " type_constant_descriptions="${type_constant_descriptions} case $id: out << \"${comment}\"; break; " type_constant_to_theory_id="${type_constant_to_theory_id} case $id: return $theory_id; break; " } function register_kind { r=$1 nc=$2 comment=$3 kind_decls="${kind_decls} $r, /**< $comment */ " kind_printers="${kind_printers} case $r: out << \"$r\"; break; " kind_to_theory_id="${kind_to_theory_id} case kind::$r: return $theory_id; break; " } function check_theory_seen { if ! $seen_theory; then echo "$kf:$lineno: error: no \"theory\" declaration found (it has to be first)" >&2 exit 1 fi } function check_builtin_theory_seen { if ! $seen_theory_builtin; then echo "$me: warning: no declaration for the builtin theory found" >&2 fi } while [ $# -gt 0 ]; do kf=$1 seen_theory=false b=$(basename $(dirname "$kf")) kind_decls="${kind_decls} /* from $b */ " kind_printers="${kind_printers} /* from $b */ " source "$kf" check_theory_seen shift done check_builtin_theory_seen ## output text=$(cat "$template") for var in kind_decls kind_printers kind_to_theory_id theory_enum type_constant_list type_constant_descriptions type_constant_to_theory_id theory_descriptions; do eval text="\${text//\\\$\\{$var\\}/\${$var}}" done error=`expr "$text" : '.*\${\([^}]*\)}.*'` if [ -n "$error" ]; then echo "$template:0: error: undefined replacement \${$error}" >&2 exit 1 fi echo "$text"