Beispiel #1
0
static bool is_skip(goto_programt::instructionst::iterator it)
{
  if (it->is_skip())
    return true;

  if (it->is_goto())
  {
    if (is_constant_bool2t(it->guard) &&
        !to_constant_bool2t(it->guard).constant_value)
      return true;

    if (it->targets.size()!=1)
      return false;

    goto_programt::instructionst::iterator next_it=it;
    next_it++;

    return it->targets.front()==next_it;
  }

  if(it->is_other())
  {
    return is_nil_expr(it->code);
  }

  return false;
}
Beispiel #2
0
static bool is_skip(goto_programt::instructionst::iterator it)
{
  // we won't remove labelled statements
  // (think about error labels or the like)
  
  if(!it->labels.empty())
    return false;

  if(it->is_skip())
    return !it->code.get_bool(ID_explicit);
 
  if(it->is_goto())
  {
    if(it->guard.is_false()) return true;

    if(it->targets.size()!=1)
      return false;

    goto_programt::instructionst::iterator next_it=it;
    next_it++;

    // a branch to the next instruction is a skip
    return it->targets.front()==next_it;
  }
  
  if(it->is_other())
  {
    if(it->code.is_nil()) return true;
  
    const irep_idt &statement=it->code.get_statement();
    
    if(statement==ID_skip)
      return true;
    else if(statement==ID_expression)
    {
      const code_expressiont &code_expression=to_code_expression(it->code);
      const exprt &expr=code_expression.expression();
      if(expr.id()==ID_typecast &&
         expr.type().id()==ID_empty &&
         to_typecast_expr(expr).op().is_constant())
      {
        // something like (void)0
        return true;
      }
    }
      
    return false;
  }
  
  return false;
}