#include #include #include #include #include #include // Analyze structure definition fzl_an_res_t analyze_struct(fzl_analyzer_t *analyzer, fzl_node_t *struct_node) { if (!analyzer) return (fzl_an_res_t){.error = true}; if (!struct_node || struct_node->type != FZL_NODETYPE_STRUCT) { an_push_error(analyzer, NULL, "node is not a structure"); return (fzl_an_res_t){.error = true}; } an_nest_ctx(analyzer, FZL_AN_CTX_TYPE_UNNECESSARY); if (struct_node->structure.entries_count < 1) { an_push_warning(analyzer, struct_node->token, "empty structure"); return (fzl_an_res_t){.error = false}; } for (size_t i = 0; i < struct_node->structure.entries_count; i++) { fzl_node_t *entry = struct_node->structure.entries[i]; if (entry->type != FZL_NODETYPE_DECLARATION && entry->type != FZL_NODETYPE_IDENTIFIER) { an_push_error( analyzer, entry->token, "structure can contain only declarations and another structures"); return (fzl_an_res_t){.error = true}; } fzl_an_res_t res = analyze_common(analyzer, entry); if (res.error) return (fzl_an_res_t){.error = true}; if (res.type == FZL_TYPE_OBJECT) { an_push_error(analyzer, entry->token, "cannot store object inside struct"); return (fzl_an_res_t){.error = true}; } } an_fin_ctx(analyzer); return (fzl_an_res_t){ .error = false, .type = FZL_TYPE_STRUCT, .classname = NULL}; }