symbol: get rid of assign/unassign (for performance and other reasons).
[ginac.git] / ginac / symbol.cpp
index f1b2be6e13885b3cc337c7cde26e9cb689894559..cf31cb490a4de81de5638f06f7ab2900487ae1a3 100644 (file)
@@ -45,7 +45,7 @@ GINAC_IMPLEMENT_REGISTERED_CLASS_OPT(symbol, basic,
 // symbol
 
 symbol::symbol()
- : inherited(&symbol::tinfo_static), asexinfop(new assigned_ex_info), serial(next_serial++), name(autoname_prefix() + ToString(serial)), TeX_name(name), domain(domain::complex), ret_type(return_types::commutative), ret_type_tinfo(&symbol::tinfo_static)
+ : inherited(&symbol::tinfo_static), serial(next_serial++), name(autoname_prefix() + ToString(serial)), TeX_name(name), domain(domain::complex), ret_type(return_types::commutative), ret_type_tinfo(&symbol::tinfo_static)
 {
        setflag(status_flags::evaluated | status_flags::expanded);
 }
@@ -73,25 +73,25 @@ possymbol::possymbol()
 // symbol
 
 symbol::symbol(const std::string & initname, unsigned domain)
- : inherited(&symbol::tinfo_static), asexinfop(new assigned_ex_info), serial(next_serial++), name(initname), TeX_name(default_TeX_name()), domain(domain), ret_type(return_types::commutative), ret_type_tinfo(&symbol::tinfo_static)
+ : inherited(&symbol::tinfo_static), serial(next_serial++), name(initname), TeX_name(default_TeX_name()), domain(domain), ret_type(return_types::commutative), ret_type_tinfo(&symbol::tinfo_static)
 {
        setflag(status_flags::evaluated | status_flags::expanded);
 }
 
 symbol::symbol(const std::string & initname, unsigned rt, tinfo_t rtt, unsigned domain)
- : inherited(&symbol::tinfo_static), asexinfop(new assigned_ex_info), serial(next_serial++), name(initname), TeX_name(default_TeX_name()), domain(domain), ret_type(rt), ret_type_tinfo(rtt)
+ : inherited(&symbol::tinfo_static), serial(next_serial++), name(initname), TeX_name(default_TeX_name()), domain(domain), ret_type(rt), ret_type_tinfo(rtt)
 {
        setflag(status_flags::evaluated | status_flags::expanded);
 }
 
 symbol::symbol(const std::string & initname, const std::string & texname, unsigned domain)
- : inherited(&symbol::tinfo_static), asexinfop(new assigned_ex_info), serial(next_serial++), name(initname), TeX_name(texname), domain(domain), ret_type(return_types::commutative), ret_type_tinfo(&symbol::tinfo_static)
+ : inherited(&symbol::tinfo_static), serial(next_serial++), name(initname), TeX_name(texname), domain(domain), ret_type(return_types::commutative), ret_type_tinfo(&symbol::tinfo_static)
 {
        setflag(status_flags::evaluated | status_flags::expanded);
 }
 
 symbol::symbol(const std::string & initname, const std::string & texname, unsigned rt, tinfo_t rtt, unsigned domain)
- : inherited(&symbol::tinfo_static), asexinfop(new assigned_ex_info), serial(next_serial++), name(initname), TeX_name(texname), domain(domain), ret_type(rt), ret_type_tinfo(rtt)
+ : inherited(&symbol::tinfo_static),  serial(next_serial++), name(initname), TeX_name(texname), domain(domain), ret_type(rt), ret_type_tinfo(rtt)
 {
        setflag(status_flags::evaluated | status_flags::expanded);
 }
@@ -130,7 +130,7 @@ possymbol::possymbol(const std::string & initname, const std::string & texname,
 
 /** Construct object from archive_node. */
 symbol::symbol(const archive_node &n, lst &sym_lst)
- : inherited(n, sym_lst), asexinfop(new assigned_ex_info), serial(next_serial++)
+ : inherited(n, sym_lst), serial(next_serial++)
 {
        if (!n.find_string("name", name))
                name = autoname_prefix() + ToString(serial);
@@ -228,22 +228,6 @@ bool symbol::info(unsigned inf) const
        return inherited::info(inf);
 }
 
-ex symbol::eval(int level) const
-{
-       if (level == -max_recursion_level)
-               throw(std::runtime_error("max recursion level reached"));
-       
-       if (asexinfop->is_assigned) {
-               setflag(status_flags::evaluated);
-               if (level==1)
-                       return (asexinfop->assigned_expression);
-               else
-                       return (asexinfop->assigned_expression).eval(level);
-       } else {
-               return this->hold();
-       }
-}
-
 ex symbol::conjugate() const
 {
        if (this->domain == domain::complex) {
@@ -318,24 +302,6 @@ unsigned symbol::calchash() const
 // non-virtual functions in this class
 //////////
 
-// public
-
-void symbol::assign(const ex & value)
-{
-       asexinfop->is_assigned = true;
-       asexinfop->assigned_expression = value;
-       clearflag(status_flags::evaluated | status_flags::expanded);
-}
-
-void symbol::unassign()
-{
-       if (asexinfop->is_assigned) {
-               asexinfop->is_assigned = false;
-               asexinfop->assigned_expression = _ex0;
-       }
-       setflag(status_flags::evaluated | status_flags::expanded);
-}
-
 // private
 
 /** Symbols not constructed with a string get one assigned using this
@@ -376,13 +342,4 @@ std::string symbol::default_TeX_name() const
 
 unsigned symbol::next_serial = 0;
 
-//////////
-// subclass assigned_ex_info
-//////////
-
-/** Default ctor.  Defaults to unassigned. */
-symbol::assigned_ex_info::assigned_ex_info() throw() : is_assigned(false)
-{
-}
-
 } // namespace GiNaC