it helps if one understands /why/ something is done. I think this
	might be it for the reference count tweeks
switch.c:
	o	better control over whether case ranges are built
	o	/always/ append the temp = test expression and use temp instead of
		test for the != check
	o	only ever build case ranges if the switch expression is integer
This commit is contained in:
Bill Currie 2001-11-14 06:45:31 +00:00
parent dc80f51d89
commit 3fe67eecd2
2 changed files with 7 additions and 11 deletions

View file

@ -888,13 +888,11 @@ binary_expr (int op, expr_t *e1, expr_t *e2)
if (op == '=' && e1->type == ex_def)
PR_DefInitialized (e1->e.def);
if (op == '=')
inc_users (e1);
if (e1->type == ex_block && e1->e.block.is_call
&& e2->type == ex_block && e2->e.block.is_call
&& e1->e.block.result) {
e = new_temp_def_expr (e1->e.block.result->e.def->type);
inc_users (e); // for the block itself
e1 = binary_expr ('=', e, e1);
}
@ -1376,7 +1374,6 @@ incop_expr (int op, expr_t *e, int postop)
temp = new_temp_def_expr (type);
append_expr (block, binary_expr ('=', temp, e));
temp->e.temp.users = 1;
append_expr (block, incop);
block->e.block.result = temp;
return block;

View file

@ -181,7 +181,7 @@ balance_case_tree (case_node_t **nodes, int base, int count)
}
static case_node_t *
build_case_tree (case_label_t **labels, int count)
build_case_tree (case_label_t **labels, int count, int range)
{
case_node_t **nodes;
int i, j, k;
@ -193,7 +193,7 @@ build_case_tree (case_label_t **labels, int count)
if (!nodes)
Sys_Error ("out of memory");
if (labels[0]->value->type == ex_integer) {
if (range && labels[0]->value->type == ex_integer) {
for (i = 0; i < count - 1; i = j, num_nodes++) {
for (j = i + 1; j < count; j++) {
if (labels[j]->value->e.integer_val
@ -258,9 +258,10 @@ build_switch (expr_t *sw, case_node_t *tree, int op, expr_t *sw_val,
test = binary_expr ('=', temp, test);
test->line = sw_val->line;
test->file = sw_val->file;
append_expr (sw, test);
if (tree->low == tree->high) {
branch = new_binary_expr ('n', test, tree->labels[0]);
branch = new_binary_expr ('n', temp, tree->labels[0]);
branch->line = sw_val->line;
branch->file = sw_val->file;
append_expr (sw, branch);
@ -296,8 +297,6 @@ build_switch (expr_t *sw, case_node_t *tree, int op, expr_t *sw_val,
table->type = ex_def;
table->e.def = def;
append_expr (sw, test);
if (tree->left) {
branch = new_binary_expr (IFB, temp, low_label);
branch->line = sw_val->line;
@ -391,7 +390,7 @@ switch_expr (switch_block_t *switch_block, expr_t *break_label,
temp = new_temp_def_expr (&type_integer);
else
temp = new_temp_def_expr (type);
case_tree = build_case_tree (labels, num_labels);
case_tree = build_case_tree (labels, num_labels, type == &type_integer);
switch (type->type) {
case ev_string:
op = NE;