void operator() (utree const& ut){ using spirit::utree_type; typedef utree::const_iterator iterator; int id = cur_id; n_id++; switch (ut.which()) { case utree_type::reference_type: out << prefix << id << " [label=\"[reference]\"];\n"; out << prefix << id << " -> " << prefix << cur_id << ";\n"; (*this)(ut.deref()); return; case utree_type::range_type: case utree_type::list_type: { iterator it, end; int start_id = n_id; if (annotations[ut.tag()].second == json_object) { out << prefix << id << " [label=\"[object]\"];\n"; it = ut.front().begin(); end = ut.front().end(); n_id += ut.front().size(); } else { if (annotations[ut.tag()].second == json_array) { out << prefix << id << " [label=\"[array]\"];\n"; } else if (annotations[ut.tag()].second == json_pair) { out << prefix << id << " [label=\"[pair]\"];\n"; } else { BOOST_ASSERT(false); return; } it = ut.begin(); end = ut.end(); n_id += ut.size(); } for (int i=0; it != end; ++it, ++i) { cur_id = start_id+i; out << prefix << id << " -> " << prefix << cur_id << ";\n"; (*this)(*it); } return; } default: break; } utree::visit(ut, *this); }
utree expression::eval_node(utree const& node) { //std::cout << node << " " << node.which() << " " << get_node_type(node) << "\n"; if (node.which() == spirit::utree_type::list_type) { switch(get_node_type(node)) { case CARTO_EXP_PLUS: BOOST_ASSERT(node.size()==2); return eval_add( eval_node(node.front()), eval_node(node.back()) ); case CARTO_EXP_MINUS: BOOST_ASSERT(node.size()==2); return eval_sub( eval_node(node.front()), eval_node(node.back()) ); case CARTO_EXP_TIMES: BOOST_ASSERT(node.size()==2); return eval_mult( eval_node(node.front()), eval_node(node.back()) ); case CARTO_EXP_DIVIDE: BOOST_ASSERT(node.size()==2); return eval_div( eval_node(node.front()), eval_node(node.back()) ); case CARTO_EXP_NEG: BOOST_ASSERT(node.size()==1); return eval_mult( utree(-1.0), eval_node(node.back()) ); case CARTO_EXP_FUNCTION: return eval_function(node); case CARTO_EXP_COLOR: BOOST_ASSERT(node.size()==4); return node; //case exp_var: // return eval_var(node); default: { std::stringstream out; out << "Invalid expression node type: " << get_node_type(node); throw carto_error(out.str(), get_location(node)); } } } else if (get_node_type(node) == CARTO_EXP_VAR) { return eval_var(node); } //} else { // std::cout << "Shouldn't be here!\n"; // std::cout << "Node: " << node << "\n"; // std::cout << "Node which: " << node.which() << "\n"; // std::cout << "Node type: " << get_node_type(node) << "\n"; // if (node.which() == spirit::utree_type::list_type) // std::cout << "Node size: " << node.size() << "\n"; //} return node; }
void print_object (utree const& ut) const { typedef utree::const_iterator iterator; iterator it = ut.front().begin(), end = ut.front().end(); (*this)('{'); (*this)(*it); ++it; for (; it != end; ++it) { out << ", "; (*this)(*it); } (*this)('}'); }