1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314
|
#!/usr/bin/env bash
#
# mkexpr
# Morgan Deters <mdeters@cs.nyu.edu> for CVC4
# Copyright (c) 2010-2013 The CVC4 Project
#
# The purpose of this script is to create {expr,expr_manager}.{h,cpp}
# from template files and a list of theory kinds. Basically it just
# sets up the public interface for access to constants.
#
# Invocation:
#
# mkexpr template-file theory-kind-files...
#
# Output is to standard out.
#
copyright=2010-2014
filename=`basename "$1" | sed 's,_template,,'`
template_rel="<CVC4>/"$(realpath --relative-to $CMAKE_SOURCE_DIR $1)
cat <<EOF
/********************* */
/** $filename
**
** Copyright $copyright New York University and The University of Iowa,
** and as below.
**
** This file automatically generated
** for the CVC4 project.
**/
/* THIS FILE IS AUTOMATICALLY GENERATED, DO NOT EDIT ! */
/* THIS FILE IS AUTOMATICALLY GENERATED, DO NOT EDIT ! */
/* THIS FILE IS AUTOMATICALLY GENERATED, DO NOT EDIT ! */
/* THIS FILE IS AUTOMATICALLY GENERATED, DO NOT EDIT ! */
/* THIS FILE IS AUTOMATICALLY GENERATED, DO NOT EDIT ! */
/* THIS FILE IS AUTOMATICALLY GENERATED, DO NOT EDIT ! */
/* THIS FILE IS AUTOMATICALLY GENERATED, DO NOT EDIT ! */
/* THIS FILE IS AUTOMATICALLY GENERATED, DO NOT EDIT ! */
/* THIS FILE IS AUTOMATICALLY GENERATED, DO NOT EDIT ! */
/* THIS FILE IS AUTOMATICALLY GENERATED, DO NOT EDIT ! */
/* THIS FILE IS AUTOMATICALLY GENERATED, DO NOT EDIT ! */
/* THIS FILE IS AUTOMATICALLY GENERATED, DO NOT EDIT ! */
/* Edit the template file instead: */
/* $template_rel */
EOF
me=$(basename "$0")
template=$1; shift
includes=
getConst_instantiations=
getConst_implementations=
mkConst_instantiations=
mkConst_implementations=
exportConstant_cases=
typerules=
construles=
seen_theory=false
seen_theory_builtin=false
function theory {
# theory ID T header
lineno=${BASH_LINENO[0]}
if $seen_theory; then
echo "$kf:$lineno: error: multiple theories defined in one file !?" >&2
exit 1
fi
# this script doesn't care about the theory class information, but
# makes does make sure it's there
seen_theory=true
if [ "$1" = THEORY_BUILTIN ]; then
if $seen_theory_builtin; then
echo "$kf:$lineno: error: \"builtin\" theory redefined" >&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
}
function alternate {
# alternate ID name T header
lineno=${BASH_LINENO[0]}
if $seen_theory; then
echo "$kf:$lineno: error: multiple theories defined in one file !?" >&2
exit 1
fi
seen_theory=true
seen_endtheory=true
}
function rewriter {
# rewriter class header
lineno=${BASH_LINENO[0]}
check_theory_seen
}
function properties {
# properties prop*
lineno=${BASH_LINENO[0]}
check_theory_seen
}
function endtheory {
# endtheory
lineno=${BASH_LINENO[0]}
check_theory_seen
seen_endtheory=true
}
function enumerator {
# enumerator KIND enumerator-class header
lineno=${BASH_LINENO[0]}
check_theory_seen
}
function typechecker {
# typechecker header
lineno=${BASH_LINENO[0]}
check_theory_seen
typechecker_includes="${typechecker_includes}
#include \"$1\""
}
function typerule {
# typerule OPERATOR typechecking-class
lineno=${BASH_LINENO[0]}
check_theory_seen
typerules="${typerules}
#line $lineno \"$kf_rel\"
case kind::$1:
#line $lineno \"$kf_rel\"
typeNode = $2::computeType(nodeManager, n, check);
break;
"
}
function construle {
# isconst OPERATOR isconst-checking-class
lineno=${BASH_LINENO[0]}
check_theory_seen
construles="${construles}
#line $lineno \"$kf_rel\"
case kind::$1:
#line $lineno \"$kf_rel\"
return $2::computeIsConst(nodeManager, n);
"
}
function sort {
# sort TYPE cardinality [well-founded ground-term header | not-well-founded] ["comment"]
lineno=${BASH_LINENO[0]}
check_theory_seen
}
function cardinality {
# cardinality TYPE cardinality-computer [header]
lineno=${BASH_LINENO[0]}
check_theory_seen
}
function well-founded {
# well-founded TYPE wellfoundedness-computer [header]
lineno=${BASH_LINENO[0]}
check_theory_seen
}
function variable {
# variable K ["comment"]
lineno=${BASH_LINENO[0]}
check_theory_seen
}
function operator {
# operator K #children ["comment"]
lineno=${BASH_LINENO[0]}
check_theory_seen
}
function parameterized {
# parameterized K #children ["comment"]
lineno=${BASH_LINENO[0]}
check_theory_seen
}
function constant {
# constant K T Hasher header ["comment"]
lineno=${BASH_LINENO[0]}
check_theory_seen
# Only add include if it is not in the list of includes yet
if [[ "${includes}" != *"#include \"$4\""* ]]; then
includes="${includes}
#include \"$4\""
fi
mkConst_instantiations="${mkConst_instantiations}
#line $lineno \"$kf_rel\"
template <> Expr ExprManager::mkConst($2 const& val);
"
mkConst_implementations="${mkConst_implementations}
#line $lineno \"$kf_rel\"
template <> Expr ExprManager::mkConst($2 const& val) {
#line $lineno \"$kf_rel \"
return Expr(this, new Node(d_nodeManager->mkConst< $2 >(val)));
}
"
getConst_instantiations="${getConst_instantiations}
#line $lineno \"$kf_rel\"
template <> $2 const & Expr::getConst< $2 >() const;
"
getConst_implementations="${getConst_implementations}
#line $lineno \"$kf_rel\"
template <> $2 const & Expr::getConst() const {
#line $lineno \"$kf_rel\"
PrettyCheckArgument(getKind() == ::CVC4::kind::$1, *this, \"Improper kind for getConst<$2>()\");
#line $lineno \"$kf_rel\"
return d_node->getConst< $2 >();
}
"
exportConstant_cases="${exportConstant_cases}
case $1: return to->mkConst(n.getConst< $2 >());"
}
function nullaryoperator {
# nullaryoperator K ["comment"]
lineno=${BASH_LINENO[0]}
check_theory_seen
}
function check_theory_seen {
if $seen_endtheory; then
echo "$kf:$lineno: error: command after \"endtheory\" declaration (endtheory has to be last)" >&2
exit 1
fi
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
kf_rel="<CVC4>/"$(realpath --relative-to "$CMAKE_SOURCE_DIR" $kf)
seen_theory=false
seen_endtheory=false
b=$(basename $(dirname "$kf"))
source "$kf"
if ! $seen_theory; then
echo "$kf: error: no theory content found in file!" >&2
exit 1
fi
if ! $seen_endtheory; then
echo "$kf:$lineno: error: no \"endtheory\" declaration found (it is required at the end)" >&2
exit 1
fi
shift
done
check_builtin_theory_seen
## output
# generate warnings about incorrect #line annotations in templates
nl -ba -s' ' "$template" | grep '^ *[0-9][0-9]* # *line' |
awk '{OFS="";if($1+1!=$3) print "'"$template"':",$1,": warning: incorrect annotation \"#line ",$3,"\" (it should be \"#line ",($1+1),"\")"}' >&2
text=$(cat "$template")
for var in \
includes \
template_rel \
getConst_instantiations \
getConst_implementations \
mkConst_instantiations \
mkConst_implementations \
exportConstant_cases \
typechecker_includes \
typerules \
construles \
; 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"
|