]> www.ginac.de Git - ginac.git/blobdiff - ginac/function.pl
- made nops() return unsigned instead of int
[ginac.git] / ginac / function.pl
index 7167d984a20a45d41c9b66f0fcf6dec2b3f641d8..f08990d9fdd47b636a54835632a003943a1282c1 100755 (executable)
@@ -31,15 +31,25 @@ sub generate {
     return $res;
 }
 
     return $res;
 }
 
-$declare_function_macro=generate(
-    <<'END_OF_DECLARE_FUNCTION_MACRO','GiNaC::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) \\
 #define DECLARE_FUNCTION_${N}P(NAME) \\
-extern unsigned function_index_##NAME; \\
+extern const unsigned function_index_##NAME; \\
 inline GiNaC::function NAME(${SEQ1}) { \\
     return GiNaC::function(function_index_##NAME, ${SEQ2}); \\
 }
 
 inline GiNaC::function NAME(${SEQ1}) { \\
     return GiNaC::function(function_index_##NAME, ${SEQ2}); \\
 }
 
-END_OF_DECLARE_FUNCTION_MACRO
+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 const unsigned function_index_##NAME; \\
+inline function NAME(${SEQ1}) { \\
+    return function(function_index_##NAME, ${SEQ2}); \\
+}
+
+END_OF_DECLARE_FUNCTION_MACRO_NO_NAMESPACE
 
 $typedef_eval_funcp=generate(
 'typedef ex (* eval_funcp_${N})(${SEQ1});'."\n",
 
 $typedef_eval_funcp=generate(
 'typedef ex (* eval_funcp_${N})(${SEQ1});'."\n",
@@ -100,7 +110,12 @@ END_OF_DIFF_SWITCH_STATEMENT
 $series_switch_statement=generate(
     <<'END_OF_SERIES_SWITCH_STATEMENT','seq[${N}-1]','');
     case ${N}:
 $series_switch_statement=generate(
     <<'END_OF_SERIES_SWITCH_STATEMENT','seq[${N}-1]','');
     case ${N}:
-        return ((series_funcp_${N})(registered_functions()[serial].s))(${SEQ1},s,point,order);
+        try {
+            res = ((series_funcp_${N})(registered_functions()[serial].s))(${SEQ1},s,point,order);
+        } catch (do_taylor) {
+            res = basic::series(s, point, order);
+        }
+        return res;
         break;
 END_OF_SERIES_SWITCH_STATEMENT
 
         break;
 END_OF_SERIES_SWITCH_STATEMENT
 
@@ -126,7 +141,7 @@ $interface=<<END_OF_INTERFACE;
  *  Please do not modify it directly, edit the perl script instead!
  *  function.pl options: \$maxargs=${maxargs}
  *
  *  Please do not modify it directly, edit the perl script instead!
  *  function.pl options: \$maxargs=${maxargs}
  *
- *  GiNaC Copyright (C) 1999 Johannes Gutenberg University Mainz, Germany
+ *  GiNaC Copyright (C) 1999-2000 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
  *
  *  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
@@ -148,14 +163,39 @@ $interface=<<END_OF_INTERFACE;
 
 #include <string>
 #include <vector>
 
 #include <string>
 #include <vector>
+
+#ifdef __CINT__
+// CINT needs <algorithm> to work properly with <vector> 
+#include <algorithm>
+#endif // def __CINT__
+
 #include <ginac/exprseq.h>
 
 #include <ginac/exprseq.h>
 
+#ifndef NO_GINAC_NAMESPACE
+
 // the following lines have been generated for max. ${maxargs} parameters
 // the following lines have been generated for max. ${maxargs} parameters
-$declare_function_macro
+$declare_function_macro_namespace
 // end of generated lines
 
 // 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) \\
+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) \\
 #define REGISTER_FUNCTION(NAME,E,EF,D,S) \\
-unsigned function_index_##NAME=GiNaC::function::register_new(#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;
 
 #define BEGIN_TYPECHECK \\
 bool automatic_typecheck=true;
@@ -165,18 +205,31 @@ if (!is_ex_exactly_of_type(VAR,TYPE)) { \\
     automatic_typecheck=false; \\
 } else
 
     automatic_typecheck=false; \\
 } else
 
+#ifndef NO_GINAC_NAMESPACE
+
 #define TYPECHECK_INTEGER(VAR) \\
 if (!(VAR).info(GiNaC::info_flags::integer)) { \\
     automatic_typecheck=false; \\
 } else
 
 #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(); \\
 }
 
 #define END_TYPECHECK(RV) \\
 {} \\
 if (!automatic_typecheck) { \\
     return RV.hold(); \\
 }
 
+#ifndef NO_GINAC_NAMESPACE
 namespace GiNaC {
 namespace GiNaC {
+#endif // ndef NO_GINAC_NAMESPACE
 
 class function;
 
 
 class function;
 
@@ -206,6 +259,7 @@ struct registered_function_info {
     and user defined functions */
 class function : public exprseq
 {
     and user defined functions */
 class function : public exprseq
 {
+    // CINT has a linking problem
     friend void ginsh_get_ginac_functions(void);
 
 // member functions
     friend void ginsh_get_ginac_functions(void);
 
 // member functions
@@ -271,15 +325,26 @@ protected:
 
 // utility macros
 
 
 // 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)
 
 #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;
 
 // global constants
 
 extern const function some_function;
 extern type_info const & typeid_function;
 
+#ifndef NO_GINAC_NAMESPACE
 } // namespace GiNaC
 } // namespace GiNaC
+#endif // ndef NO_GINAC_NAMESPACE
 
 #endif // ndef __GINAC_FUNCTION_H__
 
 
 #endif // ndef __GINAC_FUNCTION_H__
 
@@ -295,7 +360,7 @@ $implementation=<<END_OF_IMPLEMENTATION;
  *  Please do not modify it directly, edit the perl script instead!
  *  function.pl options: \$maxargs=${maxargs}
  *
  *  Please do not modify it directly, edit the perl script instead!
  *  function.pl options: \$maxargs=${maxargs}
  *
- *  GiNaC Copyright (C) 1999 Johannes Gutenberg University Mainz, Germany
+ *  GiNaC Copyright (C) 1999-2000 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
  *
  *  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
@@ -317,9 +382,12 @@ $implementation=<<END_OF_IMPLEMENTATION;
 
 #include "function.h"
 #include "ex.h"
 
 #include "function.h"
 #include "ex.h"
+#include "utils.h"
 #include "debugmsg.h"
 
 #include "debugmsg.h"
 
+#ifndef NO_GINAC_NAMESPACE
 namespace GiNaC {
 namespace GiNaC {
+#endif // ndef NO_GINAC_NAMESPACE
 
 //////////
 // default constructor, destructor, copy constructor assignment operator and helpers
 
 //////////
 // default constructor, destructor, copy constructor assignment operator and helpers
@@ -420,7 +488,7 @@ void function::printraw(ostream & os) const
 {
     debugmsg("function printraw",LOGLEVEL_PRINT);
 
 {
     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) {
 
     os << "function(name=" << registered_functions()[serial].name;
     for (exvector::const_iterator it=seq.begin(); it!=seq.end(); ++it) {
@@ -434,7 +502,7 @@ void function::print(ostream & os, unsigned upper_precedence) const
 {
     debugmsg("function print",LOGLEVEL_PRINT);
 
 {
     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);
 
     os << registered_functions()[serial].name;
     printseq(os,'(',',',')',exprseq::precedence,function::precedence);
@@ -444,14 +512,14 @@ void function::printtree(ostream & os, unsigned indent) const
 {
     debugmsg("function printtree",LOGLEVEL_PRINT);
 
 {
     debugmsg("function printtree",LOGLEVEL_PRINT);
 
-    ASSERT(serial<registered_functions().size());
+    GINAC_ASSERT(serial<registered_functions().size());
 
     os << string(indent,' ') << "function "
        << registered_functions()[serial].name
        << ", hash=" << hashvalue << " (0x" << hex << hashvalue << dec << ")"
        << ", flags=" << flags
        << ", nops=" << nops() << endl;
 
     os << string(indent,' ') << "function "
        << registered_functions()[serial].name
        << ", hash=" << hashvalue << " (0x" << hex << hashvalue << dec << ")"
        << ", flags=" << flags
        << ", nops=" << nops() << endl;
-    for (int i=0; i<nops(); ++i) {
+    for (unsigned i=0; i<nops(); ++i) {
         seq[i].printtree(os,indent+delta_indent);
     }
     os << string(indent+delta_indent,' ') << "=====" << endl;
         seq[i].printtree(os,indent+delta_indent);
     }
     os << string(indent+delta_indent,' ') << "=====" << endl;
@@ -461,7 +529,7 @@ void function::printcsrc(ostream & os, unsigned type, unsigned upper_precedence)
 {
     debugmsg("function print csrc",LOGLEVEL_PRINT);
 
 {
     debugmsg("function print csrc",LOGLEVEL_PRINT);
 
-    ASSERT(serial<registered_functions().size());
+    GINAC_ASSERT(serial<registered_functions().size());
 
        // Print function name in lowercase
     string lname;
 
        // Print function name in lowercase
     string lname;
@@ -489,7 +557,7 @@ ex function::expand(unsigned options) const
 
 ex function::eval(int level) const
 {
 
 ex function::eval(int level) const
 {
-    ASSERT(serial<registered_functions().size());
+    GINAC_ASSERT(serial<registered_functions().size());
 
     exvector eseq=evalchildren(level);    
 
 
     exvector eseq=evalchildren(level);    
 
@@ -506,7 +574,7 @@ ${eval_switch_statement}
 
 ex function::evalf(int level) const
 {
 
 ex function::evalf(int level) const
 {
-    ASSERT(serial<registered_functions().size());
+    GINAC_ASSERT(serial<registered_functions().size());
 
     exvector eseq=evalfchildren(level);
     
 
     exvector eseq=evalfchildren(level);
     
@@ -535,11 +603,12 @@ ex function::thisexprseq(exvector * vp) const
  *  \@see ex::series */
 ex function::series(symbol const & s, ex const & point, int order) 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);
     }
 
     if (registered_functions()[serial].s==0) {
         return basic::series(s, point, order);
     }
+    ex res;
     switch (registered_functions()[serial].nparams) {
         // the following lines have been generated for max. ${maxargs} parameters
 ${series_switch_statement}
     switch (registered_functions()[serial].nparams) {
         // the following lines have been generated for max. ${maxargs} parameters
 ${series_switch_statement}
@@ -552,7 +621,7 @@ ${series_switch_statement}
 
 int function::compare_same_type(basic const & other) const
 {
 
 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) {
     function const & o=static_cast<function &>(const_cast<basic &>(other));
 
     if (serial!=o.serial) {
@@ -563,7 +632,7 @@ int function::compare_same_type(basic const & other) const
 
 bool function::is_equal_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;
     function const & o=static_cast<function &>(const_cast<basic &>(other));
 
     if (serial!=o.serial) return false;
@@ -600,7 +669,7 @@ unsigned function::return_type_tinfo(void) const
 
 ex function::pdiff(unsigned diff_param) const // partial differentiation
 {
 
 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"));
     
     if (registered_functions()[serial].d==0) {
         throw(std::logic_error(string("function::pdiff(") + registered_functions()[serial].name + "): no diff function defined"));
@@ -638,7 +707,9 @@ $register_new_implementation
 const function some_function;
 type_info const & typeid_function=typeid(some_function);
 
 const function some_function;
 type_info const & typeid_function=typeid(some_function);
 
+#ifndef NO_GINAC_NAMESPACE
 } // namespace GiNaC
 } // namespace GiNaC
+#endif // ndef NO_GINAC_NAMESPACE
 
 END_OF_IMPLEMENTATION
 
 
 END_OF_IMPLEMENTATION