37 lines
933 B
C
37 lines
933 B
C
#include <common/fzl_types.h>
|
|
#include <compiler/fzl_analyzer.h>
|
|
#include <compiler/fzl_parser.h>
|
|
#include <compiler/internals/analyzer.h>
|
|
|
|
// Analyze break node
|
|
fzl_an_res_t analyze_break(fzl_analyzer_t *analyzer, fzl_node_t *break_node)
|
|
{
|
|
if (!analyzer)
|
|
return (fzl_an_res_t){.error = true};
|
|
|
|
if (!break_node || break_node->type != FZL_NODETYPE_BREAK)
|
|
{
|
|
an_push_error(analyzer, NULL, "node is not a break statement");
|
|
return (fzl_an_res_t){.error = true};
|
|
}
|
|
|
|
fzl_an_ctx_t *ctx = analyzer->ctx;
|
|
while (ctx != NULL)
|
|
{
|
|
if (ctx && ctx->type == FZL_AN_CTX_TYPE_LOOP)
|
|
break;
|
|
|
|
ctx = ctx->parent;
|
|
}
|
|
|
|
if (!ctx || ctx->type != FZL_AN_CTX_TYPE_LOOP)
|
|
{
|
|
an_push_error(analyzer, break_node->token,
|
|
"cannot use 'break' outside the loop");
|
|
return (fzl_an_res_t){.error = true};
|
|
}
|
|
|
|
return (fzl_an_res_t){
|
|
.error = false, .type = FZL_TYPE_NULL, .classname = NULL};
|
|
}
|