*refactored error handling macros.

This commit is contained in:
Wang Renxin 2016-07-06 11:50:29 +08:00 committed by GitHub
parent c5944e67b9
commit 43677fb98c

View File

@ -1281,7 +1281,7 @@ static bool_t _is_print_terminal(mb_interpreter_t* s, _object_t* obj);
} \ } \
} while(0) } while(0)
#if _WARNING_AS_ERROR #if _WARNING_AS_ERROR
# define _handle_error(__s, __err, __f, __pos, __row, __col, __ret, __exit, __result) \ # define _handle_error_at_pos(__s, __err, __f, __pos, __row, __col, __ret, __exit, __result) \
do { \ do { \
_set_current_error((__s), (__err), (__f)); \ _set_current_error((__s), (__err), (__f)); \
_set_error_pos((__s), (__pos), (__row), (__col)); \ _set_error_pos((__s), (__pos), (__row), (__col)); \
@ -1289,7 +1289,7 @@ static bool_t _is_print_terminal(mb_interpreter_t* s, _object_t* obj);
goto __exit; \ goto __exit; \
} while(0) } while(0)
#else /* _WARNING_AS_ERROR */ #else /* _WARNING_AS_ERROR */
# define _handle_error(__s, __err, __f, __pos, __row, __col, __ret, __exit, __result) \ # define _handle_error_at_pos(__s, __err, __f, __pos, __row, __col, __ret, __exit, __result) \
do { \ do { \
_set_current_error((__s), (__err), (__f)); \ _set_current_error((__s), (__err), (__f)); \
_set_error_pos((__s), (__pos), (__row), (__col)); \ _set_error_pos((__s), (__pos), (__row), (__col)); \
@ -1300,18 +1300,18 @@ static bool_t _is_print_terminal(mb_interpreter_t* s, _object_t* obj);
} while(0) } while(0)
#endif /* _WARNING_AS_ERROR */ #endif /* _WARNING_AS_ERROR */
#ifdef MB_ENABLE_SOURCE_TRACE #ifdef MB_ENABLE_SOURCE_TRACE
# define _HANDLE_ERROR(__s, __err, __f, __obj, __ret, __exit, __result) _handle_error((__s), (__err), (__f), (__obj)->source_pos, (__obj)->source_row, (__obj)->source_col, (__ret), __exit, (__result)) # define _handle_error_on_obj(__s, __err, __f, __obj, __ret, __exit, __result) \
#else /* MB_ENABLE_SOURCE_TRACE */
# define _HANDLE_ERROR(__s, __err, __f, __obj, __ret, __exit, __result) _handle_error((__s), (__err), (__f), 0, 0, 0, (__ret), __exit, (__result))
#endif /* MB_ENABLE_SOURCE_TRACE */
#define _handle_error_on_obj(__s, __err, __f, __obj, __ret, __exit, __result) \
do { \ do { \
if(__obj) { \ if(__obj) { \
_HANDLE_ERROR((__s), (__err), (__f), (__obj), (__ret), __exit, (__result)); \ _handle_error_at_pos((__s), (__err), (__f), (__obj)->source_pos, (__obj)->source_row, (__obj)->source_col, (__ret), __exit, (__result)); \
} else { \ } else { \
_handle_error((__s), (__err), (__f), 0, 0, 0, (__ret), __exit, (__result)); \ _handle_error_at_pos((__s), (__err), (__f), 0, 0, 0, (__ret), __exit, (__result)); \
} \ } \
} while(0) } while(0)
#else /* MB_ENABLE_SOURCE_TRACE */
# define _handle_error_on_obj(__s, __err, __f, __obj, __ret, __exit, __result) \
do { ((void)(__obj)); _handle_error_at_pos((__s), (__err), (__f), 0, 0, 0, (__ret), __exit, (__result)); } while(0)
#endif /* MB_ENABLE_SOURCE_TRACE */
#define _OUTTER_SCOPE(__s) ((__s)->prev ? (__s)->prev : (__s)) #define _OUTTER_SCOPE(__s) ((__s)->prev ? (__s)->prev : (__s))
@ -5354,7 +5354,7 @@ static int _parse_char(mb_interpreter_t* s, const char* str, int n, int pos, uns
_mb_check(result = _append_char_to_symbol(s, c), _exit); _mb_check(result = _append_char_to_symbol(s, c), _exit);
} }
} else { } else {
_handle_error(s, SE_PS_INVALID_CHAR, s->source_file, pos, row, col, MB_FUNC_ERR, _exit, result); _handle_error_at_pos(s, SE_PS_INVALID_CHAR, s->source_file, pos, row, col, MB_FUNC_ERR, _exit, result);
} }
} else if(context->symbol_state == _SS_OPERATOR) { } else if(context->symbol_state == _SS_OPERATOR) {
if(_is_identifier_char(c)) { if(_is_identifier_char(c)) {
@ -5366,7 +5366,7 @@ static int _parse_char(mb_interpreter_t* s, const char* str, int n, int pos, uns
_mb_check(result = _cut_symbol(s, pos, row, col), _exit); _mb_check(result = _cut_symbol(s, pos, row, col), _exit);
_mb_check(result = _append_char_to_symbol(s, c), _exit); _mb_check(result = _append_char_to_symbol(s, c), _exit);
} else { } else {
_handle_error(s, SE_PS_INVALID_CHAR, s->source_file, pos, row, col, MB_FUNC_ERR, _exit, result); _handle_error_at_pos(s, SE_PS_INVALID_CHAR, s->source_file, pos, row, col, MB_FUNC_ERR, _exit, result);
} }
} else { } else {
mb_assert(0 && "Impossible."); mb_assert(0 && "Impossible.");