]> www.ginac.de Git - ginac.git/commitdiff
- Changes to make it more ANSI-conformant. Stuff detected while trying
authorRichard Kreckel <Richard.Kreckel@uni-mainz.de>
Sat, 12 Aug 2000 22:00:04 +0000 (22:00 +0000)
committerRichard Kreckel <Richard.Kreckel@uni-mainz.de>
Sat, 12 Aug 2000 22:00:04 +0000 (22:00 +0000)
  the compiler from Portland Group.

15 files changed:
ginac/archive.cpp
ginac/archive.h
ginac/basic.h
ginac/ex.cpp
ginac/expairseq.cpp
ginac/function.pl
ginac/input_lexer.ll
ginac/matrix.cpp
ginac/ncmul.cpp
ginac/ncmul.h
ginac/numeric.cpp
ginac/relational.cpp
ginac/remember.cpp
ginac/simp_lor.cpp
ginac/symbol.h

index dcfb00dc9c37e382cb0ae88550cec11adaf4fd93..171766c98678ff8678bd7244ce98d5cc4ee1e532 100644 (file)
@@ -188,7 +188,9 @@ static unsigned int read_unsigned(std::istream &is)
        unsigned int ret = 0;
        unsigned int shift = 0;
        do {
-               is.get(b);
+        char b2;
+               is.get(b2);
+        b = b2;
                ret |= (b & 0x7f) << shift;
                shift += 7;
        } while (b & 0x80);
index fd4430da4b0c1ea6e1a04544ce4cfb819b3fcfc6..b869222d9bd58f529ef730f5ad4ed0807ebec7fa 100644 (file)
 
 #include <string>
 #include <vector>
-
-namespace std {
-       class ostream;
-       class istream;
-}
+#include <iostream>
 
 #ifndef NO_NAMESPACE_GINAC
 namespace GiNaC {
index 1a7ffcf02944cbd9738374f31a6c151bab7371b7..eb30fd19a3398d5af64735ee04116157177a9e14 100644 (file)
@@ -91,8 +91,8 @@ public:
 #else
 ;
 #endif // def INLINE_BASIC_CONSTRUCTORS
-
-       virtual const basic & operator=(const basic & other);
+       
+       const basic & operator=(const basic & other);
        
 protected:
        void copy(const basic & other)
index 559bae47d95932793f49b9e87ecc9ec6d206012c..5414cd5a8dc195944fb96b6d3fc0d81dac8e2179 100644 (file)
@@ -81,11 +81,10 @@ const ex & ex::operator=(const ex & other)
        GINAC_ASSERT(other.bp!=0);
        GINAC_ASSERT(other.bp->flags & status_flags::dynallocated);
        ++other.bp->refcount;
-       basic * tmpbp=other.bp;
-       if (--bp->refcount==0) {
-                       delete bp;
-       }
-       bp=tmpbp;
+       basic * tmpbp = other.bp;
+       if (--bp->refcount==0)
+               delete bp;
+       bp = tmpbp;
        return *this;
 }
 
@@ -465,7 +464,7 @@ void ex::makewriteable()
                --bp->refcount;
                bp = bp2;
        }
-       GINAC_ASSERT(bp->refcount == 1);
+       GINAC_ASSERT(bp->refcount==1);
 }
 
 void ex::construct_from_basic(const basic & other)
@@ -525,21 +524,13 @@ void ex::construct_from_int(int i)
                bp->setflag(status_flags::dynallocated);
                ++bp->refcount;
                GINAC_ASSERT((bp->flags) & status_flags::dynallocated);
-               GINAC_ASSERT(bp->refcount=1);
+               GINAC_ASSERT(bp->refcount==1);
        }
 }
        
 void ex::construct_from_uint(unsigned int i)
 {
        switch (i) {  // some tiny efficiency-hack
-       case -2:
-               bp = _ex_2().bp;
-               ++bp->refcount;
-               break;
-       case -1:
-               bp = _ex_1().bp;
-               ++bp->refcount;
-               break;
        case 0:
                bp = _ex0().bp;
                ++bp->refcount;
@@ -557,7 +548,7 @@ void ex::construct_from_uint(unsigned int i)
                bp->setflag(status_flags::dynallocated);
                ++bp->refcount;
                GINAC_ASSERT((bp->flags) & status_flags::dynallocated);
-               GINAC_ASSERT(bp->refcount=1);
+               GINAC_ASSERT(bp->refcount==1);
        }
 }
        
@@ -589,21 +580,13 @@ void ex::construct_from_long(long i)
                bp->setflag(status_flags::dynallocated);
                ++bp->refcount;
                GINAC_ASSERT((bp->flags) & status_flags::dynallocated);
-               GINAC_ASSERT(bp->refcount=1);
+               GINAC_ASSERT(bp->refcount==1);
        }
 }
        
 void ex::construct_from_ulong(unsigned long i)
 {
        switch (i) {  // some tiny efficiency-hack
-       case -2:
-               bp = _ex_2().bp;
-               ++bp->refcount;
-               break;
-       case -1:
-               bp = _ex_1().bp;
-               ++bp->refcount;
-               break;
        case 0:
                bp = _ex0().bp;
                ++bp->refcount;
@@ -621,7 +604,7 @@ void ex::construct_from_ulong(unsigned long i)
                bp->setflag(status_flags::dynallocated);
                ++bp->refcount;
                GINAC_ASSERT((bp->flags) & status_flags::dynallocated);
-               GINAC_ASSERT(bp->refcount=1);
+               GINAC_ASSERT(bp->refcount==1);
        }
 }
        
@@ -631,7 +614,7 @@ void ex::construct_from_double(double d)
        bp->setflag(status_flags::dynallocated);
        ++bp->refcount;
        GINAC_ASSERT((bp->flags) & status_flags::dynallocated);
-       GINAC_ASSERT(bp->refcount=1);
+       GINAC_ASSERT(bp->refcount==1);
 }
 
 void ex::construct_from_string_and_lst(const std::string &s, const ex &l)
index 1f7fcf4184cd76c41206d9be52bc4d12f541c0c9..5a52efe1edf59d8364dccf19dc3d87d5911b90fe 100644 (file)
@@ -23,7 +23,6 @@
 #include <algorithm>
 #include <string>
 #include <stdexcept>
-#include <cmath>
 
 #include "expairseq.h"
 #include "lst.h"
index fac659f50a329ee383c9e263c7068d271d582203..c6e00834bc76c96a01f1e9d8730e56c31d14eea8 100755 (executable)
@@ -131,14 +131,12 @@ $evalf_switch_statement=generate(
        <<'END_OF_EVALF_SWITCH_STATEMENT','eseq[${N}-1]','');
        case ${N}:
                return ((evalf_funcp_${N})(registered_functions()[serial].evalf_f))(${SEQ1});
-               break;
 END_OF_EVALF_SWITCH_STATEMENT
 
 $diff_switch_statement=generate(
        <<'END_OF_DIFF_SWITCH_STATEMENT','seq[${N}-1]','');
        case ${N}:
                return ((derivative_funcp_${N})(registered_functions()[serial].derivative_f))(${SEQ1},diff_param);
-               break;
 END_OF_DIFF_SWITCH_STATEMENT
 
 $series_switch_statement=generate(
@@ -150,7 +148,6 @@ $series_switch_statement=generate(
                        res = basic::series(r, order, options);
                }
                return res;
-               break;
 END_OF_SERIES_SWITCH_STATEMENT
 
 $eval_func_implementation=generate(
@@ -889,7 +886,7 @@ ex function::thisexprseq(exvector * vp) const
 
 /** Implementation of ex::series for functions.
  *  \@see ex::series */
-ex function::series(const relational & r, int order, unsigned options = 0) const
+ex function::series(const relational & r, int order, unsigned options) const
 {
        GINAC_ASSERT(serial<registered_functions().size());
 
@@ -1003,7 +1000,7 @@ ex function::pderivative(unsigned diff_param) const // partial differentiation
        GINAC_ASSERT(serial<registered_functions().size());
        
        if (registered_functions()[serial].derivative_f==0) {
-               return Derivative(*this, lst(diff_param));
+               return Derivative(*this, lst(ex(diff_param)));
        }
        switch (registered_functions()[serial].nparams) {
                // the following lines have been generated for max. ${maxargs} parameters
index 9795803e5ac31e02e77ca22a36fe016a25b7c4e6..18f78818746e0bbd82fd31b2650d1be3b2cb6417 100644 (file)
@@ -125,7 +125,7 @@ Digits                      ginac_yylval = (long)Digits; return T_DIGITS;
                                if (i == syms.end()) {
                                        syms[yytext] = sym_def(ginac_yylval = *(new symbol(yytext)), false);
                                } else
-                                       ginac_yylval = i->second.sym;
+                                       ginac_yylval = (*i).second.sym;
                                return T_SYMBOL;
                        }
 
@@ -194,7 +194,7 @@ bool is_lexer_symbol_predefined(const ex &s)
        if (i == syms.end())
                return false;
        else
-               return i->second.predefined;
+               return (*i).second.predefined;
 }
 
 #ifndef NO_NAMESPACE_GINAC
index b2d4f606bd772ea7be1e1969a43f9cd44b872683..8b747e8562332c724d7f211803a7aadb00267acd 100644 (file)
@@ -393,7 +393,7 @@ matrix matrix::mul(const matrix & other) const
  *  @exception range_error (index out of range) */
 const ex & matrix::operator() (unsigned ro, unsigned co) const
 {
-       if (ro<0 || ro>=row || co<0 || co>=col)
+       if (ro>=row || co>=col)
                throw (std::range_error("matrix::operator(): index out of range"));
 
        return m[ro*col+co];
@@ -405,9 +405,9 @@ const ex & matrix::operator() (unsigned ro, unsigned co) const
  *  @exception range_error (index out of range) */
 matrix & matrix::set(unsigned ro, unsigned co, ex value)
 {
-       if (ro<0 || ro>=row || co<0 || co>=col)
+       if (ro>=row || co>=col)
                throw (std::range_error("matrix::set(): index out of range"));
-       
+    
        ensure_if_modifiable();
        m[ro*col+co] = value;
        return *this;
index 7e8dce6596a728679ec397c99cbe7192fce531fd..d8e7584bc723e248702a2336255d88a7393ecc5c 100644 (file)
@@ -179,7 +179,6 @@ void ncmul::print(std::ostream & os, unsigned upper_precedence) const
 void ncmul::printraw(std::ostream & os) const
 {
        debugmsg("ncmul printraw",LOGLEVEL_PRINT);
-
        os << "%(";
        for (exvector::const_iterator it=seq.begin(); it!=seq.end(); ++it) {
                (*it).bp->printraw(os);
@@ -189,7 +188,7 @@ void ncmul::printraw(std::ostream & os) const
        os << ")";
 }
 
-void ncmul::printcsrc(std::ostream & os, unsigned upper_precedence) const
+void ncmul::printcsrc(std::ostream & os, unsigned type, unsigned upper_precedence) const
 {
        debugmsg("ncmul print csrc",LOGLEVEL_PRINT);
        exvector::const_iterator it;
index 0f9433956d958ef73e449904a4360d142df7728e..ed1b299797a8299876479cc6176a2e21d3e3f9af 100644 (file)
@@ -68,7 +68,7 @@ public:
        basic * duplicate() const;
        void print(std::ostream & os, unsigned upper_precedence) const;
        void printraw(std::ostream & os) const;
-       void printcsrc(std::ostream & os, unsigned upper_precedence) const;
+       void printcsrc(std::ostream & os, unsigned type, unsigned upper_precedence = 0) const;
        bool info(unsigned inf) const;
        int degree(const symbol & s) const;
        int ldegree(const symbol & s) const;
index af2d8effe25226ce2c7d5d33d4d6ec703ee9925c..228540d78260125bc813293998a72330256929a1 100644 (file)
@@ -225,7 +225,6 @@ numeric::numeric(double d) : basic(TINFO_numeric)
                status_flags::hash_calculated);
 }
 
-
 /** ctor from C-style string.  It also accepts complex numbers in GiNaC
  *  notation like "2+5*I". */
 numeric::numeric(const char *s) : basic(TINFO_numeric)
@@ -246,8 +245,7 @@ numeric::numeric(const char *s) : basic(TINFO_numeric)
                bool imaginary = false;
                delim = ss.find_first_of(std::string("+-"),1);
                // Do we have an exponent marker like "31.415E-1"?  If so, hop on!
-               if (delim != std::string::npos
-                && ss.at(delim-1) == 'E')
+               if ((delim != std::string::npos) && (ss.at(delim-1) == 'E'))
                        delim = ss.find_first_of(std::string("+-"),delim+1);
                term = ss.substr(0,delim);
                if (delim != std::string::npos)
@@ -282,7 +280,8 @@ numeric::numeric(const char *s) : basic(TINFO_numeric)
        } while(delim != std::string::npos);
        calchash();
        setflag(status_flags::evaluated |
-               status_flags::hash_calculated);
+                       status_flags::expanded |
+                       status_flags::hash_calculated);
 }
 
 /** Ctor from CLN types.  This is for the initiated user or internal use
@@ -1004,7 +1003,6 @@ bool numeric::operator<(const numeric & other) const
        if (this->is_real() && other.is_real())
                return (The(::cl_R)(*value) < The(::cl_R)(*other.value));  // -> CLN
        throw std::invalid_argument("numeric::operator<(): complex inequality");
-       return false;  // make compiler shut up
 }
 
 /** Numerical comparison: less or equal.
@@ -1026,7 +1024,6 @@ bool numeric::operator>(const numeric & other) const
        if (this->is_real() && other.is_real())
                return (The(::cl_R)(*value) > The(::cl_R)(*other.value));  // -> CLN
        throw std::invalid_argument("numeric::operator>(): complex inequality");
-       return false;  // make compiler shut up
 }
 
 /** Numerical comparison: greater or equal.
@@ -1037,7 +1034,6 @@ bool numeric::operator>=(const numeric & other) const
        if (this->is_real() && other.is_real())
                return (The(::cl_R)(*value) >= The(::cl_R)(*other.value));  // -> CLN
        throw std::invalid_argument("numeric::operator>=(): complex inequality");
-       return false;  // make compiler shut up
 }
 
 /** Converts numeric types to machine's int.  You should check with
@@ -1754,7 +1750,7 @@ numeric mod(const numeric & a, const numeric & b)
 numeric smod(const numeric & a, const numeric & b)
 {
        if (a.is_integer() && b.is_integer()) {
-               cl_I b2 = The(::cl_I)(ceiling1(The(::cl_I)(*b.value) / 2)) - 1;
+               cl_I b2 = The(::cl_I)(ceiling1(The(::cl_I)(*b.value) >> 1)) - 1;
                return ::mod(The(::cl_I)(*a.value) + b2, The(::cl_I)(*b.value)) - b2;
        } else
                return _num0();  // Throw?
index 5628f25ca67d04d06ec66cc039171ec09edfb28c..a03b60f8ec812eca99e56f5aa5419cd5a0ef1ff5 100644 (file)
@@ -291,12 +291,12 @@ ex relational::eval(int level) const
 
 ex relational::evalf(int level) const
 {
-       if (level==1) {
+       if (level==1)
                return *this;
-       }
-       if (level == -max_recursion_level) {
+       
+       if (level==-max_recursion_level)
                throw(std::runtime_error("max recursion level reached"));
-       }
+       
        return (new relational(lh.eval(level-1),rh.eval(level-1),o))->setflag(status_flags::dynallocated);
 }
 
@@ -315,18 +315,16 @@ int relational::compare_same_type(const basic & other) const
        int cmpval;
        
        if (o == oth.o) {
-               cmpval=lh.compare(oth.lh);
-               if (cmpval==0) {
+               cmpval = lh.compare(oth.lh);
+               if (cmpval==0)
                        return rh.compare(oth.rh);
-               } else {
+               else
                        return cmpval;
-               }
        }
-       if (o<oth.o) {
+       if (o<oth.o)
                return -1;
-       } else {
+       else
                return 1;
-       }
 }
 
 unsigned relational::return_type(void) const
@@ -366,34 +364,28 @@ relational::operator bool() const
        // please note that (a<b) == false does not imply (a>=b) == true
        // a false result means the comparison is either false or undecidable
        // (except for !=, where true means unequal or undecidable)
-       ex df=lh-rh;
-       if (!is_ex_exactly_of_type(df,numeric)) {
-               return o==not_equal ? true : false; // cannot decide on non-numerical results
-       }
-       int cmpval=ex_to_numeric(df).compare(_num0());
+       ex df = lh-rh;
+       if (!is_ex_exactly_of_type(df,numeric))
+               // cannot decide on non-numerical results
+               return o==not_equal ? true : false;
+       
+       int cmpval = ex_to_numeric(df).compare(_num0());
        switch (o) {
        case equal:
                return cmpval==0;
-               break;
        case not_equal:
                return cmpval!=0;
-               break;
        case less:
                return cmpval<0;
-               break;
        case less_or_equal:
                return cmpval<=0;
-               break;
        case greater:
                return cmpval>0;
-               break;
        case greater_or_equal:
                return cmpval>=0;
-               break;
        default:
                throw(std::logic_error("invalid relational operator"));
        }
-       return 0;
 }
 
 //////////
index 9b06a464d8d9e33e8b5672fe6705d9d1637a73f1..404c7c81bf0c1823c821521ac3a3f5885648b1e1 100644 (file)
@@ -24,7 +24,7 @@
 #include <stdexcept>
 
 #include "function.h"
-#include "utils.h" // for log_2
+#include "utils.h"
 #include "remember.h"
 
 #ifndef NO_NAMESPACE_GINAC
@@ -38,18 +38,17 @@ namespace GiNaC {
 remember_table_entry::remember_table_entry(function const & f, ex const & r)
   : hashvalue(f.gethash()), seq(f.seq), result(r)
 {
-       ++last_access=access_counter;
-       successful_hits=0;
+       ++last_access = access_counter;
+       successful_hits = 0;
 }
 
 bool remember_table_entry::is_equal(function const & f) const
 {
        GINAC_ASSERT(f.seq.size()==seq.size());
        if (f.gethash()!=hashvalue) return false;
-       for (unsigned i=0; i<seq.size(); ++i) {
+       for (unsigned i=0; i<seq.size(); ++i)
                if (!seq[i].is_equal(f.seq[i])) return false;
-       }
-       ++last_access=access_counter;
+       ++last_access = access_counter;
        ++successful_hits;
        return true;
 }
@@ -62,8 +61,8 @@ unsigned long remember_table_entry::access_counter=0;
 
 remember_table_list::remember_table_list(unsigned as, unsigned strat)
 {
-       max_assoc_size=as;
-       remember_strategy=strat;
+       max_assoc_size = as;
+       remember_strategy = strat;
 }
 
 
@@ -74,59 +73,58 @@ void remember_table_list::add_entry(function const & f, ex const & result)
                (size()>=max_assoc_size)) {
                // table is full, we must delete an older entry
                GINAC_ASSERT(size()>0); // there must be at least one entry
+               
                switch (remember_strategy) {
-               case remember_strategies::delete_cyclic:
+               case remember_strategies::delete_cyclic: {
                        // delete oldest entry (first in list)
                        erase(begin());
                        break;
-               case remember_strategies::delete_lru:
-                       {
-                               // delete least recently used entry
-                               iterator it=begin();
-                               iterator lowest_access_it=it;
-                               unsigned long lowest_access=it->get_last_access();
-                               ++it;
-                               while (it!=end()) {
-                                       if (it->get_last_access()<lowest_access) {
-                                               lowest_access=it->get_last_access();
-                                               lowest_access_it=it;
-                                       }
-                                       ++it;
+               }
+               case remember_strategies::delete_lru: {
+                       // delete least recently used entry
+                       iterator it = begin();
+                       iterator lowest_access_it = it;
+                       unsigned long lowest_access = (*it).get_last_access();
+                       ++it;
+                       while (it!=end()) {
+                               if ((*it).get_last_access()<lowest_access) {
+                                       lowest_access = (*it).get_last_access();
+                                       lowest_access_it = it;
                                }
-                               erase(lowest_access_it);
+                               ++it;
                        }
+                       erase(lowest_access_it);
                        break;
-               case remember_strategies::delete_lfu:
-                       {
-                               // delete least frequently used entry
-                               iterator it=begin();
-                               iterator lowest_hits_it=it;
-                               unsigned lowest_hits=it->get_successful_hits();
-                               ++it;
-                               while (it!=end()) {
-                                       if (it->get_successful_hits()<lowest_hits) {
-                                               lowest_hits=it->get_successful_hits();
-                                               lowest_hits_it=it;
-                                       }
-                                       ++it;
+               }
+               case remember_strategies::delete_lfu: {
+                       // delete least frequently used entry
+                       iterator it = begin();
+                       iterator lowest_hits_it = it;
+                       unsigned lowest_hits = (*it).get_successful_hits();
+                       ++it;
+                       while (it!=end()) {
+                               if ((*it).get_successful_hits()<lowest_hits) {
+                                       lowest_hits = (*it).get_successful_hits();
+                                       lowest_hits_it = it;
                                }
-                               erase(lowest_hits_it);
+                               ++it;
                        }
+                       erase(lowest_hits_it);
                        break;
+               }
                default:
                        throw(std::logic_error("remember_table_list::add_entry(): invalid remember_strategy"));
-               }
+        }
                GINAC_ASSERT(size()==max_assoc_size-1);
        }
        push_back(remember_table_entry(f,result));
-}        
+}
 
 bool remember_table_list::lookup_entry(function const & f, ex & result) const
 {
        for (const_iterator cit=begin(); cit!=end(); ++cit) {
-               if (cit->is_equal(f)) {
-                       result=cit->get_result();
+               if ((*cit).is_equal(f)) {
+                       result = (*cit).get_result();
                        return true;
                }
        }
@@ -151,20 +149,20 @@ remember_table::remember_table(unsigned s, unsigned as, unsigned strat)
        // all entries
 
        // use some power of 2 next to s
-       table_size=1 << log2(s);
+       table_size = 1 << log2(s);
        init_table();
 }
 
 bool remember_table::lookup_entry(function const & f, ex & result) const
 {
-       unsigned entry=f.gethash() & (table_size-1);
+       unsigned entry = f.gethash() & (table_size-1);
        GINAC_ASSERT(entry<size());
        return operator[](entry).lookup_entry(f,result);
 }
 
 void remember_table::add_entry(function const & f, ex const & result)
 {
-       unsigned entry=f.gethash() & (table_size-1);
+       unsigned entry = f.gethash() & (table_size-1);
        GINAC_ASSERT(entry<size());
        operator[](entry).add_entry(f,result);
 }        
@@ -178,9 +176,8 @@ void remember_table::clear_all_entries(void)
 void remember_table::init_table(void)
 {
        reserve(table_size);
-       for (unsigned i=0; i<table_size; ++i) {
+       for (unsigned i=0; i<table_size; ++i)
                push_back(remember_table_list(max_assoc_size,remember_strategy));
-       }
 }
 
 std::vector<remember_table> & remember_table::remember_tables(void)
index 06eef8ee6b03b5058784291c62565ac66abfc78f..e589b18fd351e65f8376692c808df4a29ec5c37f 100644 (file)
@@ -487,10 +487,10 @@ bool scalar_products::is_defined(const simp_lor & v1, const simp_lor & v2) const
 
 ex scalar_products::evaluate(const simp_lor & v1, const simp_lor & v2) const
 {
-       if (v1.compare_same_type(v2)>0) {
-               return evaluate(v2,v1);
-       }
-       return spm.find(make_key(v1,v2))->second;
+       if (v1.compare_same_type(v2)>0)
+               return evaluate(v2, v1);
+       
+       return (*spm.find(make_key(v1,v2))).second;
 }
 
 void scalar_products::debugprint(void) const
index d547b1d6c996da49a815fc94bc8034ed649422df..3c8c855747c706f6fd96df2cfe905dffa51c5c30 100644 (file)
@@ -125,7 +125,7 @@ inline const symbol &ex_to_symbol(const ex &e)
 
 // wrapper functions around member functions
 inline void unassign(symbol & symarg)
-{ return symarg.unassign(); }
+{ symarg.unassign(); }
 
 inline int degree(const symbol & a, const symbol & s)
 { return a.degree(s); }