bool MSConnectivityScore::check_assignment(NNGraph &G, unsigned int node_handle,
                                           Assignment const &assignment,
                                           EdgeSet &picked) const {
  MSConnectivityRestraint::ExperimentalTree::Node const *node =
      tree_.get_node(node_handle);
  MSConnectivityRestraint::ExperimentalTree::Node::Label const &lb =
      node->get_label();
  Vector<Tuples> new_tuples;
  Ints empty_vector;
  for (unsigned int i = 0; i < lb.size(); ++i) {
    int prot_count = lb[i].second;
    unsigned int id = lb[i].first;
    while (new_tuples.size() < id)
      new_tuples.push_back(Tuples(empty_vector, 0));
    if (prot_count > 0) {
      if (!assignment[id].empty()) {
        Ints const &configuration = assignment[id].get_tuple();
        if (prot_count > int(configuration.size())) {
          IMP_THROW("Experimental tree is inconsistent",
                    IMP::ValueException);
        }
        new_tuples.push_back(Tuples(configuration, prot_count));
      } else {
        IMP_THROW("Experimental tree is inconsistent",
                  IMP::ValueException);
      }
    } else
      new_tuples.push_back(Tuples(empty_vector, 0));
  }
  while (new_tuples.size() <
         restraint_.particle_matrix_.get_number_of_classes())
    new_tuples.push_back(Tuples(empty_vector, 0));
  Assignment new_assignment(new_tuples);
  if (new_assignment.empty()) return false;
  do {
    NNGraph ng = build_subgraph_from_assignment(G, new_assignment);
    if (is_connected(ng)) {
      EdgeSet n_picked;
      bool good = true;
      for (unsigned int i = 0; i < node->get_number_of_children(); ++i) {
        unsigned int child_handle = node->get_child(i);
        if (!check_assignment(ng, child_handle, new_assignment, n_picked)) {
          good = false;
          break;
        }
      }
      if (good) {
        add_edges_to_set(ng, n_picked);
        picked.insert(n_picked.begin(), n_picked.end());
        return true;
      }
    }
  } while (new_assignment.next());
  return false;
}
Ejemplo n.º 2
0
void check_return(expression e)
{
  type ret = current_return_type();
 
  if (type_void(ret))
    {
      if (pedantic || !type_void(e->type))
	warning("`return' with a value, in function returning void");
    }
  else
    {
      check_assignment(ret, default_conversion_for_assignment(e), e, "return", NULL, NULL, 0);
      /* XXX: Missing warning about returning address of local var */
    }
}
bool MSConnectivityScore::perform_search(NNGraph &G, EdgeSet &picked) const {
  unsigned int root_handle = tree_.get_root();
  MSConnectivityRestraint::ExperimentalTree::Node const *node =
      tree_.get_node(root_handle);
  MSConnectivityRestraint::ExperimentalTree::Node::Label const &lb =
      node->get_label();
  Vector<Tuples> tuples;
  Ints empty_vector;
  for (unsigned int i = 0; i < lb.size(); ++i) {
    int prot_count = lb[i].second;
    unsigned int id = lb[i].first;
    while (tuples.size() < id) tuples.push_back(Tuples(empty_vector, 0));
    if (prot_count > 0) {
      tuples.push_back(
          Tuples(restraint_.particle_matrix_.get_all_proteins_in_class(id),
                 prot_count));
    } else
      tuples.push_back(Tuples(empty_vector, 0));
  }
  while (tuples.size() < restraint_.particle_matrix_.get_number_of_classes())
    tuples.push_back(Tuples(empty_vector, 0));
  Assignment assignment(tuples);
  if (assignment.empty()) return false;
  do {
    NNGraph ng = build_subgraph_from_assignment(G, assignment);
    if (is_connected(ng)) {
      EdgeSet n_picked;
      bool good = true;
      for (unsigned int i = 0; i < node->get_number_of_children(); ++i) {
        unsigned int child_handle = node->get_child(i);
        if (!check_assignment(ng, child_handle, assignment, n_picked)) {
          good = false;
          break;
        }
      }
      if (good) {
        add_edges_to_set(ng, n_picked);
        picked.insert(n_picked.begin(), n_picked.end());
        return true;
      }
    }
  } while (assignment.next());
  return false;
}
Ejemplo n.º 4
0
 int check_statement(ast::abstract::Statement* statement) {
     assert(statement != nullptr);
     switch(*statement) {
     case ast::ReturnNode:
         return check_return(dynamic_cast<ast::Return*>(statement));
         break;
     case ast::BranchNode:
         return check_branch(dynamic_cast<ast::Branch*>(statement));
         break;
     case ast::AssignmentNode:
         return check_assignment(dynamic_cast<ast::Assignment*>(statement));
         break;
     case ast::WhileNode:
         return check_while(dynamic_cast<ast::While*>(statement));
         break;
     case ast::VoidContextNode:
         return check_void_context(dynamic_cast<ast::VoidContext*>(statement));
         break;
     }
     assert(false);
     return EXIT_SUCCESS;
 }
Ejemplo n.º 5
0
bool check_inst(struct instruction *i, struct type *ret, struct symtable *syms)
{
  switch(i->kind)
  {
    case funcall:
      {
        struct type *res;
        return check_funcall(i->instr.funcall, syms, &res);
      }

    case assignment:
      return check_assignment(i->instr.assignment, syms);

    case ifthenelse:
      {
        struct ifthenelse* e = i->instr.ifthenelse;

        char *t1 = check_expr(e->cond, syms);
        if (!t1)
          return false;
        if(strcmp(t1, TYPE_BOOLEAN) == 0)
        {
          for(unsigned int i =0; i < e->instructions.size; ++i)
          {
            if (!check_inst(list_nth(e->instructions, i), ret, syms))
            {
              return false;
            }
          }
          for(unsigned int i =0; i < e->elseblock.size; ++i)
          {
            if(!check_inst(list_nth(e->elseblock,i), ret, syms))
            {
              return false;
            }
          }
          return true;
        }

        error(e->cond->pos, "condition should be a boolean");
        return false;
      }

    case switchcase:
      {
        char *t1 = check_expr(i->instr.switchcase->cond, syms);
        if(!t1)
          return false;
        for(unsigned int l = 0; l < i->instr.switchcase->caseblocklist.size; ++l)
        {
          for( unsigned int j = 0; j < i->instr.switchcase->caseblocklist.data[l]->exprlist.size; ++j)
          {
            char *t2 =
              check_expr(i->instr.switchcase->caseblocklist.data[l]->exprlist.data[j],
                  syms);
            if(!t2)
              return false;
            if (!equal_types(t1, t2, syms))
            {
              error(i->instr.switchcase->cond->pos,
                  "different types between switch and case\n");
              return false;
            }
          }
          for(int unsigned k = 0;
              k < i->instr.switchcase->caseblocklist.data[l]->instructions.size; ++k)
          {
            if(!check_inst(i->instr.switchcase->caseblocklist.data[l]->instructions.data[k], ret, syms))
              return false;
          }

        }
        for(unsigned int l = 0; l < i->instr.switchcase->otherwiseblock.size; ++l)
        {
          if(!check_inst(i->instr.switchcase->otherwiseblock.data[l], ret, syms))
            return false;

        }
        return true;
        break;
      }

    case dowhile:
      {
        struct dowhile* e = i->instr.dowhile;
        char *t = check_expr(e->cond, syms);
        if(strcmp(t, TYPE_BOOLEAN) == 0)
        {
          for(unsigned int i = 0; i < e->instructions.size; ++i)
          {
            if(!check_inst(list_nth(e->instructions,i), ret, syms))
              return false;
          }
          return true;
        }
        error(e->cond->pos, "condition should be a boolean");
        return false;
      }
      break;

    case whiledo:
      {
        struct whiledo* e = i->instr.whiledo;
        if(strcmp(check_expr(e->cond, syms), TYPE_BOOLEAN) == 0)
        {
          for(unsigned int i = 0; i < e->instructions.size; ++i)
            if(!check_inst(list_nth(e->instructions,i), ret, syms))
              return false;
          return true;
        }
        error(e->cond->pos, "condition should be a boolean");
        return false;
      }
      break;

    case forloop:
      {
        struct forloop* e = i->instr.forloop;
        char *upto_type = check_expr(e->upto, syms);
        if(upto_type && check_assignment(e->assignment, syms))
        {
          if (strcmp(upto_type, TYPE_INT) != 0)
          {
            error(e->upto->pos, "expected int expression");
            return false;
          }
          else if (strcmp(e->assignment->e1->type, TYPE_INT) != 0)
          {
            error(e->assignment->e1->pos, "expected int expression");
            return false;
          }
          else if (strcmp(e->assignment->e2->type, TYPE_INT) != 0)
          {
            error(e->assignment->e2->pos, "expected int expression");
            return false;
          }
          else
          {
            for(unsigned int i = 0; i < e->instructions.size; ++i)
              if(!check_inst(list_nth(e->instructions, i), ret, syms))
                return false;
            return true;
          }
        }
        return false;
      }
      break;

    case returnstmt:
      {
        if (!ret)
        {
          error(i->instr.returnstmt->expr->pos,
              "algorithm is a procedure, no return statement expected");
          return false;
        }
        char *t = check_expr(i->instr.returnstmt->expr, syms);
        if (!t)
          return false;
        if(equal_types(t, ret->name, syms))
          return true;
        error(i->instr.returnstmt->expr->pos, "expected type %s, not %s", ret->name, t);
        return false;
      }
  }
  return false;

}
Ejemplo n.º 6
0
 void visitAssignment(Assignment * p)
 {
     p->m_attribute.m_scope = m_st->get_scope();
     p->visit_children(this);
     check_assignment(p);
 }
Ejemplo n.º 7
0
int check_types_in_expr(ast_node root) {
  symhashtable_t *hash = NULL;
  symnode_t *node = NULL;
  ast_node anode = NULL;

  switch (root->node_type) {
    case OP_ASSIGN_N:
    //check_binary(root);
    check_assignment(root);
    break;

    case OP_PLUS_N:
    check_binary(root);
    break;

    case OP_MINUS_N:
    check_binary(root);
    break;

    case OP_NEG_N:
    check_unary(root);
    break;

    case OP_TIMES_N:
        check_binary(root);
    break;

    case OP_DIVIDE_N:
        check_binary(root);
    break;

    case OP_EQUALS_N:
        check_binary(root);
    break;

    case OP_INCREMENT_N:
        check_unary(root);
    break;

    case OP_DECREMENT_N:
        check_unary(root);
    break;

    case OP_MODULUS_N:
        check_binary(root);
    break;

    case OP_LESS_THAN_N:
        check_binary(root);
    break;

    case OP_LESS_EQUAL_N:
        check_binary(root);
    break;

    case OP_GREATER_THAN_N:
        check_binary(root);
    break;

    case OP_GREATER_EQUAL_N:
        check_binary(root);
    break;

    case OP_NOT_EQUAL_N:
        check_binary(root);
    break;

    case OP_AND_N:
        check_binary(root);
    break;

    case OP_OR_N:
        check_binary(root);
    break;

    case OP_NOT_N:
        check_unary(root);
    break;

    case RETURN_N:
        check_unary(root);
    break;

    default:
      // printf("at default of switch\n");
      break;


  }

  /* Recurse on each child of the subtree root, with a depth one
     greater than the root's depth. */
  ast_node child;
  for (child = root->left_child; child != NULL; child = child->right_sibling)
    check_types_in_expr(child);
  return 0;
}