]> www.ginac.de Git - ginac.git/blobdiff - ginac/function.pl
function.pl did not compile
[ginac.git] / ginac / function.pl
index 6ebdada4080be3dba8bf6db65d0e68f469b1d6f9..41018c93428c8cee29b830411ab43f92fc6a5e6f 100755 (executable)
@@ -31,15 +31,25 @@ sub generate {
     return $res;
 }
 
-$declare_function_macro=generate(
-    <<'END_OF_DECLARE_FUNCTION_MACRO','ex const & p${N}','p${N}');
+$declare_function_macro_namespace=generate(
+    <<'END_OF_DECLARE_FUNCTION_MACRO_NAMESPACE','GiNaC::ex const & p${N}','p${N}');
+#define DECLARE_FUNCTION_${N}P(NAME) \\
+extern const unsigned function_index_##NAME; \\
+inline GiNaC::function NAME(${SEQ1}) { \\
+    return GiNaC::function(function_index_##NAME, ${SEQ2}); \\
+}
+
+END_OF_DECLARE_FUNCTION_MACRO_NAMESPACE
+
+$declare_function_macro_no_namespace=generate(
+    <<'END_OF_DECLARE_FUNCTION_MACRO_NO_NAMESPACE','ex const & p${N}','p${N}');
 #define DECLARE_FUNCTION_${N}P(NAME) \\
 extern unsigned function_index_##NAME; \\
 inline function NAME(${SEQ1}) { \\
     return function(function_index_##NAME, ${SEQ2}); \\
 }
 
-END_OF_DECLARE_FUNCTION_MACRO
+END_OF_DECLARE_FUNCTION_MACRO_NO_NAMESPACE
 
 $typedef_eval_funcp=generate(
 'typedef ex (* eval_funcp_${N})(${SEQ1});'."\n",
@@ -72,7 +82,7 @@ function::function(unsigned ser, ${SEQ1})
     : exprseq(${SEQ2}), serial(ser)
 {
     debugmsg(\"function constructor from unsigned,${N}*ex\",LOGLEVEL_CONSTRUCT);
-    tinfo_key = TINFO_FUNCTION;
+    tinfo_key = TINFO_function;
 }
 END_OF_CONSTRUCTORS_IMPLEMENTATION
 
@@ -119,29 +129,68 @@ END_OF_REGISTER_NEW_IMPLEMENTATION
 $interface=<<END_OF_INTERFACE;
 /** \@file function.h
  *
- *  Interface to abstract class function (new function concept).
- *
+ *  Interface to abstract class function (new function concept). */
+
+/*
  *  This file was generated automatically by function.pl.
  *  Please do not modify it directly, edit the perl script instead!
- *  function.pl options: \$maxargs=${maxargs} */
+ *  function.pl options: \$maxargs=${maxargs}
+ *
+ *  GiNaC Copyright (C) 1999 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
 
-#ifndef _FUNCTION_H_
-#define _FUNCTION_H_
+#ifndef __GINAC_FUNCTION_H__
+#define __GINAC_FUNCTION_H__
 
 #include <string>
 #include <vector>
-#include "config.h"
 
-class function;
+#ifdef __CINT__
+// CINT needs <algorithm> to work properly with <vector> 
+#include <algorithm>
+#endif // def __CINT__
+
+#include <ginac/exprseq.h>
 
-#include "exprseq.h"
+#ifndef NO_GINAC_NAMESPACE
 
 // the following lines have been generated for max. ${maxargs} parameters
-$declare_function_macro
+$declare_function_macro_namespace
 // end of generated lines
 
+#else // ndef NO_GINAC_NAMESPACE
+
+// the following lines have been generated for max. ${maxargs} parameters
+$declare_function_macro_no_namespace
+// end of generated lines
+
+#endif // ndef NO_GINAC_NAMESPACE
+
+#ifndef NO_GINAC_NAMESPACE
+
 #define REGISTER_FUNCTION(NAME,E,EF,D,S) \\
-unsigned function_index_##NAME=function::register_new(#NAME,E,EF,D,S);
+const unsigned function_index_##NAME=GiNaC::function::register_new(#NAME,E,EF,D,S);
+
+#else // ndef NO_GINAC_NAMESPACE
+
+#define REGISTER_FUNCTION(NAME,E,EF,D,S) \\
+const unsigned function_index_##NAME=function::register_new(#NAME,E,EF,D,S);
+
+#endif // ndef NO_GINAC_NAMESPACE
 
 #define BEGIN_TYPECHECK \\
 bool automatic_typecheck=true;
@@ -151,17 +200,34 @@ if (!is_ex_exactly_of_type(VAR,TYPE)) { \\
     automatic_typecheck=false; \\
 } else
 
+#ifndef NO_GINAC_NAMESPACE
+
+#define TYPECHECK_INTEGER(VAR) \\
+if (!(VAR).info(GiNaC::info_flags::integer)) { \\
+    automatic_typecheck=false; \\
+} else
+
+#else // ndef NO_GINAC_NAMESPACE
+
 #define TYPECHECK_INTEGER(VAR) \\
 if (!(VAR).info(info_flags::integer)) { \\
     automatic_typecheck=false; \\
 } else
 
+#endif // ndef NO_GINAC_NAMESPACE
+
 #define END_TYPECHECK(RV) \\
 {} \\
 if (!automatic_typecheck) { \\
     return RV.hold(); \\
 }
 
+#ifndef NO_GINAC_NAMESPACE
+namespace GiNaC {
+#endif // ndef NO_GINAC_NAMESPACE
+
+class function;
+
 typedef ex (* eval_funcp)();
 typedef ex (* evalf_funcp)();
 typedef ex (* diff_funcp)();
@@ -188,6 +254,7 @@ struct registered_function_info {
     and user defined functions */
 class function : public exprseq
 {
+    // CINT has a linking problem
     friend void ginsh_get_ginac_functions(void);
 
 // member functions
@@ -253,31 +320,68 @@ protected:
 
 // utility macros
 
+#ifndef NO_GINAC_NAMESPACE
+
+#define is_ex_the_function(OBJ, FUNCNAME) \\
+    (is_ex_exactly_of_type(OBJ, function) && static_cast<GiNaC::function *>(OBJ.bp)->getserial() == function_index_##FUNCNAME)
+
+#else // ndef NO_GINAC_NAMESPACE
+
 #define is_ex_the_function(OBJ, FUNCNAME) \\
     (is_ex_exactly_of_type(OBJ, function) && static_cast<function *>(OBJ.bp)->getserial() == function_index_##FUNCNAME)
 
+#endif // ndef NO_GINAC_NAMESPACE
+
 // global constants
 
 extern const function some_function;
 extern type_info const & typeid_function;
 
-#endif // ndef _FUNCTION_H_
+#ifndef NO_GINAC_NAMESPACE
+} // namespace GiNaC
+#endif // ndef NO_GINAC_NAMESPACE
+
+#endif // ndef __GINAC_FUNCTION_H__
 
 END_OF_INTERFACE
 
 $implementation=<<END_OF_IMPLEMENTATION;
 /** \@file function.cpp
  *
- *  Implementation of class function.
- *
+ *  Implementation of class function. */
+
+/*
  *  This file was generated automatically by function.pl.
  *  Please do not modify it directly, edit the perl script instead!
- *  function.pl options: \$maxargs=${maxargs} */
+ *  function.pl options: \$maxargs=${maxargs}
+ *
+ *  GiNaC Copyright (C) 1999 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
 
 #include <string>
 #include <stdexcept>
 
-#include "ginac.h"
+#include "function.h"
+#include "ex.h"
+#include "debugmsg.h"
+
+#ifndef NO_GINAC_NAMESPACE
+namespace GiNaC {
+#endif // ndef NO_GINAC_NAMESPACE
 
 //////////
 // default constructor, destructor, copy constructor assignment operator and helpers
@@ -288,7 +392,7 @@ $implementation=<<END_OF_IMPLEMENTATION;
 function::function() : serial(0)
 {
     debugmsg("function default constructor",LOGLEVEL_CONSTRUCT);
-    tinfo_key = TINFO_FUNCTION;
+    tinfo_key = TINFO_function;
 }
 
 function::~function()
@@ -335,7 +439,7 @@ void function::destroy(bool call_parent)
 function::function(unsigned ser) : serial(ser)
 {
     debugmsg("function constructor from unsigned",LOGLEVEL_CONSTRUCT);
-    tinfo_key = TINFO_FUNCTION;
+    tinfo_key = TINFO_function;
 }
 
 // the following lines have been generated for max. ${maxargs} parameters
@@ -345,21 +449,21 @@ $constructors_implementation
 function::function(unsigned ser, exprseq const & es) : exprseq(es), serial(ser)
 {
     debugmsg("function constructor from unsigned,exprseq",LOGLEVEL_CONSTRUCT);
-    tinfo_key = TINFO_FUNCTION;
+    tinfo_key = TINFO_function;
 }
 
 function::function(unsigned ser, exvector const & v, bool discardable) 
     : exprseq(v,discardable), serial(ser)
 {
     debugmsg("function constructor from string,exvector,bool",LOGLEVEL_CONSTRUCT);
-    tinfo_key = TINFO_FUNCTION;
+    tinfo_key = TINFO_function;
 }
 
 function::function(unsigned ser, exvector * vp) 
     : exprseq(vp), serial(ser)
 {
     debugmsg("function constructor from unsigned,exvector *",LOGLEVEL_CONSTRUCT);
-    tinfo_key = TINFO_FUNCTION;
+    tinfo_key = TINFO_function;
 }
 
 //////////
@@ -378,7 +482,7 @@ void function::printraw(ostream & os) const
 {
     debugmsg("function printraw",LOGLEVEL_PRINT);
 
-    ASSERT(serial<registered_functions().size());
+    GINAC_ASSERT(serial<registered_functions().size());
 
     os << "function(name=" << registered_functions()[serial].name;
     for (exvector::const_iterator it=seq.begin(); it!=seq.end(); ++it) {
@@ -392,7 +496,7 @@ void function::print(ostream & os, unsigned upper_precedence) const
 {
     debugmsg("function print",LOGLEVEL_PRINT);
 
-    ASSERT(serial<registered_functions().size());
+    GINAC_ASSERT(serial<registered_functions().size());
 
     os << registered_functions()[serial].name;
     printseq(os,'(',',',')',exprseq::precedence,function::precedence);
@@ -402,7 +506,7 @@ void function::printtree(ostream & os, unsigned indent) const
 {
     debugmsg("function printtree",LOGLEVEL_PRINT);
 
-    ASSERT(serial<registered_functions().size());
+    GINAC_ASSERT(serial<registered_functions().size());
 
     os << string(indent,' ') << "function "
        << registered_functions()[serial].name
@@ -419,7 +523,7 @@ void function::printcsrc(ostream & os, unsigned type, unsigned upper_precedence)
 {
     debugmsg("function print csrc",LOGLEVEL_PRINT);
 
-    ASSERT(serial<registered_functions().size());
+    GINAC_ASSERT(serial<registered_functions().size());
 
        // Print function name in lowercase
     string lname;
@@ -447,7 +551,7 @@ ex function::expand(unsigned options) const
 
 ex function::eval(int level) const
 {
-    ASSERT(serial<registered_functions().size());
+    GINAC_ASSERT(serial<registered_functions().size());
 
     exvector eseq=evalchildren(level);    
 
@@ -464,7 +568,7 @@ ${eval_switch_statement}
 
 ex function::evalf(int level) const
 {
-    ASSERT(serial<registered_functions().size());
+    GINAC_ASSERT(serial<registered_functions().size());
 
     exvector eseq=evalfchildren(level);
     
@@ -493,7 +597,7 @@ ex function::thisexprseq(exvector * vp) const
  *  \@see ex::series */
 ex function::series(symbol const & s, ex const & point, int order) const
 {
-    ASSERT(serial<registered_functions().size());
+    GINAC_ASSERT(serial<registered_functions().size());
 
     if (registered_functions()[serial].s==0) {
         return basic::series(s, point, order);
@@ -510,7 +614,7 @@ ${series_switch_statement}
 
 int function::compare_same_type(basic const & other) const
 {
-    ASSERT(is_of_type(other, function));
+    GINAC_ASSERT(is_of_type(other, function));
     function const & o=static_cast<function &>(const_cast<basic &>(other));
 
     if (serial!=o.serial) {
@@ -521,7 +625,7 @@ int function::compare_same_type(basic const & other) const
 
 bool function::is_equal_same_type(basic const & other) const
 {
-    ASSERT(is_of_type(other, function));
+    GINAC_ASSERT(is_of_type(other, function));
     function const & o=static_cast<function &>(const_cast<basic &>(other));
 
     if (serial!=o.serial) return false;
@@ -558,7 +662,7 @@ unsigned function::return_type_tinfo(void) const
 
 ex function::pdiff(unsigned diff_param) const // partial differentiation
 {
-    ASSERT(serial<registered_functions().size());
+    GINAC_ASSERT(serial<registered_functions().size());
     
     if (registered_functions()[serial].d==0) {
         throw(std::logic_error(string("function::pdiff(") + registered_functions()[serial].name + "): no diff function defined"));
@@ -596,6 +700,10 @@ $register_new_implementation
 const function some_function;
 type_info const & typeid_function=typeid(some_function);
 
+#ifndef NO_GINAC_NAMESPACE
+} // namespace GiNaC
+#endif // ndef NO_GINAC_NAMESPACE
+
 END_OF_IMPLEMENTATION
 
 print "Creating interface file function.h...";