mie: move mie_type_to_string to type.c
This commit is contained in:
@@ -24,50 +24,6 @@
|
|||||||
|
|
||||||
typedef b_status (*write_function)(struct mie_ir_converter *, struct mie_value *);
|
typedef b_status (*write_function)(struct mie_ir_converter *, struct mie_value *);
|
||||||
|
|
||||||
static void mie_type_to_string(struct mie_type *type, char *out, size_t max)
|
|
||||||
{
|
|
||||||
if (!type) {
|
|
||||||
snprintf(out, max, "<no-type>");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (type->t_id) {
|
|
||||||
case MIE_TYPE_PTR:
|
|
||||||
snprintf(out, max, "ptr");
|
|
||||||
break;
|
|
||||||
case MIE_TYPE_VOID:
|
|
||||||
snprintf(out, max, "void");
|
|
||||||
break;
|
|
||||||
case MIE_TYPE_INT:
|
|
||||||
snprintf(out, max, "i%u", type->t_width);
|
|
||||||
break;
|
|
||||||
case MIE_TYPE_ID:
|
|
||||||
snprintf(out, max, "id");
|
|
||||||
break;
|
|
||||||
case MIE_TYPE_STR:
|
|
||||||
snprintf(out, max, "str");
|
|
||||||
break;
|
|
||||||
case MIE_TYPE_ATOM:
|
|
||||||
snprintf(out, max, "atom");
|
|
||||||
break;
|
|
||||||
case MIE_TYPE_LABEL:
|
|
||||||
snprintf(out, max, "label");
|
|
||||||
break;
|
|
||||||
case MIE_TYPE_ARRAY:
|
|
||||||
snprintf(out, max, "array");
|
|
||||||
break;
|
|
||||||
case MIE_TYPE_FUNC:
|
|
||||||
snprintf(out, max, "func");
|
|
||||||
break;
|
|
||||||
case MIE_TYPE_SELECTOR:
|
|
||||||
snprintf(out, max, "");
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
snprintf(out, max, "<unknown-type>");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
b_status write_char(struct mie_ir_converter *converter, char c)
|
b_status write_char(struct mie_ir_converter *converter, char c)
|
||||||
{
|
{
|
||||||
long result = 0;
|
long result = 0;
|
||||||
|
|||||||
48
mie/type.c
48
mie/type.c
@@ -1,4 +1,5 @@
|
|||||||
#include <mie/type.h>
|
#include <mie/type.h>
|
||||||
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
@@ -25,3 +26,50 @@ struct mie_type *mie_type_create(void)
|
|||||||
|
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void mie_type_to_string(const struct mie_type *type, char *out, size_t max)
|
||||||
|
{
|
||||||
|
if (!type) {
|
||||||
|
snprintf(out, max, "no-type");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (type->t_id) {
|
||||||
|
case MIE_TYPE_PTR:
|
||||||
|
snprintf(out, max, "ptr");
|
||||||
|
break;
|
||||||
|
case MIE_TYPE_VOID:
|
||||||
|
snprintf(out, max, "void");
|
||||||
|
break;
|
||||||
|
case MIE_TYPE_INT:
|
||||||
|
snprintf(out, max, "i%u", type->t_width);
|
||||||
|
break;
|
||||||
|
case MIE_TYPE_ID:
|
||||||
|
snprintf(out, max, "id");
|
||||||
|
break;
|
||||||
|
case MIE_TYPE_STR:
|
||||||
|
snprintf(out, max, "str");
|
||||||
|
break;
|
||||||
|
case MIE_TYPE_ATOM:
|
||||||
|
snprintf(out, max, "atom");
|
||||||
|
break;
|
||||||
|
case MIE_TYPE_LABEL:
|
||||||
|
snprintf(out, max, "label");
|
||||||
|
break;
|
||||||
|
case MIE_TYPE_ARRAY:
|
||||||
|
snprintf(out, max, "array");
|
||||||
|
break;
|
||||||
|
case MIE_TYPE_FUNC:
|
||||||
|
snprintf(out, max, "func");
|
||||||
|
break;
|
||||||
|
case MIE_TYPE_GLUE:
|
||||||
|
snprintf(out, max, "glue");
|
||||||
|
break;
|
||||||
|
case MIE_TYPE_SELECTOR:
|
||||||
|
snprintf(out, max, "");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
snprintf(out, max, "unknown-type");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user