Zen-C
Loading...
Searching...
No Matches
utils.c File Reference
#include "parser.h"
#include "zprep.h"
Include dependency graph for utils.c:

Data Structures

struct  ArenaBlock
 

Macros

#define ARENA_BLOCK_SIZE   (1024 * 1024)
 

Typedefs

typedef struct ArenaBlock ArenaBlock
 

Functions

void * xmalloc (size_t size)
 Allocate memory.
 
void * xcalloc (size_t n, size_t size)
 Allocate and zero memory.
 
void * xrealloc (void *ptr, size_t new_size)
 Reallocate memory.
 
char * xstrdup (const char *s)
 Duplicate a string.
 
void zpanic (const char *fmt,...)
 Error reporting.
 
void zwarn (const char *fmt,...)
 Warning reporting.
 
void zwarn_at (Token t, const char *fmt,...)
 Warning reporting with token location.
 
void zpanic_at (Token t, const char *fmt,...)
 Error reporting with token location.
 
void zpanic_with_suggestion (Token t, const char *msg, const char *suggestion)
 Error reporting with suggestion.
 
void error_undefined_function (Token t, const char *func_name, const char *suggestion)
 Error reporting for undefined function.
 
void error_wrong_arg_count (Token t, const char *func_name, int expected, int got)
 Error reporting for wrong argument count.
 
void error_undefined_field (Token t, const char *struct_name, const char *field_name, const char *suggestion)
 Error reporting for undefined field.
 
void error_type_expected (Token t, const char *expected, const char *got)
 Error reporting for type expected.
 
void error_cannot_index (Token t, const char *type_name)
 Error reporting for cannot index.
 
void warn_unused_variable (Token t, const char *var_name)
 Warning reporting for unused variable.
 
void warn_shadowing (Token t, const char *var_name)
 Warning reporting for shadowing.
 
void warn_unreachable_code (Token t)
 Warning reporting for unreachable code.
 
void warn_implicit_conversion (Token t, const char *from_type, const char *to_type)
 Warning reporting for implicit conversion.
 
void warn_missing_return (Token t, const char *func_name)
 Warning reporting for missing return.
 
void warn_comparison_always_true (Token t, const char *reason)
 Warning reporting for comparison always true.
 
void warn_comparison_always_false (Token t, const char *reason)
 Warning reporting for comparison always false.
 
void warn_unused_parameter (Token t, const char *param_name, const char *func_name)
 Warning reporting for unused parameter.
 
void warn_narrowing_conversion (Token t, const char *from_type, const char *to_type)
 Warning reporting for narrowing conversion.
 
void warn_division_by_zero (Token t)
 Warning reporting for division by zero.
 
void warn_integer_overflow (Token t, const char *type_name, long long value)
 Warning reporting for integer overflow.
 
void warn_array_bounds (Token t, int index, int size)
 Warning reporting for array bounds.
 
void warn_format_string (Token t, int arg_num, const char *expected, const char *got)
 Warning reporting for format string.
 
void warn_null_pointer (Token t, const char *expr)
 Warning reporting for null pointer.
 
char * load_file (const char *fn)
 Load a file.
 
void scan_build_directives (ParserContext *ctx, const char *src)
 Scan build directives.
 
int levenshtein (const char *s1, const char *s2)
 Calculate Levenshtein distance.
 

Variables

char * g_current_filename = "unknown"
 Current filename.
 
ParserContextg_parser_ctx = NULL
 
char g_link_flags [MAX_FLAGS_SIZE] = ""
 
char g_cflags [MAX_FLAGS_SIZE] = ""
 
int g_warning_count = 0
 
CompilerConfig g_config = {0}
 

Macro Definition Documentation

◆ ARENA_BLOCK_SIZE

#define ARENA_BLOCK_SIZE   (1024 * 1024)

Typedef Documentation

◆ ArenaBlock

typedef struct ArenaBlock ArenaBlock

Function Documentation

◆ error_cannot_index()

void error_cannot_index ( Token  t,
const char *  type_name 
)

Error reporting for cannot index.

Here is the call graph for this function:

◆ error_type_expected()

void error_type_expected ( Token  t,
const char *  expected,
const char *  got 
)

Error reporting for type expected.

Here is the call graph for this function:

◆ error_undefined_field()

void error_undefined_field ( Token  t,
const char *  struct_name,
const char *  field_name,
const char *  suggestion 
)

Error reporting for undefined field.

Here is the call graph for this function:

◆ error_undefined_function()

void error_undefined_function ( Token  t,
const char *  func_name,
const char *  suggestion 
)

Error reporting for undefined function.

Here is the call graph for this function:

◆ error_wrong_arg_count()

void error_wrong_arg_count ( Token  t,
const char *  func_name,
int  expected,
int  got 
)

Error reporting for wrong argument count.

Here is the call graph for this function:

◆ levenshtein()

int levenshtein ( const char *  s1,
const char *  s2 
)

Calculate Levenshtein distance.

Here is the caller graph for this function:

◆ load_file()

char * load_file ( const char *  fn)

Load a file.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ scan_build_directives()

void scan_build_directives ( ParserContext ctx,
const char *  src 
)

Scan build directives.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ warn_array_bounds()

void warn_array_bounds ( Token  t,
int  index,
int  size 
)

Warning reporting for array bounds.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ warn_comparison_always_false()

void warn_comparison_always_false ( Token  t,
const char *  reason 
)

Warning reporting for comparison always false.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ warn_comparison_always_true()

void warn_comparison_always_true ( Token  t,
const char *  reason 
)

Warning reporting for comparison always true.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ warn_division_by_zero()

void warn_division_by_zero ( Token  t)

Warning reporting for division by zero.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ warn_format_string()

void warn_format_string ( Token  t,
int  arg_num,
const char *  expected,
const char *  got 
)

Warning reporting for format string.

Here is the call graph for this function:

◆ warn_implicit_conversion()

void warn_implicit_conversion ( Token  t,
const char *  from_type,
const char *  to_type 
)

Warning reporting for implicit conversion.

Here is the call graph for this function:

◆ warn_integer_overflow()

void warn_integer_overflow ( Token  t,
const char *  type_name,
long long  value 
)

Warning reporting for integer overflow.

Here is the call graph for this function:

◆ warn_missing_return()

void warn_missing_return ( Token  t,
const char *  func_name 
)

Warning reporting for missing return.

Here is the call graph for this function:

◆ warn_narrowing_conversion()

void warn_narrowing_conversion ( Token  t,
const char *  from_type,
const char *  to_type 
)

Warning reporting for narrowing conversion.

Here is the call graph for this function:

◆ warn_null_pointer()

void warn_null_pointer ( Token  t,
const char *  expr 
)

Warning reporting for null pointer.

Here is the call graph for this function:

◆ warn_shadowing()

void warn_shadowing ( Token  t,
const char *  var_name 
)

Warning reporting for shadowing.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ warn_unreachable_code()

void warn_unreachable_code ( Token  t)

Warning reporting for unreachable code.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ warn_unused_parameter()

void warn_unused_parameter ( Token  t,
const char *  param_name,
const char *  func_name 
)

Warning reporting for unused parameter.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ warn_unused_variable()

void warn_unused_variable ( Token  t,
const char *  var_name 
)

Warning reporting for unused variable.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ xcalloc()

void * xcalloc ( size_t  n,
size_t  size 
)

Allocate and zero memory.

Here is the caller graph for this function:

◆ xmalloc()

void * xmalloc ( size_t  size)

Allocate memory.

◆ xrealloc()

void * xrealloc ( void *  ptr,
size_t  new_size 
)

Reallocate memory.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ xstrdup()

char * xstrdup ( const char *  s)

Duplicate a string.

Here is the call graph for this function:

◆ zpanic()

void zpanic ( const char *  fmt,
  ... 
)

Error reporting.

◆ zpanic_at()

void zpanic_at ( Token  t,
const char *  fmt,
  ... 
)

Error reporting with token location.

Here is the caller graph for this function:

◆ zpanic_with_suggestion()

void zpanic_with_suggestion ( Token  t,
const char *  msg,
const char *  suggestion 
)

Error reporting with suggestion.

Here is the caller graph for this function:

◆ zwarn()

void zwarn ( const char *  fmt,
  ... 
)

Warning reporting.

Here is the caller graph for this function:

◆ zwarn_at()

void zwarn_at ( Token  t,
const char *  fmt,
  ... 
)

Warning reporting with token location.

Here is the caller graph for this function:

Variable Documentation

◆ g_cflags

char g_cflags = ""

◆ g_config

CompilerConfig g_config = {0}

◆ g_current_filename

char* g_current_filename = "unknown"

Current filename.

◆ g_link_flags

char g_link_flags = ""

◆ g_parser_ctx

ParserContext* g_parser_ctx = NULL

◆ g_warning_count

int g_warning_count = 0