Cedro
Data Structures | Macros | Typedefs | Enumerations | Functions | Variables
cedro.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <stdint.h>
#include <stdbool.h>
#include <iso646.h>
#include <string.h>
#include <assert.h>
#include <sys/resource.h>
#include <errno.h>
#include "array.h"
#include "macros.h"
#include <time.h>

Data Structures

struct  Options
 
struct  Marker
 
struct  Error
 
struct  Marker_array
 
struct  Marker_array_slice
 
struct  Marker_array_mut_slice
 
struct  TokenType_array
 
struct  TokenType_array_slice
 
struct  TokenType_array_mut_slice
 
struct  Byte_array
 
struct  Byte_array_slice
 
struct  Byte_array_mut_slice
 
struct  Macro
 

Macros

#define is_not   not_eq
 
#define is   ==
 
#define in(min, x, max)   (x >= min && x <= max)
 
#define mem_eq(a, b, len)   (0 is memcmp(a, b, len))
 
#define str_eq(a, b)   (0 is strcmp(a, b))
 
#define strn_eq(a, b, len)   (0 is strncmp(a, b, len))
 
#define NDEBUG
 
#define CEDRO_VERSION   "1.0"
 
#define CEDRO_PRAGMA   "#pragma Cedro 1."
 
#define CEDRO_PRAGMA_LEN   16
 
#define LANG(es, en)   (strn_eq(getenv("LANG"), "es", 2)? es: en)
 
#define eprintln(...)   eprint(__VA_ARGS__), eprint("\n")
 
#define TYPEDEF_STRUCT(T, TYPE)
 
#define TYPEDEF(T, TYPE)
 
#define B(string)   ((const unsigned char * const)string)
 
#define precedence(token_type)   (token_type - T_OP_1)
 
#define is_keyword(token_type)   (token_type >= T_TYPE && token_type <= T_CONTROL_FLOW_LABEL)
 
#define is_operator(token_type)   (token_type >= T_OP_1 && token_type <= T_COMMA)
 
#define is_fence(token_type)   (token_type >= T_BLOCK_START && token_type <= T_GROUP_END)
 
#define skip_space_forward(start, end)   while (start is_not end and (start->token_type is T_SPACE or start->token_type is T_COMMENT)) ++start
 
#define skip_space_back(start, end)   while (end is_not start and ((end-1)->token_type is T_SPACE or (end-1)->token_type is T_COMMENT)) --end
 
#define TOKEN1(token)   token_type = token
 
#define TOKEN2(token)   ++token_end; TOKEN1(token)
 
#define TOKEN3(token)   token_end += 2; TOKEN1(token)
 
#define MACROS_DECLARE
 

Typedefs

typedef size_t SrcIndexType
 
typedef uint32_t SrcLenType
 
typedef enum UTF8Error UTF8Error
 
typedef enum UTF8ErrorUTF8Error_p
 
typedef struct Options Options
 
typedef struct OptionsOptions_p
 
typedef enum TokenType mut_TokenType
 
typedef enum TokenType mut_TokenType_p
 
typedef enum TokenTypemut_TokenType_mut_p
 
typedef enum TokenType TokenType
 
typedef enum TokenType *const TokenType_p
 
typedef enum TokenType *const * TokenType_mut_p
 
typedef struct Marker mut_Marker
 
typedef struct Marker mut_Marker_p
 
typedef struct Markermut_Marker_mut_p
 
typedef const struct Marker Marker
 
typedef const struct Marker *const Marker_p
 
typedef const struct Marker *const * Marker_mut_p
 
typedef struct Error mut_Error
 
typedef struct Error mut_Error_p
 
typedef struct Errormut_Error_mut_p
 
typedef const struct Error Error
 
typedef const struct Error *const Error_p
 
typedef const struct Error *const * Error_mut_p
 
typedef struct Marker_array mut_Marker_array
 
typedef struct Marker_array mut_Marker_array_p
 
typedef struct Marker_arraymut_Marker_array_mut_p
 
typedef const struct Marker_array Marker_array
 
typedef const struct Marker_array *const Marker_array_p
 
typedef const struct Marker_array *const * Marker_array_mut_p
 
typedef struct Marker_array_slice mut_Marker_array_slice
 
typedef struct Marker_array_slice mut_Marker_array_slice_p
 
typedef struct Marker_array_slicemut_Marker_array_slice_mut_p
 
typedef const struct Marker_array_slice Marker_array_slice
 
typedef const struct Marker_array_slice *const Marker_array_slice_p
 
typedef const struct Marker_array_slice *const * Marker_array_slice_mut_p
 
typedef struct Marker_array_mut_slice mut_Marker_array_mut_slice
 
typedef struct Marker_array_mut_slice mut_Marker_array_mut_slice_p
 
typedef struct Marker_array_mut_slicemut_Marker_array_mut_slice_mut_p
 
typedef struct Marker_array_mut_slice Marker_array_mut_slice
 
typedef struct Marker_array_mut_slice *const Marker_array_mut_slice_p
 
typedef struct Marker_array_mut_slice *const * Marker_array_mut_slice_mut_p
 
typedef struct TokenType_array mut_TokenType_array
 
typedef struct TokenType_array mut_TokenType_array_p
 
typedef struct TokenType_arraymut_TokenType_array_mut_p
 
typedef const struct TokenType_array TokenType_array
 
typedef const struct TokenType_array *const TokenType_array_p
 
typedef const struct TokenType_array *const * TokenType_array_mut_p
 
typedef struct TokenType_array_slice mut_TokenType_array_slice
 
typedef struct TokenType_array_slice mut_TokenType_array_slice_p
 
typedef struct TokenType_array_slicemut_TokenType_array_slice_mut_p
 
typedef const struct TokenType_array_slice TokenType_array_slice
 
typedef const struct TokenType_array_slice *const TokenType_array_slice_p
 
typedef const struct TokenType_array_slice *const * TokenType_array_slice_mut_p
 
typedef struct TokenType_array_mut_slice mut_TokenType_array_mut_slice
 
typedef struct TokenType_array_mut_slice mut_TokenType_array_mut_slice_p
 
typedef struct TokenType_array_mut_slicemut_TokenType_array_mut_slice_mut_p
 
typedef struct TokenType_array_mut_slice TokenType_array_mut_slice
 
typedef struct TokenType_array_mut_slice *const TokenType_array_mut_slice_p
 
typedef struct TokenType_array_mut_slice *const * TokenType_array_mut_slice_mut_p
 
typedef uint8_t mut_Byte
 
typedef uint8_t *const mut_Byte_p
 
typedef uint8_t *const * mut_Byte_mut_p
 
typedef const uint8_t Byte
 
typedef const uint8_t *const Byte_p
 
typedef const uint8_t *const * Byte_mut_p
 
typedef struct Byte_array mut_Byte_array
 
typedef struct Byte_array mut_Byte_array_p
 
typedef struct Byte_arraymut_Byte_array_mut_p
 
typedef const struct Byte_array Byte_array
 
typedef const struct Byte_array *const Byte_array_p
 
typedef const struct Byte_array *const * Byte_array_mut_p
 
typedef struct Byte_array_slice mut_Byte_array_slice
 
typedef struct Byte_array_slice mut_Byte_array_slice_p
 
typedef struct Byte_array_slicemut_Byte_array_slice_mut_p
 
typedef const struct Byte_array_slice Byte_array_slice
 
typedef const struct Byte_array_slice *const Byte_array_slice_p
 
typedef const struct Byte_array_slice *const * Byte_array_slice_mut_p
 
typedef struct Byte_array_mut_slice mut_Byte_array_mut_slice
 
typedef struct Byte_array_mut_slice mut_Byte_array_mut_slice_p
 
typedef struct Byte_array_mut_slicemut_Byte_array_mut_slice_mut_p
 
typedef struct Byte_array_mut_slice Byte_array_mut_slice
 
typedef struct Byte_array_mut_slice *const Byte_array_mut_slice_p
 
typedef struct Byte_array_mut_slice *const * Byte_array_mut_slice_mut_p
 
typedef FILE * mut_File_p
 
typedef char * mut_FilePath
 
typedef const char * FilePath
 
typedef void(* MacroFunction_p) (mut_Marker_array_p markers, mut_Byte_array_p src)
 
typedef const struct Macro Macro
 
typedef const struct MacroMacro_p
 

Enumerations

enum  UTF8Error {
  UTF8_NO_ERROR , UTF8_ERROR , UTF8_ERROR_OVERLONG , UTF8_ERROR_INTERRUPTED_1 = 0x40 ,
  UTF8_ERROR_INTERRUPTED_2 = 0x80 , UTF8_ERROR_INTERRUPTED_3 = 0xC0
}
 
enum  TokenType {
  T_NONE , T_IDENTIFIER , T_TYPE , T_TYPE_STRUCT ,
  T_TYPE_QUALIFIER , T_TYPE_QUALIFIER_AUTO , T_TYPEDEF , T_CONTROL_FLOW_IF ,
  T_CONTROL_FLOW_LOOP , T_CONTROL_FLOW_SWITCH , T_CONTROL_FLOW_CASE , T_CONTROL_FLOW_BREAK ,
  T_CONTROL_FLOW_CONTINUE , T_CONTROL_FLOW_RETURN , T_CONTROL_FLOW_GOTO , T_CONTROL_FLOW_LABEL ,
  T_NUMBER , T_STRING , T_CHARACTER , T_SPACE ,
  T_COMMENT , T_PREPROCESSOR , T_GENERIC_MACRO , T_BLOCK_START ,
  T_BLOCK_END , T_TUPLE_START , T_TUPLE_END , T_INDEX_START ,
  T_INDEX_END , T_GROUP_START , T_GROUP_END , T_OP_1 ,
  T_OP_2 , T_OP_3 , T_OP_4 , T_OP_5 ,
  T_OP_6 , T_OP_7 , T_OP_8 , T_OP_9 ,
  T_OP_10 , T_OP_11 , T_OP_12 , T_OP_13 ,
  T_OP_14 , T_COMMA , T_SEMICOLON , T_LABEL_COLON ,
  T_BACKSTITCH , T_ELLIPSIS , T_OTHER
}
 

Functions

static void error (const char *const fmt,...)
 
bool utf8_error (UTF8Error err)
 
static const uint8_t * decode_utf8 (const uint8_t *cursor, const uint8_t *end, uint32_t *codepoint, UTF8Error_p err_p)
 
static void eprint (const char *const fmt,...)
 
static void init_Marker_array_slice (mut_Marker_array_slice_p _, Marker_array_p array_p, size_t start, size_t end)
 
static void init_Marker_array_mut_slice (mut_Marker_array_mut_slice_p _, mut_Marker_array_mut_p array_p, size_t start, size_t end)
 
static void destruct_Marker_block (mut_Marker_mut_p cursor, Marker_p end)
 
static void init_Marker_array (mut_Marker_array_p _, size_t initial_capacity)
 
static void init_from_constant_Marker_array (mut_Marker_array_p _, Marker *items, size_t len)
 
static mut_Marker_array new_Marker_array (size_t initial_capacity)
 
static mut_Marker_array_p new_Marker_array_p (size_t initial_capacity)
 
static void destruct_Marker_array (mut_Marker_array_p _)
 
static void free_Marker_array (mut_Marker_array_p _)
 
static mut_Marker_array move_Marker_array (mut_Marker_array_p _)
 
static void ensure_capacity_Marker_array (mut_Marker_array_p _, size_t minimum)
 
static void push_Marker_array (mut_Marker_array_p _, Marker item)
 
static void splice_Marker_array (mut_Marker_array_p _, size_t position, size_t delete, mut_Marker_array_p deleted, Marker_array_slice insert)
 
static void append_Marker_array (mut_Marker_array_p _, Marker_array_slice insert)
 
static void delete_Marker_array (mut_Marker_array_p _, size_t position, size_t delete)
 
static void pop_Marker_array (mut_Marker_array_p _, mut_Marker_p item_p)
 
static Marker_p get_Marker_array (Marker_array_p _, size_t position)
 
static mut_Marker_p get_mut_Marker_array (Marker_array_p _, size_t position)
 
static Marker_p start_of_Marker_array (Marker_array_p _)
 
static Marker_p end_of_Marker_array (Marker_array_p _)
 
static Marker_array_slice bounds_of_Marker_array (Marker_array_p _)
 
static mut_Marker_p start_of_mut_Marker_array (mut_Marker_array_p _)
 
static mut_Marker_p end_of_mut_Marker_array (mut_Marker_array_p _)
 
static mut_Marker_array_slice bounds_of_mut_Marker_array (mut_Marker_array_p _)
 
static size_t index_Marker_array (Marker_array_p _, Marker_p pointer)
 
static void init_TokenType_array_slice (mut_TokenType_array_slice_p _, TokenType_array_p array_p, size_t start, size_t end)
 
static void init_TokenType_array_mut_slice (mut_TokenType_array_mut_slice_p _, mut_TokenType_array_mut_p array_p, size_t start, size_t end)
 
static void destruct_TokenType_block (mut_TokenType_mut_p cursor, TokenType_p end)
 
static void init_TokenType_array (mut_TokenType_array_p _, size_t initial_capacity)
 
static void init_from_constant_TokenType_array (mut_TokenType_array_p _, TokenType *items, size_t len)
 
static mut_TokenType_array new_TokenType_array (size_t initial_capacity)
 
static mut_TokenType_array_p new_TokenType_array_p (size_t initial_capacity)
 
static void destruct_TokenType_array (mut_TokenType_array_p _)
 
static void free_TokenType_array (mut_TokenType_array_p _)
 
static mut_TokenType_array move_TokenType_array (mut_TokenType_array_p _)
 
static void ensure_capacity_TokenType_array (mut_TokenType_array_p _, size_t minimum)
 
static void push_TokenType_array (mut_TokenType_array_p _, TokenType item)
 
static void splice_TokenType_array (mut_TokenType_array_p _, size_t position, size_t delete, mut_TokenType_array_p deleted, TokenType_array_slice insert)
 
static void append_TokenType_array (mut_TokenType_array_p _, TokenType_array_slice insert)
 
static void delete_TokenType_array (mut_TokenType_array_p _, size_t position, size_t delete)
 
static void pop_TokenType_array (mut_TokenType_array_p _, mut_TokenType_p item_p)
 
static TokenType_p get_TokenType_array (TokenType_array_p _, size_t position)
 
static mut_TokenType_p get_mut_TokenType_array (TokenType_array_p _, size_t position)
 
static TokenType_p start_of_TokenType_array (TokenType_array_p _)
 
static TokenType_p end_of_TokenType_array (TokenType_array_p _)
 
static TokenType_array_slice bounds_of_TokenType_array (TokenType_array_p _)
 
static mut_TokenType_p start_of_mut_TokenType_array (mut_TokenType_array_p _)
 
static mut_TokenType_p end_of_mut_TokenType_array (mut_TokenType_array_p _)
 
static mut_TokenType_array_slice bounds_of_mut_TokenType_array (mut_TokenType_array_p _)
 
static size_t index_TokenType_array (TokenType_array_p _, TokenType_p pointer)
 
static void init_Byte_array_slice (mut_Byte_array_slice_p _, Byte_array_p array_p, size_t start, size_t end)
 
static void init_Byte_array_mut_slice (mut_Byte_array_mut_slice_p _, mut_Byte_array_mut_p array_p, size_t start, size_t end)
 
static void destruct_Byte_block (mut_Byte_mut_p cursor, Byte_p end)
 
static void init_Byte_array (mut_Byte_array_p _, size_t initial_capacity)
 
static void init_from_constant_Byte_array (mut_Byte_array_p _, Byte *items, size_t len)
 
static mut_Byte_array new_Byte_array (size_t initial_capacity)
 
static mut_Byte_array_p new_Byte_array_p (size_t initial_capacity)
 
static void destruct_Byte_array (mut_Byte_array_p _)
 
static void free_Byte_array (mut_Byte_array_p _)
 
static mut_Byte_array move_Byte_array (mut_Byte_array_p _)
 
static void ensure_capacity_Byte_array (mut_Byte_array_p _, size_t minimum)
 
static void push_Byte_array (mut_Byte_array_p _, Byte item)
 
static void splice_Byte_array (mut_Byte_array_p _, size_t position, size_t delete, mut_Byte_array_p deleted, Byte_array_slice insert)
 
static void append_Byte_array (mut_Byte_array_p _, Byte_array_slice insert)
 
static void delete_Byte_array (mut_Byte_array_p _, size_t position, size_t delete)
 
static void pop_Byte_array (mut_Byte_array_p _, mut_Byte_p item_p)
 
static Byte_p get_Byte_array (Byte_array_p _, size_t position)
 
static mut_Byte_p get_mut_Byte_array (Byte_array_p _, size_t position)
 
static Byte_p start_of_Byte_array (Byte_array_p _)
 
static Byte_p end_of_Byte_array (Byte_array_p _)
 
static Byte_array_slice bounds_of_Byte_array (Byte_array_p _)
 
static mut_Byte_p start_of_mut_Byte_array (mut_Byte_array_p _)
 
static mut_Byte_p end_of_mut_Byte_array (mut_Byte_array_p _)
 
static mut_Byte_array_slice bounds_of_mut_Byte_array (mut_Byte_array_p _)
 
static size_t index_Byte_array (Byte_array_p _, Byte_p pointer)
 
static void push_str (mut_Byte_array_p _, const char *const str)
 
static void push_fmt (mut_Byte_array_p _, const char *const fmt,...)
 
static const char * as_c_string (mut_Byte_array_p _)
 
static int read_file (mut_Byte_array_p _, FilePath path)
 
static void print_file_error (int err, const char *file_name, Byte_array_p src)
 
static void init_Marker (mut_Marker_p _, Byte_p start, Byte_p end, Byte_array_p src, TokenType token_type)
 
static Byte_p identifier (Byte_p start, Byte_p end)
 
static Byte_p number (Byte_p start, Byte_p end)
 
static Byte_p string (Byte_p start, Byte_p end)
 
static Byte_p character (Byte_p start, Byte_p end)
 
static Byte_p space (Byte_p start, Byte_p end)
 
static Byte_p comment (Byte_p start, Byte_p end)
 
static Byte_p preprocessor (Byte_p start, Byte_p end)
 
static Byte_p other (Byte_p start, Byte_p end)
 
static Byte_array_slice slice_for_marker (Byte_array_p src, Marker_p cursor)
 
static void extract_src (Marker_p start, Marker_p end, Byte_array_p src, mut_Byte_array_p string)
 
static bool src_eq (Marker_p marker, Byte_array_p string, Byte_array_p src)
 
static size_t count_appearances (Byte byte, Marker_p start, Marker_p end, Byte_array_p src)
 
static bool has_byte (Byte byte, Marker_p marker, Byte_array_p src)
 
static Marker_p find_matching_fence (Marker_p cursor, Marker_p end, mut_Error_p err)
 
static Marker_p find_line_start (Marker_p cursor, Marker_p start, mut_Error_p err)
 
static Marker_p find_line_end (Marker_p cursor, Marker_p end, mut_Error_p err)
 
static Marker_p find_block_start (Marker_p cursor, Marker_p start, mut_Error_p err)
 
static Marker_p find_block_end (Marker_p cursor, Marker_p end, mut_Error_p err)
 
static Marker indentation (Marker_array_p markers, Marker_p marker, bool already_at_line_start, Byte_array_p src)
 
static size_t line_number (Byte_array_p src, Marker_array_p markers, Marker_p position)
 
static size_t original_line_number (size_t position, Byte_array_p src)
 
static void indent_eprint (size_t indent)
 
static void tabulate_eprint (size_t skip, size_t tabulator)
 
static Marker new_marker (mut_Byte_array_p src, const char *const text, TokenType token_type)
 
static void print_markers (Marker_array_p markers, Byte_array_p src, const char *prefix, size_t start, size_t end)
 
static void debug_cursor (Marker_p cursor, size_t radius, const char *label, Marker_array_p markers, Byte_array_p src)
 
static void unparse (Marker_array_p markers, Byte_array_p src, size_t original_src_len, char *src_file_name, Options options, FILE *out)
 
static TokenType keyword_or_identifier (Byte_p start, Byte_p end)
 
static Byte_p parse (Byte_array_p src, mut_Marker_array_p markers)
 
static double benchmark (mut_Byte_array_p src_p, Options_p options)
 
int main (int argc, char **argv)
 

Variables

static const size_t error_buffer_size = 256
 
static char error_buffer [256] = {0}
 
static const unsigned char *const TokenType_STRING [1+T_OTHER]
 
static const size_t PADDING_Marker_ARRAY = 0
 
static const size_t PADDING_TokenType_ARRAY = 0
 
static const size_t PADDING_Byte_ARRAY = 8
 
static const char spacing [80]
 
static const size_t markers_tabulator = 20
 
static const size_t right_margin = sizeof(spacing) - 2
 
static Macro macros []
 
static const char *const usage_es
 
static const char *const usage_en
 

Macro Definition Documentation

◆ B

#define B (   string)    ((const unsigned char * const)string)

Binary string, const unsigned char const*.

◆ CEDRO_PRAGMA

#define CEDRO_PRAGMA   "#pragma Cedro 1."

Versions with the same major number are compatible in that they produce semantically equivalent output: there might be differeces in indentation etc. but will be the same after parsing by the compiler.

◆ CEDRO_PRAGMA_LEN

#define CEDRO_PRAGMA_LEN   16

◆ CEDRO_VERSION

#define CEDRO_VERSION   "1.0"

◆ eprintln

#define eprintln (   ...)    eprint(__VA_ARGS__), eprint("\n")

Same as fprintf(stderr, fmt, ...) fputc('\n', stderr) but converting UTF-8 characters to Latin-1 if the LANG environment variable does not contain UTF-8.

◆ in

#define in (   min,
  x,
  max 
)    (x >= min && x <= max)

◆ is

#define is   ==

◆ is_fence

#define is_fence (   token_type)    (token_type >= T_BLOCK_START && token_type <= T_GROUP_END)

◆ is_keyword

#define is_keyword (   token_type)    (token_type >= T_TYPE && token_type <= T_CONTROL_FLOW_LABEL)

◆ is_not

#define is_not   not_eq

◆ is_operator

#define is_operator (   token_type)    (token_type >= T_OP_1 && token_type <= T_COMMA)

◆ LANG

#define LANG (   es,
  en 
)    (strn_eq(getenv("LANG"), "es", 2)? es: en)

◆ MACROS_DECLARE

#define MACROS_DECLARE

◆ mem_eq

#define mem_eq (   a,
  b,
  len 
)    (0 is memcmp(a, b, len))

◆ NDEBUG

#define NDEBUG

◆ precedence

#define precedence (   token_type)    (token_type - T_OP_1)

◆ skip_space_back

#define skip_space_back (   start,
  end 
)    while (end is_not start and ((end-1)->token_type is T_SPACE or (end-1)->token_type is T_COMMENT)) --end

Skip backward all T_SPACE and T_COMMENT markers.

◆ skip_space_forward

#define skip_space_forward (   start,
  end 
)    while (start is_not end and (start->token_type is T_SPACE or start->token_type is T_COMMENT)) ++start

Skip forward all T_SPACE and T_COMMENT markers.

◆ str_eq

#define str_eq (   a,
 
)    (0 is strcmp(a, b))

◆ strn_eq

#define strn_eq (   a,
  b,
  len 
)    (0 is strncmp(a, b, len))

◆ TOKEN1

#define TOKEN1 (   token)    token_type = token

◆ TOKEN2

#define TOKEN2 (   token)    ++token_end; TOKEN1(token)

◆ TOKEN3

#define TOKEN3 (   token)    token_end += 2; TOKEN1(token)

◆ TYPEDEF

#define TYPEDEF (   T,
  TYPE 
)
Value:
typedef TYPE mut_##T, * const mut_##T##_p, * mut_##T##_mut_p; \
typedef const TYPE T, * const T##_p, * T##_mut_p

Defines mutable types mut_〈T〉 and mut_〈T〉_p (pointer), and constant types 〈T〉 and 〈T〉_p (pointer to constant).

You can define similar types for an existing type, for instance uint8_t:

typedef uint8_t mut_Byte, * const mut_Byte_p, * mut_Byte_mut_p;
typedef const uint8_t Byte, * const Byte_p, * Byte_mut_p;
const uint8_t *const * Byte_mut_p
Definition: cedro.c:376
uint8_t *const mut_Byte_p
Definition: cedro.c:376
const uint8_t *const Byte_p
Definition: cedro.c:376
uint8_t mut_Byte
Definition: cedro.c:376
const uint8_t Byte
Definition: cedro.c:376
uint8_t *const * mut_Byte_mut_p
Definition: cedro.c:376

◆ TYPEDEF_STRUCT

#define TYPEDEF_STRUCT (   T,
  TYPE 
)
Value:
typedef struct T TYPE mut_##T, * const mut_##T##_p, * mut_##T##_mut_p; \
typedef const struct T T, * const T##_p, * T##_mut_p

Defines mutable struct types mut_〈T〉 and mut_〈T〉_p (pointer), and constant types 〈T〉 and 〈T〉_p (pointer to constant).

Typedef Documentation

◆ Byte

typedef const uint8_t Byte

◆ Byte_array

typedef const struct Byte_array Byte_array

◆ Byte_array_mut_p

typedef const struct Byte_array * const * Byte_array_mut_p

◆ Byte_array_mut_slice

A slice of an array where the elements are constants. Example:

Byte_mut_array a;
Byte_mut_array_slice s;
init_Byte_array_slice(&s, &a, 3, 10);
assert(&s->start_p == &a->start + 3);
assert(&s->end_p == &a->start + 10);
static void init_Byte_array(mut_Byte_array_p _, size_t initial_capacity)
Definition: cedro.c:379
static void init_Byte_array_slice(mut_Byte_array_slice_p _, Byte_array_p array_p, size_t start, size_t end)
Definition: cedro.c:379


◆ Byte_array_mut_slice_mut_p

◆ Byte_array_mut_slice_p

◆ Byte_array_p

typedef const struct Byte_array * const Byte_array_p

◆ Byte_array_slice

typedef const struct Byte_array_slice Byte_array_slice

◆ Byte_array_slice_mut_p

typedef const struct Byte_array_slice * const * Byte_array_slice_mut_p

◆ Byte_array_slice_p

typedef const struct Byte_array_slice * const Byte_array_slice_p

◆ Byte_mut_p

typedef const uint8_t * const * Byte_mut_p

◆ Byte_p

typedef const uint8_t * const Byte_p

◆ Error

typedef const struct Error Error

◆ Error_mut_p

typedef const struct Error * const * Error_mut_p

◆ Error_p

typedef const struct Error * const Error_p

◆ FilePath

typedef const char* FilePath

◆ Macro

typedef const struct Macro Macro

◆ Macro_p

typedef const struct Macro * Macro_p

◆ MacroFunction_p

typedef void(* MacroFunction_p) (mut_Marker_array_p markers, mut_Byte_array_p src)

◆ Marker

typedef const struct Marker Marker

◆ Marker_array

typedef const struct Marker_array Marker_array

◆ Marker_array_mut_p

typedef const struct Marker_array * const * Marker_array_mut_p

◆ Marker_array_mut_slice

A slice of an array where the elements are constants. Example:

Marker_mut_array a;
Marker_mut_array_slice s;
init_Marker_array_slice(&s, &a, 3, 10);
assert(&s->start_p == &a->start + 3);
assert(&s->end_p == &a->start + 10);
static void init_Marker_array_slice(mut_Marker_array_slice_p _, Marker_array_p array_p, size_t start, size_t end)
Definition: cedro.c:373
static void init_Marker_array(mut_Marker_array_p _, size_t initial_capacity)
Definition: cedro.c:373


◆ Marker_array_mut_slice_mut_p

◆ Marker_array_mut_slice_p

◆ Marker_array_p

typedef const struct Marker_array * const Marker_array_p

◆ Marker_array_slice

typedef const struct Marker_array_slice Marker_array_slice

◆ Marker_array_slice_mut_p

typedef const struct Marker_array_slice * const * Marker_array_slice_mut_p

◆ Marker_array_slice_p

typedef const struct Marker_array_slice * const Marker_array_slice_p

◆ Marker_mut_p

typedef const struct Marker * const * Marker_mut_p

◆ Marker_p

typedef const struct Marker * const Marker_p

◆ mut_Byte

typedef uint8_t mut_Byte

◆ mut_Byte_array

typedef struct Byte_array mut_Byte_array

Add 8 bytes after end of buffer to avoid bounds checking while scanning for tokens. No literal token is longer. The constant PADDING_Byte_ARRAY = 8 defines how many items are physically available after those valid elements.
This can be used to avoid special cases near the end when searching for fixed-length sequences in the array, although you have to set them to 0 or other appropriate value.

◆ mut_Byte_array_mut_p

typedef struct Byte_array * mut_Byte_array_mut_p

◆ mut_Byte_array_mut_slice

A slice of an array where the elements are mutable. Example:

Byte_mut_array a;
Byte_mut_array_slice s;
init_Byte_array_slice(&s, &a, 3, 10);
assert(&s->start_p == &a->start + 3);
assert(&s->end_p == &a->start + 10);


◆ mut_Byte_array_mut_slice_mut_p

◆ mut_Byte_array_mut_slice_p

◆ mut_Byte_array_p

typedef struct Byte_array mut_Byte_array_p

◆ mut_Byte_array_slice

Example:

Byte_array_slice s = { &start, &start + 10 };
Definition: cedro.c:379


◆ mut_Byte_array_slice_mut_p

◆ mut_Byte_array_slice_p

◆ mut_Byte_mut_p

typedef uint8_t * const * mut_Byte_mut_p

◆ mut_Byte_p

typedef uint8_t * const mut_Byte_p

◆ mut_Error

typedef struct Error mut_Error

Error while processing markers.

◆ mut_Error_mut_p

typedef struct Error * mut_Error_mut_p

◆ mut_Error_p

typedef struct Error mut_Error_p

◆ mut_File_p

typedef FILE* mut_File_p

◆ mut_FilePath

typedef char* mut_FilePath

◆ mut_Marker

typedef struct Marker mut_Marker

Marks a C token in the source code.

◆ mut_Marker_array

The constant PADDING_Marker_ARRAY = 0 defines how many items are physically available after those valid elements.
This can be used to avoid special cases near the end when searching for fixed-length sequences in the array, although you have to set them to 0 or other appropriate value.

◆ mut_Marker_array_mut_p

◆ mut_Marker_array_mut_slice

A slice of an array where the elements are mutable. Example:

Marker_mut_array a;
Marker_mut_array_slice s;
init_Marker_array_slice(&s, &a, 3, 10);
assert(&s->start_p == &a->start + 3);
assert(&s->end_p == &a->start + 10);


◆ mut_Marker_array_mut_slice_mut_p

◆ mut_Marker_array_mut_slice_p

◆ mut_Marker_array_p

◆ mut_Marker_array_slice

Example:

Marker_array_slice s = { &start, &start + 10 };
Definition: cedro.c:373


◆ mut_Marker_array_slice_mut_p

◆ mut_Marker_array_slice_p

◆ mut_Marker_mut_p

typedef struct Marker * mut_Marker_mut_p

◆ mut_Marker_p

typedef struct Marker mut_Marker_p

◆ mut_TokenType

typedef enum TokenType mut_TokenType

These token types loosely correspond to those in the C grammar.

Keywords: https://en.cppreference.com/w/c/keyword

Operator precedence levels: https://en.cppreference.com/w/c/language/operator_precedence

◆ mut_TokenType_array

The constant PADDING_TokenType_ARRAY = 0 defines how many items are physically available after those valid elements.
This can be used to avoid special cases near the end when searching for fixed-length sequences in the array, although you have to set them to 0 or other appropriate value.

◆ mut_TokenType_array_mut_p

◆ mut_TokenType_array_mut_slice

A slice of an array where the elements are mutable. Example:

TokenType_mut_array a;
TokenType_mut_array_slice s;
assert(&s->start_p == &a->start + 3);
assert(&s->end_p == &a->start + 10);
static void init_TokenType_array_slice(mut_TokenType_array_slice_p _, TokenType_array_p array_p, size_t start, size_t end)
Definition: cedro.c:374
static void init_TokenType_array(mut_TokenType_array_p _, size_t initial_capacity)
Definition: cedro.c:374


◆ mut_TokenType_array_mut_slice_mut_p

◆ mut_TokenType_array_mut_slice_p

◆ mut_TokenType_array_p

◆ mut_TokenType_array_slice

Example:

TokenType_array_slice s = { &start, &start + 10 };
Definition: cedro.c:374


◆ mut_TokenType_array_slice_mut_p

◆ mut_TokenType_array_slice_p

◆ mut_TokenType_mut_p

◆ mut_TokenType_p

typedef enum TokenType mut_TokenType_p

◆ Options

typedef struct Options Options

Parameters set by command line options.

◆ Options_p

typedef struct Options * Options_p

◆ SrcIndexType

typedef size_t SrcIndexType

◆ SrcLenType

typedef uint32_t SrcLenType

◆ TokenType

typedef enum TokenType TokenType

◆ TokenType_array

typedef const struct TokenType_array TokenType_array

◆ TokenType_array_mut_p

typedef const struct TokenType_array * const * TokenType_array_mut_p

◆ TokenType_array_mut_slice

A slice of an array where the elements are constants. Example:

TokenType_mut_array a;
TokenType_mut_array_slice s;
assert(&s->start_p == &a->start + 3);
assert(&s->end_p == &a->start + 10);


◆ TokenType_array_mut_slice_mut_p

◆ TokenType_array_mut_slice_p

◆ TokenType_array_p

typedef const struct TokenType_array * const TokenType_array_p

◆ TokenType_array_slice

◆ TokenType_array_slice_mut_p

typedef const struct TokenType_array_slice * const * TokenType_array_slice_mut_p

◆ TokenType_array_slice_p

typedef const struct TokenType_array_slice * const TokenType_array_slice_p

◆ TokenType_mut_p

typedef enum TokenType * const * TokenType_mut_p

◆ TokenType_p

typedef enum TokenType * const TokenType_p

◆ UTF8Error

typedef enum UTF8Error UTF8Error

◆ UTF8Error_p

typedef enum UTF8Error * UTF8Error_p

Enumeration Type Documentation

◆ TokenType

enum TokenType

These token types loosely correspond to those in the C grammar.

Keywords: https://en.cppreference.com/w/c/keyword

Operator precedence levels: https://en.cppreference.com/w/c/language/operator_precedence

Enumerator
T_NONE 

No token, used as marker for uninitialized data.

T_IDENTIFIER 

Identifier. See identifier().

T_TYPE 

Type name: char, double, enum, float, int, long, short, union, void. (c99: bool, complex, imaginary)

T_TYPE_STRUCT 

Type name: struct.

T_TYPE_QUALIFIER 

Type qualifier: const, extern, inline, register, signed, static, unsigned, volatile. (c99: restrict)

T_TYPE_QUALIFIER_AUTO 

Type qualifier: auto.

T_TYPEDEF 

Type definition: typedef.

T_CONTROL_FLOW_IF 

Control flow keyword: else, if.

T_CONTROL_FLOW_LOOP 

Control flow keyword: do, for, while.

T_CONTROL_FLOW_SWITCH 

Control flow keyword: switch.

T_CONTROL_FLOW_CASE 

Control flow keyword: case, default.

T_CONTROL_FLOW_BREAK 

Control flow keyword: break.

T_CONTROL_FLOW_CONTINUE 

Control flow keyword: continue.

T_CONTROL_FLOW_RETURN 

Control flow keyword: return.

T_CONTROL_FLOW_GOTO 

Control flow keyword: goto.

T_CONTROL_FLOW_LABEL 

Control flow, label for goto.

T_NUMBER 

Number, either integer or float. See number().

T_STRING 

String including the quotes: "ABC"

T_CHARACTER 

Character including the apostrophes: 'A'

T_SPACE 

Whitespace, a block of SP, HT, LF or CR. See Wikipedia, Basic ASCII control codes

T_COMMENT 

Comment block or line.

T_PREPROCESSOR 

Preprocessor directive.

T_GENERIC_MACRO 

Generic macro.

T_BLOCK_START 

Start of a block: {

T_BLOCK_END 

End of a block: }

T_TUPLE_START 

Start of a tuple: (

T_TUPLE_END 

End of a tuple: )

T_INDEX_START 

Start of an array index: [

T_INDEX_END 

End of an array index: ]

T_GROUP_START 

Invisible grouping of tokens, for instance for operator precedence.

T_GROUP_END 

End invisible grouping of tokens.

T_OP_1 

++ -- () [] . -> (type){list}

T_OP_2 

++ -- + - ! ~ (type) * & sizeof _Alignof

T_OP_3 

* / %

T_OP_4 

+ -

T_OP_5 

<< >>

T_OP_6 

< <= > >=

T_OP_7 

== !=

T_OP_8 

&

T_OP_9 

^

T_OP_10 

|

T_OP_11 

&&

T_OP_12 

||

T_OP_13 

?:

T_OP_14 

= += -= *= /= %= <<= >>= &= ^= |=

T_COMMA 

,

T_SEMICOLON 

End of line: ;

T_LABEL_COLON 

Colon after label: :

T_BACKSTITCH 

Backstitch: @

T_ELLIPSIS 

Ellipsis: ...

T_OTHER 

Other token that is not part of the C grammar.

◆ UTF8Error

enum UTF8Error
Enumerator
UTF8_NO_ERROR 
UTF8_ERROR 
UTF8_ERROR_OVERLONG 
UTF8_ERROR_INTERRUPTED_1 
UTF8_ERROR_INTERRUPTED_2 
UTF8_ERROR_INTERRUPTED_3 

Function Documentation

◆ append_Byte_array()

static void append_Byte_array ( mut_Byte_array_p  _,
Byte_array_slice  insert 
)
static

Append the given insert slice to the array. Same as splice_Byte_array(_, _->len, 0, NULL, insert). The insert slice, must belong to a different array.

◆ append_Marker_array()

static void append_Marker_array ( mut_Marker_array_p  _,
Marker_array_slice  insert 
)
static

Append the given insert slice to the array. Same as splice_Marker_array(_, _->len, 0, NULL, insert). The insert slice, must belong to a different array.

◆ append_TokenType_array()

static void append_TokenType_array ( mut_TokenType_array_p  _,
TokenType_array_slice  insert 
)
static

Append the given insert slice to the array. Same as splice_TokenType_array(_, _->len, 0, NULL, insert). The insert slice, must belong to a different array.

◆ as_c_string()

static const char* as_c_string ( mut_Byte_array_p  _)
static

Make it be a valid C string, by adding a ‘’\0'character after the last valid element, without increasing the.len` value. It first makes sure there is at least one extra byte after the array contents in memory, by increasing the .capacity if needed, and then sets that byte to 0. Returns the pointer _->start which now can be used as a C string as long as you don’t modify it.

◆ benchmark()

static double benchmark ( mut_Byte_array_p  src_p,
Options_p  options 
)
static

Returns the time in seconds, as a double precision floating point value.

◆ bounds_of_Byte_array()

static Byte_array_slice bounds_of_Byte_array ( Byte_array_p  _)
static

Return the slice for the whole array of const objects.

◆ bounds_of_Marker_array()

static Marker_array_slice bounds_of_Marker_array ( Marker_array_p  _)
static

Return the slice for the whole array of const objects.

◆ bounds_of_mut_Byte_array()

static mut_Byte_array_slice bounds_of_mut_Byte_array ( mut_Byte_array_p  _)
static

Return the slice for the whole array of mutable objects.

◆ bounds_of_mut_Marker_array()

static mut_Marker_array_slice bounds_of_mut_Marker_array ( mut_Marker_array_p  _)
static

Return the slice for the whole array of mutable objects.

◆ bounds_of_mut_TokenType_array()

static mut_TokenType_array_slice bounds_of_mut_TokenType_array ( mut_TokenType_array_p  _)
static

Return the slice for the whole array of mutable objects.

◆ bounds_of_TokenType_array()

static TokenType_array_slice bounds_of_TokenType_array ( TokenType_array_p  _)
static

Return the slice for the whole array of const objects.

◆ character()

static Byte_p character ( Byte_p  start,
Byte_p  end 
)
inlinestatic

Match a character literal. Assumes end > start.

◆ comment()

static Byte_p comment ( Byte_p  start,
Byte_p  end 
)
inlinestatic

Match a comment block. Assumes end > start.

◆ count_appearances()

static size_t count_appearances ( Byte  byte,
Marker_p  start,
Marker_p  end,
Byte_array_p  src 
)
inlinestatic

Count appearances of the given byte in a marker.

◆ debug_cursor()

static void debug_cursor ( Marker_p  cursor,
size_t  radius,
const char *  label,
Marker_array_p  markers,
Byte_array_p  src 
)
static

Call print_markers() in an area around the given cursor.

◆ decode_utf8()

static const uint8_t* decode_utf8 ( const uint8_t *  cursor,
const uint8_t *  end,
uint32_t *  codepoint,
UTF8Error_p  err_p 
)
inlinestatic

Decode one Unicode® code point from a UTF-8 byte buffer. Assumes end > cursor.

◆ delete_Byte_array()

static void delete_Byte_array ( mut_Byte_array_p  _,
size_t  position,
size_t  delete 
)
static

Delete delete elements from the array at position. Same as splice_Byte_array(_, position, delete, NULL, ( Byte_array_slice){0}).

◆ delete_Marker_array()

static void delete_Marker_array ( mut_Marker_array_p  _,
size_t  position,
size_t  delete 
)
static

Delete delete elements from the array at position. Same as splice_Marker_array(_, position, delete, NULL, ( Marker_array_slice){0}).

◆ delete_TokenType_array()

static void delete_TokenType_array ( mut_TokenType_array_p  _,
size_t  position,
size_t  delete 
)
static

Delete delete elements from the array at position. Same as splice_TokenType_array(_, position, delete, NULL, ( TokenType_array_slice){0}).

◆ destruct_Byte_array()

static void destruct_Byte_array ( mut_Byte_array_p  _)
static

Release any resources allocated for this struct.
Safe to call also for objects initialized as views over constants with init_from_constant_Byte_array().

◆ destruct_Byte_block()

static void destruct_Byte_block ( mut_Byte_mut_p  cursor,
Byte_p  end 
)
static

◆ destruct_Marker_array()

static void destruct_Marker_array ( mut_Marker_array_p  _)
static

Release any resources allocated for this struct.
Safe to call also for objects initialized as views over constants with init_from_constant_Marker_array().

◆ destruct_Marker_block()

static void destruct_Marker_block ( mut_Marker_mut_p  cursor,
Marker_p  end 
)
static

◆ destruct_TokenType_array()

static void destruct_TokenType_array ( mut_TokenType_array_p  _)
static

Release any resources allocated for this struct.
Safe to call also for objects initialized as views over constants with init_from_constant_TokenType_array().

◆ destruct_TokenType_block()

static void destruct_TokenType_block ( mut_TokenType_mut_p  cursor,
TokenType_p  end 
)
static

◆ end_of_Byte_array()

static Byte_p end_of_Byte_array ( Byte_array_p  _)
static

Return a pointer to the next byte after the last element.

◆ end_of_Marker_array()

static Marker_p end_of_Marker_array ( Marker_array_p  _)
static

Return a pointer to the next byte after the last element.

◆ end_of_mut_Byte_array()

static mut_Byte_p end_of_mut_Byte_array ( mut_Byte_array_p  _)
static

Return a pointer to the next byte after the last element.

◆ end_of_mut_Marker_array()

static mut_Marker_p end_of_mut_Marker_array ( mut_Marker_array_p  _)
static

Return a pointer to the next byte after the last element.

◆ end_of_mut_TokenType_array()

static mut_TokenType_p end_of_mut_TokenType_array ( mut_TokenType_array_p  _)
static

Return a pointer to the next byte after the last element.

◆ end_of_TokenType_array()

static TokenType_p end_of_TokenType_array ( TokenType_array_p  _)
static

Return a pointer to the next byte after the last element.

◆ ensure_capacity_Byte_array()

static void ensure_capacity_Byte_array ( mut_Byte_array_p  _,
size_t  minimum 
)
static

Make sure that the array is ready to hold minimum elements, resizing the array if needed.

◆ ensure_capacity_Marker_array()

static void ensure_capacity_Marker_array ( mut_Marker_array_p  _,
size_t  minimum 
)
static

Make sure that the array is ready to hold minimum elements, resizing the array if needed.

◆ ensure_capacity_TokenType_array()

static void ensure_capacity_TokenType_array ( mut_TokenType_array_p  _,
size_t  minimum 
)
static

Make sure that the array is ready to hold minimum elements, resizing the array if needed.

◆ eprint()

static void eprint ( const char *const  fmt,
  ... 
)
static

Same as fprintf(stderr, fmt, ...) but converting UTF-8 characters to Latin-1 if the LANG environment variable does not contain UTF-8.

◆ error()

static void error ( const char *const  fmt,
  ... 
)
static

◆ extract_src()

static void extract_src ( Marker_p  start,
Marker_p  end,
Byte_array_p  src,
mut_Byte_array_p  string 
)
static

Copy the characters between start and end into the given Byte array, appending them to the end of that Byte array. If you want to replace any previous content, do string.len = 0; before calling this function.

To extract the text for Marker_p m from Byte_p src:

extract_src(m, m + 1, src, &string);
static void destruct_Byte_array(mut_Byte_array_p _)
Definition: cedro.c:379
static void extract_src(Marker_p start, Marker_p end, Byte_array_p src, mut_Byte_array_p string)
Definition: cedro.c:1027
static Byte_p string(Byte_p start, Byte_p end)
Definition: cedro.c:880
Definition: cedro.c:379

If you want string.start to be a zero-terminated C string:

push_Byte_array(&string, '\0');
static void push_Byte_array(mut_Byte_array_p _, Byte item)
Definition: cedro.c:379

or use as_c_string(mut_Byte_array_p _).

Parameters
[in]startmarker pointer.
[in]endmarker pointer.
[in]srcbyte buffer with the source code.
[out]stringByte buffer to receive the bytes copied from the segment.

◆ find_block_end()

static Marker_p find_block_end ( Marker_p  cursor,
Marker_p  end,
mut_Error_p  err 
)
inlinestatic

Find end of block that contains cursor, looking forward no further than right before end.

◆ find_block_start()

static Marker_p find_block_start ( Marker_p  cursor,
Marker_p  start,
mut_Error_p  err 
)
inlinestatic

Find start of block that contains cursor, looking back no further than start.

◆ find_line_end()

static Marker_p find_line_end ( Marker_p  cursor,
Marker_p  end,
mut_Error_p  err 
)
inlinestatic

Find end of line that contains cursor, looking forward no further than right before end.

◆ find_line_start()

static Marker_p find_line_start ( Marker_p  cursor,
Marker_p  start,
mut_Error_p  err 
)
inlinestatic

Find start of line that contains cursor, looking back no further than start.

◆ find_matching_fence()

static Marker_p find_matching_fence ( Marker_p  cursor,
Marker_p  end,
mut_Error_p  err 
)
inlinestatic

starting at cursor, which should point to an opening fence {, [ or (, advance until the corresponding closing fence }, ] or ) is found, then return that address. If the fences are not closed, the return value is ènd and an error message is stored in err.

◆ free_Byte_array()

static void free_Byte_array ( mut_Byte_array_p  _)
static

Delete this heap-allocated struct, and release any resources allocated for it.
Same as destruct_Byte_array(_); free(_);.
Safe to call also for objects initialized as views over constants with init_from_constant_Byte_array().

◆ free_Marker_array()

static void free_Marker_array ( mut_Marker_array_p  _)
static

Delete this heap-allocated struct, and release any resources allocated for it.
Same as destruct_Marker_array(_); free(_);.
Safe to call also for objects initialized as views over constants with init_from_constant_Marker_array().

◆ free_TokenType_array()

static void free_TokenType_array ( mut_TokenType_array_p  _)
static

Delete this heap-allocated struct, and release any resources allocated for it.
Same as destruct_TokenType_array(_); free(_);.
Safe to call also for objects initialized as views over constants with init_from_constant_TokenType_array().

◆ get_Byte_array()

static Byte_p get_Byte_array ( Byte_array_p  _,
size_t  position 
)
static

Return a pointer to the element at position. Panics if the index is out of range.

◆ get_Marker_array()

static Marker_p get_Marker_array ( Marker_array_p  _,
size_t  position 
)
static

Return a pointer to the element at position. Panics if the index is out of range.

◆ get_mut_Byte_array()

static mut_Byte_p get_mut_Byte_array ( Byte_array_p  _,
size_t  position 
)
static

Return a mutable pointer to the element at position. Panics if the index is out of range.

◆ get_mut_Marker_array()

static mut_Marker_p get_mut_Marker_array ( Marker_array_p  _,
size_t  position 
)
static

Return a mutable pointer to the element at position. Panics if the index is out of range.

◆ get_mut_TokenType_array()

static mut_TokenType_p get_mut_TokenType_array ( TokenType_array_p  _,
size_t  position 
)
static

Return a mutable pointer to the element at position. Panics if the index is out of range.

◆ get_TokenType_array()

static TokenType_p get_TokenType_array ( TokenType_array_p  _,
size_t  position 
)
static

Return a pointer to the element at position. Panics if the index is out of range.

◆ has_byte()

static bool has_byte ( Byte  byte,
Marker_p  marker,
Byte_array_p  src 
)
inlinestatic

Check whether a given byte appears in a marker. It is faster than count_appearances(byte, marker, marker+1, src) != 0.

◆ identifier()

static Byte_p identifier ( Byte_p  start,
Byte_p  end 
)
inlinestatic

Match an identifier. Assumes end > start.

◆ indent_eprint()

static void indent_eprint ( size_t  indent)
static

Indent by the given number of spaces, for the next eprint() or fprintf(stder, …).

◆ indentation()

static Marker indentation ( Marker_array_p  markers,
Marker_p  marker,
bool  already_at_line_start,
Byte_array_p  src 
)
static

Extract the indentation of the line for the character at index, including the preceding LF character if it exists.

◆ index_Byte_array()

static size_t index_Byte_array ( Byte_array_p  _,
Byte_p  pointer 
)
static

Return the index for the given pointer.

◆ index_Marker_array()

static size_t index_Marker_array ( Marker_array_p  _,
Marker_p  pointer 
)
static

Return the index for the given pointer.

◆ index_TokenType_array()

static size_t index_TokenType_array ( TokenType_array_p  _,
TokenType_p  pointer 
)
static

Return the index for the given pointer.

◆ init_Byte_array()

static void init_Byte_array ( mut_Byte_array_p  _,
size_t  initial_capacity 
)
static

Initialize the array at the given pointer.
For local variables, use it like this:

init_Byte_array(&things, 100); ///< We expect around 100 items.
{...}
destruct_Byte_array(&things);


◆ init_Byte_array_mut_slice()

static void init_Byte_array_mut_slice ( mut_Byte_array_mut_slice_p  _,
mut_Byte_array_mut_p  array_p,
size_t  start,
size_t  end 
)
static

Initialize the slice to point at (*array_p)[start...end]. end can be 0, in which case the slice extends to the end of array_p.

◆ init_Byte_array_slice()

static void init_Byte_array_slice ( mut_Byte_array_slice_p  _,
Byte_array_p  array_p,
size_t  start,
size_t  end 
)
static

Initialize the slice to point at (*array_p)[start...end]. end can be 0, in which case the slice extends to the end of array_p.

◆ init_from_constant_Byte_array()

static void init_from_constant_Byte_array ( mut_Byte_array_p  _,
Byte items,
size_t  len 
)
static

Initialize the array at the given pointer, as a view into a constant C array.
Can be used for copy-on-write strings:

mut_char_array text;
init_from_constant_char_array(&text, "abce", 4);
push_char_array(&text, 'f');
{...}
destruct_char_array(&text);


◆ init_from_constant_Marker_array()

static void init_from_constant_Marker_array ( mut_Marker_array_p  _,
Marker items,
size_t  len 
)
static

Initialize the array at the given pointer, as a view into a constant C array.
Can be used for copy-on-write strings:

mut_char_array text;
init_from_constant_char_array(&text, "abce", 4);
push_char_array(&text, 'f');
{...}
destruct_char_array(&text);


◆ init_from_constant_TokenType_array()

static void init_from_constant_TokenType_array ( mut_TokenType_array_p  _,
TokenType items,
size_t  len 
)
static

Initialize the array at the given pointer, as a view into a constant C array.
Can be used for copy-on-write strings:

mut_char_array text;
init_from_constant_char_array(&text, "abce", 4);
push_char_array(&text, 'f');
{...}
destruct_char_array(&text);


◆ init_Marker()

static void init_Marker ( mut_Marker_p  _,
Byte_p  start,
Byte_p  end,
Byte_array_p  src,
TokenType  token_type 
)
static

Initialize a marker with the given values.

◆ init_Marker_array()

static void init_Marker_array ( mut_Marker_array_p  _,
size_t  initial_capacity 
)
static

Initialize the array at the given pointer.
For local variables, use it like this:

init_Marker_array(&things, 100); ///< We expect around 100 items.
{...}
destruct_Marker_array(&things);
Definition: cedro.c:373


◆ init_Marker_array_mut_slice()

static void init_Marker_array_mut_slice ( mut_Marker_array_mut_slice_p  _,
mut_Marker_array_mut_p  array_p,
size_t  start,
size_t  end 
)
static

Initialize the slice to point at (*array_p)[start...end]. end can be 0, in which case the slice extends to the end of array_p.

◆ init_Marker_array_slice()

static void init_Marker_array_slice ( mut_Marker_array_slice_p  _,
Marker_array_p  array_p,
size_t  start,
size_t  end 
)
static

Initialize the slice to point at (*array_p)[start...end]. end can be 0, in which case the slice extends to the end of array_p.

◆ init_TokenType_array()

static void init_TokenType_array ( mut_TokenType_array_p  _,
size_t  initial_capacity 
)
static

Initialize the array at the given pointer.
For local variables, use it like this:

init_TokenType_array(&things, 100); ///< We expect around 100 items.
{...}
destruct_TokenType_array(&things);
Definition: cedro.c:374


◆ init_TokenType_array_mut_slice()

static void init_TokenType_array_mut_slice ( mut_TokenType_array_mut_slice_p  _,
mut_TokenType_array_mut_p  array_p,
size_t  start,
size_t  end 
)
static

Initialize the slice to point at (*array_p)[start...end]. end can be 0, in which case the slice extends to the end of array_p.

◆ init_TokenType_array_slice()

static void init_TokenType_array_slice ( mut_TokenType_array_slice_p  _,
TokenType_array_p  array_p,
size_t  start,
size_t  end 
)
static

Initialize the slice to point at (*array_p)[start...end]. end can be 0, in which case the slice extends to the end of array_p.

◆ keyword_or_identifier()

static TokenType keyword_or_identifier ( Byte_p  start,
Byte_p  end 
)
inlinestatic

Match a keyword or identifier.

Parameters
[in]startof source code segment to search in.
[in]endof source code segment.

See enum TokenType for a list of keywords.

◆ line_number()

static size_t line_number ( Byte_array_p  src,
Marker_array_p  markers,
Marker_p  position 
)
static

Compute the line number in the current state of the file.

◆ main()

int main ( int  argc,
char **  argv 
)

◆ move_Byte_array()

static mut_Byte_array move_Byte_array ( mut_Byte_array_p  _)
static

Transfer ownership of any resources allocated for this struct. This just indicates that the caller is no longer responsible for releasing those resources.
Example:

store_in_another_object(&obj, move_Byte_array(&a));
/* No need to destruct a here. It is now obj’s problem. */
// However, it is still safe to call destruct_Byte_array():
destruct_Byte_array(&a); // No effect since we transferred it.
static mut_Byte_array move_Byte_array(mut_Byte_array_p _)
Definition: cedro.c:379
#define is
Definition: cedro.c:34


◆ move_Marker_array()

static mut_Marker_array move_Marker_array ( mut_Marker_array_p  _)
static

Transfer ownership of any resources allocated for this struct. This just indicates that the caller is no longer responsible for releasing those resources.
Example:

store_in_another_object(&obj, move_Marker_array(&a));
/* No need to destruct a here. It is now obj’s problem. */
// However, it is still safe to call destruct_Marker_array():
destruct_Marker_array(&a); // No effect since we transferred it.
static mut_Marker_array move_Marker_array(mut_Marker_array_p _)
Definition: cedro.c:373
static void destruct_Marker_array(mut_Marker_array_p _)
Definition: cedro.c:373


◆ move_TokenType_array()

static mut_TokenType_array move_TokenType_array ( mut_TokenType_array_p  _)
static

Transfer ownership of any resources allocated for this struct. This just indicates that the caller is no longer responsible for releasing those resources.
Example:

store_in_another_object(&obj, move_TokenType_array(&a));
/* No need to destruct a here. It is now obj’s problem. */
// However, it is still safe to call destruct_TokenType_array():
destruct_TokenType_array(&a); // No effect since we transferred it.
static mut_TokenType_array move_TokenType_array(mut_TokenType_array_p _)
Definition: cedro.c:374
static void destruct_TokenType_array(mut_TokenType_array_p _)
Definition: cedro.c:374


◆ new_Byte_array()

static mut_Byte_array new_Byte_array ( size_t  initial_capacity)
static

Heap-allocate and initialize a mut_Byte_array.

◆ new_Byte_array_p()

static mut_Byte_array_p new_Byte_array_p ( size_t  initial_capacity)
static

Heap-allocate and initialize a mut_Byte_array.

◆ new_marker()

static Marker new_marker ( mut_Byte_array_p  src,
const char *const  text,
TokenType  token_type 
)
static

Build a new marker for the given string, pointing to its first appearance in src. If not found, append the text to src and return a marker poiting there.

◆ new_Marker_array()

static mut_Marker_array new_Marker_array ( size_t  initial_capacity)
static

Heap-allocate and initialize a mut_Marker_array.

◆ new_Marker_array_p()

static mut_Marker_array_p new_Marker_array_p ( size_t  initial_capacity)
static

Heap-allocate and initialize a mut_Marker_array.

◆ new_TokenType_array()

static mut_TokenType_array new_TokenType_array ( size_t  initial_capacity)
static

Heap-allocate and initialize a mut_TokenType_array.

◆ new_TokenType_array_p()

static mut_TokenType_array_p new_TokenType_array_p ( size_t  initial_capacity)
static

Heap-allocate and initialize a mut_TokenType_array.

◆ number()

static Byte_p number ( Byte_p  start,
Byte_p  end 
)
inlinestatic

Match a number. This matches invalid numbers like 3.4.6, 09, and 3e23.48.34e+11. See ISO/IEC 9899:TC3 6.4.8 “Preprocessing numbers”. Rejecting that is left to the compiler. Assumes end > start.

◆ original_line_number()

static size_t original_line_number ( size_t  position,
Byte_array_p  src 
)
static

Compute the line number in the original file.

◆ other()

static Byte_p other ( Byte_p  start,
Byte_p  end 
)
inlinestatic

Fallback match, just read one UTF-8 Unicode® Code Point as one token of type T_OTHER. Assumes end > start.

◆ parse()

static Byte_p parse ( Byte_array_p  src,
mut_Marker_array_p  markers 
)
static

Parse the given source code into the markers array, appending the new markers to whatever was already there.

The file must contain #pragma Cedro x.y with x as the major and y as the minor revision. Everything up to that marker is output verbatim without any processing, so standard C files are by default not modified.

Remember to empty the markers array before calling this function if you are re-parsing from scratch.

◆ pop_Byte_array()

static void pop_Byte_array ( mut_Byte_array_p  _,
mut_Byte_p  item_p 
)
static

Remove the element at the end/top of the array, copying its bits into *item_p unless item_p is 0, in which case destruct_Byte_block() is called on those elements.

◆ pop_Marker_array()

static void pop_Marker_array ( mut_Marker_array_p  _,
mut_Marker_p  item_p 
)
static

Remove the element at the end/top of the array, copying its bits into *item_p unless item_p is 0, in which case destruct_Marker_block() is called on those elements.

◆ pop_TokenType_array()

static void pop_TokenType_array ( mut_TokenType_array_p  _,
mut_TokenType_p  item_p 
)
static

Remove the element at the end/top of the array, copying its bits into *item_p unless item_p is 0, in which case destruct_TokenType_block() is called on those elements.

◆ preprocessor()

static Byte_p preprocessor ( Byte_p  start,
Byte_p  end 
)
inlinestatic

Match a pre-processor directive. Assumes end > start.

◆ print_file_error()

static void print_file_error ( int  err,
const char *  file_name,
Byte_array_p  src 
)
static

Print an error produced when reading a file.

◆ print_markers()

static void print_markers ( Marker_array_p  markers,
Byte_array_p  src,
const char *  prefix,
size_t  start,
size_t  end 
)
static

Print a human-legible dump of the markers array to stderr. Ignores the options about showing spaces/comments: it is meant as a raw display of the markers array.

Parameters
[in]markersparsed program.
[in]srcoriginal source code.
[in]prefixstring to be added at the beginning of the line.
[in]startindex to start with.
[in]endindex to end with: if 0, use the end of the array.

◆ push_Byte_array()

static void push_Byte_array ( mut_Byte_array_p  _,
Byte  item 
)
static

Push a bit copy of the element on the end/top of the array, resizing the array if needed.

◆ push_fmt()

static void push_fmt ( mut_Byte_array_p  _,
const char *const  fmt,
  ... 
)
static

Append a formatted C string to the end of the given buffer. It’s the same as printf(...), only the result is stored instead of printed to stdout.

◆ push_Marker_array()

static void push_Marker_array ( mut_Marker_array_p  _,
Marker  item 
)
static

Push a bit copy of the element on the end/top of the array, resizing the array if needed.

◆ push_str()

static void push_str ( mut_Byte_array_p  _,
const char *const  str 
)
static

Append the C string bytes to the end of the given buffer.

◆ push_TokenType_array()

static void push_TokenType_array ( mut_TokenType_array_p  _,
TokenType  item 
)
static

Push a bit copy of the element on the end/top of the array, resizing the array if needed.

◆ read_file()

static int read_file ( mut_Byte_array_p  _,
FilePath  path 
)
static

Read a file into the given buffer. Returns error code, 0 if it succeeds.

◆ slice_for_marker()

static Byte_array_slice slice_for_marker ( Byte_array_p  src,
Marker_p  cursor 
)
static

Get new slice for the given marker.

◆ space()

static Byte_p space ( Byte_p  start,
Byte_p  end 
)
inlinestatic

Match whitespace: one or more space, TAB, CR, or NL characters. Assumes end > start.

◆ splice_Byte_array()

static void splice_Byte_array ( mut_Byte_array_p  _,
size_t  position,
size_t  delete,
mut_Byte_array_p  deleted,
Byte_array_slice  insert 
)
static

Splice the given insert slice in place of the removed elements, resizing the array if needed. Starting at position, delete elements are deleted and the elements in the insert slice are inserted there as bit copies. If deleted is not NULL, the deleted elements are not destroyed but copied to that array. The insert slice must belong to a different array or be empty.

◆ splice_Marker_array()

static void splice_Marker_array ( mut_Marker_array_p  _,
size_t  position,
size_t  delete,
mut_Marker_array_p  deleted,
Marker_array_slice  insert 
)
static

Splice the given insert slice in place of the removed elements, resizing the array if needed. Starting at position, delete elements are deleted and the elements in the insert slice are inserted there as bit copies. If deleted is not NULL, the deleted elements are not destroyed but copied to that array. The insert slice must belong to a different array or be empty.

◆ splice_TokenType_array()

static void splice_TokenType_array ( mut_TokenType_array_p  _,
size_t  position,
size_t  delete,
mut_TokenType_array_p  deleted,
TokenType_array_slice  insert 
)
static

Splice the given insert slice in place of the removed elements, resizing the array if needed. Starting at position, delete elements are deleted and the elements in the insert slice are inserted there as bit copies. If deleted is not NULL, the deleted elements are not destroyed but copied to that array. The insert slice must belong to a different array or be empty.

◆ src_eq()

static bool src_eq ( Marker_p  marker,
Byte_array_p  string,
Byte_array_p  src 
)
inlinestatic

Check whether the text in a marker is the same as the given string.

◆ start_of_Byte_array()

static Byte_p start_of_Byte_array ( Byte_array_p  _)
static

Return a pointer to the start of the array (same as _->start)

◆ start_of_Marker_array()

static Marker_p start_of_Marker_array ( Marker_array_p  _)
static

Return a pointer to the start of the array (same as _->start)

◆ start_of_mut_Byte_array()

static mut_Byte_p start_of_mut_Byte_array ( mut_Byte_array_p  _)
static

Return a pointer to the start of the array (same as _->start)

◆ start_of_mut_Marker_array()

static mut_Marker_p start_of_mut_Marker_array ( mut_Marker_array_p  _)
static

Return a pointer to the start of the array (same as _->start)

◆ start_of_mut_TokenType_array()

static mut_TokenType_p start_of_mut_TokenType_array ( mut_TokenType_array_p  _)
static

Return a pointer to the start of the array (same as _->start)

◆ start_of_TokenType_array()

static TokenType_p start_of_TokenType_array ( TokenType_array_p  _)
static

Return a pointer to the start of the array (same as _->start)

◆ string()

static Byte_p string ( Byte_p  start,
Byte_p  end 
)
inlinestatic

Match a string literal. Assumes end > start.

◆ tabulate_eprint()

static void tabulate_eprint ( size_t  skip,
size_t  tabulator 
)
static

Tabulate to the given number of spaces, for the next eprint() or fprintf(stder, …).

◆ unparse()

static void unparse ( Marker_array_p  markers,
Byte_array_p  src,
size_t  original_src_len,
char *  src_file_name,
Options  options,
FILE *  out 
)
static

Format the markers back into source code form.

Parameters
[in]markerstokens for the current form of the program.
[in]srcoriginal source code, with any new tokens appended.
[in]original_src_lenoriginal source code length.
[in]src_file_namefile name corresponding to src.
[in]optionsformatting options.
[in]outFILE pointer where the source code will be written.

◆ utf8_error()

bool utf8_error ( UTF8Error  err)

Variable Documentation

◆ error_buffer

char error_buffer[256] = {0}
static

◆ error_buffer_size

const size_t error_buffer_size = 256
static

◆ macros

Macro macros[]
static
Initial value:
= {
{ NULL, NULL }
}

◆ markers_tabulator

const size_t markers_tabulator = 20
static

Tabulator position when printing markers in print_markers().

◆ PADDING_Byte_ARRAY

const size_t PADDING_Byte_ARRAY = 8
static

◆ PADDING_Marker_ARRAY

const size_t PADDING_Marker_ARRAY = 0
static

◆ PADDING_TokenType_ARRAY

const size_t PADDING_TokenType_ARRAY = 0
static

◆ right_margin

const size_t right_margin = sizeof(spacing) - 2
static

Right margin position for the newline escapes in block macros.

◆ spacing

const char spacing[80]
static
Initial value:
=
" "
" "

ISO/IEC 9899:TC3 WG14/N1256 §6.7.8 page 126: “14 An array of character type may be initialized by a character string literal, optionally enclosed in braces. Successive characters of the character string literal (including the terminating null character if there is room or if the array is of unknown size) initialize the elements of the array.” http://www.open-std.org/jtc1/sc22/WG14/www/docs/n1256.pdf#138

◆ TokenType_STRING

const unsigned char* const TokenType_STRING[1+T_OTHER]
static
Initial value:
= {
B("NONE"),
B("Identifier"),
B("Type"), B("Type struct"), B("Type qualifier"), B("Type qualifier auto"),
B("Type definition"),
B("Control flow conditional"),
B("Control flow loop"),
B("Control flow switch"), B("Control flow case"),
B("Control flow break"), B("Control flow continue"), B("Control flow return"),
B("Control flow goto"), B("Control flow label"),
B("Number"), B("String"), B("Character"),
B("Space"), B("Comment"),
B("Preprocessor"), B("Generic macro"),
B("Block start"), B("Block end"), B("Tuple start"), B("Tuple end"),
B("Index start"), B("Index end"),
B("Group start"), B("Group end"),
B("Op 1"), B("Op 2"), B("Op 3"), B("Op 4"), B("Op 5"), B("Op 6"),
B("Op 7"), B("Op 8"), B("Op 9"), B("Op 10"), B("Op 11"), B("Op 12"),
B("Op 13"), B("Op 14"),
B("Comma (op 15)"), B("Semicolon"), B("Colon after label"),
B("Backstitch"),
B("Ellipsis"),
B("OTHER")
}
#define B(string)
Definition: cedro.c:254

◆ usage_en

const char* const usage_en
static
Initial value:
=
"Usage: cedro [options] file.c [file2.c … ]\n"
" The result goes to stdout, can be used without an intermediate file like this:\n"
" cedro file.c | cc -x c - -o file\n"
" It is what the cedrocc program does:\n"
" cedrocc -o file file.c\n"
" With cedrocc, the following options are the defaults:\n"
" --discard-comments --insert-line-directives\n"
"\n"
" --apply-macros Apply the macros: backstitch, defer, etc. (default)\n"
" --escape-ucn Escape non-ASCII in identifiers as UCN.\n"
" --no-apply-macros Does not apply the macros.\n"
" --no-escape-ucn Does not escape non-ASCII in identifiers. (default)\n"
" --discard-comments Discards the comments.\n"
" --discard-space Discards all whitespace.\n"
" --no-discard-comments Does not discard comments. (default)\n"
" --no-discard-space Does not discard whitespace. (default)\n"
" --insert-line-directives Insert #line directives.\n"
" --no-insert-line-directives Does not insert #line directives."
" (default)\n"
"\n"
" --print-markers Prints the markers.\n"
" --no-print-markers Does not print the markers. (default)\n"
" --enable-core-dump Enable core dump on crash.\n"
" --no-enable-core-dump Does not enable core dump on crash. (default)\n"
" --benchmark Run a performance benchmark.\n"
" --version Show version: " CEDRO_VERSION "\n"
" The corresponding “pragma” is: #pragma Cedro "
#define CEDRO_VERSION
Definition: cedro.c:46

◆ usage_es

const char* const usage_es
static
Initial value:
=
"Uso: cedro [opciones] fichero.c [fichero2.c … ]\n"
" El resultado va a stdout, puede usarse sin fichero intermedio así:\n"
" cedro fichero.c | cc -x c - -o fichero\n"
" Es lo que hace el programa cedrocc:\n"
" cedrocc -o fichero fichero.c\n"
" Con cedrocc, las siguientes opciones son implícitas:\n"
" --discard-comments --insert-line-directives\n"
"\n"
" --apply-macros Aplica las macros: pespunte, diferido, etc. (implícito)\n"
" --escape-ucn Encapsula los caracteres no-ASCII en identificadores.\n"
" --no-apply-macros No aplica las macros.\n"
" --no-escape-ucn No encapsula caracteres en identificadores. (implícito)\n"
" --discard-comments Descarta los comentarios.\n"
" --discard-space Descarta los espacios en blanco.\n"
" --no-discard-comments No descarta los comentarios. (implícito)\n"
" --no-discard-space No descarta los espacios. (implícito)\n"
" --insert-line-directives Inserta directivas #line.\n"
" --no-insert-line-directives No inserta directivas #line. (implícito)\n"
"\n"
" --print-markers Imprime los marcadores.\n"
" --no-print-markers No imprime los marcadores. (implícito)\n"
" --enable-core-dump Activa el volcado de memoria al estrellarse.\n"
" --no-enable-core-dump No activa el volcado de memoria al estrellarse."
" (implícito)\n"
" --benchmark Realiza una medición de rendimiento.\n"
" --version Muestra la versión: " CEDRO_VERSION "\n"
" El «pragma» correspondiente es: #pragma Cedro "