From 57b66d879a72c007eabe081420de11757b5bcf90 Mon Sep 17 00:00:00 2001 From: Richard Kreckel Date: Sat, 12 Aug 2000 22:00:04 +0000 Subject: [PATCH] - Changes to make it more ANSI-conformant. Stuff detected while trying the compiler from Portland Group. --- ginac/archive.cpp | 4 +- ginac/archive.h | 6 +-- ginac/basic.h | 4 +- ginac/ex.cpp | 37 +++++------------- ginac/expairseq.cpp | 1 - ginac/function.pl | 7 +--- ginac/input_lexer.ll | 4 +- ginac/matrix.cpp | 6 +-- ginac/ncmul.cpp | 3 +- ginac/ncmul.h | 2 +- ginac/numeric.cpp | 12 ++---- ginac/relational.cpp | 38 ++++++++---------- ginac/remember.cpp | 91 +++++++++++++++++++++----------------------- ginac/simp_lor.cpp | 8 ++-- ginac/symbol.h | 2 +- 15 files changed, 93 insertions(+), 132 deletions(-) diff --git a/ginac/archive.cpp b/ginac/archive.cpp index dcfb00dc..171766c9 100644 --- a/ginac/archive.cpp +++ b/ginac/archive.cpp @@ -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); diff --git a/ginac/archive.h b/ginac/archive.h index fd4430da..b869222d 100644 --- a/ginac/archive.h +++ b/ginac/archive.h @@ -27,11 +27,7 @@ #include #include - -namespace std { - class ostream; - class istream; -} +#include #ifndef NO_NAMESPACE_GINAC namespace GiNaC { diff --git a/ginac/basic.h b/ginac/basic.h index 1a7ffcf0..eb30fd19 100644 --- a/ginac/basic.h +++ b/ginac/basic.h @@ -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) diff --git a/ginac/ex.cpp b/ginac/ex.cpp index 559bae47..5414cd5a 100644 --- a/ginac/ex.cpp +++ b/ginac/ex.cpp @@ -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) diff --git a/ginac/expairseq.cpp b/ginac/expairseq.cpp index 1f7fcf41..5a52efe1 100644 --- a/ginac/expairseq.cpp +++ b/ginac/expairseq.cpp @@ -23,7 +23,6 @@ #include #include #include -#include #include "expairseq.h" #include "lst.h" diff --git a/ginac/function.pl b/ginac/function.pl index fac659f5..c6e00834 100755 --- a/ginac/function.pl +++ b/ginac/function.pl @@ -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(serialsecond.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 diff --git a/ginac/matrix.cpp b/ginac/matrix.cpp index b2d4f606..8b747e85 100644 --- a/ginac/matrix.cpp +++ b/ginac/matrix.cpp @@ -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; diff --git a/ginac/ncmul.cpp b/ginac/ncmul.cpp index 7e8dce65..d8e7584b 100644 --- a/ginac/ncmul.cpp +++ b/ginac/ncmul.cpp @@ -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; diff --git a/ginac/ncmul.h b/ginac/ncmul.h index 0f943395..ed1b2997 100644 --- a/ginac/ncmul.h +++ b/ginac/ncmul.h @@ -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; diff --git a/ginac/numeric.cpp b/ginac/numeric.cpp index af2d8eff..228540d7 100644 --- a/ginac/numeric.cpp +++ b/ginac/numeric.cpp @@ -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? diff --git a/ginac/relational.cpp b/ginac/relational.cpp index 5628f25c..a03b60f8 100644 --- a/ginac/relational.cpp +++ b/ginac/relational.cpp @@ -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=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; } ////////// diff --git a/ginac/remember.cpp b/ginac/remember.cpp index 9b06a464..404c7c81 100644 --- a/ginac/remember.cpp +++ b/ginac/remember.cpp @@ -24,7 +24,7 @@ #include #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=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()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()get_successful_hits(); - ++it; - while (it!=end()) { - if (it->get_successful_hits()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()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 & remember_table::remember_tables(void) diff --git a/ginac/simp_lor.cpp b/ginac/simp_lor.cpp index 06eef8ee..e589b18f 100644 --- a/ginac/simp_lor.cpp +++ b/ginac/simp_lor.cpp @@ -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 diff --git a/ginac/symbol.h b/ginac/symbol.h index d547b1d6..3c8c8557 100644 --- a/ginac/symbol.h +++ b/ginac/symbol.h @@ -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); } -- 2.44.0