replaced "precedence" static member variable by virtual precedence() function
authorChristian Bauer <Christian.Bauer@uni-mainz.de>
Sat, 19 May 2001 21:37:44 +0000 (21:37 +0000)
committerChristian Bauer <Christian.Bauer@uni-mainz.de>
Sat, 19 May 2001 21:37:44 +0000 (21:37 +0000)
21 files changed:
ginac/add.cpp
ginac/add.h
ginac/basic.cpp
ginac/basic.h
ginac/container.pl
ginac/expairseq.cpp
ginac/expairseq.h
ginac/function.pl
ginac/mul.cpp
ginac/mul.h
ginac/ncmul.cpp
ginac/ncmul.h
ginac/numeric.cpp
ginac/numeric.h
ginac/power.cpp
ginac/power.h
ginac/pseries.cpp
ginac/pseries.h
ginac/registrar.h
ginac/relational.cpp
ginac/relational.h

index 412bd5a..92cb325 100644 (file)
@@ -121,7 +121,7 @@ void add::print(const print_context & c, unsigned level) const
 
        } else if (is_of_type(c, print_csrc)) {
 
-               if (precedence <= level)
+               if (precedence() <= level)
                        c.s << "(";
        
                // Print arguments, separated by "+"
@@ -130,23 +130,23 @@ void add::print(const print_context & c, unsigned level) const
                
                        // If the coefficient is -1, it is replaced by a single minus sign
                        if (it->coeff.compare(_num1()) == 0) {
-                               it->rest.bp->print(c, precedence);
+                               it->rest.bp->print(c, precedence());
                        } else if (it->coeff.compare(_num_1()) == 0) {
                                c.s << "-";
-                               it->rest.bp->print(c, precedence);
+                               it->rest.bp->print(c, precedence());
                        } else if (ex_to_numeric(it->coeff).numer().compare(_num1()) == 0) {
-                               it->rest.bp->print(c, precedence);
+                               it->rest.bp->print(c, precedence());
                                c.s << "/";
-                               ex_to_numeric(it->coeff).denom().print(c, precedence);
+                               ex_to_numeric(it->coeff).denom().print(c, precedence());
                        } else if (ex_to_numeric(it->coeff).numer().compare(_num_1()) == 0) {
                                c.s << "-";
-                               it->rest.bp->print(c, precedence);
+                               it->rest.bp->print(c, precedence());
                                c.s << "/";
-                               ex_to_numeric(it->coeff).denom().print(c, precedence);
+                               ex_to_numeric(it->coeff).denom().print(c, precedence());
                        } else {
-                               it->coeff.bp->print(c, precedence);
+                               it->coeff.bp->print(c, precedence());
                                c.s << "*";
-                               it->rest.bp->print(c, precedence);
+                               it->rest.bp->print(c, precedence());
                        }
                
                        // Separator is "+", except if the following expression would have a leading minus sign
@@ -158,15 +158,15 @@ void add::print(const print_context & c, unsigned level) const
                if (!overall_coeff.is_zero()) {
                        if (overall_coeff.info(info_flags::positive))
                                c.s << '+';
-                       overall_coeff.bp->print(c, precedence);
+                       overall_coeff.bp->print(c, precedence());
                }
        
-               if (precedence <= level)
+               if (precedence() <= level)
                        c.s << ")";
 
        } else {
 
-               if (precedence <= level) {
+               if (precedence() <= level) {
                        if (is_of_type(c, print_latex))
                                c.s << "{(";
                        else
@@ -181,7 +181,7 @@ void add::print(const print_context & c, unsigned level) const
                        if (!is_of_type(c, print_tree))
                                overall_coeff.print(c, 0);
                        else
-                               overall_coeff.print(c, precedence);
+                               overall_coeff.print(c, precedence());
                        first = false;
                }
 
@@ -204,20 +204,20 @@ void add::print(const print_context & c, unsigned level) const
                                                coeff.print(c);
                                } else {
                                        if (coeff.csgn() == -1)
-                                               (-coeff).print(c, precedence);
+                                               (-coeff).print(c, precedence());
                                        else
-                                               coeff.print(c, precedence);
+                                               coeff.print(c, precedence());
                                }
                                if (is_of_type(c, print_latex))
                                        c.s << ' ';
                                else
                                        c.s << '*';
                        }
-                       it->rest.print(c, precedence);
+                       it->rest.print(c, precedence());
                        it++;
                }
 
-               if (precedence <= level) {
+               if (precedence() <= level) {
                        if (is_of_type(c, print_latex))
                                c.s << ")}";
                        else
@@ -468,12 +468,4 @@ ex add::expand(unsigned options) const
        return (new add(vp,overall_coeff))->setflag(status_flags::expanded | status_flags::dynallocated);
 }
 
-//////////
-// static member variables
-//////////
-
-// protected
-
-unsigned add::precedence = 40;
-
 } // namespace GiNaC
index c6d04d0..1e03662 100644 (file)
@@ -47,6 +47,7 @@ public:
        // functions overriding virtual functions from bases classes
 public:
        void print(const print_context & c, unsigned level = 0) const;
+       unsigned precedence(void) const {return 40;}
        bool info(unsigned inf) const;
        int degree(const ex & s) const;
        int ldegree(const ex & s) const;
@@ -73,17 +74,6 @@ protected:
                                               const ex & c) const;
        ex recombine_pair_to_ex(const expair & p) const;
        ex expand(unsigned options=0) const;
-       
-       // new virtual functions which can be overridden by derived classes
-       // none
-       
-       // non-virtual functions in this class
-       // none
-
-// member variables
-
-protected:
-       static unsigned precedence;
 };
 
 // utility functions
index 5b0b180..bf5bd6c 100644 (file)
@@ -154,6 +154,12 @@ void basic::dbgprinttree(void) const
        this->print(print_tree(std::cerr));
 }
 
+/** Return relative operator precedence (for parenthizing output). */
+unsigned basic::precedence(void) const
+{
+       return 70;
+}
+
 /** Create a new copy of this on the heap.  One can think of this as simulating
  *  a virtual copy constructor which is needed for instance by the refcounted
  *  construction of an ex from a basic. */
@@ -635,14 +641,6 @@ void basic::ensure_if_modifiable(void) const
                throw(std::runtime_error("cannot modify multiply referenced object"));
 }
 
-//////////
-// static member variables
-//////////
-
-// protected
-
-unsigned basic::precedence = 70;
-
 //////////
 // global variables
 //////////
index 555d35c..33a9d20 100644 (file)
@@ -103,6 +103,7 @@ public: // only const functions please (may break reference counting)
        virtual void print(const print_context & c, unsigned level = 0) const;
        virtual void dbgprint(void) const;
        virtual void dbgprinttree(void) const;
+       virtual unsigned precedence(void) const;
        virtual bool info(unsigned inf) const;
        virtual unsigned nops() const;
        virtual ex op(int i) const;
@@ -162,7 +163,6 @@ protected:
        unsigned tinfo_key;                 ///< typeinfo
        mutable unsigned flags;             ///< of type status_flags
        mutable unsigned hashvalue;         ///< hash value
-       static unsigned precedence;         ///< precedence for printing parens
 private:
        unsigned refcount;                  ///< Number of reference counts
 };
index af9d537..8a02503 100755 (executable)
@@ -206,6 +206,7 @@ ${constructors_interface}
 
 public:
        void print(const print_context & c, unsigned level = 0) const;
+       unsigned precedence(void) const {return 10;}
        bool info(unsigned inf) const;
        unsigned nops() const;
        ex & let_op(int i);
@@ -241,7 +242,6 @@ protected:
 
 protected:
        ${STLT} seq;
-       static unsigned precedence;
 };
 
 // utility functions
@@ -418,7 +418,7 @@ void ${CONTAINER}::print(const print_context & c, unsigned level) const
 
        } else {
                // always print brackets around seq, ignore upper_precedence
-               printseq(c, '${open_bracket}', ',', '${close_bracket}', precedence, precedence+1);
+               printseq(c, '${open_bracket}', ',', '${close_bracket}', precedence(), precedence()+1);
        }
 }
 
@@ -726,14 +726,6 @@ ${STLT} * ${CONTAINER}::subschildren(const lst & ls, const lst & lr) const
        return 0; // nothing has changed
 }
 
-//////////
-// static member variables
-//////////
-
-// protected
-
-unsigned ${CONTAINER}::precedence = 10;
-
 } // namespace GiNaC
 
 END_OF_IMPLEMENTATION
index b6a0f37..b14ffb3 100644 (file)
@@ -267,7 +267,7 @@ void expairseq::print(const print_context & c, unsigned level) const
 
        } else {
                c.s << "[[";
-               printseq(c, ',', precedence, level);
+               printseq(c, ',', precedence(), level);
                c.s << "]]";
        }
 }
@@ -540,9 +540,9 @@ ex expairseq::thisexpairseq(epvector *vp, const ex &oc) const
 void expairseq::printpair(const print_context & c, const expair & p, unsigned upper_precedence) const
 {
        c.s << "[[";
-       p.rest.bp->print(c, precedence);
+       p.rest.bp->print(c, precedence());
        c.s << ",";
-       p.coeff.bp->print(c, precedence);
+       p.coeff.bp->print(c, precedence());
        c.s << "]]";
 }
 
@@ -1631,10 +1631,6 @@ epvector * expairseq::subschildren(const lst &ls, const lst &lr) const
 // static member variables
 //////////
 
-// protected
-
-unsigned expairseq::precedence = 10;
-
 #if EXPAIRSEQ_USE_HASHTAB
 unsigned expairseq::maxhashtabsize = 0x4000000U;
 unsigned expairseq::minhashtabsize = 0x1000U;
index e4e3465..fac36ee 100644 (file)
@@ -88,6 +88,7 @@ public:
 public:
        basic * duplicate() const;
        void print(const print_context & c, unsigned level = 0) const;
+       unsigned precedence(void) const {return 10;}
        bool info(unsigned inf) const;
        unsigned nops() const;
        ex op(int i) const;
@@ -174,7 +175,6 @@ protected:
 protected:
        epvector seq;
        ex overall_coeff;
-       static unsigned precedence;
 #if EXPAIRSEQ_USE_HASHTAB
        epplistvector hashtab;
        unsigned hashtabsize;
index 9e303d0..a08d35f 100755 (executable)
@@ -335,6 +335,7 @@ $constructors_interface
        // functions overriding virtual functions from bases classes
 public:
        void print(const print_context & c, unsigned level = 0) const;
+       unsigned precedence(void) const {return 70;}
        int degree(const ex & s) const;
        int ldegree(const ex & s) const;
        ex coeff(const ex & s, int n = 1) const;
@@ -678,10 +679,10 @@ void function::print(const print_context & c, unsigned level) const
 
        } else if is_of_type(c, print_latex) {
                c.s << registered_functions()[serial].TeX_name;
-               printseq(c, '(', ',', ')', exprseq::precedence, function::precedence);
+               printseq(c, '(', ',', ')', exprseq::precedence(), function::precedence());
        } else {
                c.s << registered_functions()[serial].name;
-               printseq(c, '(', ',', ')', exprseq::precedence, function::precedence);
+               printseq(c, '(', ',', ')', exprseq::precedence(), function::precedence());
        }
 }
 
index efc207b..8e641ca 100644 (file)
@@ -136,11 +136,11 @@ void mul::print(const print_context & c, unsigned level) const
 
        } else if (is_of_type(c, print_csrc)) {
 
-               if (precedence <= level)
+               if (precedence() <= level)
                        c.s << "(";
 
                if (!overall_coeff.is_equal(_ex1())) {
-                       overall_coeff.bp->print(c, precedence);
+                       overall_coeff.bp->print(c, precedence());
                        c.s << "*";
                }
        
@@ -158,7 +158,7 @@ void mul::print(const print_context & c, unsigned level) const
 
                        // If the exponent is 1 or -1, it is left out
                        if (it->coeff.compare(_ex1()) == 0 || it->coeff.compare(_num_1()) == 0)
-                               it->rest.print(c, precedence);
+                               it->rest.print(c, precedence());
                        else {
                                // Outer parens around ex needed for broken gcc-2.95 parser:
                                (ex(power(it->rest, abs(ex_to_numeric(it->coeff))))).print(c, level);
@@ -174,12 +174,12 @@ void mul::print(const print_context & c, unsigned level) const
                        }
                }
 
-               if (precedence <= level)
+               if (precedence() <= level)
                        c.s << ")";
 
        } else {
 
-               if (precedence <= level) {
+               if (precedence() <= level) {
                        if (is_of_type(c, print_latex))
                                c.s << "{(";
                        else
@@ -201,9 +201,9 @@ void mul::print(const print_context & c, unsigned level) const
                                        coeff.print(c);
                        } else {
                                if (coeff.csgn() == -1)
-                                       (-coeff).print(c, precedence);
+                                       (-coeff).print(c, precedence());
                                else
-                                       coeff.print(c, precedence);
+                                       coeff.print(c, precedence());
                        }
                        if (is_of_type(c, print_latex))
                                c.s << ' ';
@@ -222,11 +222,11 @@ void mul::print(const print_context & c, unsigned level) const
                        } else {
                                first = false;
                        }
-                       recombine_pair_to_ex(*it).print(c, precedence);
+                       recombine_pair_to_ex(*it).print(c, precedence());
                        it++;
                }
 
-               if (precedence <= level) {
+               if (precedence() <= level) {
                        if (is_of_type(c, print_latex))
                                c.s << ")}";
                        else
@@ -717,12 +717,4 @@ epvector * mul::expandchildren(unsigned options) const
        return 0; // nothing has changed
 }
 
-//////////
-// static member variables
-//////////
-
-// protected
-
-unsigned mul::precedence = 50;
-
 } // namespace GiNaC
index 2d3d240..d5a73cc 100644 (file)
@@ -48,6 +48,7 @@ public:
        // functions overriding virtual functions from bases classes
 public:
        void print(const print_context & c, unsigned level = 0) const;
+       unsigned precedence(void) const {return 50;}
        bool info(unsigned inf) const;
        int degree(const ex & s) const;
        int ldegree(const ex & s) const;
@@ -85,11 +86,6 @@ protected:
        // non-virtual functions in this class
 protected:
        epvector * expandchildren(unsigned options) const;
-       
-// member variables
-       
-protected:
-       static unsigned precedence;
 };
 
 // utility functions
index abe72ef..8a0cc12 100644 (file)
@@ -126,15 +126,15 @@ void ncmul::print(const print_context & c, unsigned level) const
                c.s << "ncmul(";
                exvector::const_iterator it = seq.begin(), itend = seq.end()-1;
                while (it != itend) {
-                       it->print(c, precedence);
+                       it->print(c, precedence());
                        c.s << ",";
                        it++;
                }
-               it->print(c, precedence);
+               it->print(c, precedence());
                c.s << ")";
 
        } else
-               printseq(c, '(', '*', ')', precedence, level);
+               printseq(c, '(', '*', ')', precedence(), level);
 }
 
 bool ncmul::info(unsigned inf) const
@@ -530,14 +530,6 @@ const exvector & ncmul::get_factors(void) const
        return seq;
 }
 
-//////////
-// static member variables
-//////////
-
-// protected
-
-unsigned ncmul::precedence = 50;
-
 //////////
 // friend functions
 //////////
index 05b96da..f3fc101 100644 (file)
@@ -54,6 +54,7 @@ public:
        // functions overriding virtual functions from bases classes
 public:
        void print(const print_context & c, unsigned level = 0) const;
+       unsigned precedence(void) const {return 50;}
        bool info(unsigned inf) const;
        int degree(const ex & s) const;
        int ldegree(const ex & s) const;
@@ -78,11 +79,6 @@ protected:
        exvector expandchildren(unsigned options) const;
 public:
        const exvector & get_factors(void) const;
-
-// member variables
-
-protected:
-       static unsigned precedence;
 };
 
 // friend funtions 
index ef4e3e9..a89045b 100644 (file)
@@ -418,7 +418,7 @@ void numeric::print(const print_context & c, unsigned level) const
                const cln::cl_R i = cln::imagpart(cln::the<cln::cl_N>(value));
                if (cln::zerop(i)) {
                        // case 1, real:  x  or  -x
-                       if ((precedence <= level) && (!this->is_nonneg_integer())) {
+                       if ((precedence() <= level) && (!this->is_nonneg_integer())) {
                                c.s << par_open;
                                print_real_number(c.s, r);
                                c.s << par_close;
@@ -428,7 +428,7 @@ void numeric::print(const print_context & c, unsigned level) const
                } else {
                        if (cln::zerop(r)) {
                                // case 2, imaginary:  y*I  or  -y*I
-                               if ((precedence <= level) && (i < 0)) {
+                               if ((precedence() <= level) && (i < 0)) {
                                        if (i == -1) {
                                                c.s << par_open+imag_sym+par_close;
                                        } else {
@@ -450,7 +450,7 @@ void numeric::print(const print_context & c, unsigned level) const
                                }
                        } else {
                                // case 3, complex:  x+y*I  or  x-y*I  or  -x+y*I  or  -x-y*I
-                               if (precedence <= level)
+                               if (precedence() <= level)
                                        c.s << par_open;
                                print_real_number(c.s, r);
                                if (i < 0) {
@@ -469,7 +469,7 @@ void numeric::print(const print_context & c, unsigned level) const
                                                c.s << mul_sym+imag_sym;
                                        }
                                }
-                               if (precedence <= level)
+                               if (precedence() <= level)
                                        c.s << par_close;
                        }
                }
@@ -1148,15 +1148,6 @@ int numeric::int_length(void) const
                return 0;
 }
 
-
-//////////
-// static member variables
-//////////
-
-// protected
-
-unsigned numeric::precedence = 30;
-
 //////////
 // global constants
 //////////
index 4f2ba1a..1cd7d97 100644 (file)
@@ -85,6 +85,7 @@ public:
        // functions overriding virtual functions from bases classes
 public:
        void print(const print_context & c, unsigned level = 0) const;
+       unsigned precedence(void) const {return 30;}
        bool info(unsigned inf) const;
        bool has(const ex &other) const;
        ex eval(int level = 0) const;
@@ -160,7 +161,6 @@ public:
 // member variables
 
 protected:
-       static unsigned precedence;
        cln::cl_number value;
 };
 
index b13665e..eee137b 100644 (file)
@@ -189,16 +189,16 @@ void power::print(const print_context & c, unsigned level) const
                        else
                                c.s << ")";
                } else {
-                       if (precedence <= level) {
+                       if (precedence() <= level) {
                                if (is_of_type(c, print_latex))
                                        c.s << "{(";
                                else
                                        c.s << "(";
                        }
-                       basis.print(c, precedence);
+                       basis.print(c, precedence());
                        c.s << "^";
-                       exponent.print(c, precedence);
-                       if (precedence <= level) {
+                       exponent.print(c, precedence());
+                       if (precedence() <= level) {
                                if (is_of_type(c, print_latex))
                                        c.s << ")}";
                                else
@@ -830,14 +830,6 @@ ex power::expand_noncommutative(const ex & basis, const numeric & exponent,
 }
 */
 
-//////////
-// static member variables
-//////////
-
-// protected
-
-unsigned power::precedence = 60;
-
 // helper function
 
 ex sqrt(const ex & a)
index d9748ef..480e091 100644 (file)
@@ -49,6 +49,7 @@ public:
        // functions overriding virtual functions from bases classes
 public:
        void print(const print_context & c, unsigned level = 0) const;
+       unsigned precedence(void) const {return 60;}
        bool info(unsigned inf) const;
        unsigned nops() const;
        ex & let_op(int i);
@@ -86,7 +87,6 @@ protected:
 protected:
        ex basis;
        ex exponent;
-       static unsigned precedence;
 };
 
 // utility functions
index ffb2cfb..9d04f6a 100644 (file)
@@ -142,7 +142,7 @@ void pseries::print(const print_context & c, unsigned level) const
 
        } else {
 
-               if (precedence <= level)
+               if (precedence() <= level)
                        c.s << "(";
                
                std::string par_open = is_of_type(c, print_latex) ? "{(" : "(";
@@ -198,7 +198,7 @@ void pseries::print(const print_context & c, unsigned level) const
                                Order(power(var-point,i->coeff)).print(c);
                }
 
-               if (precedence <= level)
+               if (precedence() <= level)
                        c.s << ")";
        }
 }
@@ -925,12 +925,4 @@ ex ex::series(const ex & r, int order, unsigned options) const
        return e;
 }
 
-//////////
-// static member variables
-//////////
-
-// protected
-
-unsigned pseries::precedence = 38;  // for clarity just below add::precedence
-
 } // namespace GiNaC
index 345a5fd..18baed3 100644 (file)
@@ -43,6 +43,7 @@ public:
        // functions overriding virtual functions from base classes
 public:
        void print(const print_context & c, unsigned level = 0) const;
+       unsigned precedence(void) const {return 38;} // for clarity just below add::precedence
        unsigned nops(void) const;
        ex op(int i) const;
        ex &let_op(int i);
@@ -98,8 +99,6 @@ protected:
 
        /** Expansion point */
        ex point;
-
-       static unsigned precedence;
 };
 
 /** Return a reference to the pseries object embedded in an expression.
index 8cab203..125d099 100644 (file)
@@ -81,7 +81,6 @@ public: \
        classname(const classname & other); \
        const classname & operator=(const classname & other); \
        basic * duplicate() const; \
-       unsigned get_precedence(void) const {return precedence;} \
 protected: \
        void copy(const classname & other); \
        void destroy(bool call_parent); \
index 51fd0f1..7f6337d 100644 (file)
@@ -107,9 +107,9 @@ void relational::print(const print_context & c, unsigned level) const
 
        } else {
 
-               if (precedence <= level)
+               if (precedence() <= level)
                        c.s << "(";
-               lh.print(c, precedence);
+               lh.print(c, precedence());
                switch (o) {
                case equal:
                        c.s << "==";
@@ -132,8 +132,8 @@ void relational::print(const print_context & c, unsigned level) const
                default:
                        c.s << "(INVALID RELATIONAL OPERATOR)";
                }
-               rh.print(c, precedence);
-               if (precedence <= level)
+               rh.print(c, precedence());
+               if (precedence() <= level)
                        c.s << ")";
        }
 }
@@ -282,12 +282,4 @@ relational::operator bool() const
        }
 }
 
-//////////
-// static member variables
-//////////
-
-// protected
-
-unsigned relational::precedence = 20;
-
 } // namespace GiNaC
index dcbcacc..c3b223b 100644 (file)
@@ -52,6 +52,7 @@ public:
        // functions overriding virtual functions from bases classes
 public:
        void print(const print_context & c, unsigned level = 0) const;
+       unsigned precedence(void) const {return 20;}
        bool info(unsigned inf) const;
        unsigned nops() const;
        ex & let_op(int i);
@@ -78,7 +79,6 @@ protected:
        ex lh;
        ex rh;
        operators o;
-       static unsigned precedence;
 };
 
 // utility functions