|
Zen-C
|
#include <ctype.h>#include <stdarg.h>#include <stdio.h>#include <stdlib.h>#include <string.h>#include <unistd.h>

Go to the source code of this file.
Data Structures | |
| struct | Token |
| Represents a source token. More... | |
| struct | Lexer |
| Lexer state. More... | |
| struct | CompilerConfig |
| Compiler configuration and flags. More... | |
Macros | |
| #define | z_is_windows() 0 |
| #define | ZEN_VERSION "0.1.0" |
| Zen-C version. | |
| #define | COLOR_RESET "\033[0m" |
| Reset color. | |
| #define | COLOR_RED "\033[1;31m" |
| Red color. | |
| #define | COLOR_GREEN "\033[1;32m" |
| Green color. | |
| #define | COLOR_YELLOW "\033[1;33m" |
| Yellow color. | |
| #define | COLOR_BLUE "\033[1;34m" |
| Blue color. | |
| #define | COLOR_CYAN "\033[1;36m" |
| Cyan color. | |
| #define | COLOR_BOLD "\033[1m" |
| Bold text. | |
| #define | free(ptr) ((void)0) |
| Free memory. | |
| #define | malloc(sz) xmalloc(sz) |
| Allocate memory. | |
| #define | realloc(p, s) xrealloc(p, s) |
| Reallocate memory. | |
| #define | calloc(n, s) xcalloc(n, s) |
| Allocate and zero memory. | |
| #define | MAX_FLAGS_SIZE 1024 |
| #define | MAX_PATH_SIZE 1024 |
| #define | MAX_PATTERN_SIZE 1024 |
Enumerations | |
| enum | TokenType { TOK_EOF = 0 , TOK_IDENT , TOK_INT , TOK_FLOAT , TOK_STRING , TOK_FSTRING , TOK_CHAR , TOK_LPAREN , TOK_RPAREN , TOK_LBRACE , TOK_RBRACE , TOK_LBRACKET , TOK_RBRACKET , TOK_LANGLE , TOK_RANGLE , TOK_COMMA , TOK_COLON , TOK_SEMICOLON , TOK_OP , TOK_AT , TOK_DOTDOT , TOK_DOTDOT_EQ , TOK_DOTDOT_LT , TOK_ARROW , TOK_PIPE , TOK_TEST , TOK_ASSERT , TOK_SIZEOF , TOK_DEF , TOK_DEFER , TOK_AUTOFREE , TOK_QUESTION , TOK_USE , TOK_QQ , TOK_QQ_EQ , TOK_Q_DOT , TOK_DCOLON , TOK_TRAIT , TOK_IMPL , TOK_AND , TOK_OR , TOK_FOR , TOK_COMPTIME , TOK_ELLIPSIS , TOK_UNION , TOK_ASM , TOK_VOLATILE , TOK_ASYNC , TOK_AWAIT , TOK_PREPROC , TOK_ALIAS , TOK_COMMENT , TOK_OPAQUE , TOK_UNKNOWN } |
| Token types for the Lexer. More... | |
Functions | |
| void | lexer_init (Lexer *l, const char *src) |
| Initialize the lexer. | |
| Token | lexer_next (Lexer *l) |
| Get the next token. | |
| Token | lexer_peek (Lexer *l) |
| Get the next token without advancing. | |
| Token | lexer_peek2 (Lexer *l) |
| Get the next token without advancing (2 look ahead). | |
| void | register_trait (const char *name) |
| Register a trait. | |
| int | is_trait (const char *name) |
| Check if a name is a trait. | |
| void * | xmalloc (size_t size) |
| Allocate memory. | |
| void * | xrealloc (void *ptr, size_t new_size) |
| Reallocate memory. | |
| void * | xcalloc (size_t n, size_t size) |
| Allocate and zero memory. | |
| char * | xstrdup (const char *s) |
| Duplicate a string. | |
| void | zpanic (const char *fmt,...) |
| Error reporting. | |
| void | zpanic_at (Token t, const char *fmt,...) |
| Error reporting with token location. | |
| char * | load_file (const char *filename) |
| Load a file. | |
| void | scan_build_directives (struct ParserContext *ctx, const char *src) |
| Scan build directives. | |
| int | levenshtein (const char *s1, const char *s2) |
| Calculate Levenshtein distance. | |
| 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 | zwarn (const char *fmt,...) |
| Warning reporting. | |
| void | zwarn_at (Token t, const char *fmt,...) |
| Warning reporting with token location. | |
| void | warn_unused_variable (Token t, const char *var_name) |
| Warning reporting for unused variable. | |
| void | warn_unused_parameter (Token t, const char *param_name, const char *func_name) |
| Warning reporting for unused parameter. | |
| 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_narrowing_conversion (Token t, const char *from_type, const char *to_type) |
| Warning reporting for narrowing 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_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. | |
Variables | |
| char * | g_current_filename |
| Current filename. | |
| char | g_link_flags [MAX_FLAGS_SIZE] |
| char | g_cflags [MAX_FLAGS_SIZE] |
| int | g_warning_count |
| CompilerConfig | g_config |
| #define calloc | ( | n, | |
| s | |||
| ) | xcalloc(n, s) |
Allocate and zero memory.
| #define COLOR_BLUE "\033[1;34m" |
Blue color.
| #define COLOR_BOLD "\033[1m" |
Bold text.
| #define COLOR_CYAN "\033[1;36m" |
Cyan color.
| #define COLOR_GREEN "\033[1;32m" |
Green color.
| #define COLOR_RED "\033[1;31m" |
Red color.
| #define COLOR_RESET "\033[0m" |
Reset color.
| #define COLOR_YELLOW "\033[1;33m" |
Yellow color.
| #define free | ( | ptr | ) | ((void)0) |
Free memory.
| #define malloc | ( | sz | ) | xmalloc(sz) |
Allocate memory.
| #define MAX_FLAGS_SIZE 1024 |
| #define MAX_PATH_SIZE 1024 |
| #define MAX_PATTERN_SIZE 1024 |
| #define realloc | ( | p, | |
| s | |||
| ) | xrealloc(p, s) |
Reallocate memory.
| #define z_is_windows | ( | ) | 0 |
| #define ZEN_VERSION "0.1.0" |
Zen-C version.
| enum TokenType |
| void error_cannot_index | ( | Token | t, |
| const char * | type_name | ||
| ) |
Error reporting for cannot index.

| void error_type_expected | ( | Token | t, |
| const char * | expected, | ||
| const char * | got | ||
| ) |
Error reporting for type expected.

| void error_undefined_field | ( | Token | t, |
| const char * | struct_name, | ||
| const char * | field_name, | ||
| const char * | suggestion | ||
| ) |
Error reporting for undefined field.

| 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.

| int is_trait | ( | const char * | name | ) |
Check if a name is a trait.

| int levenshtein | ( | const char * | s1, |
| const char * | s2 | ||
| ) |
Calculate Levenshtein distance.

| void lexer_init | ( | Lexer * | l, |
| const char * | src | ||
| ) |
Initialize the lexer.

Get the next token.


Get the next token without advancing.


Get the next token without advancing (2 look ahead).


| char * load_file | ( | const char * | filename | ) |
Load a file.


| void register_trait | ( | const char * | name | ) |
Register a trait.


| void scan_build_directives | ( | struct ParserContext * | ctx, |
| const char * | src | ||
| ) |
Scan build directives.


| void warn_array_bounds | ( | Token | t, |
| int | index, | ||
| int | size | ||
| ) |
Warning reporting for array bounds.


| void warn_comparison_always_false | ( | Token | t, |
| const char * | reason | ||
| ) |
Warning reporting for comparison always false.


| void warn_comparison_always_true | ( | Token | t, |
| const char * | reason | ||
| ) |
Warning reporting for comparison always true.


| void warn_division_by_zero | ( | Token | t | ) |
Warning reporting for division by zero.


| void warn_format_string | ( | Token | t, |
| int | arg_num, | ||
| const char * | expected, | ||
| const char * | got | ||
| ) |
Warning reporting for format string.

| void warn_implicit_conversion | ( | Token | t, |
| const char * | from_type, | ||
| const char * | to_type | ||
| ) |
Warning reporting for implicit conversion.

| void warn_integer_overflow | ( | Token | t, |
| const char * | type_name, | ||
| long long | value | ||
| ) |
Warning reporting for integer overflow.

| void warn_missing_return | ( | Token | t, |
| const char * | func_name | ||
| ) |
Warning reporting for missing return.

| void warn_narrowing_conversion | ( | Token | t, |
| const char * | from_type, | ||
| const char * | to_type | ||
| ) |
Warning reporting for narrowing conversion.

| void warn_null_pointer | ( | Token | t, |
| const char * | expr | ||
| ) |
Warning reporting for null pointer.

| 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_unused_parameter | ( | Token | t, |
| const char * | param_name, | ||
| const char * | func_name | ||
| ) |
Warning reporting for unused parameter.


| void warn_unused_variable | ( | Token | t, |
| const char * | var_name | ||
| ) |
Warning reporting for unused variable.


| void * xcalloc | ( | size_t | n, |
| size_t | size | ||
| ) |
Allocate and zero memory.

| void * xmalloc | ( | size_t | size | ) |
Allocate 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 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 zwarn | ( | const char * | fmt, |
| ... | |||
| ) |
Warning reporting.

| void zwarn_at | ( | Token | t, |
| const char * | fmt, | ||
| ... | |||
| ) |
Warning reporting with token location.

|
extern |
|
extern |
|
extern |
Current filename.
|
extern |
|
extern |