X-Git-Url: https://ginac.de/ginac.git//ginac.git?a=blobdiff_plain;f=ginac%2Fsymbol.cpp;h=6a07e2bd8967d80e6597ca3bdc02c963417e1ae7;hb=158748a96ae87d6d65a7c9eb475a96875c290fd4;hp=65386f3af5b2d04d070eccf1cf72e3af60160224;hpb=27d6204effdef95a00af461fff98024e290dbaa7;p=ginac.git diff --git a/ginac/symbol.cpp b/ginac/symbol.cpp index 65386f3a..6a07e2bd 100644 --- a/ginac/symbol.cpp +++ b/ginac/symbol.cpp @@ -3,7 +3,7 @@ * Implementation of GiNaC's symbolic objects. */ /* - * GiNaC Copyright (C) 1999-2001 Johannes Gutenberg University Mainz, Germany + * GiNaC Copyright (C) 1999-2002 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 @@ -27,21 +27,19 @@ #include "lst.h" #include "print.h" #include "archive.h" -#include "debugmsg.h" #include "tostring.h" #include "utils.h" namespace GiNaC { -GINAC_IMPLEMENT_REGISTERED_CLASS_NO_CTORS(symbol, basic) +GINAC_IMPLEMENT_REGISTERED_CLASS(symbol, basic) ////////// -// default ctor, dtor, copy ctor assignment operator and helpers +// default ctor, dtor, copy ctor, assignment operator and helpers ////////// symbol::symbol() : inherited(TINFO_symbol), serial(next_serial++) { - debugmsg("symbol default ctor", LOGLEVEL_CONSTRUCT); name = TeX_name = autoname_prefix()+ToString(serial); asexinfop = new assigned_ex_info; setflag(status_flags::evaluated | status_flags::expanded); @@ -55,7 +53,7 @@ void symbol::copy(const symbol & other) TeX_name = other.TeX_name; serial = other.serial; asexinfop = other.asexinfop; - ++asexinfop->refcount; + ++(asexinfop->refcount); } void symbol::destroy(bool call_parent) @@ -72,15 +70,8 @@ void symbol::destroy(bool call_parent) // public -symbol::symbol(const symbol & other) -{ - debugmsg("symbol copy ctor", LOGLEVEL_CONSTRUCT); - copy(other); -} - symbol::symbol(const std::string & initname) : inherited(TINFO_symbol) { - debugmsg("symbol ctor from string", LOGLEVEL_CONSTRUCT); name = initname; TeX_name = default_TeX_name(); serial = next_serial++; @@ -90,7 +81,6 @@ symbol::symbol(const std::string & initname) : inherited(TINFO_symbol) symbol::symbol(const std::string & initname, const std::string & texname) : inherited(TINFO_symbol) { - debugmsg("symbol ctor from string", LOGLEVEL_CONSTRUCT); name = initname; TeX_name = texname; serial = next_serial++; @@ -105,7 +95,6 @@ symbol::symbol(const std::string & initname, const std::string & texname) : inhe /** Construct object from archive_node. */ symbol::symbol(const archive_node &n, const lst &sym_lst) : inherited(n, sym_lst) { - debugmsg("symbol ctor from archive_node", LOGLEVEL_CONSTRUCT); serial = next_serial++; if (!(n.find_string("name", name))) name = autoname_prefix() + ToString(serial); @@ -122,7 +111,7 @@ ex symbol::unarchive(const archive_node &n, const lst &sym_lst) // If symbol is in sym_lst, return the existing symbol for (unsigned i=0; i(sym_lst.op(i)).name == ex_to(s).name)) + if (is_a(sym_lst.op(i)) && (ex_to(sym_lst.op(i)).name == ex_to(s).name)) return sym_lst.op(i); } return s; @@ -143,16 +132,8 @@ void symbol::archive(archive_node &n) const // public -basic *symbol::duplicate() const -{ - debugmsg("symbol duplicate", LOGLEVEL_DUPLICATE); - return new symbol(*this); -} - void symbol::print(const print_context & c, unsigned level) const { - debugmsg("symbol print", LOGLEVEL_PRINT); - if (is_a(c)) { c.s << std::string(level, ' ') << name << " (" << class_name() << ")" @@ -160,9 +141,14 @@ void symbol::print(const print_context & c, unsigned level) const << std::hex << ", hash=0x" << hashvalue << ", flags=0x" << flags << std::dec << std::endl; - } else if (is_a(c)) + } else if (is_a(c)) { c.s << TeX_name; - else + } else if (is_a(c)) { + c.s << class_name() << "('" << name; + if (TeX_name != default_TeX_name()) + c.s << "','" << TeX_name; + c.s << "')"; + } else c.s << name; } @@ -180,24 +166,6 @@ bool symbol::info(unsigned inf) const return inherited::info(inf); } -int symbol::degree(const ex & s) const -{ - return is_equal(ex_to(s)) ? 1 : 0; -} - -int symbol::ldegree(const ex & s) const -{ - return is_equal(ex_to(s)) ? 1 : 0; -} - -ex symbol::coeff(const ex & s, int n) const -{ - if (is_equal(ex_to(s))) - return n==1 ? _ex1 : _ex0; - else - return n==0 ? *this : _ex0; -} - ex symbol::eval(int level) const { if (level == -max_recursion_level) @@ -245,10 +213,7 @@ bool symbol::is_equal_same_type(const basic & other) const unsigned symbol::calchash(void) const { - // this is where the schoolbook method - // (golden_ratio_hash(tinfo()) ^ serial) - // is not good enough yet... - hashvalue = golden_ratio_hash(golden_ratio_hash(tinfo()) ^ serial); + hashvalue = golden_ratio_hash(tinfo() ^ serial); setflag(status_flags::hash_calculated); return hashvalue; }