aboutsummaryrefslogtreecommitdiff
path: root/src/types.h
blob: 73b5b636bbbd1b183ba3124636c308e54b2c8702 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#pragma once

#include "common.h"
#include <stdio.h>

typedef enum {
    TYPE_NONE,
    TYPE_ANY, // This is a hack for builtins till we can cast types
    TYPE_INT,
    TYPE_CHAR,
    TYPE_PTR,
    TYPE_ARRAY,
} DataType;

typedef struct data_type_node {
    DataType type;
    struct data_type_node *ptr;
    i64 array_size;
} Type;

Type *type_new(DataType type);
Type *type_new_ptr(DataType type);

i64 size_for_type(Type *type);
char *type_to_str(Type *type);

bool type_equals(Type *a, Type *b);
bool is_int_type(Type *type);
bool is_string_type(Type *type);
bool is_convertible(Type *from, Type *to);

// Type checking / casting expressions to right types
typedef struct ast_node Node;

Node *handle_unary_expr_types(Node *, Token *);
Node *handle_binary_expr_types(Node *, Token *);

Node *decay_array_to_pointer(Node *, Token *);