\t -> ' ' L reimar
This commit is contained in:
parent
61849ac58d
commit
76bce4efef
133
checker.c
133
checker.c
@ -63,107 +63,108 @@ int string_symbol_map_set(StringSymbolMap* map, size_t key_hash, Symbol value)
|
|||||||
|
|
||||||
int statements_symbols_vec_construct(StatementsSymbolsVec* vec)
|
int statements_symbols_vec_construct(StatementsSymbolsVec* vec)
|
||||||
{
|
{
|
||||||
const size_t start_capacity = 4;
|
const size_t start_capacity = 4;
|
||||||
StatementsSymbols* data = malloc(start_capacity * sizeof(StatementsSymbols));
|
StatementsSymbols* data
|
||||||
if (data == NULL) {
|
= malloc(start_capacity * sizeof(StatementsSymbols));
|
||||||
return -1;
|
if (data == NULL) {
|
||||||
}
|
return -1;
|
||||||
*vec = (StatementsSymbolsVec) {
|
}
|
||||||
.data = data,
|
*vec = (StatementsSymbolsVec) {
|
||||||
.length = 0,
|
.data = data,
|
||||||
.capacity = start_capacity,
|
.length = 0,
|
||||||
};
|
.capacity = start_capacity,
|
||||||
return 0;
|
};
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void statements_symbols_vec_destroy(StatementsSymbolsVec* vec)
|
void statements_symbols_vec_destroy(StatementsSymbolsVec* vec)
|
||||||
{
|
{
|
||||||
if (vec->data != NULL) {
|
if (vec->data != NULL) {
|
||||||
free(vec->data);
|
free(vec->data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int statements_symbols_vec_push(StatementsSymbolsVec* vec, StatementsSymbols pair)
|
int statements_symbols_vec_push(
|
||||||
|
StatementsSymbolsVec* vec, StatementsSymbols pair)
|
||||||
{
|
{
|
||||||
if (vec->length + 1 > vec->capacity) {
|
if (vec->length + 1 > vec->capacity) {
|
||||||
StatementsSymbols* new_data = realloc(vec->data, vec->capacity * 2 * sizeof(StatementsSymbols));
|
StatementsSymbols* new_data
|
||||||
if (new_data == NULL) {
|
= realloc(vec->data, vec->capacity * 2 * sizeof(StatementsSymbols));
|
||||||
return -1;
|
if (new_data == NULL) {
|
||||||
}
|
return -1;
|
||||||
vec->capacity *= 2;
|
}
|
||||||
vec->data = new_data;
|
vec->capacity *= 2;
|
||||||
}
|
vec->data = new_data;
|
||||||
vec->data[vec->length] = pair;
|
}
|
||||||
vec->length += 1;
|
vec->data[vec->length] = pair;
|
||||||
return 0;
|
vec->length += 1;
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void symbol_table_construct(SymbolTable* table, SymbolTable* parent)
|
void symbol_table_construct(SymbolTable* table, SymbolTable* parent)
|
||||||
{
|
{
|
||||||
*table = (SymbolTable) {
|
*table = (SymbolTable) {
|
||||||
.parent = parent,
|
.parent = parent,
|
||||||
.map = { 0 },
|
.map = { 0 },
|
||||||
};
|
};
|
||||||
string_symbol_map_construct(&table->map);
|
string_symbol_map_construct(&table->map);
|
||||||
}
|
}
|
||||||
|
|
||||||
void symbol_table_destroy(SymbolTable* table)
|
void symbol_table_destroy(SymbolTable* table)
|
||||||
{
|
{
|
||||||
string_symbol_map_destroy(&table->map);
|
string_symbol_map_destroy(&table->map);
|
||||||
}
|
}
|
||||||
|
|
||||||
void checker_construct(Checker* checker)
|
void checker_construct(Checker* checker)
|
||||||
{
|
{
|
||||||
*checker = (Checker) {
|
*checker = (Checker) {
|
||||||
.failed = false,
|
.failed = false,
|
||||||
.statements_symbols = { 0 },
|
.statements_symbols = { 0 },
|
||||||
};
|
};
|
||||||
statements_symbols_vec_construct(&checker->statements_symbols);
|
statements_symbols_vec_construct(&checker->statements_symbols);
|
||||||
}
|
}
|
||||||
|
|
||||||
void checker_destroy(Checker* checker)
|
void checker_destroy(Checker* checker) { (void)checker; }
|
||||||
{
|
|
||||||
(void)checker;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool checker_failed(const Checker* checker) { return checker->failed; }
|
bool checker_failed(const Checker* checker) { return checker->failed; }
|
||||||
|
|
||||||
CheckerResult checker_result(Checker* checker)
|
CheckerResult checker_result(Checker* checker)
|
||||||
{
|
{
|
||||||
return (CheckerResult) {
|
return (CheckerResult) {
|
||||||
.head_table = checker->head_table,
|
.head_table = checker->head_table,
|
||||||
.statements_symbols = checker->statements_symbols,
|
.statements_symbols = checker->statements_symbols,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
void checker_check_statements(Checker* checker, ASTNode* node)
|
void checker_check_statements(Checker* checker, ASTNode* node)
|
||||||
{
|
{
|
||||||
SymbolTable table;
|
SymbolTable table;
|
||||||
symbol_table_construct(&table, &checker->head_table);
|
symbol_table_construct(&table, &checker->head_table);
|
||||||
for (size_t i = 0; i < node->statements.length; ++i) {
|
for (size_t i = 0; i < node->statements.length; ++i) {
|
||||||
checker_check_statement(checker, &table, node->statements.data[i]);
|
checker_check_statement(checker, &table, node->statements.data[i]);
|
||||||
}
|
}
|
||||||
statements_symbols_vec_push(&checker->statements_symbols, (StatementsSymbols) {
|
statements_symbols_vec_push(&checker->statements_symbols,
|
||||||
.table = table,
|
(StatementsSymbols) {
|
||||||
.statements = node,
|
.table = table,
|
||||||
});
|
.statements = node,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void checker_check_statement(
|
||||||
void checker_check_statement(Checker* checker, SymbolTable* table, ASTNode* node)
|
Checker* checker, SymbolTable* table, ASTNode* node)
|
||||||
{
|
{
|
||||||
switch (node->node_type) {
|
switch (node->node_type) {
|
||||||
case ASTNodeType_Block:
|
case ASTNodeType_Block:
|
||||||
checker_check_statements(checker, node);
|
checker_check_statements(checker, node);
|
||||||
case ASTNodeType_If:
|
case ASTNodeType_If:
|
||||||
case ASTNodeType_Loop:
|
case ASTNodeType_Loop:
|
||||||
case ASTNodeType_Assign:
|
case ASTNodeType_Assign:
|
||||||
case ASTNodeType_Let:
|
case ASTNodeType_Let:
|
||||||
case ASTNodeType_Break:
|
case ASTNodeType_Break:
|
||||||
case ASTNodeType_Fn:
|
case ASTNodeType_Fn:
|
||||||
case ASTNodeType_Return:
|
case ASTNodeType_Return:
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user