From 9a4f392521083d28e1c238e7898ab1d2ac5b73cd Mon Sep 17 00:00:00 2001 From: Jens Vollinga Date: Tue, 26 Jul 2011 20:39:29 +0200 Subject: [PATCH 1/1] Quick and dirty bug fix for the parser to read GiNaC::lst again. The parser only accepts lst in the form lst(...) not {...}, though. Function prototype can now have a argument size of 0 to indicate functions with an arbitrary number of arguments (like lst). --- ginac/parser/default_reader.cpp | 9 +++++++++ ginac/parser/parse_context.h | 15 ++++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/ginac/parser/default_reader.cpp b/ginac/parser/default_reader.cpp index 4f8c69c3..69b1a0c4 100644 --- a/ginac/parser/default_reader.cpp +++ b/ginac/parser/default_reader.cpp @@ -40,15 +40,22 @@ static ex sqrt_reader(const exvector& ev) { return GiNaC::sqrt(ev[0]); } + static ex pow_reader(const exvector& ev) { return GiNaC::pow(ev[0], ev[1]); } + static ex power_reader(const exvector& ev) { return GiNaC::power(ev[0], ev[1]); } +static ex lst_reader(const exvector& ev) +{ + return GiNaC::lst(ev.begin(), ev.end()); +} + // function::registered_functions() is protected, but we need to access it // TODO: add a proper const method to the `function' class, so we don't @@ -87,6 +94,7 @@ const prototype_table& get_default_reader() reader[make_pair("sqrt", 1)] = sqrt_reader; reader[make_pair("pow", 2)] = pow_reader; reader[make_pair("power", 2)] = power_reader; + reader[make_pair("lst", 0)] = lst_reader; std::vector::const_iterator it = registered_functions_hack::get_registered_functions().begin(); std::vector::const_iterator end = @@ -112,6 +120,7 @@ const prototype_table& get_builtin_reader() reader[make_pair("sqrt", 1)] = sqrt_reader; reader[make_pair("pow", 2)] = pow_reader; reader[make_pair("power", 2)] = power_reader; + reader[make_pair("lst", 0)] = lst_reader; enum { log, exp, diff --git a/ginac/parser/parse_context.h b/ginac/parser/parse_context.h index f1042528..60151fd3 100644 --- a/ginac/parser/parse_context.h +++ b/ginac/parser/parse_context.h @@ -88,7 +88,20 @@ typedef ex (*reader_func)(const exvector& args); * function pointer!! The unsigned has to correspond to the serial number of * the defined GiNaC function. */ -typedef std::map prototype_table; +class PrototypeLess +{ +public: + bool operator()(const prototype& p1, const prototype& p2) const + { + int s = p1.first.compare(p2.first); + if (s == 0) { + if ((p1.second == 0) || (p2.second == 0)) return false; + return p1.second < p2.second; + } + return s < 0; + } +}; +typedef std::map prototype_table; /** * Default prototype table. -- 2.44.0