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.
42 pre_rewrite_get_cache
=
43 pre_rewrite_set_cache
=
45 post_rewrite_get_cache
=
46 post_rewrite_set_cache
=
48 pre_rewrite_attribute_ids
=
49 post_rewrite_attribute_ids
=
52 seen_theory_builtin
=false
57 lineno
=${BASH_LINENO[0]}
60 echo "$kf:$lineno: error: multiple theories defined in one file !?" >&2
64 # this script doesn't care about the theory class information, but
65 # makes does make sure it's there
67 if [ "$1" = THEORY_BUILTIN
]; then
68 if $seen_theory_builtin; then
69 echo "$kf:$lineno: error: \"builtin\" theory redefined" >&2
72 seen_theory_builtin
=true
73 elif [ -z "$1" -o -z "$2" -o -z "$3" ]; then
74 echo "$kf:$lineno: error: \"theory\" directive missing class or header argument" >&2
76 elif ! expr "$2" : '\(::*\)' >/dev
/null
; then
77 echo "$kf:$lineno: warning: theory class \`$2' isn't fully-qualified (e.g., ::CVC4::theory::foo)" >&2
78 elif ! expr "$2" : '\(::CVC4::theory::*\)' >/dev
/null
; then
79 echo "$kf:$lineno: warning: theory class not under ::CVC4::theory namespace" >&2
86 # alternate ID name T header
88 lineno
=${BASH_LINENO[0]}
91 echo "$kf:$lineno: error: multiple theories defined in one file !?" >&2
101 lineno
=${BASH_LINENO[0]}
107 lineno
=${BASH_LINENO[0]}
112 function enumerator
{
113 # enumerator KIND enumerator-class header
114 lineno
=${BASH_LINENO[0]}
118 function typechecker
{
120 lineno
=${BASH_LINENO[0]}
125 # typerule OPERATOR typechecking-class
126 lineno
=${BASH_LINENO[0]}
131 # construle OPERATOR isconst-checking-class
132 lineno
=${BASH_LINENO[0]}
137 # rewriter class header
141 rewriter_includes
="${rewriter_includes}#include \"$header\"
143 rewrite_init
="${rewrite_init} d_theoryRewriters[${theory_id}].reset(new ${class});
145 pre_rewrite_attribute_ids
="${pre_rewrite_attribute_ids} preids.push_back(expr::attr::AttributeManager::getAttributeId(RewriteAttibute<${theory_id}>::pre_rewrite()));
147 post_rewrite_attribute_ids
="${post_rewrite_attribute_ids} postids.push_back(expr::attr::AttributeManager::getAttributeId(RewriteAttibute<${theory_id}>::post_rewrite()));
150 pre_rewrite_get_cache
="${pre_rewrite_get_cache} case ${theory_id}: return RewriteAttibute<${theory_id}>::getPreRewriteCache(node);
152 pre_rewrite_set_cache
="${pre_rewrite_set_cache} case ${theory_id}: return RewriteAttibute<${theory_id}>::setPreRewriteCache(node, cache);
155 post_rewrite_get_cache
="${post_rewrite_get_cache} case ${theory_id}: return RewriteAttibute<${theory_id}>::getPostRewriteCache(node);
157 post_rewrite_set_cache
="${post_rewrite_set_cache} case ${theory_id}: return RewriteAttibute<${theory_id}>::setPostRewriteCache(node, cache);
160 lineno
=${BASH_LINENO[0]}
165 # sort TYPE cardinality [well-founded ground-term header | not-well-founded] ["comment"]
166 lineno
=${BASH_LINENO[0]}
170 function cardinality
{
171 # cardinality TYPE cardinality-computer [header]
172 lineno
=${BASH_LINENO[0]}
176 function well-founded
{
177 # well-founded TYPE wellfoundedness-computer [header]
178 lineno
=${BASH_LINENO[0]}
183 # variable K ["comment"]
184 lineno
=${BASH_LINENO[0]}
189 # operator K #children ["comment"]
190 lineno
=${BASH_LINENO[0]}
194 function parameterized
{
195 # parameterized K1 K2 #children ["comment"]
196 lineno
=${BASH_LINENO[0]}
201 # constant K T Hasher header ["comment"]
202 lineno
=${BASH_LINENO[0]}
206 function nullaryoperator
{
207 # nullaryoperator K ["comment"]
208 lineno
=${BASH_LINENO[0]}
212 function check_theory_seen
{
213 if $seen_endtheory; then
214 echo "$kf:$lineno: error: command after \"endtheory\" declaration (endtheory has to be last)" >&2
217 if ! $seen_theory; then
218 echo "$kf:$lineno: error: no \"theory\" declaration found (it has to be first)" >&2
223 function check_builtin_theory_seen
{
224 if ! $seen_theory_builtin; then
225 echo "$me: warning: no declaration for the builtin theory found" >&2
229 while [ $# -gt 0 ]; do
233 b
=$
(basename $
(dirname "$kf"))
235 if ! $seen_theory; then
236 echo "$kf: error: no theory content found in file!" >&2
239 if ! $seen_endtheory; then
240 echo "$kf:$lineno: error: no \"endtheory\" declaration found (it is required at the end)" >&2
245 check_builtin_theory_seen
249 # generate warnings about incorrect #line annotations in templates
250 nl -ba -s' ' "$template" |
grep '^ *[0-9][0-9]* # *line' |
251 awk '{OFS="";if($1+1!=$3) print "'"$template"':",$1,": warning: incorrect annotation \"#line ",$3,"\" (it should be \"#line ",($1+1),"\")"}' >&2
253 text
=$
(cat "$template")
256 pre_rewrite_get_cache \
257 post_rewrite_get_cache \
258 pre_rewrite_set_cache \
259 post_rewrite_set_cache \
261 pre_rewrite_attribute_ids \
262 post_rewrite_attribute_ids \
265 eval text
="\${text//\\\$\\{$var\\}/\${$var}}"
267 error
=`expr "$text" : '.*\${\([^}]*\)}.*'`
268 if [ -n "$error" ]; then
269 echo "$template:0: error: undefined replacement \${$error}" >&2