- Feat: add binary math analysis - Fix: check for function context in block analysis - Feat: add 'break' analysis - Fix: few fixes in call analysis - Feat: add class analysis - Feat: add construct analysis - Feat: add declaration analysis - Feat: add field analysis - Feat: add function analysis - Feat: add loop analysis - Ref: updated utilities and context functions
125 lines
2.5 KiB
C
125 lines
2.5 KiB
C
#include <common/fzl_types.h>
|
|
#include <compiler/fzl_token.h>
|
|
#include <stdbool.h>
|
|
#include <string.h>
|
|
|
|
// Check compatibility between A and B types (and classnames)
|
|
bool an_is_compatible(fzl_type_t a, fzl_type_t b, char *ac, char *bc)
|
|
{
|
|
if (a == b)
|
|
return true;
|
|
|
|
if (a == FZL_TYPE_OBJECT && b == FZL_TYPE_OBJECT)
|
|
{
|
|
if (strcmp(ac, "null") == 0 || strcmp(bc, "null") == 0)
|
|
return true;
|
|
|
|
return strcmp(ac, bc) == 0;
|
|
}
|
|
|
|
if (a >= FZL_TYPE_INT8 && b >= FZL_TYPE_INT8)
|
|
return true;
|
|
|
|
return false;
|
|
}
|
|
|
|
// Convert type to string
|
|
char *an_typetostr(fzl_type_t type, char *classname)
|
|
{
|
|
if (classname)
|
|
return classname;
|
|
|
|
switch (type)
|
|
{
|
|
case FZL_TYPE_NULL:
|
|
return "null";
|
|
|
|
case FZL_TYPE_BOOL:
|
|
return "boolean";
|
|
|
|
case FZL_TYPE_STRING:
|
|
return "string";
|
|
|
|
case FZL_TYPE_CHAR:
|
|
return "char";
|
|
|
|
case FZL_TYPE_INT8:
|
|
return "i8";
|
|
|
|
case FZL_TYPE_INT16:
|
|
return "i16";
|
|
|
|
case FZL_TYPE_INT32:
|
|
return "i32";
|
|
|
|
case FZL_TYPE_INT64:
|
|
return "i64";
|
|
|
|
case FZL_TYPE_UINT8:
|
|
return "u8";
|
|
|
|
case FZL_TYPE_UINT16:
|
|
return "u16";
|
|
|
|
case FZL_TYPE_UINT32:
|
|
return "u32";
|
|
|
|
case FZL_TYPE_UINT64:
|
|
return "u64";
|
|
|
|
case FZL_TYPE_INT:
|
|
return "int";
|
|
|
|
case FZL_TYPE_UINT:
|
|
return "uint";
|
|
|
|
default:
|
|
return "<unknown>";
|
|
}
|
|
}
|
|
|
|
// Convert type token to type
|
|
fzl_type_t an_toktotype(fzl_token_t *tok)
|
|
{
|
|
if (!tok)
|
|
return FZL_TYPE_NULL;
|
|
|
|
if (tok->type == FZL_TOKTYPE_NAME)
|
|
return FZL_TYPE_OBJECT;
|
|
|
|
if (strcmp(tok->value, "null") == 0)
|
|
return FZL_TYPE_NULL;
|
|
|
|
if (strcmp((char *)tok->value, "i8") == 0)
|
|
return FZL_TYPE_INT8;
|
|
if (strcmp((char *)tok->value, "i16") == 0)
|
|
return FZL_TYPE_INT16;
|
|
if (strcmp((char *)tok->value, "i32") == 0)
|
|
return FZL_TYPE_INT32;
|
|
if (strcmp((char *)tok->value, "i64") == 0)
|
|
return FZL_TYPE_INT64;
|
|
|
|
if (strcmp((char *)tok->value, "u8") == 0)
|
|
return FZL_TYPE_UINT8;
|
|
if (strcmp((char *)tok->value, "u16") == 0)
|
|
return FZL_TYPE_UINT16;
|
|
if (strcmp((char *)tok->value, "u32") == 0)
|
|
return FZL_TYPE_UINT32;
|
|
if (strcmp((char *)tok->value, "u64") == 0)
|
|
return FZL_TYPE_UINT64;
|
|
|
|
if (strcmp((char *)tok->value, "int") == 0)
|
|
return FZL_TYPE_INT;
|
|
if (strcmp((char *)tok->value, "uint") == 0)
|
|
return FZL_TYPE_UINT;
|
|
|
|
if (strcmp((char *)tok->value, "bool") == 0)
|
|
return FZL_TYPE_BOOL;
|
|
if (strcmp((char *)tok->value, "str") == 0)
|
|
return FZL_TYPE_STRING;
|
|
if (strcmp((char *)tok->value, "char") == 0)
|
|
return FZL_TYPE_CHAR;
|
|
|
|
return FZL_TYPE_NULL;
|
|
}
|