//Finds the set of all types that are subtypes of a and b. //Note that this version assumes we have the transitive closure polytype intersect_types(polytype a, polytype b) { polytype_dynarray result = polytype_dynarray_make(1); //Handle special cases where either a or b are "Any" if (is_any(a)) { return b; } if (is_any(b)) { return a; } //Is A possibly a subtype of B? if (Type_graph_possiblesubtype(UniverseGraph, a, b)) { //it is. Check if A __is__ B (trivially -- is it exactly the same?) if (polytype_trivial_eq(a, b)) { //Great, they're both the same. Add one to the result and return return a; } else { //Since A is possibly a subtype of B, but A is not B, //we should be able to find A somewhere under B. //To do so, instantiate B's subtypes in the lattice and recurse //by restricting the set of B's subtypes by A. typeslot_dynarray b_subtypes = polytype_get_subtypes(b); //TODO: Eliminate the instantiation going on here return restrict_type(typeslot_dynarray_instantiate(b_subtypes), a); } } //A cannot subtype B //Check if A's children do so instead. //TODO: Remove instantiation going on here return restrict_type(typeslot_dynarray_instantiate(polytype_get_subtypes(a)), b); }
void get_available_address_v4(io_service& ios,std::set<address>& addrs) { addrs.clear(); error_code ec; std::vector<ip_interface> interfaces=enum_net_interfaces(ios,ec); address realBindAddr; for(std::size_t i=0;i<interfaces.size();++i) { if(is_loopback(interfaces[i].interface_address) ||is_any(interfaces[i].interface_address) ||interfaces[i].interface_address.is_v6() ) { continue; } //test can we bind this port endpoint edp(interfaces[i].interface_address,0); boost::asio::ip::tcp::socket tcpSocket(ios); tcpSocket.open(boost::asio::ip::tcp::v4(),ec); tcpSocket.bind(edp,ec); if (!ec&&!is_any(realBindAddr=tcpSocket.local_endpoint(ec).address())) { addrs.insert(realBindAddr); } else { addrs.erase(realBindAddr); } tcpSocket.close(ec); } }
static int riscv_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int len) { const int no_alias = 1; struct riscv_opcode *o = NULL; insn_t word = 0; int xlen = anal->bits; op->size = 4; op->addr = addr; op->type = R_ANAL_OP_TYPE_UNK; memcpy (&word, data, 4); o = get_opcode (word); if (o == NULL) { return op->size; } for(; o < &riscv_opcodes[NUMOPCODES]; o++) { if ( !(o->match_func)(o, word) ) continue; if ( no_alias && (o->pinfo & INSN_ALIAS) ) continue; if ( isdigit (o->subset[0]) && atoi (o->subset) != xlen) continue; else break; } #define is_any(...) _is_any(NARGS(__VA_ARGS__), o->name, __VA_ARGS__) // branch/jumps/calls/rets if (is_any ("jal")) { // decide wether it's ret or call int rd = (word >> OP_SH_RD) & OP_MASK_RD; op->type = (rd == 0) ? R_ANAL_OP_TYPE_RET : R_ANAL_OP_TYPE_CALL; op->jump = EXTRACT_UJTYPE_IMM (word) + addr; op->fail = addr + 4; } else if(is_any ("jr")) {
/** \brief Return true if the ip_addr_t is said 'fully_qualified' */ bool ip_addr_t::is_fully_qualified() const throw() { if( is_null() ) return false; if( is_any() ) return false; if( is_multicast() ) return false; if( is_broadcast() ) return false; return true; }
bool subst(eterm<Alloc>& out, const varbind<Alloc>* binding) const throw (err_unbound_variable) { if (is_any()) throw err_unbound_variable(c_str()); const eterm<Alloc>* term = binding ? binding->find(c_str()) : NULL; if (!term) throw err_unbound_variable(c_str()); out = *term; return true; }
tcp::endpoint utp_socket_manager::local_endpoint(address const& remote, error_code& ec) const { tcp::endpoint socket_ep = m_sock.local_endpoint(ec); // first enumerate the routes in the routing table if (time_now() - m_last_route_update > seconds(60)) { m_last_route_update = time_now(); error_code ec; m_routes = enum_routes(m_sock.get_io_service(), ec); if (ec) return socket_ep; } if (m_routes.empty()) return socket_ep; // then find the best match ip_route* best = &m_routes[0]; for (std::vector<ip_route>::iterator i = m_routes.begin() , end(m_routes.end()); i != end; ++i) { if (is_any(i->destination) && i->destination.is_v4() == remote.is_v4()) { best = &*i; continue; } if (match_addr_mask(remote, i->destination, i->netmask)) { best = &*i; continue; } } // best now tells us which interface we would send over // for this target. Now figure out what the local address // is for that interface if (time_now() - m_last_if_update > seconds(60)) { m_last_if_update = time_now(); error_code ec; m_interfaces = enum_net_interfaces(m_sock.get_io_service(), ec); if (ec) return socket_ep; } for (std::vector<ip_interface>::iterator i = m_interfaces.begin() , end(m_interfaces.end()); i != end; ++i) { if (i->interface_address.is_v4() != remote.is_v4()) continue; if (strcmp(best->name, i->name) == 0) return tcp::endpoint(i->interface_address, socket_ep.port()); } return socket_ep; }
bool match(const eterm<Alloc>& pattern, varbind<Alloc>* binding) const throw (err_unbound_variable) { if (is_any()) return true; const eterm<Alloc>* value = binding ? binding->find(c_str()) : NULL; if (value) return value->match(pattern, binding); if (binding != NULL) { // Bind the variable eterm<Alloc> et; binding->bind(name(), pattern.subst(et, binding) ? et : pattern); } return true; }
bool match(const eterm<Alloc>& pattern, varbind<Alloc>* binding) const throw (err_unbound_variable) { if (is_any()) return true; if (!binding) return false; const eterm<Alloc>* value = binding->find(name()); if (value) return check_type(value->type()) ? value->match(pattern, binding) : false; if (!check_type(pattern.type())) return false; // Bind the variable eterm<Alloc> et; binding->bind(name(), pattern.subst(et, binding) ? et : pattern); return true; }
bool Type::compatible(const Type& type) const { if (_types.size() == 0 or type._types.size() == 0) { return true; } if (is_any()) { return true; } if (this->is_primitive() && type.is_polymorphic()) { return false; } if (this->temporary and not type.temporary) { return false; // type not compatible with type&& } if (not this->constant and type.constant) { return false; // 'const type' not compatible with 'type' } if ((is_array() && type.is_array()) || (is_set() && type.is_set()) || (is_map() && type.is_map()) || (is_function() && type.is_function())) { return _types[0]->compatible(type._types[0].get()); } if (_types[0] != type._types[0]) { // 'Integer' is compatible with 'Float' if (this->is_real() and type.is_integer()) { return true; } // 'Boolean' is compatible with 'Integer' if (this->is_integer() and type.is_bool()) { return true; } // 'Integer' is compatible with 'Long' if (this->is_long() and type.is_integer()) { return true; } // All numbers types are compatible with the base 'Number' type if (dynamic_cast<const Number_type*>(_types[0].get()) and (type.is_integer() or type.is_long() or type.is_real())) { return true; } return false; } return true; }
Type Type::operator * (const Type& t2) const { if (_types.size() == 0) { return t2; } if (t2._types.size() == 0) { return *this; } if (*this == t2) { return *this; } if (is_polymorphic() and t2.is_primitive()) { return Type::any(); } if (t2.is_polymorphic() and is_primitive()) { return Type::any(); } if (is_any()) { return t2; } if (t2.is_any()) { return *this; } // Temporary, to be removed when compatible() is removed if ((is_bool() and t2.is_integer()) or (is_integer() and t2.is_bool())) { return any(); } if (t2.compatible(*this)) { return t2; } if (compatible(t2)) { return *this; } if (is_array() and t2.is_array()) { if (element().is_polymorphic() and t2.element().is_polymorphic()) { return array(any()); } } return Type::any(); }
/* TODO make skip_chars byte* or u8*? */ int read_char(FILE* input, char* skip_chars, int complement, int clear_line) { int c, ret; byte tmp; c_array skip; char* tmp_skip = (skip_chars) ? skip_chars : (char*)""; SET_C_ARRAY(skip, (byte*)skip_chars, 1, strlen(tmp_skip)); do { ret = getc(input); if (ret == EOF) return ret; tmp = ret; c = is_any(&skip, &tmp, are_equal_uchar); } while (!complement && c || complement && !c); if (clear_line && ret != '\n') do { c = getc(input); } while (c != '\n' && c != EOF); return ret; }
static int riscv_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int len) { const int no_alias = 1; struct riscv_opcode *o = NULL; ut64 word = 0; int xlen = anal->bits; op->size = 4; op->addr = addr; op->type = R_ANAL_OP_TYPE_UNK; word = (len >= sizeof (ut64))? r_read_ble64 (data, anal->big_endian): r_read_ble16 (data, anal->big_endian); o = get_opcode (word); if (word == UT64_MAX) { op->type = R_ANAL_OP_TYPE_ILL; return -1; } if (!o || !o->name) return op->size; for (; o < &riscv_opcodes[NUMOPCODES]; o++) { // XXX ASAN segfault if ( !(o->match_func)(o, word) ) continue; if ( no_alias && (o->pinfo & INSN_ALIAS) ) continue; if ( isdigit ((int)(o->subset[0])) && atoi (o->subset) != xlen) continue; else { break; } } if (!o || !o->name) { return -1; } // branch/jumps/calls/rets if (is_any ("jal")) { // decide wether it's ret or call int rd = (word >> OP_SH_RD) & OP_MASK_RD; op->type = (rd == 0) ? R_ANAL_OP_TYPE_RET: R_ANAL_OP_TYPE_CALL; op->jump = EXTRACT_UJTYPE_IMM (word) + addr; op->fail = addr + 4; } else if (is_any ("jr")) {
char* read_string(FILE* file, char* skip_chars, int delim, size_t max_len) { int tmp; byte tmp2; char* str = NULL; c_array skip; str = (skip_chars) ? skip_chars : (char*)""; SET_C_ARRAY(skip, (byte*)skip_chars, 1, strlen(str)); do { tmp = getc(file); if (tmp == EOF) return NULL; tmp2 = tmp; } while (is_any(&skip, &tmp2, are_equal_uchar)); ungetc(tmp, file); do { str = freadstring(file, delim, max_len); } while (!str); return str; }
bool ip_voter::cast_vote(address const& ip , int source_type, address const& source) { if (is_any(ip)) return false; if (is_local(ip)) return false; if (is_loopback(ip)) return false; // don't trust source that aren't connected to us // on a different address family than the external // IP they claim we have if (ip.is_v4() != source.is_v4()) return false; // this is the key to use for the bloom filters // it represents the identity of the voter sha1_hash k; hash_address(source, k); // do we already have an entry for this external IP? std::vector<external_ip_t>::iterator i = std::find_if(m_external_addresses.begin() , m_external_addresses.end(), boost::bind(&external_ip_t::addr, _1) == ip); if (i == m_external_addresses.end()) { // each IP only gets to add a new IP once if (m_external_address_voters.find(k)) return maybe_rotate(); if (m_external_addresses.size() > 40) { if (random() % 100 < 50) return maybe_rotate(); // use stable sort here to maintain the fifo-order // of the entries with the same number of votes // this will sort in ascending order, i.e. the lowest // votes first. Also, the oldest are first, so this // is a sort of weighted LRU. std::stable_sort(m_external_addresses.begin(), m_external_addresses.end()); // erase the last element, since it is one of the // ones with the fewest votes m_external_addresses.erase(m_external_addresses.end() - 1); } m_external_addresses.push_back(external_ip_t()); i = m_external_addresses.end() - 1; i->addr = ip; } // add one more vote to this external IP if (!i->add_vote(k, source_type)) return maybe_rotate(); ++m_total_votes; if (m_valid_external) return maybe_rotate(); i = std::min_element(m_external_addresses.begin(), m_external_addresses.end()); TORRENT_ASSERT(i != m_external_addresses.end()); if (i->addr == m_external_address) return maybe_rotate(); if (m_external_address != address_v4()) { // we have a temporary external address. As soon as we have // more than 25 votes, consider deciding which one to settle for return (m_total_votes >= 25) ? maybe_rotate() : false; } m_external_address = i->addr; return true; }
bool Type::is_alt() const { return is_union() || is_any(); }
bool Type::can_be_container() const { return is_any() or is_placeholder() or std::any_of(begin(_types), end(_types), [](auto& type) { return type->is_container(); }); }
bool is_7bit() const { return is_any() && !is_14bit(); }
bool check_type(eterm_type t) const { return is_any() || m_type == UNDEFINED || t == m_type; }
bool Type::can_be_numeric() const { return is_any() or can_be_bool() or can_be_number(); }
bool Type::can_be_callable() const { return is_any() or (_types.size() and some([&](std::shared_ptr<const Base_type> t) { return t->callable(); })); }
void bBoard::process(bFpsTimer * fps) { guard(bBoard::process); BASSERT( fps != NULL ); for( int i=0; i<ball_size; ++i ) { ball[i]->process( fps->factor() ); } // find and mark balls with collisions for( int i=0; i<ball_size; ++i ) { for( int k=0; k<band_size; ++k ) { bBand::band_piece bp; if( (bp = band[k]->is_within( ball[i]->pos, ball[i]->radius )) != bBand::bNone ) { if( bp == bBand::bSide ) { luband.set( i, k, 1); } else { luband.set( i, k, bp==bBand::bEdge1?2:3); } } } for( int j=0; j<i; ++j ) { if( ball[i]->collides( ball[j] ) ) { luball.set( i, j, 1 ); } } } // move backwards balls with collision(s) for( int i=0; i<ball_size; ++i ) { if( is_any(i) ) { ball[i]->unprocess( fps->factor() ); } } Profiler.begin( "ball_mgr::reflections" ); // calculate new velocity vectors // (but no commit - one change changes next calculation result!) commit_reflections(); Profiler.end( "ball_mgr::reflections" ); luball.clear(); luband.clear(); for( int i=0; i<ball_size; ++i ) { // apply velocity vector changes ball[i]->commit_v(); /* ball[i]->process( fps->factor() ); for( int k=0; k<band_size; ++k ) { if( band[k]->is_within( ball[i]->pos, ball[i]->radius ) != bBand::bNone ) { ball[i]->unprocess( fps->factor() ); } } for( int j=0; j<i; ++j ) { if( ball[i]->collides( ball[j] ) ) { ball[i]->unprocess( fps->factor() ); } }*/ } unguard; }
std::ostream& dump(std::ostream& out, const varbind<Alloc>* binding = NULL) const { if (is_any()) { return out << c_str(); } const eterm<Alloc>* term = binding ? binding->find(name()) : NULL; return out << (term ? term->to_string(std::string::npos, binding) : *this); }
const eterm<Alloc>* find_unbound(const varbind<Alloc>* binding = NULL) const { if (is_any()) return NULL; return binding ? binding->find(c_str()) : NULL; }