void MultiWayGroup::generate_code(StatementList *x,
				  IInteger bound_below,
                                  IInteger bound_above) {
    Expression *low_check = NULL;
    Expression *high_check = NULL;
    DataType *bool_type = get_type_builder(_env)->get_boolean_type();

    // if there are no more than two entries, build if statements

    int lab_count = get_label_count();
    if (lab_count <= 2) {
	for (int i=0;i < lab_count; i ++) {
	    MultiWayBranchStatement::case_pair pair = _statement->get_case(i);

	    low_check = create_binary_expression(_env,
                                                 bool_type,
                                                 k_is_equal_to,
                                                 create_var_use(_decision),
                                                 ie(pair.first));
            x->append_statement(create_branch_statement(_env,low_check,pair.second));
	    }
	x->append_statement(create_jump_statement(_env,_default_lab));
	delete _statement;
	_statement = 0;
	return;
	}
  	
    if (bound_below.is_undetermined() || (_low_bound > bound_below + 1)) {
	low_check = create_binary_expression(_env,
						 bool_type,
						 k_is_less_than,
						 create_var_use(_decision),
						 ie(_low_bound));
	x->append_statement(create_branch_statement(_env,low_check,_default_lab));
	}
    if (bound_above.is_undetermined() || (_high_bound < bound_above)) {
        high_check = create_binary_expression(_env,
                                                 bool_type,
                                                 k_is_greater_than,
                                                 create_var_use(_decision),
                                                 ie(_high_bound));
	x->append_statement(create_branch_statement(_env,high_check,_default_lab));
        }

    // in fill the statement so that missing entries are added so as to 
    // complete the table

    IInteger next_value = _low_bound;
    while (next_value < _high_bound) {
	if (!_statement->lookup_case(next_value)) {
	    _statement->insert_case(next_value,_default_lab);
	    }	
	next_value ++;
	}
    
    x->append_statement(_statement);
    }
bool LabelManager::add_label(const std::string& name)
{
  // Make sure that a label with the specified name does not already exist.
  if(has_label(name)) return false;

  // Make sure that we're not trying to exceed the maximum number of labels.
  if(get_label_count() == get_max_label_count()) return false;

  // Add the new label.
  SpaintVoxel::Label label = static_cast<SpaintVoxel::Label>(m_labelAllocator.allocate());
  m_labelProperties.insert(std::make_pair(label, std::make_pair(name, colours[label])));
  m_labelsByName.insert(std::make_pair(name, label));

  return true;
}