4 # Morgan Deters <mdeters@cs.nyu.edu> for CVC4
5 # Copyright (c) 2010-2013 The CVC4 Project
7 # The purpose of this script is to create theory_traits.h from a template
8 # and a list of theory kinds.
12 # mktheorytraits template-file theory-kind-files...
14 # Output is to standard out.
19 filename
=`basename "$1" | sed 's,_template,,'`
22 /********************* */
25 ** Copyright $copyright New York University and The University of Iowa,
28 ** This header file automatically generated by:
32 ** for the CVC4 project.
45 type_enumerator_includes
=
46 mk_type_enumerator_cases
=
48 theory_has_check
="false"
49 theory_has_propagate
="false"
50 theory_has_ppStaticLearn
="false"
51 theory_has_notifyRestart
="false"
52 theory_has_presolve
="false"
53 theory_has_postsolve
="false"
55 theory_stable_infinite
="false"
58 theory_parametric
="false"
70 seen_theory_builtin
=false
75 lineno
=${BASH_LINENO[0]}
78 echo "$kf:$lineno: error: multiple theories defined in one file !?" >&2
82 # this script doesn't care about the theory class information, but
83 # makes does make sure it's there
85 if [ "$1" = THEORY_BUILTIN
]; then
86 if $seen_theory_builtin; then
87 echo "$kf:$lineno: error: \"builtin\" theory redefined" >&2
90 seen_theory_builtin
=true
91 elif [ -z "$1" -o -z "$2" -o -z "$3" ]; then
92 echo "$kf:$lineno: error: \"theory\" directive missing class or header argument" >&2
94 elif ! expr "$2" : '\(::*\)' >/dev
/null
; then
95 echo "$kf:$lineno: warning: theory class \`$2' isn't fully-qualified (e.g., ::CVC4::theory::foo)" >&2
96 elif ! expr "$2" : '\(::CVC4::theory::*\)' >/dev
/null
; then
97 echo "$kf:$lineno: warning: theory class not under ::CVC4::theory namespace" >&2
104 theory_includes
="${theory_includes}#include \"$theory_header\"
109 # alternate ID name T header
111 lineno
=${BASH_LINENO[0]}
113 if $seen_theory; then
114 echo "$kf:$lineno: error: multiple theories defined in one file !?" >&2
122 theory_includes
="${theory_includes}#include \"$theory_header\"
127 # rewriter class header
128 lineno
=${BASH_LINENO[0]}
134 theory_includes
="${theory_includes}#include \"$2\"
140 lineno
=${BASH_LINENO[0]}
145 theory_constructors
="${theory_constructors}
147 \$alternate_for_$theory_id
148 engine->addTheory< $theory_class >($theory_id);
152 theory_traits
="${theory_traits}
154 struct TheoryTraits<${theory_id}> {
155 // typedef ${theory_class} theory_class;
156 typedef ${rewriter_class} rewriter_class;
158 static const bool isStableInfinite = ${theory_stable_infinite};
159 static const bool isFinite = ${theory_finite};
160 static const bool isPolite = ${theory_polite};
161 static const bool isParametric = ${theory_parametric};
163 static const bool hasCheck = ${theory_has_check};
164 static const bool hasPropagate = ${theory_has_propagate};
165 static const bool hasPpStaticLearn = ${theory_has_ppStaticLearn};
166 static const bool hasNotifyRestart = ${theory_has_notifyRestart};
167 static const bool hasPresolve = ${theory_has_presolve};
168 static const bool hasPostsolve = ${theory_has_postsolve};
169 };/* struct TheoryTraits<${theory_id}> */
172 # warnings about theory content and properties
173 dir
="$(dirname "$kf")/../../"
174 if [ -e "$dir/$theory_header" ]; then
175 for function in check propagate ppStaticLearn notifyRestart presolve postsolve
; do
176 if eval "\$theory_has_$function"; then
177 grep '\<'"$function"' *\((\|;\)' "$dir/$theory_header" |
grep -vq '^ */\(/\|\*\)' ||
178 echo "$kf: warning: $theory_class has property \"$function\" in its kinds file but doesn't appear to declare the function" >&2
180 grep '\<'"$function"' *\((\|;\)' "$dir/$theory_header" |
grep -vq '^ */\(/\|\*\)' &&
181 echo "$kf: warning: $theory_class does not have property \"$function\" in its kinds file but appears to declare the function" >&2
185 echo "$me: warning: theory header \"$theory_header\" does not exist or is unreadable" >&2
188 theory_has_check
="false"
189 theory_has_propagate
="false"
190 theory_has_ppStaticLearn
="false"
191 theory_has_notifyRestart
="false"
192 theory_has_presolve
="false"
193 theory_has_postsolve
="false"
195 theory_stable_infinite
="false"
196 theory_finite
="false"
197 theory_polite
="false"
198 theory_parametric
="false"
209 lineno
=${BASH_LINENO[0]}
212 function enumerator
{
213 # enumerator KIND enumerator-class header
214 lineno
=${BASH_LINENO[0]}
216 type_enumerator_includes
="${type_enumerator_includes}
218 if expr "$type_constants" : '.* '"$1"' ' &>/dev
/null
; then
219 mk_type_enumerator_type_constant_cases
="${mk_type_enumerator_type_constant_cases}
221 return new $2(type, tep);
223 elif expr "$type_kinds" : '.* '"$1"' ' &>/dev
/null
; then
224 mk_type_enumerator_cases
="${mk_type_enumerator_cases}
226 return new $2(type, tep);
229 echo "$kf:$lineno: error: don't know anything about $1; enumerator must appear after definition" >&2
230 echo "type_constants: $type_constants" >&2
231 echo "type_kinds : $type_kinds" >&2
236 function typechecker
{
238 lineno
=${BASH_LINENO[0]}
243 # typerule OPERATOR typechecking-class
244 lineno
=${BASH_LINENO[0]}
249 # construle OPERATOR isconst-checking-class
250 lineno
=${BASH_LINENO[0]}
254 function properties
{
255 # properties property*
256 lineno
=${BASH_LINENO[0]}
262 finite
) theory_finite
="true";;
263 stable-infinite
) theory_stable_infinite
="true";;
264 parametric
) theory_parametric
="true";;
265 polite
) theory_polite
="true";;
266 check
) theory_has_check
="true";;
267 propagate
) theory_has_propagate
="true";;
268 ppStaticLearn
) theory_has_ppStaticLearn
="true";;
269 presolve
) theory_has_presolve
="true";;
270 postsolve
) theory_has_postsolve
="true";;
271 notifyRestart
) theory_has_notifyRestart
="true";;
272 *) echo "$kf:$lineno: error: unknown theory property \"$property\"" >&2; exit 1;;
279 # sort TYPE cardinality [well-founded ground-term header | not-well-founded] ["comment"]
280 lineno
=${BASH_LINENO[0]}
282 if [ "$3" = well-founded
]; then
283 register_sort
"$1" "$2" "$6"
285 register_sort
"$1" "$2" "$4"
289 function cardinality
{
290 # cardinality TYPE cardinality-computer [header]
291 lineno
=${BASH_LINENO[0]}
295 function well-founded
{
296 # well-founded TYPE wellfoundedness-computer [header]
297 lineno
=${BASH_LINENO[0]}
302 # variable K ["comment"]
303 lineno
=${BASH_LINENO[0]}
305 register_kind
"$1" 0 "$2"
309 # operator K #children ["comment"]
310 lineno
=${BASH_LINENO[0]}
312 register_kind
"$1" "$2" "$3"
315 function parameterized
{
316 # parameterized K1 K2 #children ["comment"]
317 lineno
=${BASH_LINENO[0]}
319 register_kind
"$1" "$3" "$4"
323 # constant K T Hasher header ["comment"]
324 lineno
=${BASH_LINENO[0]}
326 register_kind
"$1" 0 "$5"
329 function nullaryoperator
{
330 # nullaryoperator K ["comment"]
331 lineno
=${BASH_LINENO[0]}
333 register_kind
"$1" 0 "$2"
336 function register_sort
{
340 type_constant_to_theory_id
="${type_constant_to_theory_id} case $id: return $theory_id; break;
342 type_constants
="${type_constants} $1 "
345 function register_kind
{
349 kind_to_theory_id
="${kind_to_theory_id} case kind::$r: return $theory_id; break;
351 type_kinds
="${type_kinds} $1 "
354 function check_theory_seen
{
355 if $seen_endtheory; then
356 echo "$kf:$lineno: error: command after \"endtheory\" declaration (endtheory has to be last)" >&2
359 if ! $seen_theory; then
360 echo "$kf:$lineno: error: no \"theory\" declaration found (it has to be first)" >&2
365 function check_builtin_theory_seen
{
366 if ! $seen_theory_builtin; then
367 echo "$me: warning: no declaration for the builtin theory found" >&2
371 while [ $# -gt 0 ]; do
375 b
=$
(basename $
(dirname "$kf"))
377 if ! $seen_theory; then
378 echo "$kf: error: no theory content found in file!" >&2
381 if ! $seen_endtheory; then
382 echo "$kf:$lineno: error: no \"endtheory\" declaration found (it is required at the end)" >&2
387 check_builtin_theory_seen
391 eval "theory_constructors=\"$theory_constructors\""
393 text
=$
(cat "$template")
397 theory_constructors \
399 type_enumerator_includes \
400 mk_type_enumerator_type_constant_cases \
401 mk_type_enumerator_cases \
403 eval text
="\${text//\\\$\\{$var\\}/\${$var}}"
405 error
=`expr "$text" : '.*\${\([^}]*\)}.*'`
406 if [ -n "$error" ]; then
407 echo "$template:0: error: undefined replacement \${$error}" >&2