fix: build and .sh test file for functions

This commit is contained in:
Matteo Flebus 2026-01-31 12:53:23 +01:00
parent a63632005c
commit 3cd231f031
7 changed files with 12 additions and 7 deletions

View file

@ -20,7 +20,8 @@ libutils_a_SOURCES = \
ast/ast_loop.c \ ast/ast_loop.c \
args/args.c \ args/args.c \
vars/vars.c \ vars/vars.c \
ast/ast_assignment.c ast/ast_assignment.c \
ast/ast_function.c
libutils_a_CPPFLAGS = -I$(top_srcdir)/src libutils_a_CPPFLAGS = -I$(top_srcdir)/src

View file

@ -11,7 +11,8 @@ void ast_free(struct ast **node)
{ {
if (node == NULL || *node == NULL) if (node == NULL || *node == NULL)
{ {
fprintf(stderr, fprintf(
stderr,
"WARNING: Internal error: failed to free AST node (NULL argument)"); "WARNING: Internal error: failed to free AST node (NULL argument)");
return; return;
} }
@ -56,7 +57,8 @@ void ast_free(struct ast **node)
break; break;
default: default:
fprintf(stderr, "WARNING: Internal error: failed to free an AST node (Unknown " fprintf(stderr,
"WARNING: Internal error: failed to free an AST node (Unknown "
"type)"); "type)");
return; return;
} }

View file

@ -6,6 +6,7 @@
#include "ast_base.h" #include "ast_base.h"
#include "ast_command.h" #include "ast_command.h"
#include "ast_end.h" #include "ast_end.h"
#include "ast_function.h"
#include "ast_if.h" #include "ast_if.h"
#include "ast_list.h" #include "ast_list.h"
#include "ast_loop.h" #include "ast_loop.h"

View file

@ -23,7 +23,7 @@ struct ast *ast_create_function(char *name, struct ast *value)
if (!function_data) if (!function_data)
return NULL; return NULL;
function_data->name = strdup(name); function_data->name = name;
function_data->value = value; function_data->value = value;
return ast_create(AST_FUNCTION, function_data); return ast_create(AST_FUNCTION, function_data);

View file

@ -1,13 +1,14 @@
#ifndef AST_FUNCTION_H #ifndef AST_FUNCTION_H
#define AST_FUNCTION_H #define AST_FUNCTION_H
#include <stdbool.h>
struct ast_function struct ast_function
{ {
char *name; char *name;
struct ast *value; struct ast *value;
}; };
/** /**
* Checks if the given AST node is an ast_function * Checks if the given AST node is an ast_function
*/ */

View file

@ -24,7 +24,7 @@ struct ast_loop *ast_get_loop(struct ast *node);
/** /**
* Creates a new AST node representing a loop. * Creates a new AST node representing a loop.
*/ */
struct ast *ast_create_loop(struct ast* condition, struct ast* body); struct ast *ast_create_loop(struct ast *condition, struct ast *body);
/* /*
* @brief: frees the given ast_loop and sets the pointer to NULL. * @brief: frees the given ast_loop and sets the pointer to NULL.

0
tests/func.sh Normal file → Executable file
View file