codebased/scirpt/ast.c
2023-04-17 02:25:26 +02:00

101 lines
3.1 KiB
C

#include "scirpt/ast.h"
#include "common/string.h"
#include "common/string_array.h"
#include <stddef.h>
#include <stdlib.h>
void scirpt_ast_expr_delete(ScirptAstExpr* expr)
{
switch (expr->type) {
case ScirptAstExprTypeEof:
break;
case ScirptAstExprTypeError:
break;
case ScirptAstExprTypeId:
heapstring_destroy(&expr->id_value);
break;
case ScirptAstExprTypeInt:
break;
case ScirptAstExprTypeFloat:
break;
case ScirptAstExprTypeString:
heapstring_destroy(&expr->string_value);
break;
case ScirptAstExprTypeBool:
break;
case ScirptAstExprTypeNull:
break;
case ScirptAstExprTypeBlock:
for (size_t i = 0; i < expr->block.statements.length; ++i)
scirpt_ast_expr_delete(expr->block.statements.data[i]);
scirpt_ast_expr_array_destroy(&expr->block.statements);
break;
case ScirptAstExprTypeIf:
scirpt_ast_expr_delete(expr->if_expr.condition);
scirpt_ast_expr_delete(expr->if_expr.truthy);
if (expr->if_expr.falsy)
scirpt_ast_expr_delete(expr->if_expr.falsy);
break;
case ScirptAstExprTypeLoop:
scirpt_ast_expr_delete(expr->loop.body);
break;
case ScirptAstExprTypeWhile:
scirpt_ast_expr_delete(expr->while_expr.condition);
scirpt_ast_expr_delete(expr->while_expr.body);
break;
case ScirptAstExprTypeFor:
heapstring_destroy(&expr->for_expr.subject);
scirpt_ast_expr_delete(expr->for_expr.value);
scirpt_ast_expr_delete(expr->for_expr.body);
break;
case ScirptAstExprTypeMember:
scirpt_ast_expr_delete(expr->member.subject);
heapstring_destroy(&expr->member.value);
break;
case ScirptAstExprTypeCall:
scirpt_ast_expr_delete(expr->call.subject);
for (size_t i = 0; i < expr->call.args.length; ++i)
scirpt_ast_expr_delete(expr->call.args.data[i]);
scirpt_ast_expr_array_destroy(&expr->call.args);
break;
case ScirptAstExprTypeIndex:
scirpt_ast_expr_delete(expr->index.subject);
scirpt_ast_expr_delete(expr->index.value);
break;
case ScirptAstExprTypeUnary:
scirpt_ast_expr_delete(expr->unary.subject);
break;
case ScirptAstExprTypeBinary:
scirpt_ast_expr_delete(expr->binary.left);
scirpt_ast_expr_delete(expr->binary.right);
break;
case ScirptAstExprTypeAssign:
scirpt_ast_expr_delete(expr->assign.subject);
scirpt_ast_expr_delete(expr->assign.value);
break;
case ScirptAstExprTypeLambda:
for (size_t i = 0; i < expr->lambda.params.length; ++i)
heapstring_destroy(&expr->lambda.params.data[i]);
heapstring_array_destroy(&expr->lambda.params);
scirpt_ast_expr_delete(expr->lambda.body);
break;
case ScirptAstExprTypeFunction:
heapstring_destroy(&expr->function.subject);
for (size_t i = 0; i < expr->function.params.length; ++i)
heapstring_destroy(&expr->function.params.data[i]);
heapstring_array_destroy(&expr->function.params);
scirpt_ast_expr_delete(expr->function.body);
break;
case ScirptAstExprTypeLet:
heapstring_destroy(&expr->let.subject);
scirpt_ast_expr_delete(expr->let.value);
break;
case ScirptAstExprTypeReturn:
scirpt_ast_expr_delete(expr->return_statement.value);
break;
case ScirptAstExprTypeBreak:
scirpt_ast_expr_delete(expr->break_statement.value);
break;
}
}