// Perform unqualified lookup. Expr& make_reference(Context& cxt, Simple_id& id) { Decl_list decls = unqualified_lookup(cxt, id); if (decls.size() == 1) return make_reference(cxt, decls.front()); // TODO: Return a reference to an overload set. banjo_unhandled_case(id); }
int tester() { std::vector<Scalar> bin_ref_x,bin_ref_y; make_reference(bin_ref_x,bin_ref_y); Antioch::SigmaBinConverter<std::vector<Scalar> > bin; const Scalar tol = std::numeric_limits<Scalar>::epsilon() * 10; int return_flag = 0; // 4 cases: // - custom inside ref // - ref inside custom // - custom beyond only min ref // - custom beyond only max ref for(unsigned int i = 0; i < 4; i++) { std::vector<Scalar> bin_custom_x, exact_sol_y; make_custom(i,bin_custom_x,exact_sol_y); std::vector<Scalar> bin_custom_y(bin_custom_x.size()); bin.y_on_custom_grid(bin_ref_x,bin_ref_y, bin_custom_x,bin_custom_y); for(unsigned int il = 0; il < bin_custom_x.size() - 1; il++) { const Scalar dist = (exact_sol_y[il] < tol)?std::abs(bin_custom_y[il] - exact_sol_y[il]):std::abs(bin_custom_y[il] - exact_sol_y[il])/exact_sol_y[il]; if( dist > tol ) { std::cout << std::scientific << std::setprecision(16) << "Error: Mismatch in bin values." << std::endl << "case (" << bin_custom_x[il] << ";" << bin_custom_x[il+1] << ")" << std::endl << "bin = " << bin_custom_y[il] << std::endl << "bin_exact = " << exact_sol_y[il] << std::endl << "relative error = " << dist << std::endl << "tolerance = " << tol << std::endl; return_flag = 1; } } } return return_flag; }
Type compile(const Node& l, const UnaryOperator& op, Context& ctx) { auto l_type = l.compile(ctx); if(op == Operator('&')) { if(l_type != TypeKind::reference) { printf("参照でないオブジェクトのアドレスを取得しようとしました\n"); throw; } return I32Type(); } if(l_type == TypeKind::reference) { l_type = l_type.compile_dereference(ctx); } switch(op) { case(Operator('*')): if(l_type != TypeKind::pointer) { printf("ポインタでないオブジェクトを参照しようとしました\n"); throw; } return l_type.make_reference(); break; case(Operator('!')): ctx.push(" lnot;\n");break; case(Operator('~')): ctx.push(" bnot;\n");break; case(Operator('-')): ctx.push(" neg ;\n");break; } return I32Type(); }
Expr& operator()(Concept_id& n) { return make_reference(cxt, n); }
Expr& operator()(Template_id& n) { return make_reference(cxt, n); }
Expr& operator()(Simple_id& n) { return make_reference(cxt, n); }
Call_expr& Builder::make_call(Type& t, Function_decl& f, Expr_list const& a) { return make_call(t, make_reference(f), a); }
int vectester(const PairScalars& example, const std::string& testname) { typedef typename Antioch::value_type<PairScalars>::type Scalar; std::vector<Scalar> bin_ref_x,bin_ref_y; make_reference(bin_ref_x,bin_ref_y); Antioch::SigmaBinConverter<std::vector<Scalar> > bin; const Scalar tol = std::numeric_limits<Scalar>::epsilon() * 10; int return_flag = 0; #ifdef ANTIOCH_HAVE_GRVY gt.BeginTimer(testname); #endif // 2 * 2 cases: // - custom inside ref, ref inside custom // - custom beyond only min ref, custom beyond only max ref for(unsigned int i = 0; i < 2; i++) { std::vector<PairScalars> bin_custom_x, exact_sol_y; make_custom(i,example,bin_custom_x,exact_sol_y); std::vector<PairScalars> bin_custom_y(bin_custom_x.size(),Antioch::zero_clone(bin_custom_x[0])); bin.y_on_custom_grid(bin_ref_x,bin_ref_y, bin_custom_x,bin_custom_y); for(unsigned int il = 0; il < bin_custom_x.size() - 1; il++) { for (unsigned int tuple=0; tuple != ANTIOCH_N_TUPLES; ++tuple) { //tuple Scalar dist = Antioch::if_else(exact_sol_y[il][2*tuple] < tol, std::abs(bin_custom_y[il][2*tuple] - exact_sol_y[il][2*tuple]), std::abs(bin_custom_y[il][2*tuple] - exact_sol_y[il][2*tuple])/exact_sol_y[il][2*tuple]); if( dist > tol ) { std::cout << std::scientific << std::setprecision(16) << "Error: Mismatch in bin values for " << testname << std::endl << "case (" << bin_custom_x[il][2*tuple] << ";" << bin_custom_x[il + 1][2*tuple] << ")" << std::endl << "bin = " << bin_custom_y[il][2*tuple] << std::endl << "bin_exact = " << exact_sol_y[il][2*tuple] << std::endl << "relative error = " << dist << std::endl << "tolerance = " << tol << std::endl; return_flag = 1; } //tuple + 1 dist = Antioch::if_else(exact_sol_y[il][2*tuple + 1] < tol, std::abs(bin_custom_y[il][2*tuple + 1] - exact_sol_y[il][2*tuple + 1]), std::abs(bin_custom_y[il][2*tuple + 1] - exact_sol_y[il][2*tuple + 1])/exact_sol_y[il][2*tuple + 1]); if( dist > tol ) { std::cout << std::scientific << std::setprecision(16) << "Error: Mismatch in bin values for " << testname << std::endl << "case (" << bin_custom_x[il][2*tuple + 1] << ";" << bin_custom_x[il+1][2*tuple + 1] << ")" << std::endl << "bin = " << bin_custom_y[il][2*tuple + 1] << std::endl << "bin_exact = " << exact_sol_y[il][2*tuple + 1] << std::endl << "relative error = " << dist << std::endl << "tolerance = " << tol << std::endl; return_flag = 1; } } } } #ifdef ANTIOCH_HAVE_GRVY gt.EndTimer(testname); #endif return return_flag; }