Start work on type checker (uh oh)
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
#include "SolsType.h"
|
||||
#include "lexer.h"
|
||||
#include "../include/error.h"
|
||||
#include "../include/estr.h"
|
||||
#include <string.h>
|
||||
|
||||
ResultType(SolsType, charptr) createSolsType(SolsTypeType in) {
|
||||
SolsTypeField* ptr = malloc(sizeof(SolsTypeField) * 32);
|
||||
@@ -91,3 +93,52 @@ void freeSolsType(SolsType* type) {
|
||||
type->children.count = 0;
|
||||
type->children.capacity = 0;
|
||||
}
|
||||
|
||||
bool compareTypes(SolsType* left, SolsType* right) {
|
||||
if (left->type != right->type) {
|
||||
return false;
|
||||
}
|
||||
switch (left->type) {
|
||||
case STT_OBJECT: {
|
||||
if (left->children.count != right->children.count) {
|
||||
return false;
|
||||
}
|
||||
for (size_t i = 0; i < left->children.count; i++) {
|
||||
if (strcmp(left->children.at[i].name, right->children.at[i].name) != 0) {
|
||||
return false;
|
||||
}
|
||||
if (compareTypes(&left->children.at[i].type, &right->children.at[i].type) == false) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
case STT_TEMPLATE: {
|
||||
if (left->children.count != right->children.count) {
|
||||
return false;
|
||||
}
|
||||
for (size_t i = 0; i < left->children.count; i++) {
|
||||
if (strcmp(left->children.at[i].name, right->children.at[i].name) != 0) {
|
||||
return false;
|
||||
}
|
||||
if (compareTypes(&left->children.at[i].type, &right->children.at[i].type) == false) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
||||
}
|
||||
case STT_FUN: {
|
||||
if (left->children.count != right->children.count) {
|
||||
return false;
|
||||
}
|
||||
for (size_t i = 0; i < left->children.count; i++) {
|
||||
if (compareTypes(&left->children.at[i].type, &right->children.at[i].type) == false) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
default: return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,4 +85,7 @@ ResultType(SolsType, charptr) copySolsType(SolsType* type);
|
||||
// Frees a SolsType
|
||||
void freeSolsType(SolsType* type);
|
||||
|
||||
// Compares two SolsTypes
|
||||
bool compareTypes(SolsType* left, SolsType* right);
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user