]> www.ginac.de Git - ginac.git/blobdiff - ginac/symbol.cpp
Happy New Year!
[ginac.git] / ginac / symbol.cpp
index a736088903872dd854dfe55c34020a08a6aed1ea..b7241d52778721e7908eeff350626c00601a382b 100644 (file)
@@ -3,7 +3,7 @@
  *  Implementation of GiNaC's symbolic objects. */
 
 /*
- *  GiNaC Copyright (C) 1999-2009 Johannes Gutenberg University Mainz, Germany
+ *  GiNaC Copyright (C) 1999-2019 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
@@ -23,7 +23,6 @@
 #include "symbol.h"
 #include "lst.h"
 #include "archive.h"
-#include "tostring.h"
 #include "utils.h"
 #include "hash_seed.h"
 #include "inifcns.h"
@@ -106,9 +105,18 @@ void symbol::read_archive(const archive_node &n, lst &sym_lst)
        n.find_string("name", tmp_name);
 
        // If symbol is in sym_lst, return the existing symbol
-       for (lst::const_iterator it = sym_lst.begin(); it != sym_lst.end(); ++it) {
-               if (is_a<symbol>(*it) && (ex_to<symbol>(*it).name == tmp_name)) {
-                       *this = ex_to<symbol>(*it);
+       for (auto & s : sym_lst) {
+               if (is_a<symbol>(s) && (ex_to<symbol>(s).name == tmp_name)) {
+                       *this = ex_to<symbol>(s);
+                       // XXX: This method is responsible for reading realsymbol
+                       // and possymbol objects too. But
+                       // basic::operator=(const basic& other)
+                       // resets status_flags::evaluated if other and *this are
+                       // of different types. Usually this is a good idea, but
+                       // doing this for symbols is wrong (for one, nothing is
+                       // going to set status_flags::evaluated, evaluation will
+                       // loop forever). Therefore we need to restore flags.
+                       setflag(status_flags::evaluated | status_flags::expanded);
                        return;
                }
        }
@@ -141,12 +149,27 @@ static const std::string& get_default_TeX_name(const std::string& name);
 
 // public
 
+std::string symbol::get_name() const
+{
+       if (name.empty()) {
+               name = "symbol" + std::to_string(serial);
+       }
+       return name;
+}
+
+std::string symbol::get_TeX_name() const
+{
+       if (TeX_name.empty()) {
+               return get_default_TeX_name(get_name());
+       }
+       return TeX_name;
+}
+
+// protected
+
 void symbol::do_print(const print_context & c, unsigned level) const
 {
-       if (!name.empty())
-               c.s << name;
-       else
-               c.s << "symbol" << serial;
+       c.s << get_name();
 }
 
 void symbol::do_print_latex(const print_latex & c, unsigned level) const