[GiNaC-devel] [PATCH 2/3] Parser: don't bother to generate 3 (C++) functions with autogen.

Alexei Sheplyakov alexei.sheplyakov at gmail.com
Sun May 22 14:15:42 CEST 2011


---
 INSTALL                         |    3 +-
 ginac/Makefile.am               |   19 +----
 ginac/parser/builtin_fcns.def   |   14 ----
 ginac/parser/default_reader.cpp |  157 +++++++++++++++++++++++++++++++++++++++
 ginac/parser/default_reader.tpl |  145 ------------------------------------
 5 files changed, 160 insertions(+), 178 deletions(-)
 delete mode 100644 ginac/parser/builtin_fcns.def
 create mode 100644 ginac/parser/default_reader.cpp
 delete mode 100644 ginac/parser/default_reader.tpl

diff --git a/INSTALL b/INSTALL
index 3be16c1..3c188b6 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 bc2e1b8..dce098d 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 96cd0a2..0000000
--- 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.cpp b/ginac/parser/default_reader.cpp
new file mode 100644
index 0000000..4f8c69c
--- /dev/null
+++ b/ginac/parser/default_reader.cpp
@@ -0,0 +1,157 @@
+/** @file default_reader.cpp
+ *
+ *  Implementation of the default and builtin readers (part of GiNaC's parser).
+ **/
+
+/*
+ *  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.
+ *
+ *  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.
+ *
+ *  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"
+#include "inifcns.h"
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#ifdef HAVE_STDINT_H
+#include <stdint.h> // for uintptr_t
+#endif
+
+namespace GiNaC
+{
+
+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::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:
+	static const std::vector<function_options>& get_registered_functions()
+	{
+		return function::registered_functions();
+	}
+private:
+	registered_functions_hack();
+	registered_functions_hack(const registered_functions_hack&);
+	registered_functions_hack& operator=(const registered_functions_hack&);
+};
+
+// Encode an integer into a pointer to a function. Since functions
+// are aligned (the minimal alignment depends on CPU architecture)
+// we can distinguish between pointers and integers.
+static reader_func encode_serial_as_reader_func(unsigned serial)
+{
+	uintptr_t u = (uintptr_t)serial;
+	u = (u << 1) | (uintptr_t)1;
+	reader_func ptr = (reader_func)((void *)u);
+	return ptr;
+}
+
+const prototype_table& get_default_reader()
+{
+	using std::make_pair;
+	static bool initialized = false;
+	static prototype_table reader;
+	if (!initialized) {
+		
+		reader[make_pair("sqrt", 1)] = sqrt_reader;
+		reader[make_pair("pow", 2)] = pow_reader;
+		reader[make_pair("power", 2)] = power_reader;
+		std::vector<function_options>::const_iterator it =
+			registered_functions_hack::get_registered_functions().begin();
+		std::vector<function_options>::const_iterator end =
+			registered_functions_hack::get_registered_functions().end();
+		unsigned serial = 0;
+		for (; it != end; ++it) {
+			prototype proto = make_pair(it->get_name(), it->get_nparams());
+			reader[proto] = encode_serial_as_reader_func(serial);
+			++serial;
+		}
+		initialized = true;
+	}
+	return reader;
+}
+
+const prototype_table& get_builtin_reader()
+{
+	using std::make_pair;
+	static bool initialized = false;
+	static prototype_table reader;
+	if (!initialized) {
+		
+		reader[make_pair("sqrt", 1)] = sqrt_reader;
+		reader[make_pair("pow", 2)] = pow_reader;
+		reader[make_pair("power", 2)] = power_reader;
+		enum {
+			log,
+			exp,
+			sin,
+			cos,
+			tan,
+			asin,
+			acos,
+			atan,
+			sinh,
+			cosh,
+			tanh,
+			asinh,
+			acosh,
+			atanh,
+			atan2,
+			Li2,
+			Li3,
+			zetaderiv,
+			Li,
+			S,
+			H,
+			lgamma,
+			tgamma,
+			beta,
+			factorial,
+			binomial,
+			Order,
+			NFUNCTIONS
+		};
+		std::vector<function_options>::const_iterator it =
+			registered_functions_hack::get_registered_functions().begin();
+		unsigned serial = 0;
+		for ( ; serial<NFUNCTIONS; ++it, ++serial ) {
+			prototype proto = make_pair(it->get_name(), it->get_nparams());
+			reader[proto] = encode_serial_as_reader_func(serial);
+		}
+		initialized = true;
+	}
+	return reader;
+}
+
+} // namespace GiNaC
diff --git a/ginac/parser/default_reader.tpl b/ginac/parser/default_reader.tpl
deleted file mode 100644
index 006fb90..0000000
--- a/ginac/parser/default_reader.tpl
+++ /dev/null
@@ -1,145 +0,0 @@
-[+ AutoGen5 template .cpp +][+ 
-COMMENT a part of GiNaC parser -- construct functions from a byte stream.
-+][+
-(use-modules (ice-9 format))
-
-(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 " * " " * " ) +]
- *
- * If you want to change this file, edit either `[+ (def-file) +]' or
- * `[+ (tpl-file) +]' file, and run the following command:
- *
- * autogen -T [+ (tpl-file) +] [+ (def-file) +]
- */
-#include "parse_context.h"
-#include "power.h"
-#include "operators.h"
-#include "inifcns.h"
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#ifdef HAVE_STDINT_H
-#include <stdint.h> // for uintptr_t
-#endif
-
-namespace GiNaC
-{
-[+ FOR function +]
-static ex [+ (get "name") +]_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 +]
-
-// function::registered_functions() is protected, but we need to access it
-class registered_functions_hack : public function
-{
-public:
-	static const std::vector<function_options>& get_registered_functions()
-	{
-		return function::registered_functions();
-	}
-private:
-	registered_functions_hack();
-	registered_functions_hack(const registered_functions_hack&);
-	registered_functions_hack& operator=(const registered_functions_hack&);
-};
-
-// Encode an integer into a pointer to a function. Since functions
-// are aligned (the minimal alignment depends on CPU architecture)
-// we can distinguish between pointers and integers.
-static reader_func encode_serial_as_reader_func(unsigned serial)
-{
-	uintptr_t u = (uintptr_t)serial;
-	u = (u << 1) | (uintptr_t)1;
-	reader_func ptr = (reader_func)((void *)u);
-	return ptr;
-}
-
-const prototype_table& get_default_reader()
-{
-	using std::make_pair;
-	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 +]
-		std::vector<function_options>::const_iterator it =
-			registered_functions_hack::get_registered_functions().begin();
-		std::vector<function_options>::const_iterator end =
-			registered_functions_hack::get_registered_functions().end();
-		unsigned serial = 0;
-		for (; it != end; ++it) {
-			prototype proto = make_pair(it->get_name(), it->get_nparams());
-			reader[proto] = encode_serial_as_reader_func(serial);
-			++serial;
-		}
-		initialized = true;
-	}
-	return reader;
-}
-
-const prototype_table& get_builtin_reader()
-{
-	using std::make_pair;
-	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 +]
-		enum {
-			log,
-			exp,
-			sin,
-			cos,
-			tan,
-			asin,
-			acos,
-			atan,
-			sinh,
-			cosh,
-			tanh,
-			asinh,
-			acosh,
-			atanh,
-			atan2,
-			Li2,
-			Li3,
-			zetaderiv,
-			Li,
-			S,
-			H,
-			lgamma,
-			tgamma,
-			beta,
-			factorial,
-			binomial,
-			Order,
-			NFUNCTIONS
-		};
-		std::vector<function_options>::const_iterator it =
-			registered_functions_hack::get_registered_functions().begin();
-		unsigned serial = 0;
-		for ( ; serial<NFUNCTIONS; ++it, ++serial ) {
-			prototype proto = make_pair(it->get_name(), it->get_nparams());
-			reader[proto] = encode_serial_as_reader_func(serial);
-		}
-		initialized = true;
-	}
-	return reader;
-}
-
-} // namespace GiNaC
-- 
1.7.2.5



More information about the GiNaC-devel mailing list