80 lines
1.6 KiB
C
80 lines
1.6 KiB
C
#ifndef FZL_ANALYZER_H
|
|
#define FZL_ANALYZER_H
|
|
|
|
#include <common/fzl_types.h>
|
|
#include <compiler/fzl_parser.h>
|
|
#include <compiler/fzl_token.h>
|
|
#include <compiler/utils/fzl_symtable.h>
|
|
#include <stdbool.h>
|
|
#include <stddef.h>
|
|
|
|
// Analyzing context type
|
|
typedef enum
|
|
{
|
|
FZL_AN_CTX_TYPE_UNNECESSARY, // default type
|
|
FZL_AN_CTX_TYPE_FUNCTION, // when analyzing function
|
|
FZL_AN_CTX_TYPE_LOOP, // when analyzing loop
|
|
FZL_AN_CTX_TYPE_CLASS, // when analyzing class
|
|
} fzl_an_ctx_type_t;
|
|
|
|
// Inner node analyzing result descriptor
|
|
typedef struct
|
|
{
|
|
bool error;
|
|
|
|
fzl_type_t type;
|
|
char *classname;
|
|
} fzl_an_res_t;
|
|
|
|
// Current node context descriptor
|
|
typedef struct fzl_an_ctx
|
|
{
|
|
struct fzl_an_ctx *parent;
|
|
|
|
fzl_an_ctx_type_t type;
|
|
fzl_symtable_t *symbols;
|
|
size_t symbols_level;
|
|
|
|
union
|
|
{
|
|
fzl_node_t *fn;
|
|
char *classname;
|
|
};
|
|
} fzl_an_ctx_t;
|
|
|
|
// Analyzer descriptor
|
|
typedef struct
|
|
{
|
|
char *warnings[256];
|
|
size_t warnings_top;
|
|
|
|
char *errors[256];
|
|
size_t errors_top;
|
|
|
|
fzl_symtable_t *symbols[256];
|
|
size_t symbols_top;
|
|
|
|
char *alloc_names[256];
|
|
size_t alloc_names_top;
|
|
|
|
fzl_node_t *root;
|
|
fzl_an_ctx_t *ctx;
|
|
} fzl_analyzer_t;
|
|
|
|
// Allocate analyzer
|
|
fzl_analyzer_t *fzl_mkanalyzer(fzl_node_t *node);
|
|
|
|
// Push error to errors list
|
|
bool an_push_error(fzl_analyzer_t *analyzer, fzl_token_t *tok, char *error);
|
|
|
|
// Push warning to warnings list
|
|
bool an_push_warning(fzl_analyzer_t *analyzer, fzl_token_t *tok, char *warning);
|
|
|
|
// Analyze AST
|
|
void fzl_analyze(fzl_analyzer_t *analyzer);
|
|
|
|
// Free analyzer
|
|
void fzl_freeanalyzer(fzl_analyzer_t *analyzer);
|
|
|
|
#endif // FZL_ANALYZER_H
|