Added and integrated own memory copy, set and zero-out functions
This commit is contained in:
parent
cf124ffcdc
commit
dc13ca8bfa
|
@ -41,4 +41,10 @@ bool_t pac_rune_is_digit (rune_t rune);
|
||||||
bool_t pac_rune_is_blank (rune_t rune);
|
bool_t pac_rune_is_blank (rune_t rune);
|
||||||
bool_t pac_rune_is_sign (rune_t rune);
|
bool_t pac_rune_is_sign (rune_t rune);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void pac_memory_copy (void *destination, void *source, usz_t length);
|
||||||
|
void pac_memory_fill (void *region, usz_t len_region, u8_t byte);
|
||||||
|
void pac_memory_zero (void *region, usz_t len_region);
|
||||||
|
|
||||||
#endif // Include Guard (TN_UTIL_TYPES_H)
|
#endif // Include Guard (TN_UTIL_TYPES_H)
|
|
@ -37,7 +37,7 @@ i32_t pac_grow_reference(pac_tlist_s *tlist, pac_ast_reference_s *reference)
|
||||||
|
|
||||||
reference->len_name = len_name;
|
reference->len_name = len_name;
|
||||||
reference->name = malloc(len_name+1);
|
reference->name = malloc(len_name+1);
|
||||||
memcpy(reference->name, name, len_name);
|
pac_memory_copy(reference->name, name, len_name);
|
||||||
reference->name[len_name] = 0x00;
|
reference->name[len_name] = 0x00;
|
||||||
|
|
||||||
return 3;
|
return 3;
|
||||||
|
@ -46,13 +46,13 @@ i32_t pac_grow_reference(pac_tlist_s *tlist, pac_ast_reference_s *reference)
|
||||||
i32_t pac_grow_item(pac_tlist_s *tlist, pac_ast_item_s *item)
|
i32_t pac_grow_item(pac_tlist_s *tlist, pac_ast_item_s *item)
|
||||||
{
|
{
|
||||||
item->type = PAC_AST_ITEM_INVALID;
|
item->type = PAC_AST_ITEM_INVALID;
|
||||||
memset(item, 0x00, sizeof(pac_ast_item_s));
|
pac_memory_zero(item, sizeof(pac_ast_item_s));
|
||||||
if(CURRENT.type == PAC_TOKEN_LIT_STRING)
|
if(CURRENT.type == PAC_TOKEN_LIT_STRING)
|
||||||
{
|
{
|
||||||
item->type = PAC_AST_ITEM_LITERAL;
|
item->type = PAC_AST_ITEM_LITERAL;
|
||||||
item->data.literal.length = CURRENT.length;
|
item->data.literal.length = CURRENT.length;
|
||||||
item->data.literal.string = malloc(item->data.literal.length + 1);
|
item->data.literal.string = malloc(item->data.literal.length + 1);
|
||||||
memcpy(item->data.literal.string, CURRENT_STRING, CURRENT.length);
|
pac_memory_copy(item->data.literal.string, CURRENT_STRING, CURRENT.length);
|
||||||
item->data.literal.string[item->data.literal.length] = 0x00;
|
item->data.literal.string[item->data.literal.length] = 0x00;
|
||||||
SKIP_TOKEN;
|
SKIP_TOKEN;
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -86,7 +86,7 @@ i32_t pac_grow_variant(pac_tlist_s *tlist, pac_ast_variant_s *variant)
|
||||||
{
|
{
|
||||||
usz_t start_index = tlist->cursor;
|
usz_t start_index = tlist->cursor;
|
||||||
|
|
||||||
memset(variant, 0x00, sizeof(pac_ast_variant_s));
|
pac_memory_zero(variant, sizeof(pac_ast_variant_s));
|
||||||
|
|
||||||
usz_t items_capacity = 8;
|
usz_t items_capacity = 8;
|
||||||
variant->items = calloc(sizeof(pac_ast_item_s), items_capacity);
|
variant->items = calloc(sizeof(pac_ast_item_s), items_capacity);
|
||||||
|
@ -119,7 +119,7 @@ i32_t pac_grow_variant(pac_tlist_s *tlist, pac_ast_variant_s *variant)
|
||||||
|
|
||||||
i32_t pac_grow_rule(pac_tlist_s *tlist, pac_ast_rule_s *rule)
|
i32_t pac_grow_rule(pac_tlist_s *tlist, pac_ast_rule_s *rule)
|
||||||
{
|
{
|
||||||
memset(rule, 0x00, sizeof(pac_ast_rule_s));
|
pac_memory_zero(rule, sizeof(pac_ast_rule_s));
|
||||||
|
|
||||||
// Parse the header
|
// Parse the header
|
||||||
|
|
||||||
|
@ -155,7 +155,7 @@ i32_t pac_grow_rule(pac_tlist_s *tlist, pac_ast_rule_s *rule)
|
||||||
// Parse all variants
|
// Parse all variants
|
||||||
|
|
||||||
rule->name = malloc(len_name + 1);
|
rule->name = malloc(len_name + 1);
|
||||||
memcpy(rule->name, &tlist->source[name_start], len_name);
|
pac_memory_copy(rule->name, &tlist->source[name_start], len_name);
|
||||||
rule->name[len_name] = 0;
|
rule->name[len_name] = 0;
|
||||||
|
|
||||||
usz_t variants_capacity = 4;
|
usz_t variants_capacity = 4;
|
||||||
|
|
|
@ -15,7 +15,7 @@ void pac_copy_empty_rules_from_ast_to_grammar(pac_grammar_s *grammar, pac_ast_s
|
||||||
pac_rule_s *rule = &grammar->rules[rule_index];
|
pac_rule_s *rule = &grammar->rules[rule_index];
|
||||||
usz_t len_rule_name = strlen(ast_rule.name);
|
usz_t len_rule_name = strlen(ast_rule.name);
|
||||||
rule->name = malloc(len_rule_name + 1);
|
rule->name = malloc(len_rule_name + 1);
|
||||||
memcpy(rule->name, ast_rule.name, len_rule_name);
|
pac_memory_copy(rule->name, ast_rule.name, len_rule_name);
|
||||||
rule->name[len_rule_name] = 0x00;
|
rule->name[len_rule_name] = 0x00;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -201,7 +201,7 @@ char * pac_stringify_token_type(pac_token_e type)
|
||||||
char pac_spaces[256];
|
char pac_spaces[256];
|
||||||
char * pac_create_spaces_for_indent(u8_t count)
|
char * pac_create_spaces_for_indent(u8_t count)
|
||||||
{
|
{
|
||||||
memset(pac_spaces, ' ', 256);
|
pac_memory_fill(pac_spaces, 256, ' ');
|
||||||
pac_spaces[count] = 0x00;
|
pac_spaces[count] = 0x00;
|
||||||
return &pac_spaces[0];
|
return &pac_spaces[0];
|
||||||
}
|
}
|
||||||
|
@ -214,7 +214,7 @@ void pac_display_tlist(pac_tlist_s list)
|
||||||
pac_token_s token = list.tokens[index];
|
pac_token_s token = list.tokens[index];
|
||||||
|
|
||||||
char content[token.length+1];
|
char content[token.length+1];
|
||||||
memcpy(&content[0], &list.source[token.offset], token.length);
|
pac_memory_copy(&content[0], &list.source[token.offset], token.length);
|
||||||
content[token.length] = 0;
|
content[token.length] = 0;
|
||||||
|
|
||||||
char *token_type_string = pac_stringify_token_type(token.type);
|
char *token_type_string = pac_stringify_token_type(token.type);
|
||||||
|
|
|
@ -0,0 +1,29 @@
|
||||||
|
#include <utility.h>
|
||||||
|
|
||||||
|
void pac_memory_copy(void *destination, void *source, usz_t length)
|
||||||
|
{
|
||||||
|
u8_t *source_8 = source;
|
||||||
|
u8_t *destination_8 = destination;
|
||||||
|
usz_t index = 0;
|
||||||
|
while(index < length)
|
||||||
|
{
|
||||||
|
destination_8[index] = source_8[index];
|
||||||
|
++index;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void pac_memory_fill(void *region, usz_t len_region, u8_t byte)
|
||||||
|
{
|
||||||
|
u8_t *region_8 = region;
|
||||||
|
usz_t index = 0;
|
||||||
|
while(index < len_region)
|
||||||
|
{
|
||||||
|
region_8[index] = byte;
|
||||||
|
++index;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void pac_memory_zero(void *region, usz_t len_region)
|
||||||
|
{
|
||||||
|
pac_memory_fill(region, len_region, 0);
|
||||||
|
}
|
Loading…
Reference in New Issue