ref: move analyzer fn defs into compiler/iternals
This commit is contained in:
@@ -44,6 +44,7 @@ add_executable(fzc
|
||||
src/compiler/analyzer/an_identifier.c
|
||||
src/compiler/analyzer/an_loop.c
|
||||
src/compiler/analyzer/an_return.c
|
||||
src/compiler/analyzer/an_strfmt.c
|
||||
src/compiler/analyzer/an_unarycond.c
|
||||
src/compiler/analyzer/an_unarymath.c
|
||||
src/compiler/reader/rd_fmtstr.c
|
||||
|
||||
@@ -76,32 +76,4 @@ void fzl_analyze(fzl_analyzer_t *analyzer);
|
||||
// Free analyzer
|
||||
void fzl_freeanalyzer(fzl_analyzer_t *analyzer);
|
||||
|
||||
extern char an_problem[256];
|
||||
|
||||
bool an_is_compatible(fzl_type_t a, fzl_type_t b, char *ac, char *bc);
|
||||
char *an_typetostr(fzl_type_t type, char *classname);
|
||||
fzl_type_t an_toktotype(fzl_token_t *tok);
|
||||
|
||||
fzl_an_res_t analyze_common(fzl_analyzer_t *analyzer, fzl_node_t *node);
|
||||
fzl_an_res_t analyze_call(fzl_analyzer_t *analyzer, fzl_node_t *call_node);
|
||||
fzl_an_res_t analyze_identifier(fzl_analyzer_t *analyzer, fzl_node_t *id);
|
||||
fzl_an_res_t analyze_conditional(fzl_analyzer_t *analyzer, fzl_node_t *cond);
|
||||
fzl_an_res_t analyze_function(fzl_analyzer_t *analyzer, fzl_node_t *fn_node);
|
||||
fzl_an_res_t analyze_block(fzl_analyzer_t *analyzer, fzl_node_t *block_node);
|
||||
fzl_an_res_t analyze_return(fzl_analyzer_t *analyzer, fzl_node_t *ret_node);
|
||||
fzl_an_res_t analyze_class(fzl_analyzer_t *analyzer, fzl_node_t *class_node);
|
||||
fzl_an_res_t analyze_field(fzl_analyzer_t *analyzer, fzl_node_t *field);
|
||||
fzl_an_res_t analyze_declaration(fzl_analyzer_t *analyzer, fzl_node_t *decl);
|
||||
fzl_an_res_t analyze_construct(fzl_analyzer_t *analyzer, fzl_node_t *construct);
|
||||
fzl_an_res_t analyze_loop(fzl_analyzer_t *analyzer, fzl_node_t *loop_node);
|
||||
fzl_an_res_t analyze_break(fzl_analyzer_t *analyzer, fzl_node_t *break_node);
|
||||
fzl_an_res_t analyze_binmath(fzl_analyzer_t *analyzer, fzl_node_t *bin_node);
|
||||
fzl_an_res_t analyze_unarymath(fzl_analyzer_t *analyzer, fzl_node_t *unary);
|
||||
fzl_an_res_t analyze_condition(fzl_analyzer_t *analyzer, fzl_node_t *cond_node);
|
||||
fzl_an_res_t analyze_unarycond(fzl_analyzer_t *analyzer, fzl_node_t *unary);
|
||||
fzl_an_res_t analyze_assign(fzl_analyzer_t *analyzer, fzl_node_t *assign_node);
|
||||
|
||||
fzl_an_ctx_t *an_nest_ctx(fzl_analyzer_t *analyzer, fzl_an_ctx_type_t type);
|
||||
fzl_an_ctx_t *an_fin_ctx(fzl_analyzer_t *analyzer);
|
||||
|
||||
#endif // FZL_ANALYZER_H
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
#ifndef INTERNALS_ANALYZER_H
|
||||
#define INTERNALS_ANALYZER_H
|
||||
|
||||
#include <common/fzl_types.h>
|
||||
#include <compiler/fzl_analyzer.h>
|
||||
#include <compiler/fzl_token.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
extern char an_problem[256];
|
||||
|
||||
bool an_is_compatible(fzl_type_t a, fzl_type_t b, char *ac, char *bc);
|
||||
char *an_typetostr(fzl_type_t type, char *classname);
|
||||
fzl_type_t an_toktotype(fzl_token_t *tok);
|
||||
|
||||
fzl_an_res_t analyze_common(fzl_analyzer_t *analyzer, fzl_node_t *node);
|
||||
fzl_an_res_t analyze_call(fzl_analyzer_t *analyzer, fzl_node_t *call_node);
|
||||
fzl_an_res_t analyze_identifier(fzl_analyzer_t *analyzer, fzl_node_t *id);
|
||||
fzl_an_res_t analyze_conditional(fzl_analyzer_t *analyzer, fzl_node_t *cond);
|
||||
fzl_an_res_t analyze_function(fzl_analyzer_t *analyzer, fzl_node_t *fn_node);
|
||||
fzl_an_res_t analyze_block(fzl_analyzer_t *analyzer, fzl_node_t *block_node);
|
||||
fzl_an_res_t analyze_return(fzl_analyzer_t *analyzer, fzl_node_t *ret_node);
|
||||
fzl_an_res_t analyze_class(fzl_analyzer_t *analyzer, fzl_node_t *class_node);
|
||||
fzl_an_res_t analyze_field(fzl_analyzer_t *analyzer, fzl_node_t *field);
|
||||
fzl_an_res_t analyze_declaration(fzl_analyzer_t *analyzer, fzl_node_t *decl);
|
||||
fzl_an_res_t analyze_construct(fzl_analyzer_t *analyzer, fzl_node_t *construct);
|
||||
fzl_an_res_t analyze_loop(fzl_analyzer_t *analyzer, fzl_node_t *loop_node);
|
||||
fzl_an_res_t analyze_break(fzl_analyzer_t *analyzer, fzl_node_t *break_node);
|
||||
fzl_an_res_t analyze_binmath(fzl_analyzer_t *analyzer, fzl_node_t *bin_node);
|
||||
fzl_an_res_t analyze_unarymath(fzl_analyzer_t *analyzer, fzl_node_t *unary);
|
||||
fzl_an_res_t analyze_condition(fzl_analyzer_t *analyzer, fzl_node_t *cond_node);
|
||||
fzl_an_res_t analyze_unarycond(fzl_analyzer_t *analyzer, fzl_node_t *unary);
|
||||
fzl_an_res_t analyze_assign(fzl_analyzer_t *analyzer, fzl_node_t *assign_node);
|
||||
fzl_an_res_t analyze_strfmt(fzl_analyzer_t *analyzer, fzl_node_t *strfmt_node);
|
||||
|
||||
fzl_an_ctx_t *an_nest_ctx(fzl_analyzer_t *analyzer, fzl_an_ctx_type_t type);
|
||||
fzl_an_ctx_t *an_fin_ctx(fzl_analyzer_t *analyzer);
|
||||
|
||||
#endif // INTERNALS_ANALYZER_H
|
||||
@@ -1,6 +1,7 @@
|
||||
#include <common/fzl_types.h>
|
||||
#include <compiler/fzl_analyzer.h>
|
||||
#include <compiler/fzl_parser.h>
|
||||
#include <compiler/internals/analyzer.h>
|
||||
#include <stdio.h>
|
||||
|
||||
// Analyze assigns
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include <common/fzl_types.h>
|
||||
#include <compiler/fzl_analyzer.h>
|
||||
#include <compiler/fzl_parser.h>
|
||||
#include <compiler/internals/analyzer.h>
|
||||
#include <stdio.h>
|
||||
|
||||
// Analyze binary arithmetics
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#include <compiler/fzl_analyzer.h>
|
||||
#include <compiler/fzl_parser.h>
|
||||
#include <compiler/fzl_token.h>
|
||||
#include <compiler/internals/analyzer.h>
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#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)
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#include <compiler/fzl_analyzer.h>
|
||||
#include <compiler/fzl_parser.h>
|
||||
#include <compiler/fzl_token.h>
|
||||
#include <compiler/internals/analyzer.h>
|
||||
#include <compiler/utils/fzl_symtable.h>
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include <common/fzl_types.h>
|
||||
#include <compiler/fzl_analyzer.h>
|
||||
#include <compiler/fzl_parser.h>
|
||||
#include <compiler/internals/analyzer.h>
|
||||
#include <compiler/utils/fzl_symtable.h>
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#include <compiler/fzl_analyzer.h>
|
||||
#include <compiler/fzl_parser.h>
|
||||
#include <compiler/fzl_token.h>
|
||||
#include <compiler/internals/analyzer.h>
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
@@ -14,6 +15,10 @@ fzl_an_res_t analyze_common(fzl_analyzer_t *analyzer, fzl_node_t *node)
|
||||
fzl_an_res_t res = {.error = false, .type = FZL_TYPE_NULL, .classname = NULL};
|
||||
switch (node->type)
|
||||
{
|
||||
case FZL_NODETYPE_FMT_STRING:
|
||||
res = analyze_strfmt(analyzer, node);
|
||||
break;
|
||||
|
||||
case FZL_NODETYPE_ASSIGN:
|
||||
res = analyze_assign(analyzer, node);
|
||||
break;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include <common/fzl_types.h>
|
||||
#include <compiler/fzl_analyzer.h>
|
||||
#include <compiler/fzl_parser.h>
|
||||
#include <compiler/internals/analyzer.h>
|
||||
#include <stdio.h>
|
||||
|
||||
// Analyze binary conditional nodes
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#include <compiler/fzl_analyzer.h>
|
||||
#include <compiler/fzl_parser.h>
|
||||
#include <compiler/fzl_token.h>
|
||||
#include <compiler/internals/analyzer.h>
|
||||
#include <stdio.h>
|
||||
|
||||
// Analyze conditional statement
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include <common/fzl_types.h>
|
||||
#include <compiler/fzl_analyzer.h>
|
||||
#include <compiler/fzl_parser.h>
|
||||
#include <compiler/internals/analyzer.h>
|
||||
#include <compiler/utils/fzl_symtable.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#include <compiler/fzl_analyzer.h>
|
||||
#include <compiler/fzl_parser.h>
|
||||
#include <compiler/fzl_token.h>
|
||||
#include <compiler/internals/analyzer.h>
|
||||
#include <compiler/utils/fzl_symtable.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include <common/fzl_types.h>
|
||||
#include <compiler/fzl_analyzer.h>
|
||||
#include <compiler/fzl_parser.h>
|
||||
#include <compiler/internals/analyzer.h>
|
||||
#include <compiler/utils/fzl_symtable.h>
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include <common/fzl_types.h>
|
||||
#include <compiler/fzl_analyzer.h>
|
||||
#include <compiler/fzl_parser.h>
|
||||
#include <compiler/internals/analyzer.h>
|
||||
#include <compiler/utils/fzl_symtable.h>
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include <compiler/fzl_analyzer.h>
|
||||
#include <compiler/fzl_parser.h>
|
||||
#include <compiler/internals/analyzer.h>
|
||||
#include <compiler/utils/fzl_symtable.h>
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#include <compiler/fzl_analyzer.h>
|
||||
#include <compiler/fzl_parser.h>
|
||||
#include <compiler/fzl_token.h>
|
||||
#include <compiler/internals/analyzer.h>
|
||||
#include <compiler/utils/fzl_symtable.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#include <compiler/fzl_analyzer.h>
|
||||
#include <compiler/fzl_parser.h>
|
||||
#include <compiler/fzl_token.h>
|
||||
#include <compiler/internals/analyzer.h>
|
||||
#include <stdio.h>
|
||||
|
||||
// Analyze return statement
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
#include <common/fzl_types.h>
|
||||
#include <compiler/fzl_analyzer.h>
|
||||
#include <compiler/fzl_parser.h>
|
||||
#include <compiler/internals/analyzer.h>
|
||||
#include <stddef.h>
|
||||
|
||||
// Analyze format string
|
||||
fzl_an_res_t analyze_strfmt(fzl_analyzer_t *analyzer, fzl_node_t *strfmt_node)
|
||||
{
|
||||
if (!analyzer)
|
||||
return (fzl_an_res_t){.error = true};
|
||||
|
||||
if (!strfmt_node || strfmt_node->type != FZL_NODETYPE_FMT_STRING)
|
||||
{
|
||||
an_push_error(analyzer, NULL, "node is not format string");
|
||||
return (fzl_an_res_t){.error = true};
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < strfmt_node->list.entry_count; i++)
|
||||
{
|
||||
fzl_node_t *node = strfmt_node->list.entries[i];
|
||||
|
||||
if (node->type != FZL_NODETYPE_LITERAL &&
|
||||
node->type != FZL_NODETYPE_IDENTIFIER)
|
||||
{
|
||||
an_push_error(
|
||||
analyzer, node->token,
|
||||
"format string can only contain string literals and identifiers");
|
||||
return (fzl_an_res_t){.error = true};
|
||||
}
|
||||
|
||||
fzl_an_res_t node_res = analyze_common(analyzer, node);
|
||||
if (node_res.error)
|
||||
return (fzl_an_res_t){.error = true};
|
||||
}
|
||||
|
||||
return (fzl_an_res_t){
|
||||
.error = false, .type = FZL_TYPE_STRING, .classname = NULL};
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
#include <common/fzl_types.h>
|
||||
#include <compiler/fzl_analyzer.h>
|
||||
#include <compiler/fzl_parser.h>
|
||||
#include <compiler/internals/analyzer.h>
|
||||
|
||||
// Analyze unary condition
|
||||
fzl_an_res_t analyze_unarycond(fzl_analyzer_t *analyzer, fzl_node_t *unary)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include <common/fzl_types.h>
|
||||
#include <compiler/fzl_analyzer.h>
|
||||
#include <compiler/fzl_parser.h>
|
||||
#include <compiler/internals/analyzer.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
// Analyze unary arithmetic
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include <compiler/fzl_analyzer.h>
|
||||
#include <compiler/internals/analyzer.h>
|
||||
#include <compiler/utils/fzl_symtable.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include <compiler/fzl_analyzer.h>
|
||||
#include <compiler/fzl_parser.h>
|
||||
#include <compiler/fzl_token.h>
|
||||
#include <compiler/internals/analyzer.h>
|
||||
#include <compiler/utils/fzl_symtable.h>
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
|
||||
Reference in New Issue
Block a user