2015-01-12 13:20:53 -05:00
|
|
|
#include <iostream>
|
|
|
|
#include <sstream>
|
2015-08-06 20:20:08 -07:00
|
|
|
#include <string>
|
2015-01-12 13:20:53 -05:00
|
|
|
|
2015-04-29 15:50:57 -04:00
|
|
|
#include "isaac/symbolic/io.h"
|
2015-08-06 20:20:08 -07:00
|
|
|
#include "to_string.hpp"
|
2015-01-12 13:20:53 -05:00
|
|
|
|
2015-04-29 15:50:57 -04:00
|
|
|
namespace isaac
|
2015-01-12 13:20:53 -05:00
|
|
|
{
|
|
|
|
|
2015-04-29 15:50:57 -04:00
|
|
|
#define ISAAC_MAP_TO_STRING(NAME) case NAME: return #NAME
|
2015-01-12 13:20:53 -05:00
|
|
|
|
2015-12-19 02:04:39 -05:00
|
|
|
inline std::string to_string(node_type const & f)
|
2015-01-12 13:20:53 -05:00
|
|
|
{
|
|
|
|
switch(f)
|
|
|
|
{
|
2015-04-29 15:50:57 -04:00
|
|
|
ISAAC_MAP_TO_STRING(INVALID_SUBTYPE);
|
|
|
|
ISAAC_MAP_TO_STRING(VALUE_SCALAR_TYPE);
|
|
|
|
ISAAC_MAP_TO_STRING(DENSE_ARRAY_TYPE);
|
2015-01-12 13:20:53 -05:00
|
|
|
default: return "UNKNOWN";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
inline std::string to_string(lhs_rhs_element const & e)
|
|
|
|
{
|
2015-12-19 02:04:39 -05:00
|
|
|
if(e.subtype==COMPOSITE_OPERATOR_TYPE)
|
2015-01-12 13:20:53 -05:00
|
|
|
{
|
2015-08-06 20:20:08 -07:00
|
|
|
return"COMPOSITE [" + tools::to_string(e.node_index) + "]";
|
2015-01-12 13:20:53 -05:00
|
|
|
}
|
2015-08-06 20:20:08 -07:00
|
|
|
return tools::to_string(e.subtype);
|
2015-01-12 13:20:53 -05:00
|
|
|
}
|
|
|
|
|
2015-09-30 15:31:41 -04:00
|
|
|
inline std::ostream & operator<<(std::ostream & os, math_expression::node const & s_node)
|
2015-01-12 13:20:53 -05:00
|
|
|
{
|
|
|
|
os << "LHS: " << to_string(s_node.lhs) << "|" << s_node.lhs.dtype << ", "
|
|
|
|
<< "OP: " << s_node.op.type_family << " | " << s_node.op.type << ", "
|
|
|
|
<< "RHS: " << to_string(s_node.rhs) << "|" << s_node.rhs.dtype;
|
|
|
|
|
|
|
|
return os;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
namespace detail
|
|
|
|
{
|
2015-09-30 15:31:41 -04:00
|
|
|
/** @brief Recursive worker routine for printing a whole math_expression */
|
|
|
|
inline void print_node(std::ostream & os, isaac::math_expression const & s, size_t node_index, size_t indent = 0)
|
2015-01-12 13:20:53 -05:00
|
|
|
{
|
2015-09-30 15:31:41 -04:00
|
|
|
math_expression::container_type const & nodes = s.tree();
|
|
|
|
math_expression::node const & current_node = nodes[node_index];
|
2015-01-12 13:20:53 -05:00
|
|
|
|
|
|
|
for (size_t i=0; i<indent; ++i)
|
|
|
|
os << " ";
|
|
|
|
|
|
|
|
os << "Node " << node_index << ": " << current_node << std::endl;
|
|
|
|
|
2015-12-19 02:04:39 -05:00
|
|
|
if (current_node.lhs.subtype == COMPOSITE_OPERATOR_TYPE)
|
2015-01-12 13:20:53 -05:00
|
|
|
print_node(os, s, current_node.lhs.node_index, indent+1);
|
|
|
|
|
2015-12-19 02:04:39 -05:00
|
|
|
if (current_node.rhs.subtype == COMPOSITE_OPERATOR_TYPE)
|
2015-01-12 13:20:53 -05:00
|
|
|
print_node(os, s, current_node.rhs.node_index, indent+1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-30 15:31:41 -04:00
|
|
|
std::string to_string(isaac::math_expression const & s)
|
2015-01-12 13:20:53 -05:00
|
|
|
{
|
|
|
|
std::ostringstream os;
|
|
|
|
detail::print_node(os, s, s.root());
|
|
|
|
return os.str();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|