Adding jerry_unreachable and jerry_unimplemented routines that print file name and line for corresponding unreachable, unimplemented marks.

This commit is contained in:
Ruben Ayrapetyan
2014-09-18 17:08:32 +04:00
parent 55d9b12176
commit d9e0f2936d
4 changed files with 78 additions and 10 deletions
+5 -5
View File
@@ -98,6 +98,8 @@ typedef enum
extern uint32_t jerry_unreferenced_expression; extern uint32_t jerry_unreferenced_expression;
extern void __noreturn jerry_assert_fail (const char *assertion, const char *file, const uint32_t line); extern void __noreturn jerry_assert_fail (const char *assertion, const char *file, const uint32_t line);
extern void __noreturn jerry_unreachable (const char *comment, const char *file, const uint32_t line);
extern void __noreturn jerry_unimplemented (const char *comment, const char *file, const uint32_t line);
#ifndef JERRY_NDEBUG #ifndef JERRY_NDEBUG
#define JERRY_ASSERT(x) do { if (__builtin_expect (!(x), 0)) { jerry_assert_fail (#x, __FILE__, __LINE__); } } while (0) #define JERRY_ASSERT(x) do { if (__builtin_expect (!(x), 0)) { jerry_assert_fail (#x, __FILE__, __LINE__); } } while (0)
@@ -112,21 +114,19 @@ extern void jerry_ref_unused_variables (int unused_variables_follow, ...);
#define JERRY_UNREACHABLE() \ #define JERRY_UNREACHABLE() \
do \ do \
{ \ { \
JERRY_ASSERT (false); \ jerry_unreachable (NULL, __FILE__, __LINE__); \
jerry_exit (ERR_FAILED_INTERNAL_ASSERTION); \
} while (0) } while (0)
#define JERRY_UNIMPLEMENTED() \ #define JERRY_UNIMPLEMENTED() \
do \ do \
{ \ { \
JERRY_ASSERT (false); \ jerry_unimplemented (NULL, __FILE__, __LINE__); \
jerry_exit (ERR_UNIMPLEMENTED_CASE); \
} while (0) } while (0)
#define JERRY_UNIMPLEMENTED_REF_UNUSED_VARS(...) \ #define JERRY_UNIMPLEMENTED_REF_UNUSED_VARS(...) \
do \ do \
{ \ { \
JERRY_UNIMPLEMENTED (); \ jerry_unimplemented (NULL, __FILE__, __LINE__); \
if (false) \ if (false) \
{ \ { \
jerry_ref_unused_variables (0, __VA_ARGS__); \ jerry_ref_unused_variables (0, __VA_ARGS__); \
+38 -1
View File
@@ -24,9 +24,46 @@ jerry_assert_fail (const char *assertion, /**< assertion condition string */
const char *file, /**< file name */ const char *file, /**< file name */
const uint32_t line) /** line */ const uint32_t line) /** line */
{ {
__printf ("Assertion '%s' failed at %s:%u\n", __printf ("Assertion '%s' failed at %s:%u.\n",
assertion, file, line); assertion, file, line);
__exit (-ERR_FAILED_INTERNAL_ASSERTION); __exit (-ERR_FAILED_INTERNAL_ASSERTION);
} /* jerry_assert_fail */ } /* jerry_assert_fail */
/**
* Handle execution of control path that should be unreachable
*/
void __noreturn
jerry_unreachable (const char *comment, /**< comment to unreachable mark if exists,
NULL - otherwise */
const char *file, /**< file name */
const uint32_t line) /**< line */
{
__printf ("Unreachable control path at %s:%u was executed", file, line);
if (comment != NULL)
{
__printf ("(%s)", comment);
}
__printf (".\n");
__exit (-ERR_FAILED_INTERNAL_ASSERTION);
} /* jerry_unreachable */
/**
* Handle unimplemented case execution
*/
void __noreturn
jerry_unimplemented (const char *comment, /**< comment to unimplemented mark if exists,
NULL - otherwise */
const char *file, /**< file name */
const uint32_t line) /**< line */
{
__printf ("Unimplemented case at %s:%u was executed", file, line);
if (comment != NULL)
{
__printf ("(%s)", comment);
}
__printf (".\n");
__exit (-ERR_UNIMPLEMENTED_CASE);
} /* jerry_unimplemented */
+9 -2
View File
@@ -385,11 +385,18 @@ __putchar (int c)
return putchar (c); return putchar (c);
} /* __putchar */ } /* __putchar */
/** exit - cause normal process termination */ /**
* Exit - cause normal process termination with specified status code
*/
void __noreturn void __noreturn
__exit (int status) __exit (int status) /**< status code */
{ {
exit (status); exit (status);
while (true)
{
/* unreachable */
}
} /* __exit */ } /* __exit */
/** /**
+26 -2
View File
@@ -21,8 +21,32 @@
*/ */
void __noreturn void __noreturn
jerry_assert_fail (const char *assertion __unused, /**< assertion condition string */ jerry_assert_fail (const char *assertion __unused, /**< assertion condition string */
const char *file __unused, /**< file name */ const char *file __unused, /**< file name */
const uint32_t line __unused) /** line */ const uint32_t line __unused) /** line */
{ {
__exit (-ERR_FAILED_INTERNAL_ASSERTION); __exit (-ERR_FAILED_INTERNAL_ASSERTION);
} /* jerry_assert_fail */ } /* jerry_assert_fail */
/**
* Handle execution of control path that should be unreachable
*/
void __noreturn
jerry_unreachable (const char *comment __unused, /**< comment to unreachable mark if exists,
NULL - otherwise */
const char *file __unused, /**< file name */
const uint32_t line __unused) /**< line */
{
__exit (-ERR_FAILED_INTERNAL_ASSERTION);
} /* jerry_unreachable */
/**
* Handle unimplemented case execution
*/
void __noreturn
jerry_unimplemented (const char *comment __unused, /**< comment to unimplemented mark if exists,
NULL - otherwise */
const char *file __unused, /**< file name */
const uint32_t line __unused) /**< line */
{
__exit (-ERR_UNIMPLEMENTED_CASE);
} /* jerry_unimplemented */