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 \
args/args.c \
vars/vars.c \
ast/ast_assignment.c
ast/ast_assignment.c \
ast/ast_function.c
libutils_a_CPPFLAGS = -I$(top_srcdir)/src

View file

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

View file

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

View file

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

View file

@ -1,13 +1,14 @@
#ifndef AST_FUNCTION_H
#define AST_FUNCTION_H
#include <stdbool.h>
struct ast_function
{
char *name;
struct ast *value;
};
/**
* 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.
*/
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.

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