codebased/scirpt/ast.c
2023-04-16 04:45:15 +02:00

61 lines
1.6 KiB
C

#include "scirpt/ast.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 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:
break;
case ScirptAstExprTypeBinary:
break;
case ScirptAstExprTypeAssign:
break;
case ScirptAstExprTypeLet:
break;
}
}