wip
This commit is contained in:
parent
cdb6294f1f
commit
4ffdea07bb
@ -1,5 +1,7 @@
|
||||
#include "<TBD>.h"
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
/**************************************************************************
|
||||
* User code blocks
|
||||
@ -640,26 +642,53 @@ static immutable parser_state_t[] parser_state_table = [
|
||||
<% end %>
|
||||
];
|
||||
|
||||
/* state_values linked list functionality */
|
||||
|
||||
typedef struct state_values_list_entry_s
|
||||
{
|
||||
/** State value object. */
|
||||
state_value_t state_value;
|
||||
|
||||
/** Linked list previous entry. */
|
||||
struct state_values_list_entry_s * prev;
|
||||
|
||||
/** Linked list next entry. */
|
||||
struct state_values_list_entry_s * next;
|
||||
} state_values_list_entry_t;
|
||||
/* state_values stack functionality */
|
||||
|
||||
/** state_values stack type. */
|
||||
typedef struct
|
||||
{
|
||||
size_t length;
|
||||
state_values_list_entry_t * first;
|
||||
state_values_list_entry_t * last;
|
||||
} state_values_list_t;
|
||||
size_t capacity;
|
||||
state_value_t * entries;
|
||||
} state_values_stack_t;
|
||||
|
||||
/**
|
||||
* Initialize state_values stack structure.
|
||||
*
|
||||
* @param stack
|
||||
* state_values stack structure.
|
||||
*/
|
||||
void state_values_stack_init(state_values_stack_t * stack)
|
||||
{
|
||||
const size_t initial_capacity = 10u;
|
||||
stack->length = 0u;
|
||||
stack->capacity = initial_capacity;
|
||||
stack->entries = (state_value_t *)malloc(initial_capacity * sizeof(state_value_t));
|
||||
}
|
||||
|
||||
/**
|
||||
* Push a new state_value to the state_values stack.
|
||||
*
|
||||
* @param stack
|
||||
* state_values stack structure.
|
||||
*/
|
||||
void state_values_stack_push(state_values_stack_t * stack)
|
||||
{
|
||||
size_t const current_capacity = stack->capacity;
|
||||
size_t const current_length = stack->length;
|
||||
if (current_length >= current_capacity)
|
||||
{
|
||||
size_t const new_capacity = current_capacity * 2u;
|
||||
state_value_t * new_entries = malloc(new_capacity * sizeof(state_value_t));
|
||||
memcpy(new_entries, stack->entries, current_length * sizeof(state_value_t);
|
||||
free(stack->entries);
|
||||
stack->capacity = new_capacity;
|
||||
stack->entries = new_entries;
|
||||
}
|
||||
memset(&stack->entries[current_length], 0, sizeof(state_value_t));
|
||||
stack->length = current_length + 1u;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute user code associated with a parser rule.
|
||||
*
|
||||
|
Loading…
x
Reference in New Issue
Block a user