Purple  0.1
Standard Language Specification
logging.h
Go to the documentation of this file.
1
8#ifndef LOGGING_H
9#define LOGGING_H
10
11#include "utils/shutdown.h"
12
14#define ANSI_BOLD "\033[1m"
16#define ANSI_RED "\033[38:5:196m"
18#define ANSI_ORANGE "\033[38:5:208m"
20#define ANSI_YELLOW "\033[38:5:178m"
22#define ANSI_RESET "\033[0m"
23
25#define ERROR_RED ANSI_RED ANSI_BOLD
27#define ERROR_ORANGE ANSI_ORANGE ANSI_BOLD
29#define ERROR_YELLOW ANSI_YELLOW ANSI_BOLD
30
34typedef enum
35{
43
47typedef struct {
51 char* name;
53 char* color;
54} LogInfo;
55
59static const LogInfo logInfoLevels[] = {
60 {LOG_NONE, "", ANSI_RESET}, {LOG_DEBUG, "[DEBUG]", ANSI_BOLD},
61 {LOG_INFO, "[INFO]", ANSI_BOLD}, {LOG_WARNING, "[WARNING]", ANSI_YELLOW},
62 {LOG_ERROR, "[ERROR]", ANSI_ORANGE}, {LOG_CRITICAL, "[CRITICAL]", ANSI_RED}};
63
67typedef enum
68{
77
81static const char* returnCodeStrings[] = {
82 "OK", "ERROR", "SYNTAX ERROR", "MEMORY ERROR",
83 "FILE ERROR", "COMPILER ERROR", "IDENTIFIER ERROR"};
84
85void fatal(ReturnCode rc, const char* fmt, ...);
86void syntax_error(char* fn, int line_number, int char_number, const char* fmt, ...);
87void identifier_error(char* fn, int line_number, int char_number, const char* fmt, ...);
88
89void purple_log(LogLevel level, const char* fmt, ...);
90
91#endif /* LOGGING_H */
void identifier_error(char *fn, int line_number, int char_number, const char *fmt,...)
Raises a fatal identifier error.
Definition: logging.c:84
void fatal(ReturnCode rc, const char *fmt,...)
Raises a fatal error that will exit the compiler.
Definition: logging.c:22
#define ANSI_BOLD
Definition: logging.h:14
static const LogInfo logInfoLevels[]
Collection of LogInfos for standard logging purposes.
Definition: logging.h:59
ReturnCode
Return codes used in different scenarios.
Definition: logging.h:68
@ RC_IDENTIFIER_ERROR
Definition: logging.h:75
@ RC_FILE_ERROR
Definition: logging.h:73
@ RC_MEMORY_ERROR
Definition: logging.h:72
@ RC_COMPILER_ERROR
Definition: logging.h:74
@ RC_ERROR
Definition: logging.h:70
@ RC_OK
Definition: logging.h:69
@ RC_SYNTAX_ERROR
Definition: logging.h:71
#define ANSI_ORANGE
Definition: logging.h:18
#define ANSI_RED
Definition: logging.h:16
void purple_log(LogLevel level, const char *fmt,...)
Raises a non-fatal logging statement.
Definition: logging.c:118
static const char * returnCodeStrings[]
String representation of return codes.
Definition: logging.h:81
void syntax_error(char *fn, int line_number, int char_number, const char *fmt,...)
Raises a fatal syntax error.
Definition: logging.c:48
LogLevel
Severity levels of logging statements emitted by the compiler.
Definition: logging.h:35
@ LOG_CRITICAL
Definition: logging.h:41
@ LOG_ERROR
Definition: logging.h:40
@ LOG_INFO
Definition: logging.h:38
@ LOG_NONE
Definition: logging.h:36
@ LOG_WARNING
Definition: logging.h:39
@ LOG_DEBUG
Definition: logging.h:37
#define ANSI_YELLOW
Definition: logging.h:20
#define ANSI_RESET
Definition: logging.h:22
Function headers for shutting down the compiler.
Maps LogLevels to text and color for displaying.
Definition: logging.h:47
char * color
Definition: logging.h:53
LogLevel level
Definition: logging.h:49
char * name
Definition: logging.h:51