Cleanup code around JERRY_UNREACHABLEs (#2342)

`JERRY_UNREACHABLE`s often signal code structure that could be
improved: they can usually either be rewritten to `JERRY_ASSERT`s
or eliminated by restructuring loops, `if`s or `#if`s. Roughly,
the only valid occurences are in default cases of `switch`es. And
even they can often be merged into non-default cases.

Moreover, it is dangerous to write meaningful code after
`JERRY_UNREACHABLE` because it pretends as if there was a way to
recover from an impossible situation.

This patch rewrites/eliminates `JERRY_UNREACHABLE`s where possible
and removes misleading code from after them.

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
This commit is contained in:
Akos Kiss
2018-05-25 07:27:30 +02:00
committed by GitHub
parent acb3e71436
commit 4779451284
24 changed files with 168 additions and 256 deletions
+5 -7
View File
@@ -930,12 +930,6 @@ ecma_deref_ecma_string (ecma_string_t *string_p) /**< ecma-string */
ecma_dealloc_string_buffer (string_p, string_p->u.long_utf8_string_size + sizeof (ecma_long_string_t));
return;
}
case ECMA_STRING_CONTAINER_UINT32_IN_DESC:
case ECMA_STRING_CONTAINER_MAGIC_STRING_EX:
{
/* only the string descriptor itself should be freed */
break;
}
case ECMA_STRING_LITERAL_NUMBER:
{
ecma_free_value (string_p->u.lit_number);
@@ -943,7 +937,10 @@ ecma_deref_ecma_string (ecma_string_t *string_p) /**< ecma-string */
}
default:
{
JERRY_UNREACHABLE ();
JERRY_ASSERT (ECMA_STRING_GET_CONTAINER (string_p) == ECMA_STRING_CONTAINER_UINT32_IN_DESC
|| ECMA_STRING_GET_CONTAINER (string_p) == ECMA_STRING_CONTAINER_MAGIC_STRING_EX);
/* only the string descriptor itself should be freed */
break;
}
}
@@ -2107,6 +2104,7 @@ ecma_string_get_size (const ecma_string_t *string_p) /**< ecma-string */
default:
{
JERRY_ASSERT (ECMA_STRING_GET_CONTAINER (string_p) == ECMA_STRING_CONTAINER_MAGIC_STRING_EX);
return lit_get_magic_string_ex_size (string_p->u.magic_string_ex_id);
}
}