void get_rec_args(environment const & env, name const & n, buffer<buffer<bool>> & r) { lean_assert(inductive::is_inductive_decl(env, n)); type_checker tc(env); name_generator ngen; declaration ind_decl = env.get(n); declaration rec_decl = env.get(inductive::get_elim_name(n)); unsigned nparams = *inductive::get_num_params(env, n); unsigned nminors = *inductive::get_num_minor_premises(env, n); unsigned ntypeformers = *inductive::get_num_type_formers(env, n); buffer<expr> rec_args; to_telescope(ngen, rec_decl.get_type(), rec_args); buffer<name> typeformer_names; for (unsigned i = nparams; i < nparams + ntypeformers; i++) { typeformer_names.push_back(mlocal_name(rec_args[i])); } lean_assert(typeformer_names.size() == ntypeformers); r.clear(); // add minor premises for (unsigned i = nparams + ntypeformers; i < nparams + ntypeformers + nminors; i++) { r.push_back(buffer<bool>()); buffer<bool> & bv = r.back(); expr minor_type = mlocal_type(rec_args[i]); buffer<expr> minor_args; to_telescope(ngen, minor_type, minor_args); for (expr & minor_arg : minor_args) { buffer<expr> minor_arg_args; expr minor_arg_type = to_telescope(tc, mlocal_type(minor_arg), minor_arg_args); bv.push_back(is_typeformer_app(typeformer_names, minor_arg_type)); } } }
bool LoadDataFromFile(buffer& buff, const TCHAR* filename, bool text) { bool ret = false; FILE* file = nullptr; size_t size = 0; std::string fullpath; CHECK(filename); buff.clear(); _tfopen_s(&file, filename, text ? _T("r") : _T("rb")); CHECK(file); fseek(file, 0L, SEEK_SET); fseek(file, 0L, SEEK_END); size = ftell(file); buff.resize(text ? size + sizeof(char) : size); fseek(file, 0L, SEEK_SET); size = fread(buff.ptr(), 1, size, file); if (text) buff.ptr()[size] = 0; ret = true; Exit0: if (file) fclose(file); return ret; }
friend void copy_limbs(imp * p, buffer<name::imp *> & limbs) { limbs.clear(); while (p != nullptr) { limbs.push_back(p); p = p->m_prefix; } std::reverse(limbs.begin(), limbs.end()); }
stream::state_t socks5_proxy::recv( std::vector< buffer > &in_recv_bufs, buffer &out_send_buf, std::vector< buffer > &out_recv_bufs ) { switch ( m_state5 ) { case waiting_for_opening_response: { std::size_t bytes_available = in_recv_bufs[ 0 ].size(); std::size_t handshake_left = 2 - m_recv_handshake.size(); m_recv_handshake.append( in_recv_bufs[ 0 ].data(), std::min( handshake_left, bytes_available ) ); if ( m_recv_handshake.size() < 2 ) { in_recv_bufs[ 0 ].rotate( 0, std::min( handshake_left, bytes_available ), in_recv_bufs[ 0 ].size() ); } else { if ( m_recv_handshake[ 0 ] == 0x05 ) { if ( m_recv_handshake[ 1 ] == 0x00 ) { out_send_buf = make_connect_buffer(); out_recv_bufs.clear(); m_state5 = waiting_for_connect_response; } else if ( m_recv_handshake[ 1 ] == 0x02 ) { out_send_buf = make_auth_buffer(); out_recv_bufs.clear(); m_state5 = waiting_for_authentication_response; } else { m_state = stream::state_t::error; } } else { m_state = stream::state_t::error; } m_recv_handshake.clear(); } } break; case waiting_for_authentication_response: { std::size_t bytes_available = in_recv_bufs[ 0 ].size(); std::size_t handshake_left = 2 - m_recv_handshake.size(); m_recv_handshake.append( in_recv_bufs[ 0 ].data(), std::min( handshake_left, bytes_available ) ); if ( m_recv_handshake.size() < 2 ) { in_recv_bufs[ 0 ].rotate( 0, std::min( handshake_left, bytes_available ), in_recv_bufs[ 0 ].size() ); } else { if ( ( m_recv_handshake[ 0 ] == 0x01 ) && ( m_recv_handshake[ 1 ] == 0x00 ) ) { out_send_buf = make_connect_buffer(); out_recv_bufs.clear(); m_state5 = waiting_for_connect_response; } else { m_state = stream::state_t::error; } m_recv_handshake.clear(); } } break; case waiting_for_connect_response: { std::size_t bytes_available = in_recv_bufs[ 0 ].size(); std::size_t handshake_left = 4 - m_recv_handshake.size(); m_recv_handshake.append( in_recv_bufs[ 0 ].data(), std::min( handshake_left, bytes_available ) ); if ( m_recv_handshake.size() < 4 ) { in_recv_bufs[ 0 ].rotate( 0, std::min( handshake_left, bytes_available ), in_recv_bufs[ 0 ].size() ); } else if ( ( m_recv_handshake[ 0 ] == 0x05 ) && ( m_recv_handshake[ 1 ] == 0x00 ) ) { switch ( m_recv_handshake[ 3 ] ) { case 0x01: { in_recv_bufs[ 0 ].rotate( 0, 6, in_recv_bufs[ 0 ].size() ); out_send_buf = std::move( m_send_queue ); m_state5 = connected; m_state = stream::state_t::connected; } break; case 0x03: { auto len = in_recv_bufs[ 0 ][ 0 ]; in_recv_bufs[ 0 ].rotate( 0, len + 1, in_recv_bufs[ 0 ].size() ); out_send_buf = std::move( m_send_queue ); m_state5 = connected; m_state = stream::state_t::connected; } break; case 0x04: { in_recv_bufs[ 0 ].rotate( 0, 18, in_recv_bufs[ 0 ].size() ); out_send_buf = std::move( m_send_queue ); m_state5 = connected; m_state = stream::state_t::connected; } break; default: { m_state = stream::state_t::error; } } } } break; default: { out_recv_bufs = std::move( in_recv_bufs ); } } return m_state; }