Purple  0.1
Standard Language Specification
Classes | Macros | Enumerations | Functions | Variables
logging.h File Reference

Function headers, ANSI defines, and enums for raising internal warnings and errors. More...

#include "utils/shutdown.h"
Include dependency graph for logging.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  LogInfo
 Maps LogLevels to text and color for displaying. More...
 

Macros

#define ANSI_BOLD   "\033[1m"
 
#define ANSI_RED   "\033[38:5:196m"
 
#define ANSI_ORANGE   "\033[38:5:208m"
 
#define ANSI_YELLOW   "\033[38:5:178m"
 
#define ANSI_RESET   "\033[0m"
 
#define ERROR_RED   ANSI_RED ANSI_BOLD
 
#define ERROR_ORANGE   ANSI_ORANGE ANSI_BOLD
 
#define ERROR_YELLOW   ANSI_YELLOW ANSI_BOLD
 

Enumerations

enum  LogLevel {
  LOG_NONE , LOG_DEBUG , LOG_INFO , LOG_WARNING ,
  LOG_ERROR , LOG_CRITICAL
}
 Severity levels of logging statements emitted by the compiler. More...
 
enum  ReturnCode {
  RC_OK , RC_ERROR , RC_SYNTAX_ERROR , RC_MEMORY_ERROR ,
  RC_FILE_ERROR , RC_COMPILER_ERROR , RC_IDENTIFIER_ERROR , RC_ARG_ERROR
}
 Return codes used in different scenarios. More...
 

Functions

void fatal (ReturnCode rc, const char *fmt,...)
 Raises a fatal error that will exit the compiler. More...
 
void syntax_error (char *fn, int line_number, int char_number, const char *fmt,...)
 Raises a fatal syntax error. More...
 
void identifier_error (char *fn, int line_number, int char_number, const char *fmt,...)
 Raises a fatal identifier error. More...
 
void purple_log (LogLevel level, const char *fmt,...)
 Raises a non-fatal logging statement. More...
 

Variables

static const LogInfo logInfoLevels []
 Collection of LogInfos for standard logging purposes. More...
 
static const char * returnCodeStrings []
 String representation of return codes. More...
 

Detailed Description

Function headers, ANSI defines, and enums for raising internal warnings and errors.

Author
Charles Averill
Date
08-Sep-2022

Macro Definition Documentation

◆ ANSI_BOLD

#define ANSI_BOLD   "\033[1m"

ANSI code for bold text

◆ ANSI_ORANGE

#define ANSI_ORANGE   "\033[38:5:208m"

ANSI code for orange text

◆ ANSI_RED

#define ANSI_RED   "\033[38:5:196m"

ANSI code for red text

◆ ANSI_RESET

#define ANSI_RESET   "\033[0m"

ANSI code for default text style

◆ ANSI_YELLOW

#define ANSI_YELLOW   "\033[38:5:178m"

ANSI code for yellow text

◆ ERROR_ORANGE

#define ERROR_ORANGE   ANSI_ORANGE ANSI_BOLD

Combination of ANSI codes for orange errors

◆ ERROR_RED

#define ERROR_RED   ANSI_RED ANSI_BOLD

Combination of ANSI codes for red errors

◆ ERROR_YELLOW

#define ERROR_YELLOW   ANSI_YELLOW ANSI_BOLD

Combination of ANSI codes for yellow errors

Enumeration Type Documentation

◆ LogLevel

enum LogLevel

Severity levels of logging statements emitted by the compiler.

Enumerator
LOG_NONE 
LOG_DEBUG 
LOG_INFO 
LOG_WARNING 
LOG_ERROR 
LOG_CRITICAL 

◆ ReturnCode

enum ReturnCode

Return codes used in different scenarios.

Enumerator
RC_OK 
RC_ERROR 
RC_SYNTAX_ERROR 
RC_MEMORY_ERROR 
RC_FILE_ERROR 
RC_COMPILER_ERROR 
RC_IDENTIFIER_ERROR 
RC_ARG_ERROR 

Function Documentation

◆ fatal()

void fatal ( ReturnCode  rc,
const char *  fmt,
  ... 
)

Raises a fatal error that will exit the compiler.

Parameters
rcReturn code to exit with
fmtFormat string for printed error
...Varargs for printed error

◆ identifier_error()

void identifier_error ( char *  fn,
int  line_number,
int  char_number,
const char *  fmt,
  ... 
)

Raises a fatal identifier error.

Parameters
fnFilename in which identifier error occurs
line_numberLine number on which identifier error occurs
char_numberCharacter numbre on which syntax error occurs
fmtFormat string for details printed before fatal error
...Varargs for details printed before fatal error

◆ purple_log()

void purple_log ( LogLevel  level,
const char *  fmt,
  ... 
)

Raises a non-fatal logging statement.

Parameters
levelSeverity of statement
fmtFormat string for printed statement
...Varargs for printed statement

◆ syntax_error()

void syntax_error ( char *  fn,
int  line_number,
int  char_number,
const char *  fmt,
  ... 
)

Raises a fatal syntax error.

Parameters
fnFilename in which syntax error occurs
line_numberLine number on which syntax error occurs
char_numberCharacter numbre on which syntax error occurs
fmtFormat string for details printed before fatal error
...Varargs for details printed before fatal error

Variable Documentation

◆ logInfoLevels

const LogInfo logInfoLevels[]
static
Initial value:
= {
{LOG_NONE, "", ANSI_RESET}, {LOG_DEBUG, "[DEBUG]", ANSI_BOLD},
{LOG_INFO, "[INFO]", ANSI_BOLD}, {LOG_WARNING, "[WARNING]", ANSI_YELLOW},
{LOG_ERROR, "[ERROR]", ANSI_ORANGE}, {LOG_CRITICAL, "[CRITICAL]", ANSI_RED}}
#define ANSI_BOLD
Definition: logging.h:14
#define ANSI_ORANGE
Definition: logging.h:18
#define ANSI_RED
Definition: logging.h:16
@ 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

Collection of LogInfos for standard logging purposes.

◆ returnCodeStrings

const char* returnCodeStrings[]
static
Initial value:
= {
"OK", "ERROR", "SYNTAX ERROR", "MEMORY ERROR",
"FILE ERROR", "COMPILER ERROR", "IDENTIFIER ERROR", "ARGUMENT ERROR"}

String representation of return codes.