Tree::Expr TreeRewriter::operator()(const Tree::BinaryOpExpr& e) { //(e.op.op) . (e.lhs) . (e.rhs) //(FN2 ! (#arg0, #arg1)) // @ [fnname <- e.op.op, arg0 <- T(e.lhs), arg1 <- T(e.rhs)] Tree::Expr elhs = apply_visitor(*this, e.lhs); Tree::Expr erhs = apply_visitor(*this, e.rhs); Tree::Expr result; if (e.op.cbn) { result = Tree::PhiAppExpr ( Tree::PhiAppExpr(Tree::IdentExpr(e.op.op), e.lhs), e.rhs ); } else { result = Tree::LambdaAppExpr ( Tree::LambdaAppExpr(Tree::IdentExpr(e.op.op), e.lhs), e.rhs ); } return apply_visitor(*this, result); }
static var_t normalize(tyinfo_map_t& tm, const string& key, const var_t& v) { vector<var_t> vec = boost::get<vector<var_t> >(v); type_t typ = tm[key]; // {{a,b,c}}や{{a}}, {{}}のケースか,primitive型で{a}などのケース if (vec.size() == 1 && (is_prim_type(typ) || is_vector(vec[0]))) { return apply_visitor(var_normalizer(vec[0]), typ); } // {a}, {a,b,c}, {{a},{b}}のケース return apply_visitor(var_normalizer(v), typ); }
locked_container_type lock() const { locked_container_type locked_objects; tracked_container_type::const_iterator it; for(it = tracked_objects().begin(); it != tracked_objects().end(); ++it) { locked_objects.push_back(apply_visitor(detail::lock_weak_ptr_visitor(), *it)); if(apply_visitor(detail::expired_weak_ptr_visitor(), *it)) { throw expired_slot(); } } return locked_objects; }
Tree::Expr TreeRewriter::operator()(const Tree::UnaryOpExpr& e) { //(FN1 ! (#arg0)) @ [fnname <- e.op.op, arg0 <- T(e.e)] Tree::Expr expr = apply_visitor(*this, e.e); Tree::Expr result = Tree::LambdaAppExpr ( Tree::IdentExpr(e.op.op), expr ); return apply_visitor(*this, result); }
void config_option::report_type_error(size_t ln, config_value& x, const char* expected) { type_name_visitor tnv; std::cerr << "error in line " << ln << ": expected " << expected << " found " << apply_visitor(tnv, x) << std::endl; }
hermit::microxml operator()( const std::vector< hermit::json > &src ) const { if( src.size() < 2 ) { throw boost::mpl::int_<3>(); } std::vector< hermit::json >::const_iterator iter = src.begin(); if( iter->which() != 0 ) { throw boost::mpl::int_<4>(); } hermit::microxml temp; temp.tag = boost::get< std::u32string >( *iter ); ++iter; if( iter->which() != 2 ) { throw boost::mpl::int_<5>(); } const std::map< std::u32string, hermit::json > &attrs = boost::get< std::map< std::u32string, hermit::json > >( *iter ); for( const auto &elem : attrs ) { if( elem.second.which() != 0 ) { throw boost::mpl::int_<6>(); } temp.attribute[ elem.first ] = boost::get< std::u32string >( elem.second ); } for( ++iter; iter != src.end(); ++iter ) { if( iter->which() == 3 ) temp.child.push_back( apply_visitor( json2microxml(), *iter ) ); else if( iter->which() == 0 ) temp.child.push_back( boost::get< std::u32string >( *iter ) ); else throw boost::mpl::int_<7>(); } return temp; }
bool operator() (ti_tuple_t tv) const { vector<var_t> vec = boost::get<vector<var_t> >(v_); for (unsigned int i = 0; i < tv.size(); i++) { if (!apply_visitor(range_checker(vec[i]), tv[i])) return false; } return true; }
sch_node instantiate_locally(sd_node_ref nref, sd_tree& tree) { auto& node = tree[nref.nd]; auto defn = node.defn; // Should we attempt to maintain data already existing at this node? // Only if all of the following conditions are satisfied... bool maintain = defn // Non-null definition && node.schema // Non-null schema && node.schema.get_id() == defn.get_id(); // Matching ids if(!maintain) { // Remove any existing children tree.clear_children(nref.nd); } if(defn) { #if __DEBUG_OUTPUT std::cout << "instantiating: " << defn.get_name() << std::endl; #endif local_inst_visitor vis{ tree, nref }; return defn.apply_visitor(vis); } else { return{}; } }
VARIANT_INLINE std::basic_ostream<charT, traits>& operator<< (std::basic_ostream<charT, traits>& out, variant<Types...> const& rhs) { detail::printer<std::basic_ostream<charT, traits>> visitor(out); apply_visitor(visitor, rhs); return out; }
expression remove_reference( const std::shared_ptr< llvm::LLVMContext > &context, const std::shared_ptr< ir_builder_t > &ir_builder, const expression &value ) { return apply_visitor( node::remove_reference( context, ir_builder, value ), value.type() ); }
result_type unfold ( ast::paragraph const &source , ast::unfolded::staff &target ) { staff_converter unfold(target); return std::all_of(source.begin(), source.end(), apply_visitor(unfold)); }
result_type unfold ( ast::part const &source , ast::unfolded::part &target ) { BOOST_ASSERT(!source.empty()); size_t const staves{source.front().paragraphs.size()}; BOOST_ASSERT(std::all_of(std::next(source.begin()), source.end(), [staves](ast::section const §ion) -> bool { return section.paragraphs.size() == staves; })); for (unsigned int i = 0; i < staves; ++i) target.emplace_back(); for (ast::section const §ion: source) { int i = 0; for (ast::paragraph const ¶graph: section.paragraphs) { if (!unfold(paragraph, target.at(i++))) return false; } } std::size_t staff_nr = 0; for (ast::unfolded::staff &staff: target) { doubling_decoder undouble(report_error); if (!std::all_of(staff.begin(), staff.end(), apply_visitor(undouble))) return false; staff_nr += 1; } return true; }
result_type operator() (std::size_t staff_index, ast::part &part) { interval_direction interval_dir = interval_direction::down; switch (staff_index) { case 0: interval_dir = interval_direction::down; break; case 1: interval_dir = interval_direction::up; break; default: //report_error(part.id, L"No support for parts with more then two staves yet"); BOOST_ASSERT(false); } calculate_octaves.set(interval_dir); disambiguate_values.set(global_time_signature); calculate_alterations.set(global_key_signature); for (ast::section §ion: part) { ast::paragraph ¶graph = section.paragraphs[staff_index]; if (!std::all_of( std::begin(paragraph), std::end(paragraph) , apply_visitor(*this))) return false; } return disambiguate_values.end_of_staff(); }
void test() { util::uniform_random_real<double, std::random_device> distr(-10.0, 10.0); std::array<double, 4> seg1; std::array<double, 4> seg2; for (size_t k = 0; k < 2500; ++k) { for (size_t i = 0; i < seg1.size(); ++i) { seg1[i] = distr(); seg2[i] = distr(); } auto cgal_res = CGAL::intersection(CGAL::Segment_2<CGAL::Exact_predicates_exact_constructions_kernel> (CGAL::Point_2<CGAL::Exact_predicates_exact_constructions_kernel>(seg1[0], seg1[1]), CGAL::Point_2<CGAL::Exact_predicates_exact_constructions_kernel>(seg1[2], seg1[3])), CGAL::Segment_2<CGAL::Exact_predicates_exact_constructions_kernel> (CGAL::Point_2<CGAL::Exact_predicates_exact_constructions_kernel>(seg2[0], seg2[1]), CGAL::Point_2<CGAL::Exact_predicates_exact_constructions_kernel>(seg2[2], seg2[3]))); auto res = cg::intersection(cg::segment_2(cg::point_2(seg1[0], seg1[1]), cg::point_2(seg1[2], seg1[3])), cg::segment_2(cg::point_2(seg2[0], seg2[1]), cg::point_2(seg2[2], seg2[3])), -300); visitor_t visitor; if (const CGAL::Point_2<CGAL::Exact_predicates_exact_constructions_kernel> *ipoint = CGAL::object_cast<CGAL::Point_2<CGAL::Exact_predicates_exact_constructions_kernel>>(&cgal_res)) { visitor.numbers.push_back(CGAL::to_double((*ipoint).x())); visitor.numbers.push_back(CGAL::to_double((*ipoint).y())); res.apply_visitor(visitor); } else { if (const CGAL::Segment_2<CGAL::Exact_predicates_exact_constructions_kernel> *iseg = CGAL::object_cast<CGAL::Segment_2<CGAL::Exact_predicates_exact_constructions_kernel>>(&cgal_res)) { visitor.numbers.push_back(CGAL::to_double((*iseg)[0].x())); visitor.numbers.push_back(CGAL::to_double((*iseg)[0].y())); visitor.numbers.push_back(CGAL::to_double((*iseg)[1].x())); visitor.numbers.push_back(CGAL::to_double((*iseg)[1].y())); res.apply_visitor(visitor); } else { res.apply_visitor(visitor); } } } }
std::size_t Element ::size() const { return ( (this->_value.get_type() == Value::Type::Empty)?0: apply_visitor(Size(), this->_value)); }
bool operator() (ti_vect_t tp) const { vector<var_t> vec = boost::get<vector<var_t> >(v_); if (tp.first >= 0 && tp.first != static_cast<int>(vec.size())) return false; for (unsigned int i = 0; i < vec.size(); i++) { if (!apply_visitor(range_checker(vec[i]), tp.second)) return false; } return true; }
/* CElement operator()(const pair<_null_type, sigout>& v)const { return CEPair(v.first, v.second); //errorhandling }*/ CElement operator()(const pair<CEFunction, CElement>& fo)const{ cout<<"-e-3--\n"; return std::move(fo.first._function ? fo.first._function ( apply_visitor(evaluate_crystal<T>(),fo.second)) : CElement() ) //CEPair( _null_type, fo) ; }
bool Element ::empty() const { return ( (this->_value.get_type() == Value::Type::Empty) || apply_visitor(Empty(), this->_value)); }
hermit::messagepack operator()( const std::vector< hermit::json > &src ) const { std::vector< hermit::messagepack > temp; std::transform( src.begin(), src.end(), std::back_inserter( temp ), []( const hermit::json &elem ) { return apply_visitor( json2messagepack(), elem ); } ); return temp; }
double BHE_1U::updateFlowRateAndTemperature(double const T_out, double const current_time) { auto values = apply_visitor( [&](auto const& control) { return control(T_out, current_time); }, flowAndTemperatureControl); updateHeatTransferCoefficients(values.flow_rate); return values.temperature; }
var_t operator() (ti_vect_t tp) const { if (!is_vector(v_)) return v_; vector<var_t> vec = boost::get<vector<var_t> >(v_); vector<var_t> result; for (unsigned int i = 0; i < vec.size(); i++) { result.push_back(apply_visitor(var_normalizer(vec[i]), tp.second)); } return result; }
bool expired() const { tracked_container_type::const_iterator it; for(it = tracked_objects().begin(); it != tracked_objects().end(); ++it) { if(apply_visitor(detail::expired_weak_ptr_visitor(), *it)) return true; } return false; }
void operator()(ast::section const& section) { out; out << "section(" << section.tag << "): " << section.key << "\n"; ++level; for (auto const& content : section.contents) apply_visitor(*this, content); --level; }
void config_option::report_type_error(size_t ln, config_value& x, const char* expected, optional<std::ostream&> out) { if (!out) return; type_name_visitor tnv; *out << "error in line " << ln << ": expected " << expected << " found " << apply_visitor(tnv, x) << '\n'; }
expression modulus( const std::shared_ptr< llvm::LLVMContext > &context, const std::shared_ptr< ir_builder_t > &ir_builder, const expression &left_expr, const expression &right_expr ) { const expression left = remove_reference( context, ir_builder, left_expr ); const expression right = remove_reference( context, ir_builder, right_expr ); return apply_visitor( node::modulus( context, ir_builder, left, right ), left.type(), right.type() ); }
std::string operator()(tag::case_, Node&&, Tail&&, Int&& value)const{ if( value == typename Node::arg0() ){ return mpl::c_str<typename Node::arg1>::value; } else{ using head = typename mpl::front<Tail>::type; using tail = typename mpl::pop_front<Tail>::type; return apply_visitor(*this, head(), tail(), value); } }
var_t operator() (ti_tuple_t tv) const { if (!is_vector(v_)) return v_; vector<var_t> vec = boost::get<vector<var_t> >(v_); if (vec.size() != tv.size()) return v_; vector<var_t> result; for (unsigned int i = 0; i < tv.size(); i++) { result.push_back(apply_visitor(var_normalizer(vec[i]), tv[i])); } return result; }
std::string operator()(tag::switch_,Node const&,Int&& value)const{ static_assert( Node::arity >= 1 , "need at least oen for for switch statement"); using args = typename Node::args; using head = typename mpl::front<args>::type; using tail = typename mpl::pop_front<args>::type; return apply_visitor( *this, head(), tail(), value ); }
hermit::messagepack operator()( const std::map< std::u32string, hermit::json > &src ) const { std::map< hermit::messagepack, hermit::messagepack > temp; std::transform( src.begin(), src.end(), std::inserter( temp, temp.end() ), []( const std::pair< std::u32string, hermit::json > &elem ) { const auto name = hermit::format::write_utf32be( elem.first ); if( !name ) return std::make_pair( hermit::messagepack( std::vector< uint8_t >() ), apply_visitor( json2messagepack(), elem.second ) ); return std::make_pair( hermit::messagepack( *name ), apply_visitor( json2messagepack(), elem.second ) ); } ); return temp; }
Tree::Expr TreeRewriter::operator()(const Tree::BangAppExpr& e) { //first check if it is #!E if (get<Tree::HashSymbol>(&e.name) != nullptr) { Tree::Expr rhs = apply_visitor(*this, e.args.at(0)); return Tree::HashExpr(rhs); } else { Tree::Expr name = apply_visitor(*this, e.name); std::vector<Tree::Expr> args; for (auto expr : e.args) { args.push_back(apply_visitor(*this, expr)); } return Tree::BangAppExpr(name, args); } }