X-Git-Url: https://www.ginac.de/ginac.git//ginac.git?p=ginac.git;a=blobdiff_plain;f=ginac%2Fwildcard.cpp;h=62a4eb5086d552fd1c75a304045c739f4717b4f5;hp=33ccb461788441371846a26ccea9d7e0e4071199;hb=56fe6d8d9e7bd113e44bf2eadf26af0b9d480a01;hpb=708e9e647029af699333fceffc0a76bef70a4709 diff --git a/ginac/wildcard.cpp b/ginac/wildcard.cpp index 33ccb461..62a4eb50 100644 --- a/ginac/wildcard.cpp +++ b/ginac/wildcard.cpp @@ -3,7 +3,7 @@ * Implementation of GiNaC's wildcard objects. */ /* - * GiNaC Copyright (C) 1999-2001 Johannes Gutenberg University Mainz, Germany + * GiNaC Copyright (C) 1999-2006 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 @@ -17,55 +17,48 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#include + #include "wildcard.h" -#include "print.h" #include "archive.h" #include "utils.h" -#include "debugmsg.h" namespace GiNaC { -GINAC_IMPLEMENT_REGISTERED_CLASS(wildcard, basic) +GINAC_IMPLEMENT_REGISTERED_CLASS_OPT(wildcard, basic, + print_func(&wildcard::do_print). + print_func(&wildcard::do_print_tree). + print_func(&wildcard::do_print_python_repr)) ////////// -// default constructor, destructor, copy constructor assignment operator and helpers +// default constructor ////////// -wildcard::wildcard() : label(0) -{ - debugmsg("wildcard default constructor", LOGLEVEL_CONSTRUCT); - tinfo_key = TINFO_wildcard; -} - -void wildcard::copy(const wildcard & other) +wildcard::wildcard() : inherited(&wildcard::tinfo_static), label(0) { - inherited::copy(other); - label = other.label; + setflag(status_flags::evaluated | status_flags::expanded); } -DEFAULT_DESTROY(wildcard) - ////////// // other constructors ////////// -wildcard::wildcard(unsigned l) : label(l) +wildcard::wildcard(unsigned l) : inherited(&wildcard::tinfo_static), label(l) { - debugmsg("wildcard constructor from unsigned", LOGLEVEL_CONSTRUCT); - tinfo_key = TINFO_wildcard; + setflag(status_flags::evaluated | status_flags::expanded); } ////////// // archiving ////////// -wildcard::wildcard(const archive_node &n, const lst &sym_lst) : inherited(n, sym_lst) +wildcard::wildcard(const archive_node &n, lst &sym_lst) : inherited(n, sym_lst) { - debugmsg("wildcard constructor from archive_node", LOGLEVEL_CONSTRUCT); n.find_unsigned("label", label); + setflag(status_flags::evaluated | status_flags::expanded); } void wildcard::archive(archive_node &n) const @@ -77,12 +70,12 @@ void wildcard::archive(archive_node &n) const DEFAULT_UNARCHIVE(wildcard) ////////// -// functions overriding virtual functions from bases classes +// functions overriding virtual functions from base classes ////////// int wildcard::compare_same_type(const basic & other) const { - GINAC_ASSERT(is_of_type(other, wildcard)); + GINAC_ASSERT(is_a(other)); const wildcard &o = static_cast(other); if (label == o.label) @@ -91,24 +84,29 @@ int wildcard::compare_same_type(const basic & other) const return label < o.label ? -1 : 1; } -void wildcard::print(const print_context & c, unsigned level = 0) const +void wildcard::do_print(const print_context & c, unsigned level) const +{ + c.s << "$" << label; +} + +void wildcard::do_print_tree(const print_tree & c, unsigned level) const +{ + c.s << std::string(level, ' ') << class_name() << "(" << label << ")" << " @" << this + << std::hex << ", hash=0x" << hashvalue << ", flags=0x" << flags << std::dec + << std::endl; +} + +void wildcard::do_print_python_repr(const print_python_repr & c, unsigned level) const { - debugmsg("wildcard print", LOGLEVEL_PRINT); - - if (is_of_type(c, print_tree)) { - c.s << std::string(level, ' ') << class_name() << " (" << label << ")" - << std::hex << ", hash=0x" << hashvalue << ", flags=0x" << flags << std::dec - << std::endl; - } else - c.s << "$" << label; + c.s << class_name() << '(' << label << ')'; } -unsigned wildcard::calchash(void) const +unsigned wildcard::calchash() const { // this is where the schoolbook method // (golden_ratio_hash(tinfo()) ^ label) // is not good enough yet... - hashvalue = golden_ratio_hash(golden_ratio_hash(tinfo()) ^ label); + hashvalue = golden_ratio_hash(golden_ratio_hash((p_int)tinfo()) ^ label); setflag(status_flags::hash_calculated); return hashvalue; } @@ -118,7 +116,17 @@ bool wildcard::match(const ex & pattern, lst & repl_lst) const // Wildcards must match each other exactly (this is required for // subs() to work properly because in the final step it substitutes // all wildcards by their matching expressions) - return is_equal(*pattern.bp); + return is_equal(ex_to(pattern)); +} + +bool haswild(const ex & x) +{ + if (is_a(x)) + return true; + for (size_t i=0; i