From d951985665bf3e0248286a30c67c28f505eb27c9 Mon Sep 17 00:00:00 2001 From: Johnny Richard Date: Sun, 16 Apr 2023 03:29:02 +0200 Subject: Start using string_view on lexer and parser This change fixes the memory leak when token got created. Signed-off-by: Johnny Richard --- src/pipac.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/pipac.c') diff --git a/src/pipac.c b/src/pipac.c index 993d56d..6e6df9e 100644 --- a/src/pipac.c +++ b/src/pipac.c @@ -20,11 +20,12 @@ #include "lexer.h" #include "parser.h" +#include "string_view.h" void generate_gas_x86_64_linux(ast_function_t *func) { - if (strcmp(func->name, "main") != 0) { + if (!string_view_eq(func->name, string_view_from_str("main"))) { fprintf(stderr, "[ERROR]: no main function has been defined!\n"); exit(EXIT_FAILURE); } @@ -47,7 +48,7 @@ void print_tokens(lexer_t *lexer) { token_t token; for (lexer_next_token(lexer, &token); token.kind != TOKEN_EOF; lexer_next_token(lexer, &token)) { - printf("%s:%d:%d: [kind=%d, value='%s']\n", lexer->filepath, token.row + 1, token.col + 1, token.kind, token.value); + printf("%s:%d:%d: [kind=%d, value='"SVFMT"']\n", lexer->filepath, token.row + 1, token.col + 1, token.kind, SVARG(&token.value)); } } -- cgit v1.2.3