2015-01-12 13:20:53 -05:00
|
|
|
#include <iostream>
|
|
|
|
#include <sstream>
|
|
|
|
|
|
|
|
#include "atidlas/symbolic/io.h"
|
|
|
|
#include "atidlas/tools/to_string.hpp"
|
|
|
|
|
|
|
|
namespace atidlas
|
|
|
|
{
|
|
|
|
|
|
|
|
#define ATIDLAS_MAP_TO_STRING(NAME) case NAME: return #NAME
|
|
|
|
|
2015-01-31 22:01:48 -05:00
|
|
|
inline std::string to_string(array_expression_node_subtype const & f)
|
2015-01-12 13:20:53 -05:00
|
|
|
{
|
|
|
|
switch(f)
|
|
|
|
{
|
|
|
|
ATIDLAS_MAP_TO_STRING(INVALID_SUBTYPE);
|
|
|
|
ATIDLAS_MAP_TO_STRING(VALUE_SCALAR_TYPE);
|
|
|
|
ATIDLAS_MAP_TO_STRING(DENSE_ARRAY_TYPE);
|
|
|
|
default: return "UNKNOWN";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
inline std::string to_string(lhs_rhs_element const & e)
|
|
|
|
{
|
|
|
|
if(e.type_family==COMPOSITE_OPERATOR_FAMILY)
|
|
|
|
{
|
|
|
|
return"COMPOSITE [" + tools::to_string(e.node_index) + "]";
|
|
|
|
}
|
2015-01-20 11:17:42 -05:00
|
|
|
return tools::to_string(e.subtype);
|
2015-01-12 13:20:53 -05:00
|
|
|
}
|
|
|
|
|
2015-01-31 22:01:48 -05:00
|
|
|
inline std::ostream & operator<<(std::ostream & os, array_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-01-31 22:01:48 -05:00
|
|
|
/** @brief Recursive worker routine for printing a whole array_expression */
|
|
|
|
inline void print_node(std::ostream & os, atidlas::array_expression const & s, size_t node_index, size_t indent = 0)
|
2015-01-12 13:20:53 -05:00
|
|
|
{
|
2015-01-31 22:01:48 -05:00
|
|
|
array_expression::container_type const & nodes = s.tree();
|
|
|
|
array_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;
|
|
|
|
|
|
|
|
if (current_node.lhs.type_family == COMPOSITE_OPERATOR_FAMILY)
|
|
|
|
print_node(os, s, current_node.lhs.node_index, indent+1);
|
|
|
|
|
|
|
|
if (current_node.rhs.type_family == COMPOSITE_OPERATOR_FAMILY)
|
|
|
|
print_node(os, s, current_node.rhs.node_index, indent+1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-31 22:01:48 -05:00
|
|
|
std::string to_string(atidlas::array_expression const & s)
|
2015-01-12 13:20:53 -05:00
|
|
|
{
|
|
|
|
std::ostringstream os;
|
|
|
|
detail::print_node(os, s, s.root());
|
|
|
|
return os.str();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|