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 rewriter_tables.h from a template
8 # and a list of theory kinds.
12 # mkrewriter template-file theory-kind-files...
14 # Output is to standard out.
20 /********************* */
23 ** Copyright $copyright New York University and The University of Iowa,
26 ** This header file automatically generated by:
30 ** for the CVC4 project.
41 pre_rewrite_get_cache
=
42 pre_rewrite_set_cache
=
44 post_rewrite_get_cache
=
45 post_rewrite_set_cache
=
47 pre_rewrite_attribute_ids
=
48 post_rewrite_attribute_ids
=
51 seen_theory_builtin
=false
56 lineno
=${BASH_LINENO[0]}
59 echo "$kf:$lineno: error: multiple theories defined in one file !?" >&2
63 # this script doesn't care about the theory class information, but
64 # makes does make sure it's there
66 if [ "$1" = THEORY_BUILTIN
]; then
67 if $seen_theory_builtin; then
68 echo "$kf:$lineno: error: \"builtin\" theory redefined" >&2
71 seen_theory_builtin
=true
72 elif [ -z "$1" -o -z "$2" -o -z "$3" ]; then
73 echo "$kf:$lineno: error: \"theory\" directive missing class or header argument" >&2
75 elif ! expr "$2" : '\(::*\)' >/dev
/null
; then
76 echo "$kf:$lineno: warning: theory class \`$2' isn't fully-qualified (e.g., ::CVC4::theory::foo)" >&2
77 elif ! expr "$2" : '\(::CVC4::theory::*\)' >/dev
/null
; then
78 echo "$kf:$lineno: warning: theory class not under ::CVC4::theory namespace" >&2
85 # alternate ID name T header
87 lineno
=${BASH_LINENO[0]}
90 echo "$kf:$lineno: error: multiple theories defined in one file !?" >&2
100 lineno
=${BASH_LINENO[0]}
106 lineno
=${BASH_LINENO[0]}
111 function enumerator
{
112 # enumerator KIND enumerator-class header
113 lineno
=${BASH_LINENO[0]}
117 function typechecker
{
119 lineno
=${BASH_LINENO[0]}
124 # typerule OPERATOR typechecking-class
125 lineno
=${BASH_LINENO[0]}
130 # construle OPERATOR isconst-checking-class
131 lineno
=${BASH_LINENO[0]}
136 # rewriter class header
140 rewriter_includes
="${rewriter_includes}#include \"$header\"
142 pre_rewrite_attribute_ids
="${pre_rewrite_attribute_ids} preids.push_back(expr::attr::AttributeManager::getAttributeId(RewriteAttibute<${theory_id}>::pre_rewrite()));
144 post_rewrite_attribute_ids
="${post_rewrite_attribute_ids} postids.push_back(expr::attr::AttributeManager::getAttributeId(RewriteAttibute<${theory_id}>::post_rewrite()));
147 pre_rewrite_get_cache
="${pre_rewrite_get_cache} case ${theory_id}: return RewriteAttibute<${theory_id}>::getPreRewriteCache(node);
149 pre_rewrite_set_cache
="${pre_rewrite_set_cache} case ${theory_id}: return RewriteAttibute<${theory_id}>::setPreRewriteCache(node, cache);
152 post_rewrite_get_cache
="${post_rewrite_get_cache} case ${theory_id}: return RewriteAttibute<${theory_id}>::getPostRewriteCache(node);
154 post_rewrite_set_cache
="${post_rewrite_set_cache} case ${theory_id}: return RewriteAttibute<${theory_id}>::setPostRewriteCache(node, cache);
157 lineno
=${BASH_LINENO[0]}
162 # sort TYPE cardinality [well-founded ground-term header | not-well-founded] ["comment"]
163 lineno
=${BASH_LINENO[0]}
167 function cardinality
{
168 # cardinality TYPE cardinality-computer [header]
169 lineno
=${BASH_LINENO[0]}
173 function well-founded
{
174 # well-founded TYPE wellfoundedness-computer [header]
175 lineno
=${BASH_LINENO[0]}
180 # variable K ["comment"]
181 lineno
=${BASH_LINENO[0]}
186 # operator K #children ["comment"]
187 lineno
=${BASH_LINENO[0]}
191 function parameterized
{
192 # parameterized K1 K2 #children ["comment"]
193 lineno
=${BASH_LINENO[0]}
198 # constant K T Hasher header ["comment"]
199 lineno
=${BASH_LINENO[0]}
203 function nullaryoperator
{
204 # nullaryoperator K ["comment"]
205 lineno
=${BASH_LINENO[0]}
209 function check_theory_seen
{
210 if $seen_endtheory; then
211 echo "$kf:$lineno: error: command after \"endtheory\" declaration (endtheory has to be last)" >&2
214 if ! $seen_theory; then
215 echo "$kf:$lineno: error: no \"theory\" declaration found (it has to be first)" >&2
220 function check_builtin_theory_seen
{
221 if ! $seen_theory_builtin; then
222 echo "$me: warning: no declaration for the builtin theory found" >&2
226 while [ $# -gt 0 ]; do
230 b
=$
(basename $
(dirname "$kf"))
232 if ! $seen_theory; then
233 echo "$kf: error: no theory content found in file!" >&2
236 if ! $seen_endtheory; then
237 echo "$kf:$lineno: error: no \"endtheory\" declaration found (it is required at the end)" >&2
242 check_builtin_theory_seen
246 text
=$
(cat "$template")
249 pre_rewrite_get_cache \
250 post_rewrite_get_cache \
251 pre_rewrite_set_cache \
252 post_rewrite_set_cache \
253 pre_rewrite_attribute_ids \
254 post_rewrite_attribute_ids \
257 eval text
="\${text//\\\$\\{$var\\}/\${$var}}"
259 error
=`expr "$text" : '.*\${\([^}]*\)}.*'`
260 if [ -n "$error" ]; then
261 echo "$template:0: error: undefined replacement \${$error}" >&2