From 008b88abd1d1c2a4b44053bad71654fbade787b2 Mon Sep 17 00:00:00 2001 From: Morgan Deters Date: Fri, 10 Feb 2012 23:36:07 +0000 Subject: [PATCH] script to ease creating a new theory from scratch (will go along with new reference documentation) --- contrib/Makefile.am | 2 + contrib/new-theory | 329 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 331 insertions(+) create mode 100755 contrib/new-theory diff --git a/contrib/Makefile.am b/contrib/Makefile.am index 42e3b6f9f..66d62f8b8 100644 --- a/contrib/Makefile.am +++ b/contrib/Makefile.am @@ -6,5 +6,7 @@ EXTRA_DIST = \ cvc-mode.el \ editing-with-emacs \ luby.c \ + addsourcedir \ + new-theory \ configure-in-place \ depgraph diff --git a/contrib/new-theory b/contrib/new-theory new file mode 100755 index 000000000..6488eaec9 --- /dev/null +++ b/contrib/new-theory @@ -0,0 +1,329 @@ +#!/bin/sh +# +# usage: new-theory theory-directory-name +# + +cd "`dirname "$0"`/.." + +if [ ! -e src/theory/theory_engine.h ]; then + echo "ERROR: This script doesn't appear to be the contrib/ subdirectory" >&2 + echo "ERROR: of the CVC4 source tree." >&2 + exit 1 +fi + +if [ $# -ne 1 ]; then + echo "usage: new-theory theory-directory-name" >&2 + echo "e.g.: new-theory arith" >&2 + echo "e.g.: new-theory arrays" >&2 + echo "e.g.: new-theory sets" >&2 + echo >&2 + echo "This tool will create a new src/theory/" >&2 + echo "directory and fill in some infrastructural files in that directory." >&2 + echo "It also will incorporate that directory into the build process." >&2 + echo "Please refer to the file README.WHATS-NEXT file created in that" >&2 + echo "directory for tips on what to do next." + exit 1 +fi + +dir="$1" + +if [ -e "src/theory/$dir" ]; then + echo "ERROR: Theory \"$dir\" already exists." >&2 + echo "ERROR: Please choose a new directory name (or move that one aside)." >&2 + exit 1 +fi + +if ! expr "$dir" : '[a-zA-Z][a-zA-Z0-9_]*$' &>/dev/null || + expr "$dir" : '_$' &>/dev/null; then + echo "ERROR: \"$dir\" is not a valid theory name." >&2 + echo "ERROR:" >&2 + echo "ERROR: Theory names must start with a letter and be composed of" >&2 + echo "ERROR: letters, numbers, and the underscore (_) character; an" >&2 + echo "ERROR: underscore cannot be the final character." >&2 + exit 1 +fi + +id="`echo "$dir" | tr a-z A-Z`" +# convoluted, but should be relatively portable and give a CamelCase +# representation for a string. (e.g. "foo_bar" becomes "FooBar") +camel="`echo "$dir" | awk 'BEGIN { RS="_";ORS="";OFS="" } // {print toupper(substr($1,1,1)),substr($1,2,length($1))} END {print "\n"}'`" + +if ! mkdir "src/theory/$dir"; then + echo "ERROR: encountered an error creating directory src/theory/$dir" >&2 + exit 1 +fi + +echo "Theory directory: src/theory/$dir" +echo "Theory id: THEORY_$id" +echo "Theory class: CVC4::theory::$dir::Theory$camel" +echo "Theory string: Theory of $dir" +echo + +echo "Creating src/theory/$dir/Makefile..." +cat > "src/theory/$dir/Makefile" < "src/theory/$dir/Makefile.am" < "src/theory/$dir/kinds" < "src/theory/$dir/theory_${dir}_type_rules.h" < "src/theory/$dir/theory_${dir}_rewriter.h" < "src/theory/$dir/theory_$dir.h" < "src/theory/$dir/theory_$dir.cpp" </dev/null; then + echo "NOTE: src/theory/Makefile.am already descends into dir $dir" +else + awk '/^SUBDIRS = / {print $0,"'"$dir"'"} !/^SUBDIRS = / {print$0}' src/theory/Makefile.am > src/theory/Makefile.am.new-theory + if ! cp -f src/theory/Makefile.am src/theory/Makefile.am~; then + echo "ERROR: cannot copy src/theory/Makefile.am !" >&2 + exit 1 + fi + if ! mv -f src/theory/Makefile.am.new-theory src/theory/Makefile.am; then + echo "ERROR: cannot replace src/theory/Makefile.am !" >&2 + exit 1 + fi +fi + -- 2.30.2