Beispiel #1
0
bool
is_same(Expr* a, Expr* b) {
  if (a->kind != b->kind)
    return false;
  switch (a->kind) {
  case id_expr: return same_unary(as<Id>(a), as<Id>(b));
  case unit_term: return true;
  case true_term: return true;
  case false_term: return true;
  case int_term: return as<Int>(a)->value() == as<Int>(b)->value();
  case if_term: return same_ternary(as<If>(a), as<If>(b));
  case succ_term: return same_unary(as<Succ>(a), as<Succ>(b));
  case pred_term: return same_unary(as<Pred>(a), as<Pred>(b));
  case iszero_term: return same_unary(as<Iszero>(a), as<Iszero>(b));
  case var_term: return same_var(as<Var>(a), as<Var>(b));
  case abs_term: return same_binary(as<Var>(a), as<Var>(b));
  case app_term: return same_binary(as<Var>(a), as<Var>(b));
  case ref_term: return same_ref(as<Ref>(a), as<Ref>(b));
  case init_term: return same_init(as<Init>(a), as<Init>(b));
  case record_term: return same_record(as<Record>(a), as<Record>(b));
  case kind_type: return true;
  case unit_type: return true;
  case bool_type: return true;
  case nat_type: return true;
  case arrow_type: return same_binary(as<Arrow_type>(a), as<Arrow_type>(b));
  case record_type: return same_record_type(as<Record_type>(a), as<Record_type>(b));
  case list_type: return is_same(as<List_type>(a)->type(), as<List_type>(b)->type());
  }
}
Beispiel #2
0
/*
** brief: it will search the good line to stay with the good strategy
** @lst: our list
** @nbr: our number (we will set it in this function)
** return: return the position found
*/
static int	_find_position(t_list *lst, int *nbr)
{
  int		i;
  int		find;
  int		pos;
  t_list	*tmp;

  *nbr = bin_to_int(lst->bin);
  *nbr = *nbr == 0 ? 1 : *nbr;
  tmp = lst->next;
  i = -1;
  while (++i < ID_OCTET && !lst->bin[i]);
  if (i == 8)
    return (1);
  find = 0;
  pos = 0;
  while (tmp != NULL && !find)
    {
      ++pos;
      find = same_binary(lst, tmp, i - 1);
      tmp = tmp->next;
    }
  if (!find)
    *nbr = _fill_hole(lst, i, &pos);
  return (pos);
}