From cb6eaf13c3b3b58779a18255177589d8d5fbf85b Mon Sep 17 00:00:00 2001 From: A404M Date: Thu, 13 Feb 2025 18:39:08 +0330 Subject: add i8 u8 i16 u16 i32 u32 add overflow warning --- src/utils/log.c | 15 ++++++++++----- src/utils/log.h | 5 +++-- 2 files changed, 13 insertions(+), 7 deletions(-) (limited to 'src/utils') diff --git a/src/utils/log.c b/src/utils/log.c index 3f73729..9b8f94f 100644 --- a/src/utils/log.c +++ b/src/utils/log.c @@ -17,8 +17,8 @@ void _printLogBack(const char *format, const char *file, int line, ...) { free(errorStr); } -void _printErrorBack(const char *file, int line, char *begin, char *end, - const char *format, ...) { +void _printErrorWarningBack(const char *file, int line, char *begin, char *end, + bool isError, const char *format, ...) { va_list args; va_start(args, end); char *errorStr; @@ -35,9 +35,14 @@ void _printErrorBack(const char *file, int line, char *begin, char *end, } const char firstColor[] = "\e[0;36m"; - const char secondColor[] = "\e[0;31m"; - fprintf(stderr, "%sError: %s at compiler %s:%d\e[0m\n", firstColor, errorStr, - file, line); + const char *secondColor = isError ? "\e[0;31m" : "\e[0;33m"; + if (isError) { + fprintf(stderr, "%sError: %s at compiler %s:%d\e[0m\n", firstColor, + errorStr, file, line); + } else { + fprintf(stderr, "%sWarning: %s at compiler %s:%d\e[0m\n", firstColor, + errorStr, file, line); + } free(errorStr); if (file_index == SIZE_MAX) { diff --git a/src/utils/log.h b/src/utils/log.h index 6cede24..a0d48a6 100644 --- a/src/utils/log.h +++ b/src/utils/log.h @@ -1,10 +1,11 @@ #pragma once #define printLog(format,...) _printLogBack(format, __FILE_NAME__, __LINE__, ## __VA_ARGS__) -#define printError(begin,end,format,...) _printErrorBack(__FILE_NAME__, __LINE__, begin, end, format, ## __VA_ARGS__) +#define printError(begin,end,format,...) _printErrorWarningBack(__FILE_NAME__, __LINE__, begin, end, true, format, ## __VA_ARGS__) +#define printWarning(begin,end,format,...) _printErrorWarningBack(__FILE_NAME__, __LINE__, begin, end, false, format, ## __VA_ARGS__) #define UNREACHABLE printLog("Unreachable");exit(1) extern void _printLogBack(const char *format, const char *file, int line, ...); -extern void _printErrorBack(const char *file, int line, char *begin, char *end,const char *format, ...); +extern void _printErrorWarningBack(const char *file, int line, char *begin, char *end,bool isError,const char *format, ...); -- cgit v1.2.3