From: Alexei Sheplyakov Date: Sat, 26 Feb 2011 08:39:29 +0000 (+0200) Subject: Parser: don't bother to generate 3 (C++) functions with autogen. X-Git-Tag: release_1-6-3~67^2~1 X-Git-Url: https://www.ginac.de/ginac.git//ginac.git?p=ginac.git;a=commitdiff_plain;h=4ec372a00b1a13e6374ce880cbd68c2e14114dad;hp=5146d1bd6eb0a93d6033c1a9b33b643c5faf15a6 Parser: don't bother to generate 3 (C++) functions with autogen. --- diff --git a/INSTALL b/INSTALL index 3be16c1f..3c188b66 100644 --- a/INSTALL +++ b/INSTALL @@ -30,8 +30,7 @@ Known not to work with: is missing there. If you install from git, you also need GNU autoconf (>=2.59), automake (>=1.8), -libtool (>= 1.5), bison (>= 2.3), flex (>= 2.5.33), autogen (>= 5.6.0) to be -installed. +libtool (>= 1.5), bison (>= 2.3), flex (>= 2.5.33) to be installed. INSTALLATION diff --git a/ginac/Makefile.am b/ginac/Makefile.am index bf20afc4..5f726351 100644 --- a/ginac/Makefile.am +++ b/ginac/Makefile.am @@ -13,7 +13,7 @@ libginac_la_SOURCES = add.cpp archive.cpp basic.cpp clifford.cpp color.cpp \ parser/parse_binop_rhs.cpp \ parser/parser.cpp \ parser/parse_context.cpp \ - parser/builtin_fcns.cpp \ + parser/default_reader.cpp \ parser/lexer.cpp \ parser/lexer.h \ parser/parser_compat.cpp \ @@ -67,22 +67,7 @@ ginacinclude_HEADERS = ginac.h add.h archive.h assertion.h basic.h class_info.h parser/parser.h \ parser/parse_context.h -EXTRA_DIST = function.pl version.h.in \ -parser/default_reader.tpl parser/builtin_fcns.def - -# Files produced by autogen(1) from templates -$(srcdir)/parser/builtin_fcns.cpp: $(srcdir)/parser/builtin_fcns.def $(srcdir)/parser/default_reader.tpl - set -e; if [ -n "$(AUTOGEN)" ]; then \ - cd $(srcdir)/parser; \ - $(AUTOGEN) -T default_reader.tpl builtin_fcns.def; \ - elif [ -f $@ ]; then \ - echo "WARNING: AutoGen is not available, the \"$@\" file WON'T be re-generated"; \ - else \ - echo "*** ERROR: the \"$@\" file does not exist, and AutoGen is not installed on your system"; \ - echo "*** Please install AutoGen (http://www.gnu.org/software/autogen)"; \ - exit 1; \ - fi - +EXTRA_DIST = function.pl version.h.in # Files which are generated by perl scripts $(srcdir)/function.h $(srcdir)/function.cpp: $(srcdir)/function.pl diff --git a/ginac/parser/builtin_fcns.def b/ginac/parser/builtin_fcns.def deleted file mode 100644 index 96cd0a24..00000000 --- a/ginac/parser/builtin_fcns.def +++ /dev/null @@ -1,14 +0,0 @@ -Autogen definitions ginacfcns; - -/* Thease are not functions, but anyway ... */ -function = { name = "sqrt"; }; - -function = { - name = "pow"; - args = 2; -}; - -function = { - name = "power"; - args = 2; -}; diff --git a/ginac/parser/default_reader.tpl b/ginac/parser/default_reader.cpp similarity index 61% rename from ginac/parser/default_reader.tpl rename to ginac/parser/default_reader.cpp index 006fb908..4f8c69c3 100644 --- a/ginac/parser/default_reader.tpl +++ b/ginac/parser/default_reader.cpp @@ -1,20 +1,26 @@ -[+ AutoGen5 template .cpp +][+ -COMMENT a part of GiNaC parser -- construct functions from a byte stream. -+][+ -(use-modules (ice-9 format)) +/** @file default_reader.cpp + * + * Implementation of the default and builtin readers (part of GiNaC's parser). + **/ -(define (sequence start end . step) - (let ((step (if (null? step) 1 (car step)))) - (let loop ((n start)) - (if (> n end) '() (cons n (loop (+ step n))))))) -+]/* -[+ (dne " * " " * " ) +] +/* + * GiNaC Copyright (C) 1999-2011 Johannes Gutenberg University Mainz, Germany + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. * - * If you want to change this file, edit either `[+ (def-file) +]' or - * `[+ (tpl-file) +]' file, and run the following command: + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * autogen -T [+ (tpl-file) +] [+ (def-file) +] + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ + #include "parse_context.h" #include "power.h" #include "operators.h" @@ -29,16 +35,24 @@ COMMENT a part of GiNaC parser -- construct functions from a byte stream. namespace GiNaC { -[+ FOR function +] -static ex [+ (get "name") +]_reader(const exvector& ev) + +static ex sqrt_reader(const exvector& ev) +{ + return GiNaC::sqrt(ev[0]); +} +static ex pow_reader(const exvector& ev) +{ + return GiNaC::pow(ev[0], ev[1]); +} +static ex power_reader(const exvector& ev) { - return GiNaC::[+ (get "name") +]([+ - (let ((nargs (if (exist? "args") - (string->number (get "args")) 1))) - (format '#f "~{ev[~a]~^, ~}" (sequence 0 (- nargs 1)))) +]); -}[+ ENDFOR +] + return GiNaC::power(ev[0], ev[1]); +} + // function::registered_functions() is protected, but we need to access it +// TODO: add a proper const method to the `function' class, so we don't +// need this silly hack any more. class registered_functions_hack : public function { public: @@ -69,11 +83,10 @@ const prototype_table& get_default_reader() static bool initialized = false; static prototype_table reader; if (!initialized) { - [+ FOR function +] - reader[make_pair("[+ (get "name") +]", [+ - (if (exist? "args") (get "args") "1") - +])] = [+ (get "name") +]_reader;[+ - ENDFOR +] + + reader[make_pair("sqrt", 1)] = sqrt_reader; + reader[make_pair("pow", 2)] = pow_reader; + reader[make_pair("power", 2)] = power_reader; std::vector::const_iterator it = registered_functions_hack::get_registered_functions().begin(); std::vector::const_iterator end = @@ -95,11 +108,10 @@ const prototype_table& get_builtin_reader() static bool initialized = false; static prototype_table reader; if (!initialized) { - [+ FOR function +] - reader[make_pair("[+ (get "name") +]", [+ - (if (exist? "args") (get "args") "1") - +])] = [+ (get "name") +]_reader;[+ - ENDFOR +] + + reader[make_pair("sqrt", 1)] = sqrt_reader; + reader[make_pair("pow", 2)] = pow_reader; + reader[make_pair("power", 2)] = power_reader; enum { log, exp,